10#ifndef EIGEN_SPARSEMATRIXBASE_H
11#define EIGEN_SPARSEMATRIXBASE_H
26template<
typename Derived>
class SparseMatrixBase
27#ifndef EIGEN_PARSED_BY_DOXYGEN
28 :
public internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
29 typename NumTraits<typename internal::traits<Derived>::Scalar>::Real,
37 typedef typename internal::traits<Derived>::Scalar Scalar;
38 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
39 typedef typename internal::traits<Derived>::StorageKind StorageKind;
40 typedef typename internal::traits<Derived>::Index Index;
41 typedef typename internal::traits<Derived>::Index StorageIndex;
42 typedef typename internal::add_const_on_value_type_if_arithmetic<
43 typename internal::packet_traits<Scalar>::type
44 >::type PacketReturnType;
46 typedef SparseMatrixBase StorageBaseType;
48 template<
typename OtherDerived>
70 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
71 internal::traits<Derived>::ColsAtCompileTime>::ret),
79 MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
80 MaxColsAtCompileTime>::ret),
88 Flags = internal::traits<Derived>::Flags,
103 #ifndef EIGEN_PARSED_BY_DOXYGEN
109 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
112 >::type AdjointReturnType;
118#ifndef EIGEN_PARSED_BY_DOXYGEN
125 typedef typename NumTraits<Scalar>::Real RealScalar;
129 typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType;
138 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
139 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
140 inline Derived& const_cast_derived()
const
141 {
return *
static_cast<Derived*
>(
const_cast<SparseMatrixBase*
>(
this)); }
143 typedef internal::special_scalar_op_base<Derived, Scalar, RealScalar, EigenBase<Derived> > Base;
144 using Base::operator*;
147#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
148# include "../plugins/CommonCwiseUnaryOps.h"
149# include "../plugins/CommonCwiseBinaryOps.h"
150# include "../plugins/MatrixCwiseUnaryOps.h"
151# include "../plugins/MatrixCwiseBinaryOps.h"
152# include "../plugins/BlockMethods.h"
153# ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN
154# include EIGEN_SPARSEMATRIXBASE_PLUGIN
156# undef EIGEN_CURRENT_STORAGE_BASE_CLASS
157#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
181 bool isRValue()
const {
return m_isRValue; }
182 Derived& markAsRValue() { m_isRValue =
true;
return derived(); }
184 SparseMatrixBase() : m_isRValue(false) { }
187 template<
typename OtherDerived>
188 Derived& operator=(
const ReturnByValue<OtherDerived>& other)
195 template<
typename OtherDerived>
198 return assign(other.
derived());
201 inline Derived& operator=(
const Derived& other)
206 return assign(other.derived());
211 template<
typename OtherDerived>
212 inline Derived& assign(
const OtherDerived& other)
216 if ((!transpose) && other.isRValue())
219 derived().resize(other.rows(), other.cols());
225 for (
typename OtherDerived::InnerIterator it(other, j); it; ++it)
227 Scalar v = it.value();
228 derived().insertBackByOuterInner(j,it.index()) = v;
235 assignGeneric(other);
240 template<
typename OtherDerived>
241 inline void assignGeneric(
const OtherDerived& other)
244 eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) ||
246 "the transpose operation is supposed to be handled in SparseMatrix::operator=");
250 const Index
outerSize = other.outerSize();
253 Derived temp(other.rows(), other.cols());
255 temp.reserve((std::max)(this->
rows(),this->
cols())*2);
259 for (
typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
261 Scalar v = it.value();
262 temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
267 derived() = temp.markAsRValue();
272 template<
typename Lhs,
typename Rhs>
273 inline Derived& operator=(
const SparseSparseProduct<Lhs,Rhs>& product);
275 friend std::ostream & operator << (std::ostream & s,
const SparseMatrixBase& m)
277 typedef typename Derived::Nested Nested;
278 typedef typename internal::remove_all<Nested>::type NestedCleaned;
282 const Nested nm(m.derived());
286 for (
typename NestedCleaned::InnerIterator it(nm.derived(),
row); it; ++it)
288 for ( ;
col<it.index(); ++
col)
290 s << it.value() <<
" ";
293 for ( ; col<m.cols(); ++col)
300 const Nested nm(m.derived());
303 for (
typename NestedCleaned::InnerIterator it(nm.derived(), 0); it; ++it)
305 for ( ;
row<it.index(); ++
row)
306 s <<
"0" << std::endl;
307 s << it.value() << std::endl;
310 for ( ; row<m.rows(); ++row)
311 s <<
"0" << std::endl;
316 s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit, Index> >&>(trans);
322 template<
typename OtherDerived>
323 Derived& operator+=(
const SparseMatrixBase<OtherDerived>& other);
324 template<
typename OtherDerived>
325 Derived& operator-=(
const SparseMatrixBase<OtherDerived>& other);
327 Derived& operator*=(
const Scalar& other);
328 Derived& operator/=(
const Scalar& other);
330 template<
typename OtherDerived>
struct CwiseProductDenseReturnType {
331 typedef CwiseBinaryOp<internal::scalar_product_op<
typename internal::scalar_product_traits<
332 typename internal::traits<Derived>::Scalar,
333 typename internal::traits<OtherDerived>::Scalar
340 template<
typename OtherDerived>
341 EIGEN_STRONG_INLINE
const typename CwiseProductDenseReturnType<OtherDerived>::Type
345 template<
typename OtherDerived>
346 const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
347 operator*(
const SparseMatrixBase<OtherDerived> &other)
const;
350 template<
typename OtherDerived>
351 const SparseDiagonalProduct<Derived,OtherDerived>
352 operator*(
const DiagonalBase<OtherDerived> &other)
const;
355 template<
typename OtherDerived>
friend
356 const SparseDiagonalProduct<OtherDerived,Derived>
357 operator*(
const DiagonalBase<OtherDerived> &lhs,
const SparseMatrixBase& rhs)
358 {
return SparseDiagonalProduct<OtherDerived,Derived>(lhs.derived(), rhs.
derived()); }
361 template<
typename OtherDerived>
friend
362 const typename DenseSparseProductReturnType<OtherDerived,Derived>::Type
364 {
return typename DenseSparseProductReturnType<OtherDerived,Derived>::Type(lhs.derived(),rhs); }
367 template<
typename OtherDerived>
368 const typename SparseDenseProductReturnType<Derived,OtherDerived>::Type
370 {
return typename SparseDenseProductReturnType<Derived,OtherDerived>::Type(
derived(), other.derived()); }
375 return SparseSymmetricPermutationProduct<Derived,Upper|Lower>(
derived(), perm);
378 template<
typename OtherDerived>
381 #ifdef EIGEN2_SUPPORT
383 template<
typename OtherDerived>
384 typename internal::plain_matrix_type_column_major<OtherDerived>::type
388 template<
typename OtherDerived>
393 inline const SparseTriangularView<Derived, Mode> triangularView()
const;
399 template<
typename OtherDerived> Scalar dot(
const SparseMatrixBase<OtherDerived>& other)
const;
400 RealScalar squaredNorm()
const;
401 RealScalar norm()
const;
402 RealScalar blueNorm()
const;
406 const AdjointReturnType adjoint()
const {
return transpose(); }
421 template<
typename DenseDerived>
426 for (
typename Derived::InnerIterator i(
derived(),j); i; ++i)
427 dst.coeffRef(i.row(),i.col()) = i.
value();
435 template<
typename OtherDerived>
436 bool isApprox(
const SparseMatrixBase<OtherDerived>& other,
437 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const
438 {
return toDense().isApprox(other.toDense(),prec); }
440 template<
typename OtherDerived>
442 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const
443 {
return toDense().
isApprox(other,prec); }
450 inline const typename internal::eval<Derived>::type
eval()
const
451 {
return typename internal::eval<Derived>::type(
derived()); }
Expression of a fixed-size or dynamic-size block.
Definition Block.h:104
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:112
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:51
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:61
bool isApprox(const DenseBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Fuzzy.h:98
Derived & setZero()
Definition CwiseNullaryOp.h:499
CoeffReturnType value() const
Definition DenseBase.h:422
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:129
Permutation matrix.
Definition PermutationMatrix.h:313
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:34
Index cols() const
Definition SparseMatrixBase.h:162
const SparseDenseProductReturnType< Derived, OtherDerived >::Type operator*(const MatrixBase< OtherDerived > &other) const
Definition SparseMatrixBase.h:369
Index nonZeros() const
Definition SparseMatrixBase.h:168
const ScalarMultipleReturnType operator*(const Scalar &scalar) const
Definition SparseMatrixBase.h:50
Index innerSize() const
Definition SparseMatrixBase.h:179
Index size() const
Definition SparseMatrixBase.h:165
friend const DenseSparseProductReturnType< OtherDerived, Derived >::Type operator*(const MatrixBase< OtherDerived > &lhs, const Derived &rhs)
Definition SparseMatrixBase.h:363
bool isVector() const
Definition SparseMatrixBase.h:173
const ConstInnerVectorReturnType innerVector(Index outer) const
Definition SparseBlock.h:387
const internal::eval< Derived >::type eval() const
Definition SparseMatrixBase.h:450
const SparseSparseProductReturnType< Derived, OtherDerived >::Type operator*(const SparseMatrixBase< OtherDerived > &other) const
Definition SparseProduct.h:181
ColXpr col(Index i)
Definition SparseMatrixBase.h:733
InnerVectorReturnType innerVector(Index outer)
Definition SparseBlock.h:380
InnerVectorsReturnType innerVectors(Index outerStart, Index outerSize)
Definition SparseBlock.h:395
RowXpr row(Index i)
Definition SparseMatrixBase.h:750
SparseSymmetricPermutationProduct< Derived, Upper|Lower > twistedBy(const PermutationMatrix< Dynamic, Dynamic, Index > &perm) const
Definition SparseMatrixBase.h:373
Index rows() const
Definition SparseMatrixBase.h:160
Index outerSize() const
Definition SparseMatrixBase.h:176
const ConstInnerVectorsReturnType innerVectors(Index outerStart, Index outerSize) const
Definition SparseBlock.h:408
const CwiseBinaryOp< internal::scalar_product_op< typename Derived ::Scalar, typename OtherDerived ::Scalar >, const Derived, const OtherDerived > cwiseProduct(const Eigen::SparseMatrixBase< OtherDerived > &other) const
Definition SparseMatrixBase.h:23
@ CoeffReadCost
Definition SparseMatrixBase.h:93
@ RowsAtCompileTime
Definition SparseMatrixBase.h:57
@ IsVectorAtCompileTime
Definition SparseMatrixBase.h:82
@ Flags
Definition SparseMatrixBase.h:88
@ SizeAtCompileTime
Definition SparseMatrixBase.h:70
@ ColsAtCompileTime
Definition SparseMatrixBase.h:63
A versatible sparse matrix representation.
Definition SparseMatrix.h:87
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseSelfAdjointView.h:51
Expression of the transpose of a matrix.
Definition Transpose.h:59
const unsigned int DirectAccessBit
Definition Constants.h:142
const unsigned int RowMajorBit
Definition Constants.h:53
Definition EigenBase.h:27
Derived & derived()
Definition EigenBase.h:34