Skip to content

Commit e82231f

Browse files
SPEX test coverage; added spex_free_*_array methods
1 parent a998092 commit e82231f

26 files changed

+318
-219
lines changed

SPEX/Config/Tcov_Makefile.in

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ OBJ_Util = \
8787
spex_create_mpfr_array.o \
8888
spex_create_mpq_array.o \
8989
spex_create_mpz_array.o \
90+
spex_free_mpfr_array.o \
91+
spex_free_mpq_array.o \
92+
spex_free_mpz_array.o \
9093
spex_cumsum.o \
9194
spex_expand_double_array.o \
9295
spex_expand_mpfr_array.o \
@@ -112,8 +115,7 @@ OBJ_Util = \
112115
SPEX_determine_symmetry.o \
113116
SPEX_transpose.o \
114117
spex_amd.o \
115-
spex_colamd.o \
116-
spex_create_mpq.o
118+
spex_colamd.o
117119

118120
$(OBJ_Util): ../Include/SPEX.h ../SPEX_Utilities/Source/spex_util_internal.h
119121

@@ -256,6 +258,9 @@ vtests4llu: all
256258
$(V) ./tcov_for_lu 0 1 1 > lu5.out
257259
$(V) ./tcov_for_lu2 ../ExampleMats/Trefethen_500.mat.txt ../ExampleMats/Trefethen_500.rhs.txt > test_for_lu2.out
258260

261+
vtest2: all
262+
$(V) ./tcov_for_lu2 ../ExampleMats/Trefethen_500.mat.txt ../ExampleMats/Trefethen_500.rhs.txt > test_for_lu2.out
263+
259264
# run test for SPEX_Cholesky with valgrind
260265
vtests4chol: all
261266
$(V) ./tcov_for_cholesky ../ExampleMats/mesh1e1.mat.txt ../ExampleMats/mesh1e1.rhs.txt > test_for_cholesky.out

SPEX/SPEX_LU/Source/spex_left_lu_get_largest_pivot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
#define SPEX_FREE_ALL \
21-
SPEX_MPZ_CLEAR(big);
21+
SPEX_mpz_clear (big);
2222

2323
#include "spex_lu_internal.h"
2424

@@ -51,7 +51,7 @@ SPEX_info spex_left_lu_get_largest_pivot
5151
int r ;
5252
(*pivot) = -1 ;
5353
mpz_t big ;
54-
SPEX_MPZ_SET_NULL (big);
54+
SPEX_mpz_set_null (big);
5555
SPEX_MPZ_INIT (big);
5656

5757
//--------------------------------------------------------------------------

SPEX/SPEX_LU/Source/spex_left_lu_get_pivot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
*/
2626

2727
#define SPEX_FREE_ALL \
28-
SPEX_MPQ_CLEAR (tol); \
29-
SPEX_MPQ_CLEAR (ratio);
28+
SPEX_mpq_clear (tol); \
29+
SPEX_mpq_clear (ratio);
3030

3131
#include "spex_lu_internal.h"
3232

@@ -67,8 +67,8 @@ SPEX_info spex_left_lu_get_pivot
6767

6868
int sgn, r;
6969
mpq_t tol, ratio;
70-
SPEX_MPQ_SET_NULL(tol);
71-
SPEX_MPQ_SET_NULL(ratio);
70+
SPEX_mpq_set_null (tol);
71+
SPEX_mpq_set_null (ratio);
7272

7373
if (order == SPEX_SMALLEST)
7474
{

SPEX/SPEX_LU/Source/spex_left_lu_get_smallest_pivot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
#define SPEX_FREE_ALL \
19-
SPEX_MPZ_CLEAR(small);
19+
SPEX_mpz_clear (small);
2020

2121
#include "spex_lu_internal.h"
2222

@@ -49,7 +49,7 @@ SPEX_info spex_left_lu_get_smallest_pivot
4949
(*pivot) = -1;
5050
j = n;
5151
flag = top;
52-
mpz_t small; SPEX_MPZ_SET_NULL(small);
52+
mpz_t small; SPEX_mpz_set_null (small);
5353
SPEX_MPZ_INIT(small);
5454

5555
//--------------------------------------------------------------------------

SPEX/SPEX_Utilities/Source/SPEX_factorization_free.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SPEX_info SPEX_factorization_free
2929

3030
if ((F_handle != NULL) && (*F_handle != NULL))
3131
{
32-
SPEX_MPQ_CLEAR((*F_handle)->scale_for_A);
32+
SPEX_mpq_clear ((*F_handle)->scale_for_A);
3333

3434
SPEX_matrix_free(&((*F_handle)->L), option);
3535
SPEX_matrix_free(&((*F_handle)->U), option);

SPEX/SPEX_Utilities/Source/SPEX_gmp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,10 @@ SPEX_info SPEX_mpq_clear
21782178
mpq_t x
21792179
)
21802180
{
2181-
SPEX_MPQ_CLEAR (x) ;
2181+
if (x != NULL)
2182+
{
2183+
SPEX_MPQ_CLEAR (x) ;
2184+
}
21822185
return (SPEX_OK);
21832186
}
21842187

SPEX/SPEX_Utilities/Source/SPEX_matrix_allocate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
#define SPEX_FREE_ALL \
2626
{ \
27-
SPEX_matrix_free (&A, option); \
27+
SPEX_matrix_free (&A, option); \
2828
}
2929

3030
#include "spex_util_internal.h"
3131

3232
#if defined (__GNUC__)
3333
#if ( __GNUC__ == 11)
3434
// gcc 11 has a bug that triggers a spurious warning for the call
35-
// to SPEX_mpq_init (A->scale), from -Wstringop-overflow. see
35+
// to SPEX_MPQ_INIT (A->scale), from -Wstringop-overflow. see
3636
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
3737
#pragma GCC diagnostic ignored "-Wstringop-overflow"
3838
#endif
@@ -110,7 +110,7 @@ SPEX_info SPEX_matrix_allocate
110110
A->x_shallow = false ;
111111

112112
// A->scale = 1
113-
SPEX_CHECK (spex_create_mpq (A->scale));
113+
SPEX_MPQ_INIT (A->scale) ;
114114
SPEX_MPQ_SET_UI (A->scale, 1, 1);
115115

116116
//--------------------------------------------------------------------------

SPEX/SPEX_Utilities/Source/SPEX_matrix_check.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
//------------------------------------------------------------------------------
1111

12-
#define SPEX_FREE_ALL \
13-
SPEX_FREE (work); \
14-
SPEX_MPZ_CLEAR(q); \
15-
SPEX_MPZ_CLEAR(r);
12+
#define SPEX_FREE_ALL \
13+
{ \
14+
SPEX_FREE (work); \
15+
SPEX_mpz_clear (q); \
16+
SPEX_mpz_clear (r); \
17+
}
1618

1719
#include "spex_util_internal.h"
1820

@@ -21,7 +23,7 @@
2123
lines++ ; \
2224
if (pr == 2 && lines > 30) \
2325
{ \
24-
SPEX_PRINTF (" ...\n"); \
26+
SPEX_PRINTF (" ...\n"); \
2527
pr = 1 ; \
2628
}
2729

@@ -143,8 +145,8 @@ SPEX_info SPEX_matrix_check // returns a SPEX status code
143145
// paranoia: check prec here: cast to mprf_prec_t, and back, assert
144146
// equality, if not equal then return SPEX_PANIC
145147
mpz_t q, r;
146-
SPEX_MPZ_SET_NULL(q);
147-
SPEX_MPZ_SET_NULL(r);
148+
SPEX_mpz_set_null (q);
149+
SPEX_mpz_set_null (r);
148150

149151
int64_t lines = 0 ; // # of lines printed so far
150152

SPEX/SPEX_Utilities/Source/SPEX_matrix_free.c

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,67 +38,45 @@ SPEX_info SPEX_matrix_free
3838
//--------------------------------------------------------------------------
3939
// free any non-shallow components
4040
//--------------------------------------------------------------------------
41-
42-
// free the integer pattern
43-
if (!(A->p_shallow)) SPEX_FREE (A->p);
44-
if (!(A->i_shallow)) SPEX_FREE (A->i);
45-
if (!(A->j_shallow)) SPEX_FREE (A->j);
46-
47-
// free the values
48-
if (!(A->x_shallow))
41+
42+
// free the integer pattern
43+
if (!(A->p_shallow)) SPEX_FREE (A->p);
44+
if (!(A->i_shallow)) SPEX_FREE (A->i);
45+
if (!(A->j_shallow)) SPEX_FREE (A->j);
46+
47+
// free the values
48+
if (!(A->x_shallow))
49+
{
50+
switch (A->type)
4951
{
50-
switch (A->type)
51-
{
52-
case SPEX_MPZ:
53-
if ( A->x.mpz != NULL)
54-
{
55-
for (int64_t i = 0; i < A->nzmax; i++)
56-
{
57-
SPEX_MPZ_CLEAR( A->x.mpz[i]);
58-
}
59-
}
60-
SPEX_FREE (A->x.mpz);
61-
break ;
62-
63-
case SPEX_MPQ:
64-
if ( A->x.mpq != NULL)
65-
{
66-
for (int64_t i = 0; i < A->nzmax; i++)
67-
{
68-
SPEX_MPQ_CLEAR( A->x.mpq[i]);
69-
}
70-
}
71-
SPEX_FREE (A->x.mpq);
72-
break ;
73-
74-
case SPEX_MPFR:
75-
if ( A->x.mpfr != NULL)
76-
{
77-
for (int64_t i = 0; i < A->nzmax; i++)
78-
{
79-
SPEX_MPFR_CLEAR( A->x.mpfr[i]);
80-
}
81-
}
82-
SPEX_FREE (A->x.mpfr);
83-
break ;
84-
85-
case SPEX_INT64:
86-
SPEX_FREE (A->x.int64);
87-
break ;
88-
89-
case SPEX_FP64:
90-
SPEX_FREE (A->x.fp64);
91-
break ;
92-
93-
default:
94-
// do nothing
95-
break ;
96-
}
97-
}
52+
case SPEX_MPZ:
53+
spex_free_mpz_array (&(A->x.mpz), A->nzmax) ;
54+
break ;
55+
56+
case SPEX_MPQ:
57+
spex_free_mpq_array (&(A->x.mpq), A->nzmax) ;
58+
break ;
9859

60+
case SPEX_MPFR:
61+
spex_free_mpfr_array (&(A->x.mpfr), A->nzmax) ;
62+
break ;
63+
64+
case SPEX_INT64:
65+
SPEX_FREE (A->x.int64) ;
66+
break ;
67+
68+
case SPEX_FP64:
69+
SPEX_FREE (A->x.fp64) ;
70+
break ;
71+
72+
default:
73+
// do nothing
74+
break ;
75+
}
76+
}
9977

10078
// A->scale is never shallow
101-
SPEX_MPQ_CLEAR (A->scale);
79+
SPEX_mpq_clear (A->scale);
10280

10381
//--------------------------------------------------------------------------
10482
// free the header

SPEX/SPEX_Utilities/Source/spex_cast_array.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
// y_scale = 1.
3636
//
3737

38-
#define SPEX_FREE_ALL \
39-
SPEX_MPQ_CLEAR(temp); \
38+
#define SPEX_FREE_ALL SPEX_mpq_clear (temp) ;
4039

4140
#include "spex_util_internal.h"
4241
#if defined (__GNUC__)
@@ -67,7 +66,7 @@ SPEX_info spex_cast_array
6766
}
6867
SPEX_info info ;
6968
int r;
70-
mpq_t temp; SPEX_MPQ_SET_NULL(temp);
69+
mpq_t temp; SPEX_mpq_set_null (temp);
7170

7271
mpfr_rnd_t round = SPEX_OPTION_ROUND (option);
7372

0 commit comments

Comments
 (0)