@@ -182,11 +182,11 @@ mutable struct Common
182
182
183
183
function Common ()
184
184
common = new ()
185
- @isok ccall ((@cholmod_name (" start" ), :libcholmod ),
185
+ ccall ((@cholmod_name (" start" ), :libcholmod ),
186
186
Cint, (Ptr{Common},), common)
187
187
finalizer (common) do common
188
- @isok ccall ((@cholmod_name (" finish" ), :libcholmod ),
189
- Cint, (Ptr{Common},), common)
188
+ ccall ((@cholmod_name (" finish" ), :libcholmod ),
189
+ Cint, (Ptr{Common},), common) == TRUE
190
190
end
191
191
end
192
192
end
@@ -197,7 +197,7 @@ Base.unsafe_convert(::Type{Ptr{Common}},c::Common) =
197
197
const common = Vector {Common} ()
198
198
199
199
function defaults! (common)
200
- @isok ccall ((@cholmod_name (" defaults" ), :libcholmod ),
200
+ ccall ((@cholmod_name (" defaults" ), :libcholmod ),
201
201
Cint, (Ptr{Common},), common)
202
202
return common
203
203
end
@@ -274,9 +274,11 @@ function __init__()
274
274
# ## to temporary memory. We need to manage a copy for each thread.
275
275
nt = Threads. nthreads ()
276
276
resize! (common, nt)
277
+ errorhandler = @cfunction (error_handler, Cvoid, (Cint, Cstring, Cint, Cstring))
277
278
for i in 1 : nt
278
279
common[i] = Common ()
279
280
common[i]. print = 0 # no printing from CHOLMOD by default
281
+ common[i]. error_handler = errorhandler
280
282
end
281
283
282
284
# Register gc tracked allocator if CHOLMOD is new enough
@@ -518,9 +520,9 @@ function allocate_dense(m::Integer, n::Integer, d::Integer, ::Type{Tv}) where {T
518
520
end
519
521
520
522
function free! (p:: Ptr{C_Dense{Tv}} ) where {Tv<: VTypes }
521
- @isok ccall ((@cholmod_name (" free_dense" ), :libcholmod ), Cint,
522
- (Ref{Ptr{C_Dense{Tv}}}, Ptr{Common}),
523
- p, common[Threads. threadid ()])
523
+ ccall ((@cholmod_name (" free_dense" ), :libcholmod ), Cint,
524
+ (Ref{Ptr{C_Dense{Tv}}}, Ptr{Common}),
525
+ p, common[Threads. threadid ()]) == TRUE
524
526
end
525
527
function zeros (m:: Integer , n:: Integer , :: Type{Tv} ) where Tv<: VTypes
526
528
Dense (ccall ((@cholmod_name (" zeros" ), :libcholmod ), Ptr{C_Dense{Tv}},
@@ -551,9 +553,9 @@ function copy(A::Dense{Tv}) where Tv<:VTypes
551
553
end
552
554
553
555
function sort! (S:: Sparse{Tv} ) where Tv<: VTypes
554
- @isok ccall ((@cholmod_name (" sort" ), :libcholmod ), Cint,
555
- (Ptr{C_Sparse{Tv}}, Ptr{Common}),
556
- S, common[Threads. threadid ()])
556
+ ccall ((@cholmod_name (" sort" ), :libcholmod ), Cint,
557
+ (Ptr{C_Sparse{Tv}}, Ptr{Common}),
558
+ S, common[Threads. threadid ()])
557
559
return S
558
560
end
559
561
@@ -592,16 +594,16 @@ function allocate_sparse(nrow::Integer, ncol::Integer, nzmax::Integer,
592
594
end
593
595
594
596
function free! (ptr:: Ptr{C_Sparse{Tv}} ) where Tv<: VTypes
595
- @isok ccall ((@cholmod_name (" free_sparse" ), :libcholmod ), Cint,
596
- (Ref{Ptr{C_Sparse{Tv}}}, Ptr{Common}),
597
- ptr, common[Threads. threadid ()])
597
+ ccall ((@cholmod_name (" free_sparse" ), :libcholmod ), Cint,
598
+ (Ref{Ptr{C_Sparse{Tv}}}, Ptr{Common}),
599
+ ptr, common[Threads. threadid ()]) == TRUE
598
600
end
599
601
600
602
function free! (ptr:: Ptr{C_Factor{Tv}} ) where Tv<: VTypes
601
603
# Warning! Important that finalizer doesn't modify the global Common struct.
602
- @isok ccall ((@cholmod_name (" free_factor" ), :libcholmod ), Cint,
603
- (Ref{Ptr{C_Factor{Tv}}}, Ptr{Common}),
604
- ptr, common[Threads. threadid ()])
604
+ ccall ((@cholmod_name (" free_factor" ), :libcholmod ), Cint,
605
+ (Ref{Ptr{C_Factor{Tv}}}, Ptr{Common}),
606
+ ptr, common[Threads. threadid ()]) == TRUE
605
607
end
606
608
607
609
function aat (A:: Sparse{Tv} , fset:: Vector{SuiteSparse_long} , mode:: Integer ) where Tv<: VRealTypes
635
637
636
638
function change_factor! (F:: Factor{Tv} , to_ll:: Bool , to_super:: Bool , to_packed:: Bool ,
637
639
to_monotonic:: Bool ) where Tv<: VTypes
638
- @isok ccall ((@cholmod_name (" change_factor" ),:libcholmod ), Cint,
639
- (Cint, Cint, Cint, Cint, Cint, Ptr{C_Factor{Tv}}, Ptr{Common}),
640
- xtyp (Tv), to_ll, to_super, to_packed, to_monotonic, F, common[Threads. threadid ()])
640
+ ccall ((@cholmod_name (" change_factor" ),:libcholmod ), Cint,
641
+ (Cint, Cint, Cint, Cint, Cint, Ptr{C_Factor{Tv}}, Ptr{Common}),
642
+ xtyp (Tv), to_ll, to_super, to_packed, to_monotonic, F, common[Threads. threadid ()]) == TRUE
641
643
end
642
644
643
645
function check_sparse (A:: Sparse{Tv} ) where Tv<: VTypes
@@ -702,16 +704,16 @@ end
702
704
function print_sparse (A:: Sparse{Tv} , name:: String ) where Tv<: VTypes
703
705
isascii (name) || error (" non-ASCII name: $name " )
704
706
common[Threads. threadid ()] = 3
705
- @isok ccall ((@cholmod_name (" print_sparse" ),:libcholmod ), Cint,
706
- (Ptr{C_Sparse{Tv}}, Ptr{UInt8}, Ptr{Common}),
707
- A, name, common[Threads. threadid ()])
707
+ ccall ((@cholmod_name (" print_sparse" ),:libcholmod ), Cint,
708
+ (Ptr{C_Sparse{Tv}}, Ptr{UInt8}, Ptr{Common}),
709
+ A, name, common[Threads. threadid ()])
708
710
nothing
709
711
end
710
712
function print_factor (F:: Factor{Tv} , name:: String ) where Tv<: VTypes
711
713
common[Threads. threadid ()] = 3
712
- @isok ccall ((@cholmod_name (" print_factor" ),:libcholmod ), Cint,
713
- (Ptr{C_Factor{Tv}}, Ptr{UInt8}, Ptr{Common}),
714
- F, name, common[Threads. threadid ()])
714
+ ccall ((@cholmod_name (" print_factor" ),:libcholmod ), Cint,
715
+ (Ptr{C_Factor{Tv}}, Ptr{UInt8}, Ptr{Common}),
716
+ F, name, common[Threads. threadid ()])
715
717
nothing
716
718
end
717
719
@@ -771,9 +773,9 @@ function scale!(S::Dense{Tv}, scale::Integer, A::Sparse{Tv}) where Tv<:VRealType
771
773
end
772
774
773
775
sA = unsafe_load (pointer (A))
774
- @isok ccall ((@cholmod_name (" scale" ),:libcholmod ), Cint,
775
- (Ptr{C_Dense{Tv}}, Cint, Ptr{C_Sparse{Tv}}, Ptr{Common}),
776
- S, scale, A, common[Threads. threadid ()])
776
+ ccall ((@cholmod_name (" scale" ),:libcholmod ), Cint,
777
+ (Ptr{C_Dense{Tv}}, Cint, Ptr{C_Sparse{Tv}}, Ptr{Common}),
778
+ S, scale, A, common[Threads. threadid ()])
777
779
A
778
780
end
779
781
@@ -785,11 +787,11 @@ function sdmult!(A::Sparse{Tv}, transpose::Bool,
785
787
if nc != size (X, 1 )
786
788
throw (DimensionMismatch (" incompatible dimensions, $nc and $(size (X,1 )) " ))
787
789
end
788
- @isok ccall ((@cholmod_name (" sdmult" ),:libcholmod ), Cint,
789
- (Ptr{C_Sparse{Tv}}, Cint,
790
- Ref{ComplexF64}, Ref{ComplexF64},
791
- Ptr{C_Dense{Tv}}, Ptr{C_Dense{Tv}}, Ptr{Common}),
792
- A, transpose, α, β, X, Y, common[Threads. threadid ()])
790
+ ccall ((@cholmod_name (" sdmult" ),:libcholmod ), Cint,
791
+ (Ptr{C_Sparse{Tv}}, Cint,
792
+ Ref{ComplexF64}, Ref{ComplexF64},
793
+ Ptr{C_Dense{Tv}}, Ptr{C_Dense{Tv}}, Ptr{Common}),
794
+ A, transpose, α, β, X, Y, common[Threads. threadid ()])
793
795
Y
794
796
end
795
797
@@ -831,18 +833,18 @@ function analyze_p(A::Sparse{Tv}, perm::Vector{SuiteSparse_long}) where Tv<:VTyp
831
833
A, perm, C_NULL , 0 , common[Threads. threadid ()]))
832
834
end
833
835
function factorize! (A:: Sparse{Tv} , F:: Factor{Tv} ) where Tv<: VTypes
834
- @isok ccall ((@cholmod_name (" factorize" ),:libcholmod ), Cint,
835
- (Ptr{C_Sparse{Tv}}, Ptr{C_Factor{Tv}}, Ptr{Common}),
836
- A, F, common[Threads. threadid ()])
836
+ ccall ((@cholmod_name (" factorize" ),:libcholmod ), Cint,
837
+ (Ptr{C_Sparse{Tv}}, Ptr{C_Factor{Tv}}, Ptr{Common}),
838
+ A, F, common[Threads. threadid ()])
837
839
F
838
840
end
839
841
function factorize_p! (A:: Sparse{Tv} , β:: Real , F:: Factor{Tv} ) where Tv<: VTypes
840
842
# note that β is passed as a complex number (double beta[2]),
841
843
# but the CHOLMOD manual says that only beta[0] (real part) is used
842
- @isok ccall ((@cholmod_name (" factorize_p" ),:libcholmod ), Cint,
843
- (Ptr{C_Sparse{Tv}}, Ref{ComplexF64}, Ptr{SuiteSparse_long}, Csize_t,
844
- Ptr{C_Factor{Tv}}, Ptr{Common}),
845
- A, β, C_NULL , 0 , F, common[Threads. threadid ()])
844
+ ccall ((@cholmod_name (" factorize_p" ),:libcholmod ), Cint,
845
+ (Ptr{C_Sparse{Tv}}, Ref{ComplexF64}, Ptr{SuiteSparse_long}, Csize_t,
846
+ Ptr{C_Factor{Tv}}, Ptr{Common}),
847
+ A, β, C_NULL , 0 , F, common[Threads. threadid ()])
846
848
F
847
849
end
848
850
@@ -877,14 +879,10 @@ end
877
879
878
880
# Autodetects the types
879
881
function read_sparse (file:: Libc.FILE , :: Type{SuiteSparse_long} )
880
- ptr = ccall ((@cholmod_name (" read_sparse" ), :libcholmod ),
881
- Ptr{C_Sparse{Cvoid}},
882
- (Ptr{Cvoid}, Ptr{Common}),
883
- file. ptr, common[Threads. threadid ()])
884
- if ptr == C_NULL
885
- throw (ArgumentError (" sparse matrix construction failed. Check that input file is valid." ))
886
- end
887
- Sparse (ptr)
882
+ Sparse (ccall ((@cholmod_name (" read_sparse" ), :libcholmod ),
883
+ Ptr{C_Sparse{Cvoid}},
884
+ (Ptr{Cvoid}, Ptr{Common}),
885
+ file. ptr, common[Threads. threadid ()]))
888
886
end
889
887
890
888
function read_sparse (file:: IO , T)
@@ -963,7 +961,7 @@ function Sparse(m::Integer, n::Integer,
963
961
unsafe_copyto! (s. i, pointer (rowval0), colptr0[n + 1 ])
964
962
unsafe_copyto! (s. x, pointer (nzval) , colptr0[n + 1 ])
965
963
966
- @isok check_sparse (o)
964
+ check_sparse (o)
967
965
968
966
return o
969
967
end
@@ -1022,7 +1020,7 @@ function Sparse{Tv}(A::SparseMatrixCSC, stype::Integer) where Tv<:VTypes
1022
1020
end
1023
1021
end
1024
1022
1025
- @isok check_sparse (o)
1023
+ check_sparse (o)
1026
1024
1027
1025
return o
1028
1026
end
@@ -1677,9 +1675,9 @@ function lowrankupdowndate!(F::Factor{Tv}, C::Sparse{Tv}, update::Cint) where Tv
1677
1675
if lF. n != lC. nrow
1678
1676
throw (DimensionMismatch (" matrix dimensions do not fit" ))
1679
1677
end
1680
- @isok ccall ((@cholmod_name (" updown" ), :libcholmod ), Cint,
1681
- (Cint, Ptr{C_Sparse{Tv}}, Ptr{C_Factor{Tv}}, Ptr{Common}),
1682
- update, C, F, common[Threads. threadid ()])
1678
+ ccall ((@cholmod_name (" updown" ), :libcholmod ), Cint,
1679
+ (Cint, Ptr{C_Sparse{Tv}}, Ptr{C_Factor{Tv}}, Ptr{Common}),
1680
+ update, C, F, common[Threads. threadid ()])
1683
1681
F
1684
1682
end
1685
1683
0 commit comments