|
90 | 90 | @test @inferred(LinearInterpolation( |
91 | 91 | u_s, t; extrapolation = ExtrapolationType.Extension)) isa LinearInterpolation |
92 | 92 | A_s = LinearInterpolation(u_s, t; extrapolation = ExtrapolationType.Extension) |
93 | | - for _x in (0, 5.5, 11) |
| 93 | + for x in (0, 5.5, 11) |
94 | 94 | @test A(x) == A_s(x) |
95 | 95 | end |
96 | 96 | @test A_s(0) isa SVector{length(y)} |
|
331 | 331 | @test @inferred(output_dim(A)) == 1 |
332 | 332 | @test @inferred(output_size(A)) == (2,) |
333 | 333 |
|
| 334 | + # Vector{Vector} interpolation test |
334 | 335 | u_ = [1.0, 4.0, 9.0, 16.0]' .* ones(5) |
335 | 336 | u = [u_[:, i] for i in 1:size(u_, 2)] |
336 | 337 | A = @inferred(QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.Extension)) |
|
341 | 342 | @test A(5.0) == 25.0 * ones(5) |
342 | 343 | @test @inferred(output_dim(A)) == 1 |
343 | 344 | @test @inferred(output_size(A)) == (5,) |
| 345 | + # Test allocation-free interpolation with Vector{StaticArrays.SVector} |
| 346 | + u_s = [convert(SVector{length(u[1])}, i) for i in u] |
| 347 | + @test @inferred(QuadraticInterpolation( |
| 348 | + u_s, t; extrapolation = ExtrapolationType.Extension)) isa QuadraticInterpolation |
| 349 | + A_s = QuadraticInterpolation(u_s, t; extrapolation = ExtrapolationType.Extension) |
| 350 | + for x in (0, 1.5, 2.5, 3.5, 5.0) |
| 351 | + @test A(x) == A_s(x) |
| 352 | + end |
| 353 | + @test A_s(0) isa SVector{length(u[1])} |
| 354 | + @test_nowarn test_allocs(A_s, 0) |
344 | 355 |
|
| 356 | + # Vector{Matrix} interpolation test |
345 | 357 | u = [repeat(u[i], 1, 3) for i in 1:4] |
346 | 358 | @test_broken @inferred(QuadraticInterpolation( |
347 | 359 | u, t; extrapolation = ExtrapolationType.Extension)) isa QuadraticInterpolation |
|
568 | 580 | test_cached_index(A) |
569 | 581 | @test @inferred(output_dim(A)) == 1 |
570 | 582 | @test @inferred(output_size(A)) == (2,) |
| 583 | + |
| 584 | + # Test allocation-free interpolation with StaticArrays |
| 585 | + u_s = [convert(SVector{length(first(u))}, i) for i in u] |
| 586 | + A_s = @inferred(ConstantInterpolation( |
| 587 | + u_s, t; extrapolation = ExtrapolationType.Extension)) |
| 588 | + for x in 0.5:0.5:4.5 |
| 589 | + @test A(x) == A_s(x) |
| 590 | + end |
| 591 | + @test A_s(0) isa SVector{length(first(u))} |
| 592 | + @test_nowarn test_allocs(A_s, 0) |
571 | 593 | end |
572 | 594 |
|
573 | 595 | @testset "Vector of Matrices case" for u in [ |
|
647 | 669 | @test A(1.9) == u[1] |
648 | 670 | @test A(3.1) == u[2] |
649 | 671 | @test A(2.5) ≈ (u[1] + u[2]) / 2 |
| 672 | + |
| 673 | + u_ = u' .* ones(5) # [u for i in 1:length(t)] |
| 674 | + uv = [u_[:, i] for i in 1:size(u_, 2)] |
| 675 | + # Test Vector{Vector} interpolation |
| 676 | + A = SmoothedConstantInterpolation(uv, t; d_max) |
| 677 | + @test A(1.9) == uv[1] |
| 678 | + @test A(3.1) == uv[2] |
| 679 | + @test A(2.5) ≈ (uv[1] + uv[2]) / 2 |
| 680 | + # Test allocation-free interpolation with Vector{StaticArrays.SVector} |
| 681 | + u_s = [convert(SVector{length(uv[1])}, i) for i in uv] |
| 682 | + @test_broken @inferred(SmoothedConstantInterpolation( |
| 683 | + u_s, t; d_max)) isa SmoothedConstantInterpolation |
| 684 | + A_s = SmoothedConstantInterpolation(u_s, t; d_max) |
| 685 | + for x in (1.9, 3.1, 2.5) |
| 686 | + @test A(x) == A_s(x) |
| 687 | + end |
| 688 | + @test A_s(1.9) isa SVector{length(uv[1])} |
| 689 | + @test_nowarn test_allocs(A_s, 1.9) |
| 690 | + # Test Vector{Matrix} interpolation |
| 691 | + um = [repeat(uv[i], 1, 3) for i in 1:length(t)] |
| 692 | + A = SmoothedConstantInterpolation(um, t; d_max) |
| 693 | + @test A(1.9) == u[1] * ones(5, 3) |
| 694 | + @test A(3.1) == u[2] * ones(5, 3) |
| 695 | + @test A(2.5) ≈ ((u[1] + u[2]) / 2) * ones(5, 3) |
650 | 696 | end |
651 | 697 |
|
652 | 698 | @testset "QuadraticSpline Interpolation" begin |
|
671 | 717 | @test @inferred(output_dim(A)) == 0 |
672 | 718 | @test @inferred(output_size(A)) == () |
673 | 719 |
|
| 720 | + # Test Vector{Vector} interpolation |
674 | 721 | u_ = [0.0, 1.0, 3.0]' .* ones(4) |
675 | 722 | u = [u_[:, i] for i in 1:size(u_, 2)] |
676 | 723 | A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Extension) |
|
680 | 727 | @test A(2.0) == P₁(2.0) * ones(4) |
681 | 728 | @test @inferred(output_dim(A)) == 1 |
682 | 729 | @test @inferred(output_size(A)) == (4,) |
| 730 | + # Test allocation-free interpolation with Vector{StaticArrays.SVector} |
| 731 | + u_s = [convert(SVector{length(u[1])}, i) for i in u] |
| 732 | + A_s = @inferred(QuadraticSpline(u_s, t; extrapolation = ExtrapolationType.Extension)) |
| 733 | + for x in (-2.0, -0.5, 0.7, 2.0) |
| 734 | + @test A(x) == A_s(x) |
| 735 | + end |
| 736 | + @test A_s(0.7) isa SVector{length(u[1])} |
| 737 | + @test_nowarn test_allocs(A_s, 0.7) |
683 | 738 |
|
| 739 | + # Test Vector{Matrix} interpolation |
684 | 740 | u = [repeat(u[i], 1, 3) for i in 1:3] |
685 | 741 | A = @inferred(QuadraticSpline(u, t; extrapolation = ExtrapolationType.Extension)) |
686 | 742 | @test A(-2.0) == P₁(-2.0) * ones(4, 3) |
|
728 | 784 |
|
729 | 785 | u_ = [0.0, 1.0, 3.0]' .* ones(4) |
730 | 786 | u = [u_[:, i] for i in 1:size(u_, 2)] |
| 787 | + # Test Vector{Vector} interpolation |
731 | 788 | @test @inferred(CubicSpline(u, t; extrapolation = ExtrapolationType.Extension)) isa |
732 | | - CubicSpline broken=VERSION < v"1.11" |
| 789 | + CubicSpline |
733 | 790 | A = CubicSpline(u, t; extrapolation = ExtrapolationType.Extension) |
734 | 791 | for x in (-1.5, -0.5, -0.7) |
735 | 792 | @test A(x) ≈ P₁(x) * ones(4) |
|
739 | 796 | end |
740 | 797 | @test @inferred(output_dim(A)) == 1 |
741 | 798 | @test @inferred(output_size(A)) == (4,) |
| 799 | + # Test allocation-free interpolation with StaticArrays |
| 800 | + u_s = [convert(SVector{length(first(u))}, i) for i in u] |
| 801 | + @test_broken @inferred(CubicSpline( |
| 802 | + u_s, t; extrapolation = ExtrapolationType.Extension)) isa CubicSpline |
| 803 | + A_s = CubicSpline(u_s, t; extrapolation = ExtrapolationType.Extension) |
| 804 | + for x in (-1.5, -0.5, -0.7) |
| 805 | + @test A(x) == A_s(x) |
| 806 | + end |
| 807 | + @test A_s(0) isa SVector{length(first(u))} |
| 808 | + @test_nowarn test_allocs(A_s, 0) |
742 | 809 |
|
| 810 | + # Test Vector{Matrix} interpolation |
743 | 811 | u = [repeat(u[i], 1, 3) for i in 1:3] |
744 | | - @test_broken @inferred(CubicSpline( |
| 812 | + @test @inferred(CubicSpline( |
745 | 813 | u, t; extrapolation = ExtrapolationType.Extension)) isa CubicSpline |
746 | 814 | A = CubicSpline(u, t; extrapolation = ExtrapolationType.Extension) |
747 | 815 | for x in (-1.5, -0.5, -0.7) |
|
778 | 846 | 0.0 cos(2t)] |
779 | 847 | t = 0.1:0.1:1.0 |
780 | 848 | u3d = f3d.(t) |
781 | | - @test_broken @inferred(CubicSpline(u3d, t)) isa CubicSpline |
| 849 | + @test @inferred(CubicSpline(u3d, t)) isa CubicSpline |
782 | 850 | c = CubicSpline(u3d, t) |
783 | 851 | t_test = 0.1:0.05:1.0 |
784 | 852 | u_test = reduce(hcat, c.(t_test)) |
@@ -952,8 +1020,18 @@ end |
952 | 1020 | @testset "Vector of Vectors case" begin |
953 | 1021 | u2 = [[u[i], u[i] + 1] for i in eachindex(u)] |
954 | 1022 | du2 = [[du[i], du[i]] for i in eachindex(du)] |
955 | | - A2 = CubicHermiteSpline(du2, u2, t) |
| 1023 | + A2 = CubicHermiteSpline(du2, u2, t; extrapolation = ExtrapolationType.Extension) |
956 | 1024 | @test u2 ≈ A2.(t) |
| 1025 | + @test A2(100.0) ≈ repeat([10.106770], 2) + [0, 1] rtol=1e-5 |
| 1026 | + @test A2(300.0) ≈ repeat([9.901542], 2) + [0, 1] rtol=1e-5 |
| 1027 | + # Test allocation-free interpolation with Vector{StaticArrays.SVector} |
| 1028 | + u2_s = [convert(SVector{length(u2[1])}, i) for i in u2] |
| 1029 | + du2_s = [convert(SVector{length(du2[1])}, i) for i in du2] |
| 1030 | + A2_s = @inferred(CubicHermiteSpline(du2_s, u2_s, t; extrapolation = ExtrapolationType.Extension)) |
| 1031 | + @test A2_s(100.0) == A2(100.0) |
| 1032 | + @test A2_s(300.0) == A2(300.0) |
| 1033 | + @test A2_s(0.7) isa SVector{length(u2[1])} |
| 1034 | + @test_nowarn test_allocs(A2_s, 0.7) |
957 | 1035 | end |
958 | 1036 | @testset "Vector of Matrices case" begin |
959 | 1037 | u3 = [[u[i] u[i] + 1] for i in eachindex(u)] |
@@ -1003,8 +1081,19 @@ end |
1003 | 1081 | u2 = [[u[i], u[i] + 1] for i in eachindex(u)] |
1004 | 1082 | du2 = [[du[i], du[i]] for i in eachindex(du)] |
1005 | 1083 | ddu2 = [[ddu[i], ddu[i]] for i in eachindex(ddu)] |
1006 | | - A2 = QuinticHermiteSpline(ddu2, du2, u2, t) |
| 1084 | + A2 = QuinticHermiteSpline(ddu2, du2, u2, t; extrapolation = ExtrapolationType.Extension) |
1007 | 1085 | @test u2 ≈ A2.(t) |
| 1086 | + @test A2(100.0) ≈ repeat([10.107996], 2) + [0, 1] rtol=1e-5 |
| 1087 | + @test A2(300.0) ≈ repeat([11.364162], 2) + [0, 1] rtol=1e-5 |
| 1088 | + # Test allocation-free interpolation with Vector{StaticArrays.SVector} |
| 1089 | + u2_s = [convert(SVector{length(u2[1])}, i) for i in u2] |
| 1090 | + du2_s = [convert(SVector{length(du2[1])}, i) for i in du2] |
| 1091 | + ddu2_s = [convert(SVector{length(du2[1])}, i) for i in ddu2] |
| 1092 | + A2_s = @inferred(QuinticHermiteSpline(ddu2_s, du2_s, u2_s, t; extrapolation = ExtrapolationType.Extension)) |
| 1093 | + @test A2_s(100.0) == A2(100.0) |
| 1094 | + @test A2_s(300.0) == A2(300.0) |
| 1095 | + @test A2_s(0.7) isa SVector{length(u2[1])} |
| 1096 | + @test_nowarn test_allocs(A2_s, 0.7) |
1008 | 1097 | end |
1009 | 1098 | @testset "Vector of Matrices case" begin |
1010 | 1099 | u3 = [[u[i] u[i] + 1] for i in eachindex(u)] |
|
0 commit comments