Skip to content

Commit 859259a

Browse files
committed
Remove 'evaluate' calls that are now superfluous
1 parent 71b82b3 commit 859259a

3 files changed

Lines changed: 41 additions & 48 deletions

File tree

test/ForwardTest.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,7 @@ end
706706

707707
expected = dc.BinaryOperation{dc.Mult}(Variable("y", Lower(1)), Variable("x", Lower(1)))
708708

709-
# TODO: simplify should be sufficient here - remove evaluate
710-
@test equivalent(
711-
dc.simplify(dc.evaluate(dc.diff(e, Variable("z", Upper(9))))),
712-
expected,
713-
)
709+
@test equivalent(dc.simplify(dc.diff(e, Variable("z", Upper(9)))), expected)
714710

715711
expected = dc.BinaryOperation{dc.Mult}(Variable("y", Upper(1)), Variable("x", Upper(1)))
716712
@test equivalent(dc.simplify(dc.diff(e, Variable("z", Upper(9)))'), expected)

test/RicciTest.jl

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ using DiffMatic
66
using Test
77

88
using DiffMatic: Variable, Literal, KrD, Zero
9-
using DiffMatic: evaluate
109
using DiffMatic: Upper, Lower
1110

1211
dc = DiffMatic
@@ -273,10 +272,10 @@ end
273272
A = Variable("A", Upper(1), Lower(2))
274273
B = Variable("B", Upper(1), Lower(2))
275274

276-
p1 = dc.evaluate(A * B)
277-
p2 = dc.evaluate(A' * B)
278-
p3 = dc.evaluate(A * B')
279-
p4 = dc.evaluate(A' * B')
275+
p1 = A * B
276+
p2 = A' * B
277+
p3 = A * B'
278+
p4 = A' * B'
280279

281280
@test length(dc.get_free_indices(p1)) == 2
282281
@test p1.arg1.indices[2].letter == p1.arg2.indices[1].letter
@@ -355,20 +354,20 @@ end
355354
op1 = A .* A
356355

357356
@test typeof(op1) == dc.BinaryOperation{dc.Mult}
358-
@test equivalent(evaluate(op1.arg1), Variable("A", Upper(1), Lower(2)))
359-
@test equivalent(evaluate(op1.arg2), Variable("A", Upper(1), Lower(2)))
357+
@test equivalent(op1.arg1, Variable("A", Upper(1), Lower(2)))
358+
@test equivalent(op1.arg2, Variable("A", Upper(1), Lower(2)))
360359

361360
op2 = A .* B
362361

363362
@test typeof(op2) == dc.BinaryOperation{dc.Mult}
364-
@test equivalent(evaluate(op2.arg1), Variable("A", Upper(3), Lower(4)))
365-
@test equivalent(evaluate(op2.arg2), Variable("B", Upper(3), Lower(4)))
363+
@test equivalent(op2.arg1, Variable("A", Upper(3), Lower(4)))
364+
@test equivalent(op2.arg2, Variable("B", Upper(3), Lower(4)))
366365

367366
op3 = A' .* B'
368367

369368
@test typeof(op3) == dc.BinaryOperation{dc.Mult}
370-
@test equivalent(evaluate(op3.arg1), Variable("A", Lower(1), Upper(2)))
371-
@test equivalent(evaluate(op3.arg2), Variable("B", Lower(3), Upper(4)))
369+
@test equivalent(op3.arg1, Variable("A", Lower(1), Upper(2)))
370+
@test equivalent(op3.arg2, Variable("B", Lower(3), Upper(4)))
372371
end
373372

374373
@testset "elementwise multiplication vector-vector" begin
@@ -378,20 +377,20 @@ end
378377
op1 = x .* x
379378

380379
@test typeof(op1) == dc.BinaryOperation{dc.Mult}
381-
@test equivalent(evaluate(op1.arg1), Variable("x", Upper(1)))
382-
@test equivalent(evaluate(op1.arg2), Variable("x", Upper(1)))
380+
@test equivalent(op1.arg1, Variable("x", Upper(1)))
381+
@test equivalent(op1.arg2, Variable("x", Upper(1)))
383382

384383
op2 = x .* y
385384

386385
@test typeof(op2) == dc.BinaryOperation{dc.Mult}
387-
@test equivalent(evaluate(op2.arg1), Variable("x", Upper(2)))
388-
@test equivalent(evaluate(op2.arg2), Variable("y", Upper(2)))
386+
@test equivalent(op2.arg1, Variable("x", Upper(2)))
387+
@test equivalent(op2.arg2, Variable("y", Upper(2)))
389388

390389
op3 = x' .* y'
391390

392391
@test typeof(op3) == dc.BinaryOperation{dc.Mult}
393-
@test equivalent(evaluate(op3.arg1), Variable("x", Lower(2)))
394-
@test equivalent(evaluate(op3.arg2), Variable("y", Lower(2)))
392+
@test equivalent(op3.arg1, Variable("x", Lower(2)))
393+
@test equivalent(op3.arg2, Variable("y", Lower(2)))
395394
end
396395

397396
@testset "elementwise multiplication with ambiguous input fails" begin
@@ -439,22 +438,22 @@ end
439438
x = Variable("x", Upper(1))
440439
y = Variable("y", Lower(1))
441440

442-
@test equivalent(evaluate(x'), Variable("x", Lower(1)))
443-
@test equivalent(evaluate(y'), Variable("y", Upper(1)))
441+
@test equivalent(x', Variable("x", Lower(1)))
442+
@test equivalent(y', Variable("y", Upper(1)))
444443
end
445444

446445
@testset "transpose KrD" begin
447446
d = KrD(Upper(1), Lower(2))
448447

449-
@test equivalent(evaluate(d'), KrD(Lower(1), Upper(2)))
448+
@test equivalent(d', KrD(Lower(1), Upper(2)))
450449
end
451450

452451
@testset "combined update_index and transpose vector" begin
453452
x = Variable("x", Upper(2))
454453

455454
xt = x'
456455
x_indices = dc.get_free_indices(xt)
457-
updated_transpose = evaluate(dc.update_index(xt, x_indices[1], Lower(1)))
456+
updated_transpose = dc.update_index(xt, x_indices[1], Lower(1))
458457

459458
@test equivalent(updated_transpose, Variable("x", Lower(1)))
460459
end
@@ -491,17 +490,16 @@ end
491490
@testset "transpose matrix" begin
492491
A = Variable("A", Upper(1), Lower(2))
493492

494-
At = evaluate(A')
495-
@test equivalent(At, Variable("A", Lower(1), Upper(2)))
493+
@test equivalent(A', Variable("A", Lower(1), Upper(2)))
496494
end
497495

498496
@testset "transpose BinaryOperation{dc.Mult}" begin
499497
A = Variable("A", Upper(1), Lower(2))
500498
x = Variable("x", Upper(2))
501499

502-
op_t = evaluate((A * x)')
500+
op_t = (A * x)'
503501
@test equivalent(
504-
evaluate(op_t),
502+
op_t,
505503
dc.BinaryOperation{dc.Mult}(
506504
Variable("A", Lower(1), Lower(2)),
507505
Variable("x", Upper(2)),
@@ -534,7 +532,7 @@ end
534532
B = Variable("B", Upper(2), Lower(3))
535533

536534
@test equivalent(
537-
evaluate(A + B),
535+
A + B,
538536
dc.BinaryOperation{dc.Add}(
539537
Variable("A", Upper(1), Lower(2)),
540538
Variable("B", Upper(1), Lower(2)),
@@ -552,7 +550,7 @@ end
552550

553551
for op (+, -)
554552
for args ((x, y), (A, B))
555-
e = evaluate((op(args[1], args[2])))
553+
e = op(args[1], args[2])
556554
@test e.arg1.indices == e.arg2.indices
557555
end
558556
end
@@ -565,7 +563,7 @@ end
565563

566564
for op (+, -)
567565
for ags ((x, y), (x, z))
568-
op_t = evaluate((op(x, y))')
566+
op_t = op(x, y)'
569567
@test op_t.arg1.indices == op_t.arg2.indices
570568
end
571569
end

test/StdTest.jl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ using DiffMatic
55
using Test
66

77
using DiffMatic: Variable, KrD, Zero
8-
using DiffMatic: evaluate
98
using DiffMatic: Upper, Lower
109

1110
dc = DiffMatic
@@ -64,7 +63,7 @@ end
6463
b = Variable("b")
6564

6665
function mult(l, r)
67-
return evaluate(dc.BinaryOperation{dc.Mult}(l, r))
66+
return dc.BinaryOperation{dc.Mult}(l, r)
6867
end
6968

7069
@test to_std(mult(A, a)) == "aA"
@@ -87,7 +86,7 @@ end
8786
yt = Variable("y", Lower(1))
8887

8988
function contract(l, r)
90-
return evaluate(dc.BinaryOperation{dc.Mult}(l, r))
89+
return dc.BinaryOperation{dc.Mult}(l, r)
9190
end
9291

9392
@test to_std(contract(A, x)) == "Ax"
@@ -141,7 +140,7 @@ end
141140
y = Variable("y", Upper(1))
142141

143142
function contract(l, r)
144-
return evaluate(dc.BinaryOperation{dc.Mult}(l, r))
143+
return dc.BinaryOperation{dc.Mult}(l, r)
145144
end
146145

147146
@test to_std(contract(A, x)) == "xᵀAᵀ"
@@ -156,7 +155,7 @@ end
156155
y = Variable("y", Lower(1))
157156

158157
function contract(l, r)
159-
return evaluate(dc.BinaryOperation{dc.Mult}(l, r))
158+
return dc.BinaryOperation{dc.Mult}(l, r)
160159
end
161160

162161
@test to_std(contract(A, x)) == "Ax"
@@ -172,7 +171,7 @@ end
172171
D = Variable("D", Lower(3), Upper(2))
173172

174173
function contract(l, r)
175-
return evaluate(dc.BinaryOperation{dc.Mult}(l, r))
174+
return dc.BinaryOperation{dc.Mult}(l, r)
176175
end
177176

178177
@test to_std(contract(A, B)) == "AB"
@@ -191,10 +190,10 @@ end
191190

192191
@test to_std(A .* B) == "A ⊙ B"
193192
@test to_std(A .* A) == "A ⊙ A"
194-
@test to_std(dc.evaluate(A * (A .* B))) == "A(A ⊙ B)"
195-
@test to_std(dc.evaluate((A .* B) * A)) == "(A ⊙ B)A"
196-
@test to_std(dc.evaluate(A .* (A * B))) == "AB ⊙ A"
197-
@test to_std(dc.evaluate((A * B) .* A)) == "AB ⊙ A"
193+
@test to_std(A * (A .* B)) == "A(A ⊙ B)"
194+
@test to_std((A .* B) * A) == "(A ⊙ B)A"
195+
@test to_std(A .* (A * B)) == "AB ⊙ A"
196+
@test to_std((A * B) .* A) == "AB ⊙ A"
198197
end
199198

200199
@testset "to_std output is correct with matrix-matrix sum" begin
@@ -203,7 +202,7 @@ end
203202
C = Variable("C", Lower(2), Upper(1))
204203

205204
function sum(l, r)
206-
return evaluate(dc.BinaryOperation{dc.Add}(l, r))
205+
return dc.BinaryOperation{dc.Add}(l, r)
207206
end
208207

209208
@test to_std(sum(A, B)) == "A + B"
@@ -324,16 +323,16 @@ end
324323
y = Variable("y", Upper(2))
325324
a = Variable("a")
326325

327-
@test to_std(evaluate(a * sin.(x)' * y)) == "asin(xᵀ)y"
328-
@test to_std(evaluate(sin.(x)' * a * y)) == "asin(xᵀ)y"
329-
@test to_std(evaluate(sin.(x)' * y * a)) == "asin(xᵀ)y"
326+
@test to_std(a * sin.(x)' * y) == "asin(xᵀ)y"
327+
@test to_std(sin.(x)' * a * y) == "asin(xᵀ)y"
328+
@test to_std(sin.(x)' * y * a) == "asin(xᵀ)y"
330329
end
331330

332331
@testset "derivative interface checks" begin
333332
@matrix A
334333
@vector x
335334

336-
@test equivalent(derivative(x' * A * x, A), evaluate(x * x')) # scalar input works
335+
@test equivalent(derivative(x' * A * x, A), x * x') # scalar input works
337336
@test equivalent(derivative(A * x, x), A) # vector input works
338337
end
339338

0 commit comments

Comments
 (0)