Skip to content

Commit a8ac988

Browse files
committed
row vector non-diff shortcuts
1 parent 9ad5f44 commit a8ac988

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/projection.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ end
270270
# Row vectors
271271
function ProjectTo(x::LinearAlgebra.AdjointAbsVec)
272272
sub = ProjectTo(parent(x))
273+
sub isa ProjectTo{<:AbstractZero} && return sub
273274
return ProjectTo{Adjoint}(; parent=sub)
274275
end
275276
# Note that while [1 2; 3 4]' isa Adjoint, we use ProjectTo{Adjoint} only to encode AdjointAbsVec.
@@ -288,6 +289,7 @@ end
288289

289290
function ProjectTo(x::LinearAlgebra.TransposeAbsVec)
290291
sub = ProjectTo(parent(x))
292+
sub isa ProjectTo{<:AbstractZero} && return sub
291293
return ProjectTo{Transpose}(; parent=sub)
292294
end
293295
function (project::ProjectTo{Transpose})(dx::LinearAlgebra.AdjOrTransAbsVec)

test/projection.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
125125
@test_throws DimensionMismatch prefvec(Ref{Any}(1:5))
126126

127127
@test ProjectTo(Ref(true)) isa ProjectTo{NoTangent}
128-
@test_broken ProjectTo(Ref([false]')) isa ProjectTo{NoTangent}
128+
@test ProjectTo(Ref([false]')) isa ProjectTo{NoTangent}
129129
end
130130

131131
#####
@@ -172,6 +172,9 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
172172

173173
# issue #410
174174
@test padj([NoTangent() NoTangent() NoTangent()]) === NoTangent()
175+
176+
@test ProjectTo(adj([true, false]))([1 2]) isa AbstractZero
177+
@test ProjectTo(adj([[true], [false]])) isa ProjectTo{<:AbstractZero}
175178
end
176179

177180
@testset "LinearAlgebra: dense structured matrices" begin

0 commit comments

Comments
 (0)