19 #include "../_c_basic_algebra/c_vector_operations.h"
110 template <
typename DataType>
116 const DataType lanczos_tol,
123 if (orthogonalize == 0)
128 else if ((orthogonalize < 0) ||
129 (orthogonalize >
static_cast<FlagType>(m) - 1))
138 buffer_size = orthogonalize + 1;
144 DataType* U =
new DataType[n * buffer_size];
145 DataType* V =
new DataType[n * buffer_size];
156 for (j=0; j < m; ++j)
162 A->
dot(&V[(j % buffer_size)*n], &U[(j % buffer_size)*n]);
168 &U[((j-1) % buffer_size)*n], n, beta[j-1],
169 &U[(j % buffer_size)*n]);
173 if (orthogonalize != 0)
182 num_ortho = buffer_size - 1;
189 &U[0], n, buffer_size, (j-1)%buffer_size, num_ortho,
190 &U[(j % buffer_size)*n]);
196 &U[(j % buffer_size)*n], n);
199 A->
transpose_dot(&U[(j % buffer_size)*n], &V[((j+1) % buffer_size)*n]);
203 &V[(j % buffer_size)*n], n, alpha[j],
204 &V[((j+1) % buffer_size)*n]);
207 if (orthogonalize != 0)
210 &V[0], n, buffer_size, j%buffer_size, num_ortho,
211 &V[((j+1) % buffer_size)*n]);
216 &V[((j+1) % buffer_size)*n], n);
221 if (beta[j] < lanczos_tol * sqrt(n))
245 const float lanczos_tol,
255 const double lanczos_tol,
262 const long double* v,
265 const long double lanczos_tol,
template IndexType c_golub_kahn_bidiagonalization< float >(cLinearOperator< float > *A, const float *v, const LongIndexType n, const IndexType m, const float lanczos_tol, const FlagType orthogonalize, float *alpha, float *beta)
IndexType c_golub_kahn_bidiagonalization(cLinearOperator< DataType > *A, const DataType *v, const LongIndexType n, const IndexType m, const DataType lanczos_tol, const FlagType orthogonalize, DataType *alpha, DataType *beta)
Bi-diagonalizes the positive-definite matrix A using Golub-Kahn-Lanczos method.
template IndexType c_golub_kahn_bidiagonalization< long double >(cLinearOperator< long double > *A, const long double *v, const LongIndexType n, const IndexType m, const long double lanczos_tol, const FlagType orthogonalize, long double *alpha, long double *beta)
template IndexType c_golub_kahn_bidiagonalization< double >(cLinearOperator< double > *A, const double *v, const LongIndexType n, const IndexType m, const double lanczos_tol, const FlagType orthogonalize, double *alpha, double *beta)
Base class for linear operators. This class serves as interface for all derived classes.
virtual void transpose_dot(const DataType *vector, DataType *product)=0
virtual void dot(const DataType *vector, DataType *product)=0
static void gram_schmidt_process(const DataType *V, const LongIndexType vector_size, const IndexType num_vectors, const IndexType last_vector, const FlagType num_ortho, DataType *r)
Modified Gram-Schmidt orthogonalization process to orthogonalize the vector v against a subset of the...
static void subtract_scaled_vector(const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Subtracts the scaled input vector from the output vector.
static DataType normalize_vector_in_place(DataType *vector, const LongIndexType vector_size)
Normalizes a vector based on Euclidean 2-norm. The result is written in-place.
static DataType normalize_vector_and_copy(const DataType *vector, const LongIndexType vector_size, DataType *output_vector)
Normalizes a vector based on Euclidean 2-norm. The result is written into another vector.