Skip to content

Commit

Permalink
Remove specialized vector-matrix multiplication methods (#55538)
Browse files Browse the repository at this point in the history
The specialized methods for `TransposeAbsMat` and `AdjointAbsMat` seem
unnecessary, as these are also `AbstractMatrix`es, and are treated
identically. I've also added a `require_one_based_indexing` check on the
vector to avoid accepting `OffsetArray`s.
  • Loading branch information
jishnub authored Aug 21, 2024
1 parent 7d341ea commit 86cba99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions stdlib/LinearAlgebra/src/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ function (*)(A::AbstractMatrix{T}, x::AbstractVector{S}) where {T,S}
end

# these will throw a DimensionMismatch unless B has 1 row (or 1 col for transposed case):
(*)(a::AbstractVector, tB::TransposeAbsMat) = reshape(a, length(a), 1) * tB
(*)(a::AbstractVector, adjB::AdjointAbsMat) = reshape(a, length(a), 1) * adjB
(*)(a::AbstractVector, B::AbstractMatrix) = reshape(a, length(a), 1) * B
function (*)(a::AbstractVector, B::AbstractMatrix)
require_one_based_indexing(a)
reshape(a, length(a), 1) * B
end

# Add a level of indirection and specialize _mul! to avoid ambiguities in mul!
@inline mul!(y::AbstractVector, A::AbstractVecOrMat, x::AbstractVector,
Expand Down
10 changes: 10 additions & 0 deletions stdlib/LinearAlgebra/test/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,14 @@ end
end
end

@testset "vector-matrix multiplication" begin
a = [1,2]
A = reshape([1,2], 2, 1)
B = [1 2]
@test a * B A * B
B = reshape([1,2], 2, 1)
@test a * B' A * B'
@test a * transpose(B) A * transpose(B)
end

end # module TestMatmul

0 comments on commit 86cba99

Please sign in to comment.