Class documentation of Concepts

Loading...
Searching...
No Matches
arrayOp.hh
Go to the documentation of this file.
1
7#ifndef ArrayOp_hh
8#define ArrayOp_hh
9
10#include <stdarg.h>
11#include <initializer_list>
12#include "toolbox/array.hh"
13
14// debugging
15#define ArrayProduct_D 0
16
17namespace std {
18
19 // *************************************************************** product **
20
22 template<typename F>
23 F product(const concepts::Array<F>& a) {
24 const F* d = (const F*)a;
25 F val = F(1);
26 for(uint i = a.size(); i--; ) val *= *d++;
27 return val;
28 }
29
31 template<typename F>
32 F product(const concepts::Array<F>& a, uint j) {
33 const F* d = (const F*)a;
34 F val = F(1);
35 for(uint i = 0; i < a.size(); ++i, ++d)
36 if (i != j) val *= *d;
37 return val;
38 }
39
43 template<typename F>
44 F product(const concepts::Array<F>& a, uint j, uint k) {
45 const F* d = (const F*)a;
46 F val = F(1);
47 for(uint i = 0; i < a.size(); ++i, ++d)
48 if (i != j && i != k) val *= *d;
49 return val;
50 }
51
52 // ******************************************************************* pow **
53
55 template<typename F>
57 concepts::Array<F> res(a.size());
58 const F* d = a; F* o = res;
59 for(uint i = a.size(); i--; ) *o++ = std::pow(*d++, e);
60 return res;
61 }
62
63 // ******************************************************************* abs **
64
66 template<typename F>
68 concepts::Array<F> res(a.size());
69 const F* d = a; F* e = res;
70 for(uint i = a.size(); i--; ) *e++ = std::abs(*d++);
71 return res;
72 }
73
74 // ******************************************************************* min **
75
77 template<typename F>
78 F min(const concepts::Array<F>& a) {
80 const F* d = a;
81 F val = *d++;
82 for(uint i = a.size()-1; i--; )
83 val = std::min(val, *d++);
84 return val;
85 }
86
87 // ******************************************************************* max **
88
90 template<typename F>
91 F max(const concepts::Array<F>& a) {
93 const F* d = a;
94 F val = *d++;
95 for(uint i = a.size()-1; i--; )
96 val = std::max(val, *d++);
97 return val;
98 }
99
100} // namespace std
101
102namespace concepts {
103
104 // ************************************************************* makeArray **
105
113 template <class F>
114 Array<F> makeArray(std::initializer_list<F> list)
115 {
116 uint n = list.size();
117 Array<F> data(n);
118 uint idx = 0;
119 for( F elem : list )
120 data[idx++] = elem;
121 return data;
122 }
123
124 // ******************************************************* chebychevPoints **
125
131 uint n = p.size();
132 const Real f = M_PI / (2*n);
133 Real *x = (Real*)p;
134 while(n) *x++ = cos(f*(2*--n+1));
135 }
136
137 // ******************************************************** componentArray **
138
144 template <class F, uint dim>
147 uint n = a.size();
148 Array<F> data(n);
149 for(uint j = 0; j < n; ++j)
150 data[j] = a[j][i];
151 return data;
152 }
153
154} // namespace concepts
155
156#endif // ArrayOp_hh
F max(const concepts::Array< F > &a)
Returns the maximal value in array a.
Definition arrayOp.hh:91
concepts::Array< F > pow(const concepts::Array< F > &a, const F e)
Returns the power of values in the array a with e.
Definition arrayOp.hh:56
F min(const concepts::Array< F > &a)
Returns the minimal value in array a.
Definition arrayOp.hh:78
uint size() const
Returns the requested size of the array.
Definition array.hh:259
#define conceptsAssert(cond, exc)
double Real
Definition typedefs.hh:39
Array< F > componentArray(const Array< Point< F, dim > > &a, uint i)
Definition arrayOp.hh:145
void makeArray(const F &cell, const Array< Real > &p, G(F::*fun)(Real) const, Array< G > &array)
Definition arrays.hh:24
void chebychevPoints(concepts::Array< Real > &p)
Definition arrayOp.hh:130
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320