svdutil.h

Go to the documentation of this file.
00001 #ifndef SVDUTIL_H
00002 #define SVDUTIL_H
00003 
00004 #include "svdlib.h"
00005 
00006 #define SAFE_FREE(a) {if (a) {free(a); a = NULL;}}
00007 
00008 /* Allocates an array of longs. */
00009 extern long *svd_longArray(long size, char empty, char *name);
00010 /* Allocates an array of doubles. */
00011 extern double *svd_doubleArray(long size, char empty, char *name);
00012 
00013 extern void svd_debug(char *fmt, ...);
00014 extern void svd_error(char *fmt, ...);
00015 extern void svd_fatalError(char *fmt, ...);
00016 extern FILE *svd_fatalReadFile(char *filename);
00017 extern FILE *svd_readFile(char *fileName);
00018 extern FILE *svd_writeFile(char *fileName, char append);
00019 extern void svd_closeFile(FILE *file);
00020 
00021 extern char svd_readBinInt(FILE *file, int *val);
00022 extern char svd_readBinFloat(FILE *file, float *val);
00023 extern char svd_writeBinInt(FILE *file, int x);
00024 extern char svd_writeBinFloat(FILE *file, float r);
00025 
00026 /************************************************************** 
00027  * returns |a| if b is positive; else fsign returns -|a|      *
00028  **************************************************************/ 
00029 extern double svd_fsign(double a, double b);
00030 
00031 /************************************************************** 
00032  * returns the larger of two double precision numbers         *
00033  **************************************************************/ 
00034 extern double svd_dmax(double a, double b);
00035 
00036 /************************************************************** 
00037  * returns the smaller of two double precision numbers        *
00038  **************************************************************/ 
00039 extern double svd_dmin(double a, double b);
00040 
00041 /************************************************************** 
00042  * returns the larger of two integers                         *
00043  **************************************************************/ 
00044 extern long svd_imax(long a, long b);
00045 
00046 /************************************************************** 
00047  * returns the smaller of two integers                        *
00048  **************************************************************/ 
00049 extern long svd_imin(long a, long b);
00050 
00051 /************************************************************** 
00052  * Function scales a vector by a constant.                    *
00053  * Based on Fortran-77 routine from Linpack by J. Dongarra    *
00054  **************************************************************/ 
00055 extern void svd_dscal(long n, double da, double *dx, long incx);
00056 
00057 /************************************************************** 
00058  * function scales a vector by a constant.                    *
00059  * Based on Fortran-77 routine from Linpack by J. Dongarra    *
00060  **************************************************************/ 
00061 extern void svd_datx(long n, double da, double *dx, long incx, double *dy, long incy);
00062 
00063 /************************************************************** 
00064  * Function copies a vector x to a vector y                   *
00065  * Based on Fortran-77 routine from Linpack by J. Dongarra    *
00066  **************************************************************/ 
00067 extern void svd_dcopy(long n, double *dx, long incx, double *dy, long incy);
00068 
00069 /************************************************************** 
00070  * Function forms the dot product of two vectors.             *
00071  * Based on Fortran-77 routine from Linpack by J. Dongarra    *
00072  **************************************************************/ 
00073 extern double svd_ddot(long n, double *dx, long incx, double *dy, long incy);
00074 
00075 /************************************************************** 
00076  * Constant times a vector plus a vector                      *
00077  * Based on Fortran-77 routine from Linpack by J. Dongarra    *
00078  **************************************************************/ 
00079 extern void svd_daxpy (long n, double da, double *dx, long incx, double *dy, long incy);
00080 
00081 /********************************************************************* 
00082  * Function sorts array1 and array2 into increasing order for array1 *
00083  *********************************************************************/
00084 extern void svd_dsort2(long igap, long n, double *array1, double *array2);
00085 
00086 /************************************************************** 
00087  * Function interchanges two vectors                          *
00088  * Based on Fortran-77 routine from Linpack by J. Dongarra    *
00089  **************************************************************/ 
00090 extern void svd_dswap(long n, double *dx, long incx, double *dy, long incy);
00091 
00092 /***************************************************************** 
00093  * Function finds the index of element having max. absolute value*
00094  * based on FORTRAN 77 routine from Linpack by J. Dongarra       *
00095  *****************************************************************/ 
00096 extern long svd_idamax(long n, double *dx, long incx);
00097 
00098 /**************************************************************
00099  * multiplication of matrix B by vector x, where B = A'A,     *
00100  * and A is nrow by ncol (nrow >> ncol). Hence, B is of order *
00101  * n = ncol (y stores product vector).                        *
00102  **************************************************************/
00103 extern void svd_opb(SMat A, double *x, double *y, double *temp);
00104 
00105 /***********************************************************
00106  * multiplication of matrix A by vector x, where A is      *
00107  * nrow by ncol (nrow >> ncol).  y stores product vector.  *
00108  ***********************************************************/
00109 extern void svd_opa(SMat A, double *x, double *y);
00110 
00111 /***********************************************************************
00112  *                                                                     *
00113  *                              random2()                              *
00114  *                        (double precision)                           *
00115  ***********************************************************************/
00116 extern double svd_random2(long *iy);
00117 
00118 /************************************************************** 
00119  *                                                            *
00120  * Function finds sqrt(a^2 + b^2) without overflow or         *
00121  * destructive underflow.                                     *
00122  *                                                            *
00123  **************************************************************/ 
00124 extern double svd_pythag(double a, double b);
00125 
00126 
00127 #endif /* SVDUTIL_H */