Skip to content

Commit e6b2f04

Browse files
SPEX_mpfr_set_prec, and full test coverage
1 parent 2bc54c8 commit e6b2f04

File tree

11 files changed

+158
-33
lines changed

11 files changed

+158
-33
lines changed

SPEX/Config/SPEX.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ SPEX_info SPEX_mpq_equal (int *r, const mpq_t x, const mpq_t y) ;
976976

977977
SPEX_info SPEX_mpfr_init2(mpfr_t x, const uint64_t size) ;
978978

979+
SPEX_info SPEX_mpfr_set_prec(mpfr_t x, const uint64_t size) ;
980+
979981
SPEX_info SPEX_mpfr_set (mpfr_t x, const mpfr_t y, const mpfr_rnd_t rnd) ;
980982

981983
SPEX_info SPEX_mpfr_set_d (mpfr_t x, const double y, const mpfr_rnd_t rnd) ;

SPEX/Config/Tcov_Makefile.in

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ CFLAGS = -g -fprofile-arcs -ftest-coverage \
6666
cov: runtests
6767
./covall
6868

69-
all: tcov_for_lu spex_demo_lu_extended tcov_for_cholesky tcov_for_lu2
69+
all: tcov_for_lu spex_demo_lu_extended tcov_for_cholesky tcov_for_lu2 \
70+
tcov_for_other
7071

7172
#-------------------------------------------------------------------------------
7273
# compile .c file in this folder
@@ -219,13 +220,17 @@ spex_demo_lu_extended: $(OBJ_Util) $(OBJ_LU) ../Demo/spex_demo_lu_extended.c $(
219220
tcov_for_cholesky: $(OBJ_Tcov) $(OBJ_Util) $(OBJ_Cholesky) tcov_for_cholesky.c simple_rand.c simple_rand.h $(DEMO_SRC)
220221
$(CC) $(LDFLAGS) $(CFLAGS) tcov_for_cholesky.c simple_rand.c $(DEMO_SRC) -o tcov_for_cholesky $(OBJ_Tcov) $(OBJ_Util) $(OBJ_Cholesky) $(LIBS)
221222

223+
tcov_for_other: $(OBJ_Tcov) $(OBJ_Util) $(OBJ_LU) tcov_for_other.c
224+
$(CC) $(LDFLAGS) tcov_for_other.c $(CFLAGS) -o tcov_for_other $(OBJ_Tcov) $(OBJ_Util) $(OBJ_LU) $(LIBS)
225+
222226
#-------------------------------------------------------------------------------
223227

224228
# run all statement coverage tests
225229
runtests: runtests4llu runtests4chol
226230

227231
# only run test for SPEX_LU
228232
runtests4llu: all
233+
./tcov_for_other
229234
./spex_demo_lu_extended q 1 f ../ExampleMats/10teams.mat.txt ../ExampleMats/10teams.rhs.txt > lu1.out
230235
./spex_demo_lu_extended q 2 o 1 f ../ExampleMats/10teams.mat.txt ../ExampleMats/10teams.rhs.txt > lu2.out
231236
./spex_demo_lu_extended q 3 o 1 f ../ExampleMats/test.mat.txt ../ExampleMats/test.rhs.txt > lu3.out
@@ -250,6 +255,7 @@ vtests: vtests4llu vtests4chol
250255

251256
# run test for SPEX_LU with valgrind
252257
vtests4llu: all
258+
$(V) ./tcov_for_other
253259
$(V) ./spex_demo_lu_extended q 1 f ../ExampleMats/10teams.mat.txt ../ExampleMats/10teams.rhs.txt > lu1.out
254260
$(V) ./spex_demo_lu_extended q 2 o 1 f ../ExampleMats/10teams.mat.txt ../ExampleMats/10teams.rhs.txt > lu2.out
255261
$(V) ./spex_demo_lu_extended q 3 o 1 f ../ExampleMats/test.mat.txt ../ExampleMats/test.rhs.txt > lu3.out
@@ -270,7 +276,7 @@ vtests4chol: all
270276
# remove all files not in the original distribution, including symbolic links
271277
clean:
272278
- $(RM) *.o *.bbg *.da *.gcov *.gcda *gcno
273-
- $(RM) tcov_for_lu spex_demo_lu_extended *.out *.a out tcov_for_lu2
279+
- $(RM) tcov_for_lu spex_demo_lu_extended *.out *.a out tcov_for_lu2 tcov_for_other
274280
- $(RM) -r SPEX_*.c spex_*.c *.dSYM
275281
- $(RM) -r tcov_for_cholesky
276282

SPEX/Doc/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Feb XX, 2024: version 3.1.0 FIXME: date
1212
SPEX_mpz_clear
1313
SPEX_mpq_clear
1414
SPEX_mpfr_clear
15+
SPEX_mpfr_set_proc
1516

1617
Jul 26, 2023: version 3.0.0
1718

SPEX/Doc/SPEX_UserGuide.pdf

5.14 KB
Binary file not shown.

SPEX/Doc/SPEX_UserGuide.tex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,12 @@ \section{\texttt{SPEX\_gmp}: SPEX wrapper functions for GMP/MPFR}
15151515
\verb|mpfr_free_str(buff)|
15161516
& \verb|SPEX_mpfr_free_str(buff)|
15171517
& Free string allocated by MPFR \\ \hline
1518-
\verb|mpfr_init2(x, size)|
1519-
& \verb|SPEX_mpfr_init2(x, size)|
1520-
& Initialize x with size bits \\ \hline
1518+
\verb|mpfr_init2(x, s)|
1519+
& \verb|SPEX_mpfr_init2(x, s)|
1520+
& Initialize x with \verb's' bits \\ \hline
1521+
\verb|mpfr_set_prec(x, s)|
1522+
& \verb|SPEX_mpfr_set_prec(x, s)|
1523+
& Set x to contain \verb's' bits \\ \hline
15211524
\verb|mpfr_clear(x)|
15221525
& \verb|SPEX_mpfr_clear(x)|
15231526
& Safely free \verb|mpfr_t| value \\ \hline

SPEX/Include/SPEX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ SPEX_info SPEX_mpq_equal (int *r, const mpq_t x, const mpq_t y) ;
976976

977977
SPEX_info SPEX_mpfr_init2(mpfr_t x, const uint64_t size) ;
978978

979+
SPEX_info SPEX_mpfr_set_prec(mpfr_t x, const uint64_t size) ;
980+
979981
SPEX_info SPEX_mpfr_set (mpfr_t x, const mpfr_t y, const mpfr_rnd_t rnd) ;
980982

981983
SPEX_info SPEX_mpfr_set_d (mpfr_t x, const double y, const mpfr_rnd_t rnd) ;

SPEX/SPEX_Utilities/Source/SPEX_gmp.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ void *spex_gmp_allocate
371371
// spex_gmp_safe_free: free a block of memory and remove it from the archive
372372
//------------------------------------------------------------------------------
373373

374+
// see mpfr-4.2.1/src/mpfr-impl.h, for MPFR_GET_REAL_PTR
375+
#define SPEX_MPFR_GET_REAL_PTR(x) ((x)->_mpfr_d - 1)
376+
374377
static inline void spex_gmp_safe_free (void *p)
375378
{
376379
if (spex_gmp != NULL)
@@ -402,7 +405,7 @@ static inline void spex_gmp_safe_free (void *p)
402405
}
403406
if (spex_gmp->mpfr_archive != NULL)
404407
{
405-
if (p == SPEX_MPFR_MANT(spex_gmp->mpfr_archive))
408+
if (p == SPEX_MPFR_GET_REAL_PTR(spex_gmp->mpfr_archive))
406409
{
407410
SPEX_MPFR_MANT(spex_gmp->mpfr_archive) = NULL ;
408411
}
@@ -1784,7 +1787,10 @@ SPEX_info SPEX_mpfr_init2
17841787
)
17851788
{
17861789
// ensure the mpfr number is not too big
1787-
if (size > MPFR_PREC_MAX/2) return (SPEX_PANIC);
1790+
if (size > MPFR_PREC_MAX/2)
1791+
{
1792+
return (SPEX_PANIC);
1793+
}
17881794

17891795
// initialize the mpfr number
17901796
SPEX_GMPFR_WRAPPER_START (x);
@@ -1793,6 +1799,31 @@ SPEX_info SPEX_mpfr_init2
17931799
return (SPEX_OK);
17941800
}
17951801

1802+
//------------------------------------------------------------------------------
1803+
// SPEX_mpfr_set_prec
1804+
//------------------------------------------------------------------------------
1805+
1806+
/* Purpose: Set the precision of an mpfr_t number */
1807+
1808+
SPEX_info SPEX_mpfr_set_prec
1809+
(
1810+
mpfr_t x, // Floating point number to revise
1811+
const uint64_t size // # of bits in x
1812+
)
1813+
{
1814+
// ensure the mpfr number is not too big
1815+
if (size > MPFR_PREC_MAX/2)
1816+
{
1817+
return (SPEX_PANIC);
1818+
}
1819+
1820+
// set the precision of the mpfr number
1821+
SPEX_GMPFR_WRAPPER_START (x);
1822+
mpfr_set_prec (x, (mpfr_prec_t) size);
1823+
SPEX_GMP_WRAPPER_FINISH ;
1824+
return (SPEX_OK);
1825+
}
1826+
17961827
//------------------------------------------------------------------------------
17971828
// SPEX_mpfr_set
17981829
//------------------------------------------------------------------------------

SPEX/TODO.txt

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
11

2-
Lorena: test python interface
3-
4-
Tim: get 100% test coverage
5-
(only 1 statement left)
6-
7-
Chris: User Guide
8-
9-
Added: (need in user guide)
10-
11-
(DONE) SPEX_TRY
12-
(DONE) SPEX_CATCH
13-
(DONE) SPEX_1D
14-
(DONE) SPEX_2D
15-
16-
(DONE) SPEX_mpz_set_null
17-
(DONE) SPEX_mpq_set_null
18-
(DONE) SPEX_mpfr_set_null
19-
20-
(DONE) SPEX_mpz_clear
21-
(DONE) SPEX_mpq_clear
22-
(DONE) SPEX_mpfr_clear
23-
242
Erick: check copyright
253

26-
All: FIXMEs
4+
FIXME: date

SPEX/Tcov/tcov_for_cholesky.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
// BRUTAL: test a method with debug malloc, until it succeeds
3535
//------------------------------------------------------------------------------
3636

37-
// The method must return a bool (true if successful, false if failure).
38-
3937
#define NTRIAL_MAX 10000
4038

4139
#define BRUTAL(method) \
@@ -49,7 +47,7 @@
4947
if (info2 != SPEX_OUT_OF_MEMORY) break ; \
5048
} \
5149
if (info2 != SPEX_OK) TEST_ABORT (info2) ; \
52-
malloc_count = INT64_MAX ; \
50+
malloc_count = INT64_MAX ; \
5351
printf ("\nBrutal Cholesky trials %ld: tests passed\n", trial); \
5452
}
5553

SPEX/Tcov/tcov_for_other

440 KB
Binary file not shown.

0 commit comments

Comments
 (0)