cheshirekow  v0.1.0
Product.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_CUDA_LINALG_PRODUCT_H_
28 #define MPBLOCKS_CUDA_LINALG_PRODUCT_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace linalg {
33 
35 template <typename Scalar, class Exp1, class Exp2>
36 class Product :
37  public RValue<Scalar, Product<Scalar,Exp1,Exp2> >
38 {
39  Exp1 const& m_A;
40  Exp2 const& m_B;
41 
42  public:
43  typedef unsigned int Size_t;
44 
46  Product( Exp1 const& A, Exp2 const& B ):
47  m_A(A),
48  m_B(B)
49  {
50 // assert( A.cols() == B.rows() );
51  }
52 
55  Size_t size() const
56  {
57  return ( m_A.rows() * m_B.cols() );
58  }
59 
62  Size_t rows() const
63  {
64  return m_A.rows();
65  }
66 
69  Size_t cols() const
70  {
71  return m_B.cols();
72  }
73 
76  Scalar operator[]( Size_t i ) const
77  {
78  return 0;
79  }
80 
83  Scalar operator()( Size_t i, Size_t j )const
84  {
85  Scalar r = 0;
86  for(int k=0; k < m_A.cols(); k++ )
87  r += m_A(i,k) * m_B(k,j);
88  return r;
89  }
90 };
91 
92 
93 template <typename Scalar, class Exp1, class Exp2>
96  RValue<Scalar,Exp1> const& A, RValue<Scalar,Exp2> const& B )
97 {
98  typedef Product<Scalar,Exp1,Exp2> Product_t;
99  return Product_t( static_cast< Exp1 const& >(A),
100  static_cast< Exp2 const& >(B) );
101 }
102 
103 
104 
105 } // linalg
106 } // cuda
107 } // mpblocks
108 
109 
110 
111 
112 
113 #endif // PRODUCT_H_
__device__ __host__ Size_t cols() const
return the columns of a matrix expression
Definition: Product.h:69
__device__ __host__ Scalar operator()(Size_t i, Size_t j) const
return the evaluated (i,j)'th element of a matrix expression
Definition: Product.h:83
__device__ __host__ Size_t size() const
return the size for a vector
Definition: Product.h:55
__device__ __host__ Product< Scalar, Exp1, Exp2 > operator*(RValue< Scalar, Exp1 > const &A, RValue< Scalar, Exp2 > const &B)
Definition: Product.h:95
__device__ __host__ Size_t rows() const
return the rows of a matrix expression
Definition: Product.h:62
__device__ __host__ Scalar operator[](Size_t i) const
return the evaluated i'th element of a vector expression
Definition: Product.h:76
expression template for product of two matrix expressions
Definition: Product.h:36
#define __device__
Definition: fakecuda.h:34
#define __host__
Definition: fakecuda.h:37
expression template for rvalues
Definition: RValue.h:41
__device__ __host__ Product(Exp1 const &A, Exp2 const &B)
Definition: Product.h:46