SparseProduct.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-2010 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_SPARSEPRODUCT_H
00026 #define EIGEN_SPARSEPRODUCT_H
00027 
00028 template<typename Lhs, typename Rhs>
00029 struct SparseSparseProductReturnType
00030 {
00031   typedef typename internal::traits<Lhs>::Scalar Scalar;
00032   enum {
00033     LhsRowMajor = internal::traits<Lhs>::Flags & RowMajorBit,
00034     RhsRowMajor = internal::traits<Rhs>::Flags & RowMajorBit,
00035     TransposeRhs = (!LhsRowMajor) && RhsRowMajor,
00036     TransposeLhs = LhsRowMajor && (!RhsRowMajor)
00037   };
00038 
00039   typedef typename internal::conditional<TransposeLhs,
00040     SparseMatrix<Scalar,0>,
00041     const typename internal::nested<Lhs,Rhs::RowsAtCompileTime>::type>::type LhsNested;
00042 
00043   typedef typename internal::conditional<TransposeRhs,
00044     SparseMatrix<Scalar,0>,
00045     const typename internal::nested<Rhs,Lhs::RowsAtCompileTime>::type>::type RhsNested;
00046 
00047   typedef SparseSparseProduct<LhsNested, RhsNested> Type;
00048 };
00049 
00050 namespace internal {
00051 template<typename LhsNested, typename RhsNested>
00052 struct traits<SparseSparseProduct<LhsNested, RhsNested> >
00053 {
00054   typedef MatrixXpr XprKind;
00055   // clean the nested types:
00056   typedef typename remove_all<LhsNested>::type _LhsNested;
00057   typedef typename remove_all<RhsNested>::type _RhsNested;
00058   typedef typename _LhsNested::Scalar Scalar;
00059   typedef typename promote_index_type<typename traits<_LhsNested>::Index,
00060                                          typename traits<_RhsNested>::Index>::type Index;
00061 
00062   enum {
00063     LhsCoeffReadCost = _LhsNested::CoeffReadCost,
00064     RhsCoeffReadCost = _RhsNested::CoeffReadCost,
00065     LhsFlags = _LhsNested::Flags,
00066     RhsFlags = _RhsNested::Flags,
00067 
00068     RowsAtCompileTime    = _LhsNested::RowsAtCompileTime,
00069     ColsAtCompileTime    = _RhsNested::ColsAtCompileTime,
00070     MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime,
00071     MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime,
00072 
00073     InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime),
00074 
00075     EvalToRowMajor = (RhsFlags & LhsFlags & RowMajorBit),
00076 
00077     RemovedBits = ~(EvalToRowMajor ? 0 : RowMajorBit),
00078 
00079     Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits)
00080           | EvalBeforeAssigningBit
00081           | EvalBeforeNestingBit,
00082 
00083     CoeffReadCost = Dynamic
00084   };
00085 
00086   typedef Sparse StorageKind;
00087 };
00088 
00089 } // end namespace internal
00090 
00091 template<typename LhsNested, typename RhsNested>
00092 class SparseSparseProduct : internal::no_assignment_operator,
00093   public SparseMatrixBase<SparseSparseProduct<LhsNested, RhsNested> >
00094 {
00095   public:
00096 
00097     typedef SparseMatrixBase<SparseSparseProduct> Base;
00098     EIGEN_DENSE_PUBLIC_INTERFACE(SparseSparseProduct)
00099 
00100   private:
00101 
00102     typedef typename internal::traits<SparseSparseProduct>::_LhsNested _LhsNested;
00103     typedef typename internal::traits<SparseSparseProduct>::_RhsNested _RhsNested;
00104 
00105   public:
00106 
00107     template<typename Lhs, typename Rhs>
00108     EIGEN_STRONG_INLINE SparseSparseProduct(const Lhs& lhs, const Rhs& rhs)
00109       : m_lhs(lhs), m_rhs(rhs)
00110     {
00111       eigen_assert(lhs.cols() == rhs.rows());
00112 
00113       enum {
00114         ProductIsValid = _LhsNested::ColsAtCompileTime==Dynamic
00115                       || _RhsNested::RowsAtCompileTime==Dynamic
00116                       || int(_LhsNested::ColsAtCompileTime)==int(_RhsNested::RowsAtCompileTime),
00117         AreVectors = _LhsNested::IsVectorAtCompileTime && _RhsNested::IsVectorAtCompileTime,
00118         SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(_LhsNested,_RhsNested)
00119       };
00120       // note to the lost user:
00121       //    * for a dot product use: v1.dot(v2)
00122       //    * for a coeff-wise product use: v1.cwise()*v2
00123       EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
00124         INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
00125       EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
00126         INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
00127       EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
00128     }
00129 
00130     EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); }
00131     EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); }
00132 
00133     EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; }
00134     EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; }
00135 
00136   protected:
00137     LhsNested m_lhs;
00138     RhsNested m_rhs;
00139 };
00140 
00141 #endif // EIGEN_SPARSEPRODUCT_H


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