diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index d744cf4258a96..8d6992ff06852 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -108,42 +108,40 @@ ctranspose(M::Bidiagonal) = Bidiagonal(conj(M.dv), conj(M.ev), !M.isupper) istriu(M::Bidiagonal) = M.isupper || all(M.ev .== 0) istril(M::Bidiagonal) = !M.isupper || all(M.ev .== 0) -function tril(M::Bidiagonal, k::Integer=0) +function tril!(M::Bidiagonal, k::Integer=0) n = length(M.dv) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif M.isupper && k < 0 - return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) + fill!(M.dv,0) + fill!(M.ev,0) elseif k < -1 - return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) - elseif !M.isupper && k == 0 - return M + fill!(M.dv,0) + fill!(M.ev,0) elseif M.isupper && k == 0 - return Bidiagonal(M.dv,zeros(M.ev),M.isupper) + fill!(M.ev,0) elseif !M.isupper && k == -1 - return Bidiagonal(zeros(M.dv),M.ev,M.isupper) - elseif k > 0 - return M + fill!(M.dv,0) end + return M end -function triu(M::Bidiagonal, k::Integer=0) +function triu!(M::Bidiagonal, k::Integer=0) n = length(M.dv) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif !M.isupper && k > 0 - return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) + fill!(M.dv,0) + fill!(M.ev,0) elseif k > 1 - return Bidiagonal(zeros(M.dv),zeros(M.ev),M.isupper) - elseif M.isupper && k == 0 - return M + fill!(M.dv,0) + fill!(M.ev,0) elseif !M.isupper && k == 0 - return Bidiagonal(M.dv,zeros(M.ev),M.isupper) + fill!(M.ev,0) elseif M.isupper && k == 1 - return Bidiagonal(zeros(M.dv),M.ev,M.isupper) - elseif k < 0 - return M + fill!(M.dv,0) end + return M end function diag{T}(M::Bidiagonal{T}, n::Integer=0) diff --git a/base/linalg/diagonal.jl b/base/linalg/diagonal.jl index 16cf79b6e4e74..b4dd70c57f037 100644 --- a/base/linalg/diagonal.jl +++ b/base/linalg/diagonal.jl @@ -55,8 +55,27 @@ isposdef(D::Diagonal) = all(D.diag .> 0) factorize(D::Diagonal) = D -tril(D::Diagonal,i::Integer=0) = i == 0 ? D : zeros(D) -triu(D::Diagonal,i::Integer=0) = i == 0 ? D : zeros(D) +istriu(D::Diagonal) = true +istril(D::Diagonal) = true +function triu!(D::Diagonal,k::Integer=0) + n = size(D,1) + if abs(k) > n + throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) + elseif k > 0 + fill!(D.diag,0) + end + return D +end + +function tril!(D::Diagonal,k::Integer=0) + n = size(D,1) + if abs(k) > n + throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) + elseif k < 0 + fill!(D.diag,0) + end + return D +end ==(Da::Diagonal, Db::Diagonal) = Da.diag == Db.diag -(A::Diagonal)=Diagonal(-A.diag) diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index d7b76cb77b363..33ff90cd07391 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -40,6 +40,8 @@ cross(a::AbstractVector, b::AbstractVector) = [a[2]*b[3]-a[3]*b[2], a[3]*b[1]-a[ triu(M::AbstractMatrix) = triu!(copy(M)) tril(M::AbstractMatrix) = tril!(copy(M)) +triu(M::AbstractMatrix,k::Integer) = triu!(copy(M),k) +tril(M::AbstractMatrix,k::Integer) = tril!(copy(M),k) triu!(M::AbstractMatrix) = triu!(M,0) tril!(M::AbstractMatrix) = tril!(M,0) diff --git a/base/linalg/symmetric.jl b/base/linalg/symmetric.jl index bb37b51a5d06e..408d882e91613 100644 --- a/base/linalg/symmetric.jl +++ b/base/linalg/symmetric.jl @@ -57,10 +57,53 @@ ctranspose(A::Hermitian) = A trace(A::Hermitian) = real(trace(A.data)) #tril/triu -tril(A::Hermitian,k::Integer=0) = tril(A.data,k) -triu(A::Hermitian,k::Integer=0) = triu(A.data,k) -tril(A::Symmetric,k::Integer=0) = tril(A.data,k) -triu(A::Symmetric,k::Integer=0) = triu(A.data,k) +function tril(A::Hermitian, k::Integer=0) + if A.uplo == 'U' && k <= 0 + return tril!(A.data',k) + elseif A.uplo == 'U' && k > 0 + return tril!(A.data',-1) + tril!(triu(A.data),k) + elseif A.uplo == 'L' && k <= 0 + return tril(A.data,k) + else + return tril(A.data,-1) + tril!(triu!(A.data'),k) + end +end + +function tril(A::Symmetric, k::Integer=0) + if A.uplo == 'U' && k <= 0 + return tril!(A.data.',k) + elseif A.uplo == 'U' && k > 0 + return tril!(A.data.',-1) + tril!(triu(A.data),k) + elseif A.uplo == 'L' && k <= 0 + return tril(A.data,k) + else + return tril(A.data,-1) + tril!(triu!(A.data.'),k) + end +end + +function triu(A::Hermitian, k::Integer=0) + if A.uplo == 'U' && k >= 0 + return triu(A.data,k) + elseif A.uplo == 'U' && k < 0 + return triu(A.data,1) + triu!(tril!(A.data'),k) + elseif A.uplo == 'L' && k >= 0 + return triu!(A.data',k) + else + return triu!(A.data',1) + triu!(tril(A.data),k) + end +end + +function triu(A::Symmetric, k::Integer=0) + if A.uplo == 'U' && k >= 0 + return triu(A.data,k) + elseif A.uplo == 'U' && k < 0 + return triu(A.data,1) + triu!(tril!(A.data.'),k) + elseif A.uplo == 'L' && k >= 0 + return triu!(A.data.',k) + else + return triu!(A.data.',1) + triu!(tril(A.data),k) + end +end ## Matvec A_mul_B!{T<:BlasFloat,S<:StridedMatrix}(y::StridedVector{T}, A::Symmetric{T,S}, x::StridedVector{T}) = BLAS.symv!(A.uplo, one(T), A.data, x, zero(T), y) diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index 2c6e6c5d861e0..5eda17721192d 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -149,65 +149,98 @@ istril(A::UnitLowerTriangular) = true istriu(A::UpperTriangular) = true istriu(A::UnitUpperTriangular) = true -function tril(A::UpperTriangular,k::Integer=0) +function tril!(A::UpperTriangular,k::Integer=0) n = size(A,1) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k < 0 - return UpperTriangular(zeros(A.data)) + fill!(A.data,0) + return A elseif k == 0 - return UpperTriangular(diagm(diag(A))) + for j in 1:n, i in 1:j-1 + A.data[i,j] = 0 + end + return A else - return UpperTriangular(triu(tril(A.data,k))) + return UpperTriangular(tril!(A.data,k)) end end +triu!(A::UpperTriangular,k::Integer=0) = UpperTriangular(triu!(A.data,k)) -triu(A::UpperTriangular,k::Integer=0) = UpperTriangular(triu(triu(A.data),k)) - -function tril(A::UnitUpperTriangular,k::Integer=0) +function tril!(A::UnitUpperTriangular,k::Integer=0) n = size(A,1) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k < 0 - return UnitUpperTriangular(zeros(A.data)) + fill!(A.data,0) + return UpperTriangular(A.data) elseif k == 0 - return UnitUpperTriangular(eye(A)) + fill!(A.data,0) + for i in diagind(A) + A.data[i] = one(eltype(A)) + end + return UpperTriangular(A.data) else - return UnitUpperTriangular(triu(tril(A.data,k))) + for i in diagind(A) + A.data[i] = one(eltype(A)) + end + return UpperTriangular(tril!(A.data,k)) end end -triu(A::UnitUpperTriangular,k::Integer=0) = UnitUpperTriangular(triu(triu(A.data),k)) +function triu!(A::UnitUpperTriangular,k::Integer=0) + for i in diagind(A) + A.data[i] = one(eltype(A)) + end + return triu!(UpperTriangular(A.data),k) +end -function triu(A::LowerTriangular,k::Integer=0) +function triu!(A::LowerTriangular,k::Integer=0) n = size(A,1) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k > 0 - return LowerTriangular(zeros(A.data)) + fill!(A.data,0) + return A elseif k == 0 - return LowerTriangular(diagm(diag(A))) + for j in 1:n, i in j+1:n + A.data[i,j] = 0 + end + return A else - return LowerTriangular(tril(triu(A.data,k))) + return LowerTriangular(triu!(A.data,k)) end end -tril(A::LowerTriangular,k::Integer=0) = LowerTriangular(tril(tril(A.data),k)) +tril!(A::LowerTriangular,k::Integer=0) = LowerTriangular(tril!(A.data,k)) -function triu(A::UnitLowerTriangular,k::Integer=0) +function triu!(A::UnitLowerTriangular,k::Integer=0) n = size(A,1) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k > 0 - return UnitLowerTriangular(zeros(A.data)) + fill!(A.data,0) + return LowerTriangular(A.data) elseif k == 0 - return UnitLowerTriangular(eye(A)) + fill!(A.data,0) + for i in diagind(A) + A.data[i] = one(eltype(A)) + end + return LowerTriangular(A.data) else - return UnitLowerTriangular(tril(triu(A.data,k))) + for i in diagind(A) + A.data[i] = one(eltype(A)) + end + return LowerTriangular(triu!(A.data,k)) end end -tril(A::UnitLowerTriangular,k::Integer=0) = UnitLowerTriangular(tril(tril(A.data),k)) +function tril!(A::UnitLowerTriangular,k::Integer=0) + for i in diagind(A) + A.data[i] = one(eltype(A)) + end + return tril!(LowerTriangular(A.data),k) +end transpose{T,S}(A::LowerTriangular{T,S}) = UpperTriangular{T, S}(transpose(A.data)) transpose{T,S}(A::UnitLowerTriangular{T,S}) = UnitUpperTriangular{T, S}(transpose(A.data)) diff --git a/base/linalg/tridiag.jl b/base/linalg/tridiag.jl index 214e7405bc9ff..6aef654acdc37 100644 --- a/base/linalg/tridiag.jl +++ b/base/linalg/tridiag.jl @@ -149,33 +149,39 @@ eigvecs{T<:BlasFloat,Eigenvalue<:Real}(A::SymTridiagonal{T}, eigvals::Vector{Eig istriu(M::SymTridiagonal) = all(M.ev .== 0) istril(M::SymTridiagonal) = all(M.ev .== 0) -function tril(M::SymTridiagonal, k::Integer=0) +function tril!(M::SymTridiagonal, k::Integer=0) n = length(M.dv) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k < -1 - return SymTridiagonal(zeros(M.dv),zeros(M.ev)) + fill!(M.ev,0) + fill!(M.dv,0) + return Tridiagonal(M.ev,M.dv,copy(M.ev)) elseif k == -1 - return Tridiagonal(M.ev,zeros(M.dv),zeros(M.ev)) + fill!(M.dv,0) + return Tridiagonal(M.ev,M.dv,zeros(M.ev)) elseif k == 0 return Tridiagonal(M.ev,M.dv,zeros(M.ev)) elseif k >= 1 - return M + return Tridiagonal(M.ev,M.dv,copy(M.ev)) end end -function triu(M::SymTridiagonal, k::Integer=0) +function triu!(M::SymTridiagonal, k::Integer=0) n = length(M.dv) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k > 1 - return SymTridiagonal(zeros(M.dv),zeros(M.ev)) + fill!(M.ev,0) + fill!(M.dv,0) + return Tridiagonal(M.ev,M.dv,copy(M.ev)) elseif k == 1 - return Tridiagonal(zeros(M.ev),zeros(M.dv),M.ev) + fill!(M.dv,0) + return Tridiagonal(zeros(M.ev),M.dv,M.ev) elseif k == 0 return Tridiagonal(zeros(M.ev),M.dv,M.ev) elseif k <= -1 - return M + return Tridiagonal(M.ev,M.dv,copy(M.ev)) end end @@ -356,37 +362,41 @@ end #tril and triu -istriu(M::Tridiagonal) = all(M.ev .== 0) -istril(M::Tridiagonal) = all(M.ev .== 0) +istriu(M::Tridiagonal) = all(M.dl .== 0) +istril(M::Tridiagonal) = all(M.du .== 0) -function tril(M::Tridiagonal, k::Integer=0) +function tril!(M::Tridiagonal, k::Integer=0) n = length(M.d) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k < -1 - return Tridiagonal(zeros(M.dl),zeros(M.d),zeros(M.du)) + fill!(M.dl,0) + fill!(M.d,0) + fill!(M.du,0) elseif k == -1 - return Tridiagonal(M.dl,zeros(M.d),zeros(M.du)) + fill!(M.d,0) + fill!(M.du,0) elseif k == 0 - return Tridiagonal(M.dl,M.d,zeros(M.du)) - elseif k >= 1 - return M + fill!(M.du,0) end + return M end -function triu(M::Tridiagonal, k::Integer=0) +function triu!(M::Tridiagonal, k::Integer=0) n = length(M.d) if abs(k) > n throw(ArgumentError("requested diagonal, $k, out of bounds in matrix of size ($n,$n)")) elseif k > 1 - return Tridiagonal(zeros(M.dl),zeros(M.d),zeros(M.du)) + fill!(M.dl,0) + fill!(M.d,0) + fill!(M.du,0) elseif k == 1 - return Tridiagonal(zeros(M.dl),zeros(M.d),M.du) + fill!(M.dl,0) + fill!(M.d,0) elseif k == 0 - return Tridiagonal(zeros(M.dl),M.d,M.du) - elseif k <= -1 - return M + fill!(M.dl,0) end + return M end ################### diff --git a/test/linalg/bidiag.jl b/test/linalg/bidiag.jl index 8e5902d580072..1db230df17723 100644 --- a/test/linalg/bidiag.jl +++ b/test/linalg/bidiag.jl @@ -43,26 +43,29 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty}) end debug && println("triu and tril") - @test tril(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(zeros(dv),zeros(ev),'U') - @test tril(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(zeros(dv),ev,'L') - @test tril(Bidiagonal(dv,ev,'U'),-2) == Bidiagonal(zeros(dv),zeros(ev),'U') - @test tril(Bidiagonal(dv,ev,'L'),-2) == Bidiagonal(zeros(dv),zeros(ev),'L') - @test tril(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(dv,ev,'U') - @test tril(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(dv,ev,'L') - @test tril(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,zeros(ev),'U') - @test tril(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,ev,'L') - @test_throws ArgumentError tril(Bidiagonal(dv,ev,'U'),n+1) - - @test triu(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(zeros(dv),zeros(ev),'L') - @test triu(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(zeros(dv),ev,'U') - @test triu(Bidiagonal(dv,ev,'U'),2) == Bidiagonal(zeros(dv),zeros(ev),'U') - @test triu(Bidiagonal(dv,ev,'L'),2) == Bidiagonal(zeros(dv),zeros(ev),'L') - @test triu(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(dv,ev,'U') - @test triu(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(dv,ev,'L') - @test triu(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,zeros(ev),'L') - @test triu(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,ev,'U') - @test_throws ArgumentError triu(Bidiagonal(dv,ev,'U'),n+1) - + @test istril(Bidiagonal(dv,ev,'L')) + @test !istril(Bidiagonal(dv,ev,'U')) + @test tril!(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(zeros(dv),zeros(ev),'U') + @test tril!(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(zeros(dv),ev,'L') + @test tril!(Bidiagonal(dv,ev,'U'),-2) == Bidiagonal(zeros(dv),zeros(ev),'U') + @test tril!(Bidiagonal(dv,ev,'L'),-2) == Bidiagonal(zeros(dv),zeros(ev),'L') + @test tril!(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(dv,ev,'U') + @test tril!(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(dv,ev,'L') + @test tril!(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,zeros(ev),'U') + @test tril!(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,ev,'L') + @test_throws ArgumentError tril!(Bidiagonal(dv,ev,'U'),n+1) + + @test istriu(Bidiagonal(dv,ev,'U')) + @test !istriu(Bidiagonal(dv,ev,'L')) + @test triu!(Bidiagonal(dv,ev,'L'),1) == Bidiagonal(zeros(dv),zeros(ev),'L') + @test triu!(Bidiagonal(dv,ev,'U'),1) == Bidiagonal(zeros(dv),ev,'U') + @test triu!(Bidiagonal(dv,ev,'U'),2) == Bidiagonal(zeros(dv),zeros(ev),'U') + @test triu!(Bidiagonal(dv,ev,'L'),2) == Bidiagonal(zeros(dv),zeros(ev),'L') + @test triu!(Bidiagonal(dv,ev,'U'),-1) == Bidiagonal(dv,ev,'U') + @test triu!(Bidiagonal(dv,ev,'L'),-1) == Bidiagonal(dv,ev,'L') + @test triu!(Bidiagonal(dv,ev,'L')) == Bidiagonal(dv,zeros(ev),'L') + @test triu!(Bidiagonal(dv,ev,'U')) == Bidiagonal(dv,ev,'U') + @test_throws ArgumentError triu!(Bidiagonal(dv,ev,'U'),n+1) debug && println("Linear solver") Tfull = full(T) diff --git a/test/linalg/diagonal.jl b/test/linalg/diagonal.jl index 0d84b0e2cca3e..a7ca0d619771a 100644 --- a/test/linalg/diagonal.jl +++ b/test/linalg/diagonal.jl @@ -84,10 +84,14 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty}) @test_approx_eq D/D2 Diagonal(D.diag./D2.diag) # test triu/tril - @test triu(D,1) == zeros(D) - @test triu(D,0) == D - @test tril(D,1) == zeros(D) - @test tril(D,0) == D + @test istriu(D) + @test istril(D) + @test triu(D,1) == zeros(D) + @test triu(D,0) == D + @test triu(D,-1) == D + @test tril(D,1) == D + @test tril(D,-1) == zeros(D) + @test tril(D,0) == D # factorize @test factorize(D) == D diff --git a/test/linalg/symmetric.jl b/test/linalg/symmetric.jl index 7c8b3c6ec34d2..c1511ac42ef3f 100644 --- a/test/linalg/symmetric.jl +++ b/test/linalg/symmetric.jl @@ -60,10 +60,16 @@ let n=10 @test ctranspose(Hermitian(asym)) == asym #tril/triu - @test triu(Symmetric(asym),1) == triu(asym,1) - @test tril(Symmetric(asym),1) == tril(asym,1) - @test triu(Hermitian(asym),1) == triu(asym,1) - @test tril(Hermitian(asym),1) == tril(asym,1) + for di in -n:n + @test triu(Symmetric(a+a.'),di) == triu(a+a.',di) + @test tril(Symmetric(a+a.'),di) == tril(a+a.',di) + @test triu(Hermitian(asym),di) == triu(asym,di) + @test tril(Hermitian(asym),di) == tril(asym,di) + @test triu(Symmetric(a+a.',:L),di) == triu(a+a.',di) + @test tril(Symmetric(a+a.',:L),di) == tril(a+a.',di) + @test triu(Hermitian(asym,:L),di) == triu(asym,di) + @test tril(Hermitian(asym,:L),di) == tril(asym,di) + end eltya == BigFloat && continue # Revisit when implemented in julia d, v = eig(asym) diff --git a/test/linalg/triangular.jl b/test/linalg/triangular.jl index badfd47003e79..4bd5c67af6acd 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -87,21 +87,23 @@ for elty1 in (Float32, Float64, Complex64, Complex128, BigFloat, Int) #tril/triu if uplo1 == :L - @test tril(A1) == A1 - @test tril(A1,-1) == t1(tril(full(A1),-1)) + @test tril(A1,0) == A1 + @test tril(A1,-1) == LowerTriangular(tril(full(A1),-1)) @test tril(A1,1) == t1(tril(tril(full(A1),1))) - @test_throws ArgumentError tril(A1,n+1) - @test triu(A1) == t1(diagm(diag(A1))) + @test_throws ArgumentError tril!(A1,n+1) + @test triu(A1,0) == t1(diagm(diag(A1))) @test triu(A1,-1) == t1(tril(triu(A1.data,-1))) - @test_throws ArgumentError triu(A1,n+1) + @test triu(A1,1) == LowerTriangular(zeros(A1.data)) + @test_throws ArgumentError triu!(A1,n+1) else - @test triu(A1) == A1 - @test triu(A1,1) == t1(triu(full(A1),1)) + @test triu(A1,0) == A1 + @test triu(A1,1) == UpperTriangular(triu(full(A1),1)) @test triu(A1,-1) == t1(triu(triu(full(A1),-1))) - @test_throws ArgumentError triu(A1,n+1) - @test tril(A1) == t1(diagm(diag(A1))) + @test_throws ArgumentError triu!(A1,n+1) + @test tril(A1,0) == t1(diagm(diag(A1))) @test tril(A1,1) == t1(triu(tril(A1.data,1))) - @test_throws ArgumentError tril(A1,n+1) + @test tril(A1,-1) == UpperTriangular(zeros(A1.data)) + @test_throws ArgumentError tril!(A1,n+1) end # factorize diff --git a/test/linalg/tridiag.jl b/test/linalg/tridiag.jl index c0503c41aaa6d..f5ae60e55c0c0 100644 --- a/test/linalg/tridiag.jl +++ b/test/linalg/tridiag.jl @@ -117,8 +117,8 @@ for elty in (Float32, Float64, Complex64, Complex128, Int) @test_approx_eq_eps det(ones(elty, 3,3)) zero(elty) 3*eps(real(one(elty))) #tril/triu - @test_throws ArgumentError tril(SymTridiagonal(d,dl),n+1) - @test_throws ArgumentError tril(Tridiagonal(dl,d,du),n+1) + @test_throws ArgumentError tril!(SymTridiagonal(d,dl),n+1) + @test_throws ArgumentError tril!(Tridiagonal(dl,d,du),n+1) @test tril(SymTridiagonal(d,dl)) == Tridiagonal(dl,d,zeros(dl)) @test tril(SymTridiagonal(d,dl),1) == Tridiagonal(dl,d,dl) @test tril(SymTridiagonal(d,dl),-1) == Tridiagonal(dl,zeros(d),zeros(dl)) @@ -126,8 +126,8 @@ for elty in (Float32, Float64, Complex64, Complex128, Int) @test tril(Tridiagonal(dl,d,du),1) == Tridiagonal(dl,d,du) @test tril(Tridiagonal(dl,d,du),-1) == Tridiagonal(dl,zeros(d),zeros(du)) - @test_throws ArgumentError triu(SymTridiagonal(d,dl),n+1) - @test_throws ArgumentError triu(Tridiagonal(dl,d,du),n+1) + @test_throws ArgumentError triu!(SymTridiagonal(d,dl),n+1) + @test_throws ArgumentError triu!(Tridiagonal(dl,d,du),n+1) @test triu(SymTridiagonal(d,dl)) == Tridiagonal(zeros(dl),d,dl) @test triu(SymTridiagonal(d,dl),-1) == Tridiagonal(dl,d,dl) @test triu(SymTridiagonal(d,dl),1) == Tridiagonal(zeros(dl),zeros(d),dl)