Skip to content

Commit a9637dd

Browse files
authored
Introduce compat bounds for SuiteSparse (#408)
* Introduce compat bounds for SuiteSparse Remove remnants from SuiteSparse 5 such as SuiteSparse_long * Fix Project.toml formatting
1 parent 2c7f4d6 commit a9637dd

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1010
SuiteSparse_jll = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
1111

1212
[compat]
13+
SuiteSparse_jll = "7.2"
14+
julia = "1.10"
1315

1416
[extras]
1517
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

src/solvers/LibSuiteSparse.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@ module LibSuiteSparse
22

33
using SuiteSparse_jll
44

5-
if Sys.WORD_SIZE == 64
6-
const SuiteSparse_long = Clonglong
7-
else
8-
const SuiteSparse_long = Clong
9-
end
10-
const SuiteSparse_long_max = typemax(SuiteSparse_long)
11-
125
const TRUE = Int32(1)
136
const FALSE = Int32(0)
14-
const int64_t = Int64
15-
const INT64_MAX = typemax(Int64)
167

178
const IS_LIBC_MUSL = occursin("musl", Base.BUILD_TRIPLET)
189
if Sys.isapple() && Sys.ARCH === :aarch64

src/solvers/cholmod.jl

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
8383
xtyp(::Type{ComplexF32}) = CHOLMOD_COMPLEX
8484
xtyp(::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}
9392
end
94-
# end
93+
9594
ityp(::Type{Int32}) = CHOLMOD_INT
9695
ityp(::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

104103
const 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

src/solvers/umfpack.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import ..increment, ..increment!, ..decrement, ..decrement!
2121

2222
using ..LibSuiteSparse
2323
import ..LibSuiteSparse:
24-
SuiteSparse_long,
2524
umfpack_dl_defaults,
2625
umfpack_dl_report_control,
2726
umfpack_dl_report_info,
@@ -141,13 +140,12 @@ macro isok(A)
141140
:(umferror($(esc(A))))
142141
end
143142

144-
# check the size of SuiteSparse_long
145-
if sizeof(SuiteSparse_long) == 4
146-
const UmfpackIndexTypes = (:Int32,)
147-
const UMFITypes = Int32
148-
else
143+
if Sys.WORD_SIZE == 64
149144
const UmfpackIndexTypes = (:Int32, :Int64)
150145
const UMFITypes = Union{Int32, Int64}
146+
else
147+
const UmfpackIndexTypes = (:Int32,)
148+
const UMFITypes = Int32
151149
end
152150

153151
const UMFVTypes = Union{Float64,ComplexF64}

0 commit comments

Comments
 (0)