You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have made the following function in order to create an interpolation from a matrix of coefficients d:
functioninterpolate(d::AbstractArray{T}) where {T<:Real}
Ns, Nt =size(d)
ITPType =Gridded(Linear())
id =similar(d, Ns); copyto!(id, collect(range(oneunit(T), T(Ns), Ns)))
t =similar(d, Nt); copyto!(t, collect(range(zero(T), oneunit(T), Nt)))
return Interpolations.GriddedInterpolation{eltype(d), 2, typeof(d), typeof(ITPType), typeof((id, t))}((id, t), d, ITPType)
end
This function returns a 2D GriddedInterpolation object and is valid for both CPU and GPU arrays:
julia> d = [0.01.0; 0.01.0] # 2D CPU array
2×2 Matrix{Float64}:
0.0 1.0
0.0 1.0
julia> itp = KomaMRIBase.interpolate(d)
2×2 interpolate((::Vector{Float64},::Vector{Float64}), ::Matrix{Float64}, Gridded(Linear())) with element type Float64:
0.0 1.0
0.0 1.0
julia> d = [0.01.0] # 1xNt CPU array
1×2 Matrix{Float64}:
0.0 1.0
julia> itp =interpolate(d)
1×2 interpolate((::Vector{Float64},::Vector{Float64}), ::Matrix{Float64}, Gridded(Linear())) with element type Float64:
0.0 1.0
julia> d =CuArray([0.01.0; 0.01.0]) # 2D GPU Array
2×2 CuArray{Float64, 2, CUDA.DeviceMemory}:
0.0 1.0
0.0 1.0
julia> itp =interpolate(d)
2×2 interpolate((::CuArray{Float64, 1, CUDA.DeviceMemory},::CuArray{Float64, 1, CUDA.DeviceMemory}), ::CuArray{Float64, 2, CUDA.DeviceMemory}, Gridded(Linear())) with element type Float64:
0.0 1.0
0.0 1.0
The problem comes only when these two things happen together:
This error happens when displaying. If I put a semicolon behind itp = interpolate(d), it does not appear, but when calling to the interpolation function:
julia> t =CuArray([0.00030.00031250.000325])
1×3 CuArray{Float64, 2, CUDA.DeviceMemory}:
0.0003 0.0003125 0.000325
julia> itp.(CuArray([1.0]), t)
1×3 CuArray{Float64, 2, CUDA.DeviceMemory}:
NaN NaN NaN
It returns an array of NaNs. When I tried to reproduce this error several times, sometimes it occurred and sometimes it did not.
I guess this is somehow related with #395 and with the fact that I am bypassing the GriddedInterpolation constructor, where check_gridded is called:
functionGriddedInterpolation(::Type{TWeights}, knots::NTuple{N,GridIndex}, A::AbstractArray{TCoefs,N}, it::IT) where {N,TCoefs,TWeights<:Real,IT<:DimSpec{Gridded},pad}
...check_gridded(it, knots, axes(A))
...GriddedInterpolation{T,N,TCoefs,IT,typeof(knots)}(knots, A, it)
end@inlinefunctioncheck_gridded(itpflag, knots, axs)
flag, ax1, k1 =getfirst(itpflag), axs[1], knots[1]
...length(k1) ==1&&error("dimensions of length 1 not yet supported") #FIXME <-- This is what I am bypassing...end
By the moment, I am solving it dispatching:
functionGriddedInterpolation(nodes, A, ITP)
return Interpolations.GriddedInterpolation{eltype(A), length(nodes), typeof(A), typeof(ITP), typeof(nodes)}(nodes, A, ITP)
endfunctioninterpolate(d::AbstractArray{T}, Ns::Val{1}) where {T<:Real}
_, Nt =size(d)
ITPType =Gridded(Linear())
t =similar(d, Nt); copyto!(t, collect(range(zero(T), oneunit(T), Nt)))
returnGriddedInterpolation((t, ), d[:], ITPType)
endfunctioninterpolate(d::AbstractArray{T}, Ns::Val) where {T<:Real}
Ns, Nt =size(d)
ITPType =Gridded(Linear())
id =similar(d, Ns); copyto!(id, collect(range(oneunit(T), T(Ns), Ns)))
t =similar(d, Nt); copyto!(t, collect(range(zero(T), oneunit(T), Nt)))
returnGriddedInterpolation((id, t), d, ITPType)
end
and, depending on Ns, calling the interpolator with:
itp.(t) (Ns = 1)
itp.(id, t) (Ns > 1)
But this solution is unnecessary complex.
Sorry for the long message and for not being able to reproduce the error in a more "general" way.
Thank you
The text was updated successfully, but these errors were encountered:
I have made the following function in order to create an interpolation from a matrix of coefficients
d
:This function returns a 2D GriddedInterpolation object and is valid for both CPU and GPU arrays:
The problem comes only when these two things happen together:
d
is 1xNt)d
is a GPU arrayThis error happens when displaying. If I put a semicolon behind
itp = interpolate(d)
, it does not appear, but when calling to the interpolation function:It returns an array of NaNs. When I tried to reproduce this error several times, sometimes it occurred and sometimes it did not.
I guess this is somehow related with #395 and with the fact that I am bypassing the
GriddedInterpolation
constructor, wherecheck_gridded
is called:By the moment, I am solving it dispatching:
and, depending on Ns, calling the interpolator with:
itp.(t)
(Ns = 1)itp.(id, t)
(Ns > 1)But this solution is unnecessary complex.
Sorry for the long message and for not being able to reproduce the error in a more "general" way.
Thank you
The text was updated successfully, but these errors were encountered: