Skip to content

Commit 34c9d0d

Browse files
committed
Fix broadcast with RowVectors of matrices
Fix #20979. Amusingly, this bug is a direct of `transpose` being recursive.
1 parent 0e970f0 commit 34c9d0d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

base/linalg/rowvector.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ end
144144
@inline to_vec(x::Number) = x
145145
@inline to_vecs(rowvecs...) = (map(to_vec, rowvecs)...)
146146

147-
# map
148-
@inline map(f, rowvecs::RowVector...) = RowVector(map(f, to_vecs(rowvecs...)...))
147+
# map: Preserve the RowVector, but note that `f` expects transposed elements
148+
@inline map(f, rowvecs::RowVector...) = RowVector(map(transposeftranspose, to_vecs(rowvecs...)...))
149149

150150
# broacast (other combinations default to higher-dimensional array)
151151
@inline broadcast(f, rowvecs::Union{Number,RowVector}...) =
152-
RowVector(broadcast(f, to_vecs(rowvecs...)...))
152+
RowVector(broadcast(transposeftranspose, to_vecs(rowvecs...)...))
153153

154154
# Horizontal concatenation #
155155

test/linalg/rowvector.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,13 @@ end
249249
@test A'*x' == A'*y == B*x' == B*y == C'
250250
end
251251
end
252+
253+
@testset "issue #20979" begin
254+
f20979(z::Complex) = [z.re -z.im; z.im z.re]
255+
v = [1+2im]'
256+
@test (f20979.(v))[1] == f20979(v[1])
257+
@test f20979.(v) == f20979.(collect(v))
258+
259+
w = rand(Complex128, 3)
260+
@test f20979.(v') == f20979.(collect(v')) == (f20979.(v))'
261+
end

0 commit comments

Comments
 (0)