10 #ifndef STOKHOS_LANCZOS_HPP
11 #define STOKHOS_LANCZOS_HPP
20 template <
typename ord_type,
typename val_type>
41 val +=
w[
j]*u[
j]*v[
j];
49 v[
j] = a*u1[
j] + b*u2[
j];
57 v[
j] = a*u1[
j] + b*u2[
j] +c*u3[
j];
88 template <
typename vectorspace_type,
typename operator_type>
99 const vectorspace_type& vs,
100 const operator_type&
A,
121 nrm_sqrd[i] = vs.inner_product(u1, u1);
127 nrm = vs.inner_product(u1, v);
130 alpha[i] = nrm / nrm_sqrd[i];
134 beta[i] = nrm_sqrd[i] / nrm_sqrd[i-1];
142 vs.add3(
value_type(1), v, -alpha[i], u1, -beta[i], u0, u2);
150 "Stokhos::LanczosProjPCEBasis::lanczos(): "
151 <<
" Polynomial " << i <<
" out of " << k
152 <<
" has norm " << nrm_sqrd[i] <<
"!");
163 const vectorspace_type& vs,
164 const operator_type&
A,
183 beta[i] =
std::sqrt(vs.inner_product(u1, u1));
184 u1.
scale(1.0/beta[i]);
191 alpha[i] = vs.inner_product(u1, v);
199 vs.add3(
value_type(1), v, -alpha[i], u1, -beta[i], u0, u2);
207 "Stokhos::LanczosProjPCEBasis::lanczos(): "
208 <<
" Polynomial " << i <<
" out of " << k
209 <<
" has norm " << nrm_sqrd[i] <<
"!");
225 nrm = vs.inner_product(u0, u0);
226 dp = vs.inner_product(u2, u0);
234 #endif // STOKHOS_LANCZOS_HPP
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
Teuchos::SerialDenseVector< ordinal_type, value_type > vector_type
operator_type::ordinal_type ordinal_type
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static void gramSchmidt(ordinal_type k, const vectorspace_type &vs, matrix_type &u, vector_type &u2)
Gram-Schmidt orthogonalization routine.
int scale(const ScalarType alpha)
static void compute(ordinal_type k, const vectorspace_type &vs, const operator_type &A, const vector_type &u_init, matrix_type &u, Teuchos::Array< value_type > &alpha, Teuchos::Array< value_type > &beta, Teuchos::Array< value_type > &nrm_sqrd)
Compute Lanczos basis.
value_type inner_product(const vector_type &u, const vector_type &v) const
Teuchos::SerialDenseVector< ordinal_type, value_type > vector_type
operator_type::value_type value_type
Teuchos::SerialDenseMatrix< ordinal_type, value_type > matrix_type
vector_type create_vector() const
Applies Lanczos procedure to a given matrix.
WeightedVectorSpace(const vector_type &weights)
void add2(const value_type &a, const vector_type &u1, const value_type &b, const vector_type &u2, vector_type &v) const
static void computeNormalized(ordinal_type k, const vectorspace_type &vs, const operator_type &A, const vector_type &u_init, matrix_type &u, Teuchos::Array< value_type > &alpha, Teuchos::Array< value_type > &beta, Teuchos::Array< value_type > &nrm_sqrd)
Compute Lanczos basis.
void add3(const value_type &a, const vector_type &u1, const value_type &b, const vector_type &u2, const value_type &c, const vector_type &u3, vector_type &v) const
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)