Theoretica
Mathematical Library
Loading...
Searching...
No Matches
parallel.h
Go to the documentation of this file.
1
5
6#ifndef THEORETICA_PARALLEL_H
7#define THEORETICA_PARALLEL_H
8
9#include "./vec.h"
10#include "../core/dataset.h"
11#include "../core/real_analysis.h"
12#include "../complex/complex_analysis.h"
13#include "../autodiff/dual_functions.h"
14#include "../autodiff/dual2_functions.h"
15#include "../autodiff/multidual_functions.h"
16
17
18namespace theoretica {
19
20
22 namespace parallel {
23
24
25 // Unary operations
26
27
34 template<typename Function, typename Vector>
35 inline Vector apply_function(Function f, const Vector& v) {
36
37 Vector res;
38 res.resize(v.size());
39
40 #pragma omp parallel for
41 for (unsigned int i = 0; i < v.size(); i++)
42 res[i] = f(v[i]);
43
44 return res;
45 }
46
47
52 template<typename Vector>
53 inline Vector square(const Vector& v) {
54
55 Vector res;
56 res.resize(v.size());
57
58 #pragma omp parallel for
59 for (unsigned int i = 0; i < v.size(); i++)
60 res[i] = theoretica::square(v[i]);
61
62 return res;
63 }
64
65
70 template<typename Vector>
71 inline Vector cube(const Vector& v) {
72
73 Vector res;
74 res.resize(v.size());
75
76 #pragma omp parallel for
77 for (unsigned int i = 0; i < v.size(); i++)
78 res[i] = theoretica::cube(v[i]);
79
80 return res;
81 }
82
83
88 template<typename Vector>
89 inline Vector abs(const Vector& v) {
90
91 Vector res;
92 res.resize(v.size());
93
94 #pragma omp parallel for
95 for (unsigned int i = 0; i < v.size(); i++)
96 res[i] = theoretica::abs(v[i]);
97
98 return res;
99 }
100
101
107 template<typename Vector>
108 inline Vector pow(const Vector& v, int n) {
109
110 Vector res;
111 res.resize(v.size());
112
113 #pragma omp parallel for
114 for (unsigned int i = 0; i < v.size(); i++)
115 res[i] = theoretica::pow(v[i], n);
116
117 return res;
118 }
119
120
126 template<typename Vector>
127 inline Vector powf(const Vector& v, real x) {
128
129 Vector res;
130 res.resize(v.size());
131
132 #pragma omp parallel for
133 for (unsigned int i = 0; i < v.size(); i++)
134 res[i] = theoretica::powf(v[i], x);
135
136 return res;
137 }
138
139
144 template<typename Vector>
145 inline Vector sqrt(const Vector& v) {
146
147 Vector res;
148 res.resize(v.size());
149
150 #pragma omp parallel for
151 for (unsigned int i = 0; i < v.size(); i++)
152 res[i] = theoretica::sqrt(v[i]);
153
154 return res;
155 }
156
157
162 template<typename Vector>
163 inline Vector cbrt(const Vector& v) {
164
165 Vector res;
166 res.resize(v.size());
167
168 #pragma omp parallel for
169 for (unsigned int i = 0; i < v.size(); i++)
170 res[i] = theoretica::cbrt(v[i]);
171
172 return res;
173 }
174
175
180 template<typename Vector>
181 inline Vector exp(const Vector& v) {
182
183 Vector res;
184 res.resize(v.size());
185
186 #pragma omp parallel for
187 for (unsigned int i = 0; i < v.size(); i++)
188 res[i] = theoretica::exp(v[i]);
189
190 return res;
191 }
192
193
198 template<typename Vector>
199 inline Vector ln(const Vector& v) {
200
201 Vector res;
202 res.resize(v.size());
203
204 #pragma omp parallel for
205 for (unsigned int i = 0; i < v.size(); i++)
206 res[i] = theoretica::ln(v[i]);
207
208 return res;
209 }
210
211
216 template<typename Vector>
217 inline Vector log2(const Vector& v) {
218
219 Vector res;
220 res.resize(v.size());
221
222 #pragma omp parallel for
223 for (unsigned int i = 0; i < v.size(); i++)
224 res[i] = theoretica::log2(v[i]);
225
226 return res;
227 }
228
229
234 template<typename Vector>
235 inline Vector log10(const Vector& v) {
236
237 Vector res;
238 res.resize(v.size());
239
240 #pragma omp parallel for
241 for (unsigned int i = 0; i < v.size(); i++)
242 res[i] = theoretica::log10(v[i]);
243
244 return res;
245 }
246
247
252 template<typename Vector>
253 inline Vector sin(const Vector& v) {
254
255 Vector res;
256 res.resize(v.size());
257
258 #pragma omp parallel for
259 for (unsigned int i = 0; i < v.size(); i++)
260 res[i] = theoretica::sin(v[i]);
261
262 return res;
263 }
264
265
270 template<typename Vector>
271 inline Vector cos(const Vector& v) {
272
273 Vector res;
274 res.resize(v.size());
275
276 #pragma omp parallel for
277 for (unsigned int i = 0; i < v.size(); i++)
278 res[i] = theoretica::cos(v[i]);
279
280 return res;
281 }
282
283
288 template<typename Vector>
289 inline Vector tan(const Vector& v) {
290
291 Vector res;
292 res.resize(v.size());
293
294 #pragma omp parallel for
295 for (unsigned int i = 0; i < v.size(); i++)
296 res[i] = theoretica::tan(v[i]);
297
298 return res;
299 }
300
301
306 template<typename Vector>
307 inline Vector cot(const Vector& v) {
308
309 Vector res;
310 res.resize(v.size());
311
312 #pragma omp parallel for
313 for (unsigned int i = 0; i < v.size(); i++)
314 res[i] = theoretica::cot(v[i]);
315
316 return res;
317 }
318
319
324 template<typename Vector>
325 inline Vector asin(const Vector& v) {
326
327 Vector res;
328 res.resize(v.size());
329
330 #pragma omp parallel for
331 for (unsigned int i = 0; i < v.size(); i++)
332 res[i] = theoretica::asin(v[i]);
333
334 return res;
335 }
336
337
342 template<typename Vector>
343 inline Vector acos(const Vector& v) {
344
345 Vector res;
346 res.resize(v.size());
347
348 #pragma omp parallel for
349 for (unsigned int i = 0; i < v.size(); i++)
350 res[i] = theoretica::acos(v[i]);
351
352 return res;
353 }
354
355
360 template<typename Vector>
361 inline Vector atan(const Vector& v) {
362
363 Vector res;
364 res.resize(v.size());
365
366 #pragma omp parallel for
367 for (unsigned int i = 0; i < v.size(); i++)
368 res[i] = theoretica::atan(v[i]);
369
370 return res;
371 }
372
373
378 template<typename Vector>
379 inline Vector sinh(const Vector& v) {
380
381 Vector res;
382 res.resize(v.size());
383
384 #pragma omp parallel for
385 for (unsigned int i = 0; i < v.size(); i++)
386 res[i] = theoretica::sinh(v[i]);
387
388 return res;
389 }
390
391
396 template<typename Vector>
397 inline Vector cosh(const Vector& v) {
398
399 Vector res;
400 res.resize(v.size());
401
402 #pragma omp parallel for
403 for (unsigned int i = 0; i < v.size(); i++)
404 res[i] = theoretica::cosh(v[i]);
405
406 return res;
407 }
408
409
414 template<typename Vector>
415 inline Vector tanh(const Vector& v) {
416
417 Vector res;
418 res.resize(v.size());
419
420 #pragma omp parallel for
421 for (unsigned int i = 0; i < v.size(); i++)
422 res[i] = theoretica::tanh(v[i]);
423
424 return res;
425 }
426
427
432 template<typename Vector>
433 inline Vector coth(const Vector& v) {
434
435 Vector res;
436 res.resize(v.size());
437
438 #pragma omp parallel for
439 for (unsigned int i = 0; i < v.size(); i++)
440 res[i] = theoretica::coth(v[i]);
441
442 return res;
443 }
444 }
445}
446
447#endif
Vector exp(const Vector &v)
Parallel element-wise evaluation of the exp function.
Definition parallel.h:181
Vector cbrt(const Vector &v)
Parallel element-wise evaluation of the cbrt function.
Definition parallel.h:163
Vector tan(const Vector &v)
Vectorized (element-wise evaluation) of the tan function.
Definition parallel.h:289
Vector cos(const Vector &v)
Parallel element-wise evaluation of the cos function.
Definition parallel.h:271
Vector cot(const Vector &v)
Vectorized (element-wise evaluation) of the cot function.
Definition parallel.h:307
Vector atan(const Vector &v)
Vectorized (element-wise evaluation) of the atan function.
Definition parallel.h:361
Vector log10(const Vector &v)
Parallel element-wise evaluation of the log10 function.
Definition parallel.h:235
Vector square(const Vector &v)
Parallel element-wise evaluation of the square function.
Definition parallel.h:53
Vector tanh(const Vector &v)
Vectorized (element-wise evaluation) of the tanh function.
Definition parallel.h:415
Vector cube(const Vector &v)
Parallel element-wise evaluation of the cube function.
Definition parallel.h:71
Vector sinh(const Vector &v)
Vectorized (element-wise evaluation) of the sinh function.
Definition parallel.h:379
Vector apply_function(Function f, const Vector &v)
Parallel element-wise evaluation of a function, using OpenMP to speed up execution over a vector.
Definition parallel.h:35
Vector coth(const Vector &v)
Vectorized (element-wise evaluation) of the coth function.
Definition parallel.h:433
Vector ln(const Vector &v)
Parallel element-wise evaluation of the ln function.
Definition parallel.h:199
Vector abs(const Vector &v)
Parallel element-wise evaluation of the abs function.
Definition parallel.h:89
Vector sqrt(const Vector &v)
Parallel element-wise evaluation of the sqrt function.
Definition parallel.h:145
Vector pow(const Vector &v, int n)
Parallel element-wise evaluation of the pow function.
Definition parallel.h:108
Vector sin(const Vector &v)
Parallel element-wise evaluation of the sin function.
Definition parallel.h:253
Vector powf(const Vector &v, real x)
Parallel element-wise evaluation of the powf function.
Definition parallel.h:127
Vector log2(const Vector &v)
Parallel element-wise evaluation of the log2 function.
Definition parallel.h:217
Vector cosh(const Vector &v)
Vectorized (element-wise evaluation) of the cosh function.
Definition parallel.h:397
Vector asin(const Vector &v)
Vectorized (element-wise evaluation) of the asin function.
Definition parallel.h:325
Vector acos(const Vector &v)
Vectorized (element-wise evaluation) of the acos function.
Definition parallel.h:343
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:198
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
dual cosh(dual x)
Compute the hyperbolic cosine of a dual number.
Definition dual_functions.h:205
dual2 ln(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:151
dual sinh(dual x)
Compute the hyperbolic sine of a dual number.
Definition dual_functions.h:194
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:198
dual2 log2(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:166
dual2 asin(dual2 x)
Compute the arcsine of a second order dual number.
Definition dual2_functions.h:204
dual2 exp(dual2 x)
Compute the exponential of a second order dual number.
Definition dual2_functions.h:138
dual2 log10(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:182
real cbrt(real x)
Compute the cubic root of x.
Definition real_analysis.h:199
real coth(real x)
Compute the hyperbolic cotangent.
Definition real_analysis.h:1181
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition dual2_functions.h:86
dual2 cot(dual2 x)
Compute the cotangent of a second order dual number.
Definition dual2_functions.h:119
dual2 tan(dual2 x)
Compute the tangent of a second order dual number.
Definition dual2_functions.h:100
dual2 acos(dual2 x)
Compute the arcosine of a second order dual number.
Definition dual2_functions.h:223
complex< T > powf(complex< T > z, real p)
Compute a complex number raised to a real power.
Definition complex_analysis.h:67
dual2 sin(dual2 x)
Compute the sine of a second order dual number.
Definition dual2_functions.h:72
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23
dual2 atan(dual2 x)
Compute the arctangent of a second order dual number.
Definition dual2_functions.h:242
dual tanh(dual x)
Compute the hyperbolic tangent of a dual number.
Definition dual_functions.h:216
dual2 pow(dual2 x, int n)
Compute the n-th power of a second order dual number.
Definition dual2_functions.h:41
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition dual2_functions.h:29
Vector class and operations.