diff --git a/base/linalg/matmul.jl b/base/linalg/matmul.jl index 4dbd4c8dae817..b7090bfe4e691 100644 --- a/base/linalg/matmul.jl +++ b/base/linalg/matmul.jl @@ -80,6 +80,7 @@ function (*){T,S}(A::AbstractMatrix{T}, x::AbstractVector{S}) TS = promote_op(matprod, T, S) A_mul_B!(similar(x,TS,size(A,1)),A,x) end +(*)(A::AbstractVector, B::AbstractMatrix) = reshape(A,length(A),1)*B A_mul_B!{T<:BlasFloat}(y::StridedVector{T}, A::StridedVecOrMat{T}, x::StridedVector{T}) = gemv!(y, 'N', A, x) for elty in (Float32,Float64) diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index c5d2839e19b3c..9b8c873b46cdf 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -154,12 +154,9 @@ end sum(@inbounds(return rowvec[i]*vec[i]) for i = 1:length(vec)) end @inline *(rowvec::RowVector, mat::AbstractMatrix) = transpose(mat.' * transpose(rowvec)) -*(vec::AbstractVector, mat::AbstractMatrix) = throw(DimensionMismatch( - "Cannot left-multiply a matrix by a vector")) # Should become a deprecation *(::RowVector, ::RowVector) = throw(DimensionMismatch("Cannot multiply two transposed vectors")) @inline *(vec::AbstractVector, rowvec::RowVector) = vec .* rowvec *(vec::AbstractVector, rowvec::AbstractVector) = throw(DimensionMismatch("Cannot multiply two vectors")) -*(mat::AbstractMatrix, rowvec::RowVector) = throw(DimensionMismatch("Cannot right-multiply matrix by transposed vector")) # Transposed forms A_mul_Bt(::RowVector, ::AbstractVector) = throw(DimensionMismatch("Cannot multiply two transposed vectors")) diff --git a/test/linalg/rowvector.jl b/test/linalg/rowvector.jl index 315ec12586f5d..e35a97a0f9c93 100644 --- a/test/linalg/rowvector.jl +++ b/test/linalg/rowvector.jl @@ -104,7 +104,7 @@ end @test (rv*v) === 14 @test (rv*mat)::RowVector == [1 4 9] - @test_throws DimensionMismatch [1]*reshape([1],(1,1)) # no longer permitted + @test [1]*reshape([1],(1,1)) == reshape([1],(1,1)) @test_throws DimensionMismatch rv*rv @test (v*rv)::Matrix == [1 2 3; 2 4 6; 3 6 9] @test_throws DimensionMismatch v*v # Was previously a missing method error, now an error message @@ -238,5 +238,10 @@ end @test_throws DimensionMismatch ut\rv end +# issue #20389 +@testset "1 row/col vec*mat" begin + @test [1,2,3] * ones(1, 4) == [1,2,3] .* ones(1, 4) + @test ones(4,1) * RowVector([1,2,3]) == ones(4,1) .* RowVector([1,2,3]) +end end # @testset "RowVector"