Go to the documentation of this file.00001 #ifndef VIENNACL_LINALG_DETAIL_SPAI_SPAI_STATIC_HPP
00002 #define VIENNACL_LINALG_DETAIL_SPAI_SPAI_STATIC_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #include <utility>
00027 #include <iostream>
00028 #include <fstream>
00029 #include <string>
00030 #include <algorithm>
00031 #include <vector>
00032 #include <math.h>
00033 #include <map>
00034
00035 #include "boost/numeric/ublas/vector.hpp"
00036 #include "boost/numeric/ublas/matrix.hpp"
00037 #include "boost/numeric/ublas/matrix_proxy.hpp"
00038 #include "boost/numeric/ublas/vector_proxy.hpp"
00039 #include "boost/numeric/ublas/storage.hpp"
00040 #include "boost/numeric/ublas/io.hpp"
00041 #include "boost/numeric/ublas/lu.hpp"
00042 #include "boost/numeric/ublas/triangular.hpp"
00043 #include "boost/numeric/ublas/matrix_expression.hpp"
00044
00045 #include "viennacl/linalg/prod.hpp"
00046 #include "viennacl/matrix.hpp"
00047 #include "viennacl/compressed_matrix.hpp"
00048 #include "viennacl/linalg/compressed_matrix_operations.hpp"
00049 #include "viennacl/linalg/matrix_operations.hpp"
00050 #include "viennacl/scalar.hpp"
00051 #include "viennacl/linalg/cg.hpp"
00052 #include "viennacl/linalg/inner_prod.hpp"
00053 #include "viennacl/linalg/ilu.hpp"
00054
00055
00056
00057 namespace viennacl
00058 {
00059 namespace linalg
00060 {
00061 namespace detail
00062 {
00063 namespace spai
00064 {
00065
00066
00067
00073 template <typename VectorType, typename SparseVectorType>
00074 void fanOutVector(const VectorType& m_in, const std::vector<unsigned int>& J, SparseVectorType& m){
00075 unsigned int cnt = 0;
00076 for (size_t i = 0; i < J.size(); ++i) {
00077 m[J[i]] = m_in(cnt++);
00078 }
00079 }
00085 template <typename MatrixType, typename VectorType>
00086 void backwardSolve(const MatrixType& R, const VectorType& y, VectorType& x){
00087 typedef typename MatrixType::value_type ScalarType;
00088 for (long i = R.size2()-1; i >= 0 ; i--) {
00089 x(i) = y(i);
00090 for (size_t j = i+1; j < R.size2(); ++j) {
00091 x(i) -= R(i,j)*x(j);
00092 }
00093 x(i) /= R(i,i);
00094 }
00095 }
00101 template <typename VectorType, typename ScalarType>
00102 void projectI(const std::vector<unsigned int>& I, VectorType& y, unsigned int ind){
00103 for(size_t i = 0; i < I.size(); ++i){
00104
00105 if(I[i] == ind){
00106 y(i) = static_cast<ScalarType>(1.0);
00107 }
00108 else{
00109 y(i) = static_cast<ScalarType>(0.0);
00110 }
00111 }
00112 }
00113
00118 template <typename SparseVectorType>
00119 void buildColumnIndexSet(const SparseVectorType& v, std::vector<unsigned int>& J){
00120
00121 unsigned int tmp_v;
00122 for(typename SparseVectorType::const_iterator vec_it = v.begin(); vec_it != v.end(); ++vec_it){
00123 tmp_v = vec_it->first;
00124 J.push_back(vec_it->first);
00125 }
00126 std::sort(J.begin(), J.end());
00127 }
00128
00133 template <typename SparseMatrixType>
00134 void initPreconditioner(const SparseMatrixType& A, SparseMatrixType& M){
00135 typedef typename SparseMatrixType::value_type ScalarType;
00136 M.resize(A.size1(), A.size2(), false);
00137 for(typename SparseMatrixType::const_iterator1 row_it = A.begin1(); row_it!= A.end1(); ++row_it){
00138
00139 for(typename SparseMatrixType::const_iterator2 col_it = row_it.begin(); col_it != row_it.end(); ++col_it){
00140 M(col_it.index1(),col_it.index2()) = static_cast<ScalarType>(1);
00141 }
00142 }
00143 }
00144
00150 template <typename SparseVectorType>
00151 void projectRows(const std::vector<SparseVectorType>& A_v_c, const std::vector<unsigned int>& J, std::vector<unsigned int>& I){
00152 for(size_t i = 0; i < J.size(); ++i){
00153 for(typename SparseVectorType::const_iterator col_it = A_v_c[J[i]].begin(); col_it!=A_v_c[J[i]].end(); ++col_it){
00154 if(!isInIndexSet(I, col_it->first)){
00155 I.push_back(col_it->first);
00156 }
00157 }
00158 }
00159 std::sort(I.begin(), I.end());
00160 }
00161 }
00162 }
00163 }
00164 }
00165
00166 #endif