Skip to content

Commit

Permalink
Fix broadcast with RowVectors of matrices
Browse files Browse the repository at this point in the history
Fix #20979. Amusingly, this bug is a direct of `transpose` being recursive.
  • Loading branch information
mbauman committed Mar 10, 2017
1 parent 0e970f0 commit 8284aff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ end
@inline to_vec(x::Number) = x
@inline to_vecs(rowvecs...) = (map(to_vec, rowvecs)...)

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

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

# Horizontal concatenation #

Expand Down
10 changes: 10 additions & 0 deletions test/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,13 @@ end
@test A'*x' == A'*y == B*x' == B*y == C'
end
end

@testset "issue #20979" begin
f20979(z::Complex) = [z.re -z.im; z.im z.re]
v = [1+2im]'
@test (f20979.(v))[1] == f20979(v[1])
@test f20979.(v) == f20979.(collect(v))

w = rand(Complex128, 3)
@test f20979.(v') == f20979.(collect(v')) == (f20979.(v))'
end

0 comments on commit 8284aff

Please sign in to comment.