#include <iostream>
#include <unsupported/Eigen/IterativeSolvers>
class MatrixReplacement;
template<>
struct traits<MatrixReplacement> : public Eigen::internal::traits<Eigen::SparseMatrix<double> >
{};
}
}
public:
typedef double Scalar;
typedef double RealScalar;
typedef int StorageIndex;
enum {
IsRowMajor = false
};
Index rows()
const {
return mp_mat->rows(); }
Index cols()
const {
return mp_mat->cols(); }
template<typename Rhs>
}
MatrixReplacement() : mp_mat(0) {}
void attachMyMatrix(
const SparseMatrix<double> &
mat) {
}
const SparseMatrix<double> my_matrix() const { return *mp_mat; }
private:
const SparseMatrix<double> *mp_mat;
};
template<typename Rhs>
struct generic_product_impl<MatrixReplacement, Rhs, SparseShape, DenseShape,
GemvProduct>
: generic_product_impl_base<MatrixReplacement,Rhs,generic_product_impl<MatrixReplacement,Rhs> >
{
typedef typename Product<MatrixReplacement,Rhs>::Scalar Scalar;
template<typename Dest>
static void scaleAndAddTo(Dest& dst, const MatrixReplacement& lhs, const Rhs& rhs, const Scalar& alpha)
{
eigen_assert(alpha==Scalar(1) &&
"scaling is not implemented");
dst += rhs(
i) * lhs.my_matrix().col(
i);
}
};
}
}
{
{
std::cout <<
"CG: #iterations: " << cg.
iterations() <<
", estimated error: " << cg.
error() << std::endl;
}
{
std::cout <<
"BiCGSTAB: #iterations: " << bicg.
iterations() <<
", estimated error: " << bicg.
error() << std::endl;
}
{
Eigen::GMRES<MatrixReplacement, Eigen::IdentityPreconditioner> gmres;
std::cout << "GMRES: #iterations: " << gmres.iterations() << ", estimated error: " << gmres.error() << std::endl;
}
{
Eigen::DGMRES<MatrixReplacement, Eigen::IdentityPreconditioner> gmres;
std::cout << "DGMRES: #iterations: " << gmres.iterations() << ", estimated error: " << gmres.error() << std::endl;
}
{
Eigen::MINRES<MatrixReplacement, Eigen::Lower|Eigen::Upper, Eigen::IdentityPreconditioner> minres;
std::cout << "MINRES: #iterations: " << minres.iterations() << ", estimated error: " << minres.error() << std::endl;
}
}
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
A bi conjugate gradient stabilized solver for sparse square problems.
A conjugate gradient solver for sparse (or dense) self-adjoint problems.
static const RandomReturnType Random()
Derived & compute(const EigenBase< MatrixDerived > &A)
Base class for all dense matrices, vectors, and expressions.
The matrix class, also used for vectors and row-vectors.
Expression of the product of two arbitrary matrices or vectors.
TransposeReturnType transpose()
A versatible sparse matrix representation.
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)