42 #ifndef STOKHOS_LANCZOS_HPP
43 #define STOKHOS_LANCZOS_HPP
52 template <
typename ord_type,
typename val_type>
73 val +=
w[
j]*u[
j]*v[
j];
81 v[
j] = a*u1[
j] + b*u2[
j];
89 v[
j] = a*u1[
j] + b*u2[
j] +c*u3[
j];
120 template <
typename vectorspace_type,
typename operator_type>
131 const vectorspace_type& vs,
132 const operator_type&
A,
153 nrm_sqrd[i] = vs.inner_product(u1, u1);
159 nrm = vs.inner_product(u1, v);
162 alpha[i] = nrm / nrm_sqrd[i];
166 beta[i] = nrm_sqrd[i] / nrm_sqrd[i-1];
174 vs.add3(
value_type(1), v, -alpha[i], u1, -beta[i], u0, u2);
182 "Stokhos::LanczosProjPCEBasis::lanczos(): "
183 <<
" Polynomial " << i <<
" out of " << k
184 <<
" has norm " << nrm_sqrd[i] <<
"!");
195 const vectorspace_type& vs,
196 const operator_type&
A,
215 beta[i] =
std::sqrt(vs.inner_product(u1, u1));
216 u1.
scale(1.0/beta[i]);
223 alpha[i] = vs.inner_product(u1, v);
231 vs.add3(
value_type(1), v, -alpha[i], u1, -beta[i], u0, u2);
239 "Stokhos::LanczosProjPCEBasis::lanczos(): "
240 <<
" Polynomial " << i <<
" out of " << k
241 <<
" has norm " << nrm_sqrd[i] <<
"!");
257 nrm = vs.inner_product(u0, u0);
258 dp = vs.inner_product(u2, u0);
266 #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)