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_POLYNOMIAL_NORMALIZED_H_
28 #define MPBLOCKS_POLYNOMIAL_NORMALIZED_H_
29 
30 namespace mpblocks {
31 namespace polynomial {
32 
34 template <typename Scalar, class Exp>
35 class Normalized :
36  public RValue< Scalar,Normalized<Scalar,Exp> >
37 {
38  Exp const& m_exp;
39 
40  public:
41  typedef std::size_t Size_t;
42 
43  Normalized( Exp const& exp ):
44  m_exp(exp)
45  {
46  }
47 
49  Size_t size() const
50  {
51  return m_exp.size();
52  }
53 
55  Scalar operator[]( Size_t i ) const
56  {
57  return m_exp[i] / m_exp[ m_exp.size()-1 ];
58  }
59 
60  Scalar eval( Scalar x )
61  {
62  return m_exp.eval(x);
63  }
64 };
65 
66 
67 
68 
69 template <typename Scalar, class Exp>
71  RValue<Scalar,Exp> const& exp )
72 {
73  typedef Normalized<Scalar,Exp> Normalized_t;
74  return Normalized_t( static_cast<Exp const&>(exp) );
75 }
76 
77 
78 
79 
80 } // polynomial
81 } // mpblocks
82 
83 
84 
85 
86 
87 #endif // NORMALIZED_H_
expression template for sum of two matrix expressions
Definition: Normalized.h:35
Size_t size() const
return the size for a vector
Definition: Normalized.h:49
expression template for rvalues
Definition: RValue.h:35
Normalized< Scalar, Exp > normalized(RValue< Scalar, Exp > const &exp)
Definition: Normalized.h:70
Scalar operator[](Size_t i) const
return the evaluated i'th element of a vector expression
Definition: Normalized.h:55