// lasp_math_raw.h // // Author: J.A. de Jong - ASCEE // // Description: Raw math routines working on raw arrays of floats and // complex numbers. ////////////////////////////////////////////////////////////////////// #pragma once #ifndef LASP_MATH_RAW_H #define LASP_MATH_RAW_H #include "lasp_assert.h" #include "lasp_tracer.h" #include "lasp_types.h" #include #if LASP_USE_BLAS == 1 #include #elif LASP_USE_BLAS == 0 #else #error "LASP_USE_BLAS should be set to either 0 or 1" #endif #ifdef LASP_DOUBLE_PRECISION #define c_real creal #define c_imag cimag #define d_abs fabs #define c_abs cabs #define c_conj conj #define d_atan2 atan2 #define d_acos acos #define d_sqrt sqrt #define c_exp cexp #define d_sin sin #define d_cos cos #define d_pow pow #define d_log10 log10 #else // LASP_DOUBLE_PRECISION not defined #define c_conj conjf #define c_real crealf #define c_imag cimagf #define d_abs fabsf #define c_abs cabsf #define d_atan2 atan2f #define d_acos acosf #define d_sqrt sqrtf #define c_exp cexpf #define d_sin sinf #define d_cos cosf #define d_pow powf #define d_log10 log10f #endif // LASP_DOUBLE_PRECISION #ifdef M_PI static const d number_pi = M_PI; #else static const d number_pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679; #endif /** * Set all elements in an array equal to val * * @param to * @param val * @param size */ static inline void d_set(d to[],d val,us size) { for(us i=0;ib?a:b; } /** * Return the dot product of two arrays, one of them complex-valued, * the other real-valued * * @param a the complex-valued array * @param b the real-valued array * @param size the size of the arrays. *Should be equal-sized!* * * @return the dot product */ static inline c cd_dot(const c a[],const d b[],us size){ c result = 0; us i; for(i=0;i max) max=a[i]; } return max; } /** * Compute the minimum of an array * * @param a array * @param size size of the array * @return minimum */ static inline d d_min(const d a[],us size){ us i; d min = a[0]; for(i=1;i min) min=a[i]; } return min; } /** * Compute the \f$ L_2 \f$ norm of an array of doubles * * @param a Array * @param size Size of array */ static inline d d_norm(const d a[],us size){ #if LASP_USE_BLAS == 1 return cblas_dnrm2(size,a,1); #else d norm = 0; us i; for(i=0;i