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  fTmp = {{static_cast< size_t >(dim)...}}; //convert the arguments to an array
96  Resize(&(fTmp[0]));
97  }
98 
105  void SetExternalData(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  fTmp = {{static_cast< size_t >(idx)...}};
200  return ValueAt(fTmp);
201  }
202 
209  template< typename... XIndexTypeS >
210  typename std::enable_if< (sizeof...(XIndexTypeS) == RANK), const XValueType& >::type
211  operator()(XIndexTypeS... idx) const
212  {
213  fTmp = {{static_cast< size_t >(idx)...}};
214  return ValueAt(fTmp);
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  fTmp = {{static_cast< size_t >(idx)...}};
228  if(CheckIndexValidity(fTmp))
229  {
230  return ValueAt(fTmp);
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  fTmp = {{static_cast< size_t >(idx)...}};
249  if(CheckIndexValidity(fTmp))
250  {
251  return ValueAt(fTmp);
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[0]); };
263 
264  const XValueType* GetData() const { return &(fData[0]); };
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::memset(&(fData[0]), 0, (fData.size()) * sizeof(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 
336 
344  template< typename... XIndexTypeS >
345  typename std::enable_if< (sizeof...(XIndexTypeS) < RANK),
346  MHO_NDArrayView< XValueType, RANK - (sizeof...(XIndexTypeS)) > >::type
347  SubView(XIndexTypeS... idx)
348  {
349  constexpr typename std::integral_constant< std::size_t, sizeof...(XIndexTypeS) > nfixed_t;
350  std::array< std::size_t, sizeof...(XIndexTypeS) > leading_idx = {{static_cast< size_t >(idx)...}};
351  for(std::size_t i = 0; i < RANK; i++)
352  {
353  fTmp[i] = 0;
354  }
355  for(std::size_t i = 0; i < leading_idx.size(); i++)
356  {
357  fTmp[i] = leading_idx[i];
358  }
359  std::size_t offset = MHO_NDArrayMath::OffsetFromStrideIndex< RANK >(&(fStrides[0]), &(fTmp[0]));
360  return MHO_NDArrayView< XValueType, RANK - (sizeof...(XIndexTypeS)) >(&(fData[offset]), &(fDims[nfixed_t]),
361  &(fStrides[nfixed_t]));
362  }
363 
365 
366 
367 
377  template< typename... XIndexTypeS >
378  typename std::enable_if< (sizeof...(XIndexTypeS) == RANK),
379  MHO_NDArrayView< XValueType, count_instances_of_type< const char*, sizeof...(XIndexTypeS) - 1,
380  XIndexTypeS... >::value > >::type
381  SliceView(XIndexTypeS... idx)
382  {
383  constexpr typename std::integral_constant<
384  std::size_t, count_instances_of_type< const char*, sizeof...(XIndexTypeS) - 1, XIndexTypeS... >::value >
385  nfree_t;
386 
387  class index_filler
388  {
389  public:
390  index_filler()
391  {
392  for(std::size_t i = 0; i < RANK; i++)
393  {
394  full_idx[i] = 0;
395  }
396  fixed_idx.clear();
397  free_idx.clear();
398  }
399 
400  ~index_filler(){};
401 
402  std::array< std::size_t, RANK > full_idx; //list the index values of the start of the slice
403  std::vector< std::size_t > fixed_idx; //list the indexes which are fixed
404  std::vector< std::size_t > free_idx; //list the indexs which are free to vary
405 
406  //placeholder type sets index to zero
407  void operator()(std::size_t i, const char* )
408  {
409  full_idx[i] = 0;
410  free_idx.push_back(i);
411  }
412 
413  //index types pass along their value
414  void operator()(std::size_t i, std::size_t value)
415  {
416  full_idx[i] = value;
417  fixed_idx.push_back(i);
418  }
419 
420  //make sure the indexes are listed in increasing order
421  void reorder()
422  {
423  std::sort(free_idx.begin(), free_idx.end());
424  std::sort(fixed_idx.begin(), fixed_idx.end()); //make sure they are in increasing order
425  }
426  };
427 
428  index_filler filler;
429  std::tuple< XIndexTypeS... > input_idx = std::make_tuple(idx...);
430  indexed_tuple_visit< RANK >::visit(input_idx, filler);
431  filler.reorder();
432 
433  std::size_t offset = MHO_NDArrayMath::OffsetFromRowMajorIndex< RANK >(&(fDims[0]), &(filler.full_idx[0]));
434 
435  std::array< std::size_t, nfree_t > dim;
436  std::array< std::size_t, nfree_t > strides;
437  for(std::size_t i = 0; i < dim.size(); i++)
438  {
439  dim[i] = fDims[filler.free_idx[i]];
440  strides[i] = fStrides[filler.free_idx[i]];
441  }
442  return MHO_NDArrayView< XValueType, nfree_t >(&(fData[offset]), &(dim[0]), &(strides[0]));
443  }
444 
446 
447  //simple in-place compound assignment operators (mult/add/sub)//////////
448 
452  template< typename T >
453  typename std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or
454  std::is_floating_point< T >::value,
455  MHO_NDArrayWrapper& >::type inline
456  operator*=(T aScalar)
457  {
458  std::size_t length = fData.size();
459  for(std::size_t i = 0; i < length; i++)
460  {
461  fData[i] *= aScalar;
462  }
463  return *this;
464  }
465 
469  template< typename T >
470  typename std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or
471  std::is_floating_point< T >::value,
472  MHO_NDArrayWrapper& >::type inline
473  operator+=(T aScalar)
474  {
475  std::size_t length = fData.size();
476  for(std::size_t i = 0; i < length; i++)
477  {
478  fData[i] += aScalar;
479  }
480  return *this;
481  }
482 
486  template< typename T >
487  typename std::enable_if< std::is_same< XValueType, T >::value or std::is_integral< T >::value or
488  std::is_floating_point< T >::value,
489  MHO_NDArrayWrapper& >::type inline
490  operator-=(T aScalar)
491  {
492  std::size_t length = fData.size();
493  for(std::size_t i = 0; i < length; i++)
494  {
495  fData[i] -= aScalar;
496  }
497  return *this;
498  }
499 
504  {
505  if(!HaveSameNumberOfElements(this, &anArray))
506  {
507  throw std::out_of_range("MHO_NDArrayWrapper::*= size mismatch.");
508  }
509  std::size_t length = fData.size();
510  for(std::size_t i = 0; i < length; i++)
511  {
512  fData[i] *= anArray.fData[i];
513  }
514  return *this;
515  }
516 
521  {
522  if(!HaveSameNumberOfElements(this, &anArray))
523  {
524  throw std::out_of_range("MHO_NDArrayWrapper::+= size mismatch.");
525  }
526  std::size_t length = fData.size();
527  for(std::size_t i = 0; i < length; i++)
528  {
529  fData[i] += anArray.fData[i];
530  }
531  return *this;
532 
533  }
534 
539  {
540  if(!HaveSameNumberOfElements(this, &anArray))
541  {
542  throw std::out_of_range("MHO_NDArrayWrapper::-= size mismatch.");
543  }
544  std::size_t length = fData.size();
545  for(std::size_t i = 0; i < length; i++)
546  {
547  fData[i] -= anArray.fData[i];
548  }
549  return *this;
550  }
551 
552  bool CheckIndexValidity(const index_type& idx) const
553  {
554  return MHO_NDArrayMath::CheckIndexValidity< RANK >(&(fDims[0]), &(idx[0]));
555  }
556 
557  XValueType& ValueAt(const index_type& idx)
558  {
559  return fData[MHO_NDArrayMath::OffsetFromStrideIndex< RANK >(&(fStrides[0]), &(idx[0]))];
560  }
561 
562  const XValueType& ValueAt(const index_type& idx) const
563  {
564  return fData[MHO_NDArrayMath::OffsetFromStrideIndex< RANK >(&(fStrides[0]), &(idx[0]))];
565  }
566 
567  private:
568  std::vector< XValueType > fData; //used for internally managed data
569  index_type fDims; //size of each dimension
570  index_type fStrides; //strides between elements in each dimension
571  mutable index_type fTmp; //temp index workspace
572 
573  void Construct(XValueType* ptr, const std::size_t* dim)
574  {
575  //default construction (empty)
576  for(std::size_t i = 0; i < RANK; i++)
577  {
578  fDims[i] = 0;
579  fStrides[0] = 0;
580  }
581  if(ptr == nullptr && dim == nullptr)
582  {
583  return;
584  }
585 
586  //dimensions known, so create array but don't fill it
587  if(dim != nullptr)
588  {
589  for(std::size_t i = 0; i < RANK; i++)
590  {
591  fDims[i] = dim[i];
592  }
593  }
594  std::size_t length = MHO_NDArrayMath::TotalArraySize< RANK >(&(fDims[0]));
595  ComputeStrides();
596  fData.resize(length);
597 
598  if(ptr != nullptr) //if given a ptr, copy in data from this location
599  {
600  std::memcpy(&(fData[0]), ptr, length * sizeof(XValueType));
601  }
602  }
603 
604  void ComputeStrides()
605  {
606  for(std::size_t i = 0; i < RANK; i++)
607  {
608  //stride for elements of this dimension
609  std::size_t stride = 1;
610  std::size_t j = RANK - 1;
611  while(j > i)
612  {
613  stride *= fDims[j];
614  j--;
615  }
616  fStrides[i] = stride;
617  }
618  }
619 
620  //the iterator definitions //////////////////////////////////////////////////
621  public:
624 
627 
628  iterator begin() { return iterator(&(fData[0]), &(fData[0]), fData.size()); }
629 
630  iterator end() { return iterator(&(fData[0]), &(fData[0]) + fData.size(), fData.size()); }
631 
632  iterator iterator_at(std::size_t offset)
633  {
634  return iterator(&(fData[0]), &(fData[0]) + std::min(offset, fData.size()), fData.size());
635  }
636 
637  const_iterator cbegin() const { return const_iterator(&(fData[0]), &(fData[0]), fData.size()); }
638 
639  const_iterator cend() const { return const_iterator(&(fData[0]), &(fData[0]) + fData.size(), fData.size()); }
640 
641  const_iterator citerator_at(std::size_t offset) const
642  {
643  return const_iterator(&(fData[0]), &(fData[0]) + std::min(offset, fData.size()), fData.size());
644  }
645 
646  stride_iterator stride_begin(std::size_t stride)
647  {
648  return stride_iterator(&(fData[0]), &(fData[0]), fData.size(), stride);
649  }
650 
651  stride_iterator stride_end(std::size_t stride)
652  {
653  return stride_iterator(&(fData[0]), &(fData[0]) + fData.size(), fData.size(), stride);
654  }
655 
656  stride_iterator stride_iterator_at(std::size_t offset, std::size_t stride)
657  {
658  return stride_iterator(&(fData[0]), &(fData[0]) + std::min(offset, fData.size()), fData.size(), stride);
659  }
660 
661  const_stride_iterator cstride_begin(std::size_t stride) const
662  {
663  return const_stride_iterator(&(fData[0]), &(fData[0]), fData.size(), stride);
664  }
665 
666  const_stride_iterator cstride_end(std::size_t stride) const
667  {
668  return const_stride_iterator(&(fData[0]), &(fData[0]) + fData.size(), fData.size(), stride);
669  }
670 
671  const_stride_iterator cstride_iterator_at(std::size_t offset, std::size_t stride) const
672  {
673  return const_stride_iterator(&(fData[0]), &(fData[0]) + std::min(offset, fData.size()), fData.size(), stride);
674  }
675 };
676 
677 } // namespace hops
678 
679 //include the partial specializations for RANK=0 and RANK=1
680 #include "MHO_NDArrayWrapper_0.hh"
681 #include "MHO_NDArrayWrapper_1.hh"
682 
683 namespace hops
684 {
685 
686 //utilities ////////////////////////////////////////////////////////////////////
697 template< class XArrayType1, class XArrayType2 >
698 static bool HaveSameRank(const XArrayType1* , const XArrayType2* )
699 {
700  return (XArrayType1::rank::value == XArrayType2::rank::value);
701 }
702 
713 template< class XArrayType1, class XArrayType2 >
714 static bool HaveSameNumberOfElements(const XArrayType1* arr1, const XArrayType2* arr2)
715 {
716  return (arr1->GetSize() == arr2->GetSize());
717 }
718 
729 template< class XArrayType1, class XArrayType2 >
730 static bool HaveSameDimensions(const XArrayType1* arr1, const XArrayType2* arr2)
731 {
732  std::size_t shape1[XArrayType1::rank::value];
733  std::size_t shape2[XArrayType2::rank::value];
734 
735  if(HaveSameRank(arr1, arr2))
736  {
737  size_t rank = XArrayType1::rank::value;
738  arr1->GetDimensions(shape1);
739  arr2->GetDimensions(shape2);
740 
741  for(std::size_t i = 0; i < rank; i++)
742  {
743  if(shape1[i] != shape2[i])
744  {
745  return false;
746  }
747  }
748  return true;
749  }
750  return false;
751 }
752 
753 } // namespace hops
754 
755 #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:33
const_iterator cend() const
Definition: MHO_NDArrayView.hh:487
index_type GetDimensionArray() const
get the dimensions/shape of the array as std::array
Definition: MHO_NDArrayView.hh:127
const_iterator cbegin() const
Definition: MHO_NDArrayView.hh:485
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:661
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:552
iterator begin()
Definition: MHO_NDArrayWrapper.hh:628
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:473
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:632
MHO_NDArrayWrapper & operator-=(const MHO_NDArrayWrapper &anArray)
operator-= in place point-wise subtraction by another array
Definition: MHO_NDArrayWrapper.hh:538
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:666
const std::size_t * GetDimensions() const
get the dimensions/shape of the array
Definition: MHO_NDArrayWrapper.hh:126
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:490
const_iterator cbegin() const
Definition: MHO_NDArrayWrapper.hh:637
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:671
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:557
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:656
stride_iterator stride_begin(std::size_t stride)
Definition: MHO_NDArrayWrapper.hh:646
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:562
const_iterator cend() const
Definition: MHO_NDArrayWrapper.hh:639
const_iterator citerator_at(std::size_t offset) const
Definition: MHO_NDArrayWrapper.hh:641
MHO_NDArrayWrapper & operator*=(const MHO_NDArrayWrapper &anArray)
operator*= in place point-wise multiplication by another array
Definition: MHO_NDArrayWrapper.hh:503
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:456
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:520
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:381
stride_iterator stride_end(std::size_t stride)
Definition: MHO_NDArrayWrapper.hh:651
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:347
virtual ~MHO_NDArrayWrapper()
Definition: MHO_NDArrayWrapper.hh:67
void SetExternalData(XValueType *ptr, const std::size_t *dim)
set data pointer to externally managed array with associated dimensions
Definition: MHO_NDArrayWrapper.hh:105
iterator end()
Definition: MHO_NDArrayWrapper.hh:630
std::array< std::size_t, RANK > index_type
Definition: MHO_NDArrayWrapper.hh:45
#define min(a, b)
Definition: max555.c:9
Definition: MHO_ChannelLabeler.hh:17
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