ADOL-C: Automatic Differentiation in C/C++ 2.7.3
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File: common.h
4 Revision: $Id$
5 Contents: Common (global) ADOL-C header
6
7 Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
8 Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel
9
10 This file is part of ADOL-C. This software is provided as open source.
11 Any use, reproduction, or distribution of the software constitutes
12 recipient's acceptance of the terms of the accompanying license file.
13
14----------------------------------------------------------------------------*/
15
16#if !defined(ADOLC_COMMON_H)
17#define ADOLC_COMMON_H 1
18/*--------------------------------------------------------------------------*/
19/* standard includes */
20#if !defined(__cplusplus)
21#include <stdio.h>
22#include <stdlib.h>
23#else
24#include <cstdint>
25#include <cstdlib>
26#endif
27
28/*--------------------------------------------------------------------------*/
29/* type definitions */
30
31// define bit vector propagation type used in sparse drivers
32#if ADOLC_BITWORD_BITS == 32
33typedef uint32_t bitword_t;
34#elif ADOLC_BITWORD_BITS == 64
35typedef uint64_t bitword_t;
36#else
37typedef uint32_t bitword_t;
38#endif
39typedef unsigned int uint;
40
41/*--------------------------------------------------------------------------*/
42/* system dependent configuration */
43#if defined(ADOLC_INTERNAL)
44#if HAVE_CONFIG_H
45#include "config.h"
46
47/* malloc/calloc/realloc replacements */
48#undef ADOLC_NO_MALLOC
49#undef ADOLC_NO_REALLOC
50#if !defined(HAVE_MALLOC)
51#define ADOLC_NO_MALLOC 1
52#else
53#if (HAVE_MALLOC == 0)
54#define ADOLC_NO_MALLOC 1
55#endif /* HAVE_MALLOC == 0 */
56#endif /* HAVE_MALLOC */
57#if !defined(HAVE_REALLOC)
58#define ADOLC_NO_REALLOC 1
59#else
60#if (HAVE_REALLOC == 0)
61#define ADOLC_NO_REALLOC 1
62#endif /* HAVE_REALLOC == 0 */
63#endif /* HAVE_REALLOC */
64
65#if defined(ADOLC_NO_MALLOC)
66#include <adolc/rpl_malloc.h>
67#define malloc rpl_malloc
68#define calloc rpl_calloc
69#endif /* ADOLC_NO_MALLOC */
70#if defined(ADOLC_NO_REALLOC)
71#include <adolc/rpl_malloc.h>
72#define realloc rpl_realloc
73#endif /* ADOLC_NO_REALLOC */
74
75#ifndef HAVE_TRUNC
76#define trunc(x) ((x < 0) ? ceil(x) : floor(x))
77#endif
78
79#endif /* HAVE_CONFIG_H */
80#endif /* ADOLC_INTERNAL */
81
82/*--------------------------------------------------------------------------*/
83/* user parameters and settings */
84#include <adolc/internal/adolc_settings.h>
86
87#if defined(__cplusplus)
88
89#define BEGIN_C_DECLS extern "C" {
90#define END_C_DECLS }
91
92#include <cassert>
93#include <type_traits>
96template <typename T>
97constexpr size_t to_size_t(T value) noexcept
98 requires(std::is_integral_v<T> && !std::is_same_v<T, bool>)
99{
100 assert(value >= 0);
101 return static_cast<size_t>(value);
102}
103
105template <typename T>
106constexpr double to_double(T value) noexcept
107 requires(std::is_integral_v<T> && !std::is_same_v<T, bool>)
108{
109 return static_cast<double>(value);
110}
111
113template <auto> inline constexpr bool is_dependent_v = false;
114#else
115#define BEGIN_C_DECLS
116#define END_C_DECLS
117#endif
118
119#define MAXDEC(a, b) \
120 do { \
121 revreal __r = (b); \
122 if (__r > (a)) \
123 (a) = __r; \
124 } while (0)
125#define MAXDECI(a, b) \
126 do { \
127 int __r = (b); \
128 if (__r > (a)) \
129 (a) = __r; \
130 } while (0)
131#define MINDECR(a, b) \
132 do { \
133 revreal __r = (b); \
134 if (__r < (a)) \
135 (a) = __r; \
136 } while (0)
137#define MINDEC(a, b) \
138 do { \
139 int __r = (b); \
140 if (__r < (a)) \
141 (a) = __r; \
142 } while (0)
143
144#define MAX_ADOLC(a, b) ((a) < (b) ? (b) : (a))
145#define MIN_ADOLC(a, b) ((a) > (b) ? (b) : (a))
146
147/*--------------------------------------------------------------------------*/
148#endif
unsigned int uint
Definition common.h:39
uint32_t bitword_t
Definition common.h:37