JuliaMath / Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia
http://juliamath.github.io/Interpolations.jl/
Other
523 stars 110 forks source link

`warn` not defined #535

Closed dvetsch75 closed 1 year ago

dvetsch75 commented 1 year ago

warn is not defined in newer Julia releases. Should this be @warn instead? Line 157 of monotonic.jl

function MonotonicInterpolation(::Type{TWeights}, it::TInterpolationType, knots::TKnots, A::AbstractArray{TEl,1},
    m::Vector{TCoeffs1}, c::Vector{TCoeffs2}, d::Vector{TCoeffs3}) where {TWeights, TCoeffs1, TCoeffs2, TCoeffs3, TEl, TInterpolationType<:MonotonicInterpolationType, TKnots<:AbstractVector{<:Number}}

    isconcretetype(TInterpolationType) || error("The spline type must be a leaf type (was $TInterpolationType)")
    isconcretetype(tcoef(A)) || warn("For performance reasons, consider using an array of a concrete type (eltype(A) == $(eltype(A)))")

    check_monotonic(knots, A)

    cZero = zero(TWeights)
    if isempty(A)
        T = Base.promote_op(*, typeof(cZero), eltype(A))
    else
        T = typeof(cZero * first(A))
    end

    MonotonicInterpolation{T, TCoeffs1, TCoeffs2, TCoeffs3, TEl, TInterpolationType, TKnots, typeof(A)}(it, knots, A, m, c, d)
end

To reproduce:


using Interpolations

struct MyArray
    a::Vector{Real}
end

x = 1:5
y = MyArray(
    map(1:5) do x
        x + rand()
    end
)

interp = interpolate(
    x,
    y.a,
    FritschCarlsonMonotonicInterpolation()
)

Produces the following error:

ERROR: UndefVarError: warn not defined
Stacktrace:
 [1] Interpolations.MonotonicInterpolation(#unused#::Type{Float64}, it::FritschCarlsonMonotonicInterpolation, knots::UnitRange{Int64}, A::Vector{Real}, m::Vector{Float64}, c::Vector{Float64}, d::Vector{Float64})
   @ Interpolations C:\Users\maa98\.julia\packages\Interpolations\Sxe87\src\monotonic\monotonic.jl:157
 [2] interpolate(#unused#::Type{Float64}, #unused#::Type{Float64}, #unused#::Type{Float64}, #unused#::Type{Float64}, knots::UnitRange{Int64}, A::Vector{Real}, it::FritschCarlsonMonotonicInterpolation)
   @ Interpolations C:\Users\maa98\.julia\packages\Interpolations\Sxe87\src\monotonic\monotonic.jl:192
 [3] interpolate(knots::UnitRange{Int64}, A::Vector{Real}, it::FritschCarlsonMonotonicInterpolation)
   @ Interpolations C:\Users\maa98\.julia\packages\Interpolations\Sxe87\src\monotonic\monotonic.jl:198
 [4] top-level scope
   @ REPL[7]:1
mkitti commented 1 year ago

Yes, it probably should be @warn. By the way, what are you trying to do?

dvetsch75 commented 1 year ago

Thanks - my team tends to be more familiar with Matlab, so I always try and define a function that looks and feels similar to e.g. Matlab's pchip to make their life easier, but we also need to set up our own structs to other things with interest rates. So our typical interest rates workflow is to define a Curve struct, then a splining function that takes a Curve and a time to spline to.