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;
138 template<
class T>
void FillWhiteNoise(
int n,
const T eps, T *x,
const int incx,
int outseed)
141 boost::mutex::scoped_lock l(mutex);
146 long seed = long(outseed);
151 v1 = 2.0 * ran2<T> (&seed) - 1.0;
152 v2 = 2.0 * ran2<T> (&seed) - 1.0;
154 }
while (rsq >= 1.0 || rsq == 0.0);
155 fac = sqrt(-2.0 * log (rsq) / rsq);
169 template<
class T>
void Vmul(
int n,
const T *x,
const int incx,
const T *y,
170 const int incy, T*z,
const int incz)
173 if (incx == 1 && incy == 1 && incz == 1)
199 template<
class T>
void Smul(
int n,
const T alpha,
const T *x,
const int incx,
200 T *y,
const int incy)
203 if (incx == 1 && incy == 1)
227 template<
class T>
void Vdiv(
int n,
const T *x,
const int incx,
const T *y,
228 const int incy, T*z,
const int incz)
231 if (incx == 1 && incy == 1)
257 template<
class T>
void Sdiv(
int n,
const T alpha,
const T *x,
258 const int incx, T *y,
const int incy)
261 if (incx == 1 && incy == 1)
285 template<
class T>
void Vadd(
int n,
const T *x,
const int incx,
const T *y,
286 const int incy, T *z,
const int incz)
301 template<
class T>
void Sadd(
int n,
const T alpha,
const T *x,
302 const int incx, T *y,
const int incy)
305 if (incx == 1 && incy == 1)
329 template<
class T>
void Vsub(
int n,
const T *x,
const int incx,
const T *y,
330 const int incy, T *z,
const int incz)
333 if (incx == 1 && incy == 1 && incz == 1)
359 template<
class T>
void Zero(
int n, T *x,
const int incx)
363 std::memset(x,
'\0', n*
sizeof(T));
382 template<
class T>
void Neg(
int n, T *x,
const int incx)
394 template<
class T>
void Vsqrt(
int n,
const T *x,
const int incx,
395 T *y,
const int incy)
410 template<
class T>
void Vabs(
int n,
const T *x,
const int incx,
411 T *y,
const int incy)
415 *y = ( *x >0)? *x:-(*x);
429 const T *w,
const int incw,
430 const T *x,
const int incx,
431 const T *y,
const int incy,
432 T *z,
const int incz)
436 *z = (*w) * (*x) + (*y);
451 template<
class T>
void Vvtvm(
int n,
const T *w,
const int incw,
const T *x,
452 const int incx,
const T *y,
const int incy,
453 T *z,
const int incz)
457 *z = (*w) * (*x) - (*y);
472 const int incx,
const T *y,
const int incy,
473 T *z,
const int incz)
476 if (incx == 1 && incy == 1 && incz == 1)
480 *z = alpha * (*x) + (*y);
490 *z = alpha * (*x) + (*y);
504 template<
class T>
void Svtvm(
int n,
const T alpha,
const T *x,
505 const int incx,
const T *y,
const int incy,
506 T *z,
const int incz)
510 *z = alpha * (*x) - (*y);
524 const T* v,
int incv,
525 const T* w,
int incw,
526 const T* x,
int incx,
527 const T* y,
int incy,
532 *z = (*v) * (*w) + (*x) * (*y);
551 const T* v,
int incv,
552 const T* w,
int incw,
553 const T* x,
int incx,
554 const T* y,
int incy,
559 *z = (*v) * (*w) - (*x) * (*y);
579 const T* x,
int incx,
581 const T* y,
int incy,
586 *z = alpha * (*x) + beta * (*y);
605 const T* v,
int incv,
606 const T* w,
int incw,
607 const T* x,
int incx,
612 *z = alpha * (*v) + (*w) + (*x);
630 template<
class T>
void Gathr(
int n,
const T *x,
const int *y,
645 template<
class T>
void Gathr(
int n,
const T *
sign,
const T *x,
const int *y,
650 *z++ = *(sign++) * (*(x + *y++));
659 template<
class T>
void Scatr(
int n,
const T *x,
const int *y,
664 *(z + *(y++)) = *(x++);
672 template<
class T>
void Scatr(
int n,
const T *
sign,
const T *x,
const int *y,
679 *(z + *(y++)) = *(sign++) * (*(x++));
695 template<
class T>
void Assmb(
int n,
const T *x,
const int *y,
700 *(z + *(y++)) += *(x++);
708 template<
class T>
void Assmb(
int n,
const T *
sign,
const T *x,
const int *y,
713 *(z + *(y++)) += *(sign++) * (*(x++));
723 template<
class T> T
Vsum(
int n,
const T *x,
const int incx)
741 template<
class T>
int Imax(
int n,
const T *x,
const int incx)
744 int i, indx = ( n > 0 ) ? 0 : -1;
747 for (i = 0; i < n; i++)
765 template<
class T> T
Vmax(
int n,
const T *x,
const int incx)
786 template<
class T>
int Iamax(
int n,
const T *x,
const int incx)
789 int i, indx = ( n > 0 ) ? 0 : -1;
793 for (i = 0; i < n; i++)
795 xm = (*x > 0)? *x: -*x;
811 template<
class T> T
Vamax(
int n,
const T *x,
const int incx)
819 xm = (*x > 0)? *x: -*x;
833 template<
class T>
int Imin(
int n,
const T *x,
const int incx)
836 int i, indx = ( n > 0 ) ? 0 : -1;
857 template<
class T> T
Vmin(
int n,
const T *x,
const int incx)
878 template<
class T>
int Nnan(
int n,
const T *x,
const int incx)
900 template<
class T> T
Dot(
int n,
920 template<
class T> T
Dot(
int n,
921 const T *w,
const int incw,
922 const T *x,
const int incx)
940 template<
class T> T
Dot2(
int n,
949 sum += (*y == 1 ? (*w) * (*x) : 0 );
964 template<
class T> T
Dot2(
int n,
965 const T *w,
const int incw,
966 const T *x,
const int incx,
967 const int *y,
const int incy)
973 sum += (*y == 1 ? (*w) * (*x) : 0.0 );
984 const int *y,
const int incy);
1046 template<
typename T>
1047 void Vcopy(
int n,
const T *x,
const int incx,
1048 T *y,
const int incy)
1050 if( incx ==1 && incy == 1)
1052 memcpy(y,x,n*
sizeof(T));
1066 template LIB_UTILITIES_EXPORT void Vcopy(
int n,
const unsigned int *x,
const int incx,
unsigned int *y,
const int incy);
1071 template<
class T>
void Reverse(
int n,
const T *x,
const int incx, T *y,
const int incy)
1078 y[nloop] = x[nloop];
1080 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.