diff --git a/Project.toml b/Project.toml index fe238577..c81f89bc 100644 --- a/Project.toml +++ b/Project.toml @@ -18,10 +18,12 @@ WoodburyMatrices = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" [weakdeps] Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" [extensions] InterpolationsUnitfulExt = "Unitful" InterpolationsForwardDiffExt = "ForwardDiff" +InterpolationsSciMLBaseExt = "SciMLBase" [compat] Adapt = "2, 3, 4.0" @@ -31,6 +33,7 @@ ForwardDiff = "0.10, 1.0" JLArrays = "0.2" OffsetArrays = "0.10, 0.11, 1.0.1" Ratios = "0.3, 0.4" +SciMLBase = "1.9, 2, 3" StaticArrays = "0.12, 1" Unitful = "1" WoodburyMatrices = "0.4, 0.5, 1.0" @@ -41,9 +44,10 @@ ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4" DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [targets] -test = ["ColorVectorSpace", "DualNumbers", "JLArrays", "ForwardDiff", "Test", "Unitful", "Zygote"] +test = ["ColorVectorSpace", "DualNumbers", "JLArrays", "ForwardDiff", "Test", "SciMLBase", "Unitful", "Zygote"] diff --git a/ext/InterpolationsSciMLBaseExt.jl b/ext/InterpolationsSciMLBaseExt.jl new file mode 100644 index 00000000..7539d4e4 --- /dev/null +++ b/ext/InterpolationsSciMLBaseExt.jl @@ -0,0 +1,12 @@ +module InterpolationsSciMLBaseExt + +using Interpolations: AbstractInterpolation, coefficients +using SciMLBase: SciMLBase + +# desired behavior is to warn if the contained array would warn +# so we just forward the coefficients of the interpolation to the actual warning check +function SciMLBase.should_warn_paramtype(i::AbstractInterpolation) + return SciMLBase.should_warn_paramtype(coefficients(i)) +end + +end diff --git a/test/runtests.jl b/test/runtests.jl index 7dbcc4ba..9951ee8b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -58,5 +58,8 @@ const isci = get(ENV, "CI", "") in ("true", "True") # Chain rules interaction include("chainrules.jl") + # SciMLBase interaction + include("scimlbase.jl") + include("gpu_support.jl") end diff --git a/test/scimlbase.jl b/test/scimlbase.jl new file mode 100644 index 00000000..17499466 --- /dev/null +++ b/test/scimlbase.jl @@ -0,0 +1,36 @@ +using Interpolations, SciMLBase, StaticArrays + +@testset "SciMLBase should_warn_paramtype" begin + Xs = 10.0:2.0:20.0 + # want Y-values that are + # - Concrete + Ys_float = Xs .^ 2 + # - Abstract + Ys_number = Vector{Real}(Ys_float) + # - Array of concrete + Ys_arr = map(x -> SVector(x^2, 2 * x - 1), Xs) + # - Array of abstract + Ys_arr_number = map(((i, x),) -> SVector{2, Real}(i, x), enumerate(Xs)) + bspline_concrete_scalar = interpolate(Ys_float, BSpline(Linear())) + bspline_abstract_scalar = interpolate(Ys_number, BSpline(Linear())) + bspline_concrete_array = interpolate(Ys_arr, BSpline(Linear())) + bspline_abstract_array = interpolate(Ys_arr_number, BSpline(Linear())) + + gridded_concrete_scalar = interpolate((Xs,), Ys_float, Gridded(Linear())) + gridded_abstract_scalar = interpolate((Xs,), Ys_number, Gridded(Linear())) + gridded_concrete_array = interpolate((Xs,), Ys_arr, Gridded(Linear())) + gridded_abstract_array = interpolate((Xs,), Ys_arr_number, Gridded(Linear())) + + # should not warn on concrete number + @test SciMLBase.should_warn_paramtype(bspline_concrete_scalar) == false + @test SciMLBase.should_warn_paramtype(gridded_concrete_scalar) == false + # should not warn on concrete array eltype + @test SciMLBase.should_warn_paramtype(bspline_concrete_array) == false + @test SciMLBase.should_warn_paramtype(gridded_concrete_array) == false + # should warn on abstract number + @test SciMLBase.should_warn_paramtype(bspline_abstract_scalar) + @test SciMLBase.should_warn_paramtype(gridded_abstract_scalar) + # should warn on abstract array eltype + @test SciMLBase.should_warn_paramtype(bspline_abstract_array) + @test SciMLBase.should_warn_paramtype(gridded_abstract_array) +end