Skip to content

Commit

Permalink
re-allow vector*(1-row matrix) and transpose (closes #20389)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Feb 3, 2017
1 parent ad5cd7b commit 7f977ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions base/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
7 changes: 6 additions & 1 deletion test/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

0 comments on commit 7f977ed

Please sign in to comment.