Peano 4
Loading...
Searching...
No Matches
VectorVectorOperations.cpph
Go to the documentation of this file.
2#include "tarch/Assertions.h"
3
4
5template<int Size, typename Scalar>
7 Vector<Size,Scalar>& lhs,
8 const Vector<Size,Scalar>& rhs
9) {
10 #ifdef CompilerICC
11 #pragma forceinline recursive
12 #pragma ivdep
13 #endif
14 for ( int i=0; i < Size; i++ ) {
15 lhs(i) += rhs(i);
16 }
17 return lhs;
18}
19
20
21template<int Size, typename Scalar>
23 Vector<Size,Scalar>& lhs,
24 const Vector<Size,Scalar>& rhs
25) {
26 #ifdef CompilerICC
27 #pragma forceinline recursive
28 #pragma ivdep
29 #endif
30 for ( int i=0; i < Size; i++ ) {
31 lhs(i) -= rhs(i);
32 }
33 return lhs;
34}
35
36
37template<int Size, typename Scalar>
39 const Vector<Size,Scalar>& lhs,
40 const Vector<Size,Scalar>& rhs
41) {
43 #ifdef CompilerICC
44 #pragma forceinline recursive
45 #pragma ivdep
46 #endif
47 for ( int i=0; i < Size; i++ ) {
48 result(i) = rhs(i) + lhs(i);
49 }
50 return result;
51}
52
53
54template<int Size, typename Scalar>
56 const Vector<Size,Scalar>& lhs,
57 const Vector<Size,Scalar>& rhs
58) {
60 #ifdef CompilerICC
61 #pragma forceinline recursive
62 #pragma ivdep
63 #endif
64 for ( int i=0; i < Size; i++ ) {
65 result(i) = lhs(i) - rhs(i);
66 }
67 return result;
68}
69
70
71template<int Size, typename Scalar>
73 const Vector<Size,Scalar>& lhs,
74 const Vector<Size,Scalar>& rhs
75) {
77 #ifdef CompilerICC
78 #pragma forceinline recursive
79 #pragma ivdep
80 #endif
81 for ( int i=0; i < Size; i++ ) {
82 result(i) = lhs(i) * rhs(i);
83 }
84 return result;
85}
86
87
88template<int Size, typename Scalar>
90 const Vector<Size,Scalar>& lhs,
91 const Vector<Size,Scalar>& rhs
92) {
94 #ifdef CompilerICC
95 #pragma forceinline recursive
96 #pragma ivdep
97 #endif
98 for ( int i=0; i < Size; i++ ) {
99 result(i) = std::max( lhs(i), rhs(i) );
100 }
101 return result;
102}
103
104
105template<int Size, typename Scalar>
107 const Vector<Size,Scalar>& lhs,
108 const Vector<Size,Scalar>& rhs
109) {
111 #ifdef CompilerICC
112 #pragma forceinline recursive
113 #pragma ivdep
114 #endif
115 for ( int i=0; i < Size; i++ ) {
116 result(i) = std::min( lhs(i), rhs(i) );
117 }
118 return result;
119}
120
121
122template<int Size, typename Scalar>
124 const Vector<Size,Scalar>& lhs,
125 const Vector<Size,Scalar>& rhs
126) {
127 return innerDot(lhs, rhs);
128}
129
130
131template<int Size, typename Scalar>
133 const Vector<Size,Scalar>& lhs,
134 const Vector<Size,Scalar>& rhs
135) {
136 Scalar result = lhs(0) * rhs(0);
137 for ( int i=1; i < Size; i++ ) {
138 result += lhs(i) * rhs(i);
139 }
140 return result;
141}
142
143
144template<int Size, typename Scalar>
146 const Vector<Size,Scalar>& lhs,
147 const Vector<Size,Scalar>& rhs
148) {
149 return innerDot(lhs,rhs);
150}
151
152
153template<typename Scalar>
155 const Vector<3,Scalar>& lhs,
156 const Vector<3,Scalar>& rhs
157) {
158 Vector<3,Scalar> result;
159
160 result(0) = lhs(1) * rhs(2) - lhs(2) * rhs(1);
161 result(1) = lhs(2) * rhs(0) - lhs(0) * rhs(2);
162 result(2) = lhs(0) * rhs(1) - lhs(1) * rhs(0);
163
164 return result;
165}
166
167
168template<int Size, typename Scalar>
170 const Vector<Size,Scalar>& lhs,
171 const Vector<Size,Scalar>& rhs,
172 const Scalar tolerance
173) {
174 for ( int i=0; i < Size; i++ ) {
175 if ( la::abs(lhs(i) - rhs(i)) > tolerance ) {
176 return false;
177 }
178 }
179 return true;
180}
181
182
183template<int Size, typename Scalar>
185 const Vector<Size,Scalar>& lhs,
186 const Vector<Size,Scalar>& rhs,
187 const Scalar tolerance
188) {
189 for ( int i=0; i < Size; i++ ) {
190 if ( lhs(i) - rhs(i) > tolerance ) {
191 return true;
192 }
193 else if ( rhs(i) - lhs(i) > tolerance ) {
194 return false;
195 }
196 }
197 return false;
198}
199
200
201template<int Size, typename Scalar>
203 const Vector<Size,Scalar>& lhs,
204 const Vector<Size,Scalar>& rhs,
205 const Scalar tolerance
206) {
207 for ( int i=0; i < Size; i++ ) {
208 if ( lhs(i) - rhs(i) > tolerance ) {
209 return true;
210 }
211 }
212 return false;
213}
214
215
216template<int Size, typename Scalar>
218 const Vector<Size,Scalar>& lhs,
219 const Vector<Size,Scalar>& rhs,
220 const Scalar tolerance
221) {
222 for ( int i=0; i < Size; i++ ) {
223 if ( lhs(i) - rhs(i) >= - tolerance ) {
224 return true;
225 }
226 }
227 return false;
228}
229
230
231template<int Size, typename Scalar>
233 const Vector<Size,Scalar>& lhs,
234 const Vector<Size,Scalar>& rhs,
235 const Scalar tolerance
236) {
237 bool result = true;
238 for ( int i=0; i < Size; i++ ) {
239 result &= greater(lhs(i),rhs(i),tolerance);
240 }
241 return result;
242}
243
244
245template<int Size, typename Scalar>
247 const Vector<Size,Scalar>& lhs,
248 const Vector<Size,Scalar>& rhs,
249 const Scalar tolerance
250) {
251 bool result = true;
252 for ( int i=0; i < Size; i++ ) {
253 result &= greaterEquals(lhs(i),rhs(i),tolerance);
254 }
255 return result;
256}
257
258
259template<int Size, typename Scalar>
261 const Vector<Size,Scalar>& lhs,
262 const Vector<Size,Scalar>& rhs,
263 const Scalar tolerance
264) {
265 bool result = true;
266 for ( int i=0; i < Size; i++ ) {
267 result &= smaller(lhs(i),rhs(i),tolerance);
268 }
269 return result;
270}
271
272
273template<int Size, typename Scalar>
275 const Vector<Size,Scalar>& lhs,
276 const Vector<Size,Scalar>& rhs,
277 const Scalar tolerance
278) {
279 bool result = true;
280 for ( int i=0; i < Size; i++ ) {
281 result &= smallerEquals(lhs(i),rhs(i),tolerance);
282 }
283 return result;
284}
285
286
287template<int Size, typename Scalar>
289 const Vector<Size,Scalar>& lhs,
290 const Vector<Size,Scalar>& rhs,
291 const Scalar tolerance
292) {
293 for ( int i=0; i < Size; i++ ) {
294 if (smaller(lhs(i),rhs(i),tolerance)) {
295 return true;
296 }
297 }
298 return false;
299}
300
301
302template<int Size, typename Scalar>
304 const Vector<Size,Scalar>& lhs,
305 const Vector<Size,Scalar>& rhs,
306 const Scalar tolerance
307) {
308 for ( int i=0; i < Size; i++ ) {
309 if (smallerEquals(lhs(i),rhs(i),tolerance)) {
310 return true;
311 }
312 }
313 return false;
314}
315
316
317template<int Size, typename Scalar>
319 const Vector<Size,Scalar>& lhs,
320 const Vector<Size,Scalar>& rhs
321) {
322 for (int i=0; i < Size; i++) {
323 if (lhs(i) != rhs(i)) {
324 return false;
325 }
326 }
327 return true;
328}
329
330
331template<int Size, typename Scalar>
333 const Vector<Size,Scalar>& lhs,
334 const Vector<Size,Scalar>& rhs
335) {
336 return !(lhs==rhs);
337}
338
339
340template<int Size, typename Scalar>
342 const Vector<Size,Scalar>& lhs,
343 const Vector<Size,Scalar>& rhs,
344 const Scalar tolerance
345){
346 for (int i=0; i < Size; i++) {
347 if(std::abs(lhs(i) - rhs(i)) > tolerance) return i;
348 }
349 return -1;
350}
351
352
353template<int Size>
355 const Vector<Size,int>& lhs,
356 const Vector<Size,int>& rhs
357){
358 for (int i=0; i < Size; i++) {
359 if (lhs(i)!=rhs(i)) return i;
360 }
361 return -1;
362}
363
364
365template<int Size>
367 const Vector<Size,int>& lhs,
368 const Vector<Size,int>& rhs
369) {
370 int result = 0;
371
372 for (int i=0; i<Size; i++) {
373 result += (lhs(i)==rhs(i)) ? 1 : 0;
374 }
375
376 return result;
377}
378
379
380template<int Size, typename Scalar>
382 const Vector<Size,Scalar>& lhs,
383 const Vector<Size,Scalar>& rhs,
384 const Scalar tolerance
385) {
386 int result = 0;
387
388 for (int i=0; i<Size; i++) {
389 result += ( equals( lhs(i),rhs(i),tolerance) ) ? 1 : 0;
390 }
391
392 return result;
393}
int i
Definition makeIC.py:51
Scalar dot(const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
Performs the dot (=inner) product of two vectors.
bool allGreaterEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool operator!=(const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
Bit-wise comparison of the components of two vectors for inequality.
bool allGreater(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Vector< 3, Scalar > cross(const Vector< 3, Scalar > &lhs, const Vector< 3, Scalar > &rhs)
Performs the cross product of two 3D vectors into result.
bool oneSmaller(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
int countEqualEntries(const Vector< Size, int > &lhs, const Vector< Size, int > &rhs)
Run through both vectors and count how many entries are the same.
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool operator==(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
Bitwise comparison of the components of two matrices on equality.
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)
double max(double a, double b, double c)
I need the maximum of three values all the time, to I decided to write a function for this.
Definition Scalar.cpp:8
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool firstGreater(const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares sequentially every component pair of lVector and rVector, and stops as soon as one is greate...
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)
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.
std::pair< int, int > equalsReturnIndex(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Return Index of element which is not equals.
bool oneGreaterEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Matrix< Rows, Cols, Scalar > multiplyComponents(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
Scalar innerDot(const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
Performs the dot (=inner) product of two vectors.
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)
Scalar min(const Vector< Size, Scalar > &vector)
Returns the element with minimal value (NOT absolute value).
Simple vector class.
Definition Vector.h:134