10 #ifndef EIGEN_SPARSEMATRIXBASE_H
11 #define EIGEN_SPARSEMATRIXBASE_H
26 template<
typename Derived>
class SparseMatrixBase
27 :
public EigenBase<Derived>
31 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>::StorageIndex StorageIndex;
41 typedef typename internal::add_const_on_value_type_if_arithmetic<
42 typename internal::packet_traits<Scalar>::type
43 >::type PacketReturnType;
50 template<
typename OtherDerived>
68 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
69 internal::traits<Derived>::ColsAtCompileTime>::ret),
77 MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
78 MaxColsAtCompileTime>::ret),
86 Flags = internal::traits<Derived>::Flags,
96 #ifndef EIGEN_PARSED_BY_DOXYGEN
102 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
105 >::type AdjointReturnType;
107 typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType;
112 #ifndef EIGEN_PARSED_BY_DOXYGEN
123 typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType;
134 inline const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
135 inline Derived& derived() {
return *
static_cast<Derived*
>(
this); }
136 inline Derived& const_cast_derived()
const
137 {
return *
static_cast<Derived*
>(
const_cast<SparseMatrixBase*
>(
this)); }
139 typedef EigenBase<Derived> Base;
141 #endif // not EIGEN_PARSED_BY_DOXYGEN
143 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
144 #ifdef EIGEN_PARSED_BY_DOXYGEN
145 #define EIGEN_DOC_UNARY_ADDONS(METHOD,OP)
146 #define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
147 #define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
149 #define EIGEN_DOC_UNARY_ADDONS(X,Y)
150 #define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
151 #define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
153 # include "../plugins/CommonCwiseUnaryOps.h"
154 # include "../plugins/CommonCwiseBinaryOps.h"
155 # include "../plugins/MatrixCwiseUnaryOps.h"
156 # include "../plugins/MatrixCwiseBinaryOps.h"
157 # include "../plugins/BlockMethods.h"
158 # ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN
159 # include EIGEN_SPARSEMATRIXBASE_PLUGIN
161 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
162 #undef EIGEN_DOC_UNARY_ADDONS
163 #undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
164 #undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
185 bool isRValue()
const {
return m_isRValue; }
186 Derived& markAsRValue() { m_isRValue =
true;
return derived(); }
188 SparseMatrixBase() : m_isRValue(false) { }
191 template<
typename OtherDerived>
192 Derived& operator=(
const ReturnByValue<OtherDerived>& other);
194 template<
typename OtherDerived>
195 inline Derived& operator=(
const SparseMatrixBase<OtherDerived>& other);
197 inline Derived& operator=(
const Derived& other);
201 template<
typename OtherDerived>
202 inline Derived& assign(
const OtherDerived& other);
204 template<
typename OtherDerived>
205 inline void assignGeneric(
const OtherDerived& other);
209 friend std::ostream & operator << (std::ostream & s,
const SparseMatrixBase& m)
211 typedef typename Derived::Nested Nested;
212 typedef typename internal::remove_all<Nested>::type NestedCleaned;
216 const Nested nm(m.derived());
217 internal::evaluator<NestedCleaned> thisEval(nm);
218 for (
Index row=0; row<nm.outerSize(); ++row)
221 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, row); it; ++it)
223 for ( ; col<it.index(); ++col)
225 s << it.value() <<
" ";
228 for ( ; col<m.cols(); ++col)
235 const Nested nm(m.derived());
236 internal::evaluator<NestedCleaned> thisEval(nm);
239 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, 0); it; ++it)
241 for ( ; row<it.index(); ++row)
242 s <<
"0" << std::endl;
243 s << it.value() << std::endl;
246 for ( ; row<m.rows(); ++row)
247 s <<
"0" << std::endl;
251 SparseMatrix<Scalar, RowMajorBit, StorageIndex> trans = m;
252 s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit, StorageIndex> >&>(trans);
258 template<
typename OtherDerived>
259 Derived& operator+=(
const SparseMatrixBase<OtherDerived>& other);
260 template<
typename OtherDerived>
261 Derived& operator-=(
const SparseMatrixBase<OtherDerived>& other);
263 template<
typename OtherDerived>
264 Derived& operator+=(
const DiagonalBase<OtherDerived>& other);
265 template<
typename OtherDerived>
266 Derived& operator-=(
const DiagonalBase<OtherDerived>& other);
268 Derived& operator*=(
const Scalar& other);
269 Derived& operator/=(
const Scalar& other);
271 template<
typename OtherDerived>
struct CwiseProductDenseReturnType {
272 typedef CwiseBinaryOp<internal::scalar_product_op<
typename ScalarBinaryOpTraits<
273 typename internal::traits<Derived>::Scalar,
274 typename internal::traits<OtherDerived>::Scalar
281 template<
typename OtherDerived>
282 EIGEN_STRONG_INLINE
const typename CwiseProductDenseReturnType<OtherDerived>::Type
283 cwiseProduct(
const MatrixBase<OtherDerived> &other)
const;
286 template<
typename OtherDerived>
287 const Product<Derived,OtherDerived>
288 operator*(
const DiagonalBase<OtherDerived> &other)
const
289 {
return Product<Derived,OtherDerived>(derived(), other.derived()); }
292 template<
typename OtherDerived>
friend
293 const Product<OtherDerived,Derived>
294 operator*(
const DiagonalBase<OtherDerived> &lhs,
const SparseMatrixBase& rhs)
295 {
return Product<OtherDerived,Derived>(lhs.derived(), rhs.derived()); }
298 template<
typename OtherDerived>
299 const Product<Derived,OtherDerived,AliasFreeProduct>
300 operator*(
const SparseMatrixBase<OtherDerived> &other)
const;
303 template<
typename OtherDerived>
304 const Product<Derived,OtherDerived>
305 operator*(
const MatrixBase<OtherDerived> &other)
const
306 {
return Product<Derived,OtherDerived>(derived(), other.derived()); }
309 template<
typename OtherDerived>
friend
310 const Product<OtherDerived,Derived>
311 operator*(
const MatrixBase<OtherDerived> &lhs,
const SparseMatrixBase& rhs)
312 {
return Product<OtherDerived,Derived>(lhs.derived(), rhs.derived()); }
317 return SparseSymmetricPermutationProduct<Derived,Upper|Lower>(derived(), perm);
320 template<
typename OtherDerived>
327 template<
unsigned int UpLo>
struct ConstSelfAdjointViewReturnType {
typedef const SparseSelfAdjointView<const Derived, UpLo> Type; };
329 template<
unsigned int UpLo>
inline
330 typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView()
const;
331 template<
unsigned int UpLo>
inline
332 typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
334 template<
typename OtherDerived> Scalar dot(
const MatrixBase<OtherDerived>& other)
const;
335 template<
typename OtherDerived> Scalar dot(
const SparseMatrixBase<OtherDerived>& other)
const;
336 RealScalar squaredNorm()
const;
337 RealScalar norm()
const;
338 RealScalar blueNorm()
const;
340 TransposeReturnType transpose() {
return TransposeReturnType(derived()); }
341 const ConstTransposeReturnType transpose()
const {
return ConstTransposeReturnType(derived()); }
342 const AdjointReturnType adjoint()
const {
return AdjointReturnType(transpose()); }
345 typedef Block<Derived,IsRowMajor?1:Dynamic,IsRowMajor?Dynamic:1,true> InnerVectorReturnType;
346 typedef Block<const Derived,IsRowMajor?1:Dynamic,IsRowMajor?Dynamic:1,true> ConstInnerVectorReturnType;
351 typedef Block<Derived,Dynamic,Dynamic,true> InnerVectorsReturnType;
352 typedef Block<const Derived,Dynamic,Dynamic,true> ConstInnerVectorsReturnType;
356 DenseMatrixType toDense()
const
358 return DenseMatrixType(derived());
361 template<
typename OtherDerived>
362 bool isApprox(
const SparseMatrixBase<OtherDerived>& other,
363 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const;
365 template<
typename OtherDerived>
366 bool isApprox(
const MatrixBase<OtherDerived>& other,
367 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const
368 {
return toDense().isApprox(other,prec); }
375 inline const typename internal::eval<Derived>::type
eval()
const
376 {
return typename internal::eval<Derived>::type(derived()); }
380 inline const SparseView<Derived>
387 static inline StorageIndex convert_index(
const Index idx) {
388 return internal::convert_index<StorageIndex>(idx);
391 template<
typename Dest>
void evalTo(Dest &)
const;
396 #endif // EIGEN_SPARSEMATRIXBASE_H