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 Vmul(n, &x[0], incx, &y[0], incy, &z[0], incz);
84 ASSERTL1(n * incx <= x.size(),
"Array out of bounds");
85 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
86 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
88 Vmul(n, x.origin(), incx, &y[0], incy, &z[0], incz);
97 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
98 "Array out of bounds");
99 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
100 "Array out of bounds");
102 Smul(n, alpha, &x[0], incx, &y[0], incy);
111 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
112 "Array out of bounds");
113 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
114 "Array out of bounds");
115 ASSERTL1(
static_cast<unsigned int>(n * incz) <= z.size() + z.GetOffset(),
116 "Array out of bounds");
118 Vdiv(n, &x[0], incx, &y[0], incy, &z[0], incz);
126 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
127 "Array out of bounds");
128 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
129 "Array out of bounds");
131 Sdiv(n, alpha, &x[0], incx, &y[0], incy);
140 ASSERTL1(
static_cast<unsigned int>(n * incx) <= x.size() + x.GetOffset(),
141 "Array out of bounds");
142 ASSERTL1(
static_cast<unsigned int>(n * incy) <= y.size() + y.GetOffset(),
143 "Array out of bounds");
144 ASSERTL1(
static_cast<unsigned int>(n * incz) <= z.size() + z.GetOffset(),
145 "Array out of bounds");
147 Vadd(n, &x[0], incx, &y[0], incy, &z[0], incz);
156 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
157 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
159 Sadd(n, alpha, &x[0], incx, &y[0], incy);
168 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
169 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
170 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
172 Vsub(n, &x[0], incx, &y[0], incy, &z[0], incz);
181 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
182 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
184 Ssub(n, alpha, &x[0], incx, &y[0], incy);
190 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
192 Zero(n, &x[0], incx);
198 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
208 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
209 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
211 Vlog(n, &x[0], incx, &y[0], incy);
219 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
220 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
222 Vexp(n, &x[0], incx, &y[0], incy);
230 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
231 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
233 Vpow(n, &x[0], incx, f, &y[0], incy);
241 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
242 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
244 Vsqrt(n, &x[0], incx, &y[0], incy);
252 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
253 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
255 Vabs(n, &x[0], incx, &y[0], incy);
266 [[maybe_unused]]
const int incz)
268 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
269 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
270 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
271 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
273 Vvtvp(n, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
283 ASSERTL1(n * incw <= w.size(),
"Array out of bounds");
284 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
285 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
286 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
288 Vvtvp(n, w.origin(), incw, &x[0], incx, &y[0], incy, &z[0], incz);
297 [[maybe_unused]]
const int incz)
299 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
300 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
301 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
302 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
304 Vvtvm(n, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
313 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
314 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
315 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
317 Svtvp(n, alpha, &x[0], incx, &y[0], incy, &z[0], incz);
326 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
327 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
328 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
330 Svtvm(n, alpha, &x[0], incx, &y[0], incy, &z[0], incz);
341 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
342 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
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 Vvtvvtp(n, &v[0], incv, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
359 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
360 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
361 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
362 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
363 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
365 Vvtvvtm(n, &v[0], incv, &w[0], incw, &x[0], incx, &y[0], incy, &z[0], incz);
375 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
376 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
377 ASSERTL1(n * incz <= z.size() + z.GetOffset(),
"Array out of bounds");
379 Svtsvtp(n, alpha, &x[0], incx,
beta, &y[0], incy, &z[0], incz);
385template <
class T,
class I,
386 typename =
typename std::enable_if<std::is_floating_point_v<T> &&
387 std::is_integral_v<I>>::type>
391 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
392 ASSERTL1(n <= z.size() + z.GetOffset(),
"Array out of bounds");
394 Gathr(n, &x[0], &y[0], &z[0]);
402 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
403 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
405 Scatr(n, &x[0], &y[0], &z[0]);
413 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
414 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
416 Assmb(n, &x[0], &y[0], &z[0]);
424 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
426 return Vsum(n, &x[0], incx);
433 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
435 return Imax(n, &x[0], incx);
442 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
444 return Vmax(n, &x[0], incx);
451 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
453 return Iamax(n, &x[0], incx);
460 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
462 return Vamax(n, &x[0], incx);
469 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
471 return Imin(n, &x[0], incx);
478 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
480 return Vmin(n, &x[0], incx);
487 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
489 return Nnan(n, &x[0], incx);
496 ASSERTL1(n <= w.size() + w.GetOffset(),
"Array out of bounds");
497 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
499 return Dot(n, &w[0], &x[0]);
507 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
508 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
510 return Dot(n, &w[0], incw, &x[0], incx);
518 ASSERTL1(n <= w.size() + w.GetOffset(),
"Array out of bounds");
519 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
520 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
522 return Dot2(n, &w[0], &x[0], &y[0]);
531 ASSERTL1(n * incw <= w.size() + w.GetOffset(),
"Array out of bounds");
532 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
533 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
535 return Dot2(n, &w[0], incw, &x[0], incx, &y[0], incy);
545 ASSERTL1(
static_cast<unsigned int>(std::abs(n * incx)) <=
546 x.size() + x.GetOffset(),
547 "Array out of bounds");
548 ASSERTL1(
static_cast<unsigned int>(std::abs(n * incy)) <=
549 y.size() + y.GetOffset(),
550 "Array out of bounds");
552 Vcopy(n, &x[0], incx, &y[0], incy);
560 ASSERTL1(
static_cast<unsigned int>(std::abs(n * incx)) <=
561 x.size() + x.GetOffset(),
562 "Array out of bounds");
563 ASSERTL1(
static_cast<unsigned int>(std::abs(n * incy)) <=
564 y.size() + y.GetOffset(),
565 "Array out of bounds");
567 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,.
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.