OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Vps.hpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: Vps.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.1.1.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class: Vps
10// Vector truncated power series in n variables.
11//
12// ------------------------------------------------------------------------
13// Class category: Algebra
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:32:32 $
17// $Author: fci $
18//
19// ------------------------------------------------------------------------
20
21#include "Algebra/Vps.h"
22#include "Algebra/Matrix.h"
23#include "Algebra/LUMatrix.h"
24#include "Algebra/Vector.h"
25#include "Algebra/Tps.h"
26#include "Algebra/TpsMonomial.h"
29#include "Utilities/SizeError.h"
30#include <algorithm>
31#include <iostream>
32
33#include <cstring>
34
35
36// Template class Vps<T>
37// ------------------------------------------------------------------------
38
39template <class T>
41 data(), variables(0)
42{}
43
44
45template <class T>
46Vps<T>::Vps(int nDim, int nVar):
47 data(nDim, Tps<T>(0, nVar)), variables(nVar)
48{}
49
50
51template <class T>
52Vps<T>::Vps(const Vps<T> &rhs):
53 data(rhs.data), variables(rhs.variables) {
54 // No call to check, assume rhs is correct.
55}
56
57
58template <class T>
60 data(x.nrows()), variables(x.ncols()) {
61 for(int i = 0; i < x.nrows(); i++) {
62 data[i] = Tps<T>(1, x.ncols());
63
64 for(int j = 0; j < x.ncols(); j++) {
65 data[i][j+1] = x(i, j);
66 }
67 }
68}
69
70
71template <class T>
73 data(x.size()), variables(0) {
74 for(int i = 0; i < getDimension(); i++) data[i] = Tps<T>(x[i]);
75}
76
77
78template <class T>
80{}
81
82
83template <class T>
85 data = y.data;
86 variables = y.variables;
87 return *this;
88}
89
90
91template <class T>
92const Tps<T> &Vps<T>::getComponent(int index) const {
93 return data(index);
94}
95
96
97template <class T>
98void Vps<T>::setComponent(int index, const Tps<T> &value) {
99 check();
100 if(value.getVariables() != variables) {
101 throw SizeError("Vps::setComponent()", "Index out of range.");
102 }
103 data(index) = value;
104}
105
106
107template <class T>
108void Vps<T>::check() const {
109 variables = 0;
110
111 for(const Tps<T> *p = data.begin(); p != data.end(); ++p) {
112 if(int var = p->getVariables()) {
113 if(variables != 0 && var != variables) {
114 throw SizeError("Vps::check()",
115 "Vps has inconsistent number of variables.");
116 }
117 variables = var;
118 }
119 }
120}
121
122
123template <class T>
125 return *this;
126}
127
128
129template <class T>
131 Vps<T> z(getDimension(), variables);
132 for(int i = 0; i < getDimension(); i++) z[i] = - data[i];
133 return z;
134}
135
136
137template <class T>
139 for(int i = 0; i < getDimension(); i++) data[i] *= y;
140 return *this;
141}
142
143
144template <class T>
147 for(int i = 0; i < getDimension(); i++) data[i] *= t;
148 return *this;
149}
150
151
152template <class T>
154 for(int i = 0; i < getDimension(); i++) data[i] *= y;
155 return *this;
156}
157
158
159template <class T>
161 if(y == T(0)) throw DivideError("Vps::operator/()");
162 T t = T(1) / y;
163 for(int i = 0; i < getDimension(); i++) data[i] *= t;
164 return *this;
165}
166
167
168template <class T>
170 if(getDimension() != y.getDimension()) {
171 throw SizeError("Vps::operator+=()", "Inconsistent dimensions.");
172 }
173
174 for(int i = 0; i < getDimension(); i++) data[i] += y.data[i];
175 return *this;
176}
177
178
179template <class T>
181 if(getDimension() != y.getDimension()) {
182 throw SizeError("Vps::operator-=()", "Inconsistent dimensions.");
183 }
184
185 for(int i = 0; i < getDimension(); i++) data[i] -= y.data[i];
186 return *this;
187}
188
189
190template <class T>
192 if(getDimension() != y.size()) {
193 throw SizeError("Vps::operator+=()", "Inconsistent dimensions.");
194 }
195
196 for(int i = 0; i < getDimension(); i++) data[i] += y[i];
197 return *this;
198}
199
200
201template <class T>
203 if(getDimension() != y.size()) {
204 throw SizeError("Vps::operator-=()", "Inconsistent dimensions.");
205 }
206
207 for(int i = 0; i < getDimension(); i++) data[i] -= y[i];
208 return *this;
209}
210
211
212template <class T>
213std::istream &Vps<T>::get(std::istream &is) {
214 char head[4];
215 is.flags(std::ios::skipws);
216 is.get(head, 4);
217
218 if(std::strcmp(head, "Vps") != 0) {
219 throw FormatError("Vps::get()", "Flag word \"Vps\" missing.");
220 }
221
222 int nDim;
223 is >> nDim;
224
225 if(nDim == 0) {
226 throw FormatError("Vps::get()", "Zero Vps dimension");
227 }
228
229 Vps<T> temp(nDim);
230 for(int i = 0; i < nDim; i++) is >> data[i];
231 temp.check();
232 *this = temp;
233 return is;
234}
235
236
237template <class T>
238std::ostream &Vps<T>::put(std::ostream &os) const {
239 int nDim = getDimension();
240 os << "Vps " << nDim << std::endl;
241 for(int i = 0; i < nDim; i++) os << data[i];
242 return os;
243}
244
245
246template <class T>
248 return data.size();
249}
250
251
252template <class T>
254 const Tps<T> *p = data.begin();
255 int topOrder = p->getMaxOrder();
256
257 while(++p < data.end()) {
258 topOrder = std::max(topOrder, p->getMaxOrder());
259 }
260
261 return topOrder;
262}
263
264
265template <class T>
267 const Tps<T> *p = data.begin();
268 int truncOrder = p->getTruncOrder();
269
270 while(++p < data.end()) {
271 truncOrder = std::min(truncOrder, p->getTruncOrder());
272 }
273
274 return truncOrder;
275}
276
277
278template <class T>
280 check();
281 return variables;
282}
283
284
285template <class T>
286Vps<T> Vps<T>::filter(int lowOrder, int highOrder) const {
287 check();
288 Vps<T> z(getDimension(), variables);
289
290 for(int i = 0; i < getDimension(); i++) {
291 z.data[i] = data[i].filter(lowOrder, highOrder);
292 }
293
294 return z;
295}
296
297
298template <class T>
300 check();
301 Vps<T> z(getDimension(), variables);
302
303 for(int i = 0; i < getDimension(); i++) {
304 z.data[i] = data[i].truncate(trunc);
305 }
306
307 return *this;
308}
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
int size() const
Get array size.
Definition: Array1D.h:228
int nrows() const
Get number of rows.
Definition: Array2D.h:301
int ncols() const
Get number of columns.
Definition: Array2D.h:307
Matrix.
Definition: Matrix.h:39
Truncated power series.
Definition: Tps.h:46
int getVariables() const
Get number of variables.
Definition: Tps.hpp:1043
Tps< T > inverse(int order=truncOrder) const
Reciprocal value.
Definition: Tps.hpp:897
int getTruncOrder() const
Get truncation order.
Definition: Tps.hpp:1037
int getMaxOrder() const
Get maximal order.
Definition: Tps.hpp:1031
Vector.
Definition: Vector.h:37
Vector truncated power series.
Definition: Vps.h:38
void setComponent(int index, const Tps< T > &value)
Set component.
Definition: Vps.hpp:98
int getTopOrder() const
Get highest order contained in any component.
Definition: Vps.hpp:253
Vps< T > & operator-=(const Vps< T > &y)
Subtraction.
Definition: Vps.hpp:180
std::ostream & put(std::ostream &os) const
Put a Vps<T> to stream os.
Definition: Vps.hpp:238
int variables
Definition: Vps.h:146
std::istream & get(std::istream &is)
Get a Vps<T> from stream is.
Definition: Vps.hpp:213
Array1D< Tps< T > > data
Definition: Vps.h:143
int getVariables() const
Get number of variables (the same in all components).
Definition: Vps.hpp:279
int getTruncOrder() const
Get lowest truncation order in any component.
Definition: Vps.hpp:266
~Vps()
Definition: Vps.hpp:79
Vps< T > operator+() const
Unary plus.
Definition: Vps.hpp:124
Vps< T > operator-() const
Unary minus.
Definition: Vps.hpp:130
Vps< T > truncate(int trunc)
Truncate, may also increase truncation order.
Definition: Vps.hpp:299
const Tps< T > & getComponent(int index) const
Get component.
Definition: Vps.hpp:92
int getDimension() const
Get dimension (number of Tps<T> components).
Definition: Vps.hpp:247
Vps< T > filter(int lowOrder, int highOrder) const
Extract range of orders, set others to zero.
Definition: Vps.hpp:286
Vps< T > & operator=(const Vps< T > &)
Definition: Vps.hpp:84
void check() const
Check consistency.
Definition: Vps.hpp:108
Vps< T > & operator*=(const Tps< T > &y)
Multiply by Tps<T> and assign.
Definition: Vps.hpp:138
Vps< T > & operator+=(const Vps< T > &y)
Addition.
Definition: Vps.hpp:169
Vps< T > & operator/=(const Tps< T > &y)
Divide by Tps<T> and assign.
Definition: Vps.hpp:145
Vps()
Definition: Vps.hpp:40
Zero divide error.
Definition: DivideError.h:32
Format error exception.
Definition: FormatError.h:32
Size error exception.
Definition: SizeError.h:33