Skip to content

Commit 0331eda

Browse files
committed
update notation
1 parent 43a2756 commit 0331eda

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

test/rulesets/LinearAlgebra/norm.jl

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ println("starting unexported fnorm=$fnorm, T=$T, sz=$sz")
2828
kwargs = NamedTuple()
2929
end
3030

31-
fnorm === LinearAlgebra.norm2 && @testset "frule" begin
32-
test_frule(fnorm, x)
31+
if fnorm === LinearAlgebra.norm2
32+
@testset "frule" begin
33+
test_frule(fnorm, x)
34+
end
3335
end
3436
@testset "rrule" begin
3537
test_rrule(fnorm, x; kwargs...)
@@ -49,12 +51,37 @@ println("... non-strided")
4951
PermutedDimsArray(x, (1,2,3))
5052
end
5153
@test !(xp isa StridedArray)
52-
y = fnorm(x)
53-
# ẋ = rand(T, size(xp)) # rand_tangent(xp)
54-
= rand(T, size(xp)) # rand_tangent(xp)
55-
= rand_tangent(y)
56-
# frule_test(fnorm, (xp, ẋ))
57-
rrule_test(fnorm, ȳ, (xp, x̄))
54+
# y = fnorm(x)
55+
# # ẋ = rand(T, size(xp)) # rand_tangent(xp)
56+
# x̄ = rand(T, size(xp)) # rand_tangent(xp)
57+
# ȳ = rand_tangent(y)
58+
# # frule_test(fnorm, (xp, ẋ))
59+
# rrule_test(fnorm, ȳ, (xp, x̄)) # old notation, gives a depwarn
60+
#=
61+
┌ Warning: `rrule_test(f, ȳ, inputs::Tuple{Any, Any}...; kwargs...)` is deprecated, use `test_rrule(f, (x ⊢ dx for (x, dx) = inputs)...; output_tangent = ȳ, kwargs...)` instead.
62+
│ caller = macro expansion at norm.jl:57 [inlined]
63+
└ @ Core ~/.julia/dev/ChainRules/test/rulesets/LinearAlgebra/norm.jl:57
64+
=#
65+
# @show typeof(xp)
66+
# test_rrule(fnorm, xp) # new notation, gives a spectacular failure:
67+
#=
68+
typeof(xp) = SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}
69+
test_rrule: norm1 at ([0.2972879845354616 -0.01044524463737564 2.2950878238373105; 0.3823959677906078 -0.839026854388764 -2.2670863488005306; -0.5976344767282311 0.31111133849833383 0.5299655761667461],): Error During Test at /Users/me/.julia/packages/ChainRulesTestUtils/bDd51/src/testers.jl:168
70+
Got exception outside of a @test
71+
MethodError: no method matching +(::Composite{SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}, NamedTuple{(:parent, :indices, :offset1, :stride1), Tuple{Matrix{Float64}, Composite{Tuple{Vector{Int64}, UnitRange{Int64}}, Tuple{Vector{DoesNotExist}, Composite{UnitRange{Int64}, NamedTuple{(:start, :stop), Tuple{DoesNotExist, DoesNotExist}}}}}, DoesNotExist, DoesNotExist}}}, ::Matrix{Float64})
72+
Closest candidates are:
73+
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:560
74+
+(::Composite{P, T} where T, ::Composite{P, T} where T) where P at /Users/me/.julia/packages/ChainRulesCore/1qau5/src/differential_arithmetic.jl:167
75+
+(::Composite, ::AbstractThunk) at /Users/me/.julia/packages/ChainRulesCore/1qau5/src/differential_arithmetic.jl:161
76+
...
77+
Stacktrace:
78+
[1] +(a::Composite{SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}, NamedTuple{(:parent, :indices, :offset1, :stride1), Tuple{Matrix{Float64}, Composite{Tuple{Vector{Int64}, UnitRange{Int64}}, Tuple{Vector{DoesNotExist}, Composite{UnitRange{Int64}, NamedTuple{(:start, :stop), Tuple{DoesNotExist, DoesNotExist}}}}}, DoesNotExist, DoesNotExist}}}, b::InplaceableThunk{Thunk{ChainRules.var"#1798#1801"{Float64, SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}, Float64}}, ChainRules.var"#1799#1802"{Float64, SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}, Float64}})
79+
@ ChainRulesCore ~/.julia/packages/ChainRulesCore/1qau5/src/differential_arithmetic.jl:161
80+
[2] add!!(x::Composite{SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}, NamedTuple{(:parent, :indices, :offset1, :stride1), Tuple{Matrix{Float64}, Composite{Tuple{Vector{Int64}, UnitRange{Int64}}, Tuple{Vector{DoesNotExist}, Composite{UnitRange{Int64}, NamedTuple{(:start, :stop), Tuple{DoesNotExist, DoesNotExist}}}}}, DoesNotExist, DoesNotExist}}}, t::InplaceableThunk{Thunk{ChainRules.var"#1798#1801"{Float64, SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}, Float64}}, ChainRules.var"#1799#1802"{Float64, SubArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Int64}, UnitRange{Int64}}, false}, Float64}})
81+
@ ChainRulesCore ~/.julia/packages/ChainRulesCore/1qau5/src/accumulation.jl:23
82+
=#
83+
test_rrule(fnorm, xp rand(T, size(xp))) # ok, this passes!
84+
5885
end
5986
T == Float64 && ndims(x) == 1 && @testset "Integer input" begin
6087
println("... integer")
@@ -101,12 +128,14 @@ println("... non-strided'")
101128
PermutedDimsArray(x, (1,2,3))
102129
end
103130
@test !(xp isa StridedArray)
104-
y = norm(x)
105-
= rand(T, size(xp)) # rand_tangent(xp)
106-
= rand(T, size(xp)) # rand_tangent(xp)
107-
= rand_tangent(y)
108-
frule_test(norm, (xp, ẋ))
109-
rrule_test(norm, ȳ, (xp, x̄))
131+
# y = norm(x)
132+
# ẋ = rand(T, size(xp)) # rand_tangent(xp)
133+
# x̄ = rand(T, size(xp)) # rand_tangent(xp)
134+
# ȳ = rand_tangent(y)
135+
# frule_test(norm, (xp, ẋ))
136+
# rrule_test(norm, ȳ, (xp, x̄))
137+
test_frule(norm, xp rand(T, size(xp)))
138+
test_rrule(norm, xp rand(T, size(xp))) # rand_tangent does not work here
110139
end
111140
end
112141
@testset "$fnorm(x::Array{$T,$(length(sz))}, $p) with size $sz" for

0 commit comments

Comments
 (0)