示例#1
0
void backwardSolve(MatrixT const & R, VectorT const & y, VectorT & x)
{
  for (long i2 = static_cast<long>(R.size2())-1; i2 >= 0; i2--)
  {
    vcl_size_t i = static_cast<vcl_size_t>(i2);
    x(i) = y(i);
    for (vcl_size_t j = static_cast<vcl_size_t>(i)+1; j < R.size2(); ++j)
      x(i) -= R(i,j)*x(j);

    x(i) /= R(i,i);
  }
}
 inline DCMatrix inv(const MatrixT &mat, double regularizationCoeff = 0.0) {
   BOOST_ASSERT(mat.size1() == mat.size2());
   unsigned int n = mat.size1();
   DCMatrix inv = mat; // copy data, as it will be modified below
   if (regularizationCoeff != 0.0)
     inv += regularizationCoeff * ublas::identity_matrix<double>(n);
   std::vector<int> ipiv(n); // pivot vector, is first filled by trf, then used by tri to inverse matrix
   lapack::getrf(inv,ipiv); // inv and ipiv will both be modified
   lapack::getri(inv,ipiv); // afterwards, "inv" is the inverse
   return inv;
 }
 inline DCMatrix invSym(const MatrixT &mat, double regularizationCoeff = 0.0) {
   BOOST_ASSERT(mat.size1() == mat.size2());
   unsigned int n = mat.size1();
   DCMatrix inv = mat; // copy data, as it will be modified below
   if (regularizationCoeff != 0.0)
     inv += regularizationCoeff * ublas::identity_matrix<double>(n);
   std::vector<int> ipiv(n); // pivot vector, is first filled by trf, then used by tri to inverse matrix
   // TODO (9): use "po..." (po=positive definite matrix) instead if "sy..." (symmetric indefinite matrix) to make it faster
   lapack::sytrf('U',inv,ipiv); // inv and ipiv will both be modified
   lapack::sytri('U',inv,ipiv); // afterwards, "inv" is the real inverse, but only the upper elements are valid!!!
   ublas::symmetric_adaptor<DCMatrix, ublas::upper> iSym(inv);
   return iSym; // copies upper matrix to lower
 }
示例#4
0
 ilut_precond(MatrixT const & mat, ilut_tag const & tag) : tag_(tag), LU_(mat.size1(), mat.size2())
 {
   //initialize preconditioner:
   //std::cout << "Start CPU precond" << std::endl;
   init(mat);
   //std::cout << "End CPU precond" << std::endl;
 }
示例#5
0
 ichol0_precond(MatrixT const & mat, ichol0_tag const & tag) : tag_(tag), LLT(mat.size1(), mat.size2(), viennacl::context(viennacl::MAIN_MEMORY))
 {
     //initialize preconditioner:
     //std::cout << "Start CPU precond" << std::endl;
     init(mat);
     //std::cout << "End CPU precond" << std::endl;
 }