1
/* These are functions used here and there to write Apophenia. They're
2
not incredibly useful, or even very good form, so they're not public. Cut
3
& paste `em into your own code if you'd like.
6
/* Many Apop functions try to treat the vector and matrix equally, which
7
requires knowing which exists and what the sizes are. */
8
#define Get_vmsizes(d) \
9
int firstcol = d && (d)->vector ? -1 : 0; \
10
int vsize = d && (d)->vector ? (d)->vector->size : 0; \
11
int wsize = d && (d)->weights ? (d)->weights->size : 0; \
12
int msize1 = d && (d)->matrix ? (d)->matrix->size1 : 0; \
13
int msize2 = d && (d)->matrix ? (d)->matrix->size2 : 0; \
14
int tsize = vsize + msize1*msize2; \
15
int maxsize = GSL_MAX(vsize, GSL_MAX(msize1, d?d->textsize[0]:0));\
16
(void)(tsize||wsize||firstcol||maxsize) /*prevent unused variable complaints */;
18
// Define a static variable, and initialize on first use.
19
#define Staticdef(type, name, def) static type (name) = NULL; if (!(name)) (name) = (def);
21
// Check for NULL and complain if so.
22
#define Nullcheck(in, errval) Apop_assert_c(in, errval, apop_errorlevel, "%s is NULL.", #in);
23
#define Nullcheck_m(in, errval) Apop_assert_c(in, errval, apop_errorlevel, "%s is a NULL model.", #in);
24
#define Nullcheck_mp(in, errval) Nullcheck_m(in, errval); Apop_assert_c((in)->parameters, errval, apop_errorlevel, "%s is a model with NULL parameters. Please set the parameters and try again.", #in);
25
#define Nullcheck_d(in, errval) Apop_assert_c(in, errval, apop_errorlevel, "%s is a NULL data set.", #in);
26
//And because I do them all so often:
27
#define Nullcheck_mpd(data, model, errval) Nullcheck_m(model, errval); Nullcheck_p(model, errval); Nullcheck_d(data, errval);
29
#define Nullcheck_p(in, errval) Nullcheck_mp(in, errval);
31
//in apop_conversions.c Extend a string.
32
void xprintf(char **q, char *format, ...);
33
#define XN(in) ((in) ? (in) : "")
35
//For a pedantic compiler. Continues on error, because there's not much else to do: the computer is clearly broken.
36
#define Asprintf(...) Apop_stopif(asprintf(__VA_ARGS__)==-1, , 0, "Error printing to a string.")
40
int apop_use_sqlite_prepared_statements(size_t col_ct);
41
int apop_prepare_prepared_statements(char const *tabname, size_t col_ct, sqlite3_stmt **statement);
42
char *prep_string_for_sqlite(int prepped_statements, char const *astring);//apop_conversions.c
43
void apop_gsl_error(char const *reason, char const *file, int line, int gsl_errno); //apop_linear_algebra.c
45
//For when we're forced to use a global variable.
47
#if __STDC_VERSION__ > 201100L
48
#define threadlocal _Thread_local
49
#elif defined(__APPLE__)
51
#elif defined(__GNUC__) && !defined(threadlocal)
52
#define threadlocal __thread
58
#define PRAGMA(x) _Pragma(#x)
59
#define OMP_critical(tag) PRAGMA(omp critical ( tag ))
60
#define OMP_for(...) _Pragma("omp parallel for") for(__VA_ARGS__)
61
#define OMP_for_reduce(red, ...) PRAGMA(omp parallel for reduction( red )) for(__VA_ARGS__)
63
#define OMP_critical(tag)
64
#define OMP_for(...) for(__VA_ARGS__)
65
#define OMP_for_reduce(...) for(__VA_ARGS__)
69
#ifndef HAVE___ATTRIBUTE__
70
#define __attribute__(...)
76
//asprintf, vararg, &c
77
extern int asprintf (char **res, const char *format, ...)
78
__attribute__ ((__format__ (__printf__, 2, 3)));
79
extern int vasprintf (char **res, const char *format, va_list args)
80
__attribute__ ((__format__ (__printf__, 2, 0)));
84
void add_info_criteria(apop_data *d, apop_model *m, apop_model *est, double ll, int param_ct); //In apop_mle.c
86
apop_model *maybe_prep(apop_data *d, apop_model *m, _Bool *is_a_copy); //in apop_mcmc, for apop_update.