Class DenseGenMatProd

Synopsis

#include <include/Spectra/MatOp/DenseGenMatProd.h>

template <typename Scalar>
class DenseGenMatProd

Description

This class defines the matrix-vector multiplication operation on a general real matrix $A$, i.e., calculating $y=Ax$ for any vector $x$. It is mainly used in the GenEigsSolver and SymEigsSolver eigen solvers.

Methods

DenseGenMatProdConstructor to create the matrix operation object.
colsReturn the number of columns of the underlying matrix.
perform_opPerform the matrix-vector multiplication operation $y=Ax$.
rowsReturn the number of rows of the underlying matrix.

Source

Lines 29-76 in include/Spectra/MatOp/DenseGenMatProd.h.

template <typename Scalar>
class DenseGenMatProd
{
private:
    typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix;
    typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
    typedef Eigen::Map<const Vector> MapConstVec;
    typedef Eigen::Map<Vector> MapVec;
    typedef const Eigen::Ref<const Matrix> ConstGenericMatrix;

    ConstGenericMatrix m_mat;

public:
    ///
    /// Constructor to create the matrix operation object.
    ///
    /// \param mat An **Eigen** matrix object, whose type can be
    /// `Eigen::Matrix<Scalar, ...>` (e.g. `Eigen::MatrixXd` and
    /// `Eigen::MatrixXf`), or its mapped version
    /// (e.g. `Eigen::Map<Eigen::MatrixXd>`).
    ///
    DenseGenMatProd(ConstGenericMatrix& mat) :
        m_mat(mat)
    {}

    ///
    /// Return the number of rows of the underlying matrix.
    ///
    int rows() const { return m_mat.rows(); }
    ///
    /// Return the number of columns of the underlying matrix.
    ///
    int cols() const { return m_mat.cols(); }

    ///
    /// Perform the matrix-vector multiplication operation \f$y=Ax\f$.
    ///
    /// \param x_in  Pointer to the \f$x\f$ vector.
    /// \param y_out Pointer to the \f$y\f$ vector.
    ///
    // y_out = A * x_in
    void perform_op(const Scalar* x_in, Scalar* y_out) const
    {
        MapConstVec x(x_in,  m_mat.cols());
        MapVec      y(y_out, m_mat.rows());
        y.noalias() = m_mat * x;
    }
};





Add Discussion as Guest

Log in