Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 72bcc2d

Browse files
committed
clarified tests for VecJacProducts
1 parent f05a7a5 commit 72bcc2d

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

test/test_vecjac_products.jl

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,33 @@ f = WrapFunc(_f, 1.0f0, 1.0f0)
3434

3535
L = VecJac(f, copy(x), 1.0f0, 1.0f0; autodiff = AutoZygote())
3636

37-
Jtrue = Zygote.jacobian(f, x)[1]
37+
Jx = Zygote.jacobian(f, x)[1]
38+
Jv = Zygote.jacobian(f, v)[1]
3839

39-
@test L * x Jtrue' * x
40-
y=zero(x); @test mul!(y, L, v) Jtrue' * v
41-
@test L(x, 1.0f0, 1.0f0) Jtrue' * x
42-
y=zero(x); @test L(y, x, 1.0f0, 1.0f0) Jtrue' * x
40+
@test L * x Jx' * x
41+
@test L * v Jx' * v
42+
y=zero(x); @test mul!(y, L, v) Jx' * v
43+
y=zero(x); @test mul!(y, L, v) Jx' * v
4344

44-
@test L * v Jtrue' * v
45-
y=zero(x); @test mul!(y, L, v) Jtrue' * v
46-
# @test L(v, 1.0f0, 1.0f0) ≈ Jtrue' * v
47-
# y=zero(v); @test L(y, v, 1.0f0, 1.0f0) ≈ Jtrue' * v
45+
@test L(x, 1.0f0, 1.0f0) Jx' * x
46+
y=zero(x); @test L(y, x, 1.0f0, 1.0f0) Jx' * x
47+
@test L(v, 1.0f0, 1.0f0) Jv' * v
48+
y=zero(v); @test L(y, v, 1.0f0, 1.0f0) Jv' * v
4849

4950
update_coefficients!(L, v, 3.0, 4.0)
50-
Jtrue = Zygote.jacobian(f, v)[1]
51-
@test mul!(y, L, x) Jtrue' * x
52-
_y=copy(y); @test mul!(y, L, x, a, b) a * Jtrue' * x + b * _y;
5351

54-
update_coefficients!(f, v, 5.0, 6.0)
55-
Jtrue = Zygote.jacobian(f, v)[1]
56-
y=zero(x); @test L(y, v, 5.0, 6.0) Jtrue' * v
52+
Jx = Zygote.jacobian(f, x)[1]
53+
Jv = Zygote.jacobian(f, v)[1]
54+
55+
@test L * x Jv' * x
56+
@test L * v Jv' * v
57+
y=zero(x); @test mul!(y, L, v) Jv' * v
58+
y=zero(x); @test mul!(y, L, v) Jv' * v
59+
60+
@test L(x, 3.0f0, 4.0f0) Jx' * x
61+
y=zero(x); @test L(y, x, 3.0f0, 4.0f0) Jx' * x
62+
@test L(v, 3.0f0, 4.0f0) Jv' * v
63+
y=zero(v); @test L(y, v, 3.0f0, 4.0f0) Jv' * v
5764

5865
@info "VecJac AutoFiniteDiff"
5966

@@ -74,18 +81,21 @@ update_coefficients!(f, v, 5.0, 6.0)
7481
@test x x0
7582
@test v v0
7683

84+
@info "Base.resize!"
85+
7786
# Resize test
7887
f2(x) = 2x
7988
f2(y, x) = (copy!(y, x); lmul!(2, y); y)
8089

8190
for M in (100, 400)
8291
local L = VecJac(f2, copy(x), 1.0f0, 1.0f0; autodiff = AutoZygote())
8392
resize!(L, M)
93+
8494
_x = resize!(copy(x), M)
8595
_u = rand(M)
86-
8796
J2 = Zygote.jacobian(f2, _x)[1]
8897

98+
update_coefficients!(L, _x, 1.0f0, 1.0f0)
8999
@test L * _u J2' * _u rtol=1e-6
90100
_v = zeros(M); @test mul!(_v, L, _u) J2' * _u rtol=1e-6
91101
end

0 commit comments

Comments
 (0)