Skip to content

Commit

Permalink
use Eigen::Index in matrix operations
Browse files Browse the repository at this point in the history
  • Loading branch information
yixuan committed Jun 7, 2019
1 parent 73d4351 commit abe3d02
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion include/Spectra/GenEigsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class GenEigsBase
///
/// \return Number of converged eigenvalues.
///
int compute(Index maxit = 1000, Scalar tol = 1e-10, int sort_rule = LARGEST_MAGN)
Index compute(Index maxit = 1000, Scalar tol = 1e-10, int sort_rule = LARGEST_MAGN)
{
// The m-step Arnoldi factorization
m_fac.factorize_from(1, m_ncv, m_nmatop);
Expand Down
9 changes: 5 additions & 4 deletions include/Spectra/MatOp/DenseCholesky.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand Down Expand Up @@ -27,14 +27,15 @@ template <typename Scalar, int Uplo = Eigen::Lower>
class DenseCholesky
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Matrix> MapConstMat;
typedef Eigen::Map<const Vector> MapConstVec;
typedef Eigen::Map<Vector> MapVec;
typedef const Eigen::Ref<const Matrix> ConstGenericMatrix;

const int m_n;
const Index m_n;
Eigen::LLT<Matrix, Uplo> m_decomp;
int m_info; // status of the decomposition

Expand Down Expand Up @@ -62,11 +63,11 @@ class DenseCholesky
///
/// Returns the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Returns the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Returns the status of the computation.
Expand Down
9 changes: 5 additions & 4 deletions include/Spectra/MatOp/DenseGenComplexShiftSolve.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand Down Expand Up @@ -26,6 +26,7 @@ template <typename Scalar>
class DenseGenComplexShiftSolve
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
Expand All @@ -39,7 +40,7 @@ class DenseGenComplexShiftSolve
typedef Eigen::PartialPivLU<ComplexMatrix> ComplexSolver;

ConstGenericMatrix m_mat;
const int m_n;
const Index m_n;
ComplexSolver m_solver;
ComplexVector m_x_cache;

Expand All @@ -62,11 +63,11 @@ class DenseGenComplexShiftSolve
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Set the complex shift \f$\sigma\f$.
Expand Down
7 changes: 4 additions & 3 deletions include/Spectra/MatOp/DenseGenMatProd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand Down Expand Up @@ -30,6 +30,7 @@ template <typename Scalar>
class DenseGenMatProd
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
Expand All @@ -54,11 +55,11 @@ class DenseGenMatProd
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_mat.rows(); }
Index rows() const { return m_mat.rows(); }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_mat.cols(); }
Index cols() const { return m_mat.cols(); }

///
/// Perform the matrix-vector multiplication operation \f$y=Ax\f$.
Expand Down
9 changes: 5 additions & 4 deletions include/Spectra/MatOp/DenseGenRealShiftSolve.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand All @@ -25,14 +25,15 @@ template <typename Scalar>
class DenseGenRealShiftSolve
{
private:
typedef Eigen::Index Index;
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;
const int m_n;
const Index m_n;
Eigen::PartialPivLU<Matrix> m_solver;

public:
Expand All @@ -54,11 +55,11 @@ class DenseGenRealShiftSolve
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Set the real shift \f$\sigma\f$.
Expand Down
7 changes: 4 additions & 3 deletions include/Spectra/MatOp/DenseSymMatProd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand All @@ -23,6 +23,7 @@ template <typename Scalar, int Uplo = Eigen::Lower>
class DenseSymMatProd
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
Expand All @@ -47,11 +48,11 @@ class DenseSymMatProd
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_mat.rows(); }
Index rows() const { return m_mat.rows(); }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_mat.cols(); }
Index cols() const { return m_mat.cols(); }

///
/// Perform the matrix-vector multiplication operation \f$y=Ax\f$.
Expand Down
5 changes: 3 additions & 2 deletions include/Spectra/MatOp/DenseSymShiftSolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ template <typename Scalar, int Uplo = Eigen::Lower>
class DenseSymShiftSolve
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
Expand Down Expand Up @@ -56,11 +57,11 @@ class DenseSymShiftSolve
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Set the real shift \f$\sigma\f$.
Expand Down
9 changes: 5 additions & 4 deletions include/Spectra/MatOp/SparseCholesky.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand Down Expand Up @@ -28,13 +28,14 @@ template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename Stor
class SparseCholesky
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
typedef Eigen::Map<Vector> MapVec;
typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix;
typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix;

const int m_n;
const Index m_n;
Eigen::SimplicialLLT<SparseMatrix, Uplo> m_decomp;
int m_info; // status of the decomposition

Expand All @@ -61,11 +62,11 @@ class SparseCholesky
///
/// Returns the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Returns the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Returns the status of the computation.
Expand Down
7 changes: 4 additions & 3 deletions include/Spectra/MatOp/SparseGenMatProd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand All @@ -25,6 +25,7 @@ template <typename Scalar, int Flags = 0, typename StorageIndex = int>
class SparseGenMatProd
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
typedef Eigen::Map<Vector> MapVec;
Expand All @@ -48,11 +49,11 @@ class SparseGenMatProd
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_mat.rows(); }
Index rows() const { return m_mat.rows(); }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_mat.cols(); }
Index cols() const { return m_mat.cols(); }

///
/// Perform the matrix-vector multiplication operation \f$y=Ax\f$.
Expand Down
5 changes: 3 additions & 2 deletions include/Spectra/MatOp/SparseGenRealShiftSolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ template <typename Scalar,int Flags = 0, typename StorageIndex = int>
class SparseGenRealShiftSolve
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
typedef Eigen::Map<Vector> MapVec;
Expand Down Expand Up @@ -54,11 +55,11 @@ class SparseGenRealShiftSolve
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Set the real shift \f$\sigma\f$.
Expand Down
7 changes: 4 additions & 3 deletions include/Spectra/MatOp/SparseRegularInverse.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2017-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2017-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand Down Expand Up @@ -30,6 +30,7 @@ template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename Stor
class SparseRegularInverse
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
typedef Eigen::Map<Vector> MapVec;
Expand Down Expand Up @@ -60,11 +61,11 @@ class SparseRegularInverse
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Perform the solving operation \f$y=B^{-1}x\f$.
Expand Down
7 changes: 4 additions & 3 deletions include/Spectra/MatOp/SparseSymMatProd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2018 Yixuan Qiu <yixuan.qiu@cos.name>
// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name>
//
// 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
Expand All @@ -24,6 +24,7 @@ template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename Stor
class SparseSymMatProd
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
typedef Eigen::Map<Vector> MapVec;
Expand All @@ -47,11 +48,11 @@ class SparseSymMatProd
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_mat.rows(); }
Index rows() const { return m_mat.rows(); }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_mat.cols(); }
Index cols() const { return m_mat.cols(); }

///
/// Perform the matrix-vector multiplication operation \f$y=Ax\f$.
Expand Down
5 changes: 3 additions & 2 deletions include/Spectra/MatOp/SparseSymShiftSolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename Stor
class SparseSymShiftSolve
{
private:
typedef Eigen::Index Index;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
typedef Eigen::Map<const Vector> MapConstVec;
typedef Eigen::Map<Vector> MapVec;
Expand Down Expand Up @@ -54,11 +55,11 @@ class SparseSymShiftSolve
///
/// Return the number of rows of the underlying matrix.
///
int rows() const { return m_n; }
Index rows() const { return m_n; }
///
/// Return the number of columns of the underlying matrix.
///
int cols() const { return m_n; }
Index cols() const { return m_n; }

///
/// Set the real shift \f$\sigma\f$.
Expand Down
Loading

0 comments on commit abe3d02

Please sign in to comment.