4
4
# Use of this source code is governed by an MIT-style license that can be found
5
5
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
6
6
7
- module TestReverseAD
7
+ module TestArrayAD
8
8
9
9
using Test
10
10
import LinearAlgebra
11
11
import MathOptInterface as MOI
12
12
import SparseArrays
13
13
14
14
const Nonlinear = MOI. Nonlinear
15
- const ReverseAD = Nonlinear. ReverseAD
16
- const Coloring = ReverseAD . Coloring
15
+ const ArrayAD = Nonlinear. ArrayAD
16
+ const Coloring = ArrayAD . Coloring
17
17
18
18
function runtests ()
19
19
for name in names (@__MODULE__ ; all = true )
@@ -553,85 +553,85 @@ function test_linearity()
553
553
ex = Nonlinear. add_expression (model, input)
554
554
expr = model[ex]
555
555
adj = Nonlinear. adjacency_matrix (expr. nodes)
556
- nodes = ReverseAD . _replace_moi_variables (expr. nodes, variables)
557
- ret = ReverseAD . _classify_linearity (nodes, adj, ReverseAD . Linearity[])
556
+ nodes = ArrayAD . _replace_moi_variables (expr. nodes, variables)
557
+ ret = ArrayAD . _classify_linearity (nodes, adj, ArrayAD . Linearity[])
558
558
@test ret[1 ] == test_value
559
559
indexed_set = Coloring. IndexedSet (100 )
560
- edge_list = ReverseAD . _compute_hessian_sparsity (
560
+ edge_list = ArrayAD . _compute_hessian_sparsity (
561
561
nodes,
562
562
adj,
563
563
ret,
564
564
indexed_set,
565
565
Set{Tuple{Int,Int}}[],
566
566
Vector{Int}[],
567
567
)
568
- if ret[1 ] != ReverseAD . NONLINEAR
568
+ if ret[1 ] != ArrayAD . NONLINEAR
569
569
@test length (edge_list) == 0
570
570
elseif length (IJ) > 0
571
571
@test IJ == edge_list
572
572
end
573
573
if length (indices) > 0
574
574
empty! (indexed_set)
575
- ReverseAD . _compute_gradient_sparsity! (indexed_set, nodes)
575
+ ArrayAD . _compute_gradient_sparsity! (indexed_set, nodes)
576
576
ix = sort (collect (indexed_set))
577
577
@test indices == ix
578
578
end
579
579
return
580
580
end
581
581
_test_linearity (
582
582
:(sin ($ x^ 2 ) + cos ($ y * 4 ) - 2.0 ),
583
- ReverseAD . NONLINEAR,
583
+ ArrayAD . NONLINEAR,
584
584
Set ([(2 , 2 ), (1 , 1 )]),
585
585
[1 , 2 ],
586
586
)
587
- _test_linearity (:(3 * 4 * ($ x + $ y)), ReverseAD . LINEAR)
587
+ _test_linearity (:(3 * 4 * ($ x + $ y)), ArrayAD . LINEAR)
588
588
_test_linearity (
589
589
:($ z * $ y),
590
- ReverseAD . NONLINEAR,
590
+ ArrayAD . NONLINEAR,
591
591
Set ([(3 , 2 ), (3 , 3 ), (2 , 2 )]),
592
592
[2 , 3 ],
593
593
)
594
- _test_linearity (:(3 + 4 ), ReverseAD . CONSTANT)
595
- _test_linearity (:(sin (3 ) + $ x), ReverseAD . LINEAR)
594
+ _test_linearity (:(3 + 4 ), ArrayAD . CONSTANT)
595
+ _test_linearity (:(sin (3 ) + $ x), ArrayAD . LINEAR)
596
596
_test_linearity (
597
597
:(cos ($ z) * sin (3 ) + $ x),
598
- ReverseAD . NONLINEAR,
598
+ ArrayAD . NONLINEAR,
599
599
Set ([(3 , 3 )]),
600
600
[1 , 3 ],
601
601
)
602
- _test_linearity (:($ x - 3 * $ y), ReverseAD . LINEAR)
603
- _test_linearity (:(- $ x), ReverseAD . LINEAR)
604
- _test_linearity (:(+ $ x), ReverseAD . LINEAR)
602
+ _test_linearity (:($ x - 3 * $ y), ArrayAD . LINEAR)
603
+ _test_linearity (:(- $ x), ArrayAD . LINEAR)
604
+ _test_linearity (:(+ $ x), ArrayAD . LINEAR)
605
605
_test_linearity (
606
606
:($ x^ $ y),
607
- ReverseAD . NONLINEAR,
607
+ ArrayAD . NONLINEAR,
608
608
Set ([(2 , 2 ), (1 , 1 ), (2 , 1 )]),
609
609
[1 , 2 ],
610
610
)
611
- _test_linearity (:($ x / 3 + $ y), ReverseAD . LINEAR)
611
+ _test_linearity (:($ x / 3 + $ y), ArrayAD . LINEAR)
612
612
_test_linearity (
613
613
:(3 / ($ x * $ y)),
614
- ReverseAD . NONLINEAR,
614
+ ArrayAD . NONLINEAR,
615
615
Set ([(2 , 2 ), (1 , 1 ), (2 , 1 )]),
616
616
[1 , 2 ],
617
617
)
618
- _test_linearity (:(1 / ($ x + 3 )), ReverseAD . NONLINEAR, Set ([(1 , 1 )]), [1 ])
618
+ _test_linearity (:(1 / ($ x + 3 )), ArrayAD . NONLINEAR, Set ([(1 , 1 )]), [1 ])
619
619
_test_linearity (
620
620
:(ifelse ($ x <= 1 , $ x, $ y)),
621
- ReverseAD . PIECEWISE_LINEAR,
621
+ ArrayAD . PIECEWISE_LINEAR,
622
622
Set ([]),
623
623
[],
624
624
)
625
625
_test_linearity (
626
626
:(ifelse ($ x <= 1 , $ x^ 2 , $ y)),
627
- ReverseAD . NONLINEAR,
627
+ ArrayAD . NONLINEAR,
628
628
Set ([(1 , 1 )]),
629
629
[1 , 2 ],
630
630
)
631
- _test_linearity (:(ifelse (1 <= 1 , 2 , 3 )), ReverseAD . CONSTANT)
631
+ _test_linearity (:(ifelse (1 <= 1 , 2 , 3 )), ArrayAD . CONSTANT)
632
632
_test_linearity (
633
633
:(1 / ifelse ($ x < 1 , $ x, 0 )),
634
- ReverseAD . NONLINEAR,
634
+ ArrayAD . NONLINEAR,
635
635
Set ([(1 , 1 )]),
636
636
[1 ],
637
637
)
@@ -648,7 +648,7 @@ function test_linearity_no_hess()
648
648
# We initialized without the need for the hessian so
649
649
# the linearity shouldn't be computed.
650
650
@test only (evaluator. backend. subexpressions). linearity ==
651
- ReverseAD . NONLINEAR
651
+ ArrayAD . NONLINEAR
652
652
return
653
653
end
654
654
@@ -1247,7 +1247,7 @@ end
1247
1247
function test_unsafe_vector_view ()
1248
1248
x = Float64[]
1249
1249
GC. @preserve x begin
1250
- view = MOI. Nonlinear. ReverseAD . _UnsafeVectorView (x, 3 )
1250
+ view = MOI. Nonlinear. ArrayAD . _UnsafeVectorView (x, 3 )
1251
1251
@test length (x) == 3
1252
1252
view[2 ] = 1.0
1253
1253
@test x[2 ] == 1.0
@@ -1388,12 +1388,12 @@ end
1388
1388
function test_generate_hessian_slice_inner ()
1389
1389
# Test that it evaluates without error. The code contents are tested
1390
1390
# elsewhere.
1391
- MOI. Nonlinear. ReverseAD . _generate_hessian_slice_inner ()
1391
+ MOI. Nonlinear. ArrayAD . _generate_hessian_slice_inner ()
1392
1392
d = ex = nothing # These arguments are untyped and not needed for this test
1393
- for id in [0 , MOI. Nonlinear. ReverseAD . MAX_CHUNK + 1 ]
1393
+ for id in [0 , MOI. Nonlinear. ArrayAD . MAX_CHUNK + 1 ]
1394
1394
@test_throws (
1395
1395
ErrorException (" Invalid chunk size: $id " ),
1396
- MOI. Nonlinear. ReverseAD . _hessian_slice_inner (d, ex, id),
1396
+ MOI. Nonlinear. ArrayAD . _hessian_slice_inner (d, ex, id),
1397
1397
)
1398
1398
end
1399
1399
return
@@ -1423,4 +1423,4 @@ end
1423
1423
1424
1424
end # module
1425
1425
1426
- TestReverseAD . runtests ()
1426
+ TestArrayAD . runtests ()
0 commit comments