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,
93 #ifndef EIGEN_PARSED_BY_DOXYGEN
99 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
102 >::type AdjointReturnType;
108#ifndef EIGEN_PARSED_BY_DOXYGEN
115 typedef typename NumTraits<Scalar>::Real RealScalar;
119 typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType;
128 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
129 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
130 inline Derived& const_cast_derived()
const
131 {
return *
static_cast<Derived*
>(
const_cast<SparseMatrixBase*
>(
this)); }
134#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
135# include "../plugins/CommonCwiseUnaryOps.h"
136# include "../plugins/CommonCwiseBinaryOps.h"
137# include "../plugins/MatrixCwiseUnaryOps.h"
138# include "../plugins/MatrixCwiseBinaryOps.h"
139# ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN
140# include EIGEN_SPARSEMATRIXBASE_PLUGIN
142# undef EIGEN_CURRENT_STORAGE_BASE_CLASS
143#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
147 inline Index
rows()
const {
return derived().rows(); }
149 inline Index
cols()
const {
return derived().cols(); }
155 inline Index nonZeros()
const {
return derived().nonZeros(); }
160 inline bool isVector()
const {
return rows()==1 ||
cols()==1; }
168 bool isRValue()
const {
return m_isRValue; }
169 Derived& markAsRValue() { m_isRValue =
true;
return derived(); }
171 SparseMatrixBase() : m_isRValue(false) { }
174 template<
typename OtherDerived>
175 Derived& operator=(
const ReturnByValue<OtherDerived>& other)
182 template<
typename OtherDerived>
185 return assign(other.
derived());
188 inline Derived& operator=(
const Derived& other)
193 return assign(other.derived());
198 template<
typename OtherDerived>
199 inline Derived& assign(
const OtherDerived& other)
202 const Index outerSize = (int(OtherDerived::Flags) &
RowMajorBit) ? other.rows() : other.cols();
203 if ((!transpose) && other.isRValue())
206 derived().resize(other.rows(), other.cols());
209 for (Index j=0; j<outerSize; ++j)
212 for (
typename OtherDerived::InnerIterator it(other, j); it; ++it)
214 Scalar v = it.value();
215 derived().insertBackByOuterInner(j,it.index()) = v;
222 assignGeneric(other);
227 template<
typename OtherDerived>
228 inline void assignGeneric(
const OtherDerived& other)
231 eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) ||
233 "the transpose operation is supposed to be handled in SparseMatrix::operator=");
237 const Index outerSize = other.outerSize();
240 Derived temp(other.rows(), other.cols());
242 temp.reserve((std::max)(this->
rows(),this->
cols())*2);
243 for (Index j=0; j<outerSize; ++j)
246 for (
typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
248 Scalar v = it.value();
249 temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
254 derived() = temp.markAsRValue();
259 template<
typename Lhs,
typename Rhs>
260 inline Derived& operator=(
const SparseSparseProduct<Lhs,Rhs>& product);
262 friend std::ostream & operator << (std::ostream & s,
const SparseMatrixBase& m)
264 typedef typename Derived::Nested Nested;
265 typedef typename internal::remove_all<Nested>::type NestedCleaned;
269 const Nested nm(m.derived());
270 for (Index
row=0;
row<nm.outerSize(); ++
row)
273 for (
typename NestedCleaned::InnerIterator it(nm.derived(),
row); it; ++it)
275 for ( ;
col<it.index(); ++
col)
277 s << it.value() <<
" ";
280 for ( ;
col<m.cols(); ++
col)
287 const Nested nm(m.derived());
290 for (
typename NestedCleaned::InnerIterator it(nm.derived(), 0); it; ++it)
292 for ( ;
row<it.index(); ++
row)
293 s <<
"0" << std::endl;
294 s << it.value() << std::endl;
297 for ( ;
row<m.rows(); ++
row)
298 s <<
"0" << std::endl;
302 SparseMatrix<Scalar, RowMajorBit> trans = m;
303 s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit> >&>(trans);
309 template<
typename OtherDerived>
310 Derived& operator+=(
const SparseMatrixBase<OtherDerived>& other);
311 template<
typename OtherDerived>
312 Derived& operator-=(
const SparseMatrixBase<OtherDerived>& other);
314 Derived& operator*=(
const Scalar& other);
315 Derived& operator/=(
const Scalar& other);
317 #define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \
319 internal::scalar_product_op< \
320 typename internal::scalar_product_traits< \
321 typename internal::traits<Derived>::Scalar, \
322 typename internal::traits<OtherDerived>::Scalar \
329 template<
typename OtherDerived>
330 EIGEN_STRONG_INLINE
const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
334 template<
typename OtherDerived>
335 const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
336 operator*(
const SparseMatrixBase<OtherDerived> &other)
const;
339 template<
typename OtherDerived>
340 const SparseDiagonalProduct<Derived,OtherDerived>
341 operator*(
const DiagonalBase<OtherDerived> &other)
const;
344 template<
typename OtherDerived>
friend
345 const SparseDiagonalProduct<OtherDerived,Derived>
346 operator*(
const DiagonalBase<OtherDerived> &lhs,
const SparseMatrixBase& rhs)
347 {
return SparseDiagonalProduct<OtherDerived,Derived>(lhs.derived(), rhs.
derived()); }
350 template<
typename OtherDerived>
friend
351 const typename DenseSparseProductReturnType<OtherDerived,Derived>::Type
353 {
return typename DenseSparseProductReturnType<OtherDerived,Derived>::Type(lhs.derived(),rhs); }
356 template<
typename OtherDerived>
357 const typename SparseDenseProductReturnType<Derived,OtherDerived>::Type
363 return SparseSymmetricPermutationProduct<Derived,Upper|Lower>(
derived(), perm);
366 template<
typename OtherDerived>
367 Derived& operator*=(
const SparseMatrixBase<OtherDerived>& other);
369 #ifdef EIGEN2_SUPPORT
371 template<
typename OtherDerived>
372 typename internal::plain_matrix_type_column_major<OtherDerived>::type
373 solveTriangular(
const MatrixBase<OtherDerived>& other)
const;
376 template<
typename OtherDerived>
377 void solveTriangularInPlace(MatrixBase<OtherDerived>& other)
const;
381 inline const SparseTriangularView<Derived, Mode> triangularView()
const;
383 template<
unsigned int UpLo>
inline const SparseSelfAdjointView<Derived, UpLo> selfadjointView()
const;
384 template<
unsigned int UpLo>
inline SparseSelfAdjointView<Derived, UpLo> selfadjointView();
387 template<
typename OtherDerived> Scalar dot(
const SparseMatrixBase<OtherDerived>& other)
const;
388 RealScalar squaredNorm()
const;
389 RealScalar norm()
const;
393 const AdjointReturnType adjoint()
const {
return transpose(); }
396 SparseInnerVectorSet<Derived,1>
row(Index i);
397 const SparseInnerVectorSet<Derived,1>
row(Index i)
const;
398 SparseInnerVectorSet<Derived,1>
col(Index j);
399 const SparseInnerVectorSet<Derived,1>
col(Index j)
const;
401 const SparseInnerVectorSet<Derived,1>
innerVector(Index outer)
const;
404 SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index
size);
405 const SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index
size)
const;
406 SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index
size);
407 const SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index
size)
const;
409 SparseInnerVectorSet<Derived,Dynamic>
middleRows(Index start, Index
size);
410 const SparseInnerVectorSet<Derived,Dynamic>
middleRows(Index start, Index
size)
const;
411 SparseInnerVectorSet<Derived,Dynamic>
middleCols(Index start, Index
size);
412 const SparseInnerVectorSet<Derived,Dynamic>
middleCols(Index start, Index
size)
const;
413 SparseInnerVectorSet<Derived,Dynamic>
innerVectors(Index outerStart, Index outerSize);
414 const SparseInnerVectorSet<Derived,Dynamic>
innerVectors(Index outerStart, Index outerSize)
const;
417 template<
typename DenseDerived>
421 for (Index j=0; j<outerSize(); ++j)
422 for (
typename Derived::InnerIterator i(
derived(),j); i; ++i)
423 dst.coeffRef(i.row(),i.col()) = i.
value();
431 template<
typename OtherDerived>
432 bool isApprox(
const SparseMatrixBase<OtherDerived>& other,
433 RealScalar prec = NumTraits<Scalar>::dummy_precision())
const
434 {
return toDense().
isApprox(other.toDense(),prec); }
436 template<
typename OtherDerived>
438 RealScalar prec = NumTraits<Scalar>::dummy_precision())
const
439 {
return toDense().isApprox(other,prec); }
446 inline const typename internal::eval<Derived>::type
eval()
const
447 {
return typename internal::eval<Derived>::type(
derived()); }