Skip to content

Commit d99bf59

Browse files
committed
move dense over
1 parent aa8f158 commit d99bf59

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

test/rulesets/LinearAlgebra/dense.jl

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
end
2525
end
2626

27-
@testset "cross"
27+
@testset "cross" begin
2828
test_frule(cross, randn(3), randn(3))
2929
test_frule(cross, randn(ComplexF64, 3), randn(ComplexF64, 3))
3030
test_rrule(cross, randn(3), randn(3))
@@ -47,28 +47,31 @@
4747
@test frule((Zero(), ẋ), pinv, x)[2] isa typeof(pinv(x))
4848
@test rrule(pinv, x)[2](Δy)[2] isa typeof(x)
4949
end
50-
#TODO Everything after this point
50+
5151
@testset "$F{Vector{$T}}" for T in (Float64, ComplexF64), F in (Transpose, Adjoint)
52+
test_frule(pinv, F(randn(T, 3)) F(randn(T, 3)))
53+
test_rrule(pinv, F(randn(T, 3)))
54+
55+
# Check types.
56+
# TODO: Do we need this still?
5257
x, ẋ, x̄ = F(randn(T, 3)), F(randn(T, 3)), F(randn(T, 3))
5358
y = pinv(x)
5459
Δy = copyto!(similar(y), randn(T, 3))
55-
test_frule(pinv, (x, ẋ))
60+
5661
y_fwd, ∂y_fwd = frule((Zero(), ẋ), pinv, x)
5762
@test y_fwd isa typeof(y)
5863
@test ∂y_fwd isa typeof(y)
59-
test_rrule(pinv, Δy, (x, x̄))
64+
6065
y_rev, back = rrule(pinv, x)
6166
@test y_rev isa typeof(y)
6267
@test back(Δy)[2] isa typeof(x)
6368
end
64-
@testset "Matrix{$T} with size ($m,$3)" for T in (Float64, ComplexF64),
69+
@testset "Matrix{$T} with size ($m,$n)" for T in (Float64, ComplexF64),
6570
m in 1:3,
66-
3 in 1:3
71+
n in 1:3
6772

68-
X, Ẋ, X̄ = randn(T, m, 3), randn(T, m, 3), randn(T, m, 3)
69-
ΔY = randn(T, size(pinv(X))...)
70-
test_frule(pinv, (X, Ẋ))
71-
test_rrule(pinv, ΔY, (X, X̄))
73+
test_frule(pinv, randn(T, m, n))
74+
test_rrule(pinv, randn(T, m, n))
7275
end
7376
end
7477
@testset "$f" for f in (det, logdet)
@@ -77,27 +80,26 @@
7780
test_scalar(f, b)
7881
end
7982
@testset "$f(::Matrix{$T})" for T in (Float64, ComplexF64)
83+
B = generate_well_conditioned_matrix(T, 4)
8084
if f === logdet && float(T) <: Float32
81-
kwargs = (atol=1e-5, rtol=1e-5)
85+
test_frule(f, B; atol=1e-5, rtol=1e-5)
86+
test_rrule(f, B; atol=1e-5, rtol=1e-5)
8287
else
83-
kwargs = NamedTuple()
88+
test_frule(f, B)
89+
test_rrule(f, B)
8490
end
85-
B = generate_well_conditioned_matrix(T, 4)
86-
test_frule(f, (B, randn(T, 4, 4)); kwargs...)
87-
test_rrule(f, randn(T), (B, randn(T, 4, 4)); kwargs...)
8891
end
8992
end
9093
@testset "logabsdet(::Matrix{$T})" for T in (Float64, ComplexF64)
9194
B = randn(T, 4, 4)
92-
test_frule(logabsdet, (B, randn(T, 4, 4)))
93-
test_rrule(logabsdet, (randn(), randn(T)), (B, randn(T, 4, 4)))
95+
test_frule(logabsdet, B)
96+
test_rrule(logabsdet, B)
9497
# test for opposite sign of determinant
95-
test_frule(logabsdet, (-B, randn(T, 4, 4)))
96-
test_rrule(logabsdet, (randn(), randn(T)), (-B, randn(T, 4, 4)))
98+
test_frule(logabsdet, -B)
99+
test_rrule(logabsdet, -B)
97100
end
98101
@testset "tr" begin
99-
test_frule(tr, (randn(4, 4), randn(4, 4)))
100-
test_rrule(tr, randn(), (randn(4, 4), randn(4, 4)))
102+
test_frule(tr, randn(4, 4))
103+
test_rrule(tr, randn(4, 4))
101104
end
102-
==#
103105
end

0 commit comments

Comments
 (0)