10 #ifndef EIGEN_SPARSE_MAP_H 11 #define EIGEN_SPARSE_MAP_H 17 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
19 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
28 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
30 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
41 template<
typename Derived,
49 template<
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; }
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);
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)
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)
147 template<
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;
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];
196 Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0)
197 : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
202 : Base(size, nnz, innerIndexPtr, valuePtr)
220 #ifndef EIGEN_PARSED_BY_DOXYGEN 221 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
223 :
public SparseMapBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
225 template<typename SparseMatrixType>
226 class
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 254 template<
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)
281 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
283 :
evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
291 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
293 :
evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
305 #endif // EIGEN_SPARSE_MAP_H traits< PlainObjectType > TraitsBase
Map(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
Scalar & coeffRef(Index row, Index col)
const Scalar * valuePtr() const
const StorageIndex * outerIndexPtr() const
Map< const SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > XprType
evaluator(const XprType &mat)
A versatible sparse matrix representation.
Q id(Eigen::AngleAxisd(0, Q_z_axis))
SparseMapBase< Derived, ReadOnlyAccessors > Base
A matrix or vector expression mapping an existing array of data.
Common base class for Map and Ref instance of sparse matrix and vector.
const unsigned int LvalueBit
Base::StorageIndex StorageIndex
Namespace containing all symbols from the Eigen library.
EIGEN_DEVICE_FUNC IndexDest convert_index(const IndexSrc &idx)
internal::conditional< bool(internal::is_lvalue< Derived >::value), StorageIndex *, const StorageIndex * >::type IndexPointer
Eigen::Index Index
The interface type of indices.
const StorageIndex * innerNonZeroPtr() const
evaluator(const XprType &mat)
Map< SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > XprType
traits< PlainObjectType > TraitsBase
StorageIndex * innerIndexPtr()
internal::traits< Derived >::StorageIndex StorageIndex
SparseMatrix< MatScalar, MatOptions, MatIndex > PlainObjectType
SparseMapBase< Map > Base
MapBase< Derived, ReadOnlyAccessors > ReadOnlyMapBase
StorageIndex * outerIndexPtr()
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
StorageIndex * innerNonZeroPtr()
Base class for dense Map and Block expression with direct access.
SparseMapBase(Index size, Index nnz, IndexPointer innerIndexPtr, ScalarPointer valuePtr)
SparseMapBase(Index rows, Index cols, Index nnz, IndexPointer outerIndexPtr, IndexPointer innerIndexPtr, ScalarPointer valuePtr, IndexPointer innerNonZerosPtr=0)
internal::traits< Derived >::Scalar Scalar
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
IndexPointer m_outerIndex
IndexPointer m_innerNonZeros
IndexPointer m_innerIndices
evaluator< SparseCompressedBase< Map< SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > > > Base
Scalar coeff(Index row, Index col) const
SparseMapBase(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
const StorageIndex * innerIndexPtr() const
SparseCompressedBase< Derived > Base
const unsigned int NestByRefBit
internal::conditional< bool(internal::is_lvalue< Derived >::value), Scalar *, const Scalar * >::type ScalarPointer
Map(Index rows, Index cols, Index nnz, const StorageIndex *outerIndexPtr, const StorageIndex *innerIndexPtr, const Scalar *valuePtr, const StorageIndex *innerNonZerosPtr=0)
evaluator< SparseCompressedBase< Map< const SparseMatrix< MatScalar, MatOptions, MatIndex >, Options, StrideType > > > Base
SparseMapBase< Map > Base
SparseMapBase(Index size, Index nnz, StorageIndex *innerIndexPtr, Scalar *valuePtr)
Common base class for sparse [compressed]-{row|column}-storage format.
SparseMatrix< MatScalar, MatOptions, MatIndex > PlainObjectType
Array< StorageIndex, 2, 1 > m_zero_nnz
bool isCompressed() const
Base::StorageIndex StorageIndex