Skip to content

Commit

Permalink
Specialize Bidiagonal * AbstractVecOrMat
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Aug 10, 2024
1 parent 974425c commit fc3387f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions stdlib/LinearAlgebra/src/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,44 @@ function _mul!(C::AbstractVecOrMat, A::BiTriSym, B::AbstractVecOrMat, _add::MulA
end
return C
end
_mul_bitrisym!(C, A, B, _add)
end
function _mul_bitrisym!(C::AbstractVecOrMat, A::Bidiagonal, B::AbstractVecOrMat, _add::MulAddMul)
nA = size(A,1)
nB = size(B,2)
d = B.dv
if A.uplo == 'U'
u = B.ev
@inbounds begin
for j = 1:nB
b₀, b₊ = B[1, j], B[2, j]
_modify!(_add, d[1]*b₀ + u[1]*b₊, C, (1, j))
for i = 2:nA - 1
b₀, b₊ = b₊, B[i + 1, j]
_modify!(_add, d[i]*b₀ + u[i]*b₊, C, (i, j))
end
_modify!(_add, d[nA]*b₊, C, (nA, j))
end
end
else
l = B.ev
@inbounds begin
for j = 1:nB
b₀, b₊ = B[1, j], B[2, j]
_modify!(_add, d[1]*b₀, C, (1, j))
for i = 2:nA - 1
b₋, b₀, b₊ = b₀, b₊, B[i + 1, j]
_modify!(_add, l[i - 1]*b₋ + d[i]*b₀, C, (i, j))
end
_modify!(_add, l[nA - 1]*b₀ + d[nA]*b₊, C, (nA, j))
end
end
end
C
end
function _mul_bitrisym!(C::AbstractVecOrMat, A::TriSym, B::AbstractVecOrMat, _add::MulAddMul)
nA = size(A,1)
nB = size(B,2)
l = _diag(A, -1)
d = _diag(A, 0)
u = _diag(A, 1)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ end
@test B * B M * M
@test mul!(similar(B, size(B)), B, B) M * M

for m in 1:6
for m in 0:6
AL = rand(m,n)
AR = rand(n,m)
@test AL * B AL * M
Expand Down

0 comments on commit fc3387f

Please sign in to comment.