cheshirekow  v0.1.0
polyval.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_POLYVAL_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_POLYVAL_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace polynomial {
33 
34 
35 namespace polyval_detail
36 {
37  template <class Scalar, class Exp, int idx, int max>
38  struct Helper
39  {
41  static Scalar eval( const Exp& exp, const Scalar& s, Scalar sn )
42  {
43  return get<idx>(exp)*sn
45  }
46  };
47 
48  template <class Scalar, class Exp, int max>
49  struct Helper< Scalar, Exp, max, max>
50  {
52  static Scalar eval( const Exp& exp, const Scalar& s, Scalar sn )
53  {
54  return get<max>(exp)*sn;
55  }
56  };
57 }
58 
60 template <typename Scalar, class Exp, class Spec, typename Scalar2>
62 Scalar polyval( const RValue<Scalar,Exp,Spec>& exp, Scalar2 x )
63 {
64  enum{ max_idx = intlist::max<Spec>::value };
66  static_cast<const Exp&>(exp),Scalar(x),1);
67 }
68 
69 } // namespace polynomial
70 } // namespace cuda
71 } // namespace mpblocks
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 #endif // POLYVAL_H_
expression template for rvalues
Definition: RValue.h:40
#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__ static __device__ Scalar eval(const Exp &exp, const Scalar &s, Scalar sn)
Definition: polyval.h:52
#define __host__
Definition: fakecuda.h:37
__host__ __device__ Scalar polyval(const RValue< Scalar, Exp, Spec > &exp, Scalar2 x)
evaluate a polynomial
Definition: polyval.h:62
__host__ static __device__ Scalar eval(const Exp &exp, const Scalar &s, Scalar sn)
Definition: polyval.h:41