Skip to content

Commit

Permalink
try to find out where we are
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Apr 29, 2021
1 parent 6294622 commit ae62bc0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/rulesets/LinearAlgebra/norm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
),
T in (Float64, ComplexF64),
sz in [(3,), (3, 3), (3, 2, 1)]
println("starting unexported fnorm=$fnorm, T=$T, sz=$sz")

x = randn(T, sz)
# finite differences is unstable if maxabs (minabs) values are not well
Expand Down Expand Up @@ -37,6 +38,7 @@
@test rrule(fnorm, x)[2](Zero())[2] isa Zero
end
ndims(x) > 1 && @testset "non-strided" begin
println("... non-strided")
xp = if x isa Matrix
view(x, [1,2,3], 1:3)
elseif x isa Array{T,3}
Expand All @@ -51,6 +53,7 @@
rrule_test(fnorm, ȳ, (xp, x̄))
end
T == Float64 && ndims(x) == 1 && @testset "Integer input" begin
println("... integer")
x = [1,2,3]
int_fwd, int_back = rrule(fnorm, x)
float_fwd, float_back = rrule(fnorm, float(x))
Expand All @@ -61,6 +64,7 @@
@testset "norm(x::Array{$T,$(length(sz))})" for
T in (Float64, ComplexF64),
sz in [(0,), (3,), (3, 3), (3, 2, 1)]
println("starting exported norm T=$T, sz=$sz")

x = randn(T, sz)

Expand All @@ -84,6 +88,7 @@
@test rrule(norm, x)[2](Zero())[2] isa Zero
end
ndims(x) > 1 && @testset "non-strided" begin
println("... non-strided'")
xp = if x isa Matrix
view(x, [1,2,3], 1:3)
elseif x isa Array{T,3}
Expand All @@ -103,6 +108,7 @@
p in (1.0, 2.0, Inf, -Inf, 2.5),
T in (Float64, ComplexF64),
sz in (fnorm === norm ? [(0,), (3,), (3, 3), (3, 2, 1)] : [(3,), (3, 3), (3, 2, 1)])
println("starting p-norm p=$p, T=$T, sz=$sz")

x = randn(T, sz)
# finite differences is unstable if maxabs (minabs) values are not well
Expand Down Expand Up @@ -142,6 +148,7 @@
@test unthunk(unthunk(int_back(1.0)[2])) unthunk(unthunk(float_back(1.0)[2]))
end
end
println("starting adjoint/transpose norm T=$T")
@testset "norm($fdual(::Vector{$T}), p)" for
T in (Float64, ComplexF64),
fdual in (adjoint, transpose)
Expand All @@ -155,13 +162,15 @@
end
@testset "norm(x::$T, p)" for T in (Float64, ComplexF64)
@testset "p = $p" for p in (-1.0, 2.0, 2.5)
println("starting the other set of p-norm tests, p=$p, T=$T, sz=$sz")
test_frule(norm, randn(T), p)
test_rrule(norm, randn(T), p)

_, back = rrule(norm, randn(T), p)
@test back(Zero()) == (NO_FIELDS, Zero(), Zero())
end
@testset "p = 0" begin
println("starting 0-norm tests, T=$T, sz=$sz")
p = 0.0
x = randn(T)
y = norm(x, p)
Expand Down

0 comments on commit ae62bc0

Please sign in to comment.