-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest.jl
More file actions
95 lines (82 loc) · 3.03 KB
/
test.jl
File metadata and controls
95 lines (82 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using DifferentiationInterface, DifferentiationInterfaceTest
using DifferentiationInterface:
AutoSimpleFiniteDiff, AutoReverseFromPrimitive, DenseSparsityDetector
using SparseMatrixColorings
using Test
LOGGING = get(ENV, "CI", "false") == "false"
backends = [ #
AutoSimpleFiniteDiff(; chunksize=5),
AutoReverseFromPrimitive(AutoSimpleFiniteDiff(; chunksize=4)),
]
second_order_backends = [ #
SecondOrder(
AutoSimpleFiniteDiff(; chunksize=5),
AutoReverseFromPrimitive(AutoSimpleFiniteDiff(; chunksize=4)),
),
SecondOrder(
AutoReverseFromPrimitive(AutoSimpleFiniteDiff(; chunksize=5)),
AutoSimpleFiniteDiff(; chunksize=4),
),
]
adaptive_backends = [ #
AutoSimpleFiniteDiff(),
AutoReverseFromPrimitive(AutoSimpleFiniteDiff()),
SecondOrder(AutoSimpleFiniteDiff(), AutoReverseFromPrimitive(AutoSimpleFiniteDiff())),
SecondOrder(AutoReverseFromPrimitive(AutoSimpleFiniteDiff()), AutoSimpleFiniteDiff()),
]
for backend in vcat(backends, second_order_backends)
@test check_available(backend)
@test check_inplace(backend)
end
## Dense scenarios
@testset "Dense" begin
test_differentiation(
vcat(backends, second_order_backends),
default_scenarios(; include_constantified=true);
logging=LOGGING,
)
test_differentiation(backends, complex_scenarios(); logging=LOGGING)
end
@testset "Sparse" begin
test_differentiation(
MyAutoSparse.(adaptive_backends),
default_scenarios(; include_constantified=true);
logging=LOGGING,
)
test_differentiation(
MyAutoSparse.(
vcat(adaptive_backends, MixedMode(adaptive_backends[1], adaptive_backends[2]))
),
sparse_scenarios(; include_constantified=true, include_cachified=true);
sparsity=true,
logging=LOGGING,
)
@testset "Complex numbers" begin
test_differentiation(
AutoSparse.(
vcat(
adaptive_backends, MixedMode(adaptive_backends[1], adaptive_backends[2])
);
sparsity_detector=DenseSparsityDetector(AutoSimpleFiniteDiff(); atol=1e-5),
coloring_algorithm=GreedyColoringAlgorithm(),
),
complex_sparse_scenarios();
logging=LOGGING,
)
end
@testset "SparseMatrixColorings access" begin
jac_for_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[1]), rand(10))
jac_rev_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[2]), rand(10))
hess_prep = prepare_hessian(
x -> sum(abs2, x), MyAutoSparse(adaptive_backends[1]), rand(10)
)
@test all(==(1), column_colors(jac_for_prep))
@test all(==(1), row_colors(jac_rev_prep))
@test all(==(1), column_colors(hess_prep))
@test ncolors(jac_for_prep) == 1
@test ncolors(hess_prep) == 1
@test only(column_groups(jac_for_prep)) == 1:10
@test only(row_groups(jac_rev_prep)) == 1:10
@test only(column_groups(hess_prep)) == 1:10
end
end