Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflow for cholfact(::SparseMatrixCSC{Float32,Int}) (and the possible return of float64?) #14076

Closed
timholy opened this issue Nov 20, 2015 · 3 comments
Labels
sparse Sparse arrays

Comments

@timholy
Copy link
Member

timholy commented Nov 20, 2015

julia> S = sparse([1,2],[1,2],Float32[1,1])
2x2 sparse matrix with 2 Float32 entries:
        [1, 1]  =  1.0
        [2, 2]  =  1.0

julia> cholfact(S)
ERROR: StackOverflowError:
 [inlined code] from essentials.jl:204
 in copy at array.jl:154
 in float at sparse/sparsematrix.jl:251
 in call at essentials.jl:58 (repeats 508 times)

The proximal cause is

julia> @which convert(Base.SparseArrays.CHOLMOD.Sparse, S)
convert{T}(::Type{Base.SparseArrays.CHOLMOD.Sparse{Tv<:Union{Complex{Float64},Float64}}}, A::Union{Hermitian{T,SparseMatrixCSC{T,Int64}},SparseMatrixCSC{T,Int64},Symmetric{T,SparseMatrixCSC{T,Int64}}}, args...) at sparse/cholmod.jl:875

at this line: float(A) will just pass-through a Float32 array, but Sparse insists on Float64:

julia> Base.SparseArrays.CHOLMOD.VTypes
Union{Complex{Float64},Float64}

There seem to be several potential ways to solve this:

  • (challenging but awesome) Support single-precision in CHOLMOD
  • (easiest but perhaps short-sighted) Don't use a Union, specialize that function on each type so the conversion can be written out explicitly
  • (orthogonal to the first, redundant with the second) Bring back float64 or similar, which means "I don't care what the container type is, but make sure its internal storage is always Float64."

On the last option, I've noticed some reason for this elsewhere; I don't really want to have to say convert(Image{base_colorant_type(eltype(img)){Float64}}, img) just to convert from a UFixed8 internal representation to a Float64 internal representation.

@tkelman tkelman added the sparse Sparse arrays label Nov 20, 2015
@andreasnoack
Copy link
Member

(challenging but awesome) Support single-precision in CHOLMOD

From cholmod_internal.h

* This gives 6 different modes in which CHOLMOD can be compiled (only the
 * first two are currently supported):
 *
 *  DINT    double, int         prefix: cholmod_
 *  DLONG   double, SuiteSparse_long    prefix: cholmod_l_
 *  DMIX    double, mixed int/SuiteSparse_long  prefix: cholmod_m_
 *  SINT    float, int          prefix: cholmod_si_
 *  SLONG   float, SuiteSparse_long     prefix: cholmod_sl_
 *  SMIX    float, mixed int/log        prefix: cholmod_sm_

 * FUTURE WORK: support all six types (float, and mixed int/long)

so it would indeed be a challenging way of fixing this issue.

@timholy
Copy link
Member Author

timholy commented Nov 23, 2015

Ah, I hadn't caught the "only the first two are currently supported" part. You're right about the challenge level!

@jiahao
Copy link
Member

jiahao commented Nov 23, 2015

Just round everything off to float32 and we're golden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparse Sparse arrays
Projects
None yet
Development

No branches or pull requests

4 participants