10 #ifndef EIGEN_SPARSEMATRIXBASE_H 11 #define EIGEN_SPARSEMATRIXBASE_H 30 typedef typename internal::traits<Derived>::Scalar Scalar;
31 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
32 typedef typename internal::traits<Derived>::StorageKind StorageKind;
33 typedef typename internal::traits<Derived>::Index Index;
34 typedef typename internal::add_const_on_value_type_if_arithmetic<
35 typename internal::packet_traits<Scalar>::type
36 >::type PacketReturnType;
41 template<
typename OtherDerived>
63 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
64 internal::traits<Derived>::ColsAtCompileTime>::ret),
72 MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
73 MaxColsAtCompileTime>::ret),
81 Flags = internal::traits<Derived>::Flags,
96 #ifndef EIGEN_PARSED_BY_DOXYGEN
102 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
105 >::type AdjointReturnType;
111 #ifndef EIGEN_PARSED_BY_DOXYGEN 122 typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType;
131 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
132 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
133 inline Derived& const_cast_derived()
const 135 #endif // not EIGEN_PARSED_BY_DOXYGEN 137 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase 138 # include "../plugins/CommonCwiseUnaryOps.h" 139 # include "../plugins/CommonCwiseBinaryOps.h" 140 # include "../plugins/MatrixCwiseUnaryOps.h" 141 # include "../plugins/MatrixCwiseBinaryOps.h" 142 # include "../plugins/BlockMethods.h" 143 # ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN 144 # include EIGEN_SPARSEMATRIXBASE_PLUGIN 146 # undef EIGEN_CURRENT_STORAGE_BASE_CLASS 147 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS 171 bool isRValue()
const {
return m_isRValue; }
172 Derived& markAsRValue() { m_isRValue =
true;
return derived(); }
177 template<
typename OtherDerived>
178 Derived& operator=(
const ReturnByValue<OtherDerived>& other)
185 template<
typename OtherDerived>
188 return assign(other.
derived());
191 inline Derived& operator=(
const Derived& other)
196 return assign(other.derived());
201 template<
typename OtherDerived>
202 inline Derived& assign(
const OtherDerived& other)
206 if ((!transpose) && other.isRValue())
209 derived().resize(other.rows(), other.cols());
215 for (
typename OtherDerived::InnerIterator it(other, j); it; ++it)
217 Scalar v = it.value();
218 derived().insertBackByOuterInner(j,it.index()) = v;
225 assignGeneric(other);
230 template<
typename OtherDerived>
231 inline void assignGeneric(
const OtherDerived& other)
234 eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) ||
235 (!((
Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) &&
236 "the transpose operation is supposed to be handled in SparseMatrix::operator=");
240 const Index outerSize = other.outerSize();
243 Derived temp(other.rows(), other.cols());
245 temp.reserve((std::max)(this->
rows(),this->
cols())*2);
249 for (
typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
251 Scalar v = it.value();
252 temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
257 derived() = temp.markAsRValue();
262 template<
typename Lhs,
typename Rhs>
263 inline Derived& operator=(
const SparseSparseProduct<Lhs,Rhs>& product);
265 friend std::ostream & operator << (std::ostream & s,
const SparseMatrixBase& m)
267 typedef typename Derived::Nested Nested;
268 typedef typename internal::remove_all<Nested>::type NestedCleaned;
270 if (
Flags&RowMajorBit)
273 for (Index
row=0;
row<nm.outerSize(); ++
row)
276 for (
typename NestedCleaned::InnerIterator it(nm.derived(),
row); it; ++it)
278 for ( ; col<it.index(); ++
col)
280 s << it.value() <<
" ";
293 for (
typename NestedCleaned::InnerIterator it(nm.derived(), 0); it; ++it)
295 for ( ; row<it.index(); ++
row)
296 s <<
"0" << std::endl;
297 s << it.value() << std::endl;
301 s <<
"0" << std::endl;
306 s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit, Index> >&>(trans);
312 template<
typename OtherDerived>
314 template<
typename OtherDerived>
317 Derived& operator*=(
const Scalar& other);
318 Derived& operator/=(
const Scalar& other);
320 #define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \ 322 internal::scalar_product_op< \ 323 typename internal::scalar_product_traits< \ 324 typename internal::traits<Derived>::Scalar, \ 325 typename internal::traits<OtherDerived>::Scalar \ 332 template<
typename OtherDerived>
333 EIGEN_STRONG_INLINE
const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
337 template<
typename OtherDerived>
338 const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
342 template<
typename OtherDerived>
343 const SparseDiagonalProduct<Derived,OtherDerived>
344 operator*(
const DiagonalBase<OtherDerived> &other)
const;
347 template<
typename OtherDerived>
friend 348 const SparseDiagonalProduct<OtherDerived,Derived>
350 {
return SparseDiagonalProduct<OtherDerived,Derived>(lhs.derived(), rhs.
derived()); }
353 template<
typename OtherDerived>
friend 354 const typename DenseSparseProductReturnType<OtherDerived,Derived>::Type
356 {
return typename DenseSparseProductReturnType<OtherDerived,Derived>::Type(lhs.derived(),rhs); }
359 template<
typename OtherDerived>
360 const typename SparseDenseProductReturnType<Derived,OtherDerived>::Type
366 return SparseSymmetricPermutationProduct<Derived,Upper|Lower>(
derived(), perm);
369 template<
typename OtherDerived>
372 #ifdef EIGEN2_SUPPORT 374 template<
typename OtherDerived>
379 template<
typename OtherDerived>
381 #endif // EIGEN2_SUPPORT 384 inline const SparseTriangularView<Derived, Mode> triangularView()
const;
391 RealScalar squaredNorm()
const;
392 RealScalar norm()
const;
393 RealScalar blueNorm()
const;
397 const AdjointReturnType adjoint()
const {
return transpose(); }
403 const ConstInnerVectorReturnType
innerVector(Index outer)
const;
410 template<
typename DenseDerived>
415 for (
typename Derived::InnerIterator i(
derived(),j); i; ++i)
416 dst.coeffRef(i.row(),i.col()) = i.
value();
424 template<
typename OtherDerived>
427 {
return toDense().isApprox(other.toDense(),prec); }
429 template<
typename OtherDerived>
432 {
return toDense().isApprox(other,prec); }
439 inline const typename internal::eval<Derived>::type
eval()
const 440 {
return typename internal::eval<Derived>::type(
derived()); }
451 #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:158
Index outerSize() const
Definition: SparseMatrixBase.h:166
friend const DenseSparseProductReturnType< OtherDerived, Derived >::Type operator*(const MatrixBase< OtherDerived > &lhs, const Derived &rhs)
Definition: SparseMatrixBase.h:355
Definition: SparseMatrixBase.h:75
Definition: SparseMatrixBase.h:81
A versatible sparse matrix representation.
Definition: SparseMatrix.h:85
RowXpr row(Index i)
Definition: SparseMatrixBase.h:750
Expression of the transpose of a matrix.
Definition: Transpose.h:57
Definition: SparseMatrixBase.h:86
Definition: SparseMatrixBase.h:56
Derived & setZero()
Definition: CwiseNullaryOp.h:499
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:49
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Index cols() const
Definition: SparseMatrixBase.h:152
const ScalarMultipleReturnType operator*(const Scalar &scalar) const
Definition: SparseMatrixBase.h:50
Index rows() const
Definition: SparseMatrixBase.h:150
CoeffReturnType value() const
Definition: DenseBase.h:424
Definition: EigenBase.h:26
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:26
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
Derived & derived()
Definition: EigenBase.h:34
const internal::eval< Derived >::type eval() const
Definition: SparseMatrixBase.h:439
Definition: SparseMatrixBase.h:50
bool isVector() const
Definition: SparseMatrixBase.h:163
Index size() const
Definition: SparseMatrixBase.h:155
Index innerSize() const
Definition: SparseMatrixBase.h:169
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:102
Definition: SparseMatrixBase.h:63
Block< Derived, Dynamic, Dynamic, true > innerVectors(Index outerStart, Index outerSize)
Definition: SparseBlock.h:268
const unsigned int RowMajorBit
Definition: Constants.h:53
InnerVectorReturnType innerVector(Index outer)
Definition: SparseBlock.h:254
const unsigned int DirectAccessBit
Definition: Constants.h:142
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
ColXpr col(Index i)
Definition: SparseMatrixBase.h:733
SparseSymmetricPermutationProduct< Derived, Upper|Lower > twistedBy(const PermutationMatrix< Dynamic, Dynamic, Index > &perm) const
Definition: SparseMatrixBase.h:364