Theoretica
Scientific Computing
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"
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 map(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
55 template<typename Function, typename Vector>
56 inline Vector& transform(Function f, Vector& v) {
57
58 #pragma omp parallel for
59 for (unsigned int i = 0; i < v.size(); i++)
60 v[i] = f(v[i]);
61
62 return v;
63 }
64
65
70 template<typename Vector>
71 inline Vector square(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::square(v[i]);
79
80 return res;
81 }
82
83
88 template<typename Vector>
89 inline Vector cube(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::cube(v[i]);
97
98 return res;
99 }
100
101
106 template<typename Vector>
107 inline Vector abs(const Vector& v) {
108
109 Vector res;
110 res.resize(v.size());
111
112 #pragma omp parallel for
113 for (unsigned int i = 0; i < v.size(); i++)
114 res[i] = theoretica::abs(v[i]);
115
116 return res;
117 }
118
119
125 template<typename Vector>
126 inline Vector pow(const Vector& v, int n) {
127
128 Vector res;
129 res.resize(v.size());
130
131 #pragma omp parallel for
132 for (unsigned int i = 0; i < v.size(); i++)
133 res[i] = theoretica::pow(v[i], n);
134
135 return res;
136 }
137
138
144 template<typename Vector>
145 inline Vector powf(const Vector& v, real x) {
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::powf(v[i], x);
153
154 return res;
155 }
156
157
162 template<typename Vector>
163 inline Vector sqrt(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::sqrt(v[i]);
171
172 return res;
173 }
174
175
180 template<typename Vector>
181 inline Vector cbrt(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::cbrt(v[i]);
189
190 return res;
191 }
192
193
198 template<typename Vector>
199 inline Vector exp(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::exp(v[i]);
207
208 return res;
209 }
210
211
216 template<typename Vector>
217 inline Vector ln(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::ln(v[i]);
225
226 return res;
227 }
228
229
234 template<typename Vector>
235 inline Vector log2(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::log2(v[i]);
243
244 return res;
245 }
246
247
252 template<typename Vector>
253 inline Vector log10(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::log10(v[i]);
261
262 return res;
263 }
264
265
270 template<typename Vector>
271 inline Vector sin(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::sin(v[i]);
279
280 return res;
281 }
282
283
288 template<typename Vector>
289 inline Vector cos(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::cos(v[i]);
297
298 return res;
299 }
300
301
306 template<typename Vector>
307 inline Vector tan(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::tan(v[i]);
315
316 return res;
317 }
318
319
324 template<typename Vector>
325 inline Vector cot(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::cot(v[i]);
333
334 return res;
335 }
336
337
342 template<typename Vector>
343 inline Vector asin(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::asin(v[i]);
351
352 return res;
353 }
354
355
360 template<typename Vector>
361 inline Vector acos(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::acos(v[i]);
369
370 return res;
371 }
372
373
378 template<typename Vector>
379 inline Vector atan(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::atan(v[i]);
387
388 return res;
389 }
390
391
396 template<typename Vector>
397 inline Vector sinh(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::sinh(v[i]);
405
406 return res;
407 }
408
409
414 template<typename Vector>
415 inline Vector cosh(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::cosh(v[i]);
423
424 return res;
425 }
426
427
432 template<typename Vector>
433 inline Vector tanh(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::tanh(v[i]);
441
442 return res;
443 }
444
445
450 template<typename Vector>
451 inline Vector coth(const Vector& v) {
452
453 Vector res;
454 res.resize(v.size());
455
456 #pragma omp parallel for
457 for (unsigned int i = 0; i < v.size(); i++)
458 res[i] = theoretica::coth(v[i]);
459
460 return res;
461 }
462 }
463}
464
465#endif
Functions of complex variable.
Operations on datasets and generic ordered sets of numbers.
Functions defined on second order dual numbers for automatic differentiation.
Functions defined on dual numbers for automatic differentiation.
Functions defined on multidual numbers for automatic differentiation of multivariable real functions.
Parallelized element-wise evaluation of functions.
Vector exp(const Vector &v)
Parallel element-wise evaluation of the exp function.
Definition parallel.h:199
Vector cbrt(const Vector &v)
Parallel element-wise evaluation of the cbrt function.
Definition parallel.h:181
Vector tan(const Vector &v)
Vectorized (element-wise evaluation) of the tan function.
Definition parallel.h:307
Vector cos(const Vector &v)
Parallel element-wise evaluation of the cos function.
Definition parallel.h:289
Vector cot(const Vector &v)
Vectorized (element-wise evaluation) of the cot function.
Definition parallel.h:325
Vector & transform(Function f, Vector &v)
Transform a vector by applying a given function to each of its elements, modifying the vector itself ...
Definition parallel.h:56
Vector atan(const Vector &v)
Vectorized (element-wise evaluation) of the atan function.
Definition parallel.h:379
Vector map(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 log10(const Vector &v)
Parallel element-wise evaluation of the log10 function.
Definition parallel.h:253
Vector square(const Vector &v)
Parallel element-wise evaluation of the square function.
Definition parallel.h:71
Vector tanh(const Vector &v)
Vectorized (element-wise evaluation) of the tanh function.
Definition parallel.h:433
Vector cube(const Vector &v)
Parallel element-wise evaluation of the cube function.
Definition parallel.h:89
Vector sinh(const Vector &v)
Vectorized (element-wise evaluation) of the sinh function.
Definition parallel.h:397
Vector coth(const Vector &v)
Vectorized (element-wise evaluation) of the coth function.
Definition parallel.h:451
Vector ln(const Vector &v)
Parallel element-wise evaluation of the ln function.
Definition parallel.h:217
Vector abs(const Vector &v)
Parallel element-wise evaluation of the abs function.
Definition parallel.h:107
Vector sqrt(const Vector &v)
Parallel element-wise evaluation of the sqrt function.
Definition parallel.h:163
Vector pow(const Vector &v, int n)
Parallel element-wise evaluation of the pow function.
Definition parallel.h:126
Vector sin(const Vector &v)
Parallel element-wise evaluation of the sin function.
Definition parallel.h:271
Vector powf(const Vector &v, real x)
Parallel element-wise evaluation of the powf function.
Definition parallel.h:145
Vector log2(const Vector &v)
Parallel element-wise evaluation of the log2 function.
Definition parallel.h:235
Vector cosh(const Vector &v)
Vectorized (element-wise evaluation) of the cosh function.
Definition parallel.h:415
Vector asin(const Vector &v)
Vectorized (element-wise evaluation) of the asin function.
Definition parallel.h:343
Vector acos(const Vector &v)
Vectorized (element-wise evaluation) of the acos function.
Definition parallel.h:361
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
dual2 ln(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:195
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:242
dual2 log2(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:210
dual2 asin(dual2 x)
Compute the arcsine of a second order dual number.
Definition dual2_functions.h:248
double real
A real number, defined as a floating point type.
Definition constants.h:207
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:226
real cbrt(real x)
Compute the cubic root of x.
Definition real_analysis.h:199
dual2 tanh(dual2 x)
Compute the hyperbolic tangent of a second order dual number.
Definition dual2_functions.h:179
dual2 sinh(dual2 x)
Compute the hyperbolic sine of a second order dual number.
Definition dual2_functions.h:151
real coth(real x)
Compute the hyperbolic cotangent.
Definition real_analysis.h:1192
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 cosh(dual2 x)
Compute the hyperbolic cosine of a second order dual number.
Definition dual2_functions.h:165
dual2 acos(dual2 x)
Compute the arcosine of a second order dual number.
Definition dual2_functions.h:267
complex< T > powf(complex< T > z, real p)
Compute a complex number raised to a real power.
Definition complex_analysis.h:65
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:286
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
Real functions.
Vector class and operations.