10#ifndef EIGEN_SPARSE_MAP_H
11#define EIGEN_SPARSE_MAP_H
17template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
19 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
24 Flags = TraitsBase::Flags & (~NestByRefBit)
28template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
30 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
41template<
typename Derived,
49template<
typename Derived>
57 enum { IsRowMajor = Base::IsRowMajor };
58 using Base::operator=;
79 inline Index rows()
const {
return IsRowMajor ? m_outerSize : m_innerSize; }
81 inline Index cols()
const {
return IsRowMajor ? m_innerSize : m_outerSize; }
110 Index start = m_outerIndex[outer];
111 Index end = isCompressed() ? m_outerIndex[outer+1] : start + m_innerNonZeros[outer];
114 else if (
end>0 && inner==m_innerIndices[
end-1])
115 return m_values[
end-1];
119 const StorageIndex* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[
end-1],inner);
120 const Index id = r-&m_innerIndices[0];
121 return ((*r==inner) && (
id<
end)) ? m_values[id] :
Scalar(0);
127 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(innerNonZerosPtr)
133 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(0)
147template<
typename Derived>
157 enum { IsRowMajor = Base::IsRowMajor };
159 using Base::operator=;
165 using Base::valuePtr;
166 using Base::innerIndexPtr;
167 using Base::outerIndexPtr;
168 using Base::innerNonZeroPtr;
185 Index start = Base::m_outerIndex[outer];
186 Index end = Base::isCompressed() ? Base::m_outerIndex[outer+1] : start + Base::m_innerNonZeros[outer];
187 eigen_assert(
end>=start &&
"you probably called coeffRef on a non finalized matrix");
188 eigen_assert(
end>start &&
"coeffRef cannot be called on a zero coefficient");
189 StorageIndex* r = std::lower_bound(&Base::m_innerIndices[start],&Base::m_innerIndices[
end],inner);
190 const Index id = r - &Base::m_innerIndices[0];
191 eigen_assert((*r==inner) && (
id<
end) &&
"coeffRef cannot be called on a zero coefficient");
192 return const_cast<Scalar*
>(Base::m_values)[
id];
197 :
Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
202 :
Base(
size, nnz, innerIndexPtr, valuePtr)
220#ifndef EIGEN_PARSED_BY_DOXYGEN
221template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
223 :
public SparseMapBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
225template<typename SparseMatrixType>
226class
Map<SparseMatrixType>
233 enum { IsRowMajor = Base::IsRowMajor };
246 StorageIndex* innerIndexPtr, Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0)
247 :
Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
249#ifndef EIGEN_PARSED_BY_DOXYGEN
254template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
256 :
public SparseMapBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
261 enum { IsRowMajor = Base::IsRowMajor };
271 const StorageIndex* innerIndexPtr,
const Scalar* valuePtr,
const StorageIndex* innerNonZerosPtr = 0)
272 :
Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
281template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
283 :
evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
291template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
293 :
evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:1097
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:1118
#define eigen_assert(x)
Definition: Macros.h:1047
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Definition: SparseUtil.h:43
Specialization of class Map for SparseMatrix-like storage.
Definition: SparseMap.h:229
SparseMapBase< Map > Base
Definition: SparseMap.h:231
~Map()
Empty destructor.
Definition: SparseMap.h:251
Map(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
Constructs a read-write Map to a sparse matrix of size rows x cols, containing nnz non-zero coefficie...
Definition: SparseMap.h:245
Definition: SparseMap.h:257
SparseMapBase< Map > Base
Definition: SparseMap.h:259
Map(Index rows, Index cols, Index nnz, const StorageIndex *outerIndexPtr, const StorageIndex *innerIndexPtr, const Scalar *valuePtr, const StorageIndex *innerNonZerosPtr=0)
This is the const version of the above constructor.
Definition: SparseMap.h:270
~Map()
Empty destructor.
Definition: SparseMap.h:276
Base class for dense Map and Block expression with direct access.
Definition: MapBase.h:39
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
Common base class for sparse [compressed]-{row|column}-storage format.
Definition: SparseCompressedBase.h:38
class SparseMapBase
Definition: SparseMap.h:52
Index m_innerSize
Definition: SparseMap.h:69
SparseCompressedBase< Derived > Base
Definition: SparseMap.h:54
Index innerSize() const
Definition: SparseMap.h:83
Index cols() const
Definition: SparseMap.h:81
internal::conditional< bool(internal::is_lvalue< Derived >::value), StorageIndex *, constStorageIndex * >::type IndexPointer
Definition: SparseMap.h:66
const StorageIndex * innerIndexPtr() const
Definition: SparseMap.h:97
const Scalar * valuePtr() const
Definition: SparseMap.h:95
Base::Scalar Scalar
Definition: SparseMap.h:55
Scalar coeff(Index row, Index col) const
Definition: SparseMap.h:105
Index rows() const
Definition: SparseMap.h:79
Index outerSize() const
Definition: SparseMap.h:85
IndexPointer m_innerIndices
Definition: SparseMap.h:72
Index nonZeros() const
Definition: SparseMap.h:87
Index m_outerSize
Definition: SparseMap.h:68
Base::StorageIndex StorageIndex
Definition: SparseMap.h:56
const StorageIndex * innerNonZeroPtr() const
Definition: SparseMap.h:101
SparseMapBase(Index rows, Index cols, Index nnz, IndexPointer outerIndexPtr, IndexPointer innerIndexPtr, ScalarPointer valuePtr, IndexPointer innerNonZerosPtr=0)
Definition: SparseMap.h:124
SparseMapBase()
Definition: SparseMap.h:140
internal::conditional< bool(internal::is_lvalue< Derived >::value), Scalar *, constScalar * >::type ScalarPointer
Definition: SparseMap.h:63
Array< StorageIndex, 2, 1 > m_zero_nnz
Definition: SparseMap.h:70
bool isCompressed() const
Definition: SparseMap.h:90
IndexPointer m_outerIndex
Definition: SparseMap.h:71
~SparseMapBase()
Empty destructor.
Definition: SparseMap.h:137
SparseMapBase(Index size, Index nnz, IndexPointer innerIndexPtr, ScalarPointer valuePtr)
Definition: SparseMap.h:131
IndexPointer m_innerNonZeros
Definition: SparseMap.h:74
ScalarPointer m_values
Definition: SparseMap.h:73
const StorageIndex * outerIndexPtr() const
Definition: SparseMap.h:99
Scalar & coeffRef(Index row, Index col)
Definition: SparseMap.h:180
SparseMapBase(Index size, Index nnz, StorageIndex *innerIndexPtr, Scalar *valuePtr)
Definition: SparseMap.h:201
Scalar * valuePtr()
Definition: SparseMap.h:170
StorageIndex * innerNonZeroPtr()
Definition: SparseMap.h:176
SparseMapBase(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
Definition: SparseMap.h:195
~SparseMapBase()
Empty destructor.
Definition: SparseMap.h:206
Base::StorageIndex StorageIndex
Definition: SparseMap.h:156
StorageIndex * outerIndexPtr()
Definition: SparseMap.h:174
StorageIndex * innerIndexPtr()
Definition: SparseMap.h:172
Base::Scalar Scalar
Definition: SparseMap.h:155
SparseMapBase< Derived, ReadOnlyAccessors > Base
Definition: SparseMap.h:154
SparseMapBase()
Definition: SparseMap.h:209
Definition: SparseMap.h:43
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
internal::traits< Derived >::Scalar Scalar
Definition: SparseMatrixBase.h:31
A versatible sparse matrix representation.
Definition: SparseMatrix.h:98
type
Definition: core.h:575
@ ReadOnlyAccessors
Read-only access via a member function.
Definition: Constants.h:376
@ WriteAccessors
Read/write access via member functions.
Definition: Constants.h:378
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition: Constants.h:144
EIGEN_DEVICE_FUNC IndexDest convert_index(const IndexSrc &idx)
Definition: XprHelper.h:31
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
Namespace containing all symbols from the Eigen library.
Definition: Core:141
const unsigned int NestByRefBit
Definition: Constants.h:169
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:39
@ has_write_access
Definition: ForwardDeclarations.h:33
evaluator(const XprType &mat)
Definition: SparseMap.h:288
evaluator()
Definition: SparseMap.h:287
Map< SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > XprType
Definition: SparseMap.h:286
evaluator< SparseCompressedBase< Map< SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > > > Base
Definition: SparseMap.h:285
evaluator(const XprType &mat)
Definition: SparseMap.h:298
evaluator()
Definition: SparseMap.h:297
Map< const SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > XprType
Definition: SparseMap.h:296
evaluator< SparseCompressedBase< Map< const SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > > > Base
Definition: SparseMap.h:295
Definition: CoreEvaluators.h:91
Definition: XprHelper.h:660
traits< PlainObjectType > TraitsBase
Definition: SparseMap.h:22
SparseMatrix< MatScalar, MatOptions, MatIndex > PlainObjectType
Definition: SparseMap.h:21
traits< PlainObjectType > TraitsBase
Definition: SparseMap.h:33
SparseMatrix< MatScalar, MatOptions, MatIndex > PlainObjectType
Definition: SparseMap.h:32
Definition: ForwardDeclarations.h:17
Definition: format.h:1552