Nektar++
Vmath.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Vmath.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Collection of templated functions for vector mathematics
32//
33// Note: For those unfamiliar with the vector routines notation, it is
34// reverse polish notation (RPN). For example:
35//
36// In the function "Vvtvp()", it is "Vvt" means vector vector times,
37// which in infix notation is "v * v". So "Vvtvp" is:
38//
39// RPN: vector vector times vector plus
40// Infix: ( vector * vector ) + vector
41//
42///////////////////////////////////////////////////////////////////////////////
43
44#ifndef NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATH_HPP
45#define NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORMATH_HPP
46
48
49namespace Vmath
50{
51/***************** Math routines ***************/
52
53/// \brief Fill a vector with a constant value
54template <class T> inline void Fill(int n, const T alpha, T *x, const int incx)
55{
56 while (n--)
57 {
58 *x = alpha;
59 x += incx;
60 }
61}
62
63/// \brief Generates a number from ~Normal(0,1)
64template <class T> T ran2(long *idum);
65
66/// \brief Fills a vector with white noise.
67template <class T>
68void FillWhiteNoise(int n, const T eps, T *x, const int incx, int seed = 9999);
69
70/// \brief Multiply vector z = x*y
71template <class T>
72inline void Vmul(int n, const T *x, const int incx, const T *y, const int incy,
73 T *z, const int incz)
74{
75 ++n;
76 if (incx == 1 && incy == 1 && incz == 1)
77 {
78 while (--n)
79 {
80 *z = (*x) * (*y);
81 ++x;
82 ++y;
83 ++z;
84 }
85 }
86 else
87 {
88 while (--n)
89 {
90 *z = (*x) * (*y);
91 x += incx;
92 y += incy;
93 z += incz;
94 }
95 }
96}
97
98/// \brief Scalar multiply y = alpha*x
99template <class T>
100inline void Smul(int n, const T alpha, const T *x, const int incx, T *y,
101 const int incy)
102{
103 ++n;
104 if (incx == 1 && incy == 1)
105 {
106 while (--n)
107 {
108 *y = alpha * (*x);
109 ++x;
110 ++y;
111 }
112 }
113 else
114 {
115 while (--n)
116 {
117 *y = alpha * (*x);
118 x += incx;
119 y += incy;
120 }
121 }
122}
123
124/// \brief Multiply vector z = x/y
125template <class T>
126inline void Vdiv(int n, const T *x, const int incx, const T *y, const int incy,
127 T *z, const int incz)
128{
129 ++n;
130 if (incx == 1 && incy == 1)
131 {
132 while (--n)
133 {
134 *z = (*x) / (*y);
135 ++x;
136 ++y;
137 ++z;
138 }
139 }
140 else
141 {
142 while (--n)
143 {
144 *z = (*x) / (*y);
145 x += incx;
146 y += incy;
147 z += incz;
148 }
149 }
150}
151
152/// \brief Scalar multiply y = alpha/x
153template <class T>
154inline void Sdiv(int n, const T alpha, const T *x, const int incx, T *y,
155 const int incy)
156{
157 ++n;
158 if (incx == 1 && incy == 1)
159 {
160 while (--n)
161 {
162 *y = alpha / (*x);
163 ++x;
164 ++y;
165 }
166 }
167 else
168 {
169 while (--n)
170 {
171 *y = alpha / (*x);
172 x += incx;
173 y += incy;
174 }
175 }
176}
177
178/// \brief Add vector z = x+y
179template <class T>
180inline void Vadd(int n, const T *x, const int incx, const T *y, const int incy,
181 T *z, const int incz)
182{
183 while (n--)
184 {
185 *z = (*x) + (*y);
186 x += incx;
187 y += incy;
188 z += incz;
189 }
190}
191
192/// \brief Add vector y = alpha + x
193template <class T>
194inline void Sadd(int n, const T alpha, const T *x, const int incx, T *y,
195 const int incy)
196{
197 ++n;
198 if (incx == 1 && incy == 1)
199 {
200 while (--n)
201 {
202 *y = alpha + (*x);
203 ++x;
204 ++y;
205 }
206 }
207 else
208 {
209 while (--n)
210 {
211 *y = alpha + (*x);
212 x += incx;
213 y += incy;
214 }
215 }
216}
217
218/// \brief Subtract vector z = x-y
219template <class T>
220inline void Vsub(int n, const T *x, const int incx, const T *y, const int incy,
221 T *z, const int incz)
222{
223 ++n;
224 if (incx == 1 && incy == 1 && incz == 1)
225 {
226 while (--n)
227 {
228 *z = (*x) - (*y);
229 ++x;
230 ++y;
231 ++z;
232 }
233 }
234 else
235 {
236 while (--n)
237 {
238 *z = (*x) - (*y);
239 x += incx;
240 y += incy;
241 z += incz;
242 }
243 }
244}
245
246/// \brief Substract vector y = alpha - x
247template <class T>
248inline void Ssub(int n, const T alpha, const T *x, const int incx, T *y,
249 const int incy)
250{
251 ++n;
252 if (incx == 1 && incy == 1)
253 {
254 while (--n)
255 {
256 *y = alpha - (*x);
257 ++x;
258 ++y;
259 }
260 }
261 else
262 {
263 while (--n)
264 {
265 *y = alpha - (*x);
266 x += incx;
267 y += incy;
268 }
269 }
270}
271
272/// \brief Zero vector
273template <class T> inline void Zero(int n, T *x, const int incx)
274{
275 if (incx == 1)
276 {
277 std::memset(x, '\0', n * sizeof(T));
278 }
279 else
280 {
281 T zero = 0;
282 ++n;
283 while (--n)
284 {
285 *x = zero;
286 x += incx;
287 }
288 }
289}
290
291/// \brief Negate x = -x
292template <class T> inline void Neg(int n, T *x, const int incx)
293{
294 while (n--)
295 {
296 *x = -(*x);
297 x += incx;
298 }
299}
300
301/// \brief log y = log(x)
302template <class T>
303inline void Vlog(int n, const T *x, const int incx, T *y, const int incy)
304{
305 while (n--)
306 {
307 *y = log(*x);
308 x += incx;
309 y += incy;
310 }
311}
312
313/// \brief exp y = exp(x)
314template <class T>
315inline void Vexp(int n, const T *x, const int incx, T *y, const int incy)
316{
317 while (n--)
318 {
319 *y = exp(*x);
320 x += incx;
321 y += incy;
322 }
323}
324
325/// \brief pow y = pow(x, f)
326template <class T>
327inline void Vpow(int n, const T *x, const int incx, const T f, T *y,
328 const int incy)
329{
330 while (n--)
331 {
332 *y = pow(*x, f);
333 x += incx;
334 y += incy;
335 }
336}
337
338/// \brief sqrt y = sqrt(x)
339template <class T>
340inline void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
341{
342 while (n--)
343 {
344 *y = sqrt(*x);
345 x += incx;
346 y += incy;
347 }
348}
349
350/// \brief vabs: y = |x|
351template <class T>
352inline void Vabs(int n, const T *x, const int incx, T *y, const int incy)
353{
354 while (n--)
355 {
356 *y = (*x > 0) ? *x : -(*x);
357 x += incx;
358 y += incy;
359 }
360}
361
362/********** Triad routines ***********************/
363
364/// \brief vvtvp (vector times vector plus vector): z = w*x + y
365template <class T>
366inline void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx,
367 const T *y, const int incy, T *z, const int incz)
368{
369 while (n--)
370 {
371 *z = (*w) * (*x) + (*y);
372 w += incw;
373 x += incx;
374 y += incy;
375 z += incz;
376 }
377}
378
379/// \brief vvtvm (vector times vector minus vector): z = w*x - y
380template <class T>
381inline void Vvtvm(int n, const T *w, const int incw, const T *x, const int incx,
382 const T *y, const int incy, T *z, const int incz)
383{
384 while (n--)
385 {
386 *z = (*w) * (*x) - (*y);
387 w += incw;
388 x += incx;
389 y += incy;
390 z += incz;
391 }
392}
393
394/// \brief Svtvp (scalar times vector plus vector): z = alpha*x + y
395template <class T>
396inline void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y,
397 const int incy, T *z, const int incz)
398{
399 ++n;
400 if (incx == 1 && incy == 1 && incz == 1)
401 {
402 while (--n)
403 {
404 *z = alpha * (*x) + (*y);
405 ++x;
406 ++y;
407 ++z;
408 }
409 }
410 else
411 {
412 while (--n)
413 {
414 *z = alpha * (*x) + (*y);
415 x += incx;
416 y += incy;
417 z += incz;
418 }
419 }
420}
421
422/// \brief Svtvm (scalar times vector minus vector): z = alpha*x - y
423template <class T>
424inline void Svtvm(int n, const T alpha, const T *x, const int incx, const T *y,
425 const int incy, T *z, const int incz)
426{
427 while (n--)
428 {
429 *z = alpha * (*x) - (*y);
430 x += incx;
431 y += incy;
432 z += incz;
433 }
434}
435
436/// \brief vvtvvtp (vector times vector plus vector times vector):
437// z = v*w + x*y
438template <class T>
439inline void Vvtvvtp(int n, const T *v, int incv, const T *w, int incw,
440 const T *x, int incx, const T *y, int incy, T *z, int incz)
441{
442 while (n--)
443 {
444 *z = (*v) * (*w) + (*x) * (*y);
445 v += incv;
446 w += incw;
447 x += incx;
448 y += incy;
449 z += incz;
450 }
451}
452
453/// \brief vvtvvtm (vector times vector minus vector times vector):
454// z = v*w - x*y
455template <class T>
456inline void Vvtvvtm(int n, const T *v, int incv, const T *w, int incw,
457 const T *x, int incx, const T *y, int incy, T *z, int incz)
458{
459 while (n--)
460 {
461 *z = (*v) * (*w) - (*x) * (*y);
462 v += incv;
463 w += incw;
464 x += incx;
465 y += incy;
466 z += incz;
467 }
468}
469
470/// \brief Svtsvtp (scalar times vector plus scalar times vector):
471// z = alpha*x + beta*y
472template <class T>
473inline void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta,
474 const T *y, int incy, T *z, int incz)
475{
476 while (n--)
477 {
478 *z = alpha * (*x) + beta * (*y);
479 x += incx;
480 y += incy;
481 z += incz;
482 }
483}
484
485/// \brief Vstvpp (scalar times vector plus vector plus vector):
486// z = alpha*w + x + y
487template <class T>
488inline void Vstvpp(int n, const T alpha, const T *v, int incv, const T *w,
489 int incw, const T *x, int incx, T *z, int incz)
490{
491 while (n--)
492 {
493 *z = alpha * (*v) + (*w) + (*x);
494 v += incv;
495 w += incw;
496 x += incx;
497 z += incz;
498 }
499}
500
501/************ Misc routine from Veclib (and extras) ************/
502
503/// \brief Gather vector z[i] = x[y[i]]
504template <class T, class I,
505 typename = typename std::enable_if<std::is_floating_point<T>::value &&
506 std::is_integral<I>::value>::type>
507inline void Gathr(I n, const T *x, const I *y, T *z)
508{
509 while (n--)
510 {
511 *z++ = *(x + *y++);
512 }
513 return;
514}
515
516/// \brief Gather vector z[i] = sign*x[y[i]]
517template <class T>
518inline void Gathr(int n, const T sign, const T *x, const int *y, T *z)
519{
520 while (n--)
521 {
522 *z++ = sign * (*(x + *y++));
523 }
524 return;
525}
526
527/// \brief Gather vector z[i] = sign[i]*x[y[i]]
528template <class T>
529inline void Gathr(int n, const T *sign, const T *x, const int *y, T *z)
530{
531 while (n--)
532 {
533 *z++ = *(sign++) * (*(x + *y++));
534 }
535 return;
536}
537
538/// \brief Scatter vector z[y[i]] = x[i]
539template <class T> inline void Scatr(int n, const T *x, const int *y, T *z)
540{
541 while (n--)
542 {
543 *(z + *(y++)) = *(x++);
544 }
545}
546
547/// \brief Scatter vector z[y[i]] = sign*x[i]
548template <class T>
549inline void Scatr(int n, const T sign, const T *x, const int *y, T *z)
550{
551 while (n--)
552 {
553 *(z + *(y++)) = sign * (*(x++));
554 }
555}
556
557/// \brief Scatter vector z[y[i]] = sign[i]*x[i]
558template <class T>
559inline void Scatr(int n, const T *sign, const T *x, const int *y, T *z)
560{
561 while (n--)
562 {
563 if (*sign)
564 {
565 *(z + *(y++)) = *(sign++) * (*(x++));
566 }
567 else
568 {
569 x++;
570 y++;
571 sign++;
572 }
573 }
574}
575
576/// \brief Assemble z[y[i]] += x[i]; z should be zero'd first
577template <class T> inline void Assmb(int n, const T *x, const int *y, T *z)
578{
579 while (n--)
580 {
581 *(z + *(y++)) += *(x++);
582 }
583}
584
585/// \brief Assemble z[y[i]] += sign*x[i]; z should be zero'd first
586template <class T>
587inline void Assmb(int n, const T sign, const T *x, const int *y, T *z)
588{
589 while (n--)
590 {
591 *(z + *(y++)) += sign * (*(x++));
592 }
593}
594
595/// \brief Assemble z[y[i]] += sign[i]*x[i]; z should be zero'd first
596template <class T>
597inline void Assmb(int n, const T *sign, const T *x, const int *y, T *z)
598{
599 while (n--)
600 {
601 *(z + *(y++)) += *(sign++) * (*(x++));
602 }
603}
604
605/************* Reduction routines *****************/
606
607/// \brief Subtract return sum(x)
608template <class T> inline T Vsum(int n, const T *x, const int incx)
609{
610
611 T sum = 0;
612
613 while (n--)
614 {
615 sum += (*x);
616 x += incx;
617 }
618
619 return sum;
620}
621
622/// \brief Return the index of the maximum element in x
623template <class T> inline int Imax(int n, const T *x, const int incx)
624{
625
626 int i, indx = (n > 0) ? 0 : -1;
627 T xmax = *x;
628
629 for (i = 0; i < n; i++)
630 {
631 if (*x > xmax)
632 {
633 xmax = *x;
634 indx = i;
635 }
636 x += incx;
637 }
638
639 return indx;
640}
641
642/// \brief Return the maximum element in x -- called vmax to avoid
643/// conflict with max
644template <class T> inline T Vmax(int n, const T *x, const int incx)
645{
646
647 T xmax = *x;
648
649 while (n--)
650 {
651 if (*x > xmax)
652 {
653 xmax = *x;
654 }
655 x += incx;
656 }
657
658 return xmax;
659}
660
661/// \brief Return the index of the maximum absolute element in x
662template <class T> inline int Iamax(int n, const T *x, const int incx)
663{
664
665 int i, indx = (n > 0) ? 0 : -1;
666 T xmax = *x;
667 T xm;
668
669 for (i = 0; i < n; i++)
670 {
671 xm = (*x > 0) ? *x : -*x;
672 if (xm > xmax)
673 {
674 xmax = xm;
675 indx = i;
676 }
677 x += incx;
678 }
679
680 return indx;
681}
682
683/// \brief Return the maximum absolute element in x
684/// called vamax to avoid conflict with max
685template <class T> inline T Vamax(int n, const T *x, const int incx)
686{
687
688 T xmax = *x;
689 T xm;
690
691 while (n--)
692 {
693 xm = (*x > 0) ? *x : -*x;
694 if (xm > xmax)
695 {
696 xmax = xm;
697 }
698 x += incx;
699 }
700 return xmax;
701}
702
703/// \brief Return the index of the minimum element in x
704template <class T> inline int Imin(int n, const T *x, const int incx)
705{
706
707 int i, indx = (n > 0) ? 0 : -1;
708 T xmin = *x;
709
710 for (i = 0; i < n; i++)
711 {
712 if (*x < xmin)
713 {
714 xmin = *x;
715 indx = i;
716 }
717 x += incx;
718 }
719
720 return indx;
721}
722
723/// \brief Return the minimum element in x - called vmin to avoid
724/// conflict with min
725template <class T> inline T Vmin(int n, const T *x, const int incx)
726{
727
728 T xmin = *x;
729
730 while (n--)
731 {
732 if (*x < xmin)
733 {
734 xmin = *x;
735 }
736 x += incx;
737 }
738
739 return xmin;
740}
741
742/// \brief Return number of NaN elements of x
743template <class T> inline int Nnan(int n, const T *x, const int incx)
744{
745
746 int nNan = 0;
747
748 while (n--)
749 {
750 if (*x != *x)
751 {
752 nNan++;
753 }
754 x += incx;
755 }
756
757 return nNan;
758}
759
760/// \brief dot product
761template <class T> inline T Dot(int n, const T *w, const T *x)
762{
763 T sum = 0;
764
765 while (n--)
766 {
767 sum += (*w) * (*x);
768 ++w;
769 ++x;
770 }
771 return sum;
772}
773
774/// \brief dot product
775template <class T>
776inline T Dot(int n, const T *w, const int incw, const T *x, const int incx)
777{
778 T sum = 0;
779
780 while (n--)
781 {
782 sum += (*w) * (*x);
783 w += incw;
784 x += incx;
785 }
786 return sum;
787}
788
789/// \brief dot product
790template <class T> inline T Dot2(int n, const T *w, const T *x, const int *y)
791{
792 T sum = 0;
793
794 while (n--)
795 {
796 sum += (*y == 1 ? (*w) * (*x) : 0);
797 ++w;
798 ++x;
799 ++y;
800 }
801 return sum;
802}
803
804/// \brief dot product
805template <class T>
806inline T Dot2(int n, const T *w, const int incw, const T *x, const int incx,
807 const int *y, const int incy)
808{
809 T sum = 0;
810
811 while (n--)
812 {
813 sum += (*y == 1 ? (*w) * (*x) : 0.0);
814 w += incw;
815 x += incx;
816 y += incy;
817 }
818 return sum;
819}
820
821/********** Memory routines ***********************/
822
823// \brief copy one vector to another
824template <class T>
825inline void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
826{
827 if (incx == 1 && incy == 1)
828 {
829 memcpy(y, x, n * sizeof(T));
830 }
831 else
832 {
833 while (n--)
834 {
835 *y = *x;
836 x += incx;
837 y += incy;
838 }
839 }
840}
841
842// \brief reverse the ordering of vector to another
843template <class T>
844inline void Reverse(int n, const T *x, const int incx, T *y, const int incy)
845{
846 int i;
847 T store;
848
849 // Perform element by element swaps in case x and y reference the same
850 // array.
851 int nloop = n / 2;
852
853 // copy value in case of n is odd number
854 y[nloop] = x[nloop];
855
856 const T *x_end = x + (n - 1) * incx;
857 T *y_end = y + (n - 1) * incy;
858 for (i = 0; i < nloop; ++i)
859 {
860 store = *x_end;
861 *y_end = *x;
862 *y = store;
863 x += incx;
864 y += incy;
865 x_end -= incx;
866 y_end -= incy;
867 }
868}
869
870} // namespace Vmath
871#endif // VECTORMATH_HPP
#define sign(a, b)
return the sign(b)*a
Definition: Polylib.cpp:47
@ beta
Gauss Radau pinned at x=-1,.
Definition: PointsType.h:59
std::vector< double > w(NPUPPER)
std::vector< double > z(NPUPPER)
Definition: Vmath.cpp:38
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.hpp:340
void Ssub(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Substract vector y = alpha - x.
Definition: Vmath.hpp:248
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):
Definition: Vmath.hpp:473
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.
Definition: Vmath.hpp:72
void Gathr(I n, const T *x, const I *y, T *z)
Gather vector z[i] = x[y[i]].
Definition: Vmath.hpp:507
void Vlog(int n, const T *x, const int incx, T *y, const int incy)
log y = log(x)
Definition: Vmath.hpp:303
void Vexp(int n, const T *x, const int incx, T *y, const int incy)
exp y = exp(x)
Definition: Vmath.hpp:315
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.
Definition: Vmath.hpp:396
void Vabs(int n, const T *x, const int incx, T *y, const int incy)
vabs: y = |x|
Definition: Vmath.hpp:352
T Dot2(int n, const T *w, const T *x, const int *y)
dot product
Definition: Vmath.hpp:790
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.hpp:292
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition: Vmath.hpp:725
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
Definition: Vmath.hpp:366
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
Definition: Vmath.hpp:608
void Scatr(int n, const T *x, const int *y, T *z)
Scatter vector z[y[i]] = x[i].
Definition: Vmath.hpp:539
T Dot(int n, const T *w, const T *x)
dot product
Definition: Vmath.hpp:761
void Assmb(int n, const T *x, const int *y, T *z)
Assemble z[y[i]] += x[i]; z should be zero'd first.
Definition: Vmath.hpp:577
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.
Definition: Vmath.hpp:424
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.
Definition: Vmath.hpp:180
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
Definition: Vmath.hpp:381
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):
Definition: Vmath.hpp:456
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/x.
Definition: Vmath.hpp:154
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.hpp:623
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.
Definition: Vmath.hpp:126
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in x.
Definition: Vmath.hpp:704
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54
T ran2(long *idum)
Generates a number from ~Normal(0,1)
Definition: Vmath.cpp:56
void Vstvpp(int n, const T alpha, const T *v, int incv, const T *w, int incw, const T *x, int incx, T *z, int incz)
Vstvpp (scalar times vector plus vector plus vector):
Definition: Vmath.hpp:488
void FillWhiteNoise(int n, const T eps, T *x, const int incx, int outseed)
Fills a vector with white noise.
Definition: Vmath.cpp:154
int Nnan(int n, const T *x, const int incx)
Return number of NaN elements of x.
Definition: Vmath.hpp:743
T Vamax(int n, const T *x, const int incx)
Return the maximum absolute element in x called vamax to avoid conflict with max.
Definition: Vmath.hpp:685
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition: Vmath.hpp:194
void Reverse(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:844
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.hpp:644
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):
Definition: Vmath.hpp:439
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825
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.
Definition: Vmath.hpp:220
void Vpow(int n, const T *x, const int incx, const T f, T *y, const int incy)
pow y = pow(x, f)
Definition: Vmath.hpp:327
int Iamax(int n, const T *x, const int incx)
Return the index of the maximum absolute element in x.
Definition: Vmath.hpp:662
scalarT< T > log(scalarT< T > in)
Definition: scalar.hpp:303
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294