Peano 4
Loading...
Searching...
No Matches
VectorScalarOperations.cpph
Go to the documentation of this file.
1#include "tarch/Assertions.h"
3
4
5template <int Size, typename Scalar>
6tarch::la::Vector<Size, Scalar>& tarch::la::operator*=(Vector<Size, Scalar>& vector, const Scalar& scalar) {
7#ifdef CompilerICC
8#pragma forceinline recursive
9#endif
10 for (int i = 0; i < Size; i++) {
11 vector(i) *= scalar;
12 }
13 return vector;
14}
15
16
17template <int Size, typename Scalar>
18tarch::la::Vector<Size, Scalar> tarch::la::remainder(const Vector<Size, Scalar>& vector, double h) {
19 Vector<Size, Scalar> result = vector;
20 for (int i = 0; i < Size; i++) {
21 result(i) *= vector(i) - std::floor(vector(i) / h) * h;
22 }
23 return result;
24}
25
26
27template <int Size, typename Scalar>
28tarch::la::Vector<Size, Scalar>& tarch::la::operator/=(Vector<Size, Scalar>& vector, const Scalar& scalar) {
29#ifdef CompilerICC
30#pragma forceinline recursive
31#endif
32 for (int i = 0; i < Size; i++) {
33 vector(i) /= scalar;
34 }
35 return vector;
36}
37
38
39template <int Size, typename Scalar>
40tarch::la::Vector<Size, Scalar>& tarch::la::operator+=(Vector<Size, Scalar>& vector, const Scalar& scalar) {
41#ifdef CompilerICC
42#pragma forceinline recursive
43#endif
44 for (int i = 0; i < Size; i++) {
45 vector(i) += scalar;
46 }
47 return vector;
48}
49
50
51template <int Size, typename Scalar>
52tarch::la::Vector<Size, Scalar>& tarch::la::operator-=(Vector<Size, Scalar>& vector, const Scalar& scalar) {
53#ifdef CompilerICC
54#pragma forceinline recursive
55#endif
56 for (int i = 0; i < Size; i++) {
57 vector(i) -= scalar;
58 }
59 return vector;
60}
61
62
63template <int Size, typename Scalar>
64tarch::la::Vector<Size, Scalar> tarch::la::operator/(const Vector<Size, Scalar>& vector, const Scalar& scalar) {
65 Vector<Size, Scalar> result;
66#ifdef CompilerICC
67#pragma forceinline recursive
68#pragma ivdep
69#endif
70 for (int i = 0; i < Size; i++) {
71 result(i) = vector(i) / scalar;
72 }
73 return result;
74}
75
76
77template <int Size, typename Scalar>
78tarch::la::Vector<Size, Scalar> tarch::la::operator+(const Scalar& scalar, const Vector<Size, Scalar>& vector) {
79 return vector + scalar;
80}
81
82
83template <int Size, typename Scalar>
84tarch::la::Vector<Size, Scalar> tarch::la::operator*(const Vector<Size, Scalar>& vector, const Scalar& scalar) {
85 Vector<Size, Scalar> result;
86#ifdef CompilerICC
87#pragma forceinline recursive
88#pragma ivdep
89#endif
90 for (int i = 0; i < Size; i++) {
91 result(i) = vector(i) * scalar;
92 }
93 return result;
94}
95
96
97template <int Size, typename Scalar>
98tarch::la::Vector<Size, Scalar> tarch::la::operator*(const Scalar& scalar, const Vector<Size, Scalar>& vector) {
99 Vector<Size, Scalar> result;
100#ifdef CompilerICC
101#pragma forceinline recursive
102#endif
103 for (int i = 0; i < Size; i++) {
104 result(i) = vector(i) * scalar;
105 }
106 return result;
107}
108
109
110template <int Size, typename Scalar>
111tarch::la::Vector<Size, Scalar> tarch::la::operator+(const Vector<Size, Scalar>& vector, const Scalar& scalar) {
112 Vector<Size, Scalar> result;
113#ifdef CompilerICC
114#pragma forceinline recursive
115#endif
116 for (int i = 0; i < Size; i++) {
117 result(i) = vector(i) + scalar;
118 }
119 return result;
120}
121
122
123template <int Size, typename Scalar>
124tarch::la::Vector<Size, Scalar> tarch::la::operator-(const Vector<Size, Scalar>& vector, const Scalar& scalar) {
125 Vector<Size, Scalar> result;
126#ifdef CompilerICC
127#pragma forceinline recursive
128#endif
129 for (int i = 0; i < Size; i++) {
130 result(i) = vector(i) - scalar;
131 }
132 return result;
133}
134
135
136template <int Size, typename Scalar>
137bool tarch::la::equals(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
138#ifdef CompilerICC
139 bool result = true;
140 for (int i = 0; i < Size; i++) {
141 if (la::abs(lhs(i) - cmp) > tolerance) {
142 result = false;
143 }
144 }
145 return result;
146#else
147 for (int i = 0; i < Size; i++) {
148 if (la::abs(lhs(i) - cmp) > tolerance) {
149 return false;
150 }
151 }
152 return true;
153#endif
154}
155
156
157template <int Size, typename Scalar>
158bool tarch::la::oneEquals(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
159#ifdef CompilerICC
160 bool result = false;
161 for (int i = 0; i < Size; i++) {
162 if (la::abs(lhs(i) - cmp) <= tolerance) {
163 result = true;
164 }
165 }
166 return result;
167#else
168 for (int i = 0; i < Size; i++) {
169 if (la::abs(lhs(i) - cmp) <= tolerance) {
170 return true;
171 }
172 }
173 return false;
174#endif
175}
176
177
178template <int Size, typename Scalar>
179bool tarch::la::oneGreater(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
180#ifdef CompilerICC
181 bool result = false;
182 for (int i = 0; i < Size; i++) {
183 if (lhs(i) - cmp > tolerance) {
184 result = true;
185 }
186 }
187 return result;
188#else
189 for (int i = 0; i < Size; i++) {
190 if (lhs(i) - cmp > tolerance) {
191 return true;
192 }
193 }
194 return false;
195#endif
196}
197
198
199template <int Size, typename Scalar>
200bool tarch::la::oneGreaterEquals(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
201#ifdef CompilerICC
202 bool result = false;
203 for (int i = 0; i < Size; i++) {
204 if (lhs(i) - cmp >= -tolerance) {
205 result = true;
206 }
207 }
208 return result;
209#else
210 for (int i = 0; i < Size; i++) {
211 if (lhs(i) - cmp >= -tolerance) {
212 return true;
213 }
214 }
215 return false;
216#endif
217}
218
219
220template <int Size, typename Scalar>
221bool tarch::la::oneSmaller(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
222#ifdef CompilerICC
223 bool result = false;
224 for (int i = 0; i < Size; i++) {
225 if (lhs(i) - cmp < tolerance) {
226 result = true;
227 }
228 }
229 return result;
230#else
231 for (int i = 0; i < Size; i++) {
232 if (lhs(i) - cmp < tolerance) {
233 return true;
234 }
235 }
236 return false;
237#endif
238}
239
240
241template <int Size, typename Scalar>
242bool tarch::la::oneSmallerEquals(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
243#ifdef CompilerICC
244 bool result = false;
245 for (int i = 0; i < Size; i++) {
246 if (lhs(i) - cmp <= -tolerance) {
247 result = true;
248 }
249 }
250 return result;
251#else
252 for (int i = 0; i < Size; i++) {
253 if (lhs(i) - cmp <= -tolerance) {
254 return true;
255 }
256 }
257 return false;
258#endif
259}
260
261
262template <int Size, typename Scalar>
263bool tarch::la::allGreater(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
264 bool result = true;
265 for (int i = 0; i < Size; i++) {
266 result &= greater(lhs(i), cmp, tolerance);
267 }
268 return result;
269}
270
271
272template <int Size, typename Scalar>
273bool tarch::la::allGreaterEquals(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
274 bool result = true;
275 for (int i = 0; i < Size; i++) {
276 result &= greaterEquals(lhs(i), cmp, tolerance);
277 }
278 return result;
279}
280
281
282template <int Size, typename Scalar>
283bool tarch::la::allSmaller(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
284 bool result = true;
285 for (int i = 0; i < Size; i++) {
286 result &= smaller(lhs(i), cmp, tolerance);
287 }
288 return result;
289}
290
291
292template <int Size, typename Scalar>
293bool tarch::la::allSmallerEquals(const Vector<Size, Scalar>& lhs, const Scalar& cmp, const Scalar tolerance) {
294 bool result = true;
295 for (int i = 0; i < Size; i++) {
296 result &= smallerEquals(lhs(i), cmp, tolerance);
297 }
298 return result;
299}
300
301
302template <int Size>
303bool tarch::la::equals(const Vector<Size, int>& lhs, const int& cmp) {
304#ifdef CompilerICC
305 bool result = true;
306 for (int i = 0; i < Size; i++) {
307 if (lhs(i) != cmp) {
308 result = false;
309 }
310 }
311 return result;
312#else
313 for (int i = 0; i < Size; i++) {
314 if (lhs(i) != cmp) {
315 return false;
316 }
317 }
318 return true;
319#endif
320}
321
322
323template <int Size>
324bool tarch::la::oneEquals(const Vector<Size, int>& lhs, const int& cmp) {
325#ifdef CompilerICC
326 bool result = false;
327 for (int i = 0; i < Size; i++) {
328 if (lhs(i) == cmp) {
329 result = true;
330 }
331 }
332 return result;
333#else
334 for (int i = 0; i < Size; i++) {
335 if (lhs(i) == cmp) {
336 return true;
337 }
338 }
339 return false;
340#endif
341}
342
343
344template <int Size>
345bool tarch::la::oneGreater(const Vector<Size, int>& lhs, const int& cmp) {
346#ifdef CompilerICC
347 bool result = false;
348 for (int i = 0; i < Size; i++) {
349 if (lhs(i) > cmp) {
350 result = true;
351 }
352 }
353 return result;
354#else
355 for (int i = 0; i < Size; i++) {
356 if (lhs(i) > cmp) {
357 return true;
358 }
359 }
360 return false;
361#endif
362}
363
364
365template <int Size>
366bool tarch::la::oneGreaterEquals(const Vector<Size, int>& lhs, const int& cmp) {
367#ifdef CompilerICC
368 bool result = false;
369 for (int i = 0; i < Size; i++) {
370 if (lhs(i) >= cmp) {
371 result = true;
372 }
373 }
374 return result;
375#else
376 for (int i = 0; i < Size; i++) {
377 if (lhs(i) >= cmp) {
378 return true;
379 }
380 }
381 return false;
382#endif
383}
384
385
386template <int Size>
387bool tarch::la::oneSmaller(const Vector<Size, int>& lhs, const int& cmp) {
388#ifdef CompilerICC
389 bool result = false;
390 for (int i = 0; i < Size; i++) {
391 if (lhs(i) < cmp) {
392 result = true;
393 }
394 }
395 return result;
396#else
397 for (int i = 0; i < Size; i++) {
398 if (lhs(i) < cmp) {
399 return true;
400 }
401 }
402 return false;
403#endif
404}
405
406
407template <int Size>
408bool tarch::la::oneSmallerEquals(const Vector<Size, int>& lhs, const int& cmp) {
409#ifdef CompilerICC
410 bool result = false;
411 for (int i = 0; i < Size; i++) {
412 if (lhs(i) <= cmp) {
413 result = true;
414 }
415 }
416 return result;
417#else
418 for (int i = 0; i < Size; i++) {
419 if (lhs(i) <= cmp) {
420 return true;
421 }
422 }
423 return false;
424#endif
425}
426
427
428template <int Size>
429bool tarch::la::allGreater(const Vector<Size, int>& lhs, const int& cmp) {
430#ifdef CompilerICC
431 bool result = true;
432 for (int i = 0; i < Size; i++) {
433 if (lhs(i) <= cmp) {
434 result = false;
435 }
436 }
437 return result;
438#else
439 for (int i = 0; i < Size; i++) {
440 if (lhs(i) <= cmp) {
441 return false;
442 }
443 }
444 return true;
445#endif
446}
447
448
449template <int Size>
450bool tarch::la::allGreaterEquals(const Vector<Size, int>& lhs, const int& cmp) {
451#ifdef CompilerICC
452 bool result = true;
453 for (int i = 0; i < Size; i++) {
454 if (lhs(i) < cmp) {
455 result = false;
456 }
457 }
458 return result;
459#else
460 for (int i = 0; i < Size; i++) {
461 if (lhs(i) < cmp) {
462 return false;
463 }
464 }
465 return true;
466#endif
467}
468
469
470template <int Size>
471bool tarch::la::allSmaller(const Vector<Size, int>& lhs, const int& cmp) {
472#ifdef CompilerICC
473 bool result = true;
474 for (int i = 0; i < Size; i++) {
475 if (lhs(i) >= cmp) {
476 result = false;
477 }
478 }
479 return result;
480#else
481 for (int i = 0; i < Size; i++) {
482 if (lhs(i) >= cmp) {
483 return false;
484 }
485 }
486 return true;
487#endif
488}
489
490
491template <int Size>
492bool tarch::la::allSmallerEquals(const Vector<Size, int>& lhs, const int& cmp) {
493#ifdef CompilerICC
494 bool result = true;
495 for (int i = 0; i < Size; i++) {
496 if (lhs(i) > cmp) {
497 result = false;
498 }
499 }
500 return result;
501#else
502 for (int i = 0; i < Size; i++) {
503 if (lhs(i) > cmp) {
504 return false;
505 }
506 }
507 return true;
508#endif
509}
int i
Definition makeIC.py:51
bool allGreaterEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool allGreater(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Vector< Size, Scalar > remainder(const Vector< Size, Scalar > &vector, double h)
Return the remainder of a division.
bool oneSmaller(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Matrix< Rows, Cols, Scalar > & operator*=(Matrix< Rows, Cols, Scalar > &matrix, const Scalar &scalar)
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Matrix< Rows, Cols, Scalar > operator-(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
Vector< Size, Scalar > & operator+=(Vector< Size, Scalar > &vector, const Scalar &scalar)
Adds every component of the vector to the scalar and assigns the result to the vector.
Matrix< Rows, Cols, Scalar > operator+(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
bool oneSmallerEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Vector< Size, Scalar > operator/(const Vector< Size, Scalar > &vector, const Scalar &scalar)
Divides every component of the vector by the scalar and returns the result.
bool allSmallerEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool allSmaller(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool oneEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Matrix< Rows, Cols, Scalar > operator*(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
bool oneGreaterEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Vector< Size, Scalar > & operator-=(Vector< Size, Scalar > &vector, const Scalar &scalar)
Subtracts the scalar from every component of the vector and assigns the result to the vector.
bool oneGreater(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Vector< Size, Scalar > & operator/=(Vector< Size, Scalar > &vector, const Scalar &scalar)
Divides every component of the vector by the scalar and assigns the result to the vector.
Simple vector class.
Definition Vector.h:134