Skip to content

Commit d25acbe

Browse files
committed
Automatically convert umfpack status code in umfErr function so earlier and newer Ubuntu work
1 parent 4bad457 commit d25acbe

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

la/sparse_conversions.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121
)
2222

2323
// ToMatrix converts a sparse matrix in triplet form to column-compressed form using Umfpack's routines.
24-
// INPUT:
25-
// a -- a previous CCMatrix to be filled in; otherwise, "nil" tells to allocate a new one
26-
// OUTPUT:
27-
// the previous "a" matrix or a pointer to a new one
24+
//
25+
// INPUT:
26+
// a -- a previous CCMatrix to be filled in; otherwise, "nil" tells to allocate a new one
27+
// OUTPUT:
28+
// the previous "a" matrix or a pointer to a new one
2829
func (t *Triplet) ToMatrix(a *CCMatrix) *CCMatrix {
2930
if t.pos < 1 {
3031
chk.Panic("conversion can only be made for non-empty triplets. error: (pos = %d)", t.pos)
@@ -44,16 +45,17 @@ func (t *Triplet) ToMatrix(a *CCMatrix) *CCMatrix {
4445
Ax := (*C.double)(unsafe.Pointer(&a.x[0]))
4546
status := C.umfpack_dl_triplet_to_col(C.LONG(a.m), C.LONG(a.n), C.LONG(a.nnz), Ti, Tj, Tx, Ap, Ai, Ax, nil)
4647
if status != C.UMFPACK_OK {
47-
chk.Panic("umfpack_dl_triplet_to_col failed (UMFPACK error: %s)", umfErr(status))
48+
chk.Panic("umfpack_dl_triplet_to_col failed (UMFPACK error: %s)", umfErr((int)(status)))
4849
}
4950
return a
5051
}
5152

5253
// ToMatrix converts a sparse matrix in triplet form with complex numbers to column-compressed form.
53-
// INPUT:
54-
// a -- a previous CCMatrixC to be filled in; otherwise, "nil" tells to allocate a new one
55-
// OUTPUT:
56-
// the previous "a" matrix or a pointer to a new one
54+
//
55+
// INPUT:
56+
// a -- a previous CCMatrixC to be filled in; otherwise, "nil" tells to allocate a new one
57+
// OUTPUT:
58+
// the previous "a" matrix or a pointer to a new one
5759
func (t *TripletC) ToMatrix(a *CCMatrixC) *CCMatrixC {
5860
if t.pos < 1 {
5961
chk.Panic("conversion can only be made for non-empty triplets. error: (pos = %d)", t.pos)
@@ -73,13 +75,13 @@ func (t *TripletC) ToMatrix(a *CCMatrixC) *CCMatrixC {
7375
Tx := (*C.double)(unsafe.Pointer(&t.x[0]))
7476
status := C.umfpack_zl_triplet_to_col(C.LONG(a.m), C.LONG(a.n), C.LONG(a.nnz), Ti, Tj, Tx, nil, Ap, Ai, Ax, nil, nil)
7577
if status != C.UMFPACK_OK {
76-
chk.Panic("umfpack_zl_triplet_to_col failed (UMFPACK error: %s)", umfErr(status))
78+
chk.Panic("umfpack_zl_triplet_to_col failed (UMFPACK error: %s)", umfErr((int)(status)))
7779
}
7880
return a
7981
}
8082

8183
// umfErr returns UMFPACK error codes
82-
func umfErr(code C.int) string {
84+
func umfErr(code int) string {
8385
switch code {
8486
case C.UMFPACK_ERROR_out_of_memory:
8587
return "out_of_memory (-1)"

la/sparse_solver_umfpack.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (o *sparseSolverUmfpack) Fact() {
127127
// convert triplet to column-compressed format
128128
code := C.umfpack_dl_triplet_to_col(C.LONG(o.t.m), C.LONG(o.t.n), C.LONG(o.t.pos), o.ti, o.tj, o.tx, o.ap, o.ai, o.ax, nil)
129129
if code != C.UMFPACK_OK {
130-
chk.Panic("conversion failed (UMFPACK error: %s)\n", umfErr(code))
130+
chk.Panic("conversion failed (UMFPACK error: %s)\n", umfErr((int)(code)))
131131
}
132132

133133
// symbolic factorisation
@@ -137,7 +137,7 @@ func (o *sparseSolverUmfpack) Fact() {
137137
}
138138
code = C.umfpack_dl_symbolic(C.LONG(o.t.m), C.LONG(o.t.n), o.ap, o.ai, o.ax, &o.usymb, o.uctrl, o.uinfo)
139139
if code != C.UMFPACK_OK {
140-
chk.Panic("symbolic factorized failed (UMFPACK error: %s)\n", umfErr(code))
140+
chk.Panic("symbolic factorized failed (UMFPACK error: %s)\n", umfErr((int)(code)))
141141
}
142142
o.symbFact = true
143143

@@ -148,7 +148,7 @@ func (o *sparseSolverUmfpack) Fact() {
148148
}
149149
code = C.umfpack_dl_numeric(o.ap, o.ai, o.ax, o.usymb, &o.unum, o.uctrl, o.uinfo)
150150
if code != C.UMFPACK_OK {
151-
chk.Panic("numeric factorisation failed (UMFPACK error: %s)\n", umfErr(code))
151+
chk.Panic("numeric factorisation failed (UMFPACK error: %s)\n", umfErr((int)(code)))
152152
}
153153
o.numeFact = true
154154

@@ -158,8 +158,7 @@ func (o *sparseSolverUmfpack) Fact() {
158158

159159
// Solve solves sparse linear systems using UMFPACK or MUMPS
160160
//
161-
// Given: A ⋅ x = b find x such that x = A⁻¹ ⋅ b
162-
//
161+
// Given: A ⋅ x = b find x such that x = A⁻¹ ⋅ b
163162
func (o *sparseSolverUmfpack) Solve(x, b Vector) {
164163

165164
// check
@@ -174,7 +173,7 @@ func (o *sparseSolverUmfpack) Solve(x, b Vector) {
174173
// solve
175174
code := C.umfpack_dl_solve(C.UMFPACK_A, o.ap, o.ai, o.ax, px, pb, o.unum, o.uctrl, o.uinfo)
176175
if code != C.UMFPACK_OK {
177-
chk.Panic("solve failed (UMFPACK error: %s)\n", umfErr(code))
176+
chk.Panic("solve failed (UMFPACK error: %s)\n", umfErr((int)(code)))
178177
}
179178
}
180179

@@ -286,7 +285,7 @@ func (o *sparseSolverUmfpackC) Fact() {
286285
// convert triplet to column-compressed format
287286
code := C.umfpack_zl_triplet_to_col(C.LONG(o.t.m), C.LONG(o.t.n), C.LONG(o.t.pos), o.ti, o.tj, o.tx, nil, o.ap, o.ai, o.ax, nil, nil)
288287
if code != C.UMFPACK_OK {
289-
chk.Panic("conversion failed (UMFPACK error: %s)\n", umfErr(code))
288+
chk.Panic("conversion failed (UMFPACK error: %s)\n", umfErr((int)(code)))
290289
}
291290

292291
// symbolic factorisation
@@ -296,7 +295,7 @@ func (o *sparseSolverUmfpackC) Fact() {
296295
}
297296
code = C.umfpack_zl_symbolic(C.LONG(o.t.m), C.LONG(o.t.n), o.ap, o.ai, o.ax, nil, &o.usymb, o.uctrl, o.uinfo)
298297
if code != C.UMFPACK_OK {
299-
chk.Panic("symbolic factorized failed (UMFPACK error: %s)\n", umfErr(code))
298+
chk.Panic("symbolic factorized failed (UMFPACK error: %s)\n", umfErr((int)(code)))
300299
}
301300
o.symbFact = true
302301

@@ -307,7 +306,7 @@ func (o *sparseSolverUmfpackC) Fact() {
307306
}
308307
code = C.umfpack_zl_numeric(o.ap, o.ai, o.ax, nil, o.usymb, &o.unum, o.uctrl, o.uinfo)
309308
if code != C.UMFPACK_OK {
310-
chk.Panic("numeric factorisation failed (UMFPACK error: %s)\n", umfErr(code))
309+
chk.Panic("numeric factorisation failed (UMFPACK error: %s)\n", umfErr((int)(code)))
311310
}
312311
o.numeFact = true
313312

@@ -317,8 +316,7 @@ func (o *sparseSolverUmfpackC) Fact() {
317316

318317
// Solve solves sparse linear systems using UMFPACK or MUMPS
319318
//
320-
// Given: A ⋅ x = b find x such that x = A⁻¹ ⋅ b
321-
//
319+
// Given: A ⋅ x = b find x such that x = A⁻¹ ⋅ b
322320
func (o *sparseSolverUmfpackC) Solve(x, b VectorC) {
323321

324322
// check
@@ -333,7 +331,7 @@ func (o *sparseSolverUmfpackC) Solve(x, b VectorC) {
333331
// solve
334332
code := C.umfpack_zl_solve(C.UMFPACK_A, o.ap, o.ai, o.ax, nil, px, nil, pb, nil, o.unum, o.uctrl, o.uinfo)
335333
if code != C.UMFPACK_OK {
336-
chk.Panic("solve failed (UMFPACK error: %s)\n", umfErr(code))
334+
chk.Panic("solve failed (UMFPACK error: %s)\n", umfErr((int)(code)))
337335
}
338336
}
339337

0 commit comments

Comments
 (0)