Skip to content

Commit 8566975

Browse files
committed
Merge pull request #5427 from JuliaLang/anj/symmetrize
Deprecate symmetrize! in favor of copytri!
2 parents 419c1c4 + 63d517a commit 8566975

13 files changed

+27
-47
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ Deprecated or removed
136136
* cholpfact and qrpfact are deprecated in favor of keyword arguments in
137137
cholfact and qrfact.
138138

139+
* symmetrize! is deprecated in favor copytri! but the new function is not exported
140+
139141
[#4042]: https://github.com/JuliaLang/julia/issues/4042
140142
[#5164]: https://github.com/JuliaLang/julia/issues/5164
141143
[#4026]: https://github.com/JuliaLang/julia/issues/4026

base/deprecated.jl

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export PipeString
176176
@deprecate cholpfact!(A,tol=tol) cholfact!(A, :U, pivot=true, tol=tol)
177177
@deprecate cholpfact!(A,uplo,tol=tol) cholfact!(A, uplo, pivot=true, tol=tol)
178178
@deprecate cholpfact(A) cholfact(A, :U, pivot=true)
179+
@deprecate symmetrize!(A) Base.LinAlg.copytri!(A, 'U')
180+
@deprecate symmetrize!(A, uplo) Base.LinAlg.copytri!(A, uplo)
179181

180182
deprecated_ls() = run(`ls -l`)
181183
deprecated_ls(args::Cmd) = run(`ls -l $args`)

base/exports.jl

-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ export
649649
svdfact,
650650
svdvals!,
651651
svdvals,
652-
symmetrize!,
653652
trace,
654653
transpose,
655654
tril!,

base/linalg.jl

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ export
110110
svdfact,
111111
svdvals!,
112112
svdvals,
113-
symmetrize!,
114-
symmetrize_conj!,
115113
trace,
116114
transpose,
117115
tril,

base/linalg/bunchkaufman.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ size(B::BunchKaufman,d::Integer) = size(B.LD,d)
2727
issym(B::BunchKaufman) = B.symmetric
2828
ishermitian(B::BunchKaufman) = !B.symmetric
2929

30-
inv{T<:BlasReal}(B::BunchKaufman{T})=symmetrize_conj!(LAPACK.sytri!(B.uplo, copy(B.LD), B.ipiv), B.uplo)
30+
inv{T<:BlasReal}(B::BunchKaufman{T})=copytri!(LAPACK.sytri!(B.uplo, copy(B.LD), B.ipiv), B.uplo, true)
3131

3232
function inv{T<:BlasComplex}(B::BunchKaufman{T})
3333
if issym(B)
34-
symmetrize!(LAPACK.sytri!(B.uplo, copy(B.LD), B.ipiv), B.uplo)
34+
copytri!(LAPACK.sytri!(B.uplo, copy(B.LD), B.ipiv), B.uplo)
3535
else
36-
symmetrize_conj!(LAPACK.hetri!(B.uplo, copy(B.LD), B.ipiv), B.uplo)
36+
copytri!(LAPACK.hetri!(B.uplo, copy(B.LD), B.ipiv), B.uplo, true)
3737
end
3838
end
3939

base/linalg/dense.jl

-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ kron(a::Vector, b::Vector)=vec(kron(reshape(a,length(a),1),reshape(b,length(b),1
141141
kron(a::Matrix, b::Vector)=kron(a,reshape(b,length(b),1))
142142
kron(a::Vector, b::Matrix)=kron(reshape(a,length(a),1),b)
143143

144-
randsym(n) = symmetrize!(randn(n,n))
145-
146144
^(A::Matrix, p::Integer) = p < 0 ? inv(A^-p) : Base.power_by_squaring(A,p)
147145

148146
function ^(A::Matrix, p::Number)

base/linalg/factorization.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ function logdet{T}(C::Cholesky{T})
104104
dd + dd # instead of 2.0dd which can change the type
105105
end
106106

107-
inv(C::Cholesky)=symmetrize_conj!(LAPACK.potri!(C.uplo, copy(C.UL)), C.uplo)
107+
inv(C::Cholesky) = copytri!(LAPACK.potri!(C.uplo, copy(C.UL)), C.uplo, true)
108108

109109
function inv(C::CholeskyPivoted)
110110
chkfullrank(C)
111111
ipiv = invperm(C.piv)
112-
(symmetrize!(LAPACK.potri!(C.uplo, copy(C.UL)), C.uplo))[ipiv, ipiv]
112+
copytri!(LAPACK.potri!(C.uplo, copy(C.UL)), C.uplo, true)[ipiv, ipiv]
113113
end
114114

115115
chkfullrank(C::CholeskyPivoted) = C.rank<size(C.UL, 1) && throw(RankDeficientException(C.info))

base/linalg/hermitian.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function copy!(A::Hermitian, B::Hermitian)
1717
end
1818
size(A::Hermitian, args...) = size(A.S, args...)
1919
getindex(A::Hermitian, i::Integer, j::Integer) = (A.uplo == 'U') == (i < j) ? getindex(A.S, i, j) : conj(getindex(A.S, j, i))
20-
full(A::Hermitian) = symmetrize_conj!(A.S, A.uplo)
20+
full(A::Hermitian) = copytri!(A.S, A.uplo, true)
2121
ishermitian(A::Hermitian) = true
2222
issym{T<:Real}(A::Hermitian{T}) = true
2323
issym{T<:Complex}(A::Hermitian{T}) = all(imag(A.S) .== 0)
@@ -57,10 +57,10 @@ function sqrtm(A::Hermitian, cond::Bool=false)
5757
length(F[:values]) == 0 && return A
5858
vsqrt = sqrt(complex(F[:values]))
5959
if all(imag(vsqrt) .== 0)
60-
retmat = symmetrize!(scale(F[:vectors], real(vsqrt)) * F[:vectors]')
60+
retmat = copytri!(scale(F[:vectors], real(vsqrt)) * F[:vectors]', 'U')
6161
else
6262
zc = complex(F[:vectors])
63-
retmat = symmetrize!(scale(zc, vsqrt) * zc')
63+
retmat = copytri!(scale(zc, vsqrt) * zc', 'U')
6464
end
6565
return cond ? (retmat, norm(vsqrt, Inf)^2/norm(F[:values], Inf)) : retmat
6666
end

base/linalg/matmul.jl

+8-21
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,19 @@ Ac_mul_Bt!{T,S,R}(C::StridedMatrix{R}, A::StridedMatrix{T}, B::StridedMatrix{S})
141141

142142
# Supporting functions for matrix multiplication
143143

144-
function symmetrize!(A::StridedMatrix, uplo::Char='U')
144+
function copytri!(A::StridedMatrix, uplo::Char, conjugate::Bool=false)
145145
n = chksquare(A)
146146
@chkuplo
147147
if uplo == 'U'
148148
for i = 1:(n-1), j = (i+1):n
149-
A[j,i] = A[i,j]
149+
A[j,i] = conjugate ? conj(A[i,j]) : A[i,j]
150150
end
151-
else #uplo == 'L'
151+
elseif uplo == 'L'
152152
for i = 1:(n-1), j = (i+1):n
153-
A[i,j] = A[j,i]
154-
end
155-
end
156-
A
157-
end
158-
159-
function symmetrize_conj!(A::StridedMatrix, uplo::Char='U')
160-
n = chksquare(A)
161-
@chkuplo
162-
if uplo == 'U'
163-
for i = 1:(n-1), j = (i+1):n
164-
A[j,i] = conj(A[i,j])
165-
end
166-
else #uplo == 'L'
167-
for i = 1:(n-1), j = (i+1):n
168-
A[i,j] = conj(A[j,i])
153+
A[i,j] = conjugate ? conj(A[j,i]) : A[j,i]
169154
end
155+
else
156+
throw(ArgumentError("second argument must be 'U' or 'L'"))
170157
end
171158
A
172159
end
@@ -200,7 +187,7 @@ function syrk_wrapper{T<:BlasFloat}(tA::Char, A::StridedMatrix{T})
200187
if mA == 3 && nA == 3; return matmul3x3(tA,tAt,A,A); end
201188

202189
stride(A, 1) == 1 || (return generic_matmatmul(tA, tAt, A, A))
203-
symmetrize!(BLAS.syrk('U', tA, one(T), A))
190+
copytri!(BLAS.syrk('U', tA, one(T), A), 'U')
204191
end
205192

206193
function herk_wrapper{T<:BlasFloat}(tA::Char, A::StridedMatrix{T})
@@ -220,7 +207,7 @@ function herk_wrapper{T<:BlasFloat}(tA::Char, A::StridedMatrix{T})
220207
# Result array does not need to be initialized as long as beta==0
221208
# C = Array(T, mA, mA)
222209

223-
symmetrize_conj!(BLAS.herk('U', tA, one(T), A))
210+
copytri!(BLAS.herk('U', tA, one(T), A), 'U', true)
224211
end
225212

226213
function gemm_wrapper{T<:BlasFloat}(tA::Char, tB::Char,

base/linalg/symmetric.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function copy!(A::Symmetric, B::Symmetric)
1717
end
1818
size(A::Symmetric, args...) = size(A.S, args...)
1919
getindex(A::Symmetric, i::Integer, j::Integer) = (A.uplo == 'U') == (i < j) ? getindex(A.S, i, j) : getindex(A.S, j, i)
20-
full(A::Symmetric) = symmetrize!(A.S, A.uplo)
20+
full(A::Symmetric) = copytri!(A.S, A.uplo)
2121
ishermitian{T<:Real}(A::Symmetric{T}) = true
2222
ishermitian{T<:Complex}(A::Symmetric{T}) = all(imag(A.S) .== 0)
2323
issym(A::Symmetric) = true
@@ -57,10 +57,10 @@ function sqrtm{T<:Real}(A::Symmetric{T}, cond::Bool)
5757
F = eigfact(A)
5858
vsqrt = sqrt(complex(F[:values]))
5959
if all(imag(vsqrt) .== 0)
60-
retmat = symmetrize!(scale(F[:vectors], real(vsqrt)) * F[:vectors]')
60+
retmat = copytri!(scale(F[:vectors], real(vsqrt)) * F[:vectors]', 'U')
6161
else
6262
zc = complex(F[:vectors])
63-
retmat = symmetrize!(scale(zc, vsqrt) * zc')
63+
retmat = copytri!(scale(zc, vsqrt) * zc', 'U')
6464
end
6565
cond ? (retmat, norm(vsqrt, Inf)^2/norm(F[:values], Inf)) : retmat
6666
end

base/linalg/triangular.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ getindex{T}(A::Triangular{T}, i::Integer, j::Integer) = i == j ? (A.unitdiag ==
8989
istril(A::Triangular) = A.uplo == 'L' || istriu(A.UL)
9090
istriu(A::Triangular) = A.uplo == 'U' || istril(A.UL)
9191

92-
transpose(A::Triangular) = Triangular(symmetrize!(A.UL, A.uplo), A.uplo=='U'?'L':'U', A.unitdiag)
93-
ctranspose(A::Triangular) = Triangular(symmetrize_conj!(A.UL, A.uplo), A.uplo=='U'?'L':'U', A.unitdiag)
92+
transpose(A::Triangular) = Triangular(copytri!(A.UL, A.uplo), A.uplo=='U'?'L':'U', A.unitdiag)
93+
ctranspose(A::Triangular) = Triangular(copytri!(A.UL, A.uplo, true), A.uplo=='U'?'L':'U', A.unitdiag)
9494
diag(A::Triangular) = diag(A.UL)
9595
big(A::Triangular) = Triangular(big(A.UL), A.uplo, A.unitdiag)
9696

doc/stdlib/linalg.rst

-6
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,6 @@ Linear algebra functions in Julia are largely implemented by calling functions f
246246
``A`` by ``b[i]`` (similar to ``diagm(b)*A``), again operating in-place
247247
on ``A``.
248248

249-
.. function:: symmetrize!(A[, UL::Char])
250-
251-
``symmetrize!(A)`` converts from the BLAS/LAPACK symmetric storage
252-
format, in which only the ``UL`` ('U'pper or 'L'ower, default 'U')
253-
triangle is used, to a full symmetric matrix.
254-
255249
.. function:: Tridiagonal(dl, d, du)
256250

257251
Construct a tridiagonal matrix from the lower diagonal, diagonal, and upper diagonal, respectively. The result is of type ``Tridiagonal`` and provides efficient specialized linear solvers, but may be converted into a regular matrix with ``full``.

test/blas.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ for elty in (Float32, Float64, Complex64, Complex128)
7777
@test all(tril(BLAS.herk('L', 'C', L4)) .== tril(BLAS.gemm('T', 'N', L4, L4)))
7878
ans = similar(L4)
7979
@test all(tril(BLAS.herk('L','C', L4)) .== tril(BLAS.herk!('L', 'C', one(elty), L4, zero(elty), ans)))
80-
@test all(symmetrize!(ans, 'L') .== LinAlg.BLAS.gemm('T', 'N', L4, L4))
80+
@test all(Base.LinAlg.copytri!(ans, 'L') .== LinAlg.BLAS.gemm('T', 'N', L4, L4))
8181
else
8282
@test all(triu(BLAS.syrk('U', 'N', U4)) .== triu(BLAS.gemm('N', 'T', U4, U4)))
8383
@test all(tril(BLAS.syrk('L', 'N', U4)) .== tril(BLAS.gemm('N', 'T', U4, U4)))
@@ -89,6 +89,6 @@ for elty in (Float32, Float64, Complex64, Complex128)
8989
@test all(tril(BLAS.syrk('L', 'T', L4)) .== tril(BLAS.gemm('T', 'N', L4, L4)))
9090
ans = similar(L4)
9191
@test all(tril(BLAS.syrk('L','T', L4)) .== tril(BLAS.syrk!('L', 'T', one(elty), L4, zero(elty), ans)))
92-
@test all(symmetrize!(ans, 'L') .== BLAS.gemm('T', 'N', L4, L4))
92+
@test all(Base.LinAlg.copytri!(ans, 'L') .== BLAS.gemm('T', 'N', L4, L4))
9393
end
9494
end

0 commit comments

Comments
 (0)