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 
17 namespace std {
18 
19  // *************************************************************** product **
20 
22  template<typename F>
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  // ******************************************************************* abs **
53 
55  template<typename F>
57  concepts::Array<F> res(a.size());
58  const F* d = a; F* e = res;
59  for(uint i = a.size(); i--; ) *e++ = std::abs(*d++);
60  return res;
61  }
62 
63  // ******************************************************************* min **
64 
66  template<typename F>
67  F min(const concepts::Array<F>& a) {
69  const F* d = a;
70  F val = *d++;
71  for(uint i = a.size()-1; i--; )
72  val = std::min(val, *d++);
73  return val;
74  }
75 
76 } // namespace std
77 
78 namespace concepts {
79 
80  // ************************************************************* makeArray **
81 
89  template <class F>
90  Array<F> makeArray(std::initializer_list<F> list)
91  {
92  uint n = list.size();
93  Array<F> data(n);
94  uint idx = 0;
95  for( F elem : list )
96  data[idx++] = elem;
97  return data;
98  }
99 
100  // ******************************************************* chebychevPoints **
101 
107  uint n = p.size();
108  const Real f = M_PI / (2*n);
109  Real *x = (Real*)p;
110  while(n) *x++ = cos(f*(2*--n+1));
111  }
112 
113  // ******************************************************** componentArray **
114 
120  template <class F, uint dim>
123  uint n = a.size();
124  Array<F> data(n);
125  for(uint j = 0; j < n; ++j)
126  data[j] = a[j][i];
127  return data;
128  }
129 
130 } // namespace concepts
131 
132 #endif // ArrayOp_hh
uint size() const
Returns the requested size of the array.
Definition: array.hh:259
Basic class for a Point or a vector.
Array< F > componentArray(const Array< Point< F, dim >> &a, uint i)
Returns the component array of an array of vectors.
Definition: arrayOp.hh:121
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
#define M_PI
Definition: typedefs.hh:13
An array of objects.
Definition: bilinearForm.hh:23
Exception class for assertions.
Definition: exceptions.hh:258
F product(const concepts::Array< F > &a)
Returns the product of values in the array a.
Definition: arrayOp.hh:23
void makeArray(const F &cell, const Array< Real > &p, G(F::*fun)(Real) const, Array< G > &array)
Creates an array array by applying an function fun of a cell cell for each value p.
Definition: arrays.hh:24
F min(const concepts::Array< F > &a)
Returns the minimal value in array a.
Definition: arrayOp.hh:67
uint abs(const uint &v)
Definition: operations.hh:95
void chebychevPoints(concepts::Array< Real > &p)
Zeros of Chebychev polynomials in [-1,1].
Definition: arrayOp.hh:106
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich