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_POLYNOMIAL_SUM_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_SUM_H_
29 
31 
32 namespace mpblocks {
33 namespace cuda {
34 namespace polynomial {
35 
37 template <typename Scalar,
38  class Exp1, class Spec1,
39  class Exp2, class Spec2>
40 struct Sum:
41  public RValue<Scalar, Sum<Scalar,Exp1,Spec1,Exp2,Spec2>,
42  typename intlist::make_union<Spec1,Spec2>::result >
43 {
44  Exp1 const& A;
45  Exp2 const& B;
46 
47  public:
49  Sum( Exp1 const& A, Exp2 const& B ):
50  A(A),
51  B(B)
52  {}
53 
55  Scalar eval( Scalar x )
56  {
57  return A.eval(x) + B.eval(x);
58  }
59 };
60 
61 
62 
63 template <typename Scalar,
64  class Exp1, class Spec1,
65  class Exp2, class Spec2>
66 struct get_spec< Sum<Scalar,Exp1,Spec1,Exp2,Spec2> >
67 {
69 };
70 
71 
72 template <int idx, typename Scalar,
73  class Exp1, class Spec1,
74  class Exp2, class Spec2>
76 Scalar get( const Sum<Scalar,Exp1,Spec1,Exp2,Spec2>& sum )
77 {
78  return get<idx>( sum.A ) + get<idx>( sum.B );
79 }
80 
81 
82 
83 template <typename Scalar, class Exp1, class Spec1, class Exp2, class Spec2>
87  RValue<Scalar,Exp2,Spec2> const& B )
88 {
90  return Sum_t(
91  static_cast<Exp1 const&>(A),
92  static_cast<Exp2 const&>(B));
93 }
94 
95 
96 
97 
98 } // polynomial
99 } // cuda
100 } // mpblocks
101 
102 
103 
104 
105 
106 #endif // SUM_H_
expression template for sum of two matrix expressions
Definition: Sum.h:40
expression template for rvalues
Definition: RValue.h:40
__host__ __device__ Sum(Exp1 const &A, Exp2 const &B)
Definition: Sum.h:49
__host__ __device__ Scalar eval(Scalar x)
Definition: Sum.h:55
#define __device__
Definition: fakecuda.h:34
__host__ __device__ __forceinline__ ScalarSum< Scalar, Exp, Spec > operator+(const Scalar &a, RValue< Scalar, Exp, Spec > const &B)
Definition: ScalarSum.h:102
#define __host__
Definition: fakecuda.h:37
strip_dups< typename merge_sort< typename join< IntList1, IntList2 >::result >::result >::result result
Definition: IntList.h:392