10 #ifndef EIGEN_SPARSE_MAP_H
11 #define EIGEN_SPARSE_MAP_H
19 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
20 struct 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;
30 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
31 struct 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;
43 template<
typename Derived,
51 template<
typename Derived>
59 enum { IsRowMajor = Base::IsRowMajor };
60 using Base::operator=;
63 typedef std::conditional_t<
64 bool(internal::is_lvalue<Derived>::value),
66 typedef std::conditional_t<
67 bool(internal::is_lvalue<Derived>::value),
81 inline Index rows()
const {
return IsRowMajor ? m_outerSize : m_innerSize; }
83 inline Index cols()
const {
return IsRowMajor ? m_innerSize : m_outerSize; }
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);
129 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(innerNonZerosPtr)
135 m_innerIndices(innerIndexPtr), m_values(valuePtr), m_innerNonZeros(0)
149 template<
typename Derived>
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;
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];
199 :
Base(
rows,
cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
204 :
Base(
size, nnz, innerIndexPtr, valuePtr)
222 #ifndef EIGEN_PARSED_BY_DOXYGEN
223 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
224 class Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
225 :
public SparseMapBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
227 template<typename SparseMatrixType>
228 class
Map<SparseMatrixType>
235 enum { IsRowMajor = Base::IsRowMajor };
250 :
Base(
rows,
cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
252 #ifndef EIGEN_PARSED_BY_DOXYGEN
257 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
258 class Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
259 :
public SparseMapBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
262 typedef SparseMapBase<Map>
Base;
264 enum { IsRowMajor = Base::IsRowMajor };
275 :
Base(
rows,
cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
284 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
285 struct evaluator<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
286 : evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
288 typedef evaluator<SparseCompressedBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
289 typedef Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
290 evaluator() : Base() {}
291 explicit evaluator(
const XprType &
mat) : Base(
mat) {}
294 template<
typename MatScalar,
int MatOptions,
typename MatIndex,
int Options,
typename Str
ideType>
295 struct evaluator<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
296 : evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > >
298 typedef evaluator<SparseCompressedBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > > Base;
299 typedef Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> XprType;
300 evaluator() : Base() {}
301 explicit evaluator(
const XprType &
mat) : Base(
mat) {}
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Base class for dense Map and Block expression with direct access.
SparseMapBase< Map > Base
Map(Index rows, Index cols, Index nnz, const StorageIndex *outerIndexPtr, const StorageIndex *innerIndexPtr, const Scalar *valuePtr, const StorageIndex *innerNonZerosPtr=0)
Map(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
A matrix or vector expression mapping an existing array of data.
Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Common base class for sparse [compressed]-{row|column}-storage format.
Common base class for Map and Ref instance of sparse matrix and vector.
SparseCompressedBase< Derived > Base
Scalar coeff(Index row, Index col) const
const StorageIndex * outerIndexPtr() const
std::conditional_t< bool(internal::is_lvalue< Derived >::value), StorageIndex *, const StorageIndex * > IndexPointer
const StorageIndex * innerNonZeroPtr() const
IndexPointer m_innerIndices
std::conditional_t< bool(internal::is_lvalue< Derived >::value), Scalar *, const Scalar * > ScalarPointer
const Scalar * valuePtr() const
Base::StorageIndex StorageIndex
SparseMapBase(Index rows, Index cols, Index nnz, IndexPointer outerIndexPtr, IndexPointer innerIndexPtr, ScalarPointer valuePtr, IndexPointer innerNonZerosPtr=0)
Array< StorageIndex, 2, 1 > m_zero_nnz
bool isCompressed() const
IndexPointer m_outerIndex
const StorageIndex * innerIndexPtr() const
SparseMapBase(Index size, Index nnz, IndexPointer innerIndexPtr, ScalarPointer valuePtr)
IndexPointer m_innerNonZeros
SparseMapBase(Index size, Index nnz, StorageIndex *innerIndexPtr, Scalar *valuePtr)
StorageIndex * outerIndexPtr()
SparseMapBase(Index rows, Index cols, Index nnz, StorageIndex *outerIndexPtr, StorageIndex *innerIndexPtr, Scalar *valuePtr, StorageIndex *innerNonZerosPtr=0)
Base::StorageIndex StorageIndex
Scalar & coeffRef(Index row, Index col)
MapBase< Derived, ReadOnlyAccessors > ReadOnlyMapBase
SparseMapBase< Derived, ReadOnlyAccessors > Base
StorageIndex * innerIndexPtr()
StorageIndex * innerNonZeroPtr()
Base class of any sparse matrices or sparse expressions.
internal::traits< Derived >::StorageIndex StorageIndex
internal::traits< Derived >::Scalar Scalar
static const lastp1_t end
const unsigned int LvalueBit
IndexDest convert_index(const IndexSrc &idx)
const unsigned int NestByRefBit
Eigen::Index Index
The interface type of indices.