Product.h
Go to the documentation of this file.
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@inria.fr>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_PRODUCT_H
26 #define EIGEN_PRODUCT_H
27 
28 template<typename Lhs, typename Rhs> class Product;
29 template<typename Lhs, typename Rhs, typename StorageKind> class ProductImpl;
30 
43 namespace internal {
44 template<typename Lhs, typename Rhs>
45 struct traits<Product<Lhs, Rhs> >
46 {
47  typedef MatrixXpr XprKind;
48  typedef typename remove_all<Lhs>::type LhsCleaned;
49  typedef typename remove_all<Rhs>::type RhsCleaned;
50  typedef typename scalar_product_traits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
51  typedef typename promote_storage_type<typename traits<LhsCleaned>::StorageKind,
52  typename traits<RhsCleaned>::StorageKind>::ret StorageKind;
53  typedef typename promote_index_type<typename traits<LhsCleaned>::Index,
54  typename traits<RhsCleaned>::Index>::type Index;
55  enum {
56  RowsAtCompileTime = LhsCleaned::RowsAtCompileTime,
57  ColsAtCompileTime = RhsCleaned::ColsAtCompileTime,
58  MaxRowsAtCompileTime = LhsCleaned::MaxRowsAtCompileTime,
59  MaxColsAtCompileTime = RhsCleaned::MaxColsAtCompileTime,
60  Flags = (MaxRowsAtCompileTime==1 ? RowMajorBit : 0), // TODO should be no storage order
61  CoeffReadCost = 0 // TODO CoeffReadCost should not be part of the expression traits
62  };
63 };
64 } // end namespace internal
65 
66 
67 template<typename Lhs, typename Rhs>
68 class Product : public ProductImpl<Lhs,Rhs,typename internal::promote_storage_type<typename internal::traits<Lhs>::StorageKind,
69  typename internal::traits<Rhs>::StorageKind>::ret>
70 {
71  public:
72 
73  typedef typename ProductImpl<
74  Lhs, Rhs,
75  typename internal::promote_storage_type<typename Lhs::StorageKind,
76  typename Rhs::StorageKind>::ret>::Base Base;
78 
79  typedef typename Lhs::Nested LhsNested;
80  typedef typename Rhs::Nested RhsNested;
81  typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
82  typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
83 
84  Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
85  {
86  eigen_assert(lhs.cols() == rhs.rows()
87  && "invalid matrix product"
88  && "if you wanted a coeff-wise or a dot product use the respective explicit functions");
89  }
90 
91  inline Index rows() const { return m_lhs.rows(); }
92  inline Index cols() const { return m_rhs.cols(); }
93 
94  const LhsNestedCleaned& lhs() const { return m_lhs; }
95  const RhsNestedCleaned& rhs() const { return m_rhs; }
96 
97  protected:
98 
101 };
102 
103 template<typename Lhs, typename Rhs>
104 class ProductImpl<Lhs,Rhs,Dense> : public internal::dense_xpr_base<Product<Lhs,Rhs> >::type
105 {
106  typedef Product<Lhs, Rhs> Derived;
107  public:
108 
109  typedef typename internal::dense_xpr_base<Product<Lhs, Rhs> >::type Base;
111 };
112 
113 #endif // EIGEN_PRODUCT_H