Array: add array_alloc_tmps_*
This commit is contained in:
parent
2125f01f97
commit
46cae873fa
4
Changelog
Normal file
4
Changelog
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
1.0.1:
|
||||||
|
|
||||||
|
* Add a function to allocate memory for arrays of temporary values
|
||||||
|
|
2
Makefile
2
Makefile
@ -18,7 +18,7 @@
|
|||||||
# if static=1 then compile the static library
|
# if static=1 then compile the static library
|
||||||
STATIC=0
|
STATIC=0
|
||||||
|
|
||||||
VERSION=1.0
|
VERSION=1.0.1
|
||||||
|
|
||||||
# products of the compilation
|
# products of the compilation
|
||||||
PROJECT_SO=libinum.so.$(VERSION)
|
PROJECT_SO=libinum.so.$(VERSION)
|
||||||
|
@ -76,10 +76,10 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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>
|
<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>
|
</p>
|
||||||
|
|
||||||
<h2 style="margin-top:50pt;">Table of contents</h2>
|
<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>.
|
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>
|
</li>
|
||||||
<br>
|
<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">
|
<li id="func_array_subarray">
|
||||||
|
|
||||||
<div style="margin-bottom:5pt">
|
<div style="margin-bottom:5pt">
|
||||||
|
@ -76,10 +76,10 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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>
|
<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>
|
</p>
|
||||||
|
|
||||||
<h2 style="margin-top:50pt;">Table of contents</h2>
|
<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>.
|
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>
|
</li>
|
||||||
<br>
|
<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">
|
<li id="func_array_subarray">
|
||||||
<?php
|
<?php
|
||||||
for ($i=0; $i<count($typenames); $i++){
|
for ($i=0; $i<count($typenames); $i++){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef LIBINUM_H
|
#ifndef LIBINUM_H
|
||||||
#define LIBINUM_H
|
#define LIBINUM_H
|
||||||
|
|
||||||
#define LIBINUM_VERSION "1.0"
|
#define LIBINUM_VERSION "1.0.1"
|
||||||
|
|
||||||
#include <libinum/types.h>
|
#include <libinum/types.h>
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
@ -39,6 +40,8 @@ limitations under the License.
|
|||||||
|
|
||||||
// type of values
|
// type of values
|
||||||
#define ARRAY_VAL_TYPE array_mpfr
|
#define ARRAY_VAL_TYPE array_mpfr
|
||||||
|
// init
|
||||||
|
#define ARRAY_VAL_INIT(VAL, SIZE) array_mpfr_init(VAL, SIZE)
|
||||||
// free
|
// free
|
||||||
#define ARRAY_VAL_FREE(VAL) array_mpfr_free(VAL)
|
#define ARRAY_VAL_FREE(VAL) array_mpfr_free(VAL)
|
||||||
// set values
|
// set values
|
||||||
|
@ -247,3 +247,19 @@ int ARRAY_FUNC(print) (ARRAY_TYPENAME array){
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
||||||
|
@ -76,3 +76,7 @@ int ARRAY_FUNC(cmp) (ARRAY_TYPENAME array1, ARRAY_TYPENAME array2);
|
|||||||
int ARRAY_FUNC(print) (ARRAY_TYPENAME array);
|
int ARRAY_FUNC(print) (ARRAY_TYPENAME array);
|
||||||
#endif
|
#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
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
@ -39,6 +40,8 @@ limitations under the License.
|
|||||||
|
|
||||||
// type of values
|
// type of values
|
||||||
#define ARRAY_VAL_TYPE mpfr_t
|
#define ARRAY_VAL_TYPE mpfr_t
|
||||||
|
// init
|
||||||
|
#define ARRAY_VAL_INIT(VAL, SIZE) mpfr_init(*(VAL))
|
||||||
// free
|
// free
|
||||||
#define ARRAY_VAL_FREE(VAL) mpfr_clear(VAL)
|
#define ARRAY_VAL_FREE(VAL) mpfr_clear(VAL)
|
||||||
// set values
|
// set values
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
@ -39,6 +40,8 @@ limitations under the License.
|
|||||||
|
|
||||||
// type of values
|
// type of values
|
||||||
#define ARRAY_VAL_TYPE polynomial_double
|
#define ARRAY_VAL_TYPE polynomial_double
|
||||||
|
// init
|
||||||
|
#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_double_init(VAL, SIZE)
|
||||||
// free
|
// free
|
||||||
#define ARRAY_VAL_FREE(VAL) polynomial_double_free(VAL)
|
#define ARRAY_VAL_FREE(VAL) polynomial_double_free(VAL)
|
||||||
// set values
|
// set values
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
@ -39,6 +40,8 @@ limitations under the License.
|
|||||||
|
|
||||||
// type of values
|
// type of values
|
||||||
#define ARRAY_VAL_TYPE polynomial_ldouble
|
#define ARRAY_VAL_TYPE polynomial_ldouble
|
||||||
|
// init
|
||||||
|
#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_ldouble_init(VAL, SIZE)
|
||||||
// free
|
// free
|
||||||
#define ARRAY_VAL_FREE(VAL) polynomial_ldouble_free(VAL)
|
#define ARRAY_VAL_FREE(VAL) polynomial_ldouble_free(VAL)
|
||||||
// set values
|
// set values
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
@ -39,6 +40,8 @@ limitations under the License.
|
|||||||
|
|
||||||
// type of values
|
// type of values
|
||||||
#define ARRAY_VAL_TYPE polynomial_mpfr
|
#define ARRAY_VAL_TYPE polynomial_mpfr
|
||||||
|
// init
|
||||||
|
#define ARRAY_VAL_INIT(VAL, SIZE) polynomial_mpfr_init(VAL, SIZE)
|
||||||
// free
|
// free
|
||||||
#define ARRAY_VAL_FREE(VAL) polynomial_mpfr_free(VAL)
|
#define ARRAY_VAL_FREE(VAL) polynomial_mpfr_free(VAL)
|
||||||
// set values
|
// set values
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
@ -39,6 +40,8 @@ limitations under the License.
|
|||||||
|
|
||||||
// type of values
|
// type of values
|
||||||
#define ARRAY_VAL_TYPE array_char
|
#define ARRAY_VAL_TYPE array_char
|
||||||
|
// init
|
||||||
|
#define ARRAY_VAL_INIT(VAL, SIZE) array_char_init(VAL, SIZE)
|
||||||
// free
|
// free
|
||||||
#define ARRAY_VAL_FREE(VAL) array_char_free(VAL)
|
#define ARRAY_VAL_FREE(VAL) array_char_free(VAL)
|
||||||
// set values
|
// set values
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
#undef ARRAY_TYPENAME
|
#undef ARRAY_TYPENAME
|
||||||
#undef ARRAY_FUNC
|
#undef ARRAY_FUNC
|
||||||
#undef ARRAY_VAL_TYPE
|
#undef ARRAY_VAL_TYPE
|
||||||
|
#undef ARRAY_VAL_INIT
|
||||||
#undef ARRAY_VAL_FREE
|
#undef ARRAY_VAL_FREE
|
||||||
#undef ARRAY_VAL_SET
|
#undef ARRAY_VAL_SET
|
||||||
#undef ARRAY_VAL_CPY
|
#undef ARRAY_VAL_CPY
|
||||||
|
@ -254,16 +254,8 @@ int INTEGRAL_FUNC(integrate_gauss_smarttmp) (INTEGRAL_FLOAT_TYPE* out, int (*fun
|
|||||||
return(LIBINUM_ERROR_SIZE_MISMATCH);
|
return(LIBINUM_ERROR_SIZE_MISMATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate tmps if needed
|
// allocate tmp values if needed
|
||||||
if(tmps->memory<4){
|
INTEGRAL_FLOATARRAY_FUNC(alloc_tmps)(4, tmps);
|
||||||
// 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)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// init to 0
|
// init to 0
|
||||||
INTEGRAL_FLOAT_SET_UI(*out, 0);
|
INTEGRAL_FLOAT_SET_UI(*out, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user