2008-06-26 23:22:26 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-06-26 23:22:26 +00:00
|
|
|
//
|
2014-07-01 13:27:35 +02:00
|
|
|
// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-06-26 23:22:26 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// 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 http://mozilla.org/MPL/2.0/.
|
2008-06-26 23:22:26 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_SPARSEUTIL_H
|
|
|
|
|
#define EIGEN_SPARSEUTIL_H
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
namespace Eigen {
|
2012-04-15 11:06:28 +01:00
|
|
|
|
2008-06-26 23:22:26 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#define EIGEN_DBG_SPARSE(X)
|
|
|
|
|
#else
|
|
|
|
|
#define EIGEN_DBG_SPARSE(X) X
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
#define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
|
|
|
|
|
template <typename OtherDerived> \
|
|
|
|
|
EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) { \
|
|
|
|
|
return Base::operator Op(other.derived()); \
|
|
|
|
|
} \
|
|
|
|
|
EIGEN_STRONG_INLINE Derived& operator Op(const Derived & other) { return Base::operator Op(other); }
|
2009-01-14 14:24:10 +00:00
|
|
|
|
|
|
|
|
#define EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename Other> \
|
|
|
|
|
EIGEN_STRONG_INLINE Derived& operator Op(const Other & scalar) { \
|
|
|
|
|
return Base::operator Op(scalar); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =)
|
|
|
|
|
|
|
|
|
|
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
|
|
|
|
|
|
|
|
|
|
const int CoherentAccessPattern = 0x1;
|
|
|
|
|
const int InnerRandomAccessPattern = 0x2 | CoherentAccessPattern;
|
|
|
|
|
const int OuterRandomAccessPattern = 0x4 | CoherentAccessPattern;
|
|
|
|
|
const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
|
|
|
|
|
|
|
|
|
|
template <typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
|
|
|
|
|
class SparseMatrix;
|
|
|
|
|
template <typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
|
|
|
|
|
class SparseVector;
|
|
|
|
|
|
|
|
|
|
template <typename MatrixType, unsigned int UpLo>
|
|
|
|
|
class SparseSelfAdjointView;
|
|
|
|
|
template <typename Lhs, typename Rhs>
|
|
|
|
|
class SparseDiagonalProduct;
|
|
|
|
|
template <typename MatrixType>
|
|
|
|
|
class SparseView;
|
|
|
|
|
|
|
|
|
|
template <typename Lhs, typename Rhs>
|
|
|
|
|
class SparseSparseProduct;
|
|
|
|
|
template <typename Lhs, typename Rhs>
|
|
|
|
|
class SparseTimeDenseProduct;
|
|
|
|
|
template <typename Lhs, typename Rhs>
|
|
|
|
|
class DenseTimeSparseProduct;
|
|
|
|
|
template <typename Lhs, typename Rhs, bool Transpose>
|
|
|
|
|
class SparseDenseOuterProduct;
|
|
|
|
|
|
|
|
|
|
template <typename Lhs, typename Rhs>
|
|
|
|
|
struct SparseSparseProductReturnType;
|
|
|
|
|
template <typename Lhs, typename Rhs,
|
|
|
|
|
int InnerSize = internal::min_size_prefer_fixed(internal::traits<Lhs>::ColsAtCompileTime,
|
|
|
|
|
internal::traits<Rhs>::RowsAtCompileTime)>
|
|
|
|
|
struct DenseSparseProductReturnType;
|
|
|
|
|
|
|
|
|
|
template <typename Lhs, typename Rhs,
|
|
|
|
|
int InnerSize = internal::min_size_prefer_fixed(internal::traits<Lhs>::ColsAtCompileTime,
|
|
|
|
|
internal::traits<Rhs>::RowsAtCompileTime)>
|
|
|
|
|
struct SparseDenseProductReturnType;
|
|
|
|
|
template <typename MatrixType, int UpLo>
|
|
|
|
|
class SparseSymmetricPermutationProduct;
|
2009-01-14 14:24:10 +00:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename T, int Rows, int Cols, int Flags>
|
|
|
|
|
struct sparse_eval;
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct eval<T, Sparse> : sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, traits<T>::Flags> {
|
|
|
|
|
};
|
2011-12-22 14:01:06 +01:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename T, int Cols, int Flags>
|
|
|
|
|
struct sparse_eval<T, 1, Cols, Flags> {
|
|
|
|
|
typedef typename traits<T>::Scalar Scalar_;
|
|
|
|
|
typedef typename traits<T>::StorageIndex StorageIndex_;
|
2011-12-22 14:01:06 +01:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
public:
|
|
|
|
|
typedef SparseVector<Scalar_, RowMajor, StorageIndex_> type;
|
2011-12-22 14:01:06 +01:00
|
|
|
};
|
2008-06-26 23:22:26 +00:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename T, int Rows, int Flags>
|
|
|
|
|
struct sparse_eval<T, Rows, 1, Flags> {
|
|
|
|
|
typedef typename traits<T>::Scalar Scalar_;
|
|
|
|
|
typedef typename traits<T>::StorageIndex StorageIndex_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
typedef SparseVector<Scalar_, ColMajor, StorageIndex_> type;
|
2011-12-22 14:01:06 +01:00
|
|
|
};
|
|
|
|
|
|
2014-12-04 22:48:53 +01:00
|
|
|
// TODO this seems almost identical to plain_matrix_type<T, Sparse>
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename T, int Rows, int Cols, int Flags>
|
|
|
|
|
struct sparse_eval {
|
|
|
|
|
typedef typename traits<T>::Scalar Scalar_;
|
|
|
|
|
typedef typename traits<T>::StorageIndex StorageIndex_;
|
|
|
|
|
enum { Options_ = ((Flags & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor };
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
typedef SparseMatrix<Scalar_, Options_, StorageIndex_> type;
|
2008-06-26 23:22:26 +00:00
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename T, int Flags>
|
|
|
|
|
struct sparse_eval<T, 1, 1, Flags> {
|
|
|
|
|
typedef typename traits<T>::Scalar Scalar_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
typedef Matrix<Scalar_, 1, 1> type;
|
2011-12-22 14:01:06 +01:00
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename T>
|
|
|
|
|
struct plain_matrix_type<T, Sparse> {
|
2021-08-04 22:41:52 +00:00
|
|
|
typedef typename traits<T>::Scalar Scalar_;
|
|
|
|
|
typedef typename traits<T>::StorageIndex StorageIndex_;
|
2023-11-29 11:12:48 +00:00
|
|
|
enum { Options_ = ((evaluator<T>::Flags & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor };
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
typedef SparseMatrix<Scalar_, Options_, StorageIndex_> type;
|
2009-12-23 09:07:01 +01:00
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename T>
|
|
|
|
|
struct plain_object_eval<T, Sparse>
|
|
|
|
|
: sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, evaluator<T>::Flags> {};
|
2015-10-14 10:12:58 +02:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename Decomposition, typename RhsType>
|
|
|
|
|
struct solve_traits<Decomposition, RhsType, Sparse> {
|
|
|
|
|
typedef typename sparse_eval<RhsType, RhsType::RowsAtCompileTime, RhsType::ColsAtCompileTime,
|
|
|
|
|
traits<RhsType>::Flags>::type PlainObject;
|
2014-09-01 14:50:59 +02:00
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename Derived>
|
|
|
|
|
struct generic_xpr_base<Derived, MatrixXpr, Sparse> {
|
2014-06-20 15:42:13 +02:00
|
|
|
typedef SparseMatrixBase<Derived> type;
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
struct SparseTriangularShape {
|
|
|
|
|
static std::string debugName() { return "SparseTriangularShape"; }
|
|
|
|
|
};
|
|
|
|
|
struct SparseSelfAdjointShape {
|
|
|
|
|
static std::string debugName() { return "SparseSelfAdjointShape"; }
|
|
|
|
|
};
|
2014-07-22 11:35:56 +02:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <>
|
|
|
|
|
struct glue_shapes<SparseShape, SelfAdjointShape> {
|
|
|
|
|
typedef SparseSelfAdjointShape type;
|
|
|
|
|
};
|
|
|
|
|
template <>
|
|
|
|
|
struct glue_shapes<SparseShape, TriangularShape> {
|
|
|
|
|
typedef SparseTriangularShape type;
|
|
|
|
|
};
|
2014-07-22 11:35:56 +02:00
|
|
|
|
2019-01-28 17:24:44 +01:00
|
|
|
// return type of SparseCompressedBase::lower_bound;
|
|
|
|
|
struct LowerBoundIndex {
|
|
|
|
|
LowerBoundIndex() : value(-1), found(false) {}
|
|
|
|
|
LowerBoundIndex(Index val, bool ok) : value(val), found(ok) {}
|
|
|
|
|
Index value;
|
|
|
|
|
bool found;
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
} // end namespace internal
|
2010-10-25 10:15:22 -04:00
|
|
|
|
2012-01-28 11:13:59 +01:00
|
|
|
/** \ingroup SparseCore_Module
|
2023-11-29 11:12:48 +00:00
|
|
|
*
|
|
|
|
|
* \class Triplet
|
|
|
|
|
*
|
|
|
|
|
* \brief A small structure to hold a non zero as a triplet (i,j,value).
|
|
|
|
|
*
|
|
|
|
|
* \sa SparseMatrix::setFromTriplets()
|
|
|
|
|
*/
|
|
|
|
|
template <typename Scalar, typename StorageIndex = typename SparseMatrix<Scalar>::StorageIndex>
|
|
|
|
|
class Triplet {
|
|
|
|
|
public:
|
2012-01-28 11:13:59 +01:00
|
|
|
Triplet() : m_row(0), m_col(0), m_value(0) {}
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
Triplet(const StorageIndex& i, const StorageIndex& j, const Scalar& v = Scalar(0)) : m_row(i), m_col(j), m_value(v) {}
|
2012-01-28 11:13:59 +01:00
|
|
|
|
|
|
|
|
/** \returns the row index of the element */
|
2014-12-04 22:48:53 +01:00
|
|
|
const StorageIndex& row() const { return m_row; }
|
2012-01-28 11:13:59 +01:00
|
|
|
|
|
|
|
|
/** \returns the column index of the element */
|
2014-12-04 22:48:53 +01:00
|
|
|
const StorageIndex& col() const { return m_col; }
|
2012-01-28 11:13:59 +01:00
|
|
|
|
|
|
|
|
/** \returns the value of the element */
|
|
|
|
|
const Scalar& value() const { return m_value; }
|
2023-11-29 11:12:48 +00:00
|
|
|
|
|
|
|
|
protected:
|
2014-12-04 22:48:53 +01:00
|
|
|
StorageIndex m_row, m_col;
|
2012-01-28 11:13:59 +01:00
|
|
|
Scalar m_value;
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
} // end namespace Eigen
|
2012-04-15 11:06:28 +01:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
#endif // EIGEN_SPARSEUTIL_H
|