10#ifndef EIGEN_SPARSEMATRIXBASE_H
11#define EIGEN_SPARSEMATRIXBASE_H
13#include "./InternalHeaderCheck.h"
33 typedef typename internal::traits<Derived>::Scalar Scalar;
40 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
41 typedef typename internal::traits<Derived>::StorageKind StorageKind;
45 typedef typename internal::traits<Derived>::StorageIndex
StorageIndex;
47 typedef typename internal::add_const_on_value_type_if_arithmetic<
48 typename internal::packet_traits<Scalar>::type
49 >::type PacketReturnType;
56 template<
typename OtherDerived>
74 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
75 internal::traits<Derived>::ColsAtCompileTime>::ret),
83 MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
84 MaxColsAtCompileTime>::ret),
97 Flags = internal::traits<Derived>::Flags,
107 #ifndef EIGEN_PARSED_BY_DOXYGEN
113 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
116 >::type AdjointReturnType;
123#ifndef EIGEN_PARSED_BY_DOXYGEN
134 typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType;
145 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
146 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
147 inline Derived& const_cast_derived()
const
148 {
return *
static_cast<Derived*
>(
const_cast<SparseMatrixBase*
>(
this)); }
150 typedef EigenBase<Derived> Base;
154#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
155#ifdef EIGEN_PARSED_BY_DOXYGEN
156#define EIGEN_DOC_UNARY_ADDONS(METHOD,OP)
157#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
158#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
160#define EIGEN_DOC_UNARY_ADDONS(X,Y)
161#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
162#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
164# include "../plugins/CommonCwiseUnaryOps.h"
165# include "../plugins/CommonCwiseBinaryOps.h"
166# include "../plugins/MatrixCwiseUnaryOps.h"
167# include "../plugins/MatrixCwiseBinaryOps.h"
168# include "../plugins/BlockMethods.h"
169# ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN
170# include EIGEN_SPARSEMATRIXBASE_PLUGIN
172#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
173#undef EIGEN_DOC_UNARY_ADDONS
174#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
175#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
196 bool isRValue()
const {
return m_isRValue; }
197 Derived& markAsRValue() { m_isRValue =
true;
return derived(); }
199 SparseMatrixBase() : m_isRValue(false) { }
202 template<
typename OtherDerived>
203 Derived& operator=(
const ReturnByValue<OtherDerived>& other);
205 template<
typename OtherDerived>
206 inline Derived& operator=(
const SparseMatrixBase<OtherDerived>& other);
208 inline Derived& operator=(
const Derived& other);
212 template<
typename OtherDerived>
213 inline Derived& assign(
const OtherDerived& other);
215 template<
typename OtherDerived>
216 inline void assignGeneric(
const OtherDerived& other);
220 friend std::ostream & operator << (std::ostream & s,
const SparseMatrixBase& m)
222 typedef typename Derived::Nested Nested;
223 typedef typename internal::remove_all<Nested>::type NestedCleaned;
227 Nested nm(m.derived());
228 internal::evaluator<NestedCleaned> thisEval(nm);
229 for (
Index row=0; row<nm.outerSize(); ++row)
232 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, row); it; ++it)
234 for ( ; col<it.index(); ++col)
236 s << it.value() <<
" ";
239 for ( ; col<m.cols(); ++col)
246 Nested nm(m.derived());
247 internal::evaluator<NestedCleaned> thisEval(nm);
250 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, 0); it; ++it)
252 for ( ; row<it.index(); ++row)
253 s <<
"0" << std::endl;
254 s << it.value() << std::endl;
257 for ( ; row<m.rows(); ++row)
258 s <<
"0" << std::endl;
262 SparseMatrix<Scalar, RowMajorBit, StorageIndex> trans = m;
263 s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit, StorageIndex> >&>(trans);
269 template<
typename OtherDerived>
270 Derived& operator+=(
const SparseMatrixBase<OtherDerived>& other);
271 template<
typename OtherDerived>
272 Derived& operator-=(
const SparseMatrixBase<OtherDerived>& other);
274 template<
typename OtherDerived>
275 Derived& operator+=(
const DiagonalBase<OtherDerived>& other);
276 template<
typename OtherDerived>
277 Derived& operator-=(
const DiagonalBase<OtherDerived>& other);
279 template<
typename OtherDerived>
280 Derived& operator+=(
const EigenBase<OtherDerived> &other);
281 template<
typename OtherDerived>
282 Derived& operator-=(
const EigenBase<OtherDerived> &other);
284 Derived& operator*=(
const Scalar& other);
285 Derived& operator/=(
const Scalar& other);
287 template<
typename OtherDerived>
struct CwiseProductDenseReturnType {
288 typedef CwiseBinaryOp<internal::scalar_product_op<
typename ScalarBinaryOpTraits<
289 typename internal::traits<Derived>::Scalar,
290 typename internal::traits<OtherDerived>::Scalar
297 template<
typename OtherDerived>
298 EIGEN_STRONG_INLINE
const typename CwiseProductDenseReturnType<OtherDerived>::Type
299 cwiseProduct(
const MatrixBase<OtherDerived> &other)
const;
302 template<
typename OtherDerived>
303 const Product<Derived,OtherDerived>
304 operator*(
const DiagonalBase<OtherDerived> &other)
const
305 {
return Product<Derived,OtherDerived>(
derived(), other.derived()); }
308 template<
typename OtherDerived>
friend
309 const Product<OtherDerived,Derived>
310 operator*(
const DiagonalBase<OtherDerived> &lhs,
const SparseMatrixBase& rhs)
311 {
return Product<OtherDerived,Derived>(lhs.derived(), rhs.derived()); }
314 template<
typename OtherDerived>
315 const Product<Derived,OtherDerived,AliasFreeProduct>
316 operator*(
const SparseMatrixBase<OtherDerived> &other)
const;
319 template<
typename OtherDerived>
320 const Product<Derived,OtherDerived>
321 operator*(
const MatrixBase<OtherDerived> &other)
const
322 {
return Product<Derived,OtherDerived>(
derived(), other.derived()); }
325 template<
typename OtherDerived>
friend
326 const Product<OtherDerived,Derived>
327 operator*(
const MatrixBase<OtherDerived> &lhs,
const SparseMatrixBase& rhs)
328 {
return Product<OtherDerived,Derived>(lhs.derived(), rhs.derived()); }
333 return SparseSymmetricPermutationProduct<Derived,Upper|Lower>(
derived(), perm);
336 template<
typename OtherDerived>
343 template<
unsigned int UpLo>
struct ConstSelfAdjointViewReturnType {
typedef const SparseSelfAdjointView<const Derived, UpLo> Type; };
345 template<
unsigned int UpLo>
inline
346 typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView()
const;
347 template<
unsigned int UpLo>
inline
348 typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
350 template<
typename OtherDerived> Scalar dot(
const MatrixBase<OtherDerived>& other)
const;
351 template<
typename OtherDerived> Scalar dot(
const SparseMatrixBase<OtherDerived>& other)
const;
352 RealScalar squaredNorm()
const;
353 RealScalar norm()
const;
354 RealScalar blueNorm()
const;
356 TransposeReturnType transpose() {
return TransposeReturnType(
derived()); }
357 const ConstTransposeReturnType transpose()
const {
return ConstTransposeReturnType(
derived()); }
358 const AdjointReturnType adjoint()
const {
return AdjointReturnType(transpose()); }
360 DenseMatrixType toDense()
const
362 return DenseMatrixType(
derived());
365 template<
typename OtherDerived>
366 bool isApprox(
const SparseMatrixBase<OtherDerived>& other,
367 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const;
369 template<
typename OtherDerived>
370 bool isApprox(
const MatrixBase<OtherDerived>& other,
371 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const
372 {
return toDense().isApprox(other,prec); }
379 inline const typename internal::eval<Derived>::type
eval()
const
380 {
return typename internal::eval<Derived>::type(
derived()); }
392 return internal::convert_index<StorageIndex>(idx);
395 template<
typename Dest>
void evalTo(Dest &)
const;
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:63
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:58
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:67
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:30
internal::traits< Derived >::StorageIndex StorageIndex
Definition: SparseMatrixBase.h:45
Index size() const
Definition: SparseMatrixBase.h:183
Index innerSize() const
Definition: SparseMatrixBase.h:194
Index rows() const
Definition: SparseMatrixBase.h:178
bool isVector() const
Definition: SparseMatrixBase.h:188
@ IsVectorAtCompileTime
Definition: SparseMatrixBase.h:86
@ NumDimensions
Definition: SparseMatrixBase.h:92
@ ColsAtCompileTime
Definition: SparseMatrixBase.h:67
@ Flags
Definition: SparseMatrixBase.h:97
@ RowsAtCompileTime
Definition: SparseMatrixBase.h:61
@ SizeAtCompileTime
Definition: SparseMatrixBase.h:74
Scalar value_type
Definition: SparseMatrixBase.h:38
Index outerSize() const
Definition: SparseMatrixBase.h:191
const SparseView< Derived > pruned(const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
Definition: SparseView.h:248
Index cols() const
Definition: SparseMatrixBase.h:180
SparseSymmetricPermutationProduct< Derived, Upper|Lower > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
Definition: SparseMatrixBase.h:331
const internal::eval< Derived >::type eval() const
Definition: SparseMatrixBase.h:379
A versatible sparse matrix representation.
Definition: SparseMatrix.h:100
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:47
Expression of a dense or sparse matrix with zero or too small values removed.
Definition: SparseView.h:48
Expression of the transpose of a matrix.
Definition: Transpose.h:56
Expression of a triangular part in a matrix.
Definition: TriangularMatrix.h:191
const unsigned int DirectAccessBit
Definition: Constants.h:157
const unsigned int RowMajorBit
Definition: Constants.h:68
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
Definition: EigenBase.h:32
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41
Derived & derived()
Definition: EigenBase.h:48
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:235