1 // This file is part of Eigen, a lightweight C++ template library 2 // for linear algebra. 3 // 4 // Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud (at) inria.fr> 5 // 6 // This Source Code Form is subject to the terms of the Mozilla Public 7 // License, v. 2.0. If a copy of the MPL was not distributed with this 8 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 10 #ifndef EIGEN_PRODUCT_H 11 #define EIGEN_PRODUCT_H 12 13 template<typename Lhs, typename Rhs> class Product; 14 template<typename Lhs, typename Rhs, typename StorageKind> class ProductImpl; 15 16 /** \class Product 17 * \ingroup Core_Module 18 * 19 * \brief Expression of the product of two arbitrary matrices or vectors 20 * 21 * \param Lhs the type of the left-hand side expression 22 * \param Rhs the type of the right-hand side expression 23 * 24 * This class represents an expression of the product of two arbitrary matrices. 25 * 26 */ 27 28 namespace internal { 29 template<typename Lhs, typename Rhs> 30 struct traits<Product<Lhs, Rhs> > 31 { 32 typedef MatrixXpr XprKind; 33 typedef typename remove_all<Lhs>::type LhsCleaned; 34 typedef typename remove_all<Rhs>::type RhsCleaned; 35 typedef typename scalar_product_traits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar; 36 typedef typename promote_storage_type<typename traits<LhsCleaned>::StorageKind, 37 typename traits<RhsCleaned>::StorageKind>::ret StorageKind; 38 typedef typename promote_index_type<typename traits<LhsCleaned>::Index, 39 typename traits<RhsCleaned>::Index>::type Index; 40 enum { 41 RowsAtCompileTime = LhsCleaned::RowsAtCompileTime, 42 ColsAtCompileTime = RhsCleaned::ColsAtCompileTime, 43 MaxRowsAtCompileTime = LhsCleaned::MaxRowsAtCompileTime, 44 MaxColsAtCompileTime = RhsCleaned::MaxColsAtCompileTime, 45 Flags = (MaxRowsAtCompileTime==1 ? RowMajorBit : 0), // TODO should be no storage order 46 CoeffReadCost = 0 // TODO CoeffReadCost should not be part of the expression traits 47 }; 48 }; 49 } // end namespace internal 50 51 52 template<typename Lhs, typename Rhs> 53 class Product : public ProductImpl<Lhs,Rhs,typename internal::promote_storage_type<typename internal::traits<Lhs>::StorageKind, 54 typename internal::traits<Rhs>::StorageKind>::ret> 55 { 56 public: 57 58 typedef typename ProductImpl< 59 Lhs, Rhs, 60 typename internal::promote_storage_type<typename Lhs::StorageKind, 61 typename Rhs::StorageKind>::ret>::Base Base; 62 EIGEN_GENERIC_PUBLIC_INTERFACE(Product) 63 64 typedef typename Lhs::Nested LhsNested; 65 typedef typename Rhs::Nested RhsNested; 66 typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned; 67 typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned; 68 69 Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) 70 { 71 eigen_assert(lhs.cols() == rhs.rows() 72 && "invalid matrix product" 73 && "if you wanted a coeff-wise or a dot product use the respective explicit functions"); 74 } 75 76 inline Index rows() const { return m_lhs.rows(); } 77 inline Index cols() const { return m_rhs.cols(); } 78 79 const LhsNestedCleaned& lhs() const { return m_lhs; } 80 const RhsNestedCleaned& rhs() const { return m_rhs; } 81 82 protected: 83 84 const LhsNested m_lhs; 85 const RhsNested m_rhs; 86 }; 87 88 template<typename Lhs, typename Rhs> 89 class ProductImpl<Lhs,Rhs,Dense> : public internal::dense_xpr_base<Product<Lhs,Rhs> >::type 90 { 91 typedef Product<Lhs, Rhs> Derived; 92 public: 93 94 typedef typename internal::dense_xpr_base<Product<Lhs, Rhs> >::type Base; 95 EIGEN_DENSE_PUBLIC_INTERFACE(Derived) 96 }; 97 98 #endif // EIGEN_PRODUCT_H 99