OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FMonomial.h
Go to the documentation of this file.
1 #ifndef CLASSIC_FMonomial_HH
2 #define CLASSIC_FMonomial_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: FMonomial.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.3.2.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: FMonomial<N>
13 //
14 // ------------------------------------------------------------------------
15 // Class category: FixedAlgebra
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2004/11/18 22:18:06 $
19 // $Author: jsberg $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include <algorithm>
24 #include <numeric>
25 
26 
27 // Class FMonomial
28 // ------------------------------------------------------------------------
30 
31 template <int N>
32 class FMonomial {
33 
34 public:
35 
37  explicit FMonomial(int var);
38 
39  FMonomial();
40  FMonomial(const FMonomial &);
41  ~FMonomial();
42  const FMonomial &operator=(const FMonomial &);
43 
45  int &operator[](int index);
46 
48  int operator[](int index) const;
49 
51  FMonomial operator*(const FMonomial &rhs) const;
52 
54  int getOrder() const;
55 
57  int getVariables() const;
58 
59 private:
60 
61  // The monomial's exponents.
62  int array[N];
63 };
64 
65 
66 // Class FMonomial
67 // ------------------------------------------------------------------------
68 
69 template <int N>
71  std::fill(array + 0, array + N, 0u);
72 }
73 
74 
75 template <int N>
77  std::copy(rhs.array + 0, rhs.array + N, array + 0);
78 }
79 
80 
81 template <int N>
83  std::fill(array + 0, array + N, 0u);
84  if(var < N) array[var] = 1;
85 }
86 
87 
88 template <int N>
90 {}
91 
92 
93 template <int N>
95  if(&rhs != this) {
96  std::copy(rhs.array + 0, rhs.array + N, array + 0);
97  }
98 
99  return *this;
100 }
101 
102 
103 template <int N>
104 int &FMonomial<N>::operator[](int index) {
105  return array[index];
106 }
107 
108 
109 template <int N>
110 int FMonomial<N>::operator[](int index) const {
111  return array[index];
112 }
113 
114 
115 template <int N>
117  FMonomial result;
118  for(int i = 0; i < N; ++i) result.array[i] = array[i] + rhs.array[i];
119  return result;
120 }
121 
122 
123 template <int N>
125  return std::accumulate(array + 0, array + N, 0);
126 }
127 
128 
129 template <int N>
131  return N;
132 }
133 
134 #endif // CLASSIC_FMonomial_HH
int getVariables() const
Get the monomial&#39;s number of variables.
Definition: FMonomial.h:130
Representation of the exponents for a monomial with fixed dimension.
Definition: FMonomial.h:32
int & operator[](int index)
Return reference to exponent.
Definition: FMonomial.h:104
FMonomial()
Definition: FMonomial.h:70
~FMonomial()
Definition: FMonomial.h:89
int getOrder() const
Compute the monomial&#39;s order.
Definition: FMonomial.h:124
int array[N]
Definition: FMonomial.h:62
const FMonomial & operator=(const FMonomial &)
Definition: FMonomial.h:94
FMonomial operator*(const FMonomial &rhs) const
Get exponent set of a product.
Definition: FMonomial.h:116