35 #ifndef NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATHARRAY_HPP
36 #define NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATHARRAY_HPP
51 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Out of bounds");
53 Fill(n,alpha,&x[0],incx);
58 const int incx,
int outseed = 9999)
60 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Out of bounds");
68 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
69 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
70 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
72 #ifdef NEKTAR_ENABLE_SIMD_VMATH
73 boost::ignore_unused(incx, incy, incz);
74 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
75 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
76 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
79 Vmul(n,&x[0],incx,&y[0],incy,&z[0],incz);
86 ASSERTL1(n*incx <= x.size(),
"Array out of bounds");
87 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
88 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
90 Vmul(n,x.origin(),incx,&y[0],incy,&z[0],incz);
97 ASSERTL1(
static_cast<unsigned int>(n*incx) <= x.size()+x.GetOffset(),
"Array out of bounds");
98 ASSERTL1(
static_cast<unsigned int>(n*incy) <= y.size()+y.GetOffset(),
"Array out of bounds");
100 Smul(n,alpha, &x[0],incx,&y[0],incy);
106 ASSERTL1(
static_cast<unsigned int>(n*incx) <= x.size()+x.GetOffset(),
"Array out of bounds");
107 ASSERTL1(
static_cast<unsigned int>(n*incy) <= y.size()+y.GetOffset(),
"Array out of bounds");
108 ASSERTL1(
static_cast<unsigned int>(n*incz) <= z.size()+z.GetOffset(),
"Array out of bounds");
110 Vdiv(n,&x[0],incx,&y[0],incy,&z[0],incz);
117 ASSERTL1(
static_cast<unsigned int>(n*incx) <= x.size()+x.GetOffset(),
"Array out of bounds");
118 ASSERTL1(
static_cast<unsigned int>(n*incy) <= y.size()+y.GetOffset(),
"Array out of bounds");
120 Sdiv(n,alpha,&x[0],incx,&y[0],incy);
126 ASSERTL1(
static_cast<unsigned int>(n*incx) <= x.size()+x.GetOffset(),
"Array out of bounds");
127 ASSERTL1(
static_cast<unsigned int>(n*incy) <= y.size()+y.GetOffset(),
"Array out of bounds");
128 ASSERTL1(
static_cast<unsigned int>(n*incz) <= z.size()+z.GetOffset(),
"Array out of bounds");
130 #ifdef NEKTAR_ENABLE_SIMD_VMATH
131 boost::ignore_unused(incx, incy, incz);
132 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
133 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
134 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
137 Vadd(n,&x[0],incx,&y[0],incy,&z[0],incz);
145 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
146 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
148 Sadd(n,alpha,&x[0],incx,&y[0],incy);
154 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
155 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
156 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
158 Vsub(n,&x[0],incx,&y[0],incy,&z[0],incz);
163 template<
class T>
void Ssub(
int n,
const T alpha,
168 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
169 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
171 Ssub(n,alpha,&x[0],incx,&y[0],incy);
177 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
186 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
194 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
195 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
197 Vlog(n, &x[0], incx, &y[0], incy);
203 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
204 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
206 Vexp(n, &x[0], incx, &y[0], incy);
211 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
212 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
214 Vpow(n, &x[0], incx, f, &y[0], incy);
220 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
221 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
223 Vsqrt(n,&x[0],incx,&y[0],incy);
229 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
230 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
232 Vabs(n,&x[0],incx,&y[0],incy);
238 template<
class T>
void Vvtvp(
int n,
const Array<OneD, const T> &w,
const int incw,
const Array<OneD,const T> &x,
const int incx,
const Array<OneD, const T> &y,
const int incy,
Array<OneD,T> &z,
const int incz)
240 ASSERTL1(n*incw <= w.size()+w.GetOffset(),
"Array out of bounds");
241 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
242 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
243 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
245 #ifdef NEKTAR_ENABLE_SIMD_VMATH
246 boost::ignore_unused(incw, incx, incy, incz);
247 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
248 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
249 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
250 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
253 Vvtvp(n,&w[0],incw,&x[0],incx,&y[0],incy,&z[0],incz);
257 template<
class T>
void Vvtvp(
int n,
const Array<TwoD,NekDouble>::const_reference &w,
const int incw,
const Array<OneD, const T> &x,
const int incx,
const Array<OneD,const T> &y,
const int incy,
Array<OneD,T> &z,
const int incz)
259 ASSERTL1(n*incw <= w.size(),
"Array out of bounds");
260 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
261 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
262 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
264 Vvtvp(n,w.origin(),incw,&x[0],incx,&y[0],incy,&z[0],incz);
268 template<
class T>
void Svtvp(
int n,
const T alpha,
const Array<OneD,const T> &x,
const int incx,
const Array<OneD, const T> &y,
const int incy,
Array<OneD,T> &z,
const int incz)
270 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
271 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
272 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
274 Svtvp(n,alpha,&x[0],incx,&y[0],incy,&z[0],incz);
279 template<
class T>
void Svtvm(
int n,
const T alpha,
const Array<OneD,const T> &x,
const int incx,
const Array<OneD, const T> &y,
const int incy,
Array<OneD,T> &z,
const int incz)
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 Svtvm(n,alpha,&x[0],incx,&y[0],incy,&z[0],incz);
290 template<
class T>
void Vvtvm(
int n,
const Array<OneD,const T> &w,
const int incw,
const Array<OneD,const T> &x,
const int incx,
const Array<OneD,const T> &y,
const int incy,
Array<OneD,T> &z,
const int incz)
292 ASSERTL1(n*incw <= w.size()+w.GetOffset(),
"Array out of bounds");
293 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
294 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
295 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
299 #ifdef NEKTAR_ENABLE_SIMD_VMATH
300 boost::ignore_unused(incw, incx, incy, incz);
301 ASSERTL1(incw == 1,
"Simd vmath requires inc = 1");
302 ASSERTL1(incx == 1,
"Simd vmath requires inc = 1");
303 ASSERTL1(incy == 1,
"Simd vmath requires inc = 1");
304 ASSERTL1(incz == 1,
"Simd vmath requires inc = 1");
307 Vvtvm(n,&w[0],incw,&x[0],incx,&y[0],incy,&z[0],incz);
321 ASSERTL1(n*incv <= v.size()+v.GetOffset(),
"Array out of bounds");
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(incv, 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 Vvtvvtp(n,&v[0],incv,&w[0],incw,&x[0],incx,&y[0],incy,&z[0],incz);
340 template<
class T>
void Svtsvtp(
int n,
const T alpha,
const Array<OneD,const T> &x,
const int incx,
const T beta,
const Array<OneD,const T> &y,
const int incy,
Array<OneD,T> &z,
const int incz)
342 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
343 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
344 ASSERTL1(n*incz <= z.size()+z.GetOffset(),
"Array out of bounds");
346 Svtsvtp(n,alpha,&x[0],incx,beta,&y[0],incy,&z[0],incz);
355 template<
class T,
class I,
typename =
typename std::enable_if
357 std::is_floating_point<T>::value &&
358 std::is_integral<I>::value
364 ASSERTL1(n <= y.size()+y.GetOffset(),
"Array out of bounds");
365 ASSERTL1(n <= z.size()+z.GetOffset(),
"Array out of bounds");
367 #ifdef NEKTAR_ENABLE_SIMD_VMATH
370 Gathr(n,&x[0],&y[0],&z[0]);
377 ASSERTL1(n <= x.size()+x.GetOffset(),
"Array out of bounds");
378 ASSERTL1(n <= y.size()+y.GetOffset(),
"Array out of bounds");
380 Scatr(n,&x[0],&y[0],&z[0]);
387 ASSERTL1(n <= x.size()+x.GetOffset(),
"Array out of bounds");
388 ASSERTL1(n <= y.size()+y.GetOffset(),
"Array out of bounds");
390 Assmb(n,&x[0],&y[0],&z[0]);
399 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
401 return Vsum(n,&x[0],incx);
408 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
410 return Imax(n,&x[0],incx);
417 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
419 return Vmax(n,&x[0],incx);
425 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
427 return Iamax(n,&x[0],incx);
435 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
437 return Vamax(n,&x[0],incx);
444 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
446 return Imin(n,&x[0],incx);
453 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
455 return Vmin(n,&x[0],incx);
461 ASSERTL1(n * incx <= x.size() + x.GetOffset(),
"Array out of bounds");
463 return Nnan(n, &x[0], incx);
467 template<
class T> T
Dot(
int n,
471 ASSERTL1(n <= w.size()+w.GetOffset(),
"Array out of bounds");
472 ASSERTL1(n <= x.size()+x.GetOffset(),
"Array out of bounds");
474 return Dot(n,&w[0],&x[0]);
478 template<
class T> T
Dot(
int n,
482 ASSERTL1(n*incw <= w.size()+w.GetOffset(),
"Array out of bounds");
483 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
485 return Dot(n,&w[0],incw,&x[0],incx);
489 template<
class T> T
Dot2(
int n,
494 ASSERTL1(n <= w.size()+w.GetOffset(),
"Array out of bounds");
495 ASSERTL1(n <= x.size()+x.GetOffset(),
"Array out of bounds");
496 ASSERTL1(n <= y.size()+y.GetOffset(),
"Array out of bounds");
498 return Dot2(n,&w[0],&x[0],&y[0]);
502 template<
class T> T
Ddot(
int n,
507 ASSERTL1(n*incw <= w.size()+w.GetOffset(),
"Array out of bounds");
508 ASSERTL1(n*incx <= x.size()+x.GetOffset(),
"Array out of bounds");
509 ASSERTL1(n*incy <= y.size()+y.GetOffset(),
"Array out of bounds");
511 return Dot2(n,&w[0],incw,&x[0],incx,&y[0],incy);
518 ASSERTL1(
static_cast<unsigned int>(
std::abs(n*incx)) <= x.size()+x.GetOffset(),
"Array out of bounds");
519 ASSERTL1(
static_cast<unsigned int>(
std::abs(n*incy)) <= y.size()+y.GetOffset(),
"Array out of bounds");
521 Vcopy(n,&x[0],incx,&y[0],incy);
526 ASSERTL1(
static_cast<unsigned int>(
std::abs(n*incx)) <= x.size()+x.GetOffset(),
"Array out of bounds");
527 ASSERTL1(
static_cast<unsigned int>(
std::abs(n*incy)) <= y.size()+y.GetOffset(),
"Array out of bounds");
529 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....
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 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)
Add 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)
vvtvvtp (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)
vvtvp (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)
vvtvp (vector times vector times vector): z = w*x*y
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 plus 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 plus vector): z = w*x - y
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 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)
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)