32 #ifndef VSMC_MATH_VMATH_HPP 33 #define VSMC_MATH_VMATH_HPP 43 #define VSMC_DEFINE_MATH_VMATH_1(func, name) \ 44 template <typename T> \ 45 inline void name(std::size_t n, const T *a, T *y) \ 47 for (std::size_t i = 0; i != n; ++i) \ 51 #define VSMC_DEFINE_MATH_VMATH_2(func, name) \ 52 template <typename T> \ 53 inline void name(std::size_t n, const T *a, const T *b, T *y) \ 55 for (std::size_t i = 0; i != n; ++i) \ 56 y[i] = func(a[i], b[i]); \ 59 #define VSMC_DEFINE_MATH_VMATH_B(op, name) \ 60 template <typename T> \ 61 inline void name(std::size_t n, const T *a, const T *b, T *y) \ 63 for (std::size_t i = 0; i != n; ++i) \ 64 y[i] = a[i] op b[i]; \ 67 #define VSMC_DEFINE_MATH_VMATH_VS(op, name) \ 68 template <typename T> \ 69 inline void name(std::size_t n, const T *a, T b, T *y) \ 71 for (std::size_t i = 0; i != n; ++i) \ 75 #define VSMC_DEFINE_MATH_VMATH_SV(op, name) \ 76 template <typename T> \ 77 inline void name(std::size_t n, T a, const T *b, T *y) \ 79 for (std::size_t i = 0; i != n; ++i) \ 85 #define VSMC_DEFINE_MATH_VMATH_VML_1(func, name) \ 86 inline void name(std::size_t n, const float *a, float *y) \ 88 ::vs##func(static_cast<MKL_INT>(n), a, y); \ 90 inline void name(std::size_t n, const double *a, double *y) \ 92 ::vd##func(static_cast<MKL_INT>(n), a, y); \ 95 #define VSMC_DEFINE_MATH_VMATH_VML_2(func, name) \ 96 inline void name(std::size_t n, const float *a, const float *b, float *y) \ 98 ::vs##func(static_cast<MKL_INT>(n), a, b, y); \ 101 std::size_t n, const double *a, const double *b, double *y) \ 103 ::vd##func(static_cast<MKL_INT>(n), a, b, y); \ 115 float beta_a,
float beta_b,
float mu_a,
float mu_b,
float *y)
118 static_cast<MKL_INT>(n), a, b, beta_a, beta_b, mu_a, mu_b, y);
120 inline void linear_frac(std::size_t n,
const double *a,
const double *b,
121 double beta_a,
double beta_b,
double mu_a,
double mu_b,
double *y)
124 static_cast<MKL_INT>(n), a, b, beta_a, beta_b, mu_a, mu_b, y);
136 inline
void pow(
std::
size_t n, const
float *a,
float b,
float *y)
138 ::vsPowx(static_cast<MKL_INT>(n), a, b, y);
140 inline void pow(std::size_t n,
const double *a,
double b,
double *y)
142 ::vdPowx(static_cast<MKL_INT>(n), a, b, y);
154 inline
void sincos(
std::
size_t n, const
float *a,
float *y,
float *z)
156 ::vsSinCos(static_cast<MKL_INT>(n), a, y, z);
158 inline void sincos(std::size_t n,
const double *a,
double *y,
double *z)
160 ::vdSinCos(static_cast<MKL_INT>(n), a, y, z);
186 #endif // VSMC_USE_MKL_VML 208 VSMC_DEFINE_MATH_VMATH_VS(-,
sub)
214 template <typename T>
215 inline
void sqr(
std::
size_t n, const T *a, T *y)
217 for (std::size_t i = 0; i != n; ++i)
235 template <typename T>
237 T beta_b, T mu_a, T mu_b, T *y)
239 const std::size_t k = 1024;
240 const std::size_t m = n / k;
241 const std::size_t l = n % k;
242 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
243 for (std::size_t j = 0; j != k; ++j)
244 y[j] = beta_a * a[j] + mu_a;
245 for (std::size_t j = 0; j != k; ++j)
246 y[j] /= beta_b * b[j] + mu_b;
248 for (std::size_t i = 0; i != l; ++i)
249 y[i] = beta_a * a[i] + mu_a;
250 for (std::size_t i = 0; i != l; ++i)
251 y[i] /= beta_b * b[i] + mu_b;
256 template <
typename T>
257 inline void fma(std::size_t n,
const T *a,
const T *b,
const T *c, T *y)
259 for (std::size_t i = 0; i != n; ++i)
260 y[i] = a[i] * b[i] + c[i];
265 template <
typename T>
266 inline void fma(std::size_t n,
const T *a,
const T *b, T c, T *y)
268 for (std::size_t i = 0; i != n; ++i)
269 y[i] = a[i] * b[i] + c;
274 template <
typename T>
275 inline void fma(std::size_t n,
const T *a, T b,
const T *c, T *y)
277 for (std::size_t i = 0; i != n; ++i)
278 y[i] = a[i] * b + c[i];
283 template <
typename T>
284 inline void fma(std::size_t n,
const T *a, T b, T c, T *y)
286 for (std::size_t i = 0; i != n; ++i)
292 template <
typename T>
293 inline void fma(std::size_t n, T a,
const T *b,
const T *c, T *y)
295 for (std::size_t i = 0; i != n; ++i)
296 y[i] = a * b[i] + c[i];
301 template <
typename T>
302 inline void fma(std::size_t n, T a,
const T *b, T c, T *y)
304 for (std::size_t i = 0; i != n; ++i)
310 template <
typename T>
311 inline void fma(std::size_t n, T a, T b,
const T *c, T *y)
323 template <
typename T>
324 inline void inv(std::size_t n,
const T *a, T *y)
326 const T one =
static_cast<T
>(1);
327 for (std::size_t i = 0; i != n; ++i)
344 template <typename T>
347 const std::size_t k = 1024;
348 const std::size_t m = n / k;
349 const std::size_t l = n % k;
350 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
361 template <typename T>
365 const std::size_t k = 1024;
366 const std::size_t m = n / k;
367 const std::size_t l = n % k;
368 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
377 template <
typename T>
378 inline void pow2o3(std::size_t n,
const T *a, T *y)
380 const std::size_t k = 1024;
381 const std::size_t m = n / k;
382 const std::size_t l = n % k;
383 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
392 template <
typename T>
393 inline void pow3o2(std::size_t n,
const T *a, T *y)
395 const std::size_t k = 1024;
396 const std::size_t m = n / k;
397 const std::size_t l = n % k;
398 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
400 for (std::size_t j = 0; j != k; ++j)
401 y[j] = y[j] * y[j] * y[j];
404 for (std::size_t i = 0; i != l; ++i)
405 y[i] = y[i] * y[i] * y[i];
411 template <typename T>
413 inline
void pow(
std::
size_t n, const T *a, T b, T *y)
415 for (std::size_t i = 0; i != n; ++i)
435 template <typename T>
438 const std::size_t k = 1024;
439 const std::size_t m = n / k;
440 const std::size_t l = n % k;
441 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
442 mul(k, const_ln_10<T>(), a, y);
445 mul(l, const_ln_10<T>(), a, y);
477 template <typename T>
478 inline
void sincos(
std::
size_t n, const T *a, T *y, T *z)
480 const std::size_t k = 1024;
481 const std::size_t m = n / k;
482 const std::size_t l = n % k;
483 for (std::size_t i = 0; i != m; ++i, a += k, y += k, z += k) {
546 template <typename T>
549 const std::size_t k = 1024;
550 const std::size_t m = n / k;
551 const std::size_t l = n % k;
552 for (std::size_t i = 0; i != m; ++i, a += k, y += k) {
553 mul(k, 1 / const_sqrt_2<T>(), a, y);
555 fma(k, static_cast<T>(0.5), static_cast<T>(0.5), y, y);
557 mul(l, 1 / const_sqrt_2<T>(), a, y);
559 fma(l, static_cast<T>(0.5), static_cast<T>(0.5), y, y);
573 #endif // VSMC_MATH_VMATH_HPP void cdfnorm(std::size_t n, const float *a, float *y)
void erfcinv(std::size_t n, const float *a, float *y)
void cbrt(std::size_t n, const T *a, T *y)
For , compute .
#define VSMC_DEFINE_MATH_VMATH_1(func, name)
void mul(std::size_t n, const float *a, const float *b, float *y)
void log1p(std::size_t n, const float *a, float *y)
void acosh(std::size_t n, const float *a, float *y)
void sqrt(std::size_t n, const float *a, float *y)
void sinh(std::size_t n, const float *a, float *y)
void invsqrt(std::size_t n, const float *a, float *y)
void pow3o2(std::size_t n, const float *a, float *y)
void pow2o3(std::size_t n, const float *a, float *y)
void asin(std::size_t n, const float *a, float *y)
void tan(std::size_t n, const T *a, T *y)
For , compute .
void cdfnorminv(std::size_t n, const float *a, float *y)
void exp2(std::size_t n, const T *a, T *y)
For , compute .
void log2(std::size_t n, const T *a, T *y)
For , compute .
void tanh(std::size_t n, const float *a, float *y)
void erfinv(std::size_t n, const float *a, float *y)
void linear_frac(std::size_t n, const float *a, const float *b, float beta_a, float beta_b, float mu_a, float mu_b, float *y)
#define VSMC_DEFINE_MATH_VMATH_2(func, name)
#define VSMC_DEFINE_MATH_VMATH_SV(op, name)
void invcbrt(std::size_t n, const float *a, float *y)
void erf(std::size_t n, const float *a, float *y)
void expm1(std::size_t n, const float *a, float *y)
void pow(std::size_t n, const float *a, const float *b, float *y)
void cos(std::size_t n, const float *a, float *y)
void lgamma(std::size_t n, const float *a, float *y)
void exp(std::size_t n, const float *a, float *y)
void atanh(std::size_t n, const float *a, float *y)
void inv(std::size_t n, const float *a, float *y)
void asinh(std::size_t n, const float *a, float *y)
#define VSMC_DEFINE_MATH_VMATH_VML_2(func, name)
void atan2(std::size_t n, const float *a, const float *b, float *y)
void div(std::size_t n, const float *a, const float *b, float *y)
void sub(std::size_t n, const float *a, const float *b, float *y)
void fma(std::size_t n, const T *a, const T *b, const T *c, T *y)
For , compute .
void tgamma(std::size_t n, const T *a, T *y)
For , compute , the Gamma function.
void sincos(std::size_t n, const float *a, float *y, float *z)
void sin(std::size_t n, const float *a, float *y)
void cosh(std::size_t n, const float *a, float *y)
void acos(std::size_t n, const float *a, float *y)
void add(std::size_t n, const float *a, const float *b, float *y)
void tgamm(std::size_t n, const float *a, float *y)
void atan(std::size_t n, const float *a, float *y)
#define VSMC_DEFINE_MATH_VMATH_VS(op, name)
void exp10(std::size_t n, const T *a, T *y)
For , compute .
void pow(std::size_t n, const T *a, T b, T *y)
For , compute .
void erfc(std::size_t n, const float *a, float *y)
void tan(std::size_t n, const float *a, float *y)
void hypot(std::size_t n, const T *a, const T *b, T *y)
For , compute .
void hypot(std::size_t n, const float *a, const float *b, float *y)
void cbrt(std::size_t n, const float *a, float *y)
#define VSMC_DEFINE_MATH_VMATH_VML_1(func, name)
#define VSMC_DEFINE_MATH_VMATH_B(op, name)
void log(std::size_t n, const float *a, float *y)
void lgamma(std::size_t n, const T *a, T *y)
For , compute , logarithm of the Gamma function.
void sqr(std::size_t n, const float *a, float *y)
void log10(std::size_t n, const float *a, float *y)
void abs(std::size_t n, const float *a, float *y)
void expm1(std::size_t n, const T *a, T *y)
For , compute .