Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:07

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_SKYLINEMATRIXBASE_H
0011 #define EIGEN_SKYLINEMATRIXBASE_H
0012 
0013 #include "SkylineUtil.h"
0014 
0015 namespace Eigen {
0016 
0017 /** \ingroup Skyline_Module
0018  *
0019  * \class SkylineMatrixBase
0020  *
0021  * \brief Base class of any skyline matrices or skyline expressions
0022  *
0023  * \param Derived
0024  *
0025  */
0026 template<typename Derived> class SkylineMatrixBase : public EigenBase<Derived> {
0027 public:
0028 
0029     typedef typename internal::traits<Derived>::Scalar Scalar;
0030     typedef typename internal::traits<Derived>::StorageKind StorageKind;
0031     typedef typename internal::index<StorageKind>::type Index;
0032 
0033     enum {
0034         RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
0035         /**< The number of rows at compile-time. This is just a copy of the value provided
0036          * by the \a Derived type. If a value is not known at compile-time,
0037          * it is set to the \a Dynamic constant.
0038          * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
0039 
0040         ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
0041         /**< The number of columns at compile-time. This is just a copy of the value provided
0042          * by the \a Derived type. If a value is not known at compile-time,
0043          * it is set to the \a Dynamic constant.
0044          * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
0045 
0046 
0047         SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
0048         internal::traits<Derived>::ColsAtCompileTime>::ret),
0049         /**< This is equal to the number of coefficients, i.e. the number of
0050          * rows times the number of columns, or to \a Dynamic if this is not
0051          * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
0052 
0053         MaxRowsAtCompileTime = RowsAtCompileTime,
0054         MaxColsAtCompileTime = ColsAtCompileTime,
0055 
0056         MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
0057         MaxColsAtCompileTime>::ret),
0058 
0059         IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1,
0060         /**< This is set to true if either the number of rows or the number of
0061          * columns is known at compile-time to be equal to 1. Indeed, in that case,
0062          * we are dealing with a column-vector (if there is only one column) or with
0063          * a row-vector (if there is only one row). */
0064 
0065         Flags = internal::traits<Derived>::Flags,
0066         /**< This stores expression \ref flags flags which may or may not be inherited by new expressions
0067          * constructed from this one. See the \ref flags "list of flags".
0068          */
0069 
0070         CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
0071         /**< This is a rough measure of how expensive it is to read one coefficient from
0072          * this expression.
0073          */
0074 
0075         IsRowMajor = Flags & RowMajorBit ? 1 : 0
0076     };
0077 
0078 #ifndef EIGEN_PARSED_BY_DOXYGEN
0079     /** This is the "real scalar" type; if the \a Scalar type is already real numbers
0080      * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If
0081      * \a Scalar is \a std::complex<T> then RealScalar is \a T.
0082      *
0083      * \sa class NumTraits
0084      */
0085     typedef typename NumTraits<Scalar>::Real RealScalar;
0086 
0087     /** type of the equivalent square matrix */
0088     typedef Matrix<Scalar, EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime),
0089                            EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime) > SquareMatrixType;
0090 
0091     inline const Derived& derived() const {
0092         return *static_cast<const Derived*> (this);
0093     }
0094 
0095     inline Derived& derived() {
0096         return *static_cast<Derived*> (this);
0097     }
0098 
0099     inline Derived& const_cast_derived() const {
0100         return *static_cast<Derived*> (const_cast<SkylineMatrixBase*> (this));
0101     }
0102 #endif // not EIGEN_PARSED_BY_DOXYGEN
0103 
0104     /** \returns the number of rows. \sa cols(), RowsAtCompileTime */
0105     inline EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT {
0106         return derived().rows();
0107     }
0108 
0109     /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
0110     inline EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT {
0111         return derived().cols();
0112     }
0113 
0114     /** \returns the number of coefficients, which is \a rows()*cols().
0115      * \sa rows(), cols(), SizeAtCompileTime. */
0116     inline EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT {
0117         return rows() * cols();
0118     }
0119 
0120     /** \returns the number of nonzero coefficients which is in practice the number
0121      * of stored coefficients. */
0122     inline Index nonZeros() const {
0123         return derived().nonZeros();
0124     }
0125 
0126     /** \returns the size of the storage major dimension,
0127      * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */
0128     Index outerSize() const {
0129         return (int(Flags) & RowMajorBit) ? this->rows() : this->cols();
0130     }
0131 
0132     /** \returns the size of the inner dimension according to the storage order,
0133      * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */
0134     Index innerSize() const {
0135         return (int(Flags) & RowMajorBit) ? this->cols() : this->rows();
0136     }
0137 
0138     bool isRValue() const {
0139         return m_isRValue;
0140     }
0141 
0142     Derived& markAsRValue() {
0143         m_isRValue = true;
0144         return derived();
0145     }
0146 
0147     SkylineMatrixBase() : m_isRValue(false) {
0148         /* TODO check flags */
0149     }
0150 
0151     inline Derived & operator=(const Derived& other) {
0152         this->operator=<Derived > (other);
0153         return derived();
0154     }
0155 
0156     template<typename OtherDerived>
0157     inline void assignGeneric(const OtherDerived& other) {
0158         derived().resize(other.rows(), other.cols());
0159         for (Index row = 0; row < rows(); row++)
0160             for (Index col = 0; col < cols(); col++) {
0161                 if (other.coeff(row, col) != Scalar(0))
0162                     derived().insert(row, col) = other.coeff(row, col);
0163             }
0164         derived().finalize();
0165     }
0166 
0167     template<typename OtherDerived>
0168             inline Derived & operator=(const SkylineMatrixBase<OtherDerived>& other) {
0169         //TODO
0170     }
0171 
0172     template<typename Lhs, typename Rhs>
0173             inline Derived & operator=(const SkylineProduct<Lhs, Rhs, SkylineTimeSkylineProduct>& product);
0174 
0175     friend std::ostream & operator <<(std::ostream & s, const SkylineMatrixBase& m) {
0176         s << m.derived();
0177         return s;
0178     }
0179 
0180     template<typename OtherDerived>
0181     const typename SkylineProductReturnType<Derived, OtherDerived>::Type
0182     operator*(const MatrixBase<OtherDerived> &other) const;
0183 
0184     /** \internal use operator= */
0185     template<typename DenseDerived>
0186     void evalTo(MatrixBase<DenseDerived>& dst) const {
0187         dst.setZero();
0188         for (Index i = 0; i < rows(); i++)
0189             for (Index j = 0; j < rows(); j++)
0190                 dst(i, j) = derived().coeff(i, j);
0191     }
0192 
0193     Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> toDense() const {
0194         return derived();
0195     }
0196 
0197     /** \returns the matrix or vector obtained by evaluating this expression.
0198      *
0199      * Notice that in the case of a plain matrix or vector (not an expression) this function just returns
0200      * a const reference, in order to avoid a useless copy.
0201      */
0202     EIGEN_STRONG_INLINE const typename internal::eval<Derived, IsSkyline>::type eval() const {
0203         return typename internal::eval<Derived>::type(derived());
0204     }
0205 
0206 protected:
0207     bool m_isRValue;
0208 };
0209 
0210 } // end namespace Eigen
0211 
0212 #endif // EIGEN_SKYLINEMATRIXBASE_H