|
228 | 228 | -(A::SymTridiagonal) = SymTridiagonal(-A.dv, -A.ev)
|
229 | 229 | *(A::SymTridiagonal, B::Number) = SymTridiagonal(A.dv*B, A.ev*B)
|
230 | 230 | *(B::Number, A::SymTridiagonal) = SymTridiagonal(B*A.dv, B*A.ev)
|
| 231 | +function rmul!(A::SymTridiagonal, x::Number) |
| 232 | + if size(A,1) > 2 |
| 233 | + # ensure that zeros are preserved on scaling |
| 234 | + y = A[3,1] * x |
| 235 | + iszero(y) || throw(ArgumentError(LazyString("cannot set index (3, 1) off ", |
| 236 | + lazy"the tridiagonal band to a nonzero value ($y)"))) |
| 237 | + end |
| 238 | + A.dv .*= x |
| 239 | + _evview(A) .*= x |
| 240 | + return A |
| 241 | +end |
| 242 | +function lmul!(x::Number, B::SymTridiagonal) |
| 243 | + if size(B,1) > 2 |
| 244 | + # ensure that zeros are preserved on scaling |
| 245 | + y = x * B[3,1] |
| 246 | + iszero(y) || throw(ArgumentError(LazyString("cannot set index (3, 1) off ", |
| 247 | + lazy"the tridiagonal band to a nonzero value ($y)"))) |
| 248 | + end |
| 249 | + @. B.dv = x * B.dv |
| 250 | + ev = _evview(B) |
| 251 | + @. ev = x * ev |
| 252 | + return B |
| 253 | +end |
231 | 254 | /(A::SymTridiagonal, B::Number) = SymTridiagonal(A.dv/B, A.ev/B)
|
232 | 255 | \(B::Number, A::SymTridiagonal) = SymTridiagonal(B\A.dv, B\A.ev)
|
233 | 256 | ==(A::SymTridiagonal{<:Number}, B::SymTridiagonal{<:Number}) =
|
@@ -836,6 +859,30 @@ tr(M::Tridiagonal) = sum(M.d)
|
836 | 859 | -(A::Tridiagonal) = Tridiagonal(-A.dl, -A.d, -A.du)
|
837 | 860 | *(A::Tridiagonal, B::Number) = Tridiagonal(A.dl*B, A.d*B, A.du*B)
|
838 | 861 | *(B::Number, A::Tridiagonal) = Tridiagonal(B*A.dl, B*A.d, B*A.du)
|
| 862 | +function rmul!(T::Tridiagonal, x::Number) |
| 863 | + if size(T,1) > 2 |
| 864 | + # ensure that zeros are preserved on scaling |
| 865 | + y = T[3,1] * x |
| 866 | + iszero(y) || throw(ArgumentError(LazyString("cannot set index (3, 1) off ", |
| 867 | + lazy"the tridiagonal band to a nonzero value ($y)"))) |
| 868 | + end |
| 869 | + T.dl .*= x |
| 870 | + T.d .*= x |
| 871 | + T.du .*= x |
| 872 | + return T |
| 873 | +end |
| 874 | +function lmul!(x::Number, T::Tridiagonal) |
| 875 | + if size(T,1) > 2 |
| 876 | + # ensure that zeros are preserved on scaling |
| 877 | + y = x * T[3,1] |
| 878 | + iszero(y) || throw(ArgumentError(LazyString("cannot set index (3, 1) off ", |
| 879 | + lazy"the tridiagonal band to a nonzero value ($y)"))) |
| 880 | + end |
| 881 | + @. T.dl = x * T.dl |
| 882 | + @. T.d = x * T.d |
| 883 | + @. T.du = x * T.du |
| 884 | + return T |
| 885 | +end |
839 | 886 | /(A::Tridiagonal, B::Number) = Tridiagonal(A.dl/B, A.d/B, A.du/B)
|
840 | 887 | \(B::Number, A::Tridiagonal) = Tridiagonal(B\A.dl, B\A.d, B\A.du)
|
841 | 888 |
|
|
0 commit comments