Patterns in static

Apophenia

apop_internal.h
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.
4  */
5 
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 */;
17 
18 // Define a static variable, and initialize on first use.
19 #define Staticdef(type, name, def) static type (name) = NULL; if (!(name)) (name) = (def);
20 
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);
28 //deprecated:
29 #define Nullcheck_p(in, errval) Nullcheck_mp(in, errval);
30 
31 //in apop_conversions.c Extend a string.
32 void xprintf(char **q, char *format, ...);
33 #define XN(in) ((in) ? (in) : "")
34 
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.")
37 
38 #include <sqlite3.h>
39 #include <stddef.h>
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
44 
45 //For when we're forced to use a global variable.
46 #undef threadlocal
47 #if __STDC_VERSION__ > 201100L
48  #define threadlocal _Thread_local
49 #elif defined(__APPLE__)
50  #define threadlocal
51 #elif defined(__GNUC__) && !defined(threadlocal)
52  #define threadlocal __thread
53 #else
54  #define threadlocal
55 #endif
56 
57 #ifdef _OPENMP
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__)
62 #else
63 #define OMP_critical(tag)
64 #define OMP_for(...) for(__VA_ARGS__)
65 #define OMP_for_reduce(...) for(__VA_ARGS__)
66 #endif
67 
68 #include "config.h"
69 #ifndef HAVE___ATTRIBUTE__
70 #define __attribute__(...)
71 #endif
72 
73 #ifndef HAVE_ASPRINTF
74 #include <stdarg.h>
75 
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)));
81 #endif
82 
83 #include "apop.h"
84 void add_info_criteria(apop_data *d, apop_model *m, apop_model *est, double ll, int param_ct); //In apop_mle.c
85 
86 apop_model *maybe_prep(apop_data *d, apop_model *m, _Bool *is_a_copy); //in apop_mcmc, for apop_update.
Definition: apop.h:77
Definition: apop.h:102
char * prep_string_for_sqlite(int prepped_statements, char const *astring)
Definition: apop_conversions.c:1035

Autogenerated by doxygen on Wed Oct 15 2014 (Debian 0.999b+ds3-2).