22
33# Theoretically CHOLMOD supports both Int32 and Int64 indices on 64-bit.
44# However experience suggests that using both in the same session causes memory
5- # leaks, so we restrict indices to be `SuiteSparse_long`.
5+ # leaks, so we restrict indices to be Sys.WORD_SIZE
66# Ref: https://github.com/JuliaLang/julia/issues/12664
77
88# Additionally, only Float64/ComplexF64 are supported in practice.
@@ -39,8 +39,8 @@ import ..LibSuiteSparse: TRUE, FALSE, CHOLMOD_INT, CHOLMOD_INTLONG, CHOLMOD_LONG
3939
4040# # itype defines the types of integer used:
4141# CHOLMOD_INT, # all integer arrays are int
42- # CHOLMOD_INTLONG, # most are int, some are SuiteSparse_long
43- # CHOLMOD_LONG, # all integer arrays are SuiteSparse_long
42+ # CHOLMOD_INTLONG, # most are int, some are Sys.WORD_SIZE
43+ # CHOLMOD_LONG, # all integer arrays are Sys.WORD_SIZE
4444# # dtype defines what the numerical type is (double or float):
4545# CHOLMOD_DOUBLE, # all numerical values are double
4646# CHOLMOD_SINGLE, # all numerical values are float
@@ -83,22 +83,21 @@ xtyp(::Type{Float64}) = CHOLMOD_REAL
8383xtyp (:: Type{ComplexF32} ) = CHOLMOD_COMPLEX
8484xtyp (:: Type{ComplexF64} ) = CHOLMOD_COMPLEX
8585
86- # check the size of SuiteSparse_long
87- if sizeof (Int) == 4
88- const IndexTypes = (:Int32 ,)
89- const ITypes = Union{Int32}
90- else
86+ if Sys. WORD_SIZE == 64
9187 const IndexTypes = (:Int32 , :Int64 )
9288 const ITypes = Union{Int32, Int64}
89+ else
90+ const IndexTypes = (:Int32 ,)
91+ const ITypes = Union{Int32}
9392end
94- # end
93+
9594ityp (:: Type{Int32} ) = CHOLMOD_INT
9695ityp (:: Type{Int64} ) = CHOLMOD_LONG
9796
98- jlitype (t) = t == CHOLMOD_INT ? Int32 :
97+ jlitype (t) = t == CHOLMOD_INT ? Int32 :
9998 (t == CHOLMOD_LONG ? Int64 : throw (CHOLMODException (" Unsupported itype $t " )))
10099
101- cholname (name:: Symbol , type) = type === :Int64 ? Symbol (:cholmod_l_ , name) :
100+ cholname (name:: Symbol , type) = type === :Int64 ? Symbol (:cholmod_l_ , name) :
102101 type === :Int32 ? Symbol (:cholmod_ , name) : throw (ArgumentError (" Unsupported type: $type " ))
103102
104103const VTypes = Union{ComplexF64, Float64}
@@ -508,7 +507,7 @@ for TI ∈ IndexTypes
508507 packed:: Cint
509508 cholmod_sparse_struct () = new ()
510509 end
511-
510+
512511 typedpointer (x:: Sparse{<:Any, $TI} ) = Ptr {$(cholname(:sparse_struct_typed, TI))} (pointer (x))
513512
514513 mutable struct $ (cholname (:factor_struct_typed , TI))
@@ -553,13 +552,13 @@ for TI ∈ IndexTypes
553552 end
554553 function allocate_sparse (nrow:: Integer , ncol:: Integer , nzmax:: Integer ,
555554 sorted:: Bool , packed:: Bool , stype:: Integer , :: Type{Tv} , :: Type{$TI} ) where {Tv<: VTypes }
556- Sparse {Tv, $TI} ($ (cholname (:allocate_sparse , TI))(nrow, ncol, nzmax, sorted,
555+ Sparse {Tv, $TI} ($ (cholname (:allocate_sparse , TI))(nrow, ncol, nzmax, sorted,
557556 packed, stype, xtyp (Tv), getcommon ($ TI)))
558557 end
559558 function free! (ptr:: Ptr{cholmod_sparse} , :: Type{$TI} )
560559 $ (cholname (:free_sparse , TI))(Ref (ptr), getcommon ($ TI)) == TRUE
561560 end
562-
561+
563562 function free! (ptr:: Ptr{cholmod_factor} , :: Type{$TI} )
564563 # Warning! Important that finalizer doesn't modify the global Common struct.
565564 $ (cholname (:free_factor , TI))(Ref (ptr), getcommon ($ TI)) == TRUE
@@ -587,7 +586,7 @@ for TI ∈ IndexTypes
587586 function check_sparse (A:: Sparse{Tv, $TI} ) where Tv<: VTypes
588587 $ (cholname (:check_sparse , TI))(A, getcommon ($ TI)) != 0
589588 end
590-
589+
591590 function check_factor (F:: Factor{Tv, $TI} ) where Tv<: VTypes
592591 $ (cholname (:check_factor , TI))(F, getcommon ($ TI)) != 0
593592 end
@@ -596,7 +595,7 @@ for TI ∈ IndexTypes
596595 function speye (m:: Integer , n:: Integer , :: Type{Tv} , :: Type{$TI} ) where Tv<: VTypes
597596 Sparse {Tv, $TI} ($ (cholname (:speye , TI))(m, n, xtyp (Tv), getcommon ($ TI)))
598597 end
599-
598+
600599 function spzeros (m:: Integer , n:: Integer , nzmax:: Integer , :: Type{Tv} , :: Type{$TI} ) where Tv<: VTypes
601600 Sparse {Tv, $TI} ($ (cholname (:spzeros , TI))(m, n, nzmax, xtyp (Tv), getcommon ($ TI)))
602601 end
0 commit comments