Skip to content

Commit 86cba99

Browse files
authored
Remove specialized vector-matrix multiplication methods (#55538)
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.
1 parent 7d341ea commit 86cba99

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

stdlib/LinearAlgebra/src/matmul.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ function (*)(A::AbstractMatrix{T}, x::AbstractVector{S}) where {T,S}
6161
end
6262

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

6869
# Add a level of indirection and specialize _mul! to avoid ambiguities in mul!
6970
@inline mul!(y::AbstractVector, A::AbstractVecOrMat, x::AbstractVector,

stdlib/LinearAlgebra/test/matmul.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,4 +1120,14 @@ end
11201120
end
11211121
end
11221122

1123+
@testset "vector-matrix multiplication" begin
1124+
a = [1,2]
1125+
A = reshape([1,2], 2, 1)
1126+
B = [1 2]
1127+
@test a * B A * B
1128+
B = reshape([1,2], 2, 1)
1129+
@test a * B' A * B'
1130+
@test a * transpose(B) A * transpose(B)
1131+
end
1132+
11231133
end # module TestMatmul

0 commit comments

Comments
 (0)