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");
224 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
225 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
227 Vlog(n, &x[0], incx, &y[0], incy);
235 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
236 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
238 Vexp(n, &x[0], incx, &y[0], incy);
246 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
247 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
249 Vpow(n, &x[0], incx, f, &y[0], incy);
257 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
258 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
260 Vsqrt(n, &x[0], incx, &y[0], incy);
268 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
269 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
271 Vabs(n, &x[0], incx, &y[0], incy);
283 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"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#ifdef NEKTAR_ENABLE_SIMD_VMATH
289 boost::ignore_unused(incw, incx, incy, incz);
290 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
291 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
292 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
293 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
296 Vvtvp(n, &
w[0], incw, &x[0], incx, &y[0], incy, &
z[0], incz);
307 ASSERTL1(n * incw <=
w.size(),
"Array out of bounds");
308 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
309 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
310 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
312 Vvtvp(n,
w.origin(), incw, &x[0], incx, &y[0], incy, &
z[0], incz);
322 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
323 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
324 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
325 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
327#ifdef NEKTAR_ENABLE_SIMD_VMATH
328 boost::ignore_unused(incw, incx, incy, incz);
329 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
330 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
331 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
332 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
335 Vvtvm(n, &
w[0], incw, &x[0], incx, &y[0], incy, &
z[0], incz);
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 Svtvp(n, alpha, &x[0], incx, &y[0], incy, &
z[0], incz);
358 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
359 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
360 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
362 Svtvm(n, alpha, &x[0], incx, &y[0], incy, &
z[0], incz);
373 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
374 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
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#ifdef NEKTAR_ENABLE_SIMD_VMATH
380 boost::ignore_unused(incv, incw, incx, incy, incz);
381 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
382 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
383 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
384 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
387 Vvtvvtp(n, &v[0], incv, &
w[0], incw, &x[0], incx, &y[0], incy, &
z[0], incz);
400 ASSERTL1(n * incv <= v.size() + v.GetOffset(),
"Array out of bounds");
401 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
402 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
403 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
404 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
406#ifdef NEKTAR_ENABLE_SIMD_VMATH
407 boost::ignore_unused(incv, incw, incx, incy, incz);
408 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
409 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
410 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
411 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
414 Vvtvvtm(n, &v[0], incv, &
w[0], incw, &x[0], incx, &y[0], incy, &
z[0], incz);
425 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
426 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
427 ASSERTL1(n * incz <=
z.size() +
z.GetOffset(),
"Array out of bounds");
429 Svtsvtp(n, alpha, &x[0], incx,
beta, &y[0], incy, &
z[0], incz);
435template <
class T,
class I,
436 typename =
typename std::enable_if<std::is_floating_point<T>::value &&
437 std::is_integral<I>::value>::type>
441 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
442 ASSERTL1(n <=
z.size() +
z.GetOffset(),
"Array out of bounds");
444#ifdef NEKTAR_ENABLE_SIMD_VMATH
447 Gathr(n, &x[0], &y[0], &
z[0]);
456 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
457 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
459 Scatr(n, &x[0], &y[0], &
z[0]);
467 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
468 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
470 Assmb(n, &x[0], &y[0], &
z[0]);
478 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
480 return Vsum(n, &x[0], incx);
487 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
489 return Imax(n, &x[0], incx);
496 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
498 return Vmax(n, &x[0], incx);
505 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
507 return Iamax(n, &x[0], incx);
514 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
516 return Vamax(n, &x[0], incx);
523 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
525 return Imin(n, &x[0], incx);
532 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
534 return Vmin(n, &x[0], incx);
541 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
543 return Nnan(n, &x[0], incx);
550 ASSERTL1(n <=
w.size() +
w.GetOffset(),
"Array out of bounds");
551 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
553 return Dot(n, &
w[0], &x[0]);
561 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
562 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
564 return Dot(n, &
w[0], incw, &x[0], incx);
572 ASSERTL1(n <=
w.size() +
w.GetOffset(),
"Array out of bounds");
573 ASSERTL1(n <= x.size() + x.GetOffset(),
"Array out of bounds");
574 ASSERTL1(n <= y.size() + y.GetOffset(),
"Array out of bounds");
576 return Dot2(n, &
w[0], &x[0], &y[0]);
585 ASSERTL1(n * incw <=
w.size() +
w.GetOffset(),
"Array out of bounds");
586 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
587 ASSERTL1(n * incy <= y.size() + y.GetOffset(),
"Array out of bounds");
589 return Dot2(n, &
w[0], incw, &x[0], incx, &y[0], incy);
600 x.size() + x.GetOffset(),
601 "Array out of bounds");
603 y.size() + y.GetOffset(),
604 "Array out of bounds");
606 Vcopy(n, &x[0], incx, &y[0], incy);
615 x.size() + x.GetOffset(),
616 "Array out of bounds");
618 y.size() + y.GetOffset(),
619 "Array out of bounds");
621 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)
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)
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)
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)
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)
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)
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 (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)
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 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)
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)