Skip to content

Commit 1207f3c

Browse files
timholydkarrasch
authored andcommitted
Add missing convert methods for Cholesky (#56562)
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
1 parent e451927 commit 1207f3c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/cholesky.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,16 @@ function Cholesky{T}(C::Cholesky) where T
631631
Cnew = convert(AbstractMatrix{T}, C.factors)
632632
Cholesky{T, typeof(Cnew)}(Cnew, C.uplo, C.info)
633633
end
634+
Cholesky{T,S}(C::Cholesky) where {T,S<:AbstractMatrix} = Cholesky{T,S}(C.factors, C.uplo, C.info)
634635
Factorization{T}(C::Cholesky{T}) where {T} = C
635636
Factorization{T}(C::Cholesky) where {T} = Cholesky{T}(C)
636637
CholeskyPivoted{T}(C::CholeskyPivoted{T}) where {T} = C
637638
CholeskyPivoted{T}(C::CholeskyPivoted) where {T} =
638-
CholeskyPivoted(AbstractMatrix{T}(C.factors),C.uplo,C.piv,C.rank,C.tol,C.info)
639+
CholeskyPivoted(AbstractMatrix{T}(C.factors), C.uplo, C.piv, C.rank, C.tol, C.info)
640+
CholeskyPivoted{T,S}(C::CholeskyPivoted) where {T,S<:AbstractMatrix} =
641+
CholeskyPivoted{T,S,typeof(C.piv)}(C.factors, C.uplo, C.piv, C.rank, C.tol, C.info)
642+
CholeskyPivoted{T,S,P}(C::CholeskyPivoted) where {T,S<:AbstractMatrix,P<:AbstractVector{<:Integer}} =
643+
CholeskyPivoted{T,S,P}(C.factors, C.uplo, C.piv, C.rank, C.tol, C.info)
639644
Factorization{T}(C::CholeskyPivoted{T}) where {T} = C
640645
Factorization{T}(C::CholeskyPivoted) where {T} = CholeskyPivoted{T}(C)
641646

test/cholesky.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,24 @@ end
281281
end
282282
end
283283
end
284+
285+
@testset "eltype/matrixtype conversions" begin
286+
apd = Matrix(Hermitian(areal'*areal))
287+
capd = cholesky(apd)
288+
@test convert(Cholesky{Float64}, capd) === capd
289+
@test convert(Cholesky{Float64,Matrix{Float64}}, capd) === convert(typeof(capd), capd) === capd
290+
@test eltype(convert(Cholesky{Float32}, capd)) === Float32
291+
@test eltype(convert(Cholesky{Float32,Matrix{Float32}}, capd)) === Float32
292+
293+
capd = cholesky(apd, RowMaximum())
294+
@test convert(CholeskyPivoted{Float64}, capd) === capd
295+
@test convert(CholeskyPivoted{Float64,Matrix{Float64}}, capd) === capd
296+
@test convert(CholeskyPivoted{Float64,Matrix{Float64},Vector{Int}}, capd) === convert(typeof(capd), capd) === capd
297+
@test eltype(convert(CholeskyPivoted{Float32}, capd)) === Float32
298+
@test eltype(convert(CholeskyPivoted{Float32,Matrix{Float32}}, capd)) === Float32
299+
@test eltype(convert(CholeskyPivoted{Float32,Matrix{Float32},Vector{Int}}, capd)) === Float32
300+
@test eltype(convert(CholeskyPivoted{Float32,Matrix{Float32},Vector{Int16}}, capd).piv) === Int16
301+
end
284302
end
285303

286304
@testset "behavior for non-positive definite matrices" for T in (Float64, ComplexF64, BigFloat)

0 commit comments

Comments
 (0)