cheshirekow  v0.1.0
LValue.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_LVALUE_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_LVALUE_H_
29 
31 
32 namespace mpblocks {
33 namespace cuda {
34 namespace polynomial {
35 
36 
37 template< int idx, typename Scalar, class Exp1 >
39 Scalar& set( Exp1& );
40 
41 
42 
43 
44 template <typename Scalar, class Exp1, class Exp2, class Spec>
46 
47 template <typename Scalar, class Exp1, class Exp2, int Head, class Tail>
48 struct AssignmentHelper< Scalar, Exp1, Exp2, IntList<Head,Tail> >
49 {
51  static void assign( Exp1& lvalue, const Exp2& rvalue )
52  {
53  set<Head>( lvalue ) = get<Head>( rvalue );
55  }
56 };
57 
58 template <typename Scalar, class Exp1, class Exp2, int Tail>
59 struct AssignmentHelper< Scalar, Exp1, Exp2, IntList<Tail,intlist::Terminal> >
60 {
62  static void assign( Exp1& lvalue, const Exp2& rvalue )
63  {
64  set<Tail>( lvalue ) = get<Tail>( rvalue );
65  }
66 };
67 
68 
72 template <int n, typename Scalar, class Exp, class Spec>
74 {
75  Exp const& exp;
76 
78  DerivativeSurrogate( Exp const& exp ):
79  exp(exp)
80  {}
81 };
82 
83 
84 template <typename Scalar, class Exp>
85 class LValue;
86 
87 template <int n, typename Scalar, class Exp1, class InSpec, class Exp2>
90  LValue<Scalar,Exp2>& out );
91 
92 
94 template <typename Scalar, class Exp>
95 class LValue
96 {
97  public:
98 // template <class Exp2, class Spec>
99 // __host__ __device__
100 // LValue<Scalar,Exp>& operator=( RValue<Scalar,Exp2,Spec> const& rvalue )
101 // {
102 // AssignmentHelper<Scalar,Exp,Exp2,Spec>::assign(
103 // static_cast<Exp&>(*this),
104 // static_cast<const Exp2&>( rvalue ) );
105 // return *this;
106 // }
107 
108  template <int n, class Exp2, class Spec2>
112  {
113  differentiate<n>( surrogate.exp, *this );
114  return *this;
115  }
116 };
117 
118 
119 
120 
121 template <typename Scalar, class Exp>
124 {
125  return exp;
126 }
127 
128 
129 
130 
131 
132 
133 
134 
135 } // polynomial
136 } // cuda
137 } // mpblocks
138 
139 
140 
141 
142 
143 #endif // MATRIXEXPRESSION_H_
__host__ __device__ RValue< Scalar, Exp, Spec > & rvalue(RValue< Scalar, Exp, Spec > &exp)
Definition: RValue.h:46
__host__ __device__ void differentiate(const RValue< Scalar, Exp1, InSpec > &in, LValue< Scalar, Exp2 > &out)
evaluate a polynomial
__host__ __device__ Scalar & set(Exp1 &)
__host__ __device__ LValue< Scalar, Exp > & lvalue(LValue< Scalar, Exp > &exp)
Definition: LValue.h:123
expression template for rvalues
Definition: RValue.h:40
__host__ static __device__ void assign(Exp1 &lvalue, const Exp2 &rvalue)
Definition: LValue.h:62
expression template for lvalues
Definition: LValue.h:85
__host__ __device__ DerivativeSurrogate(Exp const &exp)
Definition: LValue.h:78
__host__ __device__ LValue< Scalar, Exp > & operator=(DerivativeSurrogate< n, Scalar, Exp2, Spec2 > &surrogate)
Definition: LValue.h:110
intermediate object which allows LValue assignment operator to call differntiate expression template ...
Definition: LValue.h:73
#define __device__
Definition: fakecuda.h:34
#define __host__
Definition: fakecuda.h:37
__host__ static __device__ void assign(Exp1 &lvalue, const Exp2 &rvalue)
Definition: LValue.h:51
compile time integer list (because cuda doesn't understand variadic templates )
Definition: IntList.h:50
__host__ __device__ __forceinline__ void assign(Polynomial< Scalar, Spec > &p, const Exp &exp)
Definition: assign.h:55