19 #ifndef __HERMES_COMMON_COMMON_H
20 #define __HERMES_COMMON_COMMON_H
32 #include <initializer_list>
71 #define MONGO_HAVE_STDINT
82 inline int omp_get_max_threads() {
return 1; }
83 inline int omp_get_num_threads() {
return 1; }
84 inline int omp_get_thread_num() {
return 0; }
93 typedef __int8 int8_t;
94 typedef __int16 int16_t;
95 typedef __int32 int32_t;
96 typedef __int64 int64_t;
98 typedef unsigned __int8 uint8_t;
99 typedef unsigned __int16 uint16_t;
100 typedef unsigned __int32 uint32_t;
101 typedef unsigned __int64 uint64_t;
103 #include <inttypes.h>
107 #define finite _finite
115 typedef double double2[2];
116 typedef double double3[3];
117 typedef double double4[4];
118 typedef double double2x2[2][2];
119 typedef double double2x3[2][3];
120 typedef double double2x4[2][4];
121 typedef double double3x2[3][2];
122 typedef double double3x3[3][3];
123 typedef double double3x4[3][4];
125 typedef float float2[2];
126 typedef float float3[3];
127 typedef float float4[4];
128 typedef float float2x2[2][2];
129 typedef float float2x3[2][3];
130 typedef float float2x4[2][4];
131 typedef float float3x2[3][2];
132 typedef float float3x3[3][3];
133 typedef float float3x4[3][4];
135 template<
typename Scalar>
143 val[0] = v1; val[1] = v2;
146 Scalar& operator[] (
int idx)
148 assert(idx >= 0 && idx < 2);
153 template<
typename Scalar>
159 Scalar3(Scalar v1, Scalar v2, Scalar v3)
161 val[0] = v1; val[1] = v2, val[2] = v3;
164 Scalar& operator[] (
int idx)
166 assert(idx >= 0 && idx < 3);
173 #define M_PI 3.14159265358979323846
178 const double HermesEpsilon = std::numeric_limits<double>::epsilon() * 10.;
179 const double HermesSqrtEpsilon = std::sqrt(std::numeric_limits<double>::epsilon());
181 inline int sqr(
int x) {
return x*x; }
182 inline double sqr(
double x) {
return x*x; }
183 inline double sqrt(
double x) {
return std::sqrt(x); }
184 inline double sqr(std::complex<double> x) {
return std::norm(x); }
185 inline double magn(
double x) {
return fabs(x); }
186 inline double conj(
double a) {
return a; }
187 inline double cos(
double x) {
return std::cos(x); }
188 inline double sin(
double x) {
return std::sin(x); }
189 inline double atan(
double x) {
return std::atan(x); }
190 inline double atan2(
double x,
double y) {
return std::atan2(x, y); }
191 inline double abs(
double x) {
return std::abs(x); }
192 inline double pow(
double x,
double y) {
return std::pow(x, y); }
193 inline double log(
double x) {
return std::log(x); }
196 #define HERMES_EC_ERROR 'E'
197 #define HERMES_EC_WARNING 'W'
198 #define HERMES_EC_INFO 'I'
200 #define HERMES_LOG_FILE_DELIM_SIZE 80
208 # ifdef __MINGW32__ //MinGW
209 # define __CURRENT_FUNCTION __func__
210 # else //MSVC and other compilers
211 # define __CURRENT_FUNCTION __FUNCTION__
213 #else //Linux and Mac
214 # define __CURRENT_FUNCTION __PRETTY_FUNCTION__
218 const std::string HERMES_ANY =
"-1234";
220 const int HERMES_ANY_INT = -1234;
225 class LengthException;
232 inline void check_for_null(T instance)
240 inline void check_length(
const std::vector<T>& instance,
const unsigned int length)
242 if (instance.size() != length)
247 template<
typename T,
typename U>
248 inline void check_length(
const std::vector<T>& instanceT,
const std::vector<U>& instanceU)
250 if (instanceT.size() != instanceU.size())
255 inline void fprint_num(FILE*f,
double x,
char* number_format)
257 fprintf(f, number_format, x);
260 inline void fprint_num(FILE*f, std::complex<double> x,
char* number_format)
262 std::stringstream ss;
263 ss <<
"(" << number_format <<
", " << number_format <<
")";
264 fprintf(f, ss.str().c_str(), x.real(), x.imag());
267 template<
typename Scalar>
268 inline void fprint_coordinate_num(FILE*f,
int i,
int j, Scalar x,
char* number_format)
270 fprintf(f,
"%d %d ", i, j);
271 fprint_num(f, x, number_format);
275 template<
typename Scalar>
278 static const bool value =
false;
281 template<
typename Scalar>
284 static const bool value =
false;
290 static const bool value =
true;
296 static const bool value =
true;
310 extern int zscal_(
int *, std::complex<double> *, std::complex<double> *,
int *);
311 extern int zaxpy_(
int *, std::complex<double> *, std::complex<double> *,
int *, std::complex<double> *,
int *);
312 extern int zcopy_(
int *, std::complex<double> *,
int *, std::complex<double> *,
int *);
314 extern int dscal_(
int *,
double *,
double *,
int *);
315 extern int daxpy_(
int *,
double *,
double *,
int *,
double *,
int *);
316 extern int dcopy_(
int *,
double *,
int *,
double *,
int *);
323 inline void blas_scal(
int n, std::complex<double> alpha, std::complex<double> *x,
int incx) { zscal_(&n, &alpha, x, &incx); }
325 inline void blas_axpy(
int n, std::complex<double> alpha, std::complex<double> *x,
int incx, std::complex<double> *y,
int incy) { zaxpy_(&n, &alpha, x, &incx, y, &incy); }
327 inline void blas_copy(
int n, std::complex<double> *x,
int incx, std::complex<double> *y,
int incy) { zcopy_(&n, x, &incx, y, &incx); }
330 inline void blas_scal(
int n,
double alpha,
double *x,
int incx) { dscal_(&n, &alpha, x, &incx); }
332 inline void blas_axpy(
int n,
double alpha,
double *x,
int incx,
double *y,
int incy) { daxpy_(&n, &alpha, x, &incx, y, &incy); }
334 inline void blas_copy(
int n,
double *x,
int incx,
double *y,
int incy) { dcopy_(&n, x, &incx, y, &incx); }
General namespace for the Hermes library.
Parameter length parameter exception. Internal. Exception occurs when some parameter has wrong length...
Null parameter exception. Internal. Exception occurs when some parameter is Null or empty and it shou...
int int2[2]
Int types handling.