QPALM
A proximal augmented Lagrangian method for QPs.
All Data Structures Files Functions Variables Typedefs Macros Pages
global_opts.h
Go to the documentation of this file.
1 
11 #ifndef GLOBAL_OPTS_H
12 # define GLOBAL_OPTS_H
13 
14 # ifdef __cplusplus
15 extern "C" {
16 # endif /* ifdef __cplusplus */
17 
18 
19 #include "ladel.h"
20 typedef ladel_double c_float;
21 typedef ladel_int c_int;
32 # include <stdlib.h>
33 
42 # ifdef MATLAB
43  # include "mex.h"
44 static void* c_calloc(size_t num, size_t size) {
45  void *m = mxCalloc(num, size);
46  mexMakeMemoryPersistent(m);
47  return m;
48 }
49 
50 static void* c_malloc(size_t size) {
51  void *m = mxMalloc(size);
52 
53  mexMakeMemoryPersistent(m);
54  return m;
55 }
56 
57 static void* c_realloc(void *ptr, size_t size) {
58  void *m = mxRealloc(ptr, size);
59 
60  mexMakeMemoryPersistent(m);
61  return m;
62 }
63 
64  # define c_free mxFree
65 # elif defined PYTHON
66 
67 // Define memory allocation for python. Note that in Python 2 memory manager
68 // Calloc is not implemented
69  # include <Python.h>
70  # define c_malloc PyMem_Malloc
71  # if PY_MAJOR_VERSION >= 3
72  # define c_calloc PyMem_Calloc
73  # else /* if PY_MAJOR_VERSION >= 3 */
74 static void* c_calloc(size_t num, size_t size) {
75  void *m = PyMem_Malloc(num * size);
76 
77  memset(m, 0, num * size);
78  return m;
79 }
80 
81  # endif /* if PY_MAJOR_VERSION >= 3 */
82 
83  # define c_free PyMem_Free
84  # define c_realloc PyMem_Realloc
85 # else /* if not MATLAB of Python */
86  # define c_malloc malloc
87  # define c_calloc calloc
88  # define c_free free
89  # define c_realloc realloc
91 # endif /* ifdef MATLAB */
92 
98 /* PRINTING */
99 # ifdef PRINTING
100 # include <stdio.h>
101 # include <string.h>
102 
103 # ifdef MATLAB
104 # define c_print mexPrintf
105 
106 # elif defined PYTHON
107 # include <Python.h>
108 # define c_print(...) {PyGILState_STATE gstate; gstate = PyGILState_Ensure(); PySys_WriteStdout(__VA_ARGS__); PyGILState_Release(gstate);}
109 # elif defined R_LANG
110 # include <R_ext/Print.h>
111 # define c_print Rprintf
112 # else /* ifdef MATLAB */
113 # define c_print printf
114 # endif /* ifdef MATLAB */
115 
116 // Print error macro
117 # define c_eprint(...) c_print("ERROR in %s: ", __FUNCTION__); c_print( \
118  __VA_ARGS__); c_print("\n");
119 
120 # endif /* ifdef PRINTING */
121 
122 
127 # ifndef c_absval
128 # define c_absval(x) (((x) < 0) ? -(x) : (x))
129 # endif /* ifndef c_absval */
130 
131 # ifndef c_max
132 # define c_max(a, b) (((a) > (b)) ? (a) : (b))
133 # endif /* ifndef c_max */
134 
135 # ifndef c_min
136 # define c_min(a, b) (((a) < (b)) ? (a) : (b))
137 # endif /* ifndef c_min */
138 
139 # ifndef mod
140 # define mod(a,b) ((((a)%(b))+(b))%(b))
141 #endif
142 
143 #include <math.h>
144 # define c_sqrt sqrt
148 # ifdef __cplusplus
149 }
150 # endif /* ifdef __cplusplus */
151 
152 #endif /* ifndef GLOBAL_OPTS_H */
#define c_malloc
custom malloc
Definition: global_opts.h:86
#define c_calloc
custom calloc
Definition: global_opts.h:87
#define c_realloc
custom realloc
Definition: global_opts.h:89
ladel_int c_int
type for integer numbers
Definition: global_opts.h:21
ladel_double c_float
type for floating point numbers
Definition: global_opts.h:20