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,
677 *(z + *(y++)) = *(sign++) * (*(x++));
686 template<
class T>
void Assmb(
int n,
const T *x,
const int *y,
691 *(z + *(y++)) += *(x++);
699 template<
class T>
void Assmb(
int n,
const T *
sign,
const T *x,
const int *y,
704 *(z + *(y++)) += *(sign++) * (*(x++));
714 template<
class T> T
Vsum(
int n,
const T *x,
const int incx)
732 template<
class T>
int Imax(
int n,
const T *x,
const int incx)
735 int i, indx = ( n > 0 ) ? 0 : -1;
738 for (i = 0; i < n; i++)
756 template<
class T> T
Vmax(
int n,
const T *x,
const int incx)
777 template<
class T>
int Iamax(
int n,
const T *x,
const int incx)
780 int i, indx = ( n > 0 ) ? 0 : -1;
784 for (i = 0; i < n; i++)
786 xm = (*x > 0)? *x: -*x;
802 template<
class T> T
Vamax(
int n,
const T *x,
const int incx)
810 xm = (*x > 0)? *x: -*x;
824 template<
class T>
int Imin(
int n,
const T *x,
const int incx)
827 int i, indx = ( n > 0 ) ? 0 : -1;
848 template<
class T> T
Vmin(
int n,
const T *x,
const int incx)
869 template<
class T>
int Nnan(
int n,
const T *x,
const int incx)
891 template<
class T> T
Dot(
int n,
911 template<
class T> T
Dot(
int n,
912 const T *w,
const int incw,
913 const T *x,
const int incx)
931 template<
class T> T
Dot2(
int n,
940 sum += (*y == 1 ? (*w) * (*x) : 0 );
955 template<
class T> T
Dot2(
int n,
956 const T *w,
const int incw,
957 const T *x,
const int incx,
958 const int *y,
const int incy)
964 sum += (*y == 1 ? (*w) * (*x) : 0.0 );
975 const int *y,
const int incy);
1037 template<
typename T>
1038 void Vcopy(
int n,
const T *x,
const int incx,
1039 T *y,
const int incy)
1041 if( incx ==1 && incy == 1)
1043 memcpy(y,x,n*
sizeof(T));
1057 template LIB_UTILITIES_EXPORT void Vcopy(
int n,
const unsigned int *x,
const int incx,
unsigned int *y,
const int incy);
1062 template<
class T>
void Reverse(
int n,
const T *x,
const int incx, T *y,
const int incy)
1069 y[nloop] = x[nloop];
1071 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.