Skip to content

Commit ce852af

Browse files
authored
cleanup support for Float32 and ComplexF32 (#597)
I fixed the same bug as #585, without realizing that it had already been done. It wasn't a complete waste of time, because the PR #586 left some cleanup to do: the lines ```julia LinearAlgebra.qr(A::SparseMatrixCSC{<:Union{Float16,Float32}}; tol=_default_tol(A)) = qr(convert(SparseMatrixCSC{Float64}, A); tol=tol) LinearAlgebra.qr(A::SparseMatrixCSC{<:Union{ComplexF16,ComplexF32}}; tol=_default_tol(A)) = qr(convert(SparseMatrixCSC{ComplexF64}, A); tol=tol) ``` would have prevented it from working if they actually worked! Luckily they don't, as the correct method is more specific and gets called, but it's still worth fixing. I also changed them to convert `Float16` to `Float32` instead of `Float64`, and the analogous change for complex numbers. I also fixed the error messages one gets. They were of the form "dtype=$(s.dtype) not supported", which in my case translated to saying that `Float64` wasn't supported when I tried calling it with `Float32`. `s.dtype` is the type that actually got computed, so it clearly is supported. I changed them to say "dtype=$(dtyp(Tv)) not supported".
1 parent 72c7cac commit ce852af

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/solvers/cholmod.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ mutable struct Dense{Tv<:VTypes} <: DenseMatrix{Tv}
270270
s = unsafe_load(ptr)
271271
if s.xtype != xtyp(Tv)
272272
free!(ptr)
273-
throw(CHOLMODException("xtype=$(s.xtype) not supported"))
273+
throw(CHOLMODException("xtype=$(xtyp(Tv)) not supported"))
274274
elseif s.dtype != dtyp(Tv)
275275
free!(ptr)
276-
throw(CHOLMODException("dtype=$(s.dtype) not supported"))
276+
throw(CHOLMODException("dtype=$(dtyp(Tv)) not supported"))
277277
end
278278
obj = new(ptr)
279279
finalizer(free!, obj)
@@ -294,10 +294,10 @@ mutable struct Sparse{Tv<:VTypes, Ti<:ITypes} <: AbstractSparseMatrix{Tv,Ti}
294294
throw(CHOLMODException("Ti=$Ti does not match s.itype=$(s.itype)"))
295295
elseif s.xtype != xtyp(Tv)
296296
free!(ptr, Ti)
297-
throw(CHOLMODException("xtype=$(s.xtype) not supported"))
297+
throw(CHOLMODException("xtype=$(xtyp(Tv)) not supported"))
298298
elseif s.dtype != dtyp(Tv)
299299
free!(ptr, Ti)
300-
throw(CHOLMODException("dtype=$(s.dtype) not supported"))
300+
throw(CHOLMODException("dtype=$(dtyp(Tv)) not supported"))
301301
end
302302
A = new(ptr)
303303
finalizer(free!, A)
@@ -337,10 +337,10 @@ mutable struct Factor{Tv<:VTypes, Ti<:ITypes} <: Factorization{Tv}
337337
throw(CHOLMODException("Ti=$Ti does not match s.itype=$(s.itype)"))
338338
elseif s.xtype != xtyp(Tv) && s.xtype != CHOLMOD_PATTERN
339339
free!(ptr, Ti)
340-
throw(CHOLMODException("xtype=$(s.xtype) not supported"))
340+
throw(CHOLMODException("xtype=$(xtyp(Tv)) not supported"))
341341
elseif s.dtype != dtyp(Tv)
342342
free!(ptr, Ti)
343-
throw(CHOLMODException("dtype=$(s.dtype) not supported"))
343+
throw(CHOLMODException("dtype=$(dtyp(Tv)) not supported"))
344344
end
345345
F = new(ptr)
346346
if register_finalizer

src/solvers/spqr.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ function LinearAlgebra.qr(A::SparseMatrixCSC{Tv, Ti}; tol=_default_tol(A), order
214214
nonzeros(R_)),
215215
p, hpinv)
216216
end
217-
LinearAlgebra.qr(A::SparseMatrixCSC{<:Union{Float16,Float32}}; tol=_default_tol(A)) =
218-
qr(convert(SparseMatrixCSC{Float64}, A); tol=tol)
219-
LinearAlgebra.qr(A::SparseMatrixCSC{<:Union{ComplexF16,ComplexF32}}; tol=_default_tol(A)) =
220-
qr(convert(SparseMatrixCSC{ComplexF64}, A); tol=tol)
217+
LinearAlgebra.qr(A::SparseMatrixCSC{Float16}; tol=_default_tol(A)) =
218+
qr(convert(SparseMatrixCSC{Float32}, A); tol=tol)
219+
LinearAlgebra.qr(A::SparseMatrixCSC{ComplexF16}; tol=_default_tol(A)) =
220+
qr(convert(SparseMatrixCSC{ComplexF32}, A); tol=tol)
221221
LinearAlgebra.qr(A::Union{SparseMatrixCSC{T},SparseMatrixCSC{Complex{T}}};
222222
tol=_default_tol(A)) where {T<:AbstractFloat} =
223223
throw(ArgumentError(string("matrix type ", typeof(A), "not supported. ",

test/spqr.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ end
110110
@test (F.Q*F.R)::SparseMatrixCSC == A[F.prow,F.pcol]
111111
end
112112

113-
@testset "Issue #585 for element type: $eltyA" for eltyA in (Float64, Float32)
113+
@testset "Issue #585 for element type: $eltyA" for eltyA in (Float64, Float32, ComplexF64, ComplexF32)
114114
A = sparse(eltyA[1 0; 0 1])
115115
F = qr(A)
116116
@test eltype(F.Q) == eltype(F.R) == eltyA
117117
end
118118

119+
@testset "Complementing issue #585 for element type: $eltyA" for (eltyA, eltyB) in [(Float16, Float32), (ComplexF16, ComplexF32)]
120+
A = sparse(eltyA[1 0; 0 1])
121+
F = qr(A)
122+
@test eltype(F.Q) == eltype(F.R) == eltyB
123+
end
124+
119125
@testset "select ordering overdetermined" begin
120126
A = sparse([1:n; rand(1:m, nn - n)], [1:n; rand(1:n, nn - n)], randn(nn), m, n)
121127
b = randn(m)

0 commit comments

Comments
 (0)