JuliaMath / Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia

Home Page:http://juliamath.github.io/Interpolations.jl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ConstantInterpolation fails with Unitful arrays

ivan-boikov opened this issue Β· comments

ConstantInterpolation fails when argument is Unitful array, but works when it's StepRangeLen. For LinearInterpolation it works in both cases.

using Unitful, Interpolations

x0 = (0:0.5:2)u"s";
y0 = (0:0.5:2)u"m";

# this works 
ConstantInterpolation(x0, y0)(1u"s")

# this fails
ConstantInterpolation(collect(x0), y0)(1u"s")

# these both work
LinearInterpolation(x0, y0)(1u"s")
LinearInterpolation(collect(x0), y0)(1u"s")

Using Julia v.1.7.3, Interpolations v.0.14.1

Need a stack trace here.

Here it is with latest version (v.0.14.4), julia is still v.1.7.3

julia> ConstantInterpolation(collect(x0), y0)(1u"s")
ERROR: DimensionError: 1 s and 3 are not dimensionally compatible.
Stacktrace:
[1] -(x::Quantity{Int64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}, y::Quantity{Int64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}})
  @ Unitful ~/.local/share/julia/packages/Unitful/SUQzL/src/quantities.jl:132
[2] -(x::Quantity{Int64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}, y::Int64) 
  @ Base ./promotion.jl:381
[3] positions(c::Constant{Nearest, Throw{OnGrid}}, ax::Vector{Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}}, x::Quantity{Int64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}) 
  @ Interpolations ~/.local/share/julia/packages/Interpolations/jPlKV/src/b-splines/constant.jl:49
[4] weightedindex(fs::Tuple{typeof(Interpolations.value_weights)}, deg::Constant{Nearest, Throw{OnGrid}}, knotvec::Vector{Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}}, x::Quantity{Int64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}, iclamp::Int64) 
  @ Interpolations ~/.local/share/julia/packages/Interpolations/jPlKV/src/gridded/indexing.jl:66
[5] weightedindex_parts2 
  @ ~/.local/share/julia/packages/Interpolations/jPlKV/src/gridded/indexing.jl:62 [inlined]
[6] weightedindex_parts 
  @ ~/.local/share/julia/packages/Interpolations/jPlKV/src/gridded/indexing.jl:56 [inlined]
[7] map3argf 
  @ ~/.local/share/julia/packages/Interpolations/jPlKV/src/b-splines/indexing.jl:70 [inlined]
[8] weightedindexes 
  @ ~/.local/share/julia/packages/Interpolations/jPlKV/src/b-splines/indexing.jl:66 [inlined]
[9] GriddedInterpolation 
  @ ~/.local/share/julia/packages/Interpolations/jPlKV/src/gridded/indexing.jl:4 [inlined]
[10] (::Interpolations.Extrapolation{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, 1, Interpolations.GriddedInterpolation{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, 1, StepRangeLen{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, Base.TwicePrecision{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, Base.TwicePrecision{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, Int64}, Gridded{Constant{Nearest, Throw{OnGrid}}}, Tuple{Vector{Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}}}}, Gridded{Constant{Nearest, Throw{OnGrid}}}, Throw{Nothing}})(x::Quantity{Int64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}) 
  @ Interpolations ~/.local/share/julia/packages/Interpolations/jPlKV/src/extrapolation/extrapolation.jl:49
[11] top-level scope 
  @ REPL[10]:1