OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
31template <int N>
32class FMonomial {
33
34public:
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
59private:
60
61 // The monomial's exponents.
62 int array[N];
63};
64
65
66// Class FMonomial
67// ------------------------------------------------------------------------
68
69template <int N>
71 std::fill(array + 0, array + N, 0u);
72}
73
74
75template <int N>
77 std::copy(rhs.array + 0, rhs.array + N, array + 0);
78}
79
80
81template <int N>
83 std::fill(array + 0, array + N, 0u);
84 if(var < N) array[var] = 1;
85}
86
87
88template <int N>
90{}
91
92
93template <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
103template <int N>
105 return array[index];
106}
107
108
109template <int N>
110int FMonomial<N>::operator[](int index) const {
111 return array[index];
112}
113
114
115template <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
123template <int N>
125 return std::accumulate(array + 0, array + N, 0);
126}
127
128
129template <int N>
131 return N;
132}
133
134#endif // CLASSIC_FMonomial_HH
Representation of the exponents for a monomial with fixed dimension.
Definition: FMonomial.h:32
int getOrder() const
Compute the monomial's order.
Definition: FMonomial.h:124
~FMonomial()
Definition: FMonomial.h:89
int & operator[](int index)
Return reference to exponent.
Definition: FMonomial.h:104
int getVariables() const
Get the monomial's number of variables.
Definition: FMonomial.h:130
int array[N]
Definition: FMonomial.h:62
FMonomial operator*(const FMonomial &rhs) const
Get exponent set of a product.
Definition: FMonomial.h:116
FMonomial()
Definition: FMonomial.h:70
const FMonomial & operator=(const FMonomial &)
Definition: FMonomial.h:94