cheshirekow  v0.1.0
Sum.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_SUM_H_
28 #define MPBLOCKS_CUDA_LINALG_SUM_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace linalg {
33 
35 template <typename Scalar, class Exp1, class Exp2>
36 class Sum :
37  public RValue<Scalar, Sum<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  Sum( Exp1 const& A, Exp2 const& B ):
47  m_A(A),
48  m_B(B)
49  {
50 // assert( A.size() == B.size() );
51 // assert( A.rows() == B.rows() );
52 // assert( A.cols() == B.cols() );
53  }
54 
57  Size_t size() const
58  {
59  return m_A.size();
60  }
61 
64  Size_t rows() const
65  {
66  return m_A.rows();
67  }
68 
71  Size_t cols() const
72  {
73  return m_A.cols();
74  }
75 
78  Scalar operator[]( Size_t i ) const
79  {
80  return (m_A[i] + m_B[i]);
81  }
82 
85  Scalar operator()( Size_t i, Size_t j )const
86  {
87  return ( m_A(i,j) + m_B(i,j) );
88  }
89 };
90 
91 
92 
93 
94 template <typename Scalar, class Exp1, class Exp2>
97  RValue<Scalar,Exp1> const& A, RValue<Scalar,Exp2> const& B )
98 {
99  typedef Sum<Scalar,Exp1,Exp2> Sum_t;
100  return Sum_t(
101  static_cast<Exp1 const&>(A),
102  static_cast<Exp2 const&>(B));
103 }
104 
105 
106 
107 
108 } // linalg
109 } // cuda
110 } // mpblocks
111 
112 
113 
114 
115 
116 #endif // SUM_H_
Exp2 const & m_B
Definition: Sum.h:40
unsigned int Size_t
Definition: Sum.h:43
__device__ __host__ Sum< Scalar, Exp1, Exp2 > operator+(RValue< Scalar, Exp1 > const &A, RValue< Scalar, Exp2 > const &B)
Definition: Sum.h:96
Exp1 const & m_A
Definition: Sum.h:39
__device__ __host__ Scalar operator[](Size_t i) const
return the evaluated i'th element of a vector expression
Definition: Sum.h:78
__device__ __host__ Sum(Exp1 const &A, Exp2 const &B)
Definition: Sum.h:46
__device__ __host__ Size_t rows() const
return the rows of a matrix expression
Definition: Sum.h:64
expression template for sum of two matrix expressions
Definition: Sum.h:36
#define __device__
Definition: fakecuda.h:34
__device__ __host__ Scalar operator()(Size_t i, Size_t j) const
return the evaluated (i,j)'th element of a matrix expression
Definition: Sum.h:85
#define __host__
Definition: fakecuda.h:37
expression template for rvalues
Definition: RValue.h:41
__device__ __host__ Size_t size() const
return the size for a vector
Definition: Sum.h:57
__device__ __host__ Size_t cols() const
return the columns of a matrix expression
Definition: Sum.h:71