36 #ifndef NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATHARRAY_HPP
37 #define NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATHARRAY_HPP
44 using namespace Nektar;
48 template<
class T>
void Fill(
int n,
const T alpha, Array<OneD, T> &x,
const int incx )
51 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Out of bounds");
53 Fill(n,alpha,&x[0],incx);
56 template<
class T>
void FillWhiteNoise(
int n,
const T eps, Array<OneD, T> &x,
const int incx,
int outseed)
58 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Out of bounds");
64 template<
class T>
void Vmul(
int n,
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)
66 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
67 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
68 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
70 Vmul(n,&x[0],incx,&y[0],incy,&z[0],incz);
73 template<
class T>
void Vmul(
int n,
const Array<TwoD,NekDouble>::const_reference &x,
const int incx,
const Array<OneD,const T> &y,
const int incy, Array<OneD,T> &z,
const int incz)
75 ASSERTL1(n*incx <= x.num_elements(),
"Array out of bounds");
76 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
77 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
79 Vmul(n,x.origin(),incx,&y[0],incy,&z[0],incz);
84 template<
class T>
void Smul(
int n,
const T alpha,
const Array<OneD,const T> &x,
const int incx, Array<OneD,T> &y,
const int incy)
86 ASSERTL1(static_cast<unsigned int>(n*incx) <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
87 ASSERTL1(static_cast<unsigned int>(n*incy) <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
89 Smul(n,alpha, &x[0],incx,&y[0],incy);
93 template<
class T>
void Vdiv(
int n,
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)
95 ASSERTL1(static_cast<unsigned int>(n*incx) <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
96 ASSERTL1(static_cast<unsigned int>(n*incy) <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
97 ASSERTL1(static_cast<unsigned int>(n*incz) <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
99 Vdiv(n,&x[0],incx,&y[0],incy,&z[0],incz);
104 template<
class T>
void Sdiv(
int n,
const T alpha,
const Array<OneD,const T> &x,
const int incx, Array<OneD,T> &y,
const int incy)
106 ASSERTL1(static_cast<unsigned int>(n*incx) <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
107 ASSERTL1(static_cast<unsigned int>(n*incy) <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
109 Sdiv(n,alpha,&x[0],incx,&y[0],incy);
113 template<
class T>
void Vadd(
int n,
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)
116 ASSERTL1(static_cast<unsigned int>(n*incx) <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
117 ASSERTL1(static_cast<unsigned int>(n*incy) <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
118 ASSERTL1(static_cast<unsigned int>(n*incz) <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
120 Vadd(n,&x[0],incx,&y[0],incy,&z[0],incz);
124 template<
class T>
void Sadd(
int n,
const T alpha,
const Array<OneD,const T> &x,
const int incx, Array<OneD,T> &y,
const int incy)
127 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
128 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
130 Sadd(n,alpha,&x[0],incx,&y[0],incy);
134 template<
class T>
void Vsub(
int n,
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)
136 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
137 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
138 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
140 Vsub(n,&x[0],incx,&y[0],incy,&z[0],incz);
145 template<
class T>
void Zero(
int n, Array<OneD,T> &x,
const int incx)
147 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
154 template<
class T>
void Neg(
int n, Array<OneD,T> &x,
const int incx)
156 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
162 template<
class T>
void Vlog(
int n,
const Array<OneD,const T> &x,
const int incx, Array<OneD,T> &y,
const int incy)
164 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
165 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
167 Vlog(n, &x[0], incx, &y[0], incy);
171 template<
class T>
void Vexp(
int n,
const Array<OneD,const T> &x,
const int incx, Array<OneD,T> &y,
const int incy)
173 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
174 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
176 Vexp(n, &x[0], incx, &y[0], incy);
179 template<
class T>
void Vpow(
int n,
const Array<OneD,const T> &x,
const int incx,
const T f, Array<OneD,T> &y,
const int incy)
181 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
182 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
184 Vpow(n, &x[0], incx, f, &y[0], incy);
188 template<
class T>
void Vsqrt(
int n,
const Array<OneD,const T> &x,
const int incx, Array<OneD,T> &y,
const int incy)
190 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
191 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
193 Vsqrt(n,&x[0],incx,&y[0],incy);
197 template<
class T>
void Vabs(
int n,
const Array<OneD,const T> &x,
const int incx, Array<OneD,T> &y,
const int incy)
199 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
200 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
202 Vabs(n,&x[0],incx,&y[0],incy);
208 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)
210 ASSERTL1(n*incw <= w.num_elements()+w.GetOffset(),
"Array out of bounds");
211 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
212 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
213 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
215 Vvtvp(n,&w[0],incw,&x[0],incx,&y[0],incy,&z[0],incz);
218 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)
220 ASSERTL1(n*incw <= w.num_elements(),
"Array out of bounds");
221 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
222 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
223 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
225 Vvtvp(n,w.origin(),incw,&x[0],incx,&y[0],incy,&z[0],incz);
229 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)
231 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
232 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
233 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
235 Svtvp(n,alpha,&x[0],incx,&y[0],incy,&z[0],incz);
240 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)
242 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
243 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
244 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
246 Svtvm(n,alpha,&x[0],incx,&y[0],incy,&z[0],incz);
251 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)
253 ASSERTL1(n*incw <= w.num_elements()+w.GetOffset(),
"Array out of bounds");
254 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
255 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
256 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
258 Vvtvm(n,&w[0],incw,&x[0],incx,&y[0],incy,&z[0],incz);
265 const Array<OneD,const T> &v,
int incv,
266 const Array<OneD,const T> &w,
int incw,
267 const Array<OneD,const T> &x,
int incx,
268 const Array<OneD,const T> &y,
int incy,
269 Array<OneD, T> &z,
int incz)
271 ASSERTL1(n*incv <= v.num_elements()+v.GetOffset(),
"Array out of bounds");
272 ASSERTL1(n*incw <= w.num_elements()+w.GetOffset(),
"Array out of bounds");
273 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
274 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
275 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
277 Vvtvvtp(n,&v[0],incv,&w[0],incw,&x[0],incx,&y[0],incy,&z[0],incz);
281 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)
283 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
284 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
285 ASSERTL1(n*incz <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
287 Svtsvtp(n,alpha,&x[0],incx,beta,&y[0],incy,&z[0],incz);
296 template<
class T>
void Gathr(
int n,
const Array<OneD, const T> &x,
const Array<OneD, const int> &y, Array<OneD,T> &z)
299 ASSERTL1(n <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
300 ASSERTL1(n <= z.num_elements()+z.GetOffset(),
"Array out of bounds");
302 Gathr(n,&x[0],&y[0],&z[0]);
307 template<
class T>
void Scatr(
int n,
const Array<OneD,const T> &x,
const Array<OneD,const int> &y, Array<OneD,T> &z)
309 ASSERTL1(n <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
310 ASSERTL1(n <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
312 Scatr(n,&x[0],&y[0],&z[0]);
317 template<
class T>
void Assmb(
int n,
const Array<OneD,T> &x,
const Array<OneD,int> &y, Array<OneD,T> &z)
319 ASSERTL1(n <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
320 ASSERTL1(n <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
322 Assmb(n,&x[0],&y[0],&z[0]);
329 template<
class T> T
Vsum(
int n,
const Array<OneD, const T> &x,
const int incx)
331 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
333 return Vsum(n,&x[0],incx);
338 template<
class T>
int Imax(
int n,
const Array<OneD, const T> &x,
const int incx)
340 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
342 return Imax(n,&x[0],incx);
347 template<
class T> T
Vmax(
int n,
const Array<OneD, const T> &x,
const int incx)
349 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
351 return Vmax(n,&x[0],incx);
355 template<
class T>
int Iamax(
int n,
const Array<OneD, const T> &x,
const int incx)
357 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
359 return Iamax(n,&x[0],incx);
365 template<
class T> T
Vamax(
int n,
const Array<OneD, const T> &x,
const int incx)
367 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
369 return Vamax(n,&x[0],incx);
374 template<
class T>
int Imin(
int n,
const Array<OneD, const T> &x,
const int incx)
376 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
378 return Imin(n,&x[0],incx);
383 template<
class T> T
Vmin(
int n,
const Array<OneD, const T> &x,
const int incx)
385 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
387 return Vmin(n,&x[0],incx);
391 template<
class T> T
Dot(
int n,
392 const Array<OneD, const T> &w,
393 const Array<OneD, const T> &x)
395 ASSERTL1(n <= w.num_elements()+w.GetOffset(),
"Array out of bounds");
396 ASSERTL1(n <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
398 return Dot(n,&w[0],&x[0]);
402 template<
class T> T
Dot(
int n,
403 const Array<OneD, const T> &w,
const int incw,
404 const Array<OneD, const T> &x,
const int incx)
406 ASSERTL1(n*incw <= w.num_elements()+w.GetOffset(),
"Array out of bounds");
407 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
409 return Dot(n,&w[0],incw,&x[0],incx);
413 template<
class T> T
Dot2(
int n,
414 const Array<OneD, const T> &w,
415 const Array<OneD, const T> &x,
416 const Array<OneD, const int> &y)
418 ASSERTL1(n <= w.num_elements()+w.GetOffset(),
"Array out of bounds");
419 ASSERTL1(n <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
420 ASSERTL1(n <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
422 return Dot2(n,&w[0],&x[0],&y[0]);
426 template<
class T> T
Ddot(
int n,
427 const Array<OneD, const T> &w,
const int incw,
428 const Array<OneD, const T> &x,
const int incx,
429 const Array<OneD, const int> &y,
const int incy)
431 ASSERTL1(n*incw <= w.num_elements()+w.GetOffset(),
"Array out of bounds");
432 ASSERTL1(n*incx <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
433 ASSERTL1(n*incy <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
435 return Dot2(n,&w[0],incw,&x[0],incx,&y[0],incy);
440 template<
class T>
void Vcopy(
int n,
const Array<OneD, const T> &x,
int incx, Array<OneD,T> &y,
int const incy)
442 ASSERTL1(static_cast<unsigned int>(std::abs(n*incx)) <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
443 ASSERTL1(static_cast<unsigned int>(std::abs(n*incy)) <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
445 Vcopy(n,&x[0],incx,&y[0],incy);
448 template<
class T>
void Reverse(
int n,
const Array<OneD, const T> &x,
int incx, Array<OneD,T> &y,
int const incy)
450 ASSERTL1(static_cast<unsigned int>(std::abs(n*incx)) <= x.num_elements()+x.GetOffset(),
"Array out of bounds");
451 ASSERTL1(static_cast<unsigned int>(std::abs(n*incy)) <= y.num_elements()+y.GetOffset(),
"Array out of bounds");
453 Reverse(n,&x[0],incx,&y[0],incy);
457 #endif //VECTORMATHARRAY_HPP