Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lmul! and rmul! for Bidiagonal #51777

Merged
merged 7 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add lmul! and rmul! for Bidiagonal
  • Loading branch information
dkarrasch committed Oct 19, 2023
commit 1a785c4c2e35f98c7725fbb5c8891569db338286
3 changes: 3 additions & 0 deletions stdlib/LinearAlgebra/src/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ const BiTri = Union{Bidiagonal,Tridiagonal}
@inline mul!(C::AbstractMatrix, A::AbstractMatrix, B::BandedMatrix, alpha::Number, beta::Number) = _mul!(C, A, B, MulAddMul(alpha, beta))
@inline mul!(C::AbstractMatrix, A::BandedMatrix, B::BandedMatrix, alpha::Number, beta::Number) = _mul!(C, A, B, MulAddMul(alpha, beta))

lmul!(A::Bidiagonal, B::AbstractVecOrMat) = @inline _mul!(B, A, B, MulAddMul())
rmul!(B::AbstractMatrix, A::Bidiagonal) = @inline _mul!(B, B, A, MulAddMul())

function check_A_mul_B!_sizes(C, A, B)
mA, nA = size(A)
mB, nB = size(B)
Expand Down
9 changes: 6 additions & 3 deletions stdlib/LinearAlgebra/test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ Random.seed!(1)
# test pass-through of mul! for AbstractTriangular*Bidiagonal
Tri = UpperTriangular(diagm(1 => T.ev))
Dia = Diagonal(T.dv)
@test Array(Tri*T) ≈ Array(Tri)*Array(T)
@test Array(Tri*T) ≈ Array(Tri)*Array(T) ≈ rmul!(copy(Tri), T)
@test Array(T*Tri) ≈ Array(T)*Array(Tri) ≈ lmul!(T, copy(Tri))
# test mul! itself for these types
for AA in (Tri, Dia)
for f in (identity, transpose, adjoint)
Expand All @@ -459,8 +460,10 @@ Random.seed!(1)
for f in (identity, transpose, adjoint)
C = relty == Int ? rand(float(elty), n, n) : rand(elty, n, n)
B = rand(elty, n, n)
D = copy(C) + 2.0 * Array(T*f(B))
mul!(C, T, f(B), 2.0, 1.0) ≈ D
D = C + 2.0 * Array(T*f(B))
@test mul!(C, T, f(B), 2.0, 1.0) ≈ D
@test lmul!(T, copy(f(B))) ≈ T * f(B)
@test rmul!(copy(f(B)), T) ≈ f(B) * T
end

# Issue #31870
Expand Down