1
// This file is part of Eigen, a lightweight C++ template library
4
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
6
// Eigen is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 3 of the License, or (at your option) any later version.
11
// Alternatively, you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License as
13
// published by the Free Software Foundation; either version 2 of
14
// the License, or (at your option) any later version.
16
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
// GNU General Public License for more details.
21
// You should have received a copy of the GNU Lesser General Public
22
// License and a copy of the GNU General Public License along with
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
25
#ifndef EIGEN_SPARSEMATRIXBASE_H
26
#define EIGEN_SPARSEMATRIXBASE_H
28
/** \ingroup Sparse_Module
30
* \class SparseMatrixBase
32
* \brief Base class of any sparse matrices or sparse expressions
36
* This class can be extended with the help of the plugin mechanism described on the page
37
* \ref TopicCustomizingEigen by defining the preprocessor symbol \c EIGEN_SPARSEMATRIXBASE_PLUGIN.
39
template<typename Derived> class SparseMatrixBase : public EigenBase<Derived>
43
typedef typename internal::traits<Derived>::Scalar Scalar;
44
typedef typename internal::packet_traits<Scalar>::type PacketScalar;
45
typedef typename internal::traits<Derived>::StorageKind StorageKind;
46
typedef typename internal::traits<Derived>::Index Index;
48
typedef SparseMatrixBase StorageBaseType;
49
typedef EigenBase<Derived> Base;
51
template<typename OtherDerived>
52
Derived& operator=(const EigenBase<OtherDerived> &other)
54
other.derived().evalTo(derived());
58
// using Base::operator=;
62
RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
63
/**< The number of rows at compile-time. This is just a copy of the value provided
64
* by the \a Derived type. If a value is not known at compile-time,
65
* it is set to the \a Dynamic constant.
66
* \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
68
ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
69
/**< The number of columns at compile-time. This is just a copy of the value provided
70
* by the \a Derived type. If a value is not known at compile-time,
71
* it is set to the \a Dynamic constant.
72
* \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
75
SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
76
internal::traits<Derived>::ColsAtCompileTime>::ret),
77
/**< This is equal to the number of coefficients, i.e. the number of
78
* rows times the number of columns, or to \a Dynamic if this is not
79
* known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
81
MaxRowsAtCompileTime = RowsAtCompileTime,
82
MaxColsAtCompileTime = ColsAtCompileTime,
84
MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
85
MaxColsAtCompileTime>::ret),
87
IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1,
88
/**< This is set to true if either the number of rows or the number of
89
* columns is known at compile-time to be equal to 1. Indeed, in that case,
90
* we are dealing with a column-vector (if there is only one column) or with
91
* a row-vector (if there is only one row). */
93
Flags = internal::traits<Derived>::Flags,
94
/**< This stores expression \ref flags flags which may or may not be inherited by new expressions
95
* constructed from this one. See the \ref flags "list of flags".
98
CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
99
/**< This is a rough measure of how expensive it is to read one coefficient from
103
IsRowMajor = Flags&RowMajorBit ? 1 : 0,
105
#ifndef EIGEN_PARSED_BY_DOXYGEN
106
_HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC
110
/* \internal the return type of MatrixBase::conjugate() */
111
// typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
112
// const SparseCwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Derived>,
114
// >::type ConjugateReturnType;
115
/* \internal the return type of MatrixBase::real() */
116
// typedef SparseCwiseUnaryOp<internal::scalar_real_op<Scalar>, Derived> RealReturnType;
117
/* \internal the return type of MatrixBase::imag() */
118
// typedef SparseCwiseUnaryOp<internal::scalar_imag_op<Scalar>, Derived> ImagReturnType;
119
/** \internal the return type of MatrixBase::adjoint() */
120
typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
121
CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Eigen::Transpose<const Derived> >,
122
Transpose<const Derived>
123
>::type AdjointReturnType;
126
typedef SparseMatrix<Scalar, Flags&RowMajorBit ? RowMajor : ColMajor> PlainObject;
128
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
129
# include "../plugins/CommonCwiseUnaryOps.h"
130
# include "../plugins/CommonCwiseBinaryOps.h"
131
# include "../plugins/MatrixCwiseUnaryOps.h"
132
# include "../plugins/MatrixCwiseBinaryOps.h"
133
# ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN
134
# include EIGEN_SPARSEMATRIXBASE_PLUGIN
136
# undef EIGEN_CURRENT_STORAGE_BASE_CLASS
137
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
139
#ifndef EIGEN_PARSED_BY_DOXYGEN
140
/** This is the "real scalar" type; if the \a Scalar type is already real numbers
141
* (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If
142
* \a Scalar is \a std::complex<T> then RealScalar is \a T.
144
* \sa class NumTraits
146
typedef typename NumTraits<Scalar>::Real RealScalar;
148
/** \internal the return type of coeff()
150
typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType;
152
/** \internal Represents a matrix with all coefficients equal to one another*/
153
typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Matrix<Scalar,Dynamic,Dynamic> > ConstantReturnType;
155
/** type of the equivalent square matrix */
156
typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
157
EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
159
inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
160
inline Derived& derived() { return *static_cast<Derived*>(this); }
161
inline Derived& const_cast_derived() const
162
{ return *static_cast<Derived*>(const_cast<SparseMatrixBase*>(this)); }
163
#endif // not EIGEN_PARSED_BY_DOXYGEN
165
/** \returns the number of rows. \sa cols(), RowsAtCompileTime */
166
inline Index rows() const { return derived().rows(); }
167
/** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
168
inline Index cols() const { return derived().cols(); }
169
/** \returns the number of coefficients, which is \a rows()*cols().
170
* \sa rows(), cols(), SizeAtCompileTime. */
171
inline Index size() const { return rows() * cols(); }
172
/** \returns the number of nonzero coefficients which is in practice the number
173
* of stored coefficients. */
174
inline Index nonZeros() const { return derived().nonZeros(); }
175
/** \returns true if either the number of rows or the number of columns is equal to 1.
176
* In other words, this function returns
177
* \code rows()==1 || cols()==1 \endcode
178
* \sa rows(), cols(), IsVectorAtCompileTime. */
179
inline bool isVector() const { return rows()==1 || cols()==1; }
180
/** \returns the size of the storage major dimension,
181
* i.e., the number of columns for a columns major matrix, and the number of rows otherwise */
182
Index outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); }
183
/** \returns the size of the inner dimension according to the storage order,
184
* i.e., the number of rows for a columns major matrix, and the number of cols otherwise */
185
Index innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); }
187
bool isRValue() const { return m_isRValue; }
188
Derived& markAsRValue() { m_isRValue = true; return derived(); }
190
SparseMatrixBase() : m_isRValue(false) { /* TODO check flags */ }
192
inline Derived& operator=(const Derived& other)
194
// std::cout << "Derived& operator=(const Derived& other)\n";
195
// if (other.isRValue())
196
// derived().swap(other.const_cast_derived());
198
this->operator=<Derived>(other);
202
template<typename OtherDerived>
203
Derived& operator=(const ReturnByValue<OtherDerived>& other)
205
other.evalTo(derived());
210
template<typename OtherDerived>
211
inline void assignGeneric(const OtherDerived& other)
213
// std::cout << "Derived& operator=(const MatrixBase<OtherDerived>& other)\n";
214
//const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
215
eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) ||
216
(!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) &&
217
"the transpose operation is supposed to be handled in SparseMatrix::operator=");
219
enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) };
221
const Index outerSize = other.outerSize();
222
//typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType;
223
// thanks to shallow copies, we always eval to a tempary
224
Derived temp(other.rows(), other.cols());
226
temp.reserve((std::max)(this->rows(),this->cols())*2);
227
for (Index j=0; j<outerSize; ++j)
230
for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
232
Scalar v = it.value();
234
temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
239
derived() = temp.markAsRValue();
243
template<typename OtherDerived>
244
inline Derived& operator=(const SparseMatrixBase<OtherDerived>& other)
246
// std::cout << typeid(OtherDerived).name() << "\n";
247
// std::cout << Flags << " " << OtherDerived::Flags << "\n";
248
const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
249
// std::cout << "eval transpose = " << transpose << "\n";
250
const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols();
251
if ((!transpose) && other.isRValue())
253
// eval without temporary
254
derived().resize(other.rows(), other.cols());
256
derived().reserve((std::max)(this->rows(),this->cols())*2);
257
for (Index j=0; j<outerSize; ++j)
259
derived().startVec(j);
260
for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
262
Scalar v = it.value();
264
derived().insertBackByOuterInner(j,it.index()) = v;
267
derived().finalize();
271
assignGeneric(other.derived());
276
template<typename Lhs, typename Rhs>
277
inline Derived& operator=(const SparseSparseProduct<Lhs,Rhs>& product);
279
template<typename Lhs, typename Rhs>
280
inline void _experimentalNewProduct(const Lhs& lhs, const Rhs& rhs);
282
friend std::ostream & operator << (std::ostream & s, const SparseMatrixBase& m)
284
if (Flags&RowMajorBit)
286
for (Index row=0; row<m.outerSize(); ++row)
289
for (typename Derived::InnerIterator it(m.derived(), row); it; ++it)
291
for ( ; col<it.index(); ++col)
293
s << it.value() << " ";
296
for ( ; col<m.cols(); ++col)
305
for (typename Derived::InnerIterator it(m.derived(), 0); it; ++it)
307
for ( ; row<it.index(); ++row)
308
s << "0" << std::endl;
309
s << it.value() << std::endl;
312
for ( ; row<m.rows(); ++row)
313
s << "0" << std::endl;
317
SparseMatrix<Scalar, RowMajorBit> trans = m.derived();
324
// const SparseCwiseUnaryOp<internal::scalar_opposite_op<typename internal::traits<Derived>::Scalar>,Derived> operator-() const;
326
// template<typename OtherDerived>
327
// const CwiseBinaryOp<internal::scalar_sum_op<typename internal::traits<Derived>::Scalar>, Derived, OtherDerived>
328
// operator+(const SparseMatrixBase<OtherDerived> &other) const;
330
// template<typename OtherDerived>
331
// const CwiseBinaryOp<internal::scalar_difference_op<typename internal::traits<Derived>::Scalar>, Derived, OtherDerived>
332
// operator-(const SparseMatrixBase<OtherDerived> &other) const;
334
template<typename OtherDerived>
335
Derived& operator+=(const SparseMatrixBase<OtherDerived>& other);
336
template<typename OtherDerived>
337
Derived& operator-=(const SparseMatrixBase<OtherDerived>& other);
339
// template<typename Lhs,typename Rhs>
340
// Derived& operator+=(const Flagged<Product<Lhs,Rhs,CacheFriendlyProduct>, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other);
342
Derived& operator*=(const Scalar& other);
343
Derived& operator/=(const Scalar& other);
345
#define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \
347
internal::scalar_product_op< \
348
typename internal::scalar_product_traits< \
349
typename internal::traits<Derived>::Scalar, \
350
typename internal::traits<OtherDerived>::Scalar \
357
template<typename OtherDerived>
358
EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
359
cwiseProduct(const MatrixBase<OtherDerived> &other) const;
361
// const SparseCwiseUnaryOp<internal::scalar_multiple_op<typename internal::traits<Derived>::Scalar>, Derived>
362
// operator*(const Scalar& scalar) const;
363
// const SparseCwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>, Derived>
364
// operator/(const Scalar& scalar) const;
366
// inline friend const SparseCwiseUnaryOp<internal::scalar_multiple_op<typename internal::traits<Derived>::Scalar>, Derived>
367
// operator*(const Scalar& scalar, const SparseMatrixBase& matrix)
368
// { return matrix*scalar; }
372
template<typename OtherDerived>
373
const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type
374
operator*(const SparseMatrixBase<OtherDerived> &other) const;
377
template<typename OtherDerived>
378
const SparseDiagonalProduct<Derived,OtherDerived>
379
operator*(const DiagonalBase<OtherDerived> &other) const;
382
template<typename OtherDerived> friend
383
const SparseDiagonalProduct<OtherDerived,Derived>
384
operator*(const DiagonalBase<OtherDerived> &lhs, const SparseMatrixBase& rhs)
385
{ return SparseDiagonalProduct<OtherDerived,Derived>(lhs.derived(), rhs.derived()); }
387
/** dense * sparse (return a dense object unless it is an outer product) */
388
template<typename OtherDerived> friend
389
const typename DenseSparseProductReturnType<OtherDerived,Derived>::Type
390
operator*(const MatrixBase<OtherDerived>& lhs, const Derived& rhs)
391
{ return typename DenseSparseProductReturnType<OtherDerived,Derived>::Type(lhs.derived(),rhs); }
393
/** sparse * dense (returns a dense object unless it is an outer product) */
394
template<typename OtherDerived>
395
const typename SparseDenseProductReturnType<Derived,OtherDerived>::Type
396
operator*(const MatrixBase<OtherDerived> &other) const;
398
template<typename OtherDerived>
399
Derived& operator*=(const SparseMatrixBase<OtherDerived>& other);
401
#ifdef EIGEN2_SUPPORT
403
template<typename OtherDerived>
404
typename internal::plain_matrix_type_column_major<OtherDerived>::type
405
solveTriangular(const MatrixBase<OtherDerived>& other) const;
408
template<typename OtherDerived>
409
void solveTriangularInPlace(MatrixBase<OtherDerived>& other) const;
410
// template<typename OtherDerived>
411
// void solveTriangularInPlace(SparseMatrixBase<OtherDerived>& other) const;
412
#endif // EIGEN2_SUPPORT
415
inline const SparseTriangularView<Derived, Mode> triangularView() const;
417
template<unsigned int UpLo> inline const SparseSelfAdjointView<Derived, UpLo> selfadjointView() const;
418
template<unsigned int UpLo> inline SparseSelfAdjointView<Derived, UpLo> selfadjointView();
420
template<typename OtherDerived> Scalar dot(const MatrixBase<OtherDerived>& other) const;
421
template<typename OtherDerived> Scalar dot(const SparseMatrixBase<OtherDerived>& other) const;
422
RealScalar squaredNorm() const;
423
RealScalar norm() const;
424
// const PlainObject normalized() const;
427
Transpose<Derived> transpose() { return derived(); }
428
const Transpose<const Derived> transpose() const { return derived(); }
429
// void transposeInPlace();
430
const AdjointReturnType adjoint() const { return transpose(); }
433
SparseInnerVectorSet<Derived,1> row(Index i);
434
const SparseInnerVectorSet<Derived,1> row(Index i) const;
435
SparseInnerVectorSet<Derived,1> col(Index j);
436
const SparseInnerVectorSet<Derived,1> col(Index j) const;
437
SparseInnerVectorSet<Derived,1> innerVector(Index outer);
438
const SparseInnerVectorSet<Derived,1> innerVector(Index outer) const;
440
// set of sub-vectors
441
SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size);
442
const SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size) const;
443
SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size);
444
const SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size) const;
445
SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize);
446
const SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize) const;
448
// typename BlockReturnType<Derived>::Type block(int startRow, int startCol, int blockRows, int blockCols);
449
// const typename BlockReturnType<Derived>::Type
450
// block(int startRow, int startCol, int blockRows, int blockCols) const;
452
// typename BlockReturnType<Derived>::SubVectorType segment(int start, int size);
453
// const typename BlockReturnType<Derived>::SubVectorType segment(int start, int size) const;
455
// typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size);
456
// const typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size) const;
458
// typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size);
459
// const typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size) const;
461
// template<int BlockRows, int BlockCols>
462
// typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol);
463
// template<int BlockRows, int BlockCols>
464
// const typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol) const;
466
// template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType start(void);
467
// template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType start() const;
469
// template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType end();
470
// template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType end() const;
472
// template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType segment(int start);
473
// template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType segment(int start) const;
475
// Diagonal<Derived> diagonal();
476
// const Diagonal<Derived> diagonal() const;
478
// template<unsigned int Mode> Part<Derived, Mode> part();
479
// template<unsigned int Mode> const Part<Derived, Mode> part() const;
482
// static const ConstantReturnType Constant(int rows, int cols, const Scalar& value);
483
// static const ConstantReturnType Constant(int size, const Scalar& value);
484
// static const ConstantReturnType Constant(const Scalar& value);
486
// template<typename CustomNullaryOp>
487
// static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(int rows, int cols, const CustomNullaryOp& func);
488
// template<typename CustomNullaryOp>
489
// static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(int size, const CustomNullaryOp& func);
490
// template<typename CustomNullaryOp>
491
// static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(const CustomNullaryOp& func);
493
// static const ConstantReturnType Zero(int rows, int cols);
494
// static const ConstantReturnType Zero(int size);
495
// static const ConstantReturnType Zero();
496
// static const ConstantReturnType Ones(int rows, int cols);
497
// static const ConstantReturnType Ones(int size);
498
// static const ConstantReturnType Ones();
499
// static const IdentityReturnType Identity();
500
// static const IdentityReturnType Identity(int rows, int cols);
501
// static const BasisReturnType Unit(int size, int i);
502
// static const BasisReturnType Unit(int i);
503
// static const BasisReturnType UnitX();
504
// static const BasisReturnType UnitY();
505
// static const BasisReturnType UnitZ();
506
// static const BasisReturnType UnitW();
508
// const DiagonalMatrix<Derived> asDiagonal() const;
510
// Derived& setConstant(const Scalar& value);
511
// Derived& setZero();
512
// Derived& setOnes();
513
// Derived& setRandom();
514
// Derived& setIdentity();
516
/** \internal use operator= */
517
template<typename DenseDerived>
518
void evalTo(MatrixBase<DenseDerived>& dst) const
521
for (Index j=0; j<outerSize(); ++j)
522
for (typename Derived::InnerIterator i(derived(),j); i; ++i)
523
dst.coeffRef(i.row(),i.col()) = i.value();
526
Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> toDense() const
531
template<typename OtherDerived>
532
bool isApprox(const SparseMatrixBase<OtherDerived>& other,
533
RealScalar prec = NumTraits<Scalar>::dummy_precision()) const
534
{ return toDense().isApprox(other.toDense(),prec); }
536
template<typename OtherDerived>
537
bool isApprox(const MatrixBase<OtherDerived>& other,
538
RealScalar prec = NumTraits<Scalar>::dummy_precision()) const
539
{ return toDense().isApprox(other,prec); }
540
// bool isMuchSmallerThan(const RealScalar& other,
541
// RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
542
// template<typename OtherDerived>
543
// bool isMuchSmallerThan(const MatrixBase<OtherDerived>& other,
544
// RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
546
// bool isApproxToConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
547
// bool isZero(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
548
// bool isOnes(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
549
// bool isIdentity(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
550
// bool isDiagonal(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
552
// bool isUpper(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
553
// bool isLower(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
555
// template<typename OtherDerived>
556
// bool isOrthogonal(const MatrixBase<OtherDerived>& other,
557
// RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
558
// bool isUnitary(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const;
560
// template<typename OtherDerived>
561
// inline bool operator==(const MatrixBase<OtherDerived>& other) const
562
// { return (cwise() == other).all(); }
564
// template<typename OtherDerived>
565
// inline bool operator!=(const MatrixBase<OtherDerived>& other) const
566
// { return (cwise() != other).any(); }
569
// template<typename NewType>
570
// const SparseCwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, Derived> cast() const;
572
/** \returns the matrix or vector obtained by evaluating this expression.
574
* Notice that in the case of a plain matrix or vector (not an expression) this function just returns
575
* a const reference, in order to avoid a useless copy.
577
inline const typename internal::eval<Derived>::type eval() const
578
{ return typename internal::eval<Derived>::type(derived()); }
580
// template<typename OtherDerived>
581
// void swap(MatrixBase<OtherDerived> const & other);
583
// template<unsigned int Added>
584
// const SparseFlagged<Derived, Added, 0> marked() const;
585
// const Flagged<Derived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit> lazy() const;
587
/** \returns number of elements to skip to pass from one row (resp. column) to another
588
* for a row-major (resp. column-major) matrix.
589
* Combined with coeffRef() and the \ref flags flags, it allows a direct access to the data
590
* of the underlying matrix.
592
// inline int stride(void) const { return derived().stride(); }
595
// ConjugateReturnType conjugate() const;
596
// const RealReturnType real() const;
597
// const ImagReturnType imag() const;
599
// template<typename CustomUnaryOp>
600
// const SparseCwiseUnaryOp<CustomUnaryOp, Derived> unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const;
602
// template<typename CustomBinaryOp, typename OtherDerived>
603
// const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>
604
// binaryExpr(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const;
608
// Scalar trace() const;
610
// typename internal::traits<Derived>::Scalar minCoeff() const;
611
// typename internal::traits<Derived>::Scalar maxCoeff() const;
613
// typename internal::traits<Derived>::Scalar minCoeff(int* row, int* col = 0) const;
614
// typename internal::traits<Derived>::Scalar maxCoeff(int* row, int* col = 0) const;
616
// template<typename BinaryOp>
617
// typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type
618
// redux(const BinaryOp& func) const;
620
// template<typename Visitor>
621
// void visit(Visitor& func) const;
624
// const SparseCwise<Derived> cwise() const;
625
// SparseCwise<Derived> cwise();
627
// inline const WithFormat<Derived> format(const IOFormat& fmt) const;
629
/////////// Array module ///////////
631
bool all(void) const;
632
bool any(void) const;
634
const VectorwiseOp<Derived,Horizontal> rowwise() const;
635
const VectorwiseOp<Derived,Vertical> colwise() const;
637
static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(int rows, int cols);
638
static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(int size);
639
static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random();
641
template<typename ThenDerived,typename ElseDerived>
642
const Select<Derived,ThenDerived,ElseDerived>
643
select(const MatrixBase<ThenDerived>& thenMatrix,
644
const MatrixBase<ElseDerived>& elseMatrix) const;
646
template<typename ThenDerived>
647
inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
648
select(const MatrixBase<ThenDerived>& thenMatrix, typename ThenDerived::Scalar elseScalar) const;
650
template<typename ElseDerived>
651
inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
652
select(typename ElseDerived::Scalar thenScalar, const MatrixBase<ElseDerived>& elseMatrix) const;
654
template<int p> RealScalar lpNorm() const;
658
// template<typename OtherDerived>
659
// Scalar dot(const MatrixBase<OtherDerived>& other) const
661
// EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
662
// EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
663
// EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
664
// YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
666
// eigen_assert(derived().size() == other.size());
667
// // short version, but the assembly looks more complicated because
668
// // of the CwiseBinaryOp iterator complexity
669
// // return res = (derived().cwise() * other.derived().conjugate()).sum();
671
// // optimized, generic version
672
// typename Derived::InnerIterator i(derived(),0);
673
// typename OtherDerived::InnerIterator j(other.derived(),0);
677
// if (i.index()==j.index())
679
// // std::cerr << i.value() << " * " << j.value() << "\n";
680
// res += i.value() * internal::conj(j.value());
683
// else if (i.index()<j.index())
691
// Scalar sum() const
694
// for (typename Derived::InnerIterator iter(*this,0); iter; ++iter)
696
// res += iter.value();
706
#endif // EIGEN_SPARSEMATRIXBASE_H