-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsvdutil.h
158 lines (128 loc) · 7.37 KB
/
svdutil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
Copyright © 2002, University of Tennessee Research Foundation.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the University of Tennessee nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SVDUTIL_H
#define SVDUTIL_H
#include "svdlib.h"
#define SAFE_FREE(a) {if (a) {free(a); a = NULL;}}
/* Allocates an array of longs. */
extern long *svd_longArray(long size, char empty, char *name);
/* Allocates an array of doubles. */
extern double *svd_doubleArray(long size, char empty, char *name);
extern void svd_debug(char *fmt, ...);
extern void svd_error(char *fmt, ...);
extern void svd_fatalError(char *fmt, ...);
extern FILE *svd_fatalReadFile(char *filename);
extern FILE *svd_readFile(char *fileName);
extern FILE *svd_writeFile(char *fileName, char append);
extern void svd_closeFile(FILE *file);
extern char svd_readBinInt(FILE *file, int *val);
extern char svd_readBinFloat(FILE *file, float *val);
extern char svd_writeBinInt(FILE *file, int x);
extern char svd_writeBinFloat(FILE *file, float r);
/**************************************************************
* returns |a| if b is positive; else fsign returns -|a| *
**************************************************************/
extern double svd_fsign(double a, double b);
/**************************************************************
* returns the larger of two double precision numbers *
**************************************************************/
extern double svd_dmax(double a, double b);
/**************************************************************
* returns the smaller of two double precision numbers *
**************************************************************/
extern double svd_dmin(double a, double b);
/**************************************************************
* returns the larger of two integers *
**************************************************************/
extern long svd_imax(long a, long b);
/**************************************************************
* returns the smaller of two integers *
**************************************************************/
extern long svd_imin(long a, long b);
/**************************************************************
* Function scales a vector by a constant. *
* Based on Fortran-77 routine from Linpack by J. Dongarra *
**************************************************************/
extern void svd_dscal(long n, double da, double *dx, long incx);
/**************************************************************
* function scales a vector by a constant. *
* Based on Fortran-77 routine from Linpack by J. Dongarra *
**************************************************************/
extern void svd_datx(long n, double da, double *dx, long incx, double *dy, long incy);
/**************************************************************
* Function copies a vector x to a vector y *
* Based on Fortran-77 routine from Linpack by J. Dongarra *
**************************************************************/
extern void svd_dcopy(long n, double *dx, long incx, double *dy, long incy);
/**************************************************************
* Function forms the dot product of two vectors. *
* Based on Fortran-77 routine from Linpack by J. Dongarra *
**************************************************************/
extern double svd_ddot(long n, double *dx, long incx, double *dy, long incy);
/**************************************************************
* Constant times a vector plus a vector *
* Based on Fortran-77 routine from Linpack by J. Dongarra *
**************************************************************/
extern void svd_daxpy (long n, double da, double *dx, long incx, double *dy, long incy);
/*********************************************************************
* Function sorts array1 and array2 into increasing order for array1 *
*********************************************************************/
extern void svd_dsort2(long igap, long n, double *array1, double *array2);
/**************************************************************
* Function interchanges two vectors *
* Based on Fortran-77 routine from Linpack by J. Dongarra *
**************************************************************/
extern void svd_dswap(long n, double *dx, long incx, double *dy, long incy);
/*****************************************************************
* Function finds the index of element having max. absolute value*
* based on FORTRAN 77 routine from Linpack by J. Dongarra *
*****************************************************************/
extern long svd_idamax(long n, double *dx, long incx);
/**************************************************************
* multiplication of matrix B by vector x, where B = A'A, *
* and A is nrow by ncol (nrow >> ncol). Hence, B is of order *
* n = ncol (y stores product vector). *
**************************************************************/
extern void svd_opb(SMat A, double *x, double *y, double *temp);
/***********************************************************
* multiplication of matrix A by vector x, where A is *
* nrow by ncol (nrow >> ncol). y stores product vector. *
***********************************************************/
extern void svd_opa(SMat A, double *x, double *y);
/***********************************************************************
* *
* random2() *
* (double precision) *
***********************************************************************/
extern double svd_random2(long *iy);
/**************************************************************
* *
* Function finds sqrt(a^2 + b^2) without overflow or *
* destructive underflow. *
* *
**************************************************************/
extern double svd_pythag(double a, double b);
#endif /* SVDUTIL_H */