SparseArrays.jl icon indicating copy to clipboard operation
SparseArrays.jl copied to clipboard

\ does not work for sparse matrices with Float32 elements

Open ViralBShah opened this issue 3 years ago • 4 comments

As discussed in https://stackoverflow.com/questions/70648351/getting-an-error-when-using-backslash-operator-on-sparse-matrix-and-dense-vector/70662601#70662601, \ does not work for sparse matrices with Float32 elements.

It would be nice to bring back Float32 support in sparse solvers. The issue is that \ calls lu!, which does not have a matching method. Naturally lu! should not promote, but \ should check and promote.

ViralBShah avatar Jan 11 '22 06:01 ViralBShah

I think the core problem is that you cannot change between float32 and float64 support in suitesparse during runtime.

Edit: Actually https://github.com/JuliaLang/julia/issues/14076#issuecomment-158998239 says that it's not even supported.

KristofferC avatar Jan 11 '22 14:01 KristofferC

It's not supported in at least UMFPACK and KLU. I think there's promotions to Float64 somewhere, they just may not be available in the \ interface. I'm not sure about CHOLMOD.

rayegun avatar Jan 11 '22 15:01 rayegun

The issue with the given problem is that the sparse matrix is recognized as Hermitian, so it gets wrapped as Hermitian(A). The next step would be that SuiteSparse.jl takes over, but it doesn't because this signature is too narrow:

https://github.com/JuliaLang/SuiteSparse.jl/blob/2f355a266ac3439c98c531f0fc774bcccb2dd43d/src/cholmod.jl#L1568-L1585

It should perhaps be widened to include all those nzval-types that get promoted to Float64 if necessary.

dkarrasch avatar Jan 15 '22 17:01 dkarrasch

Note that CHOLMOD does not support Float32, but UMFPACK does (and Julia should probably as well).

We do emit the warning for CHOLMOD

┌ Warning: 2022-06-21 14:36:17 : CHOLMOD only works with double precision. Converting single precision matrix to double
└ @ Circuitscape ~/.julia/packages/Circuitscape/XpftG/src/logging.jl:25

So what we need to do is what @dkarrasch suggests above.

ViralBShah avatar Jun 21 '22 14:06 ViralBShah