clean up debugging format statements

parent 94122792
......@@ -2,20 +2,20 @@
#include "rinterpolate_internal.h"
/*
* librinterpolate
*
*
* A library to perform n-dimensional linear interpolation on a table
* of data.
*
* The table should be organised (in memory) like this
*
* p1[0] p2[0] p3[0] ... d1[0] d2[0] d3[0] d4[0] ...
* p1[1] p2[1] p3[1] ... d1[1] d2[1] d3[1] d4[1] ...
* p1[2] p2[2] p3[2] ... d1[2] d2[2] d3[2] d4[2] ...
* p1[0] p2[0] p3[0] ... d1[0] d2[0] d3[0] d4[0] ...
* p1[1] p2[1] p3[1] ... d1[1] d2[1] d3[1] d4[1] ...
* p1[2] p2[2] p3[2] ... d1[2] d2[2] d3[2] d4[2] ...
*
* so there are n parameters (p1, p2, p3...) and d data items
* per data line (d1, d2, d3, d4 ...). There are l lines of data.
*
* The parameters should be ordered from low to high values.
* The parameters should be ordered from low to high values.
* The parameters should be on a *constant* grid (which does NOT
* need to be regular).
*
......@@ -34,13 +34,13 @@
* 0.3 -100 30 ...data...
* 0.3 -50 10 ...data...
* 0.3 -50 25 ...data...
* 0.3 -50 30 ...data...
* 0.3 -50 30 ...data...
* 0.9 -100 10 ...data...
* 0.9 -100 25 ...data...
* 0.9 -100 30 ...data...
* 0.9 -50 10 ...data...
* 0.9 -50 25 ...data...
* 0.9 -50 30 ...data...
* 0.9 -50 30 ...data...
*
* In the above case, the parameters have values:
* p0 : 0.1,0.3,0.9
......@@ -49,7 +49,7 @@
*
* The parameter "hypercube" then is the 3D-hypercube of
* 3 * 2 * 3 = 18 data lines.
*
*
* Note that the points on the cube are *constant* but not *regular*,
* e.g. p0 has spacing (0.3-0.1)=0.2 and (0.9-0.3)=0.6, which are different,
* BUT e.g. the spacing for p1 (-100 - -50 = -50) is the same, whatever the
......@@ -60,9 +60,9 @@
* to LARGEST parameter values. It is also assumed to be regular and filled.
* So no missing data please, just put some dummy values in the table.
*
* In order to interpolate data, n parameters are passed into this
* In order to interpolate data, n parameters are passed into this
* routine in the array x. The result of the interpolation is put
* into the array r (of size d).
* into the array r (of size d).
*
* If you enable RINTERPOLATE_CACHE then results are cached to avoid
* slowing the code too much. (This is set in binary_c_code_options.h) This means
......@@ -81,13 +81,13 @@
* two spanning values). Linear interpolation is then done in the largest
* dimension, above this is the third parameter (p2), then the second (p1)
* and finally on the remaining variable (p0). This would reduce the table
* from 2^3 lines to 2^2 to 2^1 to (finally) 2^0 i.e. one line which is the
* from 2^3 lines to 2^2 to 2^1 to (finally) 2^0 i.e. one line which is the
* interpolation result.
*
* To find the spanning lines a binary search is performed. This code was
* donated by Evert Glebbeek. See e.g.
* donated by Evert Glebbeek. See e.g.
* http://en.wikipedia.org/wiki/Binary_search_algorithm
* and note the comment "Although the basic idea of binary search is comparatively
* and note the comment "Although the basic idea of binary search is comparatively
* straightforward, the details can be surprisingly tricky... " haha! :)
*
* Each table has its own unique table_id number. This is just to allow
......@@ -97,7 +97,7 @@
* you do not have to set one yourself, but this does assume that the tables
* are each at fixed memory locations. This is guaranteed if you declare them
* with the recommended data type Const_data_table, e.g.
*
*
* Const_data_table mytable = { 0.0, 100.0, 1.0, 200.0, 2.0, 500.0 };
*
* (Const_data_table is a "const static rinterpolate_float_t" type, which implies its memory
......@@ -111,11 +111,11 @@
*
* I have optimized this as best I can, please let me know if
* you can squeeze any more speed out of the function.
* I am sorry this has made most of the function unreadable! The
* I am sorry this has made most of the function unreadable! The
* comments should help, but you will need to know some tricks...
*
* Certain variables deserve extra mention:
*
*
* varcount
* This is the number of unique values of a given parameters. In the above
* example, this would be varcount[0]=3, varcount[1]=2, varcount[2]=3
......@@ -129,19 +129,19 @@
*
* int_table
* This is the initially constructed hypercube which is reduced
* in dimension (e.g. in the above from 3 to 2 to 1) until final
* in dimension (e.g. in the above from 3 to 2 to 1) until final
* interpolation is done.
*
* RINTERPOLATE_CACHE_LENGTH
* The length of the table. Should be >= the number of tables you
* The length of the table. Should be >= the number of tables you
* are using. Usually 5 is good, less means faster cache compares
* but you're less likely to match!
*
* Note: uses Fequal macros to check for floating-point equality, you should
* check that TINY (current the smallest floating point epsilon)
* is small enough for your parameters, or rescale your
* parameters so they are much bigger than TINY (that's best,
* as TINY may be used used elsewhere). You could, of course, define a
* parameters so they are much bigger than TINY (that's best,
* as TINY may be used used elsewhere). You could, of course, define a
* different (slower) macro.
*
* (c) Robert Izzard, 2005-2019, please send bug fixes!
......@@ -159,10 +159,10 @@ struct rinterpolate_data_t * rinterpolate(
const rinterpolate_counter_t cache_length // number of cache lines
)
{
#if defined RINTERPOLATE_DEBUG && defined RINTERPOLATE_SHOW_TABLE
#if defined RINTERPOLATE_DEBUG && defined RINTERPOLATE_SHOW_TABLE
rinterpolate_counter_t i=0;
#endif
Rinterpolate_print("DEBUG RINTERPOLATE datatable=%p n=%d d=%d l=%d x=%p r=%p cache_length=%d\n",
Rinterpolate_print("DEBUG RINTERPOLATE datatable=%p n=%u d=%u l=%u x=%p r=%p cache_length=%u\n",
datatable,
n,d,l,x,r,cache_length);
......@@ -179,10 +179,10 @@ struct rinterpolate_data_t * rinterpolate(
rinterpolate_signed_counter_t table_id;
/*
* First time through:
* First time through:
* set up memory space if not already done
*/
if(unlikely(rinterpolate_data==NULL))
if(unlikely(rinterpolate_data==NULL))
{
rinterpolate_alloc_dataspace(&rinterpolate_data);
table_id = -1;
......@@ -198,11 +198,11 @@ struct rinterpolate_data_t * rinterpolate(
}
Rinterpolate_print("Table ID %d\n",table_id);
if(table_id == -1)
{
/*
* Table not found, so add a new table
* Table not found, so add a new table
*/
table_id = rinterpolate_add_new_table(rinterpolate_data,
datatable,
......@@ -212,7 +212,7 @@ struct rinterpolate_data_t * rinterpolate(
cache_length);
Rinterpolate_print("New table ID %d\n",table_id);
}
/*
* Pointer to the table
*/
......@@ -228,8 +228,8 @@ struct rinterpolate_data_t * rinterpolate(
{
rinterpolate_resize_cache(table,cache_length);
}
#endif // RINTERPOLATE_CACHE
#endif // RINTERPOLATE_CACHE
#ifdef RINTERPOLATE_DEBUG
#ifdef RINTERPOLATE_DEBUG_SHOW_TABLE
if(rinterpolate_debug == TRUE)
......@@ -237,7 +237,7 @@ struct rinterpolate_data_t * rinterpolate(
int _i;
for(_i=0;_i<l;_i++)
{
Rinterpolate_print("L%d ",_i);
Rinterpolate_print("L%u ",_i);
rinterpolate_counter_t j;
for(j=0;j<table->line_length;j++)
{
......@@ -250,8 +250,8 @@ struct rinterpolate_data_t * rinterpolate(
#endif // RINTERPOLATE_DEBUG_SHOW_TABLE
#endif //RINTERPOLATE_DEBUG
#ifdef RINTERPOLATE_CACHE
#ifdef RINTERPOLATE_CACHE
/* check for cache match */
if(cache_length &&
rinterpolate_check_cache(table,x,r) == TRUE)
......@@ -267,7 +267,7 @@ struct rinterpolate_data_t * rinterpolate(
* First, search the table to find the spanning indices.
*/
rinterpolate_search_table(table,x);
#ifdef RINTERPOLATE_DEBUG
if(rinterpolate_debug==TRUE)
{
......@@ -288,12 +288,12 @@ struct rinterpolate_data_t * rinterpolate(
Rinterpolate_print("Interpolation hypertable:\n");
}
#endif
/*
* construct hypercube
*/
rinterpolate_construct_hypercube(table);
/*
* Do interpolation on hypercube
*/
......@@ -315,7 +315,7 @@ struct rinterpolate_data_t * rinterpolate(
Rinterpolate_print("\n");FLUSH;
}
#endif
#ifdef RINTERPOLATE_CACHE
/*
* No cache match but interpolation done:
......@@ -328,10 +328,9 @@ struct rinterpolate_data_t * rinterpolate(
}
cache_match:
#endif // RINTERPOLATE_CACHE
return rinterpolate_data;
}
}
......@@ -76,10 +76,10 @@ typedef unsigned int rinterpolate_Boolean_t;
/* ditto for the j loop (see below) */
#define RINTERPOLATE_POINTER_ARITHMETIC_J_LOOP
/*
/*
* with the new cache we use macros to
* access cache items, rather than accessing
* them directly
* access cache items, rather than accessing
* them directly
*/
/* length of a line in the cache */
......@@ -96,7 +96,7 @@ typedef unsigned int rinterpolate_Boolean_t;
/*
* Make short arrays through which binary searches are done:
* this is usually faster because these are smaller than the
* this is usually faster because these are smaller than the
* CPU cache.
*/
#define RINTERPOLATE_PRESEARCH
......@@ -106,14 +106,14 @@ typedef unsigned int rinterpolate_Boolean_t;
/*
* Use memcmp to compare cache lines?
* The alternative is !Fequal, which is usually a bit faster.
* The alternative is !Fequal, which is usually a bit faster.
* Your mileage may vary.
*/
#define RINTERPOLATE_CACHE_USE_MEMCMP
/************************************************************
* rinterpolate's structures
* rinterpolate's structures
************************************************************/
struct rinterpolate_hypertable_t {
......@@ -128,7 +128,7 @@ struct rinterpolate_hypertable_t {
struct rinterpolate_table_t {
struct rinterpolate_data_t * parent;
struct rinterpolate_hypertable_t * hypertable;
struct rinterpolate_hypertable_t * hypertable;
rinterpolate_float_t * data;
#ifdef RINTERPOLATE_CACHE
rinterpolate_float_t * RESTRICT cache;
......@@ -158,7 +158,7 @@ struct rinterpolate_table_t {
rinterpolate_counter_t hypertable_length;
rinterpolate_counter_t table_number;
};
struct rinterpolate_data_t {
struct rinterpolate_table_t * * RESTRICT tables;
......
......@@ -9,16 +9,16 @@ void rinterpolate_alloc_cacheline(struct rinterpolate_table_t * RESTRICT const t
table->cache_spin_line = -1;
#ifdef RINTERPOLATE_DEBUG
Rinterpolate_print("Allocated new cache array for table_id=%d\n",
Rinterpolate_print("Allocated new cache array for table_id=%u\n",
table->table_number);
#endif
/*
* Allocate cache space for this interpolation table
*/
table->cache =
table->cache =
Rinterpolate_calloc(table->line_length*table->cache_length,
sizeof(rinterpolate_float_t));
#ifdef RINTERPOLATE_ALLOC_CHECKS
if(unlikely(table->cache==NULL))
{
......
......@@ -4,8 +4,8 @@
void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT const table)
{
/* make space for hypertable */
table->hypertable = Rinterpolate_malloc(sizeof(struct rinterpolate_hypertable_t));
table->hypertable = Rinterpolate_malloc(sizeof(struct rinterpolate_hypertable_t));
#ifdef RINTERPOLATE_DEBUG
Rinterpolate_print("Interpolate: memory allocation\n");FLUSH;
#endif
......@@ -30,9 +30,9 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT const
table->parent);
}
#endif//RINTERPOLATE_ALLOC_CHECKS
#ifdef RINTERPOLATE_DEBUG
Rinterpolate_print("table->hypertable->data alloc 2 * %d * %zu\n",table->hypertable_length,table->line_length_sizeof);
Rinterpolate_print("table->hypertable->data alloc 2 * %u * %zu\n",table->hypertable_length,table->line_length_sizeof);
#endif
#ifdef RINTERPOLATE_USE_REALLOC
......
......@@ -12,14 +12,14 @@ void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT const ta
table->parent,
table->table_number);
}
#endif
#endif
/* fast counting method! */
rinterpolate_counter_t b = table->l;
rinterpolate_counter_t j;
for(j=0; j<table->n; j++)
{
#ifdef RINTERPOLATE_DEBUG
Rinterpolate_print("Interpolate debug: varcount[%d]=%d, b=%d, steps[%d]=%d\n",
Rinterpolate_print("Interpolate debug: varcount[%u]=%u, b=%u, steps[%u]=%u\n",
j,table->varcount[j],b,j,table->steps[j]);
FLUSH;
#endif
......
......@@ -10,22 +10,22 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
* Set the cache location
*/
rinterpolate_Boolean_t match = FALSE;
/*
* Now check the cache to see if it matches with the current search.
*
* ... but if no cache was previously saved there is no point trying.
* ... but if no cache was previously saved there is no point trying.
*/
if(table->cache_spin_line == -1 || table->cache_length == 0)
{
match = FALSE;
}
else
{
{
/*
* Start the loop
*/
rinterpolate_counter_t imax =
rinterpolate_counter_t imax =
table->cache_match_line + table->cache_length;
rinterpolate_counter_t iloop,iline;
for(iloop = table->cache_match_line;
......@@ -41,7 +41,7 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
#ifdef RINTERPOLATE_CACHE_USE_MEMCMP
#ifdef RINTERPOLATE_DEBUG
{
Rinterpolate_print("check cache : cf %d\n x={ ",iline);
Rinterpolate_print("check cache : cf %u\n x={ ",iline);
int m;
for(m=0;m<table->n;m++)
{
......@@ -76,26 +76,26 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
#endif // RINTERPOLATE_CACHE_USE_MEMCMP
Rinterpolate_print("Post Match = %d\n",match);
Rinterpolate_print("Post Match = %u\n",match);
if(match==TRUE)
{
/*
/*
* cache matches at line iline so
* set the interpolation result directly from
* the cache
*/
memcpy(r,RINTERPOLATE_CACHE_RESULT(iline),table->d_float_sizeof);
Rinterpolate_print("cache match at line iline=%d (iloop=%d loop start %d)\n",iline,iloop,table->cache_match_line);
/*
* Save the position of the match for
Rinterpolate_print("cache match at line iline=%u (iloop=%u loop start %u)\n",iline,iloop,table->cache_match_line);
/*
* Save the position of the match for
* next time so we start searching at the match
* rather than the beginning of the cache
*/
table->cache_match_line = iline;
/* skip everything else */
goto cache_match;
}
......@@ -103,7 +103,7 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
}
cache_match:
Rinterpolate_print("return match = %d\n",match);
Rinterpolate_print("return match = %u\n",match);
return match;
}
#endif//RINTERPOLATE_CACHE
......@@ -4,7 +4,7 @@
void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT const table)
{
/*
* Construct hypercube
* Construct hypercube
*/
struct rinterpolate_hypertable_t * hypertable = table->hypertable;
......@@ -13,9 +13,9 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT con
rinterpolate_counter_t i;
for(i=0;i<table->hypertable_length;i++)
{
Rinterpolate_print("SUM %d was %d now ",i,hypertable->sum[i]);
Rinterpolate_print("SUM %u was %u now ",i,hypertable->sum[i]);
hypertable->sum[i] *= table->line_length;
Rinterpolate_print("%d (lnl = %d)\n",hypertable->sum[i],table->line_length);
Rinterpolate_print("%u (lnl = %u)\n",hypertable->sum[i],table->line_length);
}
rinterpolate_counter_t k = 0;
......@@ -24,26 +24,26 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT con
#ifdef RINTERPOLATE_DEBUG
if(rinterpolate_debug==TRUE)
{
Rinterpolate_print("memcpy k=%d i=%d : from %p to %p ( = %p + %d )\n",
k,
i,
hypertable->data + k,
table + hypertable->sum[i],
table,
hypertable->sum[i]
);
Rinterpolate_print("memcpy k=%u i=%u : from %p to %p ( = %p + %u )\n",
k,
i,
hypertable->data + k,
table + hypertable->sum[i],
table,
hypertable->sum[i]
);
}
#endif//RINTERPOLATE_DEBUG
memcpy(hypertable->data + k,
table->data + hypertable->sum[i],
table->line_length_sizeof);
k += table->line_length;
k += table->line_length;
#ifdef RINTERPOLATE_DEBUG
{
Rinterpolate_print("Line %d : ",i);FLUSH;
Rinterpolate_print("Line %u : ",i);FLUSH;
rinterpolate_counter_t j;
for(j=0;j<table->n;j++)
{
......@@ -54,9 +54,9 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT con
{
Rinterpolate_print("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
}
Rinterpolate_print(" %d/%d\n",i,table->hypertable_length-1);FLUSH;
Rinterpolate_print(" %u/%u\n",i,table->hypertable_length-1);FLUSH;
}
#endif
#endif
}
......
......@@ -11,12 +11,12 @@ rinterpolate_signed_counter_t Pure_function rinterpolate_id_table(
)
{
/* look for data table in the existing table_ids */
rinterpolate_Boolean_t found = FALSE;
Rinterpolate_print("Look for table in existing table ids\n");
Rinterpolate_print("currently have %d tables\n",rinterpolate_data->number_of_interpolation_tables);
Rinterpolate_print("currently have %u tables\n",rinterpolate_data->number_of_interpolation_tables);
rinterpolate_counter_t table_num = 0;
while(table_num < rinterpolate_data->number_of_interpolation_tables)
{
......@@ -39,7 +39,7 @@ rinterpolate_signed_counter_t Pure_function rinterpolate_id_table(
}
else
{
Rinterpolate_print("Found at %d\n",table_num);
Rinterpolate_print("Found at %u\n",table_num);
}
return table_num;
......
......@@ -27,7 +27,7 @@ void rinterpolate_interpolate(
* Do the interpolation
*/
#ifdef RINTERPOLATE_DEBUG
Rinterpolate_print("Interpolate n=%d f=%g\n",table->n,hypertable->f[n]);
Rinterpolate_print("Interpolate n=%u f=%g\n",table->n,hypertable->f[n]);
FLUSH;
#endif
#ifdef RINTERPOLATE_USE_POINTER_ARITHMETIC
......
......@@ -6,7 +6,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT const table)
/*
* First time with this table: Find the variable steps
*/
table->steps = Rinterpolate_calloc(table->n,sizeof(rinterpolate_counter_t));
table->steps = Rinterpolate_calloc(table->n,sizeof(rinterpolate_counter_t));
#ifdef RINTERPOLATE_ALLOC_CHECKS
if(unlikely(table->steps==NULL))
......@@ -23,10 +23,10 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT const table)
#endif
rinterpolate_counter_t i,j;
if(table->l<2)
{
/* special case : one line of data */
/* special case : one line of data */
for(j=0; j<table->n; j++)
{
table->steps[j] = 1;
......@@ -38,7 +38,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT const table)
for(j=0; j<table->n; j++)
{
table->steps[j] = table->l; // fallback
/* loop over lines */
for(i=1; i<table->l; i++)
{
......@@ -50,17 +50,29 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT const table)
table->data[(i-1)*table->line_length + j],
table->data[i *table->line_length + j]);
*/
/*
/*
* Compare this line to the previous,
* if different, set the step
*/
#ifdef RINTERPOLATE_DEBUG
Rinterpolate_print("cf. data at indices %zu and %zu\n",
(size_t)((i-1)*table->line_length + j),
(size_t)(i *table->line_length + j));
Rinterpolate_print("cf. pointers %p and %p\n",
table->data + (size_t)((i-1)*table->line_length + j),
table->data + (size_t)(i *table->line_length + j));
Rinterpolate_print("cf. data are %g and %g\n",
table->data[(i-1)*table->line_length + j],
table->data[i *table->line_length + j]);
#endif
if(!Fequal(table->data[(i-1)*table->line_length + j],
table->data[i *table->line_length + j]))
{
// change
table->steps[j] = i;
Rinterpolate_print("SET STEPS for var %d to %d\n",j,table->steps[j]);
Rinterpolate_print("SET STEPS for var %u to %u\n",j,table->steps[j]);
i=table->l+1; // break i loop
}
}
......
......@@ -11,7 +11,7 @@ void rinterpolate_search_table(
Rinterpolate_print("search table for span of { ");
for(j=0;j<table->n;j++)
{
Rinterpolate_print("x[%d]=%g%s",j,x[j],j!=(table->n-1)?", ":" }\n");
Rinterpolate_print("x[%u]=%g%s",j,x[j],j!=(table->n-1)?", ":" }\n");
}
FLUSH;
#endif
......@@ -31,7 +31,7 @@ void rinterpolate_search_table(
for(j=0;j<table->n;j++)
{
/*
* limit the value of our given parameter x[j] to the range we have
* limit the value of our given parameter x[j] to the range we have
* and save to the parameter v
*/
rinterpolate_counter_t b = table->varcount[j];
......@@ -59,7 +59,7 @@ void rinterpolate_search_table(
#ifdef RINTERPOLATE_DEBUG
if(rinterpolate_debug)
{
Rinterpolate_print("Construct variable %d hypertable position\n",
Rinterpolate_print("Construct variable %u hypertable position\n",
j);
FLUSH;
......@@ -69,7 +69,7 @@ void rinterpolate_search_table(
*/
if(x[j] - DBL_EPSILON > table->data[g+j])
{
printf("WARNING : parameter %d is %g which exceeds (by %g cf. TINY = %g DBL_EPSILON = %g) the maximum possible which is %g\n",
printf("WARNING : parameter %u is %g which exceeds (by %g cf. TINY = %g DBL_EPSILON = %g) the maximum possible which is %g\n",
j,
x[j],
x[j] - table->data[g+j],
......@@ -86,11 +86,11 @@ void rinterpolate_search_table(
* and b=varcount[j] (the max possible value, set above)
*/
rinterpolate_counter_t a = 0;
if(likely(b>1))
{
/*
* Binary search blatantly stolen (well, with permission)
* Binary search blatantly stolen (well, with permission)
* from Evert Glebbeek's code (thanks Evert!)
*/
#ifndef RINTERPOLATE_PRESEARCH
......@@ -106,15 +106,15 @@ void rinterpolate_search_table(
*
* BINARY_SEARCH 10.68
* QUADRATIC_SEARCH 11.03 (inaccurate)
* PULVER_SEARCH 11.95
* DIRECT_SEARCH 44.34
* PULVER_SEARCH 11.95
* DIRECT_SEARCH 44.34