Skip to content

Commit 62b55ce

Browse files
committed
Revert "Remove redundant uplo argument in chol family. When using Hermitian (#17909)"
This reverts commit d992f3d.
1 parent 75a347f commit 62b55ce

File tree

4 files changed

+56
-66
lines changed

4 files changed

+56
-66
lines changed

base/deprecated.jl

-3
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,6 @@ function transpose(x)
775775
return x
776776
end
777777

778-
@deprecate cholfact!(A::Base.LinAlg.HermOrSym, uplo::Symbol, ::Type{Val{false}}) cholfact!(A, Val{false})
779-
@deprecate cholfact!(A::Base.LinAlg.HermOrSym, uplo::Symbol = :U) cholfact!(A)
780-
781778
# During the 0.5 development cycle, do not add any deprecations below this line
782779
# To be deprecated in 0.6
783780

base/linalg/cholesky.jl

+45-52
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ non_hermitian_error(f) = throw(ArgumentError("matrix is not symmetric/" *
121121

122122
# chol!. Destructive methods for computing Cholesky factor of real symmetric or Hermitian
123123
# matrix
124-
chol!(A::Hermitian) =
125-
_chol!(A.uplo == 'U' ? A.data : LinAlg.copytri!(A.data, 'L', true), UpperTriangular)
126-
chol!{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}) =
127-
_chol!(A.uplo == 'U' ? A.data : LinAlg.copytri!(A.data, 'L', true), UpperTriangular)
124+
chol!(A::Hermitian) = _chol!(A.data, UpperTriangular)
125+
chol!{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}) = _chol!(A.data, UpperTriangular)
128126
function chol!(A::StridedMatrix)
129127
ishermitian(A) || non_hermitian_error("chol!")
130128
return _chol!(A, UpperTriangular)
@@ -137,22 +135,14 @@ end
137135
function chol(A::Hermitian)
138136
T = promote_type(typeof(chol(one(eltype(A)))), Float32)
139137
AA = similar(A, T, size(A))
140-
if A.uplo == 'U'
141-
copy!(AA, A.data)
142-
else
143-
Base.ccopy!(AA, A.data)
144-
end
145-
chol!(Hermitian(AA, :U))
138+
copy!(AA, A.data)
139+
chol!(Hermitian(AA))
146140
end
147141
function chol{T<:Real,S<:AbstractMatrix}(A::Symmetric{T,S})
148142
TT = promote_type(typeof(chol(one(T))), Float32)
149143
AA = similar(A, TT, size(A))
150-
if A.uplo == 'U'
151-
copy!(AA, A.data)
152-
else
153-
Base.ccopy!(AA, A.data)
154-
end
155-
chol!(Hermitian(AA, :U))
144+
copy!(AA, A.data)
145+
chol!(Hermitian(AA))
156146
end
157147

158148
## for StridedMatrices, check that matrix is symmetric/Hermitian
@@ -180,15 +170,15 @@ chol(x::Number, args...) = _chol!(x, nothing)
180170
# cholfact!. Destructive methods for computing Cholesky factorization of real symmetric
181171
# or Hermitian matrix
182172
## No pivoting
183-
function cholfact!(A::Hermitian, ::Type{Val{false}})
184-
if A.uplo == :U
173+
function cholfact!(A::Hermitian, uplo::Symbol, ::Type{Val{false}})
174+
if uplo == :U
185175
Cholesky(_chol!(A.data, UpperTriangular).data, 'U')
186176
else
187177
Cholesky(_chol!(A.data, LowerTriangular).data, 'L')
188178
end
189179
end
190-
function cholfact!{T<:Real,S}(A::Symmetric{T,S}, ::Type{Val{false}})
191-
if A.uplo == :U
180+
function cholfact!{T<:Real,S}(A::Symmetric{T,S}, uplo::Symbol, ::Type{Val{false}})
181+
if uplo == :U
192182
Cholesky(_chol!(A.data, UpperTriangular).data, 'U')
193183
else
194184
Cholesky(_chol!(A.data, LowerTriangular).data, 'L')
@@ -197,7 +187,7 @@ end
197187

198188
### for StridedMatrices, check that matrix is symmetric/Hermitian
199189
"""
200-
cholfact!(A, [uplo::Symbol,] Val{false}) -> Cholesky
190+
cholfact!(A, uplo::Symbol, Val{false}) -> Cholesky
201191
202192
The same as `cholfact`, but saves space by overwriting the input `A`, instead
203193
of creating a copy. An `InexactError` exception is thrown if the factorisation
@@ -206,36 +196,37 @@ integer types.
206196
"""
207197
function cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}})
208198
ishermitian(A) || non_hermitian_error("cholfact!")
209-
return cholfact!(Hermitian(A, uplo), Val{false})
199+
return cholfact!(Hermitian(A), uplo, Val{false})
210200
end
211201

212202
### Default to no pivoting (and storing of upper factor) when not explicit
213-
cholfact!(A::Hermitian) = cholfact!(A, Val{false})
214-
cholfact!{T<:Real,S}(A::Symmetric{T,S}) = cholfact!(A, Val{false})
203+
cholfact!(A::Hermitian, uplo::Symbol = :U) = cholfact!(A, uplo, Val{false})
204+
cholfact!{T<:Real,S}(A::Symmetric{T,S}, uplo::Symbol = :U) = cholfact!(A, uplo, Val{false})
215205
#### for StridedMatrices, check that matrix is symmetric/Hermitian
216206
function cholfact!(A::StridedMatrix, uplo::Symbol = :U)
217207
ishermitian(A) || non_hermitian_error("cholfact!")
218-
return cholfact!(Hermitian(A, uplo))
208+
return cholfact!(Hermitian(A), uplo)
219209
end
220210

221211

222212
## With pivoting
223213
### BLAS/LAPACK element types
224214
function cholfact!{T<:BlasReal,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S},
225-
::Type{Val{true}}; tol = 0.0)
226-
AA, piv, rank, info = LAPACK.pstrf!(A.uplo, A.data, tol)
227-
return CholeskyPivoted{eltype(AA),typeof(AA)}(AA, A.uplo, piv, rank, tol, info)
215+
uplo::Symbol, ::Type{Val{true}}; tol = 0.0)
216+
uplochar = char_uplo(uplo)
217+
AA, piv, rank, info = LAPACK.pstrf!(uplochar, A.data, tol)
218+
return CholeskyPivoted{eltype(AA),typeof(AA)}(AA, uplochar, piv, rank, tol, info)
228219
end
229220

230221
### Non BLAS/LAPACK element types (generic). Since generic fallback for pivoted Cholesky
231222
### is not implemented yet we throw an error
232-
cholfact!{T<:Real,S}(A::RealHermSymComplexHerm{T,S}, ::Type{Val{true}};
223+
cholfact!{T<:Real,S}(A::RealHermSymComplexHerm{T,S}, uplo::Symbol, ::Type{Val{true}};
233224
tol = 0.0) =
234225
throw(ArgumentError("generic pivoted Cholesky factorization is not implemented yet"))
235226

236227
### for StridedMatrices, check that matrix is symmetric/Hermitian
237228
"""
238-
cholfact!(A, [uplo::Symbol,] Val{true}; tol = 0.0) -> CholeskyPivoted
229+
cholfact!(A, uplo::Symbol, Val{true}; tol = 0.0) -> CholeskyPivoted
239230
240231
The same as `cholfact`, but saves space by overwriting the input `A`, instead
241232
of creating a copy. An `InexactError` exception is thrown if the
@@ -244,61 +235,63 @@ e.g. for integer types.
244235
"""
245236
function cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{true}}; tol = 0.0)
246237
ishermitian(A) || non_hermitian_error("cholfact!")
247-
return cholfact!(Hermitian(A, uplo), Val{true}; tol = tol)
238+
return cholfact!(Hermitian(A), uplo, Val{true}; tol = tol)
248239
end
249240

241+
242+
250243
# cholfact. Non-destructive methods for computing Cholesky factorization of real symmetric
251244
# or Hermitian matrix
252245
## No pivoting
253-
cholfact(A::Hermitian, ::Type{Val{false}}) =
254-
cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), Val{false})
255-
cholfact{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}, ::Type{Val{false}}) =
256-
cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), Val{false})
246+
cholfact(A::Hermitian, uplo::Symbol, ::Type{Val{false}}) =
247+
cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), uplo, Val{false})
248+
cholfact{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}, uplo::Symbol, ::Type{Val{false}}) =
249+
cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)), uplo, Val{false})
257250

258251
### for StridedMatrices, check that matrix is symmetric/Hermitian
259252
"""
260-
cholfact(A, [uplo::Symbol,] Val{false}) -> Cholesky
253+
cholfact(A, uplo::Symbol, Val{false}) -> Cholesky
261254
262255
Compute the Cholesky factorization of a dense symmetric positive definite matrix `A`
263-
and return a `Cholesky` factorization. The matrix `A` can either be a `Symmetric` or `Hermitian`
264-
`StridedMatrix` or a *perfectly* symmetric or Hermitian `StridedMatrix`. In the latter case,
265-
the optional argument `uplo` may be `:L` for using the lower part or `:U` for the upper part of `A`.
256+
and return a `Cholesky` factorization.
257+
The `uplo` argument may be `:L` for using the lower part or `:U` for the upper part of `A`.
266258
The default is to use `:U`.
267259
The triangular Cholesky factor can be obtained from the factorization `F` with: `F[:L]` and `F[:U]`.
268260
The following functions are available for `Cholesky` objects: `size`, `\\`, `inv`, `det`.
269261
A `PosDefException` exception is thrown in case the matrix is not positive definite.
270262
"""
271263
function cholfact(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}})
272264
ishermitian(A) || non_hermitian_error("cholfact")
273-
return cholfact(Hermitian(A, uplo), Val{false})
265+
return cholfact(Hermitian(A), uplo, Val{false})
274266
end
275267

276268
### Default to no pivoting (and storing of upper factor) when not explicit
277-
cholfact(A::Hermitian) = cholfact(A, Val{false})
278-
cholfact{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}) = cholfact(A, Val{false})
269+
cholfact(A::Hermitian, uplo::Symbol = :U) = cholfact(A, uplo, Val{false})
270+
cholfact{T<:Real,S<:StridedMatrix}(A::Symmetric{T,S}, uplo::Symbol = :U) =
271+
cholfact(A, uplo, Val{false})
279272
#### for StridedMatrices, check that matrix is symmetric/Hermitian
280273
function cholfact(A::StridedMatrix, uplo::Symbol = :U)
281274
ishermitian(A) || non_hermitian_error("cholfact")
282-
return cholfact(Hermitian(A, uplo))
275+
return cholfact(Hermitian(A), uplo)
283276
end
284277

285278

286279
## With pivoting
287-
cholfact(A::Hermitian, ::Type{Val{true}}; tol = 0.0) =
280+
cholfact(A::Hermitian, uplo::Symbol, ::Type{Val{true}}; tol = 0.0) =
288281
cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)),
289-
Val{true}; tol = tol)
290-
cholfact{T<:Real,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, ::Type{Val{true}}; tol = 0.0) =
282+
uplo, Val{true}; tol = tol)
283+
cholfact{T<:Real,S<:StridedMatrix}(A::RealHermSymComplexHerm{T,S}, uplo::Symbol,
284+
::Type{Val{true}}; tol = 0.0) =
291285
cholfact!(copy_oftype(A, promote_type(typeof(chol(one(eltype(A)))),Float32)),
292-
Val{true}; tol = tol)
286+
uplo, Val{true}; tol = tol)
293287

294288
### for StridedMatrices, check that matrix is symmetric/Hermitian
295289
"""
296-
cholfact(A, [uplo::Symbol,] Val{true}; tol = 0.0) -> CholeskyPivoted
290+
cholfact(A, uplo::Symbol, Val{true}; tol = 0.0) -> CholeskyPivoted
297291
298292
Compute the pivoted Cholesky factorization of a dense symmetric positive semi-definite matrix `A`
299-
and return a `CholeskyPivoted` factorization. The matrix `A` can either be a `Symmetric` or `Hermitian`
300-
`StridedMatrix` or a *perfectly* symmetric or Hermitian `StridedMatrix`. In the latter case,
301-
the optional argument `uplo` may be `:L` for using the lower part or `:U` for the upper part of `A`.
293+
and return a `CholeskyPivoted` factorization.
294+
The `uplo` argument may be `:L` for using the lower part or `:U` for the upper part of `A`.
302295
The default is to use `:U`.
303296
The triangular Cholesky factor can be obtained from the factorization `F` with: `F[:L]` and `F[:U]`.
304297
The following functions are available for `PivotedCholesky` objects: `size`, `\\`, `inv`, `det`, and `rank`.
@@ -307,7 +300,7 @@ For negative values, the tolerance is the machine precision.
307300
"""
308301
function cholfact(A::StridedMatrix, uplo::Symbol, ::Type{Val{true}}; tol = 0.0)
309302
ishermitian(A) || non_hermitian_error("cholfact")
310-
return cholfact(Hermitian(A, uplo), Val{true}; tol = tol)
303+
return cholfact(Hermitian(A), uplo, Val{true}; tol = tol)
311304
end
312305

313306
## Number

doc/stdlib/linalg.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,17 @@ Linear algebra functions in Julia are largely implemented by calling functions f
308308
309309
Compute the square root of a non-negative number ``x``\ .
310310

311-
.. function:: cholfact(A, [uplo::Symbol,] Val{false}) -> Cholesky
311+
.. function:: cholfact(A, uplo::Symbol, Val{false}) -> Cholesky
312312

313313
.. Docstring generated from Julia source
314314
315-
Compute the Cholesky factorization of a dense symmetric positive definite matrix ``A`` and return a ``Cholesky`` factorization. The matrix ``A`` can either be a ``Symmetric`` or ``Hermitian`` ``StridedMatrix`` or a *perfectly* symmetric or Hermitian ``StridedMatrix``\ . In the latter case, the optional argument ``uplo`` may be ``:L`` for using the lower part or ``:U`` for the upper part of ``A``\ . The default is to use ``:U``\ . The triangular Cholesky factor can be obtained from the factorization ``F`` with: ``F[:L]`` and ``F[:U]``\ . The following functions are available for ``Cholesky`` objects: ``size``\ , ``\``\ , ``inv``\ , ``det``\ . A ``PosDefException`` exception is thrown in case the matrix is not positive definite.
315+
Compute the Cholesky factorization of a dense symmetric positive definite matrix ``A`` and return a ``Cholesky`` factorization. The ``uplo`` argument may be ``:L`` for using the lower part or ``:U`` for the upper part of ``A``\ . The default is to use ``:U``\ . The triangular Cholesky factor can be obtained from the factorization ``F`` with: ``F[:L]`` and ``F[:U]``\ . The following functions are available for ``Cholesky`` objects: ``size``\ , ``\``\ , ``inv``\ , ``det``\ . A ``PosDefException`` exception is thrown in case the matrix is not positive definite.
316316

317-
.. function:: cholfact(A, [uplo::Symbol,] Val{true}; tol = 0.0) -> CholeskyPivoted
317+
.. function:: cholfact(A, uplo::Symbol, Val{true}; tol = 0.0) -> CholeskyPivoted
318318

319319
.. Docstring generated from Julia source
320320
321-
Compute the pivoted Cholesky factorization of a dense symmetric positive semi-definite matrix ``A`` and return a ``CholeskyPivoted`` factorization. The matrix ``A`` can either be a ``Symmetric`` or ``Hermitian`` ``StridedMatrix`` or a *perfectly* symmetric or Hermitian ``StridedMatrix``\ . In the latter case, the optional argument ``uplo`` may be ``:L`` for using the lower part or ``:U`` for the upper part of ``A``\ . The default is to use ``:U``\ . The triangular Cholesky factor can be obtained from the factorization ``F`` with: ``F[:L]`` and ``F[:U]``\ . The following functions are available for ``PivotedCholesky`` objects: ``size``\ , ``\``\ , ``inv``\ , ``det``\ , and ``rank``\ . The argument ``tol`` determines the tolerance for determining the rank. For negative values, the tolerance is the machine precision.
321+
Compute the pivoted Cholesky factorization of a dense symmetric positive semi-definite matrix ``A`` and return a ``CholeskyPivoted`` factorization. The ``uplo`` argument may be ``:L`` for using the lower part or ``:U`` for the upper part of ``A``\ . The default is to use ``:U``\ . The triangular Cholesky factor can be obtained from the factorization ``F`` with: ``F[:L]`` and ``F[:U]``\ . The following functions are available for ``PivotedCholesky`` objects: ``size``\ , ``\``\ , ``inv``\ , ``det``\ , and ``rank``\ . The argument ``tol`` determines the tolerance for determining the rank. For negative values, the tolerance is the machine precision.
322322

323323
.. function:: cholfact(A; shift = 0.0, perm = Int[]) -> CHOLMOD.Factor
324324

@@ -344,13 +344,13 @@ Linear algebra functions in Julia are largely implemented by calling functions f
344344
This method uses the CHOLMOD library from SuiteSparse, which only supports doubles or complex doubles. Input matrices not of those element types will be converted to ``SparseMatrixCSC{Float64}`` or ``SparseMatrixCSC{Complex128}`` as appropriate.
345345

346346

347-
.. function:: cholfact!(A, [uplo::Symbol,] Val{false}) -> Cholesky
347+
.. function:: cholfact!(A, uplo::Symbol, Val{false}) -> Cholesky
348348

349349
.. Docstring generated from Julia source
350350
351351
The same as ``cholfact``\ , but saves space by overwriting the input ``A``\ , instead of creating a copy. An ``InexactError`` exception is thrown if the factorisation produces a number not representable by the element type of ``A``\ , e.g. for integer types.
352352

353-
.. function:: cholfact!(A, [uplo::Symbol,] Val{true}; tol = 0.0) -> CholeskyPivoted
353+
.. function:: cholfact!(A, uplo::Symbol, Val{true}; tol = 0.0) -> CholeskyPivoted
354354

355355
.. Docstring generated from Julia source
356356

test/linalg/cholesky.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
7474
@test full(lapd) apd
7575
l = lapd[:L]
7676
@test l*l' apd
77-
@test capd[:U] lapd[:U]
78-
@test lapd[:L] capd[:L]
77+
@test triu(capd.factors) lapd[:U]
78+
@test tril(lapd.factors) capd[:L]
7979
if eltya <: Real
8080
capds = cholfact(apds)
81-
lapds = cholfact(full(apds), :L)
81+
lapds = cholfact(apds, :L)
8282
ls = lapds[:L]
8383
@test ls*ls' apd
84-
@test capds[:U] lapds[:U]
85-
@test lapds[:L] capds[:L]
84+
@test triu(capds.factors) lapds[:U]
85+
@test tril(lapds.factors) capds[:L]
8686
end
8787

8888
#pivoted upper Cholesky

0 commit comments

Comments
 (0)