cheshirekow  v0.1.0
Negative.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_NEGATIVE_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_NEGATIVE_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace polynomial {
33 
35 template <typename Scalar,class Exp,class Spec>
36 struct Negative :
37  public RValue< Scalar,Negative<Scalar,Exp,Spec>,Spec >
38 {
39  Exp const& exp;
40 
42  Negative( Exp const& exp ):
43  exp(exp)
44  {}
45 
47  Scalar eval( Scalar x )
48  {
49  return -exp.eval(x);
50  }
51 };
52 
53 template <typename Scalar, class Exp, class Spec>
54 struct get_spec< Negative<Scalar,Exp,Spec > >
55 {
56  typedef Spec result;
57 };
58 
59 template <int idx, typename Scalar, class Exp, class Spec>
61 Scalar get( const Negative<Scalar,Exp,Spec>& exp )
62 {
63  return -get<idx>( exp.exp );
64 }
65 
66 
67 template <typename Scalar, class Exp, class Spec>
70  RValue<Scalar,Exp,Spec> const& exp )
71 {
72  return Negative<Scalar,Exp,Spec>( static_cast<Exp const&>(exp) );
73 }
74 
75 
76 
77 
78 } // polynomial
79 } // cuda
80 } // mpblocks
81 
82 
83 
84 
85 
86 #endif // NEGATIVE_H_
expression template for sum of two matrix expressions
Definition: Negative.h:36
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
#define __device__
Definition: fakecuda.h:34
#define __host__
Definition: fakecuda.h:37
__host__ __device__ Negative(Exp const &exp)
Definition: Negative.h:42
__host__ __device__ Scalar eval(Scalar x)
Definition: Negative.h:47