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_LINALG2_SUM_H_
28 #define MPBLOCKS_CUDA_LINALG2_SUM_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace linalg2 {
33 
35 template <typename Scalar, Size_t ROWS, Size_t COLS, class Exp1, class Exp2>
36 class Sum:
37  public RValue< Scalar, ROWS, COLS, Sum< Scalar, ROWS, COLS, Exp1, Exp2> >
38 {
39  Exp1 const& m_A;
40  Exp2 const& m_B;
41 
42  public:
44  Sum( Exp1 const& A, Exp2 const& B ):
45  m_A(A),
46  m_B(B)
47  {}
48 
50  template< Size_t i >
52  Scalar ve() const
53  {
54  return m_A.Exp1::template ve<i>()
55  + m_B.Exp2::template ve<i>();
56  }
57 
59  template< Size_t i, Size_t j >
61  Scalar me() const
62  {
63  return m_A.Exp1::template me<i,j>()
64  + m_B.Exp2::template me<i,j>();
65  }
66 };
67 
68 
69 
70 
71 template <typename Scalar, Size_t ROWS, Size_t COLS, class Exp1, class Exp2>
72 __device__ __host__ inline
73 Sum< Scalar, ROWS, COLS, Exp1, Exp2 >
76 {
78  static_cast< Exp1 const& >(A),
79  static_cast< Exp2 const& >(B) );
80 }
81 
82 
83 
84 
85 
86 } // linalg
87 } // cuda
88 } // mpblocks
89 
90 
91 
92 
93 
94 #endif // SUM_H_
expression template for rvalues
Definition: RValue.h:36
expression template for sum of two expressions
Definition: Sum.h:36
__device__ __host__ Sum< Scalar, ROWS, COLS, Exp1, Exp2 > operator+(RValue< Scalar, ROWS, COLS, Exp1 > const &A, RValue< Scalar, ROWS, COLS, Exp2 > const &B)
Definition: Sum.h:74
Exp2 const & m_B
Definition: Sum.h:40
#define __device__
Definition: fakecuda.h:34
__device__ __host__ Scalar me() const
return the evaluated (j,i)'th element of a matrix expression
Definition: Sum.h:61
#define __host__
Definition: fakecuda.h:37
__device__ __host__ Scalar ve() const
return the evaluated i'th element of a vector expression
Definition: Sum.h:52
Exp1 const & m_A
Definition: Sum.h:39
__device__ __host__ Sum(Exp1 const &A, Exp2 const &B)
Definition: Sum.h:44