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 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
78 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
79 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
82 Vmul(n, &x[0], incx, &y[0], incy, &
z[0], incz);
91 ASSERTL1(n * incx <= x.size(),
"Array out of bounds");
92 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
93 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
95 Vmul(n, x.origin(), incx, &y[0], incy, &
z[0], incz);
104 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
105 "Array out of bounds");
106 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
107 "Array out of bounds");
109 Smul(n, alpha, &x[0], incx, &y[0], incy);
118 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
119 "Array out of bounds");
120 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
121 "Array out of bounds");
122 ASSERTL1(
static_cast<unsigned int>(n * incz) <=
z.size() +
z.GetOffset(),
123 "Array out of bounds");
125 Vdiv(n, &x[0], incx, &y[0], incy, &
z[0], incz);
133 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
134 "Array out of bounds");
135 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
136 "Array out of bounds");
138 Sdiv(n, alpha, &x[0], incx, &y[0], incy);
147 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
148 "Array out of bounds");
149 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
150 "Array out of bounds");
151 ASSERTL1(
static_cast<unsigned int>(n * incz) <=
z.size() +
z.GetOffset(),
152 "Array out of bounds");
154#ifdef NEKTAR_ENABLE_SIMD_VMATH
155 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
156 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
157 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
160 Vadd(n, &x[0], incx, &y[0], incy, &
z[0], incz);
170 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
171 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
173 Sadd(n, alpha, &x[0], incx, &y[0], incy);
182 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
183 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
184 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
186 Vsub(n, &x[0], incx, &y[0], incy, &
z[0], incz);
195 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
196 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
198 Ssub(n, alpha, &x[0], incx, &y[0], incy);
204 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
206 Zero(n, &x[0], incx);
212 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
222 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
223 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
225 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);
244 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
245 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
247 Vpow(n, &x[0], incx, f, &y[0], incy);
255 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
256 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
258 Vsqrt(n, &x[0], incx, &y[0], incy);
266 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
267 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
269 Vabs(n, &x[0], incx, &y[0], incy);
280 [[maybe_unused]]
const int incz)
282 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
283 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
284 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
285 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
287#ifdef NEKTAR_ENABLE_SIMD_VMATH
288 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
289 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
290 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
291 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
294 Vvtvp(n, &
w[0], incw, &x[0], incx, &y[0], incy, &
z[0], incz);
305 ASSERTL1(n * incw <=
w.size(),
"Array out of bounds");
306 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
307 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
308 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
310 Vvtvp(n,
w.origin(), incw, &x[0], incx, &y[0], incy, &
z[0], incz);
319 [[maybe_unused]]
const int incz)
321 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
322 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
323 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
324 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
326#ifdef NEKTAR_ENABLE_SIMD_VMATH
327 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
328 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
329 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
330 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
333 Vvtvm(n, &
w[0], incw, &x[0], incx, &y[0], incy, &
z[0], incz);
343 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
344 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
345 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
347 Svtvp(n, alpha, &x[0], incx, &y[0], incy, &
z[0], incz);
356 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
357 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
358 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
360 Svtvm(n, alpha, &x[0], incx, &y[0], incy, &
z[0], incz);
371 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
372 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
373 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
374 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
375 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
377#ifdef NEKTAR_ENABLE_SIMD_VMATH
378 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
379 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
380 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
381 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
384 Vvtvvtp(n, &v[0], incv, &
w[0], incw, &x[0], incx, &y[0], incy, &
z[0], incz);
397 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
398 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
399 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
400 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
401 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
403#ifdef NEKTAR_ENABLE_SIMD_VMATH
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);
431template <
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);
596 x.size() + x.GetOffset(),
597 "Array out of bounds");
599 y.size() + y.GetOffset(),
600 "Array out of bounds");
602 Vcopy(n, &x[0], incx, &y[0], incy);
611 x.size() + x.GetOffset(),
612 "Array out of bounds");
614 y.size() + y.GetOffset(),
615 "Array out of bounds");
617 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,.
std::vector< double > w(NPUPPER)
std::vector< double > z(NPUPPER)
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)
Add 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 minus 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)
Svtsvtp (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 Gathr(I n, const T *x, const I *y, T *z)
Gather vector z[i] = x[y[i]].
void Vlog(int n, const T *x, const int incx, T *y, const int incy)
log y = log(x)
void Vexp(int n, const T *x, const int incx, T *y, const int incy)
exp y = exp(x)
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)
dot product
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)
dot product
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 product
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)
Svtvm (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/x.
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 vector 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)
pow y = pow(x, f)
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)