2
2
3
3
# Theoretically CHOLMOD supports both Int32 and Int64 indices on 64-bit.
4
4
# 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
6
6
# Ref: https://github.com/JuliaLang/julia/issues/12664
7
7
8
8
# Additionally, only Float64/ComplexF64 are supported in practice.
@@ -39,8 +39,8 @@ import ..LibSuiteSparse: TRUE, FALSE, CHOLMOD_INT, CHOLMOD_INTLONG, CHOLMOD_LONG
39
39
40
40
# # itype defines the types of integer used:
41
41
# 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
44
44
# # dtype defines what the numerical type is (double or float):
45
45
# CHOLMOD_DOUBLE, # all numerical values are double
46
46
# CHOLMOD_SINGLE, # all numerical values are float
@@ -83,22 +83,21 @@ xtyp(::Type{Float64}) = CHOLMOD_REAL
83
83
xtyp (:: Type{ComplexF32} ) = CHOLMOD_COMPLEX
84
84
xtyp (:: Type{ComplexF64} ) = CHOLMOD_COMPLEX
85
85
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
91
87
const IndexTypes = (:Int32 , :Int64 )
92
88
const ITypes = Union{Int32, Int64}
89
+ else
90
+ const IndexTypes = (:Int32 ,)
91
+ const ITypes = Union{Int32}
93
92
end
94
- # end
93
+
95
94
ityp (:: Type{Int32} ) = CHOLMOD_INT
96
95
ityp (:: Type{Int64} ) = CHOLMOD_LONG
97
96
98
- jlitype (t) = t == CHOLMOD_INT ? Int32 :
97
+ jlitype (t) = t == CHOLMOD_INT ? Int32 :
99
98
(t == CHOLMOD_LONG ? Int64 : throw (CHOLMODException (" Unsupported itype $t " )))
100
99
101
- cholname (name:: Symbol , type) = type === :Int64 ? Symbol (:cholmod_l_ , name) :
100
+ cholname (name:: Symbol , type) = type === :Int64 ? Symbol (:cholmod_l_ , name) :
102
101
type === :Int32 ? Symbol (:cholmod_ , name) : throw (ArgumentError (" Unsupported type: $type " ))
103
102
104
103
const VTypes = Union{ComplexF64, Float64}
@@ -508,7 +507,7 @@ for TI ∈ IndexTypes
508
507
packed:: Cint
509
508
cholmod_sparse_struct () = new ()
510
509
end
511
-
510
+
512
511
typedpointer (x:: Sparse{<:Any, $TI} ) = Ptr {$(cholname(:sparse_struct_typed, TI))} (pointer (x))
513
512
514
513
mutable struct $ (cholname (:factor_struct_typed , TI))
@@ -553,13 +552,13 @@ for TI ∈ IndexTypes
553
552
end
554
553
function allocate_sparse (nrow:: Integer , ncol:: Integer , nzmax:: Integer ,
555
554
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,
557
556
packed, stype, xtyp (Tv), getcommon ($ TI)))
558
557
end
559
558
function free! (ptr:: Ptr{cholmod_sparse} , :: Type{$TI} )
560
559
$ (cholname (:free_sparse , TI))(Ref (ptr), getcommon ($ TI)) == TRUE
561
560
end
562
-
561
+
563
562
function free! (ptr:: Ptr{cholmod_factor} , :: Type{$TI} )
564
563
# Warning! Important that finalizer doesn't modify the global Common struct.
565
564
$ (cholname (:free_factor , TI))(Ref (ptr), getcommon ($ TI)) == TRUE
@@ -587,7 +586,7 @@ for TI ∈ IndexTypes
587
586
function check_sparse (A:: Sparse{Tv, $TI} ) where Tv<: VTypes
588
587
$ (cholname (:check_sparse , TI))(A, getcommon ($ TI)) != 0
589
588
end
590
-
589
+
591
590
function check_factor (F:: Factor{Tv, $TI} ) where Tv<: VTypes
592
591
$ (cholname (:check_factor , TI))(F, getcommon ($ TI)) != 0
593
592
end
@@ -596,7 +595,7 @@ for TI ∈ IndexTypes
596
595
function speye (m:: Integer , n:: Integer , :: Type{Tv} , :: Type{$TI} ) where Tv<: VTypes
597
596
Sparse {Tv, $TI} ($ (cholname (:speye , TI))(m, n, xtyp (Tv), getcommon ($ TI)))
598
597
end
599
-
598
+
600
599
function spzeros (m:: Integer , n:: Integer , nzmax:: Integer , :: Type{Tv} , :: Type{$TI} ) where Tv<: VTypes
601
600
Sparse {Tv, $TI} ($ (cholname (:spzeros , TI))(m, n, nzmax, xtyp (Tv), getcommon ($ TI)))
602
601
end
0 commit comments