1 #ifndef VIENNACL_LINALG_ROW_SCALING_HPP_
2 #define VIENNACL_LINALG_ROW_SCALING_HPP_
50 unsigned int norm()
const {
return norm_; }
61 struct row_scaling_for_viennacl
63 enum { value =
false };
66 template<
typename ScalarType,
unsigned int ALIGNMENT>
67 struct row_scaling_for_viennacl<
viennacl::compressed_matrix<ScalarType, ALIGNMENT> >
69 enum { value =
true };
72 template<
typename ScalarType,
unsigned int ALIGNMENT>
73 struct row_scaling_for_viennacl<
viennacl::coordinate_matrix<ScalarType, ALIGNMENT> >
75 enum { value =
true };
85 template<
typename MatrixType,
86 bool is_viennacl = detail::row_scaling_for_viennacl<MatrixType>::value >
89 typedef typename MatrixType::value_type ScalarType;
99 assert(mat.size1() == mat.size2() && bool(
"Size mismatch"));
105 diag_M.resize(mat.size1());
107 for (
typename MatrixType::const_iterator1 row_it = mat.begin1();
108 row_it != mat.end1();
111 for (
typename MatrixType::const_iterator2 col_it = row_it.begin();
112 col_it != row_it.end();
116 diag_M[col_it.index1()] = std::max<ScalarType>(diag_M[col_it.index1()], std::fabs(*col_it));
117 else if (tag.
norm() == 1)
118 diag_M[col_it.index1()] += std::fabs(*col_it);
119 else if (tag.
norm() == 2)
120 diag_M[col_it.index1()] += (*col_it) * (*col_it);
122 if (!diag_M[row_it.index1()])
126 diag_M[row_it.index1()] = std::sqrt(diag_M[row_it.index1()]);
132 template<
typename VectorType>
135 assert(vec.size() == diag_M.size() && bool(
"Size mismatch"));
141 std::vector<ScalarType> diag_M;
149 template<
typename MatrixType>
184 template<
unsigned int ALIGNMENT>
viennacl::vector_expression< const vector_base< T >, const vector_base< T >, op_element_binary< op_div > > element_div(vector_base< T > const &v1, vector_base< T > const &v2)
row_scaling(MatrixType const &mat, row_scaling_tag const &tag)
Constructor for the preconditioner.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
This file provides the forward declarations for the main types used within ViennaCL.
unsigned int norm() const
Returns the index p of the l^p-norm (0 ... ||x||_sup, 1... sum(abs(x)), 2... sqrt(sum(x_i^2))). Currently only p=0, p=1, and p=2 supported.
Jacobi-type preconditioner class, can be supplied to solve()-routines. This is a diagonal preconditio...
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
void init(MatrixType const &mat, row_scaling_tag const &tag)
Implementation of the compressed_matrix class.
A tag for a row scaling preconditioner which merely normalizes the equation system such that each row...
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
row_scaling(MatrixType const &mat, row_scaling_tag const &tag)
Constructor for the preconditioner.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void apply(VectorType &vec) const
Apply to res = b - Ax, i.e. row applied vec (right hand side),.
viennacl::enable_if< viennacl::is_any_sparse_matrix< SparseMatrixType >::value >::type row_info(SparseMatrixType const &mat, vector< SCALARTYPE, VEC_ALIGNMENT > &vec, row_info_types info_selector)
row_scaling_tag(unsigned int p=2)
Constructor.
void apply(viennacl::vector< ScalarType, ALIGNMENT > &vec) const
void init(MatrixType const &mat, row_scaling_tag const &tag)