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;
137 template<
class T>
void FillWhiteNoise(
int n,
const T eps, T *x,
const int incx,
int outseed)
143 long seed = long(outseed);
148 v1 = 2.0 * ran2<T> (&seed) - 1.0;
149 v2 = 2.0 * ran2<T> (&seed) - 1.0;
151 }
while (rsq >= 1.0 || rsq == 0.0);
152 fac = sqrt(-2.0 * log (rsq) / rsq);
166 template<
class T>
void Vmul(
int n,
const T *x,
const int incx,
const T *y,
167 const int incy, T*z,
const int incz)
170 if (incx == 1 && incy == 1 && incz == 1)
196 template<
class T>
void Smul(
int n,
const T alpha,
const T *x,
const int incx,
197 T *y,
const int incy)
200 if (incx == 1 && incy == 1)
224 template<
class T>
void Vdiv(
int n,
const T *x,
const int incx,
const T *y,
225 const int incy, T*z,
const int incz)
228 if (incx == 1 && incy == 1)
254 template<
class T>
void Sdiv(
int n,
const T alpha,
const T *x,
255 const int incx, T *y,
const int incy)
258 if (incx == 1 && incy == 1)
282 template<
class T>
void Vadd(
int n,
const T *x,
const int incx,
const T *y,
283 const int incy, T *z,
const int incz)
298 template<
class T>
void Sadd(
int n,
const T alpha,
const T *x,
299 const int incx, T *y,
const int incy)
302 if (incx == 1 && incy == 1)
326 template<
class T>
void Vsub(
int n,
const T *x,
const int incx,
const T *y,
327 const int incy, T *z,
const int incz)
330 if (incx == 1 && incy == 1 && incz == 1)
356 template<
class T>
void Zero(
int n, T *x,
const int incx)
360 std::memset(x,
'\0', n*
sizeof(T));
379 template<
class T>
void Neg(
int n, T *x,
const int incx)
391 template<
class T>
void Vsqrt(
int n,
const T *x,
const int incx,
392 T *y,
const int incy)
407 template<
class T>
void Vabs(
int n,
const T *x,
const int incx,
408 T *y,
const int incy)
412 *y = ( *x >0)? *x:-(*x);
426 const T *w,
const int incw,
427 const T *x,
const int incx,
428 const T *y,
const int incy,
429 T *z,
const int incz)
433 *z = (*w) * (*x) + (*y);
448 template<
class T>
void Vvtvm(
int n,
const T *w,
const int incw,
const T *x,
449 const int incx,
const T *y,
const int incy,
450 T *z,
const int incz)
454 *z = (*w) * (*x) - (*y);
469 const int incx,
const T *y,
const int incy,
470 T *z,
const int incz)
473 if (incx == 1 && incy == 1 && incz == 1)
477 *z = alpha * (*x) + (*y);
487 *z = alpha * (*x) + (*y);
501 template<
class T>
void Svtvm(
int n,
const T alpha,
const T *x,
502 const int incx,
const T *y,
const int incy,
503 T *z,
const int incz)
507 *z = alpha * (*x) - (*y);
521 const T* v,
int incv,
522 const T* w,
int incw,
523 const T* x,
int incx,
524 const T* y,
int incy,
529 *z = (*v) * (*w) + (*x) * (*y);
548 const T* v,
int incv,
549 const T* w,
int incw,
550 const T* x,
int incx,
551 const T* y,
int incy,
556 *z = (*v) * (*w) - (*x) * (*y);
576 const T* x,
int incx,
578 const T* y,
int incy,
583 *z = alpha * (*x) + beta * (*y);
602 const T* v,
int incv,
603 const T* w,
int incw,
604 const T* x,
int incx,
609 *z = alpha * (*v) + (*w) + (*x);
627 template<
class T>
void Gathr(
int n,
const T *x,
const int *y,
642 template<
class T>
void Gathr(
int n,
const T *
sign,
const T *x,
const int *y,
647 *z++ = *(sign++) * (*(x + *y++));
656 template<
class T>
void Scatr(
int n,
const T *x,
const int *y,
661 *(z + *(y++)) = *(x++);
669 template<
class T>
void Scatr(
int n,
const T *
sign,
const T *x,
const int *y,
674 *(z + *(y++)) = *(sign++) * (*(x++));
683 template<
class T>
void Assmb(
int n,
const T *x,
const int *y,
688 *(z + *(y++)) += *(x++);
696 template<
class T>
void Assmb(
int n,
const T *
sign,
const T *x,
const int *y,
701 *(z + *(y++)) += *(sign++) * (*(x++));
711 template<
class T> T
Vsum(
int n,
const T *x,
const int incx)
729 template<
class T>
int Imax(
int n,
const T *x,
const int incx)
732 int i, indx = ( n > 0 ) ? 0 : -1;
735 for (i = 0; i < n; i++)
753 template<
class T> T
Vmax(
int n,
const T *x,
const int incx)
774 template<
class T>
int Iamax(
int n,
const T *x,
const int incx)
777 int i, indx = ( n > 0 ) ? 0 : -1;
781 for (i = 0; i < n; i++)
783 xm = (*x > 0)? *x: -*x;
799 template<
class T> T
Vamax(
int n,
const T *x,
const int incx)
807 xm = (*x > 0)? *x: -*x;
821 template<
class T>
int Imin(
int n,
const T *x,
const int incx)
824 int i, indx = ( n > 0 ) ? 0 : -1;
844 template<
class T> T
Vmin(
int n,
const T *x,
const int incx)
865 template<
class T> T
Dot(
int n,
885 template<
class T> T
Dot(
int n,
886 const T *w,
const int incw,
887 const T *x,
const int incx)
905 template<
class T> T
Dot2(
int n,
914 sum += (*y == 1 ? (*w) * (*x) : 0 );
929 template<
class T> T
Dot2(
int n,
930 const T *w,
const int incw,
931 const T *x,
const int incx,
932 const int *y,
const int incy)
938 sum += (*y == 1 ? (*w) * (*x) : 0.0 );
949 const int *y,
const int incy);
1011 template<
typename T>
1012 void Vcopy(
int n,
const T *x,
const int incx,
1013 T *y,
const int incy)
1015 if( incx ==1 && incy == 1)
1017 memcpy(y,x,n*
sizeof(T));
1031 template LIB_UTILITIES_EXPORT void Vcopy(
int n,
const unsigned int *x,
const int incx,
unsigned int *y,
const int incy);
1036 template<
class T>
void Reverse(
int n,
const T *x,
const int incx, T *y,
const int incy)
1043 y[nloop] = x[nloop];
1045 for(i = 0; i < nloop; ++i)