⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bls2.c

📁 svd 算法代码 This directory contains instrumented SVDPACKC Version 1.0 (ANSI-C) programs for compiling
💻 C
📖 第 1 页 / 共 5 页
字号:
 **************************************************************/void opb(long nrow, long ncol, double *x, double *y){   long i, j, end;      mxvcount += 1;   mtxvcount += 1;   for (i = 0; i < ncol; i++) y[i] = ZERO;   for (i = 0; i < nrow; i++) ztemp[i] = ZERO;   for (i = 0; i < ncol; i++) {      end = pointr[i+1];      for (j = pointr[i]; j < end; j++) 	 ztemp[rowind[j]] += value[j] * (*x);       x++;   }   for (i = 0; i < ncol; i++) {      end = pointr[i+1];      for (j = pointr[i]; j < end; j++) 	 *y += value[j] * ztemp[rowind[j]];      y++;   }   return;}extern long mxvcount, mtxvcount;extern long *pointr, *rowind;extern double *value, **ztempp;#define       ZERO    0.0/************************************************************** *                                                            * * multiplication of A'A by the transpose of an nc by n       * * matrix X.  A is nrow by ncol and is stored using the       * * Harwell-Boeing compressed column sparse matrix format.     * * The transpose of the n by nc product matrix Y is returned  * * in the two-dimensional array y.                            * *                                                            * *              Y = A'A * X'  and  y := Y'                    * *                                                            * **************************************************************/void opm(long nrow, long ncol, long nc, double **x, double **y){   long i, j, k, end;      mxvcount  += nc;   mtxvcount += nc;   for (i = 0; i < nc; i++)       for (j = 0; j < nrow; j++) ztempp[i][j] = ZERO;   for (i = 0; i < nc; i++)       for (j = 0; j < ncol; j++) y[i][j] = ZERO;   /* multiply by sparse matrix A */   for (i = 0; i < ncol; i++) {      end = pointr[i+1];      for (j = pointr[i]; j < end; j++)         for (k = 0; k < nc; k++)	    ztempp[k][rowind[j]] += value[j] * x[k][i];    }   /* multiply by transpose of A (A') */   for (k = 0; k < nc; k++)      for (i = 0; i < ncol; i++) {         end = pointr[i+1];         for (j = pointr[i]; j < end; j++) 	    y[k][i] += value[j] * ztempp[k][rowind[j]];      }   return;}#define       ZERO    0.0extern long mxvcount;extern long *pointr, *rowind;extern double *value;/************************************************************** *                                                            * * multiplication of matrix A by vector x, where A is m by n  * * (m >> n) and is stored using the Harwell-Boeing compressed * * column sparse matrix format.  y stores product vector.     * *                                                            * **************************************************************/void opa(long m, long n, double *x, double *y){   long end,i,j;      mxvcount += 1;   for (i = 0; i < m; i++) y[i] = ZERO;   for (i = 0; i < n; i++) {      end = pointr[i+1];      for (j = pointr[i]; j < end; j++)	 y[rowind[j]] += value[j] * x[i];    }   return;}double fsign(double a,double b)/**************************************************************  * returns |a| if b is positive; else fsign returns -|a|      * **************************************************************/ {   if ((a>=0.0 && b>=0.0) || (a<0.0 && b<0.0))return(a);   if  ((a<0.0 && b>=0.0) || (a>=0.0 && b<0.0))return(-a);}double dmax(double a, double b)/**************************************************************  * returns the larger of two double precision numbers         * **************************************************************/ {   if (a > b) return(a);   else return(b);}double dmin(double a, double b)/**************************************************************  * returns the smaller of two double precision numbers        * **************************************************************/ {   if (a < b) return(a);   else return(b);}long imin(long a, long b)/**************************************************************  * returns the smaller of two integers                        * **************************************************************/ {   if (a < b) return(a);   else return(b);}long imax(long a,long b)/**************************************************************  * returns the larger of two integers                         * **************************************************************/ {   if (a > b) return(a);   else return(b);}#include <math.h>#include <stdio.h>#define		TRUE	 1#define		FALSE  	 0#define		TRANSP   1#define		NTRANSP  0#define		ZERO	 0.0#define		ONE	 1.0#define		CONST    100.0void   dgemv(long, long, long, double, double **, double *, double, double *);double ddot(long, double *,long, double *, long);void   dscal(long, double, double *,long);void   daxpy(long, double, double *,long, double *, long);void   dcopy(long, double *, long, double *, long);/*********************************************************************** *                                                                     * *                        orthg()                                      * *         Gram-Schmidt orthogonalization procedure                    * *                                                                     * ***********************************************************************//***********************************************************************   Description   -----------   The p by n matrix Z stored row-wise in rows f to (f+p-1) of   array X is reorthogonalized w.r.t. the first f rows of array X.   The resulting matrix Z is then factored longo the product of a   p by n orthonormal matrix (stored over matrix Z) and a p by p   upper-triangular matrix (stored in the first p rows and columns    of array B).  (Based on orthog from Rutishauser)    Parameters   ----------   (input)   p           number of consecutive vectors of array x (stored row-wise)	       to be orthogonalized   f           number of rows against which the next p rows are to be	       orthogonalized   n           column dimension of x   x           2-dimensional array whose p rows are to be orthogonalized	       against its first f rows   temp        work array   (output)   x           output matrix whose f+p rows are orthonormalized   b           p by p upper-triangular matrix   Functions called   --------------   BLAS         dgemv, ddot, dscal, daxpy, dcopy ***********************************************************************/void orthg(long p, long f, long n, double **b, double **x, double *temp){   long fp, k, km1;   long orig, small;   double t, s;   if (!p) return;   if (f == 0 && p > n) {      fprintf(stderr,"%s\n",         "*** ON ENTRY TO ORTHG, MATRIX TO BE ORTHONORMALIZED IS SINGULAR");      exit(-1);   }   fp = f + p;   for (k = f; k < fp; k++) {      km1 = k - 1;      orig = TRUE;      while(TRUE) {         t = ZERO;	 if (km1 >= 0) {	    if (km1 > 0) {	       dgemv(NTRANSP, k, n, ONE, x, x[k], ZERO, temp);	       t += ddot(k, temp, 1, temp, 1);	    }	    else {	       temp[0] = ddot(n, x[0], 1, x[k], 1);	       t += temp[0] * temp[0];	    }	    if (orig && km1 >= f)                dcopy(k - f, &temp[f], 1, &b[k - f][0], 1);             if (km1 > 0) 	       dgemv(TRANSP, k, n, -ONE, x, temp, ONE, &x[k][0]);            else	       daxpy(n, -temp[0], x[0], 1, x[k], 1);         }	 if (km1 < 0 || p != 1) {	    s = ddot(n, x[k], 1, x[k], 1);	    t += s;	    if (s > t/CONST) {	       small = FALSE;	       s = sqrt(s);               b[k - f][k - f] = s;	       if (s != ZERO) s = ONE/s;	       dscal(n, s, x[k], 1);	    }	    else {	       small = TRUE;	       orig  = FALSE;	    }	 }	 if (small == FALSE || p == 1) break;      }   }}#include <stdio.h>#define		TRANSP   1#define		NTRANSP  0#define		ZERO	 0.0#define		ONE	 1.0/*********************************************************************** *                                                                     * *                         dgemv()                                     * * A C-translation of the level 2 BLAS routine DGEMV by Dongarra,      * * du Croz, and Hammarling, and Hanson (see LAPACK Users' Guide).      * *                                                                     * ***********************************************************************//***********************************************************************   Description   -----------   dgemv() performs one of the matrix-vector operations   y := alpha * A * x + beta * y  or  y := alpha * A' * x + beta * y   where alpha and beta are scalars, X, Y are vectors and A is an   m by n matrix.void dgemv(long transa, long m, long n,            double alpha, double **a, double *x, double beta, double *y)   Parameters   ----------   (input)   transa   TRANSP indicates op(A) = A' is to be used in the multiplication	    NTRANSP indicates op(A) = A is to be used in the multiplication   m        on entry, m specifies the number of rows of the matrix A.	    m must be at least zero.  Unchanged upon exit.   n        on entry, n specifies the number of columns of the matrix A.	    n must be at least zero.  Unchanged upon exit.   alpha    a scalar multiplier.  Unchanged upon exit.   a        matrix A as a 2-dimensional array.  Before entry, the leading	    m by n part of the array a must contain the matrix A.   x        linear array of dimension of at least n if transa = NTRANSP	    and at least m otherwise.   beta     a scalar multiplier.  When beta is supplied as zero then y	    need not be set on input.  Unchanged upon exit.   y        linear array of dimension of at least m if transa = NTRANSP	    and at leat n otherwise.  Before entry with beta nonzero,	    the array y must contain the vector y.  On exit, y is 	    overwritten by the updated vector y. ***********************************************************************/void dgemv(long transa, long m, long n,            double alpha, double **a, double *x, double beta, double *y){   long info, leny, i, j;   double temp, *ptrtemp;   info = 0;   if      ( transa != TRANSP && transa != NTRANSP ) info = 1;   else if ( m < 0 ) 				     info = 2;   else if ( n < 0 )				     info = 3;   if (info) {      fprintf(stderr, "%s %1d %s\n",      "*** ON ENTRY TO DGEMV, PARAMETER NUMBER",info,"HAD AN ILLEGAL VALUE");      exit(info);   }   if (transa) leny = n;   else        leny = m;   if (!m || !n || (alpha == ZERO && beta == ONE))      return;   ptrtemp = y;    /* form Y := beta * Y */   if (beta == ZERO)       for (i = 0; i < leny; i++) *ptrtemp++ = ZERO;   else if (beta != ONE)       for (i = 0; i < leny; i++) *ptrtemp++ *= beta;   if (alpha == ZERO) return;   switch(transa) {      /* form Y := alpha * A * X + Y */      case NTRANSP:  for(i = 0; i < m; i++) {                        ptrtemp = *a++;		        temp = ZERO;		        for(j = 0; j < n; j++) 			   temp += *ptrtemp++ * x[j];			y[i] += alpha * temp;		     }		     break;		           /* form Y := alpha * A' * X + Y */      case TRANSP:   for(i = 0; i < m; i++) {                         ptrtemp = *a++;			if (x[i] != ZERO) {			   temp = alpha * x[i];			   for(j = 0; j < n; j++)			      y[j] += temp * (*ptrtemp++);			}		     }		     break;   }}#include <stdio.h>#define		TRANSP   1#define		NTRANSP  0#define		ZERO	 0.0#define		ONE	 1.0/*********************************************************************** *                                                                     * *                         dgemm2()                                    * *                                                                     * * A C-translation of the level 3 BLAS routine DGEMM by Dongarra,      * * Duff, du Croz, and Hammarling (see LAPACK Users' Guide).            * * In this version, the arrays which store the matrices used in this   * * matrix-matrix multiplication are accessed as two-dimensional arrays.* *                                                                     * ***********************************************************************//***********************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -