Skip to content

Commit 7f977ed

Browse files
committed
re-allow vector*(1-row matrix) and transpose (closes #20389)
1 parent ad5cd7b commit 7f977ed

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

base/linalg/matmul.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function (*){T,S}(A::AbstractMatrix{T}, x::AbstractVector{S})
8080
TS = promote_op(matprod, T, S)
8181
A_mul_B!(similar(x,TS,size(A,1)),A,x)
8282
end
83+
(*)(A::AbstractVector, B::AbstractMatrix) = reshape(A,length(A),1)*B
8384

8485
A_mul_B!{T<:BlasFloat}(y::StridedVector{T}, A::StridedVecOrMat{T}, x::StridedVector{T}) = gemv!(y, 'N', A, x)
8586
for elty in (Float32,Float64)

base/linalg/rowvector.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,9 @@ end
154154
sum(@inbounds(return rowvec[i]*vec[i]) for i = 1:length(vec))
155155
end
156156
@inline *(rowvec::RowVector, mat::AbstractMatrix) = transpose(mat.' * transpose(rowvec))
157-
*(vec::AbstractVector, mat::AbstractMatrix) = throw(DimensionMismatch(
158-
"Cannot left-multiply a matrix by a vector")) # Should become a deprecation
159157
*(::RowVector, ::RowVector) = throw(DimensionMismatch("Cannot multiply two transposed vectors"))
160158
@inline *(vec::AbstractVector, rowvec::RowVector) = vec .* rowvec
161159
*(vec::AbstractVector, rowvec::AbstractVector) = throw(DimensionMismatch("Cannot multiply two vectors"))
162-
*(mat::AbstractMatrix, rowvec::RowVector) = throw(DimensionMismatch("Cannot right-multiply matrix by transposed vector"))
163160

164161
# Transposed forms
165162
A_mul_Bt(::RowVector, ::AbstractVector) = throw(DimensionMismatch("Cannot multiply two transposed vectors"))

test/linalg/rowvector.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ end
104104

105105
@test (rv*v) === 14
106106
@test (rv*mat)::RowVector == [1 4 9]
107-
@test_throws DimensionMismatch [1]*reshape([1],(1,1)) # no longer permitted
107+
@test [1]*reshape([1],(1,1)) == reshape([1],(1,1))
108108
@test_throws DimensionMismatch rv*rv
109109
@test (v*rv)::Matrix == [1 2 3; 2 4 6; 3 6 9]
110110
@test_throws DimensionMismatch v*v # Was previously a missing method error, now an error message
@@ -238,5 +238,10 @@ end
238238
@test_throws DimensionMismatch ut\rv
239239
end
240240

241+
# issue #20389
242+
@testset "1 row/col vec*mat" begin
243+
@test [1,2,3] * ones(1, 4) == [1,2,3] .* ones(1, 4)
244+
@test ones(4,1) * RowVector([1,2,3]) == ones(4,1) .* RowVector([1,2,3])
245+
end
241246

242247
end # @testset "RowVector"

0 commit comments

Comments
 (0)