19 #include "../_c_basic_algebra/c_vector_operations.h"
116 template <
typename DataType>
122 const DataType lanczos_tol,
129 if (orthogonalize == 0 || orthogonalize == 1)
134 else if ((orthogonalize < 0) ||
135 (orthogonalize >
static_cast<FlagType>(m)))
143 buffer_size = orthogonalize;
149 DataType* V =
new DataType[n * buffer_size];
152 DataType* r =
new DataType[n];
166 for (j=0; j < m; ++j)
175 r, n, 1.0/initial_beta, &V[(j % buffer_size)*n]);
180 r, n, 1.0/beta[j-1], &V[(j % buffer_size)*n]);
184 A->
dot(&V[(j % buffer_size)*n], r);
188 &V[(j % buffer_size)*n], r, n);
192 &V[(j % buffer_size)*n], n, alpha[j], r);
198 &V[((j-1) % buffer_size)*n], n, beta[j-1], r);
202 if (orthogonalize != 0)
211 num_ortho = buffer_size;
216 &V[0], n, buffer_size, j%buffer_size, num_ortho, r);
225 if (beta[j] < lanczos_tol * sqrt(n))
249 const float lanczos_tol,
259 const double lanczos_tol,
266 const long double* v,
269 const long double lanczos_tol,
IndexType c_lanczos_tridiagonalization(cLinearOperator< DataType > *A, const DataType *v, const LongIndexType n, const IndexType m, const DataType lanczos_tol, const FlagType orthogonalize, DataType *alpha, DataType *beta)
Tri-diagonalizes matrix A to T using the start vector v. is the Lanczos degree, which will be the siz...
template IndexType c_lanczos_tridiagonalization< 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_lanczos_tridiagonalization< double >(cLinearOperator< double > *A, const double *v, const LongIndexType n, const IndexType m, const double lanczos_tol, const FlagType orthogonalize, double *alpha, double *beta)
template IndexType c_lanczos_tridiagonalization< float >(cLinearOperator< float > *A, const float *v, const LongIndexType n, const IndexType m, const float lanczos_tol, const FlagType orthogonalize, float *alpha, float *beta)
Base class for linear operators. This class serves as interface for all derived classes.
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 copy_vector(const DataType *input_vector, const LongIndexType vector_size, DataType *output_vector)
Copies a vector to a new vector. Result is written in-place.
static void copy_scaled_vector(const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Scales a vector and stores to a new vector.
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 inner_product(const DataType *vector1, const DataType *vector2, const LongIndexType vector_size)
Computes Euclidean inner product of two vectors.
static DataType euclidean_norm(const DataType *vector, const LongIndexType vector_size)
Computes the Euclidean norm of a 1D array.