10 #ifndef EIGEN_SPARSEMATRIXBASE_H 11 #define EIGEN_SPARSEMATRIXBASE_H 26 template<
typename Derived>
class SparseMatrixBase
27 #ifndef EIGEN_PARSED_BY_DOXYGEN
29 typename NumTraits<typename internal::traits<Derived>::Scalar>::Real,
33 #endif // not EIGEN_PARSED_BY_DOXYGEN 47 template<
typename OtherDerived>
79 MaxColsAtCompileTime>::ret),
102 #ifndef EIGEN_PARSED_BY_DOXYGEN
117 #ifndef EIGEN_PARSED_BY_DOXYGEN 137 inline const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
138 inline Derived& derived() {
return *
static_cast<Derived*
>(
this); }
139 inline Derived& const_cast_derived()
const 143 using Base::operator*;
144 #endif // not EIGEN_PARSED_BY_DOXYGEN 146 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase 147 # include "../plugins/CommonCwiseUnaryOps.h" 148 # include "../plugins/CommonCwiseBinaryOps.h" 149 # include "../plugins/MatrixCwiseUnaryOps.h" 150 # include "../plugins/MatrixCwiseBinaryOps.h" 151 # include "../plugins/BlockMethods.h" 152 # ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN 153 # include EIGEN_SPARSEMATRIXBASE_PLUGIN 155 # undef EIGEN_CURRENT_STORAGE_BASE_CLASS 156 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS 159 inline Index
rows()
const {
return derived().rows(); }
161 inline Index
cols()
const {
return derived().cols(); }
167 inline Index
nonZeros()
const {
return derived().nonZeros(); }
180 bool isRValue()
const {
return m_isRValue; }
181 Derived& markAsRValue() { m_isRValue =
true;
return derived(); }
186 template<
typename OtherDerived>
189 other.evalTo(derived());
194 template<
typename OtherDerived>
197 return assign(other.derived());
200 inline Derived& operator=(
const Derived& other)
205 return assign(other.derived());
210 template<
typename OtherDerived>
211 inline Derived& assign(
const OtherDerived& other)
215 if ((!transpose) && other.isRValue())
218 derived().resize(other.rows(), other.cols());
220 derived().reserve((std::max)(this->
rows(),this->
cols())*2);
223 derived().startVec(j);
224 for (
typename OtherDerived::InnerIterator it(other, j); it; ++it)
226 Scalar v = it.value();
227 derived().insertBackByOuterInner(j,it.index()) = v;
230 derived().finalize();
234 assignGeneric(other);
239 template<
typename OtherDerived>
240 inline void assignGeneric(
const OtherDerived& other)
244 (!((
Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) &&
245 "the transpose operation is supposed to be handled in SparseMatrix::operator=");
247 enum { Flip = (
Flags &
RowMajorBit) != (OtherDerived::Flags & RowMajorBit) };
249 const Index outerSize = other.outerSize();
252 Derived temp(other.rows(), other.cols());
254 temp.reserve((std::max)(this->
rows(),this->
cols())*2);
258 for (
typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
260 Scalar v = it.value();
261 temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
266 derived() = temp.markAsRValue();
271 template<
typename Lhs,
typename Rhs>
274 friend std::ostream & operator << (std::ostream & s,
const SparseMatrixBase& m)
276 typedef typename Derived::Nested Nested;
279 if (
Flags&RowMajorBit)
281 const Nested nm(m.derived());
282 for (Index
row=0;
row<nm.outerSize(); ++
row)
285 for (
typename NestedCleaned::InnerIterator it(nm.derived(),
row); it; ++it)
287 for ( ; col<it.index(); ++
col)
289 s << it.value() <<
" ";
299 const Nested nm(m.derived());
302 for (
typename NestedCleaned::InnerIterator it(nm.derived(), 0); it; ++it)
304 for ( ; row<it.index(); ++
row)
305 s <<
"0" << std::endl;
306 s << it.value() << std::endl;
310 s <<
"0" << std::endl;
315 s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit, Index> >&>(trans);
321 template<
typename OtherDerived>
323 template<
typename OtherDerived>
326 Derived& operator*=(
const Scalar& other);
327 Derived& operator/=(
const Scalar& other);
339 template<
typename OtherDerived>
340 EIGEN_STRONG_INLINE
const typename CwiseProductDenseReturnType<OtherDerived>::Type
344 template<
typename OtherDerived>
349 template<
typename OtherDerived>
354 template<
typename OtherDerived>
friend 360 template<
typename OtherDerived>
friend 366 template<
typename OtherDerived>
377 template<
typename OtherDerived>
380 #ifdef EIGEN2_SUPPORT 382 template<
typename OtherDerived>
387 template<
typename OtherDerived>
389 #endif // EIGEN2_SUPPORT 399 RealScalar squaredNorm()
const;
400 RealScalar norm()
const;
401 RealScalar blueNorm()
const;
405 const AdjointReturnType adjoint()
const {
return transpose(); }
411 const ConstInnerVectorReturnType
innerVector(Index outer)
const;
416 InnerVectorsReturnType
innerVectors(Index outerStart, Index outerSize);
417 const ConstInnerVectorsReturnType
innerVectors(Index outerStart, Index outerSize)
const;
420 template<
typename DenseDerived>
425 for (
typename Derived::InnerIterator i(derived(),j); i; ++i)
426 dst.coeffRef(i.row(),i.col()) = i.value();
434 template<
typename OtherDerived>
437 {
return toDense().isApprox(other.toDense(),prec); }
439 template<
typename OtherDerived>
442 {
return toDense().isApprox(other,prec); }
461 #endif // EIGEN_SPARSEMATRIXBASE_H Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:49
Index nonZeros() const
Definition: SparseMatrixBase.h:167
Index innerSize() const
Definition: SparseMatrixBase.h:178
Index cols() const
Definition: SparseMatrixBase.h:161
friend const DenseSparseProductReturnType< OtherDerived, Derived >::Type operator*(const MatrixBase< OtherDerived > &lhs, const Derived &rhs)
dense * sparse (return a dense object unless it is an outer product)
Definition: SparseMatrixBase.h:362
Definition: SparseProduct.h:80
This is a rough measure of how expensive it is to read one coefficient from this expression.
Definition: SparseMatrixBase.h:92
A versatible sparse matrix representation.
Definition: SparseMatrix.h:85
This stores expression Flags flags which may or may not be inherited by new expressions constructed f...
Definition: SparseMatrixBase.h:87
Definition: SparseSelfAdjointView.h:465
Expression of the transpose of a matrix.
Definition: Transpose.h:57
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array...
Definition: Constants.h:142
RowXpr row(Index i)
Definition: SparseMatrixBase.h:750
Derived & setZero()
Sets all coefficients in this expression to zero.
Definition: CwiseNullaryOp.h:499
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:49
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:539
Index outerSize() const
Definition: SparseMatrixBase.h:175
Derived & derived()
Definition: EigenBase.h:34
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
This is equal to the number of coefficients, i.e.
Definition: SparseMatrixBase.h:69
bool isVector() const
Definition: SparseMatrixBase.h:172
Definition: DenseCoeffsBase.h:16
Definition: SparseTriangularView.h:25
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:26
The number of rows at compile-time.
Definition: SparseMatrixBase.h:56
Definition: ReturnByValue.h:50
Index size() const
Definition: SparseMatrixBase.h:164
Definition: Functors.h:47
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:107
Index rows() const
Definition: SparseMatrixBase.h:159
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:239
Definition: XprHelper.h:371
InnerVectorReturnType innerVector(Index outer)
Definition: SparseBlock.h:380
The number of columns at compile-time.
Definition: SparseMatrixBase.h:62
Definition: SparseMatrixBase.h:329
Definition: SparseDenseProduct.h:258
Definition: SparseDenseProduct.h:288
InnerVectorsReturnType innerVectors(Index outerStart, Index outerSize)
Definition: SparseBlock.h:395
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
This is set to true if either the number of rows or the number of columns is known at compile-time to...
Definition: SparseMatrixBase.h:81
Definition: DiagonalMatrix.h:18
Definition: SparseDiagonalProduct.h:59
Matrix< Scalar, EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime), EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime)> SquareMatrixType
type of the equivalent square matrix
Definition: SparseMatrixBase.h:135
const internal::eval< Derived >::type eval() const
Definition: SparseMatrixBase.h:449
ColXpr col(Index i)
Definition: SparseMatrixBase.h:733
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
const SparseDenseProductReturnType< Derived, OtherDerived >::Type operator*(const MatrixBase< OtherDerived > &other) const
sparse * dense (returns a dense object unless it is an outer product)
Definition: SparseMatrixBase.h:368
NumTraits< Scalar >::Real RealScalar
This is the "real scalar" type; if the Scalar type is already real numbers (e.g.
Definition: SparseMatrixBase.h:124
SparseSymmetricPermutationProduct< Derived, Upper|Lower > twistedBy(const PermutationMatrix< Dynamic, Dynamic, Index > &perm) const
Definition: SparseMatrixBase.h:372
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
Definition: XprHelper.h:203
Definition: XprHelper.h:161