cheshirekow  v0.1.0
Difference.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_DIFFERENCE_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_DIFFERENCE_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace polynomial {
33 
35 template <typename Scalar,
36  class Exp1, class Spec1,
37  class Exp2, class Spec2>
38 struct Difference:
39  public RValue<Scalar, Difference<Scalar,Exp1,Spec1,Exp2,Spec2>,
40  typename intlist::make_union<Spec1,Spec2>::result >
41 {
42  Exp1 const& A;
43  Exp2 const& B;
44 
45  public:
47  Difference( Exp1 const& A, Exp2 const& B ):
48  A(A),
49  B(B)
50  {}
51 
53  Scalar eval( Scalar x )
54  {
55  return A.eval(x) - B.eval(x);
56  }
57 };
58 
59 
60 
61 template <typename Scalar,
62  class Exp1, class Spec1,
63  class Exp2, class Spec2>
64 struct get_spec< Difference<Scalar,Exp1,Spec1,Exp2,Spec2> >
65 {
67 };
68 
69 
70 template <int idx, typename Scalar,
71  class Exp1, class Spec1,
72  class Exp2, class Spec2>
75 {
76  return get<idx>( sum.A ) - get<idx>( sum.B );
77 }
78 
79 
80 
81 
82 template <typename Scalar, class Exp1, class Spec1, class Exp2, class Spec2>
86  RValue<Scalar,Exp2,Spec2> const& B )
87 {
88  typedef Difference<Scalar,Exp1,Spec1,Exp2,Spec2> Difference_t;
89  return Difference_t(
90  static_cast<Exp1 const&>(A),
91  static_cast<Exp2 const&>(B));
92 }
93 
94 
95 
96 
97 } // polynomial
98 } // cuda
99 } // mpblocks
100 
101 
102 
103 #endif // DIFFERENCE_H_
__host__ __device__ Difference(Exp1 const &A, Exp2 const &B)
Definition: Difference.h:47
expression template for rvalues
Definition: RValue.h:40
__host__ __device__ Difference< Scalar, Exp1, Spec1, Exp2, Spec2 > operator-(RValue< Scalar, Exp1, Spec1 > const &A, RValue< Scalar, Exp2, Spec2 > const &B)
Definition: Difference.h:84
__host__ __device__ Scalar eval(Scalar x)
Definition: Difference.h:53
expression template for sum of two matrix expressions
Definition: Difference.h:38
#define __device__
Definition: fakecuda.h:34
#define __host__
Definition: fakecuda.h:37
strip_dups< typename merge_sort< typename join< IntList1, IntList2 >::result >::result >::result result
Definition: IntList.h:392