10#ifndef EIGEN_SPARSE_COMPRESSED_BASE_H
11#define EIGEN_SPARSE_COMPRESSED_BASE_H
15template<
typename Derived>
class SparseCompressedBase;
19template<
typename Derived>
35template<
typename Derived>
42 using Base::operator=;
43 using Base::IsRowMajor;
65 return innerNonZeros().
sum();
71 inline const Scalar*
valuePtr()
const {
return derived().valuePtr(); }
75 inline Scalar*
valuePtr() {
return derived().valuePtr(); }
139 const Index outer = Derived::IsRowMajor ? row : col;
140 const Index inner = Derived::IsRowMajor ? col : row;
144 eigen_assert(end>=start &&
"you are using a non finalized sparse matrix or written coefficient does not exist");
147 p.found = (p.value<end) && (this->
innerIndexPtr()[p.value]==inner);
154 template<
typename OtherDerived>
explicit SparseCompressedBase(
const SparseCompressedBase<OtherDerived>&);
157template<
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)
171 m_values = other.m_values;
172 m_indices = other.m_indices;
180 : m_values(
mat.valuePtr()), m_indices(
mat.innerIndexPtr()), m_outer(outer)
182 if(Derived::IsVectorAtCompileTime &&
mat.outerIndexPtr()==0)
189 m_id =
mat.outerIndexPtr()[outer];
190 if(
mat.isCompressed())
191 m_end =
mat.outerIndexPtr()[outer+1];
193 m_end = m_id +
mat.innerNonZeroPtr()[outer];
198 : m_values(
mat.valuePtr()), m_indices(
mat.innerIndexPtr()), m_outer(0), m_id(0), m_end(
mat.
nonZeros())
200 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
204 : m_values(data.valuePtr()), m_indices(data.indexPtr()), m_outer(0), m_id(0), m_end(data.size())
206 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
219 inline const Scalar& value()
const {
return m_values[m_id]; }
220 inline Scalar& valueRef() {
return const_cast<Scalar&
>(m_values[m_id]); }
222 inline StorageIndex index()
const {
return m_indices[m_id]; }
223 inline Index outer()
const {
return m_outer.value(); }
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); }
230 const Scalar* m_values;
243template<
typename Derived>
248 : m_values(
mat.valuePtr()), m_indices(
mat.innerIndexPtr()), m_outer(outer)
250 if(Derived::IsVectorAtCompileTime &&
mat.outerIndexPtr()==0)
257 m_start =
mat.outerIndexPtr()[outer];
258 if(
mat.isCompressed())
259 m_id =
mat.outerIndexPtr()[outer+1];
261 m_id = m_start +
mat.innerNonZeroPtr()[outer];
266 : m_values(
mat.valuePtr()), m_indices(
mat.innerIndexPtr()), m_outer(0), m_start(0), m_id(
mat.
nonZeros())
268 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
272 : m_values(data.valuePtr()), m_indices(data.indexPtr()), m_outer(0), m_start(0), m_id(data.size())
274 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
287 inline const Scalar& value()
const {
return m_values[m_id-1]; }
288 inline Scalar& valueRef() {
return const_cast<Scalar&
>(m_values[m_id-1]); }
290 inline StorageIndex index()
const {
return m_indices[m_id-1]; }
291 inline Index outer()
const {
return m_outer.value(); }
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); }
298 const Scalar* m_values;
308template<
typename Derived>
312 typedef typename Derived::Scalar Scalar;
313 typedef typename Derived::InnerIterator InnerIterator;
317 Flags = Derived::Flags
322 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
326 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
329 inline Index nonZerosEstimate()
const {
330 return m_matrix->nonZeros();
333 operator Derived&() {
return m_matrix->const_cast_derived(); }
334 operator const Derived&()
const {
return *m_matrix; }
337 const Scalar& coeff(
Index row,
Index col)
const
339 Index p = find(row,col);
344 return m_matrix->const_cast_derived().valuePtr()[p];
349 Index p = find(row,col);
350 eigen_assert(p!=
Dynamic &&
"written coefficient does not exist");
351 return m_matrix->const_cast_derived().valuePtr()[p];
359 return p.found ? p.value :
Dynamic;
362 const Derived *m_matrix;
General-purpose arrays with easy API for coefficient-wise operations.
Definition Array.h:47
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const
Definition DenseBase.h:223
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index nonZeros() const
Definition DenseBase.h:215
EIGEN_DEVICE_FUNC CoeffReturnType value() const
Definition DenseBase.h:526
EIGEN_DEVICE_FUNC Scalar sum() const
Definition Redux.h:459
Definition ForwardDeclarations.h:50
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Definition SparseCompressedBase.h:159
Definition SparseCompressedBase.h:245
Common base class for sparse [compressed]-{row|column}-storage format.
Definition SparseCompressedBase.h:38
StorageIndex * innerNonZeroPtr()
Definition SparseCompressedBase.h:104
Index nonZeros() const
Definition SparseCompressedBase.h:56
const StorageIndex * innerIndexPtr() const
Definition SparseCompressedBase.h:80
StorageIndex * innerIndexPtr()
Definition SparseCompressedBase.h:84
const Scalar * valuePtr() const
Definition SparseCompressedBase.h:71
bool isCompressed() const
Definition SparseCompressedBase.h:107
const StorageIndex * outerIndexPtr() const
Definition SparseCompressedBase.h:90
Scalar * valuePtr()
Definition SparseCompressedBase.h:75
Map< Array< Scalar, Dynamic, 1 > > coeffs()
Definition SparseCompressedBase.h:126
const StorageIndex * innerNonZeroPtr() const
Definition SparseCompressedBase.h:100
StorageIndex * outerIndexPtr()
Definition SparseCompressedBase.h:95
const Map< const Array< Scalar, Dynamic, 1 > > coeffs() const
Definition SparseCompressedBase.h:114
SparseCompressedBase()
Default constructor.
Definition SparseCompressedBase.h:130
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:28
internal::traits< Derived >::StorageIndex StorageIndex
The integer type used to store indices within a SparseMatrix.
Definition SparseMatrixBase.h:43
Index rows() const
Definition SparseMatrixBase.h:176
Index outerSize() const
Definition SparseMatrixBase.h:189
Index cols() const
Definition SparseMatrixBase.h:178
Definition CompressedStorage.h:23
Definition XprHelper.h:130
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition Constants.h:22
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:39
Holds information about the various numeric (i.e.
Definition NumTraits.h:236
Definition SparseUtil.h:144
Definition CoreEvaluators.h:111
Definition CoreEvaluators.h:91
Definition ForwardDeclarations.h:17