<commit_before>// Copyright (C) 2016-2020 <NAME> <<EMAIL>>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#ifndef SPECTRA_SPARSE_GEN_MAT_PROD_H
#define SPECTRA_SPARSE_GEN_MAT_PROD_H

#include <Eigen/Core>
#include <Eigen/SparseCore>

    namespace Spectra
{
    ///
    /// \ingroup MatOp
    ///
    /// This class defines the matrix-vector multiplication operation on a
    /// sparse real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector
    /// \f$x\f$. It is mainly used in the GenEigsSolver and SymEigsSolver
    /// eigen solvers.
    ///
    template <typename Scalar_, int Flags = Eigen::ColMajor, typename StorageIndex = int>
    class SparseGenMatProd
    {
    private:
        using Scalar = Scalar_;
        using Index = Eigen::Index;
        using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
        using MapConstVec = Eigen::Map<const Vector>;
        using MapVec = Eigen::Map<Vector>;
        using SparseMatrix = Eigen::SparseMatrix<Scalar, Flags, StorageIndex>;
        using ConstGenericSparseMatrix = const Eigen::Ref<const SparseMatrix>;

        ConstGenericSparseMatrix m_mat;

    public:
        ///
        /// Constructor to create the matrix operation object.
        ///
        /// \param mat An **Eigen** sparse matrix object, whose type can be
        /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version
        /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`.
        ///
        SparseGenMatProd(ConstGenericSparseMatrix& mat) :
            m_mat(mat)
        {}

        ///
        /// Return the number of rows of the underlying matrix.
        ///
        Index rows() const { return m_mat.rows(); }
        ///
        /// Return the number of columns of the underlying matrix.
        ///
        Index 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;
        }

        ///
        /// Perform the matrix-matrix multiplication operation \f$y=Ax\f$.
        ///
        SparseMatrix operator*(const SparseMatrix mat_in)
        {
            return m_mat * mat_in;
        }

        ///
        /// Extract (i,j) element of the underlying matrix.
        ///
        Scalar operator()(Index i, Index j)
        {
            return m_mat(i, j);
        }
    };<commit_msg>format<commit_after>// Copyright (C) 2016-2020 <NAME> <<EMAIL>>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#ifndef SPECTRA_SPARSE_GEN_MAT_PROD_H
#define SPECTRA_SPARSE_GEN_MAT_PROD_H

#include <Eigen/Core>
#include <Eigen/SparseCore>

namespace Spectra {
///
/// \ingroup MatOp
///
/// This class defines the matrix-vector multiplication operation on a
/// sparse real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector
/// \f$x\f$. It is mainly used in the GenEigsSolver and SymEigsSolver
/// eigen solvers.
///
template <typename Scalar_, int Flags = Eigen::ColMajor, typename StorageIndex = int>
class SparseGenMatProd
{
private:
    using Scalar = Scalar_;
    using Index = Eigen::Index;
    using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
    using MapConstVec = Eigen::Map<const Vector>;
    using MapVec = Eigen::Map<Vector>;
    using SparseMatrix = Eigen::SparseMatrix<Scalar, Flags, StorageIndex>;
    using ConstGenericSparseMatrix = const Eigen::Ref<const SparseMatrix>;

    ConstGenericSparseMatrix m_mat;

public:
    ///
    /// Constructor to create the matrix operation object.
    ///
    /// \param mat An **Eigen** sparse matrix object, whose type can be
    /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version
    /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`.
    ///
    SparseGenMatProd(ConstGenericSparseMatrix& mat) :
        m_mat(mat)
    {}

    ///
    /// Return the number of rows of the underlying matrix.
    ///
    Index rows() const { return m_mat.rows(); }
    ///
    /// Return the number of columns of the underlying matrix.
    ///
    Index 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;
    }

    ///
    /// Perform the matrix-matrix multiplication operation \f$y=Ax\f$.
    ///
    SparseMatrix operator*(const SparseMatrix mat_in)
    {
        return m_mat * mat_in;
    }

    ///
    /// Extract (i,j) element of the underlying matrix.
    ///
    Scalar operator()(Index i, Index j)
    {
        return m_mat(i, j);
    }
};
{'fraction_non_alphanumeric': 0.13239904112115067, 'fraction_numerical': 0.004794394246726904, 'mean_word_length': 2.119033927544566, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6121975', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1680, 'n_words': 496}