00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // 00006 // Eigen is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 3 of the License, or (at your option) any later version. 00010 // 00011 // Alternatively, you can redistribute it and/or 00012 // modify it under the terms of the GNU General Public License as 00013 // published by the Free Software Foundation; either version 2 of 00014 // the License, or (at your option) any later version. 00015 // 00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY 00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License and a copy of the GNU General Public License along with 00023 // Eigen. If not, see <http://www.gnu.org/licenses/>. 00024 00025 #ifndef EIGEN_SPARSEMATRIXBASE_H 00026 #define EIGEN_SPARSEMATRIXBASE_H 00027 00028 /** \ingroup Sparse_Module 00029 * 00030 * \class SparseMatrixBase 00031 * 00032 * \brief Base class of any sparse matrices or sparse expressions 00033 * 00034 * \param Derived 00035 * 00036 * 00037 * 00038 */ 00039 template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> 00040 { 00041 public: 00042 00043 typedef typename internal::traits<Derived>::Scalar Scalar; 00044 typedef typename internal::packet_traits<Scalar>::type PacketScalar; 00045 typedef typename internal::traits<Derived>::StorageKind StorageKind; 00046 typedef typename internal::traits<Derived>::Index Index; 00047 00048 typedef SparseMatrixBase StorageBaseType; 00049 typedef EigenBase<Derived> Base; 00050 00051 template<typename OtherDerived> 00052 Derived& operator=(const EigenBase<OtherDerived> &other) 00053 { 00054 other.derived().evalTo(derived()); 00055 return derived(); 00056 } 00057 00058 // using Base::operator=; 00059 00060 enum { 00061 00062 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, 00063 /**< The number of rows at compile-time. This is just a copy of the value provided 00064 * by the \a Derived type. If a value is not known at compile-time, 00065 * it is set to the \a Dynamic constant. 00066 * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ 00067 00068 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, 00069 /**< The number of columns at compile-time. This is just a copy of the value provided 00070 * by the \a Derived type. If a value is not known at compile-time, 00071 * it is set to the \a Dynamic constant. 00072 * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ 00073 00074 00075 SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime, 00076 internal::traits<Derived>::ColsAtCompileTime>::ret), 00077 /**< This is equal to the number of coefficients, i.e. the number of 00078 * rows times the number of columns, or to \a Dynamic if this is not 00079 * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ 00080 00081 MaxRowsAtCompileTime = RowsAtCompileTime, 00082 MaxColsAtCompileTime = ColsAtCompileTime, 00083 00084 MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime, 00085 MaxColsAtCompileTime>::ret), 00086 00087 IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1, 00088 /**< This is set to true if either the number of rows or the number of 00089 * columns is known at compile-time to be equal to 1. Indeed, in that case, 00090 * we are dealing with a column-vector (if there is only one column) or with 00091 * a row-vector (if there is only one row). */ 00092 00093 Flags = internal::traits<Derived>::Flags, 00094 /**< This stores expression \ref flags flags which may or may not be inherited by new expressions 00095 * constructed from this one. See the \ref flags "list of flags". 00096 */ 00097 00098 CoeffReadCost = internal::traits<Derived>::CoeffReadCost, 00099 /**< This is a rough measure of how expensive it is to read one coefficient from 00100 * this expression. 00101 */ 00102 00103 IsRowMajor = Flags&RowMajorBit ? 1 : 0, 00104 00105 #ifndef EIGEN_PARSED_BY_DOXYGEN 00106 _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC 00107 #endif 00108 }; 00109 00110 /* \internal the return type of MatrixBase::conjugate() */ 00111 // typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, 00112 // const SparseCwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Derived>, 00113 // const Derived& 00114 // >::type ConjugateReturnType; 00115 /* \internal the return type of MatrixBase::real() */ 00116 // typedef SparseCwiseUnaryOp<internal::scalar_real_op<Scalar>, Derived> RealReturnType; 00117 /* \internal the return type of MatrixBase::imag() */ 00118 // typedef SparseCwiseUnaryOp<internal::scalar_imag_op<Scalar>, Derived> ImagReturnType; 00119 /** \internal the return type of MatrixBase::adjoint() */ 00120 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, 00121 CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Eigen::Transpose<Derived> >, 00122 Transpose<Derived> 00123 >::type AdjointReturnType; 00124 00125 typedef SparseMatrix<Scalar, Flags&RowMajorBit ? RowMajor : ColMajor> PlainObject; 00126 00127 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase 00128 #include "../plugins/CommonCwiseUnaryOps.h" 00129 #include "../plugins/CommonCwiseBinaryOps.h" 00130 #include "../plugins/MatrixCwiseUnaryOps.h" 00131 #include "../plugins/MatrixCwiseBinaryOps.h" 00132 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS 00133 00134 #ifndef EIGEN_PARSED_BY_DOXYGEN 00135 /** This is the "real scalar" type; if the \a Scalar type is already real numbers 00136 * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If 00137 * \a Scalar is \a std::complex<T> then RealScalar is \a T. 00138 * 00139 * \sa class NumTraits 00140 */ 00141 typedef typename NumTraits<Scalar>::Real RealScalar; 00142 00143 /** \internal the return type of coeff() 00144 */ 00145 typedef typename internal::conditional<_HasDirectAccess, const Scalar&, Scalar>::type CoeffReturnType; 00146 00147 /** \internal Represents a matrix with all coefficients equal to one another*/ 00148 typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Matrix<Scalar,Dynamic,Dynamic> > ConstantReturnType; 00149 00150 /** type of the equivalent square matrix */ 00151 typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime), 00152 EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType; 00153 00154 inline const Derived& derived() const { return *static_cast<const Derived*>(this); } 00155 inline Derived& derived() { return *static_cast<Derived*>(this); } 00156 inline Derived& const_cast_derived() const 00157 { return *static_cast<Derived*>(const_cast<SparseMatrixBase*>(this)); } 00158 #endif // not EIGEN_PARSED_BY_DOXYGEN 00159 00160 /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ 00161 inline Index rows() const { return derived().rows(); } 00162 /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ 00163 inline Index cols() const { return derived().cols(); } 00164 /** \returns the number of coefficients, which is \a rows()*cols(). 00165 * \sa rows(), cols(), SizeAtCompileTime. */ 00166 inline Index size() const { return rows() * cols(); } 00167 /** \returns the number of nonzero coefficients which is in practice the number 00168 * of stored coefficients. */ 00169 inline Index nonZeros() const { return derived().nonZeros(); } 00170 /** \returns true if either the number of rows or the number of columns is equal to 1. 00171 * In other words, this function returns 00172 * \code rows()==1 || cols()==1 \endcode 00173 * \sa rows(), cols(), IsVectorAtCompileTime. */ 00174 inline bool isVector() const { return rows()==1 || cols()==1; } 00175 /** \returns the size of the storage major dimension, 00176 * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */ 00177 Index outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); } 00178 /** \returns the size of the inner dimension according to the storage order, 00179 * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */ 00180 Index innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); } 00181 00182 bool isRValue() const { return m_isRValue; } 00183 Derived& markAsRValue() { m_isRValue = true; return derived(); } 00184 00185 SparseMatrixBase() : m_isRValue(false) { /* TODO check flags */ } 00186 00187 inline Derived& operator=(const Derived& other) 00188 { 00189 // std::cout << "Derived& operator=(const Derived& other)\n"; 00190 // if (other.isRValue()) 00191 // derived().swap(other.const_cast_derived()); 00192 // else 00193 this->operator=<Derived>(other); 00194 return derived(); 00195 } 00196 00197 template<typename OtherDerived> 00198 Derived& operator=(const ReturnByValue<OtherDerived>& other) 00199 { 00200 other.evalTo(derived()); 00201 return derived(); 00202 } 00203 00204 00205 template<typename OtherDerived> 00206 inline void assignGeneric(const OtherDerived& other) 00207 { 00208 // std::cout << "Derived& operator=(const MatrixBase<OtherDerived>& other)\n"; 00209 //const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); 00210 eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) || 00211 (!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) && 00212 "the transpose operation is supposed to be handled in SparseMatrix::operator="); 00213 00214 enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) }; 00215 00216 const Index outerSize = other.outerSize(); 00217 //typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType; 00218 // thanks to shallow copies, we always eval to a tempary 00219 Derived temp(other.rows(), other.cols()); 00220 00221 temp.reserve(std::max(this->rows(),this->cols())*2); 00222 for (Index j=0; j<outerSize; ++j) 00223 { 00224 temp.startVec(j); 00225 for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) 00226 { 00227 Scalar v = it.value(); 00228 if (v!=Scalar(0)) 00229 temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v; 00230 } 00231 } 00232 temp.finalize(); 00233 00234 derived() = temp.markAsRValue(); 00235 } 00236 00237 00238 template<typename OtherDerived> 00239 inline Derived& operator=(const SparseMatrixBase<OtherDerived>& other) 00240 { 00241 // std::cout << typeid(OtherDerived).name() << "\n"; 00242 // std::cout << Flags << " " << OtherDerived::Flags << "\n"; 00243 const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); 00244 // std::cout << "eval transpose = " << transpose << "\n"; 00245 const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols(); 00246 if ((!transpose) && other.isRValue()) 00247 { 00248 // eval without temporary 00249 derived().resize(other.rows(), other.cols()); 00250 derived().setZero(); 00251 derived().reserve(std::max(this->rows(),this->cols())*2); 00252 for (Index j=0; j<outerSize; ++j) 00253 { 00254 derived().startVec(j); 00255 for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) 00256 { 00257 Scalar v = it.value(); 00258 if (v!=Scalar(0)) 00259 derived().insertBackByOuterInner(j,it.index()) = v; 00260 } 00261 } 00262 derived().finalize(); 00263 } 00264 else 00265 { 00266 assignGeneric(other.derived()); 00267 } 00268 return derived(); 00269 } 00270 00271 template<typename Lhs, typename Rhs> 00272 inline Derived& operator=(const SparseSparseProduct<Lhs,Rhs>& product); 00273 00274 template<typename Lhs, typename Rhs> 00275 inline void _experimentalNewProduct(const Lhs& lhs, const Rhs& rhs); 00276 00277 friend std::ostream & operator << (std::ostream & s, const SparseMatrixBase& m) 00278 { 00279 if (Flags&RowMajorBit) 00280 { 00281 for (Index row=0; row<m.outerSize(); ++row) 00282 { 00283 Index col = 0; 00284 for (typename Derived::InnerIterator it(m.derived(), row); it; ++it) 00285 { 00286 for ( ; col<it.index(); ++col) 00287 s << "0 "; 00288 s << it.value() << " "; 00289 ++col; 00290 } 00291 for ( ; col<m.cols(); ++col) 00292 s << "0 "; 00293 s << std::endl; 00294 } 00295 } 00296 else 00297 { 00298 if (m.cols() == 1) { 00299 Index row = 0; 00300 for (typename Derived::InnerIterator it(m.derived(), 0); it; ++it) 00301 { 00302 for ( ; row<it.index(); ++row) 00303 s << "0" << std::endl; 00304 s << it.value() << std::endl; 00305 ++row; 00306 } 00307 for ( ; row<m.rows(); ++row) 00308 s << "0" << std::endl; 00309 } 00310 else 00311 { 00312 SparseMatrix<Scalar, RowMajorBit> trans = m.derived(); 00313 s << trans; 00314 } 00315 } 00316 return s; 00317 } 00318 00319 // const SparseCwiseUnaryOp<internal::scalar_opposite_op<typename internal::traits<Derived>::Scalar>,Derived> operator-() const; 00320 00321 // template<typename OtherDerived> 00322 // const CwiseBinaryOp<internal::scalar_sum_op<typename internal::traits<Derived>::Scalar>, Derived, OtherDerived> 00323 // operator+(const SparseMatrixBase<OtherDerived> &other) const; 00324 00325 // template<typename OtherDerived> 00326 // const CwiseBinaryOp<internal::scalar_difference_op<typename internal::traits<Derived>::Scalar>, Derived, OtherDerived> 00327 // operator-(const SparseMatrixBase<OtherDerived> &other) const; 00328 00329 template<typename OtherDerived> 00330 Derived& operator+=(const SparseMatrixBase<OtherDerived>& other); 00331 template<typename OtherDerived> 00332 Derived& operator-=(const SparseMatrixBase<OtherDerived>& other); 00333 00334 // template<typename Lhs,typename Rhs> 00335 // Derived& operator+=(const Flagged<Product<Lhs,Rhs,CacheFriendlyProduct>, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other); 00336 00337 Derived& operator*=(const Scalar& other); 00338 Derived& operator/=(const Scalar& other); 00339 00340 #define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \ 00341 CwiseBinaryOp< \ 00342 internal::scalar_product_op< \ 00343 typename internal::scalar_product_traits< \ 00344 typename internal::traits<Derived>::Scalar, \ 00345 typename internal::traits<OtherDerived>::Scalar \ 00346 >::ReturnType \ 00347 >, \ 00348 Derived, \ 00349 OtherDerived \ 00350 > 00351 00352 template<typename OtherDerived> 00353 EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE 00354 cwiseProduct(const MatrixBase<OtherDerived> &other) const; 00355 00356 // const SparseCwiseUnaryOp<internal::scalar_multiple_op<typename internal::traits<Derived>::Scalar>, Derived> 00357 // operator*(const Scalar& scalar) const; 00358 // const SparseCwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>, Derived> 00359 // operator/(const Scalar& scalar) const; 00360 00361 // inline friend const SparseCwiseUnaryOp<internal::scalar_multiple_op<typename internal::traits<Derived>::Scalar>, Derived> 00362 // operator*(const Scalar& scalar, const SparseMatrixBase& matrix) 00363 // { return matrix*scalar; } 00364 00365 00366 // sparse * sparse 00367 template<typename OtherDerived> 00368 const typename SparseSparseProductReturnType<Derived,OtherDerived>::Type 00369 operator*(const SparseMatrixBase<OtherDerived> &other) const; 00370 00371 // sparse * diagonal 00372 template<typename OtherDerived> 00373 const SparseDiagonalProduct<Derived,OtherDerived> 00374 operator*(const DiagonalBase<OtherDerived> &other) const; 00375 00376 // diagonal * sparse 00377 template<typename OtherDerived> friend 00378 const SparseDiagonalProduct<OtherDerived,Derived> 00379 operator*(const DiagonalBase<OtherDerived> &lhs, const SparseMatrixBase& rhs) 00380 { return SparseDiagonalProduct<OtherDerived,Derived>(lhs.derived(), rhs.derived()); } 00381 00382 /** dense * sparse (return a dense object unless it is an outer product) */ 00383 template<typename OtherDerived> friend 00384 const typename DenseSparseProductReturnType<OtherDerived,Derived>::Type 00385 operator*(const MatrixBase<OtherDerived>& lhs, const Derived& rhs) 00386 { return typename DenseSparseProductReturnType<OtherDerived,Derived>::Type(lhs.derived(),rhs); } 00387 00388 /** sparse * dense (returns a dense object unless it is an outer product) */ 00389 template<typename OtherDerived> 00390 const typename SparseDenseProductReturnType<Derived,OtherDerived>::Type 00391 operator*(const MatrixBase<OtherDerived> &other) const; 00392 00393 template<typename OtherDerived> 00394 Derived& operator*=(const SparseMatrixBase<OtherDerived>& other); 00395 00396 #ifdef EIGEN2_SUPPORT 00397 // deprecated 00398 template<typename OtherDerived> 00399 typename internal::plain_matrix_type_column_major<OtherDerived>::type 00400 solveTriangular(const MatrixBase<OtherDerived>& other) const; 00401 00402 // deprecated 00403 template<typename OtherDerived> 00404 void solveTriangularInPlace(MatrixBase<OtherDerived>& other) const; 00405 // template<typename OtherDerived> 00406 // void solveTriangularInPlace(SparseMatrixBase<OtherDerived>& other) const; 00407 #endif // EIGEN2_SUPPORT 00408 00409 template<int Mode> 00410 inline const SparseTriangularView<Derived, Mode> triangularView() const; 00411 00412 template<unsigned int UpLo> inline const SparseSelfAdjointView<Derived, UpLo> selfadjointView() const; 00413 template<unsigned int UpLo> inline SparseSelfAdjointView<Derived, UpLo> selfadjointView(); 00414 00415 template<typename OtherDerived> Scalar dot(const MatrixBase<OtherDerived>& other) const; 00416 template<typename OtherDerived> Scalar dot(const SparseMatrixBase<OtherDerived>& other) const; 00417 RealScalar squaredNorm() const; 00418 RealScalar norm() const; 00419 // const PlainObject normalized() const; 00420 // void normalize(); 00421 00422 Transpose<Derived> transpose() { return derived(); } 00423 const Transpose<Derived> transpose() const { return derived(); } 00424 // void transposeInPlace(); 00425 const AdjointReturnType adjoint() const { return transpose(); } 00426 00427 // sub-vector 00428 SparseInnerVectorSet<Derived,1> row(Index i); 00429 const SparseInnerVectorSet<Derived,1> row(Index i) const; 00430 SparseInnerVectorSet<Derived,1> col(Index j); 00431 const SparseInnerVectorSet<Derived,1> col(Index j) const; 00432 SparseInnerVectorSet<Derived,1> innerVector(Index outer); 00433 const SparseInnerVectorSet<Derived,1> innerVector(Index outer) const; 00434 00435 // set of sub-vectors 00436 SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size); 00437 const SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size) const; 00438 SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size); 00439 const SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size) const; 00440 SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize); 00441 const SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize) const; 00442 00443 // typename BlockReturnType<Derived>::Type block(int startRow, int startCol, int blockRows, int blockCols); 00444 // const typename BlockReturnType<Derived>::Type 00445 // block(int startRow, int startCol, int blockRows, int blockCols) const; 00446 // 00447 // typename BlockReturnType<Derived>::SubVectorType segment(int start, int size); 00448 // const typename BlockReturnType<Derived>::SubVectorType segment(int start, int size) const; 00449 // 00450 // typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size); 00451 // const typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size) const; 00452 // 00453 // typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size); 00454 // const typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size) const; 00455 // 00456 // template<int BlockRows, int BlockCols> 00457 // typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol); 00458 // template<int BlockRows, int BlockCols> 00459 // const typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol) const; 00460 00461 // template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType start(void); 00462 // template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType start() const; 00463 00464 // template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType end(); 00465 // template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType end() const; 00466 00467 // template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType segment(int start); 00468 // template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType segment(int start) const; 00469 00470 // Diagonal<Derived> diagonal(); 00471 // const Diagonal<Derived> diagonal() const; 00472 00473 // template<unsigned int Mode> Part<Derived, Mode> part(); 00474 // template<unsigned int Mode> const Part<Derived, Mode> part() const; 00475 00476 00477 // static const ConstantReturnType Constant(int rows, int cols, const Scalar& value); 00478 // static const ConstantReturnType Constant(int size, const Scalar& value); 00479 // static const ConstantReturnType Constant(const Scalar& value); 00480 00481 // template<typename CustomNullaryOp> 00482 // static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(int rows, int cols, const CustomNullaryOp& func); 00483 // template<typename CustomNullaryOp> 00484 // static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(int size, const CustomNullaryOp& func); 00485 // template<typename CustomNullaryOp> 00486 // static const CwiseNullaryOp<CustomNullaryOp, Derived> NullaryExpr(const CustomNullaryOp& func); 00487 00488 // static const ConstantReturnType Zero(int rows, int cols); 00489 // static const ConstantReturnType Zero(int size); 00490 // static const ConstantReturnType Zero(); 00491 // static const ConstantReturnType Ones(int rows, int cols); 00492 // static const ConstantReturnType Ones(int size); 00493 // static const ConstantReturnType Ones(); 00494 // static const IdentityReturnType Identity(); 00495 // static const IdentityReturnType Identity(int rows, int cols); 00496 // static const BasisReturnType Unit(int size, int i); 00497 // static const BasisReturnType Unit(int i); 00498 // static const BasisReturnType UnitX(); 00499 // static const BasisReturnType UnitY(); 00500 // static const BasisReturnType UnitZ(); 00501 // static const BasisReturnType UnitW(); 00502 00503 // const DiagonalMatrix<Derived> asDiagonal() const; 00504 00505 // Derived& setConstant(const Scalar& value); 00506 // Derived& setZero(); 00507 // Derived& setOnes(); 00508 // Derived& setRandom(); 00509 // Derived& setIdentity(); 00510 00511 /** \internal use operator= */ 00512 template<typename DenseDerived> 00513 void evalTo(MatrixBase<DenseDerived>& dst) const 00514 { 00515 dst.setZero(); 00516 for (Index j=0; j<outerSize(); ++j) 00517 for (typename Derived::InnerIterator i(derived(),j); i; ++i) 00518 dst.coeffRef(i.row(),i.col()) = i.value(); 00519 } 00520 00521 Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> toDense() const 00522 { 00523 return derived(); 00524 } 00525 00526 template<typename OtherDerived> 00527 bool isApprox(const SparseMatrixBase<OtherDerived>& other, 00528 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const 00529 { return toDense().isApprox(other.toDense(),prec); } 00530 00531 template<typename OtherDerived> 00532 bool isApprox(const MatrixBase<OtherDerived>& other, 00533 RealScalar prec = NumTraits<Scalar>::dummy_precision()) const 00534 { return toDense().isApprox(other,prec); } 00535 // bool isMuchSmallerThan(const RealScalar& other, 00536 // RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00537 // template<typename OtherDerived> 00538 // bool isMuchSmallerThan(const MatrixBase<OtherDerived>& other, 00539 // RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00540 00541 // bool isApproxToConstant(const Scalar& value, RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00542 // bool isZero(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00543 // bool isOnes(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00544 // bool isIdentity(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00545 // bool isDiagonal(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00546 00547 // bool isUpper(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00548 // bool isLower(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00549 00550 // template<typename OtherDerived> 00551 // bool isOrthogonal(const MatrixBase<OtherDerived>& other, 00552 // RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00553 // bool isUnitary(RealScalar prec = NumTraits<Scalar>::dummy_precision()) const; 00554 00555 // template<typename OtherDerived> 00556 // inline bool operator==(const MatrixBase<OtherDerived>& other) const 00557 // { return (cwise() == other).all(); } 00558 00559 // template<typename OtherDerived> 00560 // inline bool operator!=(const MatrixBase<OtherDerived>& other) const 00561 // { return (cwise() != other).any(); } 00562 00563 00564 // template<typename NewType> 00565 // const SparseCwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, Derived> cast() const; 00566 00567 /** \returns the matrix or vector obtained by evaluating this expression. 00568 * 00569 * Notice that in the case of a plain matrix or vector (not an expression) this function just returns 00570 * a const reference, in order to avoid a useless copy. 00571 */ 00572 inline const typename internal::eval<Derived>::type eval() const 00573 { return typename internal::eval<Derived>::type(derived()); } 00574 00575 // template<typename OtherDerived> 00576 // void swap(MatrixBase<OtherDerived> const & other); 00577 00578 // template<unsigned int Added> 00579 // const SparseFlagged<Derived, Added, 0> marked() const; 00580 // const Flagged<Derived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit> lazy() const; 00581 00582 /** \returns number of elements to skip to pass from one row (resp. column) to another 00583 * for a row-major (resp. column-major) matrix. 00584 * Combined with coeffRef() and the \ref flags flags, it allows a direct access to the data 00585 * of the underlying matrix. 00586 */ 00587 // inline int stride(void) const { return derived().stride(); } 00588 00589 // FIXME 00590 // ConjugateReturnType conjugate() const; 00591 // const RealReturnType real() const; 00592 // const ImagReturnType imag() const; 00593 00594 // template<typename CustomUnaryOp> 00595 // const SparseCwiseUnaryOp<CustomUnaryOp, Derived> unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const; 00596 00597 // template<typename CustomBinaryOp, typename OtherDerived> 00598 // const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> 00599 // binaryExpr(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const; 00600 00601 00602 Scalar sum() const; 00603 // Scalar trace() const; 00604 00605 // typename internal::traits<Derived>::Scalar minCoeff() const; 00606 // typename internal::traits<Derived>::Scalar maxCoeff() const; 00607 00608 // typename internal::traits<Derived>::Scalar minCoeff(int* row, int* col = 0) const; 00609 // typename internal::traits<Derived>::Scalar maxCoeff(int* row, int* col = 0) const; 00610 00611 // template<typename BinaryOp> 00612 // typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type 00613 // redux(const BinaryOp& func) const; 00614 00615 // template<typename Visitor> 00616 // void visit(Visitor& func) const; 00617 00618 00619 // const SparseCwise<Derived> cwise() const; 00620 // SparseCwise<Derived> cwise(); 00621 00622 // inline const WithFormat<Derived> format(const IOFormat& fmt) const; 00623 00624 /////////// Array module /////////// 00625 /* 00626 bool all(void) const; 00627 bool any(void) const; 00628 00629 const VectorwiseOp<Derived,Horizontal> rowwise() const; 00630 const VectorwiseOp<Derived,Vertical> colwise() const; 00631 00632 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(int rows, int cols); 00633 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(int size); 00634 static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(); 00635 00636 template<typename ThenDerived,typename ElseDerived> 00637 const Select<Derived,ThenDerived,ElseDerived> 00638 select(const MatrixBase<ThenDerived>& thenMatrix, 00639 const MatrixBase<ElseDerived>& elseMatrix) const; 00640 00641 template<typename ThenDerived> 00642 inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType> 00643 select(const MatrixBase<ThenDerived>& thenMatrix, typename ThenDerived::Scalar elseScalar) const; 00644 00645 template<typename ElseDerived> 00646 inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived > 00647 select(typename ElseDerived::Scalar thenScalar, const MatrixBase<ElseDerived>& elseMatrix) const; 00648 00649 template<int p> RealScalar lpNorm() const; 00650 */ 00651 00652 00653 // template<typename OtherDerived> 00654 // Scalar dot(const MatrixBase<OtherDerived>& other) const 00655 // { 00656 // EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) 00657 // EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) 00658 // EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value), 00659 // YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) 00660 // 00661 // eigen_assert(derived().size() == other.size()); 00662 // // short version, but the assembly looks more complicated because 00663 // // of the CwiseBinaryOp iterator complexity 00664 // // return res = (derived().cwise() * other.derived().conjugate()).sum(); 00665 // 00666 // // optimized, generic version 00667 // typename Derived::InnerIterator i(derived(),0); 00668 // typename OtherDerived::InnerIterator j(other.derived(),0); 00669 // Scalar res = 0; 00670 // while (i && j) 00671 // { 00672 // if (i.index()==j.index()) 00673 // { 00674 // // std::cerr << i.value() << " * " << j.value() << "\n"; 00675 // res += i.value() * internal::conj(j.value()); 00676 // ++i; ++j; 00677 // } 00678 // else if (i.index()<j.index()) 00679 // ++i; 00680 // else 00681 // ++j; 00682 // } 00683 // return res; 00684 // } 00685 // 00686 // Scalar sum() const 00687 // { 00688 // Scalar res = 0; 00689 // for (typename Derived::InnerIterator iter(*this,0); iter; ++iter) 00690 // { 00691 // res += iter.value(); 00692 // } 00693 // return res; 00694 // } 00695 00696 protected: 00697 00698 bool m_isRValue; 00699 }; 00700 00701 #endif // EIGEN_SPARSEMATRIXBASE_H
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011 |