HOPS
HOPS class reference
MHO_NDArrayWrapper.hh
Go to the documentation of this file.
1 #ifndef MHO_NDArrayWrapper_HH__
2 #define MHO_NDArrayWrapper_HH__
3 
4 #include <algorithm>
5 #include <array>
6 #include <cinttypes>
7 #include <cmath>
8 #include <cstdlib>
9 #include <cstring> //for memset
10 #include <stdexcept>
11 #include <string>
12 #include <vector>
13 
16 #include "MHO_ExtensibleElement.hh"
17 #include "MHO_Message.hh"
18 #include "MHO_Meta.hh"
19 #include "MHO_NDArrayMath.hh"
20 
21 #include "MHO_NDArrayView.hh"
22 
23 namespace hops
24 {
25 
39 template< typename XValueType, std::size_t RANK >
41  : public MHO_ExtensibleElement //any and all extensions are purely a runtime concept and do NOT get streamed for I/O
42 {
43  public:
44  using value_type = XValueType;
45  using index_type = std::array< std::size_t, RANK >;
46  typedef std::integral_constant< std::size_t, RANK > rank;
47 
48  //constructors
49  //empty constructor, to be configured later
50  MHO_NDArrayWrapper() { Construct(nullptr, nullptr); };
51 
52  //data is internally allocated
53  MHO_NDArrayWrapper(const std::size_t* dim) { Construct(nullptr, dim); };
54 
55  //data is interally allocated, but copied in from an external source
56  MHO_NDArrayWrapper(XValueType* ptr, const std::size_t* dim) { Construct(ptr, dim); };
57 
58  //copy constructor
60  {
61  Construct(nullptr, &(obj.fDims[0]));
62  std::copy(obj.fData.begin(), obj.fData.end(), fData.begin());
63  }
64 
65  public:
66  //destructor
67  virtual ~MHO_NDArrayWrapper(){};
68 
74  MHO_NDArrayWrapper* Clone() { return new MHO_NDArrayWrapper(*this); }
75 
76  //resize function -- destroys contents
83  virtual void Resize(const std::size_t* dim) { Construct(nullptr, dim); }
84 
92  template< typename... XDimSizeTypeS >
93  typename std::enable_if< (sizeof...(XDimSizeTypeS) == RANK), void >::type Resize(XDimSizeTypeS... dim)
94  {
95  index_type tmp = {{static_cast< size_t >(dim)...}}; //convert the arguments to an array
96  Resize(&(tmp[0]));
97  }
98 
105  void CopyFromExternalData(XValueType* ptr, const std::size_t* dim) { Construct(ptr, dim); }
106 
112  std::size_t GetRank() const { return RANK; }
113 
119  std::size_t GetSize() const { return fData.size(); };
120 
126  const std::size_t* GetDimensions() const { return &(fDims[0]); }
127 
133  void GetDimensions(std::size_t* dim) const
134  {
135  for(std::size_t i = 0; i < RANK; i++)
136  {
137  dim[i] = fDims[i];
138  }
139  }
140 
146  index_type GetDimensionArray() const { return fDims; }
147 
154  std::size_t GetDimension(std::size_t idx) const
155  {
156  if(idx < RANK)
157  {
158  return fDims[idx];
159  }
160  else
161  {
162  throw std::out_of_range("MHO_NDArrayWrapper::GetDimension() index out of range.");
163  }
164  }
165 
171  const std::size_t* GetStrides() const { return &(fStrides[0]); }
172 
178  void GetStrides(std::size_t* strd) const
179  {
180  for(std::size_t i = 0; i < RANK; i++)
181  {
182  strd[i] = fStrides[i];
183  }
184  }
185 
186  index_type GetStrideArray() const { return fStrides; }
187 
188  std::size_t GetStride(std::size_t idx) const { return fStrides[idx]; }
189 
196  template< typename... XIndexTypeS >
197  typename std::enable_if< (sizeof...(XIndexTypeS) == RANK), XValueType& >::type operator()(XIndexTypeS... idx)
198  {
199  index_type tmp = {{static_cast< size_t >(idx)...}};
200  return ValueAt(tmp);
201  }
202 
209  template< typename... XIndexTypeS >
210  typename std::enable_if< (sizeof...(XIndexTypeS) == RANK), const XValueType& >::type
211  operator()(XIndexTypeS... idx) const
212  {
213  index_type tmp = {{static_cast< size_t >(idx)...}};
214  return ValueAt(tmp);
215  }
216 
223  template< typename... XIndexTypeS >
224  typename std::enable_if< (sizeof...(XIndexTypeS) == RANK), XValueType& >::type at(XIndexTypeS... idx)
225  {
226  //make sure the indices are valid for the given array dimensions
227  index_type tmp = {{static_cast< size_t >(idx)...}};
228  if(CheckIndexValidity(tmp))
229  {
230  return ValueAt(tmp);
231  }
232  else
233  {
234  throw std::out_of_range("MHO_NDArrayWrapper::at() indices out of range.");
235  }
236  }
237 
244  template< typename... XIndexTypeS >
245  typename std::enable_if< (sizeof...(XIndexTypeS) == RANK), const XValueType& >::type at(XIndexTypeS... idx) const
246  {
247  //make sure the indices are valid for the given array dimensions
248  index_type tmp = {{static_cast< size_t >(idx)...}};
249  if(CheckIndexValidity(tmp))
250  {
251  return ValueAt(tmp);
252  }
253  else
254  {
255  throw std::out_of_range("MHO_NDArrayWrapper::at() indices out of range.");
256  }
257  }
258 
262  XValueType* GetData() { return fData.data(); };
263 
264  const XValueType* GetData() const { return fData.data(); };
265 
266  //fast access operator by 1-dim index (absolute-position) into the array
267  //this assumes the data is contiguous in memory, which may not be true
268  //if the array wrapper is a slice of a larger array
269  XValueType& operator[](std::size_t i) { return fData[i]; }
270 
271  const XValueType& operator[](std::size_t i) const { return fData[i]; }
272 
273  //assignment operator
275  {
276  if(this != &rhs)
277  {
278  Construct(nullptr, &(rhs.fDims[0]));
279  std::copy(rhs.fData.begin(), rhs.fData.end(), this->fData.begin());
280  }
281  return *this;
282  }
283 
287  void SetArray(const XValueType& obj)
288  {
289  for(auto it = fData.begin(); it != fData.end(); it++)
290  {
291  *it = obj;
292  }
293  }
294 
298  void ZeroArray() { std::fill(fData.begin(), fData.end(), XValueType{}); }
299 
300  //copy, effectively the same as assignment operator
301  virtual void Copy(const MHO_NDArrayWrapper& rhs)
302  {
303  if(this != &rhs)
304  {
305  Construct(nullptr, &(rhs.fDims[0]));
306  std::copy(rhs.fData.begin(), rhs.fData.end(), this->fData.begin());
307  }
308  }
309 
310  //copy, but from an array view with the same rank
311  virtual void Copy(const MHO_NDArrayView< XValueType, RANK >& rhs)
312  {
313  auto dims = rhs.GetDimensionArray();
314  Construct(nullptr, &(dims[0]));
315  std::copy(rhs.cbegin(), rhs.cend(), this->fData.begin());
316  }
317 
321  std::size_t GetOffsetForIndices(const std::size_t* index)
322  {
323  return MHO_NDArrayMath::OffsetFromStrideIndex< RANK >(&(fStrides[0]), index);
324  }
325 
329  index_type GetIndicesForOffset(std::size_t offset)
330  {
331  index_type index;
332  MHO_NDArrayMath::RowMajorIndexFromOffset< RANK >(offset, &(fDims[0]), &(index[0]));
333  return index;
334  }
335 
343  template< typename... XIndexTypeS >
344  typename std::enable_if< (sizeof...(XIndexTypeS) < RANK),
345  MHO_NDArrayView< XValueType, RANK - (sizeof...(XIndexTypeS)) > >::type
346  SubView(XIndexTypeS... idx)
347  {
348  constexpr typename std::integral_constant< std::size_t, sizeof...(XIndexTypeS) > nfixed_t;
349  std::array< std::size_t, sizeof...(XIndexTypeS) > leading_idx = {{static_cast< size_t >(idx)...}};
350  index_type tmp;
351  for(std::size_t i = 0; i < RANK; i++)
352  {
353  tmp[i] = 0;
354  }
355  for(std::size_t i = 0; i < leading_idx.size(); i++)
356  {
357  tmp[i] = leading_idx[i];
358  }
359  std::size_t offset = MHO_NDArrayMath::OffsetFromStrideIndex< RANK >(&(fStrides[0]), &(tmp[0]));
360  return MHO_NDArrayView< XValueType, RANK - (sizeof...(XIndexTypeS)) >(&(fData[offset]), &(fDims[nfixed_t]),
361  &(fStrides[nfixed_t]));
362  }
363 
365 
375  template< typename... XIndexTypeS >
376  typename std::enable_if< (sizeof...(XIndexTypeS) == RANK),
377  MHO_NDArrayView< XValueType, count_instances_of_type< const char*, sizeof...(XIndexTypeS) - 1,
378  XIndexTypeS... >::value > >::type
379  SliceView(XIndexTypeS... idx)
380  {
381  constexpr typename std::integral_constant<
382  std::size_t, count_instances_of_type< const char*, sizeof...(XIndexTypeS) - 1, XIndexTypeS... >::value >
383  nfree_t;
384 
385  class index_filler
386  {
387  public:
388  index_filler()
389  {
390  for(std::size_t i = 0; i < RANK; i++)
391  {
392  full_idx[i] = 0;
393  }
394  fixed_idx.clear();
395  free_idx.clear();
396  }
397 
398  ~index_filler(){};
399 
400  std::array< std::size_t, RANK > full_idx; //list the index values of the start of the slice
401  std::vector< std::size_t > fixed_idx; //list the indexes which are fixed
402  std::vector< std::size_t > free_idx; //list the indexs which are free to vary
403 
404  //placeholder type sets index to zero
405  void operator()(std::size_t i, const char* )
406  {
407  full_idx[i] = 0;
408  free_idx.push_back(i);
409  }
410 
411  //index types pass along their value
412  void operator()(std::size_t i, std::size_t value)
413  {
414  full_idx[i] = value;
415  fixed_idx.push_back(i);
416  }
417 
418  //make sure the indexes are listed in increasing order
419  void reorder()
420  {
421  std::sort(free_idx.begin(), free_idx.end());
422  std::sort(fixed_idx.begin(), fixed_idx.end()); //make sure they are in increasing order
423  }
424  };
425 
426  index_filler filler;
427  std::tuple< XIndexTypeS... > input_idx = std::make_tuple(idx...);
428  indexed_tuple_visit< RANK >::visit(input_idx, filler);
429  filler.reorder();
430 
431  std::size_t offset = MHO_NDArrayMath::OffsetFromRowMajorIndex< RANK >(&(fDims[0]), &(filler.full_idx[0]));
432 
433  std::array< std::size_t, nfree_t > dim;
434  std::array< std::size_t, nfree_t > strides;
435  for(std::size_t i = 0; i < dim.size(); i++)
436  {
437  dim[i] = fDims[filler.free_idx[i]];
438  strides[i] = fStrides[filler.free_idx[i]];
439  }
440  return MHO_NDArrayView< XValueType, nfree_t >(&(fData[offset]), &(dim[0]), &(strides[0]));
441  }
442 
444 
445  //simple in-place compound assignment operators (mult/add/sub)//////////
446 
450  template< typename T >
451  typename std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or
452  std::is_floating_point< T >::value,
453  MHO_NDArrayWrapper& >::type inline
454  operator*=(T aScalar)
455  {
456  std::size_t length = fData.size();
457  for(std::size_t i = 0; i < length; i++)
458  {
459  fData[i] *= aScalar;
460  }
461  return *this;
462  }
463 
467  template< typename T >
468  typename std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or
469  std::is_floating_point< T >::value,
470  MHO_NDArrayWrapper& >::type inline
471  operator+=(T aScalar)
472  {
473  std::size_t length = fData.size();
474  for(std::size_t i = 0; i < length; i++)
475  {
476  fData[i] += aScalar;
477  }
478  return *this;
479  }
480 
484  template< typename T >
485  typename std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or
486  std::is_floating_point< T >::value,
487  MHO_NDArrayWrapper& >::type inline
488  operator-=(T aScalar)
489  {
490  std::size_t length = fData.size();
491  for(std::size_t i = 0; i < length; i++)
492  {
493  fData[i] -= aScalar;
494  }
495  return *this;
496  }
497 
502  {
503  if(!HaveSameNumberOfElements(this, &anArray))
504  {
505  throw std::out_of_range("MHO_NDArrayWrapper::*= size mismatch.");
506  }
507  std::size_t length = fData.size();
508  for(std::size_t i = 0; i < length; i++)
509  {
510  fData[i] *= anArray.fData[i];
511  }
512  return *this;
513  }
514 
519  {
520  if(!HaveSameNumberOfElements(this, &anArray))
521  {
522  throw std::out_of_range("MHO_NDArrayWrapper::+= size mismatch.");
523  }
524  std::size_t length = fData.size();
525  for(std::size_t i = 0; i < length; i++)
526  {
527  fData[i] += anArray.fData[i];
528  }
529  return *this;
530  }
531 
536  {
537  if(!HaveSameNumberOfElements(this, &anArray))
538  {
539  throw std::out_of_range("MHO_NDArrayWrapper::-= size mismatch.");
540  }
541  std::size_t length = fData.size();
542  for(std::size_t i = 0; i < length; i++)
543  {
544  fData[i] -= anArray.fData[i];
545  }
546  return *this;
547  }
548 
549  bool CheckIndexValidity(const index_type& idx) const
550  {
551  return MHO_NDArrayMath::CheckIndexValidity< RANK >(&(fDims[0]), &(idx[0]));
552  }
553 
554  XValueType& ValueAt(const index_type& idx)
555  {
556  return fData[MHO_NDArrayMath::OffsetFromStrideIndex< RANK >(&(fStrides[0]), &(idx[0]))];
557  }
558 
559  const XValueType& ValueAt(const index_type& idx) const
560  {
561  return fData[MHO_NDArrayMath::OffsetFromStrideIndex< RANK >(&(fStrides[0]), &(idx[0]))];
562  }
563 
564  private:
565  std::vector< XValueType > fData; //used for internally managed data
566  index_type fDims; //size of each dimension
567  index_type fStrides; //strides between elements in each dimension
568 
569  void Construct(XValueType* ptr, const std::size_t* dim)
570  {
571  //default construction (empty)
572  for(std::size_t i = 0; i < RANK; i++)
573  {
574  fDims[i] = 0;
575  fStrides[i] = 0;
576  }
577  if(ptr == nullptr && dim == nullptr)
578  {
579  return;
580  }
581 
582  //dimensions known, so create array but don't fill it
583  if(dim != nullptr)
584  {
585  for(std::size_t i = 0; i < RANK; i++)
586  {
587  fDims[i] = dim[i];
588  }
589  }
590  std::size_t length = MHO_NDArrayMath::TotalArraySize< RANK >(&(fDims[0]));
591  ComputeStrides();
592  fData.resize(length);
593 
594  if(ptr != nullptr) //if given a ptr, copy in data from this location
595  {
596  std::copy(ptr, ptr + length, fData.begin());
597  //std::memcpy(&(fData[0]), ptr, length * sizeof(XValueType));
598  }
599  }
600 
601  void ComputeStrides()
602  {
603  for(std::size_t i = 0; i < RANK; i++)
604  {
605  //stride for elements of this dimension
606  std::size_t stride = 1;
607  std::size_t j = RANK - 1;
608  while(j > i)
609  {
610  stride *= fDims[j];
611  j--;
612  }
613  fStrides[i] = stride;
614  }
615  }
616 
617  //the iterator definitions //////////////////////////////////////////////////
618  public:
621 
624 
625  iterator begin() { return iterator(fData.data(), fData.data(), fData.size()); }
626 
627  iterator end() { return iterator(fData.data(), fData.data() + fData.size(), fData.size()); }
628 
629  iterator iterator_at(std::size_t offset)
630  {
631  return iterator(fData.data(), fData.data() + std::min(offset, fData.size()), fData.size());
632  }
633 
634  const_iterator cbegin() const { return const_iterator(fData.data(), fData.data(), fData.size()); }
635 
636  const_iterator cend() const { return const_iterator(fData.data(), fData.data() + fData.size(), fData.size()); }
637 
638  const_iterator citerator_at(std::size_t offset) const
639  {
640  return const_iterator(fData.data(), fData.data() + std::min(offset, fData.size()), fData.size());
641  }
642 
643  stride_iterator stride_begin(std::size_t stride)
644  {
645  return stride_iterator(fData.data(), fData.data(), fData.size(), stride);
646  }
647 
648  stride_iterator stride_end(std::size_t stride)
649  {
650  return stride_iterator(fData.data(), fData.data() + fData.size(), fData.size(), stride);
651  }
652 
653  stride_iterator stride_iterator_at(std::size_t offset, std::size_t stride)
654  {
655  return stride_iterator(fData.data(), fData.data() + std::min(offset, fData.size()), fData.size(), stride);
656  }
657 
658  const_stride_iterator cstride_begin(std::size_t stride) const
659  {
660  return const_stride_iterator(fData.data(), fData.data(), fData.size(), stride);
661  }
662 
663  const_stride_iterator cstride_end(std::size_t stride) const
664  {
665  return const_stride_iterator(fData.data(), fData.data() + fData.size(), fData.size(), stride);
666  }
667 
668  const_stride_iterator cstride_iterator_at(std::size_t offset, std::size_t stride) const
669  {
670  return const_stride_iterator(fData.data(), fData.data() + std::min(offset, fData.size()), fData.size(), stride);
671  }
672 };
673 
674 } // namespace hops
675 
676 //include the partial specializations for RANK=0 and RANK=1
677 #include "MHO_NDArrayWrapper_0.hh"
678 #include "MHO_NDArrayWrapper_1.hh"
679 
680 namespace hops
681 {
682 
683 //utilities ////////////////////////////////////////////////////////////////////
694 template< class XArrayType1, class XArrayType2 >
695 static bool HaveSameRank(const XArrayType1* , const XArrayType2* )
696 {
697  return (XArrayType1::rank::value == XArrayType2::rank::value);
698 }
699 
710 template< class XArrayType1, class XArrayType2 >
711 static bool HaveSameNumberOfElements(const XArrayType1* arr1, const XArrayType2* arr2)
712 {
713  return (arr1->GetSize() == arr2->GetSize());
714 }
715 
726 template< class XArrayType1, class XArrayType2 >
727 static bool HaveSameDimensions(const XArrayType1* arr1, const XArrayType2* arr2)
728 {
729  std::size_t shape1[XArrayType1::rank::value];
730  std::size_t shape2[XArrayType2::rank::value];
731 
732  if(HaveSameRank(arr1, arr2))
733  {
734  size_t rank = XArrayType1::rank::value;
735  arr1->GetDimensions(shape1);
736  arr2->GetDimensions(shape2);
737 
738  for(std::size_t i = 0; i < rank; i++)
739  {
740  if(shape1[i] != shape2[i])
741  {
742  return false;
743  }
744  }
745  return true;
746  }
747  return false;
748 }
749 
750 } // namespace hops
751 
752 #endif
template meta-programming helper functions, mostly tuple access/modification
Class MHO_BidirectionalConstIterator.
Definition: MHO_BidirectionalIterator.hh:144
Class MHO_BidirectionalConstStrideIterator.
Definition: MHO_BidirectionalStrideIterator.hh:139
Class MHO_BidirectionalIterator.
Definition: MHO_BidirectionalIterator.hh:22
Class MHO_BidirectionalStrideIterator.
Definition: MHO_BidirectionalStrideIterator.hh:22
Class MHO_ExtensibleElement.
Definition: MHO_ExtensibleElement.hh:60
MHO_NDArrayView is a class to represent a view (slice) of a n-dimensional array Thu 13 Aug 2020 02:53...
Definition: MHO_NDArrayView.hh:32
const_iterator cend() const
Definition: MHO_NDArrayView.hh:485
index_type GetDimensionArray() const
get the dimensions/shape of the array as std::array
Definition: MHO_NDArrayView.hh:126
const_iterator cbegin() const
Definition: MHO_NDArrayView.hh:483
Class MHO_NDArrayWrapper.
Definition: MHO_NDArrayWrapper.hh:42
std::size_t GetSize() const
get the total size of the array
Definition: MHO_NDArrayWrapper.hh:119
const_stride_iterator cstride_begin(std::size_t stride) const
Definition: MHO_NDArrayWrapper.hh:658
std::size_t GetRank() const
Getter for the rank (dimensionality) of the array.
Definition: MHO_NDArrayWrapper.hh:112
MHO_NDArrayWrapper()
Definition: MHO_NDArrayWrapper.hh:50
std::enable_if<(sizeof...(XIndexTypeS)==RANK), XValueType & >::type operator()(XIndexTypeS... idx)
access operator, accepts multiple indices (,,...,) but does no bounds checking
Definition: MHO_NDArrayWrapper.hh:197
void GetStrides(std::size_t *strd) const
Getter for strides (along each dimension), fills passed array.
Definition: MHO_NDArrayWrapper.hh:178
std::integral_constant< std::size_t, RANK > rank
Definition: MHO_NDArrayWrapper.hh:46
bool CheckIndexValidity(const index_type &idx) const
Definition: MHO_NDArrayWrapper.hh:549
iterator begin()
Definition: MHO_NDArrayWrapper.hh:625
index_type GetStrideArray() const
Definition: MHO_NDArrayWrapper.hh:186
std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or std::is_floating_point< T >::value, MHO_NDArrayWrapper & >::type operator+=(T aScalar)
operator+= in place addition by a scalar amount
Definition: MHO_NDArrayWrapper.hh:471
MHO_NDArrayWrapper * Clone()
clone functionality - creates a deep copy of this MHO_NDArrayWrapper object.
Definition: MHO_NDArrayWrapper.hh:74
void GetDimensions(std::size_t *dim) const
Getter for dimensions, fills passed array.
Definition: MHO_NDArrayWrapper.hh:133
XValueType * GetData()
access to underlying data pointer (unsafe)
Definition: MHO_NDArrayWrapper.hh:262
MHO_NDArrayWrapper & operator=(const MHO_NDArrayWrapper &rhs)
Definition: MHO_NDArrayWrapper.hh:274
iterator iterator_at(std::size_t offset)
Definition: MHO_NDArrayWrapper.hh:629
MHO_NDArrayWrapper & operator-=(const MHO_NDArrayWrapper &anArray)
operator-= in place point-wise subtraction by another array
Definition: MHO_NDArrayWrapper.hh:535
XValueType value_type
Definition: MHO_NDArrayWrapper.hh:44
const XValueType * GetData() const
Definition: MHO_NDArrayWrapper.hh:264
const_stride_iterator cstride_end(std::size_t stride) const
Definition: MHO_NDArrayWrapper.hh:663
const std::size_t * GetDimensions() const
get the dimensions/shape of the array
Definition: MHO_NDArrayWrapper.hh:126
void CopyFromExternalData(XValueType *ptr, const std::size_t *dim)
set data pointer to externally managed array with associated dimensions
Definition: MHO_NDArrayWrapper.hh:105
std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or std::is_floating_point< T >::value, MHO_NDArrayWrapper & >::type operator-=(T aScalar)
operator+= in place addition by a scalar amount
Definition: MHO_NDArrayWrapper.hh:488
const_iterator cbegin() const
Definition: MHO_NDArrayWrapper.hh:634
std::enable_if<(sizeof...(XIndexTypeS)==RANK), XValueType & >::type at(XIndexTypeS... idx)
at(): same as operator(...) but with bounds checking with bounds checking
Definition: MHO_NDArrayWrapper.hh:224
const_stride_iterator cstride_iterator_at(std::size_t offset, std::size_t stride) const
Definition: MHO_NDArrayWrapper.hh:668
virtual void Resize(const std::size_t *dim)
Destroys contents and resizes using passed dimensions.
Definition: MHO_NDArrayWrapper.hh:83
XValueType & ValueAt(const index_type &idx)
Definition: MHO_NDArrayWrapper.hh:554
MHO_NDArrayWrapper(const MHO_NDArrayWrapper &obj)
Definition: MHO_NDArrayWrapper.hh:59
const std::size_t * GetStrides() const
Getter for element strides (along each dimension)
Definition: MHO_NDArrayWrapper.hh:171
void SetArray(const XValueType &obj)
set all elements in the array to a certain value
Definition: MHO_NDArrayWrapper.hh:287
void ZeroArray()
set all elements in the array to zero
Definition: MHO_NDArrayWrapper.hh:298
std::enable_if<(sizeof...(XDimSizeTypeS)==RANK), void >::type Resize(XDimSizeTypeS... dim)
Resize function that destroys contents and resizes according to dimension arguments.
Definition: MHO_NDArrayWrapper.hh:93
virtual void Copy(const MHO_NDArrayView< XValueType, RANK > &rhs)
Definition: MHO_NDArrayWrapper.hh:311
std::enable_if<(sizeof...(XIndexTypeS)==RANK), const XValueType & >::type operator()(XIndexTypeS... idx) const
const reference access operator, accepts multiple indices (,,...,) but does no bounds checking
Definition: MHO_NDArrayWrapper.hh:211
stride_iterator stride_iterator_at(std::size_t offset, std::size_t stride)
Definition: MHO_NDArrayWrapper.hh:653
stride_iterator stride_begin(std::size_t stride)
Definition: MHO_NDArrayWrapper.hh:643
MHO_NDArrayWrapper(XValueType *ptr, const std::size_t *dim)
Definition: MHO_NDArrayWrapper.hh:56
const XValueType & ValueAt(const index_type &idx) const
Definition: MHO_NDArrayWrapper.hh:559
const_iterator cend() const
Definition: MHO_NDArrayWrapper.hh:636
const_iterator citerator_at(std::size_t offset) const
Definition: MHO_NDArrayWrapper.hh:638
MHO_NDArrayWrapper & operator*=(const MHO_NDArrayWrapper &anArray)
operator*= in place point-wise multiplication by another array
Definition: MHO_NDArrayWrapper.hh:501
std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or std::is_floating_point< T >::value, MHO_NDArrayWrapper & >::type operator*=(T aScalar)
operator*= in place multiplication by a scalar factor
Definition: MHO_NDArrayWrapper.hh:454
std::size_t GetDimension(std::size_t idx) const
Getter for dimension.
Definition: MHO_NDArrayWrapper.hh:154
MHO_NDArrayWrapper & operator+=(const MHO_NDArrayWrapper &anArray)
operator+= in place point-wise addition by another array
Definition: MHO_NDArrayWrapper.hh:518
std::enable_if<(sizeof...(XIndexTypeS)==RANK), MHO_NDArrayView< XValueType, count_instances_of_type< const char *, sizeof...(XIndexTypeS) - 1, XIndexTypeS... >::value > >::type SliceView(XIndexTypeS... idx)
creates a slice-view of the array (given n < RANK indexes), return the remaining chunk of the array w...
Definition: MHO_NDArrayWrapper.hh:379
stride_iterator stride_end(std::size_t stride)
Definition: MHO_NDArrayWrapper.hh:648
std::enable_if<(sizeof...(XIndexTypeS)==RANK), const XValueType & >::type at(XIndexTypeS... idx) const
at(): same as const operator(...) but with bounds checking with bounds checking
Definition: MHO_NDArrayWrapper.hh:245
index_type GetDimensionArray() const
Getter for dimension array.
Definition: MHO_NDArrayWrapper.hh:146
std::size_t GetStride(std::size_t idx) const
Definition: MHO_NDArrayWrapper.hh:188
virtual void Copy(const MHO_NDArrayWrapper &rhs)
Definition: MHO_NDArrayWrapper.hh:301
XValueType & operator[](std::size_t i)
Definition: MHO_NDArrayWrapper.hh:269
MHO_NDArrayWrapper(const std::size_t *dim)
Definition: MHO_NDArrayWrapper.hh:53
index_type GetIndicesForOffset(std::size_t offset)
invert (memory) offset into array to indexes of the associated element
Definition: MHO_NDArrayWrapper.hh:329
std::size_t GetOffsetForIndices(const std::size_t *index)
compute (memory) offset into array from a set of indexes
Definition: MHO_NDArrayWrapper.hh:321
const XValueType & operator[](std::size_t i) const
Definition: MHO_NDArrayWrapper.hh:271
std::enable_if<(sizeof...(XIndexTypeS)< RANK), MHO_NDArrayView< XValueType, RANK -(sizeof...(XIndexTypeS)) > >::type SubView(XIndexTypeS... idx)
creates a sub-view of the array (given n < RANK leading indexes), return the remaining chunk of the a...
Definition: MHO_NDArrayWrapper.hh:346
virtual ~MHO_NDArrayWrapper()
Definition: MHO_NDArrayWrapper.hh:67
iterator end()
Definition: MHO_NDArrayWrapper.hh:627
std::array< std::size_t, RANK > index_type
Definition: MHO_NDArrayWrapper.hh:45
#define min(a, b)
Definition: max555.c:9
Definition: MHO_AdhocFlagging.hh:18
Class count_instances_of_type - utility to count the instances of a particular type in a parameter pa...
Definition: MHO_Meta.hh:98
static void visit(XTupleType &tup, XFunctorType &functor)
Applies a functor to all elements of an XTupleType tuple and recursively visits the next type.
Definition: MHO_Meta.hh:193
Definition: vex.h:175