SkylineMatrixBase.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.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_SKYLINEMATRIXBASE_H
00026 #define EIGEN_SKYLINEMATRIXBASE_H
00027 
00028 #include "SkylineUtil.h"
00029 
00039 template<typename Derived> class SkylineMatrixBase : public EigenBase<Derived> {
00040 public:
00041 
00042     typedef typename internal::traits<Derived>::Scalar Scalar;
00043     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00044     typedef typename internal::index<StorageKind>::type Index;
00045 
00046     enum {
00047         RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
00053         ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
00060         SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
00061         internal::traits<Derived>::ColsAtCompileTime>::ret),
00066         MaxRowsAtCompileTime = RowsAtCompileTime,
00067         MaxColsAtCompileTime = ColsAtCompileTime,
00068 
00069         MaxSizeAtCompileTime = (internal::size_at_compile_time<MaxRowsAtCompileTime,
00070         MaxColsAtCompileTime>::ret),
00071 
00072         IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1,
00078         Flags = internal::traits<Derived>::Flags,
00083         CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
00088         IsRowMajor = Flags & RowMajorBit ? 1 : 0
00089     };
00090 
00091 #ifndef EIGEN_PARSED_BY_DOXYGEN
00092 
00098     typedef typename NumTraits<Scalar>::Real RealScalar;
00099 
00101     typedef Matrix<Scalar, EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime),
00102                            EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime) > SquareMatrixType;
00103 
00104     inline const Derived& derived() const {
00105         return *static_cast<const Derived*> (this);
00106     }
00107 
00108     inline Derived& derived() {
00109         return *static_cast<Derived*> (this);
00110     }
00111 
00112     inline Derived& const_cast_derived() const {
00113         return *static_cast<Derived*> (const_cast<SkylineMatrixBase*> (this));
00114     }
00115 #endif // not EIGEN_PARSED_BY_DOXYGEN
00116 
00118     inline Index rows() const {
00119         return derived().rows();
00120     }
00121 
00123     inline Index cols() const {
00124         return derived().cols();
00125     }
00126 
00129     inline Index size() const {
00130         return rows() * cols();
00131     }
00132 
00135     inline Index nonZeros() const {
00136         return derived().nonZeros();
00137     }
00138 
00141     Index outerSize() const {
00142         return (int(Flags) & RowMajorBit) ? this->rows() : this->cols();
00143     }
00144 
00147     Index innerSize() const {
00148         return (int(Flags) & RowMajorBit) ? this->cols() : this->rows();
00149     }
00150 
00151     bool isRValue() const {
00152         return m_isRValue;
00153     }
00154 
00155     Derived& markAsRValue() {
00156         m_isRValue = true;
00157         return derived();
00158     }
00159 
00160     SkylineMatrixBase() : m_isRValue(false) {
00161         /* TODO check flags */
00162     }
00163 
00164     inline Derived & operator=(const Derived& other) {
00165         this->operator=<Derived > (other);
00166         return derived();
00167     }
00168 
00169     template<typename OtherDerived>
00170     inline void assignGeneric(const OtherDerived& other) {
00171         derived().resize(other.rows(), other.cols());
00172         for (Index row = 0; row < rows(); row++)
00173             for (Index col = 0; col < cols(); col++) {
00174                 if (other.coeff(row, col) != Scalar(0))
00175                     derived().insert(row, col) = other.coeff(row, col);
00176             }
00177         derived().finalize();
00178     }
00179 
00180     template<typename OtherDerived>
00181             inline Derived & operator=(const SkylineMatrixBase<OtherDerived>& other) {
00182         //TODO
00183     }
00184 
00185     template<typename Lhs, typename Rhs>
00186             inline Derived & operator=(const SkylineProduct<Lhs, Rhs, SkylineTimeSkylineProduct>& product);
00187 
00188     friend std::ostream & operator <<(std::ostream & s, const SkylineMatrixBase& m) {
00189         s << m.derived();
00190         return s;
00191     }
00192 
00193     template<typename OtherDerived>
00194     const typename SkylineProductReturnType<Derived, OtherDerived>::Type
00195     operator*(const MatrixBase<OtherDerived> &other) const;
00196 
00198     template<typename DenseDerived>
00199     void evalTo(MatrixBase<DenseDerived>& dst) const {
00200         dst.setZero();
00201         for (Index i = 0; i < rows(); i++)
00202             for (Index j = 0; j < rows(); j++)
00203                 dst(i, j) = derived().coeff(i, j);
00204     }
00205 
00206     Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> toDense() const {
00207         return derived();
00208     }
00209 
00215     EIGEN_STRONG_INLINE const typename internal::eval<Derived, IsSkyline>::type eval() const {
00216         return typename internal::eval<Derived>::type(derived());
00217     }
00218 
00219 protected:
00220     bool m_isRValue;
00221 };
00222 
00223 #endif // EIGEN_SkylineMatrixBase_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:32