35 #ifndef NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATHARRAY_HPP
36 #define NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATHARRAY_HPP
52 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Out of bounds");
54 Fill(n, alpha, &x[0], incx);
61 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Out of bounds");
72 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
73 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
74 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
76 #ifdef NEKTAR_ENABLE_SIMD_VMATH
77 boost::ignore_unused(incx, incy, incz);
78 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
79 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
80 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
83 Vmul(n, &x[0], incx, &y[0], incy, &z[0], incz);
92 ASSERTL1(n * incx <= x.size(),
"Array out of bounds");
93 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
94 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
96 Vmul(n, x.origin(), incx, &y[0], incy, &z[0], incz);
105 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
106 "Array out of bounds");
107 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
108 "Array out of bounds");
110 Smul(n, alpha, &x[0], incx, &y[0], incy);
119 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
120 "Array out of bounds");
121 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
122 "Array out of bounds");
123 ASSERTL1(
static_cast<unsigned int>(n * incz) <= z.size() + z.GetOffset(),
124 "Array out of bounds");
126 Vdiv(n, &x[0], incx, &y[0], incy, &z[0], incz);
134 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
135 "Array out of bounds");
136 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
137 "Array out of bounds");
139 Sdiv(n, alpha, &x[0], incx, &y[0], incy);
148 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
149 "Array out of bounds");
150 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
151 "Array out of bounds");
152 ASSERTL1(
static_cast<unsigned int>(n * incz) <= z.size() + z.GetOffset(),
153 "Array out of bounds");
155 #ifdef NEKTAR_ENABLE_SIMD_VMATH
156 boost::ignore_unused(incx, incy, incz);
157 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
158 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
159 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
162 Vadd(n, &x[0], incx, &y[0], incy, &z[0], incz);
172 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
173 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
175 Sadd(n, alpha, &x[0], incx, &y[0], incy);
184 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
185 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
186 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
188 Vsub(n, &x[0], incx, &y[0], incy, &z[0], incz);
197 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
198 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
200 Ssub(n, alpha, &x[0], incx, &y[0], incy);
206 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
208 Zero(n, &x[0], incx);
214 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
223 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
224 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
226 Vlog(n, &x[0], incx, &y[0], incy);
233 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
234 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
236 Vexp(n, &x[0], incx, &y[0], incy);
243 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
244 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
246 Vpow(n, &x[0], incx, f, &y[0], incy);
254 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
255 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
257 Vsqrt(n, &x[0], incx, &y[0], incy);
265 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
266 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
268 Vabs(n, &x[0], incx, &y[0], incy);
280 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
281 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
282 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
283 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
285 #ifdef NEKTAR_ENABLE_SIMD_VMATH
286 boost::ignore_unused(incw, incx, incy, incz);
287 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
288 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
289 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
290 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
293 Vvtvp(n, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
303 ASSERTL1(n * incw <= w.size(),
"Array out of bounds");
304 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
305 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
306 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
308 Vvtvp(n, w.origin(), incw, &x[0], incx, &y[0], incy, &z[0], incz);
317 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
318 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
319 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
321 Svtvp(n, alpha, &x[0], incx, &y[0], incy, &z[0], incz);
330 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
331 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
332 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
334 Svtvm(n, alpha, &x[0], incx, &y[0], incy, &z[0], incz);
344 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
345 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
346 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
347 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
349 #ifdef NEKTAR_ENABLE_SIMD_VMATH
350 boost::ignore_unused(incw, incx, incy, incz);
351 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
352 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
353 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
354 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
357 Vvtvm(n, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
369 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
370 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
371 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
372 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
373 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
375 #ifdef NEKTAR_ENABLE_SIMD_VMATH
376 boost::ignore_unused(incv, incw, incx, incy, incz);
377 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
378 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
379 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
380 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
383 Vvtvvtp(n, &v[0], incv, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
396 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
397 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
398 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
399 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
400 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
402 #ifdef NEKTAR_ENABLE_SIMD_VMATH
403 boost::ignore_unused(incv, incw, incx, incy, incz);
404 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
405 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
406 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
407 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
410 Vvtvvtm(n, &v[0], incv, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
421 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
422 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
423 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
425 Svtsvtp(n, alpha, &x[0], incx,
beta, &y[0], incy, &z[0], incz);
431 template <
class T,
class I,
432 typename =
typename std::enable_if<std::is_floating_point<T>::value &&
433 std::is_integral<I>::value>::type>
437 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
438 ASSERTL1(n <= z.size() + z.GetOffset(),
"Array out of bounds");
440 #ifdef NEKTAR_ENABLE_SIMD_VMATH
443 Gathr(n, &x[0], &y[0], &z[0]);
452 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
453 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
455 Scatr(n, &x[0], &y[0], &z[0]);
463 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
464 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
466 Assmb(n, &x[0], &y[0], &z[0]);
474 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
476 return Vsum(n, &x[0], incx);
483 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
485 return Imax(n, &x[0], incx);
492 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
494 return Vmax(n, &x[0], incx);
501 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
503 return Iamax(n, &x[0], incx);
510 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
512 return Vamax(n, &x[0], incx);
519 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
521 return Imin(n, &x[0], incx);
528 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
530 return Vmin(n, &x[0], incx);
537 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
539 return Nnan(n, &x[0], incx);
546 ASSERTL1(n <= w.size() + w.GetOffset(),
"Array out of bounds");
547 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
549 return Dot(n, &w[0], &x[0]);
557 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
558 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
560 return Dot(n, &w[0], incw, &x[0], incx);
568 ASSERTL1(n <= w.size() + w.GetOffset(),
"Array out of bounds");
569 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
570 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
572 return Dot2(n, &w[0], &x[0], &y[0]);
581 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
582 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
583 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
585 return Dot2(n, &w[0], incw, &x[0], incx, &y[0], incy);
595 x.size() + x.GetOffset(),
596 "Array out of bounds");
598 y.size() + y.GetOffset(),
599 "Array out of bounds");
601 Vcopy(n, &x[0], incx, &y[0], incy);
609 x.size() + x.GetOffset(),
610 "Array out of bounds");
612 y.size() + y.GetOffset(),
613 "Array out of bounds");
615 Reverse(n, &x[0], incx, &y[0], incy);
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
@ beta
Gauss Radau pinned at x=-1,.
The above copyright notice and this permission notice shall be included.
void Vvtvp(const size_t n, const T *w, const T *x, const T *y, T *z)
vvtvp (vector times vector plus vector): z = w*x + y
void Vadd(const size_t n, const T *x, const T *y, T *z)
Multiply vector z = x + y.
void Vvtvm(const size_t n, const T *w, const T *x, const T *y, T *z)
vvtvm (vector times vector plus vector): z = w*x - y
void Vvtvvtm(const size_t n, const T *v, const T *w, const T *x, const T *y, T *z)
vvtvvtm (vector times vector minus vector times vector):
void Gathr(const I n, const T *x, const I *y, T *z)
Gather vector z[i] = x[y[i]].
void Vvtvvtp(const size_t n, const T *v, const T *w, const T *x, const T *y, T *z)
vvtvvtp (vector times vector plus vector times vector):
void Vmul(const size_t n, const T *x, const T *y, T *z)
Multiply vector z = x * y.
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
void Ssub(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Substract vector y = alpha - x.
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
svtvvtp (scalar times vector plus scalar times vector):
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
void Vlog(int n, const T *x, const int incx, T *y, const int incy)
void Vexp(int n, const T *x, const int incx, T *y, const int incy)
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
void Vabs(int n, const T *x, const int incx, T *y, const int incy)
vabs: y = |x|
T Dot2(int n, const T *w, const T *x, const int *y)
dot2 (vector times vector times vector): z = w*x*y
void Neg(int n, T *x, const int incx)
Negate x = -x.
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
T Ddot(int n, const Array< OneD, const T > &w, const int incw, const Array< OneD, const T > &x, const int incx, const Array< OneD, const int > &y, const int incy)
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
void Scatr(int n, const T *x, const int *y, T *z)
Scatter vector z[y[i]] = x[i].
T Dot(int n, const T *w, const T *x)
dot (vector times vector): z = w*x
void Gathr(int n, const T *sign, const T *x, const int *y, T *z)
Gather vector z[i] = sign[i]*x[y[i]].
void Assmb(int n, const T *x, const int *y, T *z)
Assemble z[y[i]] += x[i]; z should be zero'd first.
void Svtvm(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector minus vector): z = alpha*x - y
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
void Vvtvm(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvm (vector times vector minus vector): z = w*x - y
void Vvtvvtm(int n, const T *v, int incv, const T *w, int incw, const T *x, int incx, const T *y, int incy, T *z, int incz)
vvtvvtm (vector times vector minus vector times vector):
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/y.
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
void Vdiv(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x/y.
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in x.
void Zero(int n, T *x, const int incx)
Zero vector.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
void FillWhiteNoise(int n, const T eps, T *x, const int incx, int outseed)
Fills a vector with white noise.
int Nnan(int n, const T *x, const int incx)
Return number of NaN elements of x.
T Vamax(int n, const T *x, const int incx)
Return the maximum absolute element in x called vamax to avoid conflict with max.
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add scalar y = alpha + x.
void Reverse(int n, const T *x, const int incx, T *y, const int incy)
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
void Vvtvvtp(int n, const T *v, int incv, const T *w, int incw, const T *x, int incx, const T *y, int incy, T *z, int incz)
vvtvvtp (vector times vector plus vector times vector):
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
void Vpow(int n, const T *x, const int incx, const T f, T *y, const int incy)
int Iamax(int n, const T *x, const int incx)
Return the index of the maximum absolute element in x.
scalarT< T > abs(scalarT< T > in)