@@ -28,8 +28,10 @@ println("starting unexported fnorm=$fnorm, T=$T, sz=$sz")
28
28
kwargs = NamedTuple ()
29
29
end
30
30
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
33
35
end
34
36
@testset " rrule" begin
35
37
test_rrule (fnorm, x; kwargs... )
@@ -49,12 +51,37 @@ println("... non-strided")
49
51
PermutedDimsArray (x, (1 ,2 ,3 ))
50
52
end
51
53
@test ! (xp isa StridedArray)
52
- y = fnorm (x)
53
- # ẋ = rand(T, size(xp)) # rand_tangent(xp)
54
- x̄ = 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
+
58
85
end
59
86
T == Float64 && ndims (x) == 1 && @testset " Integer input" begin
60
87
println (" ... integer" )
@@ -101,12 +128,14 @@ println("... non-strided'")
101
128
PermutedDimsArray (x, (1 ,2 ,3 ))
102
129
end
103
130
@test ! (xp isa StridedArray)
104
- y = norm (x)
105
- ẋ = rand (T, size (xp)) # rand_tangent(xp)
106
- x̄ = 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
110
139
end
111
140
end
112
141
@testset " $fnorm (x::Array{$T ,$(length (sz)) }, $p ) with size $sz " for
0 commit comments