cheshirekow  v0.1.0
Normalized.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_NORMALIZED_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_NORMALIZED_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace polynomial {
33 
35 template <typename Scalar, class Exp, class Spec>
36 struct Normalized :
37  public RValue< Scalar, Normalized<Scalar,Exp,Spec>, Spec >
38 {
39  Exp const& exp;
40 
42  Normalized( Exp const& exp ):
43  exp(exp)
44  {
45  }
46 
48  Scalar eval( Scalar x )
49  {
50  return exp.eval(x);
51  }
52 };
53 
54 
55 template <typename Scalar, class Exp, class Spec>
56 struct get_spec< Normalized<Scalar,Exp,Spec > >
57 {
58  typedef Spec result;
59 };
60 
61 template <int idx, typename Scalar, class Exp, class Spec>
63 Scalar get( const Normalized<Scalar,Exp,Spec>& exp )
64 {
65  enum{ max_idx = intlist::max<Spec>::value };
66  return get<idx>( exp.exp ) / get<max_idx>( exp.exp );
67 }
68 
69 
70 template <typename Scalar, class Exp, class Spec>
73 {
74  return Normalized<Scalar,Exp,Spec>( static_cast<Exp const&>(exp) );
75 }
76 
77 
78 
79 
80 } // polynomial
81 } // cuda
82 } // mpblocks
83 
84 
85 
86 
87 
88 #endif // NORMALIZED_H_
__host__ __device__ Normalized(Exp const &exp)
Definition: Normalized.h:42
expression template for sum of two matrix expressions
Definition: Normalized.h:36
expression template for rvalues
Definition: RValue.h:40
__host__ __device__ Scalar eval(Scalar x)
Definition: Normalized.h:48
#define __device__
Definition: fakecuda.h:34
retrieve the max element of the list (linear without short circut so it works with non-sorted arrays ...
Definition: IntList.h:415
__host__ __device__ Normalized< Scalar, Exp, Spec > normalized(const RValue< Scalar, Exp, Spec > &exp)
Definition: Normalized.h:72
#define __host__
Definition: fakecuda.h:37