Skip to content

Commit

Permalink
Revise uses of apop_rng_get_thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben committed Jun 16, 2015
1 parent a679ba4 commit 4ff5cde
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 143 deletions.
4 changes: 2 additions & 2 deletions apop_asst.m4.c
Expand Up @@ -378,10 +378,10 @@ of <tt>gsl_rng</tt>s is extended to length \c thread, and each element extended
This function can be used anywhere a \ref gsl_rng would be used.
\param thread_in The number of the RNG to retrieve, starting at zero (which is
how OpenMP numbers its threads). If blank, I'll look up the current thread (via \c
how OpenMP numbers its threads). If -1, I'll look up the current thread (via \c
omp_get_thread_num) for you.
See \ref threading for additional notes.
See \ref threading for additional notes. In most cases, you want to use <tt>apop_rng_get_thread(-1)</tt>.
\return The appropriate RNG, initialized if necessary.
\hideinitializer
Expand Down
45 changes: 18 additions & 27 deletions apop_conversions.m4.c
Expand Up @@ -336,7 +336,7 @@ gsl_matrix *apop_matrix_copy(const gsl_matrix *in){

/** \page text_format Input text file formatting
This section describes the assumptions made by \ref apop_text_to_db and \ref apop_text_to_data.
This reference section describes the assumptions made by \ref apop_text_to_db and \ref apop_text_to_data.
Each row of the file will be converted to one record in the database or one row in the
matrix. Values on one row are separated by delimiters. Fixed-width input is also OK;
Expand All @@ -350,25 +350,20 @@ will delimit separate entries. To change the default, use an argument to
The input text file must be UTF-8 or traditional ASCII encoding. Delimiters must be ASCII characters.
If your data is in another encoding, try the POSIX-standard \c iconv program to filter the data to UTF-8.
\li The character after a backslash is read as a normal character, even if it is a delimiter, \c #, or \c ".
\li If a field contains several such special characters, surround it by \c "s. The surrounding marks are stripped and the text read verbatim.
\li Text does not need to be delimited by quotes (unless there are special characters). If a text field is quote-delimited, I'll strip them.
E.g., "Males, 30-40", is an OK column name, as is "Males named \\"Joe\\"".
\li Everything after a # is taken to be comments and ignored.
\li Blank lines (empty or consisting only of white space) are also ignored.
\li If you are reading into the <tt>gsl_matrix</tt> element of an \ref apop_data set,
\li The character after a backslash is read as a normal character, even if it is a delimiter, \c #, or \c ".
\li If a field contains several such special characters, surround it by \c "s. The
surrounding marks are stripped and the text read verbatim.
\li Text does not need to be delimited by quotes (unless there are special characters). If a text field is quote-delimited, I'll strip them.
E.g., "Males, 30-40", is an OK column name, as is "Males named \"Joe\\"".
\li Everything after an unprotected # is taken to be comments and ignored.
\li Blank lines (empty or consisting only of white space) are also ignored.
\li If you are reading into the <tt>gsl_matrix</tt> element of an \ref apop_data set,
all text fields are taken as zeros. You will be warned of such substitutions unless
you set \code apop_opts.verbose==0\endcode beforehand. For mixed text/numeric data,
you set <tt>apop_opts.verbose==0</tt> beforehand. For mixed text/numeric data,
try using \ref apop_text_to_db and then \ref apop_query_to_mixed_data.
\li There are often two delimiters in a row, e.g., "23, 32,, 12". When it's two commas
\li There are often two delimiters in a row, e.g., "23, 32,, 12". When it's two commas
like this, the user typically means that there is a missing value and the system should
insert an NAN; when it is two tabs in a row, this is typically just a formatting
insert a NAN; when it is two tabs in a row, this is typically just a formatting
glitch. Thus, if there are multiple delimiters in a row, I check whether the second
(and subsequent) is a space or a tab; if it is, then it is ignored, and if it is any
other delimiter (including the end of the line) then a NaN is inserted.
Expand All @@ -393,22 +388,18 @@ apop_opts.nan_string = NULL;
\endcode
SQLite stores these NaN-type values internally as \c NULL; that means that functions like
\ref apop_query_to_data will convert both your \c nan_string string and \c NULL to an \c NaN value.
\ref apop_query_to_data will convert both your \c nan_string string and \c NULL to \c NaN.
\li The system uses the standards for C's \c atof() function for
\li The system uses the standards for C's \c atof() function for
floating-point numbers: INFINITY, -INFINITY, and NaN work as expected.
\li If there are row names and column names, then the input will not be perfectly square:
\li If there are row names and column names, then the input will not be perfectly square:
there should be no first entry in the sequence of column names like <tt>row names</tt>. That is,
for a 100x100 data set with row and column names, there are 100 names in the top row,
and 101 entries in each subsequent row (name plus 100 data points).
\li White space before or after a field is ignored. So <tt>1, 2,3, 4 , 5, " six ",7 </tt>
\li White space before or after a field is ignored. So <tt>1, 2,3, 4 , 5, " six ",7 </tt>
is eqivalent to <tt>1,2,3,4,5," six ",7</tt>.
\li NUL characters are treated as white space, so if your fields have NULs as padding, you should have no problem. NULs inside of a string will probably break.
\li Fixed-width formats are supported (for plain ASCII encoding only), but you have to provide a list of field ending positions. For example, given
\li NUL characters (<tt>'\0'</tt>) are treated as white space, so if your fields have NULs as padding, you should have no problem. NULs inside of a string terminates the string as it always does in C.
\li Fixed-width formats are supported (for plain ASCII encoding only), but you have to provide a list of field ending positions. For example, given
\code
NUMLEOL
123AABB
Expand Down
3 changes: 2 additions & 1 deletion apop_db_sqlite.c
Expand Up @@ -135,7 +135,8 @@ static void powFn(sqlite3_context *context, int argc, sqlite3_value **argv){

static void rngFn(sqlite3_context *context, int argc, sqlite3_value **argv){
Staticdef(gsl_rng *, rng, apop_rng_alloc(apop_opts.rng_seed++));
sqlite3_result_double(context, gsl_rng_uniform(rng));
//sqlite3_result_double(context, gsl_rng_uniform(rng));
sqlite3_result_double(context, gsl_rng_uniform(apop_rng_get_thread(-1)));
}

#define sqfn(name) static void name##Fn(sqlite3_context *context, int argc, sqlite3_value **argv){ \
Expand Down
2 changes: 1 addition & 1 deletion apop_mcmc.m4.c
Expand Up @@ -281,7 +281,7 @@ APOP_VAR_HEAD apop_model *apop_model_metropolis(apop_data *d, gsl_rng *rng, apop
apop_data *apop_varad_var(d, NULL);
apop_model *apop_varad_var(m, NULL);
Apop_stopif(!m, return NULL, 0, "NULL model input.");
gsl_rng *apop_varad_var(rng, apop_rng_get_thread());
gsl_rng *apop_varad_var(rng, apop_rng_get_thread(-1));
APOP_VAR_END_HEAD
apop_model *outp;
OMP_critical(metropolis)
Expand Down
2 changes: 1 addition & 1 deletion apop_model.c
Expand Up @@ -400,7 +400,7 @@ int apop_model_metropolis_draw(double *out, gsl_rng* rng, apop_model *params);//
\return Zero on success; nozero on failure. <tt>out[0]</tt> is probably \c NAN on failure.
*/
int apop_draw(double *out, gsl_rng *r, apop_model *m){
if (!r) r = apop_rng_get_thread();
if (!r) r = apop_rng_get_thread(-1);
if (m->draw)
return m->draw(out, r, m);
else if (m->dsize == 1)
Expand Down
4 changes: 2 additions & 2 deletions apop_stats.m4.c
Expand Up @@ -702,7 +702,7 @@ APOP_VAR_HEAD long double apop_kl_divergence(apop_model *from, apop_model *to, i
Apop_stopif(!from, return NAN, 0, "The first model is NULL; returning NaN.");
Apop_stopif(!to, return NAN, 0, "The second model is NULL.");
double apop_varad_var(draw_ct, 1e5);
gsl_rng * apop_varad_var(rng, apop_rng_get_thread());
gsl_rng * apop_varad_var(rng, apop_rng_get_thread(-1));
APOP_VAR_ENDHEAD
double div = 0;
Apop_notify(3, "p(from)\tp(to)\tfrom*log(from/to)\n");
Expand All @@ -728,7 +728,7 @@ APOP_VAR_ENDHEAD
apop_data *draw_list = apop_data_alloc(draw_ct, 2);
OMP_for_reduce(+:div, int i=0; i < draw_ct; i++){
double draw[from->dsize];
apop_draw(draw, apop_rng_get_thread(), from);
apop_draw(draw, apop_rng_get_thread(-1), from);
gsl_matrix_view dm = gsl_matrix_view_array(draw, 1, from->dsize);
double pi = apop_p(&(apop_data){.matrix=&(dm.matrix)}, from);
double qi = apop_p(&(apop_data){.matrix=&(dm.matrix)}, to);
Expand Down
2 changes: 1 addition & 1 deletion apop_update.m4.c
Expand Up @@ -184,7 +184,7 @@ APOP_VAR_HEAD apop_model * apop_update(apop_data *data, apop_model *prior, apop_
apop_data *apop_varad_var(data, NULL);
apop_model *apop_varad_var(prior, NULL);
apop_model *apop_varad_var(likelihood, NULL);
gsl_rng *apop_varad_var(rng, apop_rng_get_thread());
gsl_rng *apop_varad_var(rng, apop_rng_get_thread(-1));
APOP_VAR_END_HEAD
static int setup=0; if (!(setup++)){
apop_update_vtable_add(betabinom, apop_beta, apop_binomial);
Expand Down
3 changes: 1 addition & 2 deletions docs/adjust
Expand Up @@ -12,8 +12,7 @@ sed -i 's/pdflatex/xelatex/' latex/Makefile
sed -i "/familydefault.*sfdefault/ d" latex/refman.tex

#No footer
sed -i "/fancyhead/ d" latex/refman.tex
sed -i "/fancyfoot/ d" latex/refman.tex
sed -i -e "/fancyhead/ d" -e "/fancyfoot/ d" -e "Generated by Doxygen/ d" latex/refman.tex

#Fix enumerations -> model documentation
sed -i -f edit_group.sed latex/group__models.tex
Expand Down

0 comments on commit 4ff5cde

Please sign in to comment.