10#ifndef EIGEN_SPARSE_MAP_H
11#define EIGEN_SPARSE_MAP_H
13#include "./InternalHeaderCheck.h"
19template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
20struct traits<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
21 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
23 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType;
24 typedef traits<PlainObjectType> TraitsBase;
26 Flags = TraitsBase::Flags & (~NestByRefBit)
30template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
31struct traits<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
32 :
public traits<SparseMatrix<MatScalar,MatOptions,MatIndex> >
34 typedef SparseMatrix<MatScalar,MatOptions,MatIndex> PlainObjectType;
35 typedef traits<PlainObjectType> TraitsBase;
37 Flags = TraitsBase::Flags & (~ (NestByRefBit |
LvalueBit))
43template<
typename Derived,
51template<
typename Derived>
57 typedef typename Base::Scalar Scalar;
59 enum { IsRowMajor = Base::IsRowMajor };
60 using Base::operator=;
63 typedef typename internal::conditional<
64 bool(internal::is_lvalue<Derived>::value),
65 Scalar *,
const Scalar *>::type ScalarPointer;
66 typedef typename internal::conditional<
67 bool(internal::is_lvalue<Derived>::value),
68 StorageIndex *,
const StorageIndex *>::type IndexPointer;
73 IndexPointer m_outerIndex;
74 IndexPointer m_innerIndices;
75 ScalarPointer m_values;
76 IndexPointer m_innerNonZeros;
81 inline Index rows()
const {
return IsRowMajor ? m_outerSize : m_innerSize; }
83 inline Index cols()
const {
return IsRowMajor ? m_innerSize : m_outerSize; }
97 inline const Scalar*
valuePtr()
const {
return m_values; }
99 inline const StorageIndex*
innerIndexPtr()
const {
return m_innerIndices; }
109 const Index outer = IsRowMajor ? row : col;
110 const Index inner = IsRowMajor ? col : row;
112 Index start = m_outerIndex[outer];
113 Index end = isCompressed() ? m_outerIndex[outer+1] : start + m_innerNonZeros[outer];
116 else if (
end>0 && inner==m_innerIndices[
end-1])
117 return m_values[
end-1];
121 const StorageIndex* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[
end-1],inner);
122 const Index id = r-&m_innerIndices[0];
123 return ((*r==inner) && (
id<
end)) ? m_values[id] : Scalar(0);
126 inline SparseMapBase(
Index rows,
Index cols,
Index nnz, IndexPointer outerIndexPtr, IndexPointer innerIndexPtr,
127 ScalarPointer valuePtr, IndexPointer innerNonZerosPtr = 0)
128 : m_outerSize(IsRowMajor?rows:cols), m_innerSize(IsRowMajor?cols:rows), m_zero_nnz(0,internal::convert_index<StorageIndex>(nnz)), m_outerIndex(outerIndexPtr),
129 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(innerNonZerosPtr)
133 inline SparseMapBase(
Index size,
Index nnz, IndexPointer innerIndexPtr, ScalarPointer valuePtr)
134 : m_outerSize(1), m_innerSize(size), m_zero_nnz(0,internal::convert_index<StorageIndex>(nnz)), m_outerIndex(m_zero_nnz.data()),
135 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(0)
142 inline SparseMapBase() {}
149template<
typename Derived>
151 :
public SparseMapBase<Derived,ReadOnlyAccessors>
157 typedef typename Base::Scalar Scalar;
159 enum { IsRowMajor = Base::IsRowMajor };
161 using Base::operator=;
167 using Base::valuePtr;
168 using Base::innerIndexPtr;
169 using Base::outerIndexPtr;
170 using Base::innerNonZeroPtr;
172 inline Scalar*
valuePtr() {
return Base::m_values; }
184 const Index outer = IsRowMajor ? row : col;
185 const Index inner = IsRowMajor ? col : row;
187 Index start = Base::m_outerIndex[outer];
188 Index end = Base::isCompressed() ? Base::m_outerIndex[outer+1] : start + Base::m_innerNonZeros[outer];
189 eigen_assert(
end>=start &&
"you probably called coeffRef on a non finalized matrix");
190 eigen_assert(
end>start &&
"coeffRef cannot be called on a zero coefficient");
191 StorageIndex* r = std::lower_bound(&Base::m_innerIndices[start],&Base::m_innerIndices[
end],inner);
192 const Index id = r - &Base::m_innerIndices[0];
193 eigen_assert((*r==inner) && (
id<
end) &&
"coeffRef cannot be called on a zero coefficient");
194 return const_cast<Scalar*
>(Base::m_values)[
id];
197 inline SparseMapBase(
Index rows,
Index cols,
Index nnz, StorageIndex* outerIndexPtr, StorageIndex* innerIndexPtr,
198 Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0)
199 : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
203 inline SparseMapBase(
Index size,
Index nnz, StorageIndex* innerIndexPtr, Scalar* valuePtr)
204 : Base(size, nnz, innerIndexPtr, valuePtr)
211 inline SparseMapBase() {}
222#ifndef EIGEN_PARSED_BY_DOXYGEN
223template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
224class Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
225 :
public SparseMapBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
227template<typename SparseMatrixType>
228class
Map<SparseMatrixType>
229 :
public SparseMapBase<Derived,WriteAccessors>
233 typedef SparseMapBase<Map>
Base;
234 EIGEN_SPARSE_PUBLIC_INTERFACE(
Map)
235 enum { IsRowMajor = Base::IsRowMajor };
248 StorageIndex* innerIndexPtr, Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0)
249 :
Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
251#ifndef EIGEN_PARSED_BY_DOXYGEN
256template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
257class Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
258 :
public SparseMapBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
261 typedef SparseMapBase<Map> Base;
262 EIGEN_SPARSE_PUBLIC_INTERFACE(
Map)
263 enum { IsRowMajor = Base::IsRowMajor };
273 const StorageIndex* innerIndexPtr,
const Scalar* valuePtr,
const StorageIndex* innerNonZerosPtr = 0)
274 :
Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
283template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
284struct evaluator<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
285 : evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
287 typedef evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
288 typedef Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
289 evaluator() : Base() {}
290 explicit evaluator(
const XprType &mat) : Base(mat) {}
293template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
294struct evaluator<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
295 : evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
297 typedef evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
298 typedef Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
299 evaluator() : Base() {}
300 explicit evaluator(
const XprType &mat) : Base(mat) {}
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:49
Base class for dense Map and Block expression with direct access.
Definition: MapBase.h:41
Map(Index rows, Index cols, Index nnz, const StorageIndex *outerIndexPtr, const StorageIndex *innerIndexPtr, const Scalar *valuePtr, const StorageIndex *innerNonZerosPtr=0)
Definition: SparseMap.h:272
Map(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
Definition: SparseMap.h:247
~Map()
Definition: SparseMap.h:278
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:98
Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition: Map.h:131
Common base class for sparse [compressed]-{row|column}-storage format.
Definition: SparseCompressedBase.h:40
Common base class for Map and Ref instance of sparse matrix and vector.
Definition: SparseMap.h:54
Index innerSize() const
Definition: SparseMap.h:85
Index cols() const
Definition: SparseMap.h:83
const StorageIndex * innerIndexPtr() const
Definition: SparseMap.h:99
const Scalar * valuePtr() const
Definition: SparseMap.h:97
Scalar coeff(Index row, Index col) const
Definition: SparseMap.h:107
Index rows() const
Definition: SparseMap.h:81
Index outerSize() const
Definition: SparseMap.h:87
Index nonZeros() const
Definition: SparseMap.h:89
const StorageIndex * innerNonZeroPtr() const
Definition: SparseMap.h:103
bool isCompressed() const
Definition: SparseMap.h:92
~SparseMapBase()
Definition: SparseMap.h:139
const StorageIndex * outerIndexPtr() const
Definition: SparseMap.h:101
Scalar & coeffRef(Index row, Index col)
Definition: SparseMap.h:182
Scalar * valuePtr()
Definition: SparseMap.h:172
StorageIndex * innerNonZeroPtr()
Definition: SparseMap.h:178
~SparseMapBase()
Definition: SparseMap.h:208
StorageIndex * outerIndexPtr()
Definition: SparseMap.h:176
StorageIndex * innerIndexPtr()
Definition: SparseMap.h:174
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:30
internal::traits< Derived >::StorageIndex StorageIndex
Definition: SparseMatrixBase.h:45
static const lastp1_t end
Definition: IndexedViewHelper.h:183
@ ReadOnlyAccessors
Definition: Constants.h:378
@ WriteAccessors
Definition: Constants.h:380
const unsigned int LvalueBit
Definition: Constants.h:146
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41