From 7e27d9b7b2dade95ac1e165eed24d48c12658ef3 Mon Sep 17 00:00:00 2001 From: Jiahao Chen Date: Sun, 31 Mar 2013 19:37:54 -0400 Subject: [PATCH] Adds cross-multiplies between Bidiagonal and {,Sym}Tridiagonal or scalars --- base/linalg/bidiag.jl | 8 ++++++++ base/linalg/tridiag.jl | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 6117b114e58ec..110543b8f5d99 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -99,8 +99,16 @@ end -(A::Bidiagonal)=Bidiagonal(-A.dv,-A.ev) #XXX Returns dense matrix but really should be banded *(A::Bidiagonal, B::Bidiagonal) = full(A)*full(B) +*(A::Bidiagonal, B::Number) = Bidiagonal(A.dv*B, A.ev*B, A.isupper) +*(B::Number, A::Bidiagonal) = A*B +/(A::Bidiagonal, B::Number) = Bidiagonal(A.dv/B, A.ev/B, A.isupper) ==(A::Bidiagonal, B::Bidiagonal) = (A.dv==B.dv) && (A.ev==B.ev) && (A.isupper==B.isupper) +*(A::SymTridiagonal, B::Bidiagonal) = full(A)*full(B) +*(A::Bidiagonal, B::SymTridiagonal) = full(A)*full(B) +*(A::Tridiagonal, B::Bidiagonal) = full(A)*full(B) +*(A::Bidiagonal, B::Tridiagonal) = full(A)*full(B) + # solver uses tridiagonal gtsv! function \{T<:BlasFloat}(M::Bidiagonal{T}, rhs::StridedVecOrMat{T}) if stride(rhs, 1) == 1 diff --git a/base/linalg/tridiag.jl b/base/linalg/tridiag.jl index c79ee7e588e0a..0fd6e3eba6b23 100644 --- a/base/linalg/tridiag.jl +++ b/base/linalg/tridiag.jl @@ -49,9 +49,10 @@ ctranspose(M::SymTridiagonal) = conj(M) +(A::SymTridiagonal, B::SymTridiagonal) = SymTridiagonal(A.dv+B.dv, A.ev+B.ev) -(A::SymTridiagonal, B::SymTridiagonal) = SymTridiagonal(A.dv-B.dv, A.ev-B.ev) -#XXX Returns dense matrix but really should be banded *(A::SymTridiagonal, B::SymTridiagonal) = full(A)*full(B) - +*(A::SymTridiagonal, B::Number) = SymTridiagonal(A.dv*B, A.ev*B) +*(B::Number, A::SymTridiagonal) = A*B +/(A::SymTridiagonal, B::Number) = SymTridiagonal(A.dv/B, A.ev/B) ==(A::SymTridiagonal, B::SymTridiagonal) = (A.dv==B.dv) && (A.ev==B.ev) ## Solver @@ -144,8 +145,10 @@ ctranspose(M::Tridiagonal) = conj(transpose(M)) +(A::Tridiagonal, B::Tridiagonal) = Tridiagonal(A.dl+B.dl, A.d+B.d, A.du+B.du) -(A::Tridiagonal, B::Tridiagonal) = Tridiagonal(A.dl-B.dl, A.d-B.d, A.du+B.du) -#XXX Returns dense matrix but really should be banded *(A::Tridiagonal, B::Tridiagonal) = full(A)*full(B) +*(A::Tridiagonal, B::Number) = Tridiagonal(A.dl*B, A.d*B, A.du*B) +*(B::Number, A::SymTridiagonal) = A*B +/(A::Tridiagonal, B::Number) = Tridiagonal(A.dl/B, A.d/B, A.du/B) ==(A::Tridiagonal, B::Tridiagonal) = (A.dl==B.dl) && (A.d==B.d) && (A.du==B.du) ==(A::Tridiagonal, B::SymTridiagonal) = (A.dl==A.du==B.ev) && (A.d==B.dv)