Spectra
1.2.0
Header-only C++ Library for Large Scale Eigenvalue Problems
Toggle main menu visibility
Loading...
Searching...
No Matches
DenseGenMatProd.h
1
// Copyright (C) 2016-2025 Yixuan Qiu <yixuan.qiu@cos.name>
2
//
3
// This Source Code Form is subject to the terms of the Mozilla
4
// Public License v. 2.0. If a copy of the MPL was not distributed
5
// with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7
#ifndef SPECTRA_DENSE_GEN_MAT_PROD_H
8
#define SPECTRA_DENSE_GEN_MAT_PROD_H
9
10
#include <Eigen/Core>
11
12
namespace
Spectra {
13
19
34
template
<
typename
Scalar_,
int
Flags = Eigen::ColMajor>
35
class
DenseGenMatProd
36
{
37
public
:
41
using
Scalar
= Scalar_;
42
43
private
:
44
using
Index = Eigen::Index;
45
using
Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Flags>;
46
using
Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
47
using
MapConstVec = Eigen::Map<const Vector>;
48
using
MapVec = Eigen::Map<Vector>;
49
using
ConstGenericMatrix =
const
Eigen::Ref<const Matrix>;
50
51
ConstGenericMatrix m_mat;
52
53
public
:
62
template
<
typename
Derived>
63
DenseGenMatProd
(
const
Eigen::MatrixBase<Derived>& mat) :
64
m_mat(mat)
65
{
66
static_assert
(
67
static_cast<
int
>
(Derived::PlainObject::IsRowMajor) ==
static_cast<
int
>
(Matrix::IsRowMajor),
68
"DenseGenMatProd: the \"Flags\" template parameter does not match the input matrix (Eigen::ColMajor/Eigen::RowMajor)"
);
69
}
70
74
Index
rows
()
const
{
return
m_mat.rows(); }
78
Index
cols
()
const
{
return
m_mat.cols(); }
79
86
// y_out = A * x_in
87
void
perform_op
(
const
Scalar
* x_in,
Scalar
* y_out)
const
88
{
89
MapConstVec x(x_in, m_mat.cols());
90
MapVec y(y_out, m_mat.rows());
91
y.noalias() = m_mat * x;
92
}
93
97
Matrix
operator*
(
const
Eigen::Ref<const Matrix>& mat_in)
const
98
{
99
return
m_mat * mat_in;
100
}
101
105
Scalar
operator()
(Index i, Index j)
const
106
{
107
return
m_mat(i, j);
108
}
109
};
110
111
}
// namespace Spectra
112
113
#endif
// SPECTRA_DENSE_GEN_MAT_PROD_H
Spectra::DenseGenMatProd::DenseGenMatProd
DenseGenMatProd(const Eigen::MatrixBase< Derived > &mat)
Definition
DenseGenMatProd.h:63
Spectra::DenseGenMatProd::cols
Index cols() const
Definition
DenseGenMatProd.h:78
Spectra::DenseGenMatProd::Scalar
Scalar_ Scalar
Definition
DenseGenMatProd.h:41
Spectra::DenseGenMatProd::operator*
Matrix operator*(const Eigen::Ref< const Matrix > &mat_in) const
Definition
DenseGenMatProd.h:97
Spectra::DenseGenMatProd::perform_op
void perform_op(const Scalar *x_in, Scalar *y_out) const
Definition
DenseGenMatProd.h:87
Spectra::DenseGenMatProd::operator()
Scalar operator()(Index i, Index j) const
Definition
DenseGenMatProd.h:105
Spectra::DenseGenMatProd::rows
Index rows() const
Definition
DenseGenMatProd.h:74
Spectra
MatOp
DenseGenMatProd.h
Generated by
1.17.0