10 #ifndef EIGEN_SPARSE_COMPRESSED_BASE_H 11 #define EIGEN_SPARSE_COMPRESSED_BASE_H 19 template<
typename Derived>
35 template<
typename Derived>
42 using Base::operator=;
43 using Base::IsRowMajor;
46 class ReverseInnerIterator;
58 if(Derived::IsVectorAtCompileTime && outerIndexPtr()==0)
59 return derived().nonZeros();
60 else if(isCompressed())
61 return outerIndexPtr()[derived().outerSize()]-outerIndexPtr()[0];
62 else if(derived().outerSize()==0)
65 return innerNonZeros().sum();
139 const Index outer = Derived::IsRowMajor ?
row :
col;
140 const Index inner = Derived::IsRowMajor ?
col :
row;
142 Index start = this->outerIndexPtr()[outer];
143 Index end = this->isCompressed() ? this->outerIndexPtr()[outer+1] : this->outerIndexPtr()[outer] + this->innerNonZeroPtr()[outer];
144 eigen_assert(end>=start &&
"you are using a non finalized sparse matrix or written coefficient does not exist");
146 p.
value = std::lower_bound(this->innerIndexPtr()+start, this->innerIndexPtr()+end,inner) - this->innerIndexPtr();
157 template<
typename Derived>
162 : m_values(0), m_indices(0), m_outer(0), m_id(0), m_end(0)
166 : m_values(other.m_values), m_indices(other.m_indices), m_outer(other.m_outer), m_id(other.m_id), m_end(other.m_end)
180 : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer)
198 : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(0), m_id(0), m_end(mat.nonZeros())
204 : m_values(data.valuePtr()), m_indices(data.indexPtr()), m_outer(0), m_id(0), m_end(data.
size())
224 inline Index row()
const {
return IsRowMajor ? m_outer.value() : index(); }
225 inline Index col()
const {
return IsRowMajor ? index() : m_outer.value(); }
227 inline operator bool()
const {
return (m_id < m_end); }
243 template<
typename Derived>
248 : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer)
266 : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(0), m_start(0), m_id(mat.nonZeros())
272 : m_values(data.valuePtr()), m_indices(data.indexPtr()), m_outer(0), m_start(0), m_id(data.
size())
292 inline Index row()
const {
return IsRowMajor ? m_outer.value() : index(); }
293 inline Index col()
const {
return IsRowMajor ? index() : m_outer.value(); }
295 inline operator bool()
const {
return (m_id > m_start); }
308 template<
typename Derived>
317 Flags = Derived::Flags
330 return m_matrix->nonZeros();
333 operator Derived&() {
return m_matrix->const_cast_derived(); }
334 operator const Derived&()
const {
return *m_matrix; }
344 return m_matrix->const_cast_derived().valuePtr()[
p];
351 return m_matrix->const_cast_derived().valuePtr()[
p];
370 #endif // EIGEN_SPARSE_COMPRESSED_BASE_H ReverseInnerIterator(const internal::CompressedStorage< Scalar, StorageIndex > &data)
InnerIterator & operator+=(Index i)
bool isCompressed() const
const Eigen::Map< const IndexVector > innerNonZeros() const
internal::LowerBoundIndex lower_bound(Index row, Index col) const
SparseMatrixBase< Derived > Base
A matrix or vector expression mapping an existing array of data.
evaluator(const Derived &mat)
InnerIterator(const InnerIterator &other)
Namespace containing all symbols from the Eigen library.
StorageIndex * innerIndexPtr()
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
InnerIterator & operator++()
Eigen::Index Index
The interface type of indices.
const StorageIndex * innerNonZeroPtr() const
Eigen::Map< IndexVector > innerNonZeros()
Map< Array< Scalar, Dynamic, 1 > > coeffs()
internal::traits< SparseVector< double, _Options, _StorageIndex > >::StorageIndex StorageIndex
const StorageIndex * m_indices
Index find(Index row, Index col) const
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Base class of any sparse matrices or sparse expressions.
Derived::InnerIterator InnerIterator
StorageIndex index() const
StorageIndex * innerNonZeroPtr()
internal::traits< SparseVector< double, _Options, _StorageIndex > >::Scalar Scalar
internal::variable_if_dynamic< Index, Derived::IsVectorAtCompileTime?0:Dynamic > OuterType
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
InnerIterator(const internal::CompressedStorage< Scalar, StorageIndex > &data)
InnerIterator(const SparseCompressedBase &mat, Index outer)
const Scalar & value() const
const StorageIndex * innerIndexPtr() const
Base::IndexVector IndexVector
internal::variable_if_dynamic< Index, Derived::IsVectorAtCompileTime?0:Dynamic > OuterType
ReverseInnerIterator(const SparseCompressedBase &mat)
DenseCoeffsBase< Derived, ReadOnlyAccessors >::CoeffReturnType CoeffReturnType
const StorageIndex * outerIndexPtr() const
EIGEN_CONSTEXPR Index size(const T &x)
InnerIterator & operator=(const InnerIterator &other)
StorageIndex * outerIndexPtr()
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR T value()
Index nonZerosEstimate() const
InnerIterator operator+(Index i)
static EIGEN_DEPRECATED const end_t end
const StorageIndex * m_indices
static ConstMapType Map(const Scalar *data)
ReverseInnerIterator & operator-=(Index i)
const Scalar & value() const
ReverseInnerIterator(const SparseCompressedBase &mat, Index outer)
const Scalar & coeff(Index row, Index col) const
ReverseInnerIterator & operator--()
#define eigen_internal_assert(x)
ReverseInnerIterator operator-(Index i)
Common base class for sparse [compressed]-{row|column}-storage format.
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
const Scalar * valuePtr() const
StorageIndex index() const
InnerIterator(const SparseCompressedBase &mat)
const Map< const Array< Scalar, Dynamic, 1 > > coeffs() const
An InnerIterator allows to loop over the element of any matrix expression.
Scalar & coeffRef(Index row, Index col)