diff options
author | Ian Jauslin <ian.jauslin@roma1.infn.it> | 2016-05-20 21:41:54 +0000 |
---|---|---|
committer | Ian Jauslin <ian.jauslin@roma1.infn.it> | 2016-05-20 21:41:54 +0000 |
commit | 46cae873fa2bd7973aa2e98d5955d2287822c604 (patch) | |
tree | e5b254c772210d6910c7b8fa4dbbdaa9a9400a12 | |
parent | 2125f01f97abfe343fc5e0cc078bf1d081b2e441 (diff) |
-rw-r--r-- | Changelog | 4 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | doc/libinum-doc.html | 33 | ||||
-rw-r--r-- | doc/libinum-doc.php | 20 | ||||
-rw-r--r-- | include/libinum.h | 2 | ||||
-rw-r--r-- | src/array_2_mpfr.h | 3 | ||||
-rw-r--r-- | src/array_base.c | 16 | ||||
-rw-r--r-- | src/array_base.h | 4 | ||||
-rw-r--r-- | src/array_char.h | 1 | ||||
-rw-r--r-- | src/array_double.h | 1 | ||||
-rw-r--r-- | src/array_int.h | 1 | ||||
-rw-r--r-- | src/array_ldouble.h | 1 | ||||
-rw-r--r-- | src/array_mpfr.h | 3 | ||||
-rw-r--r-- | src/array_polynomial_double.h | 3 | ||||
-rw-r--r-- | src/array_polynomial_ldouble.h | 3 | ||||
-rw-r--r-- | src/array_polynomial_mpfr.h | 3 | ||||
-rw-r--r-- | src/array_pthread_t.h | 1 | ||||
-rw-r--r-- | src/array_str.h | 3 | ||||
-rw-r--r-- | src/array_uint.h | 1 | ||||
-rw-r--r-- | src/integral_base.c | 12 |
20 files changed, 101 insertions, 16 deletions
diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..8d2d246 --- /dev/null +++ b/Changelog @@ -0,0 +1,4 @@ +1.0.1: + + * Add a function to allocate memory for arrays of temporary values + @@ -18,7 +18,7 @@ # if static=1 then compile the static library STATIC=0 -VERSION=1.0 +VERSION=1.0.1 # products of the compilation PROJECT_SO=libinum.so.$(VERSION) diff --git a/doc/libinum-doc.html b/doc/libinum-doc.html index e50e8f7..1486797 100644 --- a/doc/libinum-doc.html +++ b/doc/libinum-doc.html @@ -76,10 +76,10 @@ </head> <body> - <h1 style="margin-bottom:50pt;">libinum <span style="margin-left:10pt;font-size:18pt">v1.0</span></h1> + <h1 style="margin-bottom:50pt;">libinum <span style="margin-left:10pt;font-size:18pt">v1.0.1</span></h1> <p> - This is the official documentation for <b>libinum</b>, version 1.0. + This is the official documentation for <b>libinum</b>, version 1.0.1. </p> <h2 style="margin-top:50pt;">Table of contents</h2> @@ -1262,6 +1262,35 @@ copy <code>input</code> to the array pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>. </li> <br> + <li id="func_array_alloc_tmps"> + + <div style="margin-bottom:5pt"> + <code id="func_array_alloc_tmps_mpfr">int array_mpfr_alloc_tmps(unsigned int n, array_mpfr* array)</code> + </div> + + <div style="margin-bottom:5pt"> + <code id="func_array_alloc_tmps_2_mpfr">int array_2_mpfr_alloc_tmps(unsigned int n, array_2_mpfr* array)</code> + </div> + + <div style="margin-bottom:5pt"> + <code id="func_array_alloc_tmps_str">int array_str_alloc_tmps(unsigned int n, array_str* array)</code> + </div> + + <div style="margin-bottom:5pt"> + <code id="func_array_alloc_tmps_polynomial_double">int array_polynomial_double_alloc_tmps(unsigned int n, array_polynomial_double* array)</code> + </div> + + <div style="margin-bottom:5pt"> + <code id="func_array_alloc_tmps_polynomial_ldouble">int array_polynomial_ldouble_alloc_tmps(unsigned int n, array_polynomial_ldouble* array)</code> + </div> + + <div style="margin-bottom:5pt"> + <code id="func_array_alloc_tmps_polynomial_mpfr">int array_polynomial_mpfr_alloc_tmps(unsigned int n, array_polynomial_mpfr* array)</code> + </div> + <br> + Ensure that <code>*array</code> has at least <code>n</code> allocated values. If it has fewer, then allocate as many as needed. + </li> + <br> <li id="func_array_subarray"> <div style="margin-bottom:5pt"> diff --git a/doc/libinum-doc.php b/doc/libinum-doc.php index 2daf429..d140ab2 100644 --- a/doc/libinum-doc.php +++ b/doc/libinum-doc.php @@ -76,10 +76,10 @@ </head> <body> - <h1 style="margin-bottom:50pt;">libinum <span style="margin-left:10pt;font-size:18pt">v1.0</span></h1> + <h1 style="margin-bottom:50pt;">libinum <span style="margin-left:10pt;font-size:18pt">v1.0.1</span></h1> <p> - This is the official documentation for <b>libinum</b>, version 1.0. + This is the official documentation for <b>libinum</b>, version 1.0.1. </p> <h2 style="margin-top:50pt;">Table of contents</h2> @@ -839,6 +839,22 @@ copy <code>input</code> to the array pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>. </li> <br> + <li id="func_array_alloc_tmps"> + <?php + for ($i=0; $i<count($typenames_init); $i++){ + $TYPENAME=$typenames_init[$i]; + $TYPE=$types_init[$i]; + print(" + <div style=\"margin-bottom:5pt\"> + <code id=\"func_array_alloc_tmps_${TYPENAME}\">int array_${TYPENAME}_alloc_tmps(unsigned int n, array_${TYPENAME}* array)</code> + </div> + "); + } + ?> + <br> + Ensure that <code>*array</code> has at least <code>n</code> allocated values. If it has fewer, then allocate as many as needed. + </li> + <br> <li id="func_array_subarray"> <?php for ($i=0; $i<count($typenames); $i++){ diff --git a/include/libinum.h b/include/libinum.h index bd510cc..aa7aa91 100644 --- a/include/libinum.h +++ b/include/libinum.h @@ -1,7 +1,7 @@ #ifndef LIBINUM_H #define LIBINUM_H -#define LIBINUM_VERSION "1.0" +#define LIBINUM_VERSION "1.0.1" #include <libinum/types.h> diff --git a/src/array_2_mpfr.h b/src/array_2_mpfr.h index afd99d9..35947ad 100644 --- a/src/array_2_mpfr.h +++ b/src/array_2_mpfr.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY @@ -39,6 +40,8 @@ limitations under the License. // type of values #define ARRAY_VAL_TYPE array_mpfr +// init +#define ARRAY_VAL_INIT(VAL, SIZE) array_mpfr_init(VAL, SIZE) // free #define ARRAY_VAL_FREE(VAL) array_mpfr_free(VAL) // set values diff --git a/src/array_base.c b/src/array_base.c index a70bd86..f340d6c 100644 --- a/src/array_base.c +++ b/src/array_base.c @@ -247,3 +247,19 @@ int ARRAY_FUNC(print) (ARRAY_TYPENAME array){ return(0); } #endif + +// allocate memory for values until there are at least 'n' alloacted values +#ifdef ARRAY_VAL_INIT +int ARRAY_FUNC(alloc_tmps) (unsigned int n, ARRAY_TYPENAME* array){ + unsigned int i; + // resize if needed + if(array->memory<n){ + ARRAY_FUNC(resize)(array, n); + } + for (i=array->length; i<n; i++){ + ARRAY_VAL_INIT(array->values+i, 2); + (array->length)++; + } + return(0); +} +#endif diff --git a/src/array_base.h b/src/array_base.h index b9de5d2..002ea08 100644 --- a/src/array_base.h +++ b/src/array_base.h @@ -76,3 +76,7 @@ int ARRAY_FUNC(cmp) (ARRAY_TYPENAME array1, ARRAY_TYPENAME array2); int ARRAY_FUNC(print) (ARRAY_TYPENAME array); #endif +// allocate memory for values until there are at least 'n' alloacted values +#ifdef ARRAY_VAL_INIT +int ARRAY_FUNC(alloc_tmps) (unsigned int n, ARRAY_TYPENAME* array); +#endif diff --git a/src/array_char.h b/src/array_char.h index 6c95174..949b17a 100644 --- a/src/array_char.h +++ b/src/array_char.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY diff --git a/src/array_double.h b/src/array_double.h index 8d3c187..0a272d7 100644 --- a/src/array_double.h +++ b/src/array_double.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY diff --git a/src/array_int.h b/src/array_int.h index 9496b89..9eed317 100644 --- a/src/array_int.h +++ b/src/array_int.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY diff --git a/src/array_ldouble.h b/src/array_ldouble.h index d314906..b00d2af 100644 --- a/src/array_ldouble.h +++ b/src/array_ldouble.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY diff --git a/src/array_mpfr.h b/src/array_mpfr.h index 46bc54b..5994ddd 100644 --- a/src/array_mpfr.h +++ b/src/array_mpfr.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY @@ -39,6 +40,8 @@ limitations under the License. // type of values #define ARRAY_VAL_TYPE mpfr_t +// init +#define ARRAY_VAL_INIT(VAL, SIZE) mpfr_init(*(VAL)) // free #define ARRAY_VAL_FREE(VAL) mpfr_clear(VAL) // set values diff --git a/src/array_polynomial_double.h b/src/array_polynomial_double.h index d25e689..a90002b 100644 --- a/src/array_polynomial_double.h +++ b/src/array_polynomial_double.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY @@ -39,6 +40,8 @@ limitations under the License. // type of values #define ARRAY_VAL_TYPE polynomial_double +// init +#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_double_init(VAL, SIZE) // free #define ARRAY_VAL_FREE(VAL) polynomial_double_free(VAL) // set values diff --git a/src/array_polynomial_ldouble.h b/src/array_polynomial_ldouble.h index 49c81cc..9ff6468 100644 --- a/src/array_polynomial_ldouble.h +++ b/src/array_polynomial_ldouble.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY @@ -39,6 +40,8 @@ limitations under the License. // type of values #define ARRAY_VAL_TYPE polynomial_ldouble +// init +#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_ldouble_init(VAL, SIZE) // free #define ARRAY_VAL_FREE(VAL) polynomial_ldouble_free(VAL) // set values diff --git a/src/array_polynomial_mpfr.h b/src/array_polynomial_mpfr.h index 8cfe6e8..6e73265 100644 --- a/src/array_polynomial_mpfr.h +++ b/src/array_polynomial_mpfr.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY @@ -39,6 +40,8 @@ limitations under the License. // type of values #define ARRAY_VAL_TYPE polynomial_mpfr +// init +#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_mpfr_init(VAL, SIZE) // free #define ARRAY_VAL_FREE(VAL) polynomial_mpfr_free(VAL) // set values diff --git a/src/array_pthread_t.h b/src/array_pthread_t.h index e200c5d..aafce6e 100644 --- a/src/array_pthread_t.h +++ b/src/array_pthread_t.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY diff --git a/src/array_str.h b/src/array_str.h index 2d35d1b..2df0bef 100644 --- a/src/array_str.h +++ b/src/array_str.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY @@ -39,6 +40,8 @@ limitations under the License. // type of values #define ARRAY_VAL_TYPE array_char +// init +#define ARRAY_VAL_INIT(VAL, SIZE) array_char_init(VAL, SIZE) // free #define ARRAY_VAL_FREE(VAL) array_char_free(VAL) // set values diff --git a/src/array_uint.h b/src/array_uint.h index b3cec85..aaa195f 100644 --- a/src/array_uint.h +++ b/src/array_uint.h @@ -23,6 +23,7 @@ limitations under the License. #undef ARRAY_TYPENAME #undef ARRAY_FUNC #undef ARRAY_VAL_TYPE +#undef ARRAY_VAL_INIT #undef ARRAY_VAL_FREE #undef ARRAY_VAL_SET #undef ARRAY_VAL_CPY diff --git a/src/integral_base.c b/src/integral_base.c index da3f05a..e743191 100644 --- a/src/integral_base.c +++ b/src/integral_base.c @@ -254,16 +254,8 @@ int INTEGRAL_FUNC(integrate_gauss_smarttmp) (INTEGRAL_FLOAT_TYPE* out, int (*fun return(LIBINUM_ERROR_SIZE_MISMATCH); } - // allocate tmps if needed - if(tmps->memory<4){ - // no need to resize since the values should not be kept - INTEGRAL_FLOATARRAY_FUNC(free)(*tmps); - INTEGRAL_FLOATARRAY_FUNC(init)(tmps, 4); - } - for (i=tmps->length;i<4;i++){ - INTEGRAL_FLOAT_INIT(tmps->values[i]); - (tmps->length)++; - } + // allocate tmp values if needed + INTEGRAL_FLOATARRAY_FUNC(alloc_tmps)(4, tmps); // init to 0 INTEGRAL_FLOAT_SET_UI(*out, 0); |