From 58db36c758e41ff4ea987e0b0763e81a084ab9a0 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 14 Oct 2017 12:20:29 -0700 Subject: [PATCH] Replace remaining full(A) calls with copy!(similar(parent(A)), A). --- base/linalg/schur.jl | 8 ++++---- base/linalg/special.jl | 9 ++++----- base/linalg/symmetric.jl | 2 +- base/linalg/triangular.jl | 12 ++++++------ 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/base/linalg/schur.jl b/base/linalg/schur.jl index fe4dce5d408ab..d50f6afbff692 100644 --- a/base/linalg/schur.jl +++ b/base/linalg/schur.jl @@ -105,10 +105,10 @@ function schur(A::StridedMatrix) SchurF = schurfact(A) SchurF[:T], SchurF[:Z], SchurF[:values] end -schur(A::Symmetric) = schur(full(A)) -schur(A::Hermitian) = schur(full(A)) -schur(A::UpperTriangular) = schur(full(A)) -schur(A::LowerTriangular) = schur(full(A)) +schur(A::Symmetric) = schur(copy!(similar(parent(A)), A)) +schur(A::Hermitian) = schur(copy!(similar(parent(A)), A)) +schur(A::UpperTriangular) = schur(copy!(similar(parent(A)), A)) +schur(A::LowerTriangular) = schur(copy!(similar(parent(A)), A)) schur(A::Tridiagonal) = schur(Matrix(A)) diff --git a/base/linalg/special.jl b/base/linalg/special.jl index fcc36c814d410..d3a4ab3b4482e 100644 --- a/base/linalg/special.jl +++ b/base/linalg/special.jl @@ -116,12 +116,11 @@ for op in (:+, :-) end for matrixtype in (:SymTridiagonal,:Tridiagonal,:Bidiagonal,:Matrix) @eval begin - ($op)(A::AbstractTriangular, B::($matrixtype)) = ($op)(full(A), B) - ($op)(A::($matrixtype), B::AbstractTriangular) = ($op)(A, full(B)) + ($op)(A::AbstractTriangular, B::($matrixtype)) = ($op)(copy!(similar(parent(A)), A), B) + ($op)(A::($matrixtype), B::AbstractTriangular) = ($op)(A, copy!(similar(parent(B)), B)) end end end -A_mul_Bc!(A::AbstractTriangular, B::QRCompactWYQ) = A_mul_Bc!(full!(A),B) -A_mul_Bc!(A::AbstractTriangular, B::QRPackedQ) = A_mul_Bc!(full!(A),B) -A_mul_Bc(A::AbstractTriangular, B::Union{QRCompactWYQ,QRPackedQ}) = A_mul_Bc(full(A), B) +A_mul_Bc!(A::AbstractTriangular, B::Union{QRCompactWYQ,QRPackedQ}) = A_mul_Bc!(full!(A), B) +A_mul_Bc(A::AbstractTriangular, B::Union{QRCompactWYQ,QRPackedQ}) = A_mul_Bc(copy!(similar(parent(A)), A), B) diff --git a/base/linalg/symmetric.jl b/base/linalg/symmetric.jl index 3335ffda0050d..9f9bbd2207062 100644 --- a/base/linalg/symmetric.jl +++ b/base/linalg/symmetric.jl @@ -300,7 +300,7 @@ A_mul_B!(C::StridedMatrix{T}, A::Hermitian{T,<:StridedMatrix}, B::StridedMatrix{ A_mul_B!(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,<:StridedMatrix}) where {T<:BlasComplex} = BLAS.hemm!('R', B.uplo, one(T), B.data, A, zero(T), C) -*(A::HermOrSym, B::HermOrSym) = A*full(B) +*(A::HermOrSym, B::HermOrSym) = A * copy!(similar(parent(B)), B) # Fallbacks to avoid generic_matvecmul!/generic_matmatmul! ## Symmetric{<:Number} and Hermitian{<:Real} are invariant to transpose; peel off the t diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index f0ab6b86ce9b4..2afedec6bfc0f 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -426,7 +426,7 @@ scale!(c::Number, A::Union{UpperTriangular,LowerTriangular}) = scale!(A,c) +(A::UnitLowerTriangular, B::LowerTriangular) = LowerTriangular(tril(A.data, -1) + B.data + I) +(A::UnitUpperTriangular, B::UnitUpperTriangular) = UpperTriangular(triu(A.data, 1) + triu(B.data, 1) + 2I) +(A::UnitLowerTriangular, B::UnitLowerTriangular) = LowerTriangular(tril(A.data, -1) + tril(B.data, -1) + 2I) -+(A::AbstractTriangular, B::AbstractTriangular) = full(A) + full(B) ++(A::AbstractTriangular, B::AbstractTriangular) = copy!(similar(parent(A)), A) + copy!(similar(parent(B)), B) -(A::UpperTriangular, B::UpperTriangular) = UpperTriangular(A.data - B.data) -(A::LowerTriangular, B::LowerTriangular) = LowerTriangular(A.data - B.data) @@ -436,15 +436,15 @@ scale!(c::Number, A::Union{UpperTriangular,LowerTriangular}) = scale!(A,c) -(A::UnitLowerTriangular, B::LowerTriangular) = LowerTriangular(tril(A.data, -1) - B.data + I) -(A::UnitUpperTriangular, B::UnitUpperTriangular) = UpperTriangular(triu(A.data, 1) - triu(B.data, 1)) -(A::UnitLowerTriangular, B::UnitLowerTriangular) = LowerTriangular(tril(A.data, -1) - tril(B.data, -1)) --(A::AbstractTriangular, B::AbstractTriangular) = full(A) - full(B) +-(A::AbstractTriangular, B::AbstractTriangular) = copy!(similar(parent(A)), A) - copy!(similar(parent(B)), B) ###################### # BlasFloat routines # ###################### A_mul_B!(A::Tridiagonal, B::AbstractTriangular) = A*full!(B) -A_mul_B!(C::AbstractMatrix, A::AbstractTriangular, B::Tridiagonal) = A_mul_B!(C, full(A), B) -A_mul_B!(C::AbstractMatrix, A::Tridiagonal, B::AbstractTriangular) = A_mul_B!(C, A, full(B)) +A_mul_B!(C::AbstractMatrix, A::AbstractTriangular, B::Tridiagonal) = A_mul_B!(C, copy!(similar(parent(A)), A), B) +A_mul_B!(C::AbstractMatrix, A::Tridiagonal, B::AbstractTriangular) = A_mul_B!(C, A, copy!(similar(parent(B)), B)) A_mul_Bt!(C::AbstractVecOrMat, A::AbstractTriangular, B::AbstractVecOrMat) = A_mul_B!(A, transpose!(C, B)) A_mul_Bc!(C::AbstractMatrix, A::AbstractTriangular, B::AbstractVecOrMat) = A_mul_B!(A, adjoint!(C, B)) A_mul_Bc!(C::AbstractVecOrMat, A::AbstractTriangular, B::AbstractVecOrMat) = A_mul_B!(A, adjoint!(C, B)) @@ -528,7 +528,7 @@ for (t, uploc, isunitc) in ((:LowerTriangular, 'L', 'N'), elseif p == Inf return inv(LAPACK.trcon!('I', $uploc, $isunitc, A.data)) else # use fallback - return cond(full(A), p) + return cond(copy!(similar(parent(A)), A), p) end end end @@ -2210,7 +2210,7 @@ eigfact(A::AbstractTriangular) = Eigen(eigvals(A), eigvecs(A)) # Generic singular systems for func in (:svd, :svdfact, :svdfact!, :svdvals) @eval begin - ($func)(A::AbstractTriangular) = ($func)(full(A)) + ($func)(A::AbstractTriangular) = ($func)(copy!(similar(parent(A)), A)) end end