Product.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-2011 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_PRODUCT_H
00026 #define EIGEN_PRODUCT_H
00027 
00028 template<typename Lhs, typename Rhs> class Product;
00029 template<typename Lhs, typename Rhs, typename StorageKind> class ProductImpl;
00030 
00043 namespace internal {
00044 template<typename Lhs, typename Rhs>
00045 struct traits<Product<Lhs, Rhs> >
00046 {
00047   typedef MatrixXpr XprKind;
00048   typedef typename remove_all<Lhs>::type LhsCleaned;
00049   typedef typename remove_all<Rhs>::type RhsCleaned;
00050   typedef typename scalar_product_traits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
00051   typedef typename promote_storage_type<typename traits<LhsCleaned>::StorageKind,
00052                                         typename traits<RhsCleaned>::StorageKind>::ret StorageKind;
00053   typedef typename promote_index_type<typename traits<LhsCleaned>::Index,
00054                                       typename traits<RhsCleaned>::Index>::type Index;
00055   enum {
00056     RowsAtCompileTime = LhsCleaned::RowsAtCompileTime,
00057     ColsAtCompileTime = RhsCleaned::ColsAtCompileTime,
00058     MaxRowsAtCompileTime = LhsCleaned::MaxRowsAtCompileTime,
00059     MaxColsAtCompileTime = RhsCleaned::MaxColsAtCompileTime,
00060     Flags = (MaxRowsAtCompileTime==1 ? RowMajorBit : 0), // TODO should be no storage order
00061     CoeffReadCost = 0 // TODO CoeffReadCost should not be part of the expression traits
00062   };
00063 };
00064 } // end namespace internal
00065 
00066 
00067 template<typename Lhs, typename Rhs>
00068 class Product : public ProductImpl<Lhs,Rhs,typename internal::promote_storage_type<typename internal::traits<Lhs>::StorageKind,
00069                                                                             typename internal::traits<Rhs>::StorageKind>::ret>
00070 {
00071   public:
00072     
00073     typedef typename ProductImpl<
00074         Lhs, Rhs,
00075         typename internal::promote_storage_type<typename Lhs::StorageKind,
00076                                                 typename Rhs::StorageKind>::ret>::Base Base;
00077     EIGEN_GENERIC_PUBLIC_INTERFACE(Product)
00078 
00079     typedef typename Lhs::Nested LhsNested;
00080     typedef typename Rhs::Nested RhsNested;
00081     typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
00082     typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
00083 
00084     Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
00085     {
00086       eigen_assert(lhs.cols() == rhs.rows()
00087         && "invalid matrix product"
00088         && "if you wanted a coeff-wise or a dot product use the respective explicit functions");
00089     }
00090 
00091     inline Index rows() const { return m_lhs.rows(); }
00092     inline Index cols() const { return m_rhs.cols(); }
00093 
00094     const LhsNestedCleaned& lhs() const { return m_lhs; }
00095     const RhsNestedCleaned& rhs() const { return m_rhs; }
00096 
00097   protected:
00098 
00099     const LhsNested m_lhs;
00100     const RhsNested m_rhs;
00101 };
00102 
00103 template<typename Lhs, typename Rhs>
00104 class ProductImpl<Lhs,Rhs,Dense> : public internal::dense_xpr_base<Product<Lhs,Rhs> >::type
00105 {
00106     typedef Product<Lhs, Rhs> Derived;
00107   public:
00108 
00109     typedef typename internal::dense_xpr_base<Product<Lhs, Rhs> >::type Base;
00110     EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
00111 };
00112 
00113 #endif // EIGEN_PRODUCT_H