Skip to content

Commit 5e26c1c

Browse files
committed
All works except HVP
1 parent 504e67d commit 5e26c1c

7 files changed

Lines changed: 102 additions & 5 deletions

File tree

DifferentiationInterface/test/Back/FiniteDiff/test.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ end
2727
include_cachified=true,
2828
include_constantorcachified=true,
2929
use_tuples=true,
30+
include_smaller=true,
3031
);
3132
excluded=[:second_derivative, :hvp],
3233
logging=LOGGING,

DifferentiationInterface/test/Back/ForwardDiff/test.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ end
4141
include_cachified=true,
4242
include_constantorcachified=true,
4343
use_tuples=true,
44+
include_smaller=true,
4445
);
4546
logging=LOGGING,
4647
)

DifferentiationInterface/test/Core/SimpleFiniteDiff/test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ end
6363
@testset "Dense" begin
6464
test_differentiation(
6565
vcat(backends, second_order_backends),
66-
default_scenarios(; include_constantified=true);
66+
default_scenarios(; include_constantified=true, include_smaller=true);
6767
logging=LOGGING,
6868
)
6969

DifferentiationInterfaceTest/src/scenarios/default.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ function default_scenarios(;
557557
include_cachified=false,
558558
include_constantorcachified=false,
559559
use_tuples=false,
560+
include_smaller=false,
560561
)
561562
x_ = 0.42
562563
dx_ = 3.14
@@ -575,7 +576,7 @@ function default_scenarios(;
575576
dy_2_3 = float.(reshape(-5:2:5, 2, 3))
576577
dy_6_2 = float.(reshape(-11:2:11, 6, 2))
577578

578-
initialscens = vcat(
579+
scens = vcat(
579580
# one argument
580581
num_to_num_scenarios(x_; dx=dx_, dy=dy_),
581582
onevec_to_onevec_scenarios_onearg(x_; dx=dx_, dy=dy_),
@@ -623,8 +624,18 @@ function default_scenarios(;
623624
),
624625
)
625626

626-
scens = map(initialscens, smallerscens) do s1, s2
627-
s1 # TODO: readd smaller scens
627+
scens_smaller_prep = map(scens, smallerscens) do s1, s2
628+
Scenario{operator(s1),operator_place(s1),function_place(s1)}(;
629+
f=s1.f,
630+
y=s1.y,
631+
x=s1.x,
632+
t=s1.t,
633+
contexts=s1.contexts,
634+
res1=s1.res1,
635+
res2=s1.res2,
636+
name=isnothing(s1.name) ? nothing : s1.name * " [smaller prep]",
637+
prep_args=s2.prep_args,
638+
)
628639
end
629640

630641
include_batchified && append!(scens, batchify(scens))
@@ -635,6 +646,7 @@ function default_scenarios(;
635646
include_constantified && append!(final_scens, constantify(scens))
636647
include_cachified && append!(final_scens, cachify(scens; use_tuples=use_tuples))
637648
include_constantorcachified && append!(final_scens, constantorcachify(scens))
649+
include_smaller && append!(final_scens, scens_smaller_prep)
638650

639651
return final_scens
640652
end

DifferentiationInterfaceTest/src/test_differentiation.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function test_differentiation(
8484
rtol::Real=1e-3,
8585
scenario_intact::Bool=true,
8686
sparsity::Bool=false,
87+
reprepare::Bool=true,
8788
# type stability options
8889
ignored_modules=nothing,
8990
function_filter=if VERSION >= v"1.11"
@@ -160,6 +161,7 @@ function test_differentiation(
160161
rtol,
161162
scenario_intact,
162163
sparsity,
164+
reprepare,
163165
)
164166
end
165167
yield()

DifferentiationInterfaceTest/src/tests/correctness_eval.jl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
has_size(::Union{Number,AbstractArray}) = true
2+
has_size(_x) = false
3+
14
const PME = PreparationMismatchError
25

36
for op in ALL_OPS
@@ -49,6 +52,7 @@ for op in ALL_OPS
4952
rtol::Real,
5053
scenario_intact::Bool,
5154
sparsity::Bool,
55+
reprepare::Bool,
5256
)
5357
(; f, x, y, res1, contexts, prep_args) = new_scen = deepcopy(scen)
5458
local prepstrict
@@ -57,6 +61,10 @@ for op in ALL_OPS
5761
prepstrict = $prep_op(
5862
f, ba, prep_args.x, prep_args.contexts...; strict=Val(true)
5963
)
64+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
65+
prep = $prep_op!(f, prep, ba, x, contexts...)
66+
prepstrict = $prep_op!(f, prepstrict, ba, x, contexts...)
67+
end
6068
[(), (prep,), (prepstrict,)]
6169
end
6270
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -98,6 +106,7 @@ for op in ALL_OPS
98106
rtol::Real,
99107
scenario_intact::Bool,
100108
sparsity::Bool,
109+
reprepare::Bool,
101110
)
102111
(; f, x, y, res1, contexts, prep_args) = new_scen = deepcopy(scen)
103112
local prepstrict
@@ -106,6 +115,10 @@ for op in ALL_OPS
106115
prepstrict = $prep_op(
107116
f, ba, prep_args.x, prep_args.contexts...; strict=Val(true)
108117
)
118+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
119+
prep = $prep_op!(f, prep, ba, x, contexts...)
120+
prepstrict = $prep_op!(f, prepstrict, ba, x, contexts...)
121+
end
109122
[(), (prep,), (prepstrict,)]
110123
end
111124
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -163,6 +176,7 @@ for op in ALL_OPS
163176
rtol::Real,
164177
scenario_intact::Bool,
165178
sparsity::Bool,
179+
reprepare::Bool,
166180
)
167181
(; f, x, y, res1, contexts, prep_args) = new_scen = deepcopy(scen)
168182
local prepstrict
@@ -176,6 +190,13 @@ for op in ALL_OPS
176190
prep_args.contexts...;
177191
strict=Val(true),
178192
)
193+
if reprepare &&
194+
has_size(x) &&
195+
has_size(y) &&
196+
(size(x) != size(prep_args.x) || size(y) != prep_args.y)
197+
prep = $prep_op!(f, y, prep, ba, x, contexts...)
198+
prepstrict = $prep_op!(f, y, prepstrict, ba, x, contexts...)
199+
end
179200
[(), (prep,), (prepstrict,)]
180201
end
181202
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -225,6 +246,7 @@ for op in ALL_OPS
225246
rtol::Real,
226247
scenario_intact::Bool,
227248
sparsity::Bool,
249+
reprepare::Bool,
228250
)
229251
(; f, x, y, res1, contexts, prep_args) = new_scen = deepcopy(scen)
230252
local prepstrict
@@ -238,6 +260,13 @@ for op in ALL_OPS
238260
prep_args.contexts...;
239261
strict=Val(true),
240262
)
263+
if reprepare &&
264+
has_size(x) &&
265+
has_size(y) &&
266+
(size(x) != size(prep_args.x) || size(y) != prep_args.y)
267+
prep = $prep_op!(f, y, prep, ba, x, contexts...)
268+
prepstrict = $prep_op!(f, y, prepstrict, ba, x, contexts...)
269+
end
241270
[(), (prep,), (prepstrict,)]
242271
end
243272
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -298,6 +327,7 @@ for op in ALL_OPS
298327
rtol::Real,
299328
scenario_intact::Bool,
300329
sparsity::Bool,
330+
reprepare::Bool,
301331
)
302332
(; f, x, y, res1, res2, contexts, prep_args) = new_scen = deepcopy(scen)
303333
local prepstrict
@@ -306,6 +336,10 @@ for op in ALL_OPS
306336
prepstrict = $prep_op(
307337
f, ba, prep_args.x, prep_args.contexts...; strict=Val(true)
308338
)
339+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
340+
prep = $prep_op!(f, prep, ba, x, contexts...)
341+
prepstrict = $prep_op!(f, prepstrict, ba, x, contexts...)
342+
end
309343
[(), (prep,), (prepstrict,)]
310344
end
311345
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -349,6 +383,7 @@ for op in ALL_OPS
349383
rtol::Real,
350384
scenario_intact::Bool,
351385
sparsity::Bool,
386+
reprepare::Bool,
352387
)
353388
(; f, x, y, res1, res2, contexts, prep_args) = new_scen = deepcopy(scen)
354389
local prepstrict
@@ -357,6 +392,10 @@ for op in ALL_OPS
357392
prepstrict = $prep_op(
358393
f, ba, prep_args.x, prep_args.contexts...; strict=Val(true)
359394
)
395+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
396+
prep = $prep_op!(f, prep, ba, x, contexts...)
397+
prepstrict = $prep_op!(f, prepstrict, ba, x, contexts...)
398+
end
360399
[(), (prep,), (prepstrict,)]
361400
end
362401
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -417,6 +456,7 @@ for op in ALL_OPS
417456
rtol::Real,
418457
scenario_intact::Bool,
419458
sparsity::Bool,
459+
reprepare::Bool,
420460
)
421461
(; f, x, y, t, res1, contexts, prep_args) = new_scen = deepcopy(scen)
422462
local prepstrict
@@ -431,6 +471,11 @@ for op in ALL_OPS
431471
strict=Val(true),
432472
)
433473
prep_same = $prep_op_same(f, ba, x, prep_args.t, contexts...)
474+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
475+
prep = $prep_op!(f, prep, ba, x, t, contexts...)
476+
prepstrict = $prep_op!(f, prepstrict, ba, x, t, contexts...)
477+
prep_same = $prep_op_same(f, ba, x, t, contexts...)
478+
end
434479
[(), (prep,), (prepstrict,), (prep_same,)]
435480
end
436481
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -468,6 +513,7 @@ for op in ALL_OPS
468513
rtol::Real,
469514
scenario_intact::Bool,
470515
sparsity::Bool,
516+
reprepare::Bool,
471517
)
472518
(; f, x, y, t, res1, contexts, prep_args) = new_scen = deepcopy(scen)
473519
local prepstrict
@@ -482,6 +528,11 @@ for op in ALL_OPS
482528
strict=Val(true),
483529
)
484530
prep_same = $prep_op_same(f, ba, x, prep_args.t, contexts...)
531+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
532+
prep = $prep_op!(f, prep, ba, x, t, contexts...)
533+
prepstrict = $prep_op!(f, prepstrict, ba, x, t, contexts...)
534+
prep_same = $prep_op_same(f, ba, x, t, contexts...)
535+
end
485536
[(), (prep,), (prepstrict,), (prep_same,)]
486537
end
487538
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -535,6 +586,7 @@ for op in ALL_OPS
535586
rtol::Real,
536587
scenario_intact::Bool,
537588
sparsity::Bool,
589+
reprepare::Bool,
538590
)
539591
(; f, x, y, t, res1, contexts, prep_args) = new_scen = deepcopy(scen)
540592
local prepstrict
@@ -552,6 +604,14 @@ for op in ALL_OPS
552604
strict=Val(true),
553605
)
554606
prep_same = $prep_op_same(f, prep_args.y, ba, x, prep_args.t, contexts...)
607+
if reprepare &&
608+
has_size(x) &&
609+
has_size(y) &&
610+
(size(x) != size(prep_args.x) || size(y) != prep_args.y)
611+
prep = $prep_op!(f, y, prep, ba, x, t, contexts...)
612+
prepstrict = $prep_op!(f, y, prepstrict, ba, x, t, contexts...)
613+
prep_same = $prep_op_same(f, y, ba, x, t, contexts...)
614+
end
555615
[(), (prep,), (prepstrict,), (prep_same,)]
556616
end
557617
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -601,6 +661,7 @@ for op in ALL_OPS
601661
rtol::Real,
602662
scenario_intact::Bool,
603663
sparsity::Bool,
664+
reprepare::Bool,
604665
)
605666
(; f, x, y, t, res1, contexts, prep_args) = new_scen = deepcopy(scen)
606667
local prepstrict
@@ -618,6 +679,14 @@ for op in ALL_OPS
618679
strict=Val(true),
619680
)
620681
prep_same = $prep_op_same(f, prep_args.y, ba, x, prep_args.t, contexts...)
682+
if reprepare &&
683+
has_size(x) &&
684+
has_size(y) &&
685+
(size(x) != size(prep_args.x) || size(y) != prep_args.y)
686+
prep = $prep_op!(f, y, prep, ba, x, t, contexts...)
687+
prepstrict = $prep_op!(f, y, prepstrict, ba, x, t, contexts...)
688+
prep_same = $prep_op_same(f, y, ba, x, t, contexts...)
689+
end
621690
[(), (prep,), (prepstrict,), (prep_same,)]
622691
end
623692
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -674,6 +743,7 @@ for op in ALL_OPS
674743
rtol::Real,
675744
scenario_intact::Bool,
676745
sparsity::Bool,
746+
reprepare::Bool,
677747
)
678748
(; f, x, y, t, res1, res2, contexts, prep_args) = new_scen = deepcopy(scen)
679749
local prepstrict
@@ -688,6 +758,11 @@ for op in ALL_OPS
688758
strict=Val(true),
689759
)
690760
prep_same = $prep_op_same(f, ba, x, prep_args.t, contexts...)
761+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
762+
prep = $prep_op!(f, prep, ba, x, t, contexts...)
763+
prepstrict = $prep_op!(f, prepstrict, ba, x, t, contexts...)
764+
prep_same = $prep_op_same(f, ba, x, t, contexts...)
765+
end
691766
[(), (prep,), (prepstrict,), (prep_same,)]
692767
end
693768
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)
@@ -725,6 +800,7 @@ for op in ALL_OPS
725800
rtol::Real,
726801
scenario_intact::Bool,
727802
sparsity::Bool,
803+
reprepare::Bool,
728804
)
729805
(; f, x, y, t, res1, res2, contexts, prep_args) = new_scen = deepcopy(scen)
730806
local prepstrict
@@ -739,6 +815,11 @@ for op in ALL_OPS
739815
strict=Val(true),
740816
)
741817
prep_same = $prep_op_same(f, ba, x, prep_args.t, contexts...)
818+
if reprepare && has_size(x) && has_size(y) && (size(x) != size(prep_args.x))
819+
prep = $prep_op!(f, prep, ba, x, t, contexts...)
820+
prepstrict = $prep_op!(f, prepstrict, ba, x, t, contexts...)
821+
prep_same = $prep_op_same(f, ba, x, t, contexts...)
822+
end
742823
[(), (prep,), (prepstrict,), (prep_same,)]
743824
end
744825
for (preptup_val, preptup_noval) in zip(preptup_cands_val, preptup_cands_noval)

DifferentiationInterfaceTest/test/standard.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LOGGING = get(ENV, "CI", "false") == "false"
1313

1414
test_differentiation(
1515
[AutoForwardDiff(), AutoForwardDiff(; chunksize=100)],
16-
default_scenarios(; include_constantified=true);
16+
default_scenarios(; include_smaller=true, include_constantified=true);
1717
logging=LOGGING,
1818
)
1919

0 commit comments

Comments
 (0)