QPALM main
Proximal Augmented Lagrangian method for Quadratic Programs
Loading...
Searching...
No Matches
global_opts.h
Go to the documentation of this file.
1/**
2 * @file global_opts.h
3 * @author Ben Hermans
4 * @brief Custom memory allocation, print and utility functions, and data types for floats and ints.
5 * @details Memory allocation and print functions depend on whether the code is compiled as a standalone
6 * library or with matlab or python. The data types used for floating point numbers and integer numbers
7 * can be changed here as well. Finally, some customized operations (max, min, mod and abs) are included
8 * as well.
9 */
10
11#ifndef GLOBAL_OPTS_H
12# define GLOBAL_OPTS_H
13
14#ifdef WIN32
15# ifdef __GNUC__
16# ifdef QPALM_EXPORTS
17# define QPALM_EXPORT __attribute__((dllexport))
18# elif QPALM_IMPORTS
19# define QPALM_EXPORT __attribute__((dllimport))
20# else
21# define QPALM_EXPORT
22# endif
23# else /* __GNUC__ */
24# ifdef QPALM_EXPORTS
25# define QPALM_EXPORT __declspec(dllexport)
26# elif QPALM_IMPORTS
27# define QPALM_EXPORT __declspec(dllimport)
28# else
29# define QPALM_EXPORT
30# endif
31# endif /* __GNUC__ */
32#else /* WIN32 */
33# define QPALM_EXPORT __attribute__((visibility("default")))
34#endif /* WIN32 */
35
36# ifdef __cplusplus
37extern "C" {
38# endif
39
40#include <ladel.h>
41typedef ladel_double c_float; /**< type for floating point numbers */
42typedef ladel_int c_int; /**< type for integer numbers */
43
44/**
45 * @name Custom memory allocation (e.g. matlab/python)
46 * @{
47 */
48
49QPALM_EXPORT void *qpalm_calloc(size_t num, size_t size);
50QPALM_EXPORT void *qpalm_malloc(size_t size);
51QPALM_EXPORT void* qpalm_realloc(void *ptr, size_t size);
52QPALM_EXPORT void qpalm_free(void *ptr);
53
54/** Set the `calloc` function used by QPALM. */
55QPALM_EXPORT calloc_sig *qpalm_set_alloc_config_calloc(calloc_sig *calloc);
56/** Set the `malloc` function used by QPALM. */
57QPALM_EXPORT malloc_sig *qpalm_set_alloc_config_malloc(malloc_sig *malloc);
58/** Set the `realloc` function used by QPALM. */
59QPALM_EXPORT realloc_sig *qpalm_set_alloc_config_realloc(realloc_sig *realloc);
60/** Set the `free` function used by QPALM. */
61QPALM_EXPORT free_sig *qpalm_set_alloc_config_free(free_sig *free);
62
63/** Set the `printf` function used by QPALM. */
64QPALM_EXPORT printf_sig *qpalm_set_print_config_printf(printf_sig *printf);
65
66/**
67 * @}
68 */
69
70
71/* QPALM_PRINTING */
72# ifdef QPALM_PRINTING
73
74// Print macro
75# define qpalm_print ladel_print
76
77// Print error macro
78# ifdef __GNUC__
79# define qpalm_eprint(...) __extension__ ({ qpalm_print("ERROR in %s: ", __FUNCTION__); qpalm_print(__VA_ARGS__); qpalm_print("\n"); })
80# else
81# define qpalm_eprint(...) do { qpalm_print("ERROR in %s: ", __FUNCTION__); qpalm_print(__VA_ARGS__); qpalm_print("\n"); } while (0)
82# endif
83
84# endif /* ifdef QPALM_PRINTING */
85
86
87/**
88 * @name Custom operations
89 * @{
90 */
91# ifndef c_absval
92# define c_absval(x) (((x) < 0) ? -(x) : (x)) /**< absolute value */
93# endif /* ifndef c_absval */
94
95# ifndef c_max
96# define c_max(a, b) (((a) > (b)) ? (a) : (b)) /**< maximum of two values */
97# endif /* ifndef c_max */
98
99# ifndef c_min
100# define c_min(a, b) (((a) < (b)) ? (a) : (b)) /**< minimum of two values */
101# endif /* ifndef c_min */
102
103# ifndef mod
104# define mod(a,b) ((((a)%(b))+(b))%(b)) /**< modulo operation (positive result for all values) */
105#endif
106
107#include <math.h>
108#ifdef DFLOAT
109#define c_sqrt sqrtf /**< square root */
110#define c_acos acosf /**< arc cosine */
111#define c_cos cosf /**< cosine */
112#else
113#define c_sqrt sqrt /**< square root */
114#define c_acos acos /**< arc cosine */
115#define c_cos cos /**< cosine */
116#endif /* DFLOAT */
117
118/** @} */
119
120# ifdef __cplusplus
121}
122# endif
123
124#endif /* ifndef GLOBAL_OPTS_H */
void qpalm_free(void *ptr)
Definition global_opts.c:16
calloc_sig * qpalm_set_alloc_config_calloc(calloc_sig *calloc)
Set the calloc function used by QPALM.
Definition global_opts.c:20
realloc_sig * qpalm_set_alloc_config_realloc(realloc_sig *realloc)
Set the realloc function used by QPALM.
Definition global_opts.c:26
ladel_int c_int
type for integer numbers
Definition global_opts.h:42
ladel_double c_float
type for floating point numbers
Definition global_opts.h:41
void * qpalm_malloc(size_t size)
Definition global_opts.c:7
printf_sig * qpalm_set_print_config_printf(printf_sig *printf)
Set the printf function used by QPALM.
Definition global_opts.c:32
void * qpalm_calloc(size_t num, size_t size)
Definition global_opts.c:3
malloc_sig * qpalm_set_alloc_config_malloc(malloc_sig *malloc)
Set the malloc function used by QPALM.
Definition global_opts.c:23
#define QPALM_EXPORT
Definition global_opts.h:33
free_sig * qpalm_set_alloc_config_free(free_sig *free)
Set the free function used by QPALM.
Definition global_opts.c:29
void * qpalm_realloc(void *ptr, size_t size)
Definition global_opts.c:11