g4tools  5.4.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
tools::array< T > Class Template Reference
Inheritance diagram for tools::array< T >:
Inheritance graph
[legend]

Public Types

typedef std::vector< std::pair< unsigned int, unsigned int > > cut_t
 
typedef std::vector< unsigned int > uints_t
 
typedef std::vector< T >::iterator vec_it_t
 
typedef std::vector< T >::const_iterator cons_vec_it_t
 

Public Member Functions

 array ()
 
 array (const uints_t &a_orders)
 
 array (unsigned int a_dimension, unsigned int a_order)
 
virtual ~array ()
 
 array (const array &a_from)
 
arrayoperator= (const array &a_from)
 
arrayoperator*= (const T &a_T)
 
bool operator== (const array &a_array) const
 
bool operator!= (const array &a_array) const
 
array operator* (const T &a_T) const
 
void copy (const array &a_from)
 
void clear ()
 
bool configure (const uints_t &a_orders)
 
size_t dimension () const
 
const uints_torders () const
 
size_t size () const
 
bool set_value (const uints_t &a_is, const T &a_value)
 
bool value (const uints_t &a_is, T &a_value) const
 
value_no_check (const uints_t &a_is) const
 
void reset ()
 
const std::vector< T > & vector () const
 
std::vector< T > & vector ()
 
bool fill (const std::vector< T > &a_values, cut_t *a_cut=0)
 
bool fill (unsigned int a_sz, const T *a_data, cut_t *a_cut=0)
 
bool equal (const array &a_array) const
 
bool equal (const array &a_array, T aEpsilon) const
 
bool is_proportional (const array &a_array, T &a_factor) const
 
bool add (const array &a_array, cut_t *a_cut=0)
 
bool subtract (const array &a_array)
 
bool multiply (const array &a_array)
 
bool divide (const array &a_array)
 
bool contract (const array &a_array, T &a_value) const
 
void add (const T &a_T, cut_t *a_cut=0)
 
void multiply (const T &a_T)
 
bool divide (const T &a_T)
 
bool invert ()
 
bool offset (const uints_t &a_is, unsigned int &a_offset) const
 
bool indices (unsigned int a_offset, uints_t &a_is) const
 
bool accept (unsigned int a_index, const cut_t &a_cut) const
 
void set_constant (const T &a_v)
 
void set_zero ()
 

Static Public Member Functions

static const std::string & s_class ()
 
static T zero ()
 
static T one ()
 
static T minus_one ()
 
static T two ()
 

Protected Attributes

uints_t m_orders
 
uints_t m_offsets
 
std::vector< T > m_vector
 
uints_t m_is
 

Detailed Description

template<class T>
class tools::array< T >

Definition at line 19 of file array.

Member Typedef Documentation

◆ cons_vec_it_t

template<class T >
typedef std::vector<T>::const_iterator tools::array< T >::cons_vec_it_t

Definition at line 29 of file array.

◆ cut_t

template<class T >
typedef std::vector< std::pair<unsigned int,unsigned int> > tools::array< T >::cut_t

Definition at line 26 of file array.

◆ uints_t

template<class T >
typedef std::vector<unsigned int> tools::array< T >::uints_t

Definition at line 27 of file array.

◆ vec_it_t

template<class T >
typedef std::vector<T>::iterator tools::array< T >::vec_it_t

Definition at line 28 of file array.

Constructor & Destructor Documentation

◆ array() [1/4]

template<class T >
tools::array< T >::array ( )
inline

Definition at line 31 of file array.

31  {
32 #ifdef TOOLS_MEM
33  mem::increment(s_class().c_str());
34 #endif
35  }

◆ array() [2/4]

template<class T >
tools::array< T >::array ( const uints_t a_orders)
inline

Definition at line 36 of file array.

36  {
37 #ifdef TOOLS_MEM
38  mem::increment(s_class().c_str());
39 #endif
40  configure(a_orders);
41  }

◆ array() [3/4]

template<class T >
tools::array< T >::array ( unsigned int  a_dimension,
unsigned int  a_order 
)
inline

Definition at line 42 of file array.

42  {
43 #ifdef TOOLS_MEM
44  mem::increment(s_class().c_str());
45 #endif
46  // A hypercube of dimension "a_dimension" and size "a_order".
47  uints_t _orders(a_dimension);
48  for(unsigned int index=0;index<a_dimension;index++)
49  _orders[index] = a_order;
50  configure(_orders);
51  }

◆ ~array()

template<class T >
virtual tools::array< T >::~array ( )
inlinevirtual

Definition at line 52 of file array.

52  {
53 #ifdef TOOLS_MEM
54  mem::decrement(s_class().c_str());
55 #endif
56  }

◆ array() [4/4]

template<class T >
tools::array< T >::array ( const array< T > &  a_from)
inline

Definition at line 58 of file array.

59  :m_orders(a_from.m_orders)
60  ,m_offsets(a_from.m_offsets)
61  ,m_vector(a_from.m_vector)
62  ,m_is(a_from.m_is){
63 #ifdef TOOLS_MEM
64  mem::increment(s_class().c_str());
65 #endif
66  }

Member Function Documentation

◆ accept()

template<class T >
bool tools::array< T >::accept ( unsigned int  a_index,
const cut_t a_cut 
) const
inline

Definition at line 339 of file array.

339  {
340  size_t dim = m_orders.size();
341  if(a_cut.size()!=dim) return false;
342  if(!indices(a_index,const_cast<uints_t&>(m_is))) return false;
343  bool good = true;
344  for(size_t iaxis=0;iaxis<dim;iaxis++) {
345  if(m_is[iaxis]<a_cut[iaxis].first) {good = false;break;}
346  if(m_is[iaxis]>a_cut[iaxis].second) {good = false;break;}
347  }
348  return good;
349  }

◆ add() [1/2]

template<class T >
bool tools::array< T >::add ( const array< T > &  a_array,
cut_t a_cut = 0 
)
inline

Definition at line 234 of file array.

234  {
235  if(m_orders!=a_array.m_orders) return false;
236  vec_it_t it = m_vector.begin();
237  cons_vec_it_t ait = a_array.m_vector.begin();
238  unsigned int index = 0;
239  for(;it!=m_vector.end();++it,++ait,index++) {
240  if(!a_cut || (a_cut && accept(index,*a_cut)) ) {
241  (*it) += (*ait);
242  }
243  }
244  return true;
245  }

◆ add() [2/2]

template<class T >
void tools::array< T >::add ( const T &  a_T,
cut_t a_cut = 0 
)
inline

Definition at line 284 of file array.

284  {
285  unsigned int index = 0;
286  for(vec_it_t it = m_vector.begin();it!=m_vector.end();++it,index++) {
287  if(!a_cut || (a_cut && accept(index,*a_cut)) ) {
288  (*it) += a_T;
289  }
290  }
291  }

◆ clear()

template<class T >
void tools::array< T >::clear ( )
inline

Definition at line 104 of file array.

104  {
105  m_orders.clear();
106  m_offsets.clear();
107  m_vector.clear();
108  m_is.clear();
109  }

◆ configure()

template<class T >
bool tools::array< T >::configure ( const uints_t a_orders)
inline

Definition at line 110 of file array.

110  {
111  m_orders = a_orders;
112  size_t dim = m_orders.size();
113  if(dim==0) {
114  clear();
115  return false;
116  }
117  unsigned int _size = 1;
118  for(size_t index=0;index<dim;index++) {
119  //if(m_orders[index]<0) {
120  //clear();
121  //return false;
122  //}
123  _size *= m_orders[index];
124  }
125  m_vector.resize(_size);
126  m_vector.assign(_size,zero());
127  m_offsets.resize(dim,0);
128  m_offsets[0] = 1;
129  for(size_t iaxis=1;iaxis<dim;iaxis++)
130  m_offsets[iaxis] = m_offsets[iaxis-1] * m_orders[iaxis-1];
131  m_is.resize(dim);
132  m_is.assign(dim,0);
133  return true;
134  }

◆ contract()

template<class T >
bool tools::array< T >::contract ( const array< T > &  a_array,
T &  a_value 
) const
inline

Definition at line 275 of file array.

275  {
276  a_value = zero();
277  if(m_orders!=a_array.m_orders) return false;
278  cons_vec_it_t it = m_vector.begin();
279  cons_vec_it_t ait = a_array.m_vector.begin();
280  for(;it!=m_vector.end();++it,++ait) a_value += (*it) * (*ait);
281  return true;
282  }

◆ copy()

template<class T >
void tools::array< T >::copy ( const array< T > &  a_from)
inline

Definition at line 98 of file array.

98  {
99  m_orders = a_from.m_orders;
100  m_offsets = a_from.m_offsets;
101  m_vector = a_from.m_vector;
102  m_is = a_from.m_is;
103  }

◆ dimension()

template<class T >
size_t tools::array< T >::dimension ( ) const
inline

Definition at line 135 of file array.

135 { return m_orders.size();}

◆ divide() [1/2]

template<class T >
bool tools::array< T >::divide ( const array< T > &  a_array)
inline

Definition at line 260 of file array.

260  {
261  if(m_orders!=a_array.m_orders) return false;
262  bool status = true;
263  vec_it_t it = m_vector.begin();
264  cons_vec_it_t ait = a_array.m_vector.begin();
265  for(;it!=m_vector.end();++it,++ait) {
266  if((*ait)==zero()) {
267  (*it) = zero(); //PAW convention.
268  status = false;
269  } else {
270  (*it) /= (*ait);
271  }
272  }
273  return status;
274  }

◆ divide() [2/2]

template<class T >
bool tools::array< T >::divide ( const T &  a_T)
inline

Definition at line 295 of file array.

295  {
296  if(a_T==zero()) return false;
297  for(vec_it_t it = m_vector.begin();it!=m_vector.end();++it) (*it) /= a_T;
298  return true;
299  }

◆ equal() [1/2]

template<class T >
bool tools::array< T >::equal ( const array< T > &  a_array) const
inline

Definition at line 189 of file array.

189  {
190  if(m_orders!=a_array.m_orders) return false;
191  cons_vec_it_t it = m_vector.begin();
192  cons_vec_it_t ait = a_array.m_vector.begin();
193  for(;it!=m_vector.end();++it,++ait) {
194  if((*it)!=(*ait)) return false;
195  }
196  return true;
197  }

◆ equal() [2/2]

template<class T >
bool tools::array< T >::equal ( const array< T > &  a_array,
aEpsilon 
) const
inline

Definition at line 198 of file array.

198  {
199  if(m_orders!=a_array.m_orders) return false;
200  cons_vec_it_t it = m_vector.begin();
201  cons_vec_it_t ait = a_array.m_vector.begin();
202  for(;it!=m_vector.end();++it,++ait) {
203  T diff = (*it) - (*ait);
204  if(diff<0) diff *= -1;
205  if(diff>=aEpsilon) return false;
206  }
207  return true;
208  }

◆ fill() [1/2]

template<class T >
bool tools::array< T >::fill ( const std::vector< T > &  a_values,
cut_t a_cut = 0 
)
inline

Definition at line 163 of file array.

163  {
164  size_t dsize = a_values.size();
165  size_t di = 0;
166  unsigned int index = 0;
167  for(vec_it_t it=m_vector.begin();it!=m_vector.end();++it,index++) {
168  if(!a_cut || (a_cut && accept(index,*a_cut)) ) {
169  if(di>=dsize) return false; //a_values exhausted too early
170  *it = a_values[di];
171  di++;
172  }
173  }
174  return true;
175  }

◆ fill() [2/2]

template<class T >
bool tools::array< T >::fill ( unsigned int  a_sz,
const T *  a_data,
cut_t a_cut = 0 
)
inline

Definition at line 176 of file array.

176  {
177  unsigned int di = 0;
178  unsigned int index = 0;
179  for(vec_it_t it=m_vector.begin();it!=m_vector.end();++it,index++) {
180  if(!a_cut || (a_cut && accept(index,*a_cut)) ) {
181  if(di>=a_sz) return false; //a_values exhausted too early
182  *it = a_data[di];
183  di++;
184  }
185  }
186  return true;
187  }

◆ indices()

template<class T >
bool tools::array< T >::indices ( unsigned int  a_offset,
uints_t a_is 
) const
inline

Definition at line 329 of file array.

329  {
330  if(a_offset>=m_vector.size()) return false;
331  size_t dim = m_orders.size();
332  unsigned int off = a_offset;
333  for(int iaxis=int(dim)-1;iaxis>=0;iaxis--) {
334  a_is[iaxis] = off/m_offsets[iaxis];
335  off -= a_is[iaxis] * m_offsets[iaxis];
336  }
337  return true;
338  }

◆ invert()

template<class T >
bool tools::array< T >::invert ( )
inline

Definition at line 300 of file array.

300  {
301  bool status = true;
302  T v_one = one();
303  for(vec_it_t it = m_vector.begin();it!=m_vector.end();++it) {
304  if((*it)==zero()) {
305  (*it) = zero(); //PAW convention.
306  status = false;
307  } else {
308  T _value = (*it);
309  (*it) = v_one/_value;
310  }
311  }
312  return status;
313  }

◆ is_proportional()

template<class T >
bool tools::array< T >::is_proportional ( const array< T > &  a_array,
T &  a_factor 
) const
inline

Definition at line 209 of file array.

209  {
210  // If true, then : a_array = a_factor * this.
211  a_factor = zero();
212  if(m_orders!=a_array.m_orders) return false;
213  bool first = true;
214  cons_vec_it_t it = m_vector.begin();
215  cons_vec_it_t ait = a_array.m_vector.begin();
216  for(;it!=m_vector.end();++it,++ait) {
217  if( ((*it)==zero()) && ((*ait)==zero())) {
218  continue;
219  } else if( ((*it)!=zero()) && ((*ait)==zero())) {
220  return false;
221  } else if( ((*it)==zero()) && ((*ait)!=zero())) {
222  return false;
223  } else {
224  if(first) {
225  a_factor = (*ait)/(*it);
226  first = false;
227  } else {
228  if((*ait)!=(*it)*a_factor) return false;
229  }
230  }
231  }
232  return true;
233  }

◆ minus_one()

template<class T >
static T tools::array< T >::minus_one ( )
inlinestatic

Definition at line 366 of file array.

366  {
367  //return (T)-1;
368  return T(-1);
369  }

◆ multiply() [1/2]

template<class T >
bool tools::array< T >::multiply ( const array< T > &  a_array)
inline

Definition at line 253 of file array.

253  {
254  if(m_orders!=a_array.m_orders) return false;
255  vec_it_t it = m_vector.begin();
256  cons_vec_it_t ait = a_array.m_vector.begin();
257  for(;it!=m_vector.end();++it,++ait) (*it) *= (*ait);
258  return true;
259  }

◆ multiply() [2/2]

template<class T >
void tools::array< T >::multiply ( const T &  a_T)
inline

Definition at line 292 of file array.

292  {
293  for(vec_it_t it = m_vector.begin();it!=m_vector.end();++it) (*it) *= a_T;
294  }

◆ offset()

template<class T >
bool tools::array< T >::offset ( const uints_t a_is,
unsigned int &  a_offset 
) const
inline

Definition at line 314 of file array.

314  {
315  size_t dim = m_orders.size();
316  a_offset = 0;
317  if(a_is.size()!=dim) return false;
318  if(dim==0) return false;
319  for(size_t iaxis=0;iaxis<dim;iaxis++) {
320  unsigned int i = a_is[iaxis];
321  if(i>=m_orders[iaxis]) {
322  a_offset = 0;
323  return false;
324  }
325  a_offset += i * m_offsets[iaxis];
326  }
327  return true;
328  }

◆ one()

template<class T >
static T tools::array< T >::one ( )
inlinestatic

Definition at line 362 of file array.

362  {
363  //return (T)1;
364  return T(1);
365  }

◆ operator!=()

template<class T >
bool tools::array< T >::operator!= ( const array< T > &  a_array) const
inline

Definition at line 79 of file array.

79  {
80  return !operator==(a_array);
81  }

◆ operator*()

template<class T >
array tools::array< T >::operator* ( const T &  a_T) const
inline

Definition at line 82 of file array.

82  {
83  array a(*this);
84  a.multiply(a_T);
85  return a;
86  }

◆ operator*=()

template<class T >
array& tools::array< T >::operator*= ( const T &  a_T)
inline

Definition at line 75 of file array.

75 {multiply(a_T);return *this;}

◆ operator=()

template<class T >
array& tools::array< T >::operator= ( const array< T > &  a_from)
inline

Definition at line 67 of file array.

67  {
68  m_orders = a_from.m_orders;
69  m_offsets = a_from.m_offsets;
70  m_vector = a_from.m_vector;
71  m_is = a_from.m_is;
72  return *this;
73  }

◆ operator==()

template<class T >
bool tools::array< T >::operator== ( const array< T > &  a_array) const
inline

Definition at line 76 of file array.

76  {
77  return equal(a_array);
78  }

◆ orders()

template<class T >
const uints_t& tools::array< T >::orders ( ) const
inline

Definition at line 136 of file array.

136 { return m_orders;}

◆ reset()

template<class T >
void tools::array< T >::reset ( )
inline

Definition at line 158 of file array.

158  {
159  for(vec_it_t it=m_vector.begin();it!=m_vector.end();++it) *it = 0;
160  }

◆ s_class()

template<class T >
static const std::string& tools::array< T >::s_class ( )
inlinestatic

Definition at line 21 of file array.

21  {
22  static const std::string s_v("tools::array");
23  return s_v;
24  }

◆ set_constant()

template<class T >
void tools::array< T >::set_constant ( const T &  a_v)
inline

Definition at line 350 of file array.

350  {
351  for(vec_it_t it = m_vector.begin();it!=m_vector.end();++it) (*it) = a_v;
352  }

◆ set_value()

template<class T >
bool tools::array< T >::set_value ( const uints_t a_is,
const T &  a_value 
)
inline

Definition at line 138 of file array.

138  {
139  unsigned int off = 0;
140  if(!offset(a_is,off)) return false;
141  m_vector[off] = a_value;
142  return true;
143  }

◆ set_zero()

template<class T >
void tools::array< T >::set_zero ( )
inline

Definition at line 353 of file array.

353  {
354  set_constant(zero());
355  }

◆ size()

template<class T >
size_t tools::array< T >::size ( ) const
inline

Definition at line 137 of file array.

137 {return m_vector.size();}

◆ subtract()

template<class T >
bool tools::array< T >::subtract ( const array< T > &  a_array)
inline

Definition at line 246 of file array.

246  {
247  if(m_orders!=a_array.m_orders) return false;
248  vec_it_t it = m_vector.begin();
249  cons_vec_it_t ait = a_array.m_vector.begin();
250  for(;it!=m_vector.end();++it,++ait) (*it) -= (*ait);
251  return true;
252  }

◆ two()

template<class T >
static T tools::array< T >::two ( )
inlinestatic

Definition at line 370 of file array.

370  {
371  //return (T)2;
372  return T(2);
373  }

◆ value()

template<class T >
bool tools::array< T >::value ( const uints_t a_is,
T &  a_value 
) const
inline

Definition at line 144 of file array.

144  {
145  unsigned int off = 0;
146  if(!offset(a_is,off)) {
147  a_value = 0;
148  return false;
149  }
150  a_value = m_vector[off];
151  return true;
152  }

◆ value_no_check()

template<class T >
T tools::array< T >::value_no_check ( const uints_t a_is) const
inline

Definition at line 153 of file array.

153  { //TOUCHY
154  unsigned int off = 0;
155  if(!offset(a_is,off)) {}
156  return m_vector[off];
157  }

◆ vector() [1/2]

template<class T >
std::vector<T>& tools::array< T >::vector ( )
inline

Definition at line 162 of file array.

162 { return m_vector;}

◆ vector() [2/2]

template<class T >
const std::vector<T>& tools::array< T >::vector ( ) const
inline

Definition at line 161 of file array.

161 { return m_vector;}

◆ zero()

template<class T >
static T tools::array< T >::zero ( )
inlinestatic

Definition at line 357 of file array.

357  {
358  //return (T)0;
359  //return T(0);
360  return T();
361  }

Member Data Documentation

◆ m_is

template<class T >
uints_t tools::array< T >::m_is
protected

Definition at line 378 of file array.

◆ m_offsets

template<class T >
uints_t tools::array< T >::m_offsets
protected

Definition at line 376 of file array.

◆ m_orders

template<class T >
uints_t tools::array< T >::m_orders
protected

Definition at line 375 of file array.

◆ m_vector

template<class T >
std::vector<T> tools::array< T >::m_vector
protected

Definition at line 377 of file array.


The documentation for this class was generated from the following file:
tools::array::s_class
static const std::string & s_class()
Definition: array:21
tools::array::m_orders
uints_t m_orders
Definition: array:375
tools::array::clear
void clear()
Definition: array:104
tools::array::vec_it_t
std::vector< T >::iterator vec_it_t
Definition: array:28
tools::array::offset
bool offset(const uints_t &a_is, unsigned int &a_offset) const
Definition: array:314
tools::array::zero
static T zero()
Definition: array:357
tools::array::cons_vec_it_t
std::vector< T >::const_iterator cons_vec_it_t
Definition: array:29
tools::array::multiply
bool multiply(const array &a_array)
Definition: array:253
tools::array::indices
bool indices(unsigned int a_offset, uints_t &a_is) const
Definition: array:329
tools::array::one
static T one()
Definition: array:362
tools::array::operator==
bool operator==(const array &a_array) const
Definition: array:76
tools::array::equal
bool equal(const array &a_array) const
Definition: array:189
tools::array::m_offsets
uints_t m_offsets
Definition: array:376
tools::diff
void diff(std::ostream &a_out, const array< T > &aA, const array< T > &aB, T a_epsilon)
Definition: array:529
tools::array::configure
bool configure(const uints_t &a_orders)
Definition: array:110
tools::array::set_constant
void set_constant(const T &a_v)
Definition: array:350
tools::array::m_vector
std::vector< T > m_vector
Definition: array:377
tools::array::array
array()
Definition: array:31
tools::array::uints_t
std::vector< unsigned int > uints_t
Definition: array:27
tools::array::m_is
uints_t m_is
Definition: array:378
tools::array::accept
bool accept(unsigned int a_index, const cut_t &a_cut) const
Definition: array:339