Skip to content

Commit 7c84d82

Browse files
committed
fix two bugs
1 parent cfe3a81 commit 7c84d82

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/projection.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ end
179179

180180
# For arrays of numbers, just store one projector:
181181
function ProjectTo(x::AbstractArray{T}) where {T<:Number}
182-
element = ProjectTo(zero(T))
182+
element = T <: Irrational ? ProjectTo{Real}() : ProjectTo(zero(T))
183183
if element isa ProjectTo{<:AbstractZero}
184184
return ProjectTo{NoTangent}() # short-circuit if all elements project to zero
185185
else
@@ -199,7 +199,11 @@ function ProjectTo(xs::AbstractArray)
199199
end
200200

201201
function (project::ProjectTo{AbstractArray})(dx::AbstractArray{S,M}) where {S,M}
202-
# First deal with shape. The rule is that we reshape to add or remove trivial dimensions
202+
# Trivial case:
203+
if all(el -> el isa AbstractZero, dx)
204+
return NoTangent()
205+
end
206+
# Now deal with shape. The rule is that we reshape to add or remove trivial dimensions
203207
# like dx = ones(4,1), where x = ones(4), but throw an error on dx = ones(1,4) etc.
204208
dy = if axes(dx) == project.axes
205209
dx

test/projection.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
6969
@test prow(transpose([1, 2, 3 + 4.0im])) isa Matrix # row vectors may not pass through
7070
@test prow(adjoint([1, 2, 3 + 5im])) == [1 2 3 - 5im]
7171
@test prow(adjoint([1, 2, 3])) isa Matrix
72+
73+
# some bugs
74+
@test pvec3(fill(NoTangent(), 3)) === NoTangent() #410, was an array of such
75+
@test pvec3(Any[NoTangent(), NoTangent(), NoTangent()]) === NoTangent()
76+
@test ProjectTo([pi])([1]) isa Vector{Int} #423, was Irrational -> Bool -> NoTangent
7277
end
7378

7479
@testset "Base: arrays of arrays, etc" begin

0 commit comments

Comments
 (0)