46 template<
class T>
void Fill(
int n,
const T alpha, T *x,
const int incx )
57 #define IM1 2147483563
58 #define IM2 2147483399
68 #define NDIV (1+IMM1/NTAB)
70 #define RNMX (1.0-EPS)
73 template<
class T> T
ran2 (
long* idum)
84 static long idum2=123456789;
90 if (-(*idum) < 1) *idum = 1;
91 else *idum = -(*idum);
93 for (j=
NTAB+7; j>=0; j--) {
96 if (*idum < 0) *idum +=
IM1;
97 if (j <
NTAB) iv[j] = *idum;
104 if (*idum < 0) *idum +=
IM1;
108 if (idum2 < 0) idum2 +=
IM2;
113 if (iy < 1) iy +=
IMM1;
139 const int incx,
int outseed)
142 boost::mutex::scoped_lock l(mutex);
147 static long seed = 0;
152 seed = long(outseed);
163 v1 = 2.0 * ran2<T> (&seed) - 1.0;
164 v2 = 2.0 * ran2<T> (&seed) - 1.0;
166 }
while (rsq >= 1.0 || rsq == 0.0);
167 fac = sqrt(-2.0 * log (rsq) / rsq);
183 template<
class T>
void Vmul(
int n,
const T *x,
const int incx,
const T *y,
184 const int incy, T*z,
const int incz)
187 if (incx == 1 && incy == 1 && incz == 1)
213 template<
class T>
void Smul(
int n,
const T alpha,
const T *x,
const int incx,
214 T *y,
const int incy)
217 if (incx == 1 && incy == 1)
241 template<
class T>
void Vdiv(
int n,
const T *x,
const int incx,
const T *y,
242 const int incy, T*z,
const int incz)
245 if (incx == 1 && incy == 1)
271 template<
class T>
void Sdiv(
int n,
const T alpha,
const T *x,
272 const int incx, T *y,
const int incy)
275 if (incx == 1 && incy == 1)
299 template<
class T>
void Vadd(
int n,
const T *x,
const int incx,
const T *y,
300 const int incy, T *z,
const int incz)
315 template<
class T>
void Sadd(
int n,
const T alpha,
const T *x,
316 const int incx, T *y,
const int incy)
319 if (incx == 1 && incy == 1)
343 template<
class T>
void Vsub(
int n,
const T *x,
const int incx,
const T *y,
344 const int incy, T *z,
const int incz)
347 if (incx == 1 && incy == 1 && incz == 1)
373 template<
class T>
void Zero(
int n, T *x,
const int incx)
377 std::memset(x,
'\0', n*
sizeof(T));
396 template<
class T>
void Neg(
int n, T *x,
const int incx)
408 template<
class T>
void Vsqrt(
int n,
const T *x,
const int incx,
409 T *y,
const int incy)
424 template<
class T>
void Vabs(
int n,
const T *x,
const int incx,
425 T *y,
const int incy)
429 *y = ( *x >0)? *x:-(*x);
443 const T *w,
const int incw,
444 const T *x,
const int incx,
445 const T *y,
const int incy,
446 T *z,
const int incz)
450 *z = (*w) * (*x) + (*y);
465 template<
class T>
void Vvtvm(
int n,
const T *w,
const int incw,
const T *x,
466 const int incx,
const T *y,
const int incy,
467 T *z,
const int incz)
471 *z = (*w) * (*x) - (*y);
486 const int incx,
const T *y,
const int incy,
487 T *z,
const int incz)
490 if (incx == 1 && incy == 1 && incz == 1)
494 *z = alpha * (*x) + (*y);
504 *z = alpha * (*x) + (*y);
518 template<
class T>
void Svtvm(
int n,
const T alpha,
const T *x,
519 const int incx,
const T *y,
const int incy,
520 T *z,
const int incz)
524 *z = alpha * (*x) - (*y);
538 const T* v,
int incv,
539 const T* w,
int incw,
540 const T* x,
int incx,
541 const T* y,
int incy,
546 *z = (*v) * (*w) + (*x) * (*y);
565 const T* v,
int incv,
566 const T* w,
int incw,
567 const T* x,
int incx,
568 const T* y,
int incy,
573 *z = (*v) * (*w) - (*x) * (*y);
593 const T* x,
int incx,
595 const T* y,
int incy,
600 *z = alpha * (*x) + beta * (*y);
619 const T* v,
int incv,
620 const T* w,
int incw,
621 const T* x,
int incx,
626 *z = alpha * (*v) + (*w) + (*x);
644 template<
class T>
void Gathr(
int n,
const T *x,
const int *y,
659 template<
class T>
void Gathr(
int n,
const T *
sign,
const T *x,
const int *y,
664 *z++ = *(sign++) * (*(x + *y++));
673 template<
class T>
void Scatr(
int n,
const T *x,
const int *y,
678 *(z + *(y++)) = *(x++);
686 template<
class T>
void Scatr(
int n,
const T *
sign,
const T *x,
const int *y,
693 *(z + *(y++)) = *(sign++) * (*(x++));
709 template<
class T>
void Assmb(
int n,
const T *x,
const int *y,
714 *(z + *(y++)) += *(x++);
722 template<
class T>
void Assmb(
int n,
const T *
sign,
const T *x,
const int *y,
727 *(z + *(y++)) += *(sign++) * (*(x++));
737 template<
class T> T
Vsum(
int n,
const T *x,
const int incx)
755 template<
class T>
int Imax(
int n,
const T *x,
const int incx)
758 int i, indx = ( n > 0 ) ? 0 : -1;
761 for (i = 0; i < n; i++)
779 template<
class T> T
Vmax(
int n,
const T *x,
const int incx)
800 template<
class T>
int Iamax(
int n,
const T *x,
const int incx)
803 int i, indx = ( n > 0 ) ? 0 : -1;
807 for (i = 0; i < n; i++)
809 xm = (*x > 0)? *x: -*x;
825 template<
class T> T
Vamax(
int n,
const T *x,
const int incx)
833 xm = (*x > 0)? *x: -*x;
847 template<
class T>
int Imin(
int n,
const T *x,
const int incx)
850 int i, indx = ( n > 0 ) ? 0 : -1;
871 template<
class T> T
Vmin(
int n,
const T *x,
const int incx)
892 template<
class T>
int Nnan(
int n,
const T *x,
const int incx)
914 template<
class T> T
Dot(
int n,
934 template<
class T> T
Dot(
int n,
935 const T *w,
const int incw,
936 const T *x,
const int incx)
954 template<
class T> T
Dot2(
int n,
963 sum += (*y == 1 ? (*w) * (*x) : 0 );
978 template<
class T> T
Dot2(
int n,
979 const T *w,
const int incw,
980 const T *x,
const int incx,
981 const int *y,
const int incy)
987 sum += (*y == 1 ? (*w) * (*x) : 0.0 );
998 const int *y,
const int incy);
1060 template<
typename T>
1061 void Vcopy(
int n,
const T *x,
const int incx,
1062 T *y,
const int incy)
1064 if( incx ==1 && incy == 1)
1066 memcpy(y,x,n*
sizeof(T));
1080 template LIB_UTILITIES_EXPORT void Vcopy(
int n,
const unsigned int *x,
const int incx,
unsigned int *y,
const int incy);
1085 template<
class T>
void Reverse(
int n,
const T *x,
const int incx, T *y,
const int incy)
1092 y[nloop] = x[nloop];
1094 for(i = 0; i < nloop; ++i)
void Gathr(int n, const T *x, const int *y, T *z)
Gather vector z[i] = x[y[i]].
#define sign(a, b)
return the sign(b)*a
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in 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 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
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/y.
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.
void Vabs(int n, const T *x, const int incx, T *y, const int incy)
vabs: y = |x|
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
void Reverse(int n, const T *x, const int incx, T *y, const int incy)
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
T ran2(long *idum)
Generates a number from ~Normal(0,1)
#define LIB_UTILITIES_EXPORT
int Nnan(int n, const T *x, const int incx)
Return number of NaN elements of x.
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 Scatr(int n, const T *x, const int *y, T *z)
Scatter vector z[y[i]] = x[i].
void Neg(int n, T *x, const int incx)
Negate x = -x.
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 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):
T Vamax(int n, const T *x, const int incx)
Return the maximum absolute element in x called vamax to avoid conflict with max. ...
int Iamax(int n, const T *x, const int incx)
Return the index of the maximum absolute element in x.
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
T Dot(int n, const T *w, const T *x)
vvtvp (vector times vector times vector): z = w*x*y
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 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):
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 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
T Dot2(int n, const T *w, const T *x, const int *y)
vvtvp (vector times vector times vector): z = w*x*y
void FillWhiteNoise(int n, const T eps, T *x, const int incx, int outseed)
Fills a vector with white noise.
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):
static boost::mutex mutex
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
void Zero(int n, T *x, const int incx)
Zero vector.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
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 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.