~ubuntu-branches/ubuntu/feisty/ncbi-tools6/feisty

« back to all changes in this revision

Viewing changes to algo/blast/composition_adjustment/nlm_linear_algebra.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: nlm_linear_algebra.h,v 1.6 2005/12/01 13:54:04 gertz Exp $
 
1
/* $Id: nlm_linear_algebra.h,v 1.7 2005/12/19 15:38:01 gertz Exp $
2
2
 * ===========================================================================
3
3
 *
4
4
 *                            PUBLIC DOMAIN NOTICE
25
25
 
26
26
/**
27
27
 * @file nlm_linear_algebra.h
 
28
 * Declarations for several linear algebra routines
28
29
 *
29
30
 * @author E. Michael Gertz
30
 
 *
31
 
 * Declarations for several linear algebra routines
32
31
 */
33
32
 
34
33
#ifndef __NLM_LINEAR_ALGEBRA__
41
40
extern "C" {
42
41
#endif
43
42
 
 
43
/**
 
44
 * Create and return a new, dense matrix.  Elements of the matrix A
 
45
 * may be accessed as A[i][j]
 
46
 *
 
47
 * @param nrows     the number of rows for the new matrix.
 
48
 * @param ncols     the number of columns for the new matrix.
 
49
 */
44
50
NCBI_XBLAST_EXPORT
45
51
double ** Nlm_DenseMatrixNew(int nrows, int ncols);
46
52
 
 
53
 
 
54
/**
 
55
 * Create and return a new, dense, lower-triangular matrix.  Elements
 
56
 * of the matrix A may be accessed as A[i][j] for i <= j.
 
57
 *
 
58
 * @param n         the dimension of the matrix.
 
59
 */
47
60
NCBI_XBLAST_EXPORT
48
61
double ** Nlm_LtriangMatrixNew(int n);
49
62
 
 
63
 
 
64
/**
 
65
 * Free a matrix created by Nlm_DenseMatrixNew or
 
66
 * Nlm_LtriangMatrixNew.
 
67
 *
 
68
 * @param mat       the matrix to be freed
 
69
 * @return          always NULL
 
70
 */
50
71
NCBI_XBLAST_EXPORT
51
72
void Nlm_DenseMatrixFree(double *** mat);
52
73
 
 
74
 
 
75
/**
 
76
 * Create and return a new Int4 matrix.  Elements of the matrix A
 
77
 * may be accessed as A[i][j]
 
78
 *
 
79
 * @param nrows     the number of rows for the new matrix.
 
80
 * @param ncols     the number of columns for the new matrix.
 
81
 */
53
82
NCBI_XBLAST_EXPORT
54
83
Int4 ** Nlm_Int4MatrixNew(int nrows, int ncols);
55
84
 
 
85
 
 
86
/**
 
87
 * Free a matrix created by Nlm_DenseMatrixNew or
 
88
 * Nlm_LtriangMatrixNew.
 
89
 *
 
90
 * @param mat       the matrix to be freed
 
91
 * @return          always NULL
 
92
 */
56
93
NCBI_XBLAST_EXPORT
57
94
void Nlm_Int4MatrixFree(Int4 *** mat);
58
95
 
 
96
 
 
97
/**
 
98
 * Accessing only the lower triangular elements of the symmetric,
 
99
 * positive definite matrix A, compute a lower triangular matrix L
 
100
 * such that A = L L^T (Cholesky factorization.)  Overwrite the lower
 
101
 * triangle of A with L.
 
102
 *
 
103
 * This routine may be used with the Nlm_SolveLtriangPosDef routine to
 
104
 * solve systems of equations.
 
105
 *
 
106
 * @param A         the lower triangle of a symmetric, positive-definite
 
107
 *                  matrix
 
108
 * @param n         the size of A
 
109
 */
59
110
NCBI_XBLAST_EXPORT
60
111
void Nlm_FactorLtriangPosDef(double ** A, int n);
61
112
 
 
113
 
 
114
/**
 
115
 * Solve the linear system \f$ L L^T y = b \f$, where L is a non-singular
 
116
 * lower triangular matrix, usually computed using
 
117
 * the Nlm_FactorLtriangPosDef routine.
 
118
 *
 
119
 * @param x         on entry, the right hand size of the linear system
 
120
 *                  L L^T y = b; on exit the solution
 
121
 * @param n         the size of x
 
122
 * @param L         a non-singular lower triangular matrix
 
123
 */
62
124
NCBI_XBLAST_EXPORT
63
125
void Nlm_SolveLtriangPosDef(double x[], int n, double ** L);
64
126
 
 
127
 
 
128
/**
 
129
 * Compute the Euclidean norm (2-norm) of a vector.
 
130
 *
 
131
 * This routine is based on the (freely available) BLAS routine dnrm2,
 
132
 * which handles the scale of the elements of v in a stable fashion.
 
133
 *
 
134
 * @param v      a vector
 
135
 * @param n      the length of v
 
136
 */
65
137
NCBI_XBLAST_EXPORT
66
138
double Nlm_EuclideanNorm(const double v[], int n);
67
139
 
 
140
 
 
141
/**
 
142
 * Let y = y + alpha * x
 
143
 *
 
144
 * @param y         a vector
 
145
 * @param x         another vector
 
146
 * @param n         the length of x and y
 
147
 * @param alpha     a scale factor
 
148
 */
68
149
NCBI_XBLAST_EXPORT
69
150
void Nlm_AddVectors(double y[], int n, double alpha,
70
151
                    const double x[]);
71
152
 
 
153
 
 
154
/**
 
155
 * Given a nonnegative vector x and a nonnegative scalar max, returns
 
156
 * the largest value in [0, max] for which x + alpha * step_x >= 0.
 
157
 *
 
158
 * @param x         a vector with nonnegative elements
 
159
 * @param step_x    another vector
 
160
 * @param n         the size of x and step_x
 
161
 * @param max       a nonnegative scalar
 
162
 */
72
163
NCBI_XBLAST_EXPORT
73
164
double Nlm_StepBound(const double x[], int n,
74
165
                     const double step_x[], double max);