10#ifndef EIGEN_SPARSE_MAP_H
11#define EIGEN_SPARSE_MAP_H
17template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
18struct traits<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
19 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
21 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType;
22 typedef traits<PlainObjectType> TraitsBase;
24 Flags = TraitsBase::Flags & (~NestByRefBit)
28template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
29struct traits<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
30 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
32 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType;
33 typedef traits<PlainObjectType> TraitsBase;
35 Flags = TraitsBase::Flags & (~ (NestByRefBit |
LvalueBit))
41template<
typename Derived,
49template<
typename Derived>
55 typedef typename Base::Scalar Scalar;
57 enum { IsRowMajor = Base::IsRowMajor };
58 using Base::operator=;
61 typedef typename internal::conditional<
62 bool(internal::is_lvalue<Derived>::value),
63 Scalar *,
const Scalar *>::type ScalarPointer;
64 typedef typename internal::conditional<
65 bool(internal::is_lvalue<Derived>::value),
66 StorageIndex *,
const StorageIndex *>::type IndexPointer;
71 IndexPointer m_outerIndex;
72 IndexPointer m_innerIndices;
73 ScalarPointer m_values;
74 IndexPointer m_innerNonZeros;
79 inline Index rows()
const {
return IsRowMajor ? m_outerSize : m_innerSize; }
81 inline Index cols()
const {
return IsRowMajor ? m_innerSize : m_outerSize; }
95 inline const Scalar*
valuePtr()
const {
return m_values; }
97 inline const StorageIndex*
innerIndexPtr()
const {
return m_innerIndices; }
99 inline const StorageIndex*
outerIndexPtr()
const {
return m_outerIndex; }
107 const Index outer = IsRowMajor ? row : col;
108 const Index inner = IsRowMajor ? col : row;
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);
124 inline SparseMapBase(
Index rows,
Index cols,
Index nnz, IndexPointer outerIndexPtr, IndexPointer innerIndexPtr,
125 ScalarPointer valuePtr, IndexPointer innerNonZerosPtr = 0)
126 : m_outerSize(IsRowMajor?rows:cols), m_innerSize(IsRowMajor?cols:rows), m_zero_nnz(0,internal::convert_index<StorageIndex>(nnz)), m_outerIndex(outerIndexPtr),
127 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(innerNonZerosPtr)
131 inline SparseMapBase(
Index size,
Index nnz, IndexPointer innerIndexPtr, ScalarPointer valuePtr)
132 : m_outerSize(1), m_innerSize(size), m_zero_nnz(0,internal::convert_index<StorageIndex>(nnz)), m_outerIndex(m_zero_nnz.data()),
133 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(0)
140 inline SparseMapBase() {}
147template<
typename Derived>
149 :
public SparseMapBase<Derived,ReadOnlyAccessors>
154 typedef SparseMapBase<Derived, ReadOnlyAccessors>
Base;
155 typedef typename Base::Scalar Scalar;
156 typedef typename Base::StorageIndex StorageIndex;
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;
170 inline Scalar*
valuePtr() {
return Base::m_values; }
182 const Index outer = IsRowMajor ? row : col;
183 const Index inner = IsRowMajor ? col : row;
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];
195 inline SparseMapBase(
Index rows,
Index cols,
Index nnz, StorageIndex* outerIndexPtr, StorageIndex* innerIndexPtr,
196 Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0)
197 : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
201 inline SparseMapBase(
Index size,
Index nnz, StorageIndex* innerIndexPtr, Scalar* valuePtr)
202 : Base(size, nnz, innerIndexPtr, valuePtr)
209 inline SparseMapBase() {}
220#ifndef EIGEN_PARSED_BY_DOXYGEN
221template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
222class Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
223 :
public SparseMapBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
225template<typename SparseMatrixType>
226class
Map<SparseMatrixType>
227 :
public SparseMapBase<Derived,WriteAccessors>
231 typedef SparseMapBase<Map> Base;
232 EIGEN_SPARSE_PUBLIC_INTERFACE(
Map)
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>
255class Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
256 :
public SparseMapBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
259 typedef SparseMapBase<Map> Base;
260 EIGEN_SPARSE_PUBLIC_INTERFACE(Map)
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>
282struct evaluator<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
283 : evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
285 typedef evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
286 typedef Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
287 evaluator() : Base() {}
288 explicit evaluator(
const XprType &mat) : Base(mat) {}
291template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
292struct evaluator<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
293 : evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
295 typedef evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
296 typedef Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
297 evaluator() : Base() {}
298 explicit evaluator(
const XprType &mat) : Base(mat) {}
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:47
Base class for dense Map and Block expression with direct access.
Definition: MapBase.h:39
Map(Index rows, Index cols, Index nnz, const StorageIndex *outerIndexPtr, const StorageIndex *innerIndexPtr, const Scalar *valuePtr, const StorageIndex *innerNonZerosPtr=0)
Definition: SparseMap.h:270
Map(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
Definition: SparseMap.h:245
~Map()
Definition: SparseMap.h:276
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
Common base class for Map and Ref instance of sparse matrix and vector.
Definition: SparseMap.h:52
Index innerSize() const
Definition: SparseMap.h:83
Index cols() const
Definition: SparseMap.h:81
const StorageIndex * innerIndexPtr() const
Definition: SparseMap.h:97
const Scalar * valuePtr() const
Definition: SparseMap.h:95
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
Index nonZeros() const
Definition: SparseMap.h:87
const StorageIndex * innerNonZeroPtr() const
Definition: SparseMap.h:101
bool isCompressed() const
Definition: SparseMap.h:90
~SparseMapBase()
Definition: SparseMap.h:137
const StorageIndex * outerIndexPtr() const
Definition: SparseMap.h:99
Scalar & coeffRef(Index row, Index col)
Definition: SparseMap.h:180
Scalar * valuePtr()
Definition: SparseMap.h:170
StorageIndex * innerNonZeroPtr()
Definition: SparseMap.h:176
~SparseMapBase()
Definition: SparseMap.h:206
StorageIndex * outerIndexPtr()
Definition: SparseMap.h:174
StorageIndex * innerIndexPtr()
Definition: SparseMap.h:172
internal::traits< Derived >::StorageIndex StorageIndex
Definition: SparseMatrixBase.h:43
@ ReadOnlyAccessors
Definition: Constants.h:376
@ WriteAccessors
Definition: Constants.h:378
const unsigned int LvalueBit
Definition: Constants.h:144
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74