7 #ifndef SPECTRA_DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
8 #define SPECTRA_DENSE_GEN_COMPLEX_SHIFT_SOLVE_H
29 template <
typename Scalar_,
int Flags = Eigen::ColMajor>
39 using Index = Eigen::Index;
40 using Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Flags>;
41 using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
42 using MapConstVec = Eigen::Map<const Vector>;
43 using MapVec = Eigen::Map<Vector>;
44 using ConstGenericMatrix =
const Eigen::Ref<const Matrix>;
46 using Complex = std::complex<Scalar>;
47 using ComplexMatrix = Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic, Flags>;
48 using ComplexVector = Eigen::Matrix<Complex, Eigen::Dynamic, 1>;
50 using ComplexSolver = Eigen::PartialPivLU<ComplexMatrix>;
52 ConstGenericMatrix m_mat;
54 ComplexSolver m_solver;
55 mutable ComplexVector m_x_cache;
66 template <
typename Derived>
68 m_mat(mat), m_n(mat.
rows())
71 static_cast<int>(Derived::PlainObject::IsRowMajor) ==
static_cast<int>(Matrix::IsRowMajor),
72 "DenseGenComplexShiftSolve: the \"Flags\" template parameter does not match the input matrix (Eigen::ColMajor/Eigen::RowMajor)");
74 if (mat.rows() != mat.cols())
75 throw std::invalid_argument(
"DenseGenComplexShiftSolve: matrix must be square");
81 Index
rows()
const {
return m_n; }
85 Index
cols()
const {
return m_n; }
95 m_solver.compute(m_mat.template cast<Complex>() - Complex(sigmar, sigmai) * ComplexMatrix::Identity(m_n, m_n));
96 m_x_cache.resize(m_n);
110 m_x_cache.real() = MapConstVec(x_in, m_n);
111 MapVec y(y_out, m_n);
112 y.noalias() = m_solver.solve(m_x_cache).real();
DenseGenComplexShiftSolve(const Eigen::MatrixBase< Derived > &mat)
void perform_op(const Scalar *x_in, Scalar *y_out) const
void set_shift(const Scalar &sigmar, const Scalar &sigmai)