DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
utlNDArray.h
Go to the documentation of this file.
1 
10 #ifndef __utlNDArray_h
11 #define __utlNDArray_h
12 
13 #include <numeric>
14 
15 #include "utlSTDHeaders.h"
16 #include "utlCore.h"
17 #include "utlCoreMacro.h"
18 #include "utlBlas.h"
19 #include "utlExpression.h"
20 #include "utlTypeinfo.h"
21 
22 #include "utlFunctors.h"
23 #include "utlNDArrayFunctions.h"
24 
25 namespace utl
26 {
30 #define __utl_ndarray_alloc_blah(shape) \
31 do { \
32  for ( int i = 0; i < this->Dimension; ++i ) \
33  this->m_Shape[i] = shape[i]; \
34  this->ComputeOffSetTable(); \
35  SizeType size = this->GetSize(); \
36  this->m_Data = (size>0) ? (new T[size]) : NULL; \
37  this->m_IsShared = false; \
38 } while (false)
39 
40 
41 template <class T, unsigned int Dim> class NDArray;
42 template <class T, unsigned int Dim> class NDArrayBase;
43 
44 template<class T> using Vector = NDArray<T,1>;
45 template<class T> using Matrix = NDArray<T,2>;
46 
47 // template <class T, unsigned int Dim>
48 // T InnerProduct ( const NDArrayBase<T,Dim>& v1, const NDArrayBase<T,Dim>& v2 );
49 
50 
60 template < class T, unsigned int Dim >
61 class NDArray : public NDArrayBase<T,Dim>
62 {
63 public:
64  typedef NDArray Self;
66 
67 
68  typedef typename Superclass::ValueType ValueType;
70 
71  typedef typename Superclass::SizeType SizeType;
72  typedef typename Superclass::ShapeType ShapeType;
73 
74  typedef typename Superclass::Iterator Iterator;
76  typedef typename Superclass::Pointer Pointer;
78  typedef typename Superclass::Reference Reference;
80 
83 
84  using Superclass::operator=;
85 
86 public:
87  NDArray() : Superclass() {}
88 
89  explicit NDArray(const ShapeType& shape) : Superclass(shape) { }
90 
91  NDArray(const NDArray<T,Dim>& vec) : Superclass(vec) { }
92 
94  {
95  operator=(std::move(vec));
96  }
97 
98  template<typename EType>
99  NDArray(const Expr<EType, typename EType::ValueType>& expr) : Superclass(expr) { }
100 
106  NDArray(const T* vec, const ShapeType& shape) : Superclass(vec,shape) { }
107 
111  NDArray(const ShapeType& shape, const T r) : Superclass(shape, r) { }
112 
113  template< typename TValue >
114  NDArray(const NDArray<TValue, Dim> & r) : Superclass(r) { }
115 
117  {
119  return *this;
120  }
121 
123  {
124  if ( this != &r )
125  {
126  this->Clear();
127  this->Swap(r);
128  }
129  return *this;
130  }
131 };
132 
133 
141 template < class T, unsigned int Dim >
142 class NDArrayBase : public Expr<NDArrayBase<T, Dim>, T >
143 {
144  static_assert(::std::is_scalar<T>::value
145  || ::std::is_same<T,std::complex<double>>::value
146  || ::std::is_same<T,std::complex<float>>::value, "NDArrayBase<T,Dim>: T must be a scalar or std::complex<double> or std::complex<float>");
147 
148 public:
149 
151  typedef NDArrayBase Self;
153 
154  typedef typename Superclass::SizeType SizeType;
156 
157 
158  // typedef SizeType ShapeType[Dim];
159 
160  enum { Dimension = Dim };
161  // static constexpr SizeType Dimension = Dim;
162  static constexpr SizeType SubDimension = Dim>1?Dim-1:1;
163 
164  typedef T ValueType;
166 
168  typedef ValueType* Iterator;
169 
171  typedef const ValueType* ConstIterator;
172 
174  typedef ValueType* Pointer;
175  typedef const ValueType* ConstPointer;
176 
178  typedef ValueType & Reference;
179  typedef const ValueType & ConstReference;
180 
181  class ConstReverseIterator;
182 
187  {
188  public:
189  explicit ReverseIterator(Iterator i):m_Iterator(i) {}
190  Iterator operator++() { return --m_Iterator; }
191  Iterator operator++(int) { return m_Iterator--; }
192  Iterator operator--() { return ++m_Iterator; }
193  Iterator operator--(int) { return m_Iterator++; }
194  Iterator operator->() const { return ( m_Iterator - 1 ); }
195  ValueType & operator*() const { return *( m_Iterator - 1 ); }
196  bool operator!=(const ReverseIterator & rit) const { return m_Iterator != rit.m_Iterator; }
197  bool operator==(const ReverseIterator & rit) const { return m_Iterator == rit.m_Iterator; }
198 
199  private:
200  Iterator m_Iterator;
201  friend class ConstReverseIterator;
202  };
203 
208  {
209  public:
210  explicit ConstReverseIterator(ConstIterator i):m_Iterator(i) {}
211  ConstReverseIterator(const ReverseIterator & rit) { m_Iterator = rit.m_Iterator; }
212  ConstIterator operator++() { return --m_Iterator; }
213  ConstIterator operator++(int) { return m_Iterator--; }
214  ConstIterator operator--() { return ++m_Iterator; }
215  ConstIterator operator--(int) { return m_Iterator++; }
216  ConstIterator operator->() const { return ( m_Iterator - 1 ); }
217  const ValueType & operator*() const { return *( m_Iterator - 1 ); }
218  bool operator!=(const ConstReverseIterator & rit) const { return m_Iterator != rit.m_Iterator; }
219  bool operator==(const ConstReverseIterator & rit) const { return m_Iterator == rit.m_Iterator; }
220 
221  private:
222  ConstIterator m_Iterator;
223  };
224 
229  NDArrayBase() : m_IsShared(false), m_Data(NULL)
230  {
231  for ( int i = 0; i < Dimension; ++i )
232  m_Shape[i]=0, m_OffSetTable[i]=0;
233  }
234 
235  explicit NDArrayBase(const ShapeType& shape) : m_IsShared(false), m_Data(NULL)
236  {
238  }
239 
240  NDArrayBase(const NDArrayBase<T,Dim>& vec) : m_IsShared(false), m_Data(NULL)
241  {
242  for ( int i = 0; i < Dimension; ++i )
243  m_Shape[i]=0, m_OffSetTable[i]=0;
244  operator=(vec);
245  }
247  {
248  // NOTE: although the type of vec is an rvalue reference,
249  // vec itself is an lvalue, since it is a named object.
250  // In order to ensure that the move assignment is used, we have to explicitly specify std::move(vec).
251  operator=(std::move(vec));
252  }
253 
254  template<typename EType>
256  {
257  for ( int i = 0; i < Dimension; ++i )
258  m_Shape[i]=0, m_OffSetTable[i]=0;
259  operator=(expr);
260  }
261 
267  NDArrayBase(const T* vec, const ShapeType& shape) : m_IsShared(false), m_Data(NULL)
268  {
270  utl::cblas_copy<T>(this->Size(), vec, 1, m_Data, 1);
271  }
272 
276  NDArrayBase(const ShapeType& shape, const T r) : m_IsShared(false), m_Data(NULL)
277  {
279  Fill(r);
280  }
281 
282  template< typename TValue >
284  {
285  for ( int i = 0; i < Dimension; ++i )
286  m_Shape[i]=0, m_OffSetTable[i]=0;
287  operator=(r);
288  }
289 
290 
303  { Clear(); }
304 
305  void Clear()
306  {
307  ClearData();
308  ClearShape();
309  m_Data = NULL;
310  m_IsShared = false;
311  }
312 
313  UTL_ALWAYS_INLINE T Eval( int i ) const
314  {
315  return m_Data[i];
316  }
317 
321  UTL_ALWAYS_INLINE SizeType Size() const
322  {
323  return Dimension==0?1:m_OffSetTable[0];
324  }
325  UTL_ALWAYS_INLINE SizeType GetSize() const
326  {
327  return Dimension==0?1:m_OffSetTable[0];
328  }
329 
330  UTL_ALWAYS_INLINE const ShapeType GetShape() const
331  {
332  return m_Shape;
333  }
334 
335  UTL_ALWAYS_INLINE static constexpr SizeType GetDimension()
336  { return Dimension; }
337 
338  UTL_ALWAYS_INLINE SizeType GetOffset(const ShapeType& shapeIndex) const
339  {
340  SizeType index = 0;
341  for ( int i = 0; i < Dimension-1; ++i )
342  index += shapeIndex[i]*m_OffSetTable[i+1];
343  index += shapeIndex[Dimension-1];
344  return index;
345  }
346 
347  UTL_ALWAYS_INLINE void GetIndex(const SizeType offset, SizeType index[Dimension]) const
348  {
349  int nn = offset;
350  for ( int i = 1; i < Dim; i++ )
351  {
352  index[i-1] = nn / m_OffSetTable[i] ;
353  nn -= index[i-1] * m_OffSetTable[i];
354  }
355  index[Dimension-1] = nn;
356  }
357 
358  const SizeType* GetOffSetTable() const
359  {
360  return m_OffSetTable;
361  }
362 
363  bool GetIsShared() const
364  {
365  return m_IsShared;
366  }
367 
368 
369 #define __Array_Saver_Expr(saver, saverReal) \
370 template<typename EType> \
371 UTL_ALWAYS_INLINE NDArrayBase<T,Dim>& operator saver (const Expr<EType, typename EType::ValueType>& src){ \
372  auto srcDim = Expr<EType, typename EType::ValueType>::GetDimension(); \
373  utlSAGlobalException(srcDim>0 && srcDim!=Dimension) \
374  (srcDim)(Dimension).msg("the expression has a difference size"); \
375  const EType &r = src.ConstRef(); \
376  const ShapeType rShape = r.GetShape(); \
377  if (srcDim>0) \
378  this->ReSize(rShape); \
379  for( int i=0; i < this->Size(); ++i ) \
380  this->m_Data[i] saverReal r.Eval(i); \
381  return *this; \
382 }
383 
384 
389  __Array_Saver_Expr(%=, *=)
390  __Array_Saver_Expr(/=, /=)
391 
392 #define __Array_Saver_Scalar(saver) \
393 inline NDArrayBase<T,Dim>& operator saver (const T val){ \
394  for (Iterator p = Begin(); p!= End(); ++p) \
395  *p saver val; \
396  return *this; \
397 }
398 
402  // these three operators use blas and mkl
403  // __Array_Saver_Scalar(=)
404  // __Array_Saver_Scalar(*=)
405  // __Array_Saver_Scalar(/=)
406 
407  NDArrayBase<T,Dim>& operator=(const NDArrayBase<T,Dim> & r)
408  {
409  // std::cout << "copy matrix" << std::endl << std::flush;
410  if ( this != &r )
411  {
412  this->ReSize(r.GetShape());
413  utl::cblas_copy(r.Size(), r.Begin(), 1, m_Data, 1);
414  }
415  return *this;
416  }
417 
419  {
420  if ( this != &r )
421  {
422  this->Clear();
423  this->Swap(r);
424  }
425  return *this;
426  }
427 
429  template< typename TValueType >
431  {
432  this->ReSize(r.GetShape());
434  Iterator i = this->Begin();
435  while ( i != this->End() )
436  *i++ = static_cast< T >( *input++ );
437  return *this;
438  }
439 
440  NDArrayBase<T,Dim>& operator=(const std::initializer_list<T>& r)
441  {
442  if (r.size()==Size())
443  utl::cblas_copy(Size(), r.begin(), 1, m_Data, 1);
444  else if (Dim==1)
445  {
446  SizeType shape[Dim];
447  shape[0] = r.size();
448  ReSize(shape);
449  utl::cblas_copy(Size(), r.begin(), 1, m_Data, 1);
450  }
451  else
452  utlException(Dim!=1, "should have only 1 dimension, or have the same size.");
453  return *this;
454  }
455 
464  NDArrayBase<T,Dim> & operator=(const std::vector<T>& r)
465  {
466  if (r.size()==Size())
467  utl::cblas_copy(Size(), r.data(), 1, m_Data, 1);
468  else if (Dim==1)
469  {
470  SizeType shape[Dim];
471  shape[0] = r.size();
472  ReSize(shape);
473  utl::cblas_copy(Size(), r.data(), 1, m_Data, 1);
474  }
475  else
476  utlException(Dim!=1, "should have only 1 dimension, or have the same size.");
477  return *this;
478  }
479 
481  { Fill(r); return *this; }
482 
486  bool operator==(const NDArrayBase<T,Dim> & r) const
487  {
488  if (!IsSameShape(r))
489  return false;
490  if (r.m_Data==m_Data)
491  return true;
492  ConstIterator i = this->Begin();
493  ConstIterator j = r.Begin();
494 
495  while ( i != this->End() )
496  {
497  if ( *i != *j )
498  return false;
499  ++j;
500  ++i;
501  }
502  return true;
503  }
504 
505  bool operator!=(const NDArrayBase<T,Dim> & r) const
506  { return !operator==(r); }
507 
508  bool IsEqual(const NDArrayBase<T,Dim>& r, const double eps) const
509  {
510  if (!IsSameShape(r))
511  return false;
512  if (r.m_Data==m_Data)
513  return true;
514  ConstIterator i = this->Begin();
515  ConstIterator j = r.Begin();
516 
517  while ( i != this->End() )
518  {
519  if ( std::abs(*i - *j) > eps )
520  return false;
521  ++j;
522  ++i;
523  }
524  return true;
525  }
526 
527  bool IsSameValues(const NDArrayBase<T,Dim>& r, const double eps) const
528  {
529  if (!IsSameSize(r))
530  return false;
531  if (r.m_Data==m_Data)
532  return true;
533  ConstIterator i = this->Begin();
534  ConstIterator j = r.Begin();
535 
536  while ( i != this->End() )
537  {
538  if ( std::abs(*i - *j) > eps )
539  return false;
540  ++j;
541  ++i;
542  }
543  return true;
544  }
545 
550  UTL_ALWAYS_INLINE Reference operator[](short index) { return m_Data[index]; }
551  UTL_ALWAYS_INLINE ConstReference operator[](short index) const { return m_Data[index]; }
552  UTL_ALWAYS_INLINE Reference operator[](unsigned short index) { return m_Data[index]; }
553  UTL_ALWAYS_INLINE ConstReference operator[](unsigned short index) const { return m_Data[index]; }
554  UTL_ALWAYS_INLINE Reference operator[](int index) { return m_Data[index]; }
555  UTL_ALWAYS_INLINE ConstReference operator[](int index) const { return m_Data[index]; }
556 // false positive warnings with GCC 4.9
557 #if defined( __GNUC__ )
558 #if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 )
559 #pragma GCC diagnostic push
560 #pragma GCC diagnostic ignored "-Warray-bounds"
561 #endif
562 #endif
563  UTL_ALWAYS_INLINE Reference operator[](unsigned int index) { return m_Data[index]; }
564  UTL_ALWAYS_INLINE ConstReference operator[](unsigned int index) const { return m_Data[index]; }
565 #if defined( __GNUC__ )
566 #if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 )
567 #pragma GCC diagnostic pop
568 #endif
569 #endif
570  UTL_ALWAYS_INLINE Reference operator[](long index) { return m_Data[index]; }
571  UTL_ALWAYS_INLINE ConstReference operator[](long index) const { return m_Data[index]; }
572  UTL_ALWAYS_INLINE Reference operator[](unsigned long index) { return m_Data[index]; }
573  UTL_ALWAYS_INLINE ConstReference operator[](unsigned long index) const { return m_Data[index]; }
574  UTL_ALWAYS_INLINE Reference operator[](long long index) { return m_Data[index]; }
575  UTL_ALWAYS_INLINE ConstReference operator[](long long index) const { return m_Data[index]; }
576  UTL_ALWAYS_INLINE Reference operator[](unsigned long long index) { return m_Data[index]; }
577  UTL_ALWAYS_INLINE ConstReference operator[](unsigned long long index) const { return m_Data[index]; }
578 
579  UTL_ALWAYS_INLINE Reference operator()(const ShapeType& shape) { return m_Data[GetOffset(shape)]; }
580  UTL_ALWAYS_INLINE ConstReference operator()(const ShapeType& shape) const { return m_Data[GetOffset(shape)]; }
581 
582  UTL_ALWAYS_INLINE Reference Back() { return m_Data[Size()-1]; }
583  UTL_ALWAYS_INLINE ConstReference Back() const { return m_Data[Size()-1]; }
584 
588  Iterator Begin()
589  {
590  return Iterator(m_Data);
591  }
592 
596  ConstIterator Begin() const
597  {
598  return ConstIterator(m_Data);
599  }
600  ConstIterator cBegin() const
601  {
603  }
604 
608  Iterator End()
609  {
610  return Iterator(m_Data + Size());
611  }
612 
616  ConstIterator End() const
617  {
618  return ConstIterator(m_Data + Size());
619  }
620  ConstIterator cEnd() const
621  {
622  return ConstIterator(m_Data + Size());
623  }
624 
628  ReverseIterator rBegin()
629  {
630  return ReverseIterator(m_Data + Size());
631  }
632 
636  ConstReverseIterator rBegin() const
637  {
638  return ConstReverseIterator(m_Data + Size());
639  }
640  ConstReverseIterator crBegin() const
641  {
642  return ConstReverseIterator(m_Data + Size());
643  }
644 
648  ReverseIterator rEnd()
649  {
650  return ReverseIterator(m_Data);
651  }
652 
656  ConstReverseIterator rEnd() const
657  {
658  return ConstReverseIterator(m_Data);
659  }
660  ConstReverseIterator crEnd() const
661  {
662  return ConstReverseIterator(m_Data);
663  }
664 
666  void SetElement(unsigned short index, ConstReference value)
667  { m_Data[index] = value; }
668  ConstReference GetElement(unsigned short index) const
669  { return m_Data[index]; }
670 
673  {
674  return m_Data;
675  }
676 
677  UTL_ALWAYS_INLINE const T* GetData() const
678  {
679  return m_Data;
680  }
681 
683  void SetData( T* const data, const ShapeType& shape )
684  {
685  utlException(data==m_Data, "cannot set itself. Please use ReShape() for change the shape");
686  Clear();
687  m_Data = data;
688  m_IsShared = true;
689  for ( int i = 0; i < Dim; ++i )
690  m_Shape[i] = shape[i];
692  }
693 
695  void CopyData(T* const data, const ShapeType& shape)
696  {
697  ReSize(shape);
698  utl::cblas_copy(Size(), data, 1, m_Data, 1);
699  }
700 
703  UTL_ALWAYS_INLINE bool ReSize(const ShapeType& shape)
704  {
705  // if no change in shape or size, do not reallocate.
706  if (IsSameShape(shape) && this->m_Data)
707  return false;
708  if (IsSameSize(shape) && this->m_Data)
709  {
710  ReShape(shape);
711  return false;
712  }
713  if (this->m_Data)
714  {
715  if (!m_IsShared)
716  Clear();
718  }
719  else
720  {
721  // this happens if the array is default constructed.
723  }
724  return true;
725  }
726 
728  inline NDArrayBase<T,Dim>& ReShape(const ShapeType& shape)
729  {
730  SizeType newSize = std::accumulate(shape, shape+Dim, 0);
731  utlException(newSize!=Size(), "need to keep the same size");
732  for ( int i = 0; i < Dim; ++i )
733  m_Shape[i] = shape[i];
735  return *this;
736  }
737 
738  NDArray<T,SubDimension> GetRefSubArray(const int i) const
739  {
741  unsigned shape[SubDimension];
742  if (Dim>1)
743  {
744  for ( int jj = 0; jj < SubDimension; ++jj )
745  shape[jj] = m_Shape[jj+1];
746  arr.SetData(m_Data+i*m_OffSetTable[1], shape);
747  }
748  else
749  {
750  shape[0] = 1;
751  arr.SetData(m_Data+i, shape);
752  }
753  return arr;
754  }
755 
756  NDArray<T,Dim> GetRefSubArray(const int istart, const int iend) const
757  {
758  NDArray<T,Dim> arr;
759  unsigned shape[Dim];
760  if (Dim>1)
761  {
762  for ( int jj = 0; jj < Dim; ++jj )
763  shape[jj] = m_Shape[jj];
764  shape[0]= iend-istart+1;
765  arr.SetData(m_Data+istart*m_OffSetTable[1], shape);
766  }
767  else
768  {
769  shape[0]= iend-istart+1;
770  arr.SetData(m_Data+istart, shape);
771  }
772  return arr;
773  }
774 
776  template<typename EType>
777  UTL_ALWAYS_INLINE bool IsSameShape(const EType& src) const
778  {
780  if (srcDim==0)
781  return true;
782  if (srcDim!=Dimension)
783  return false;
784  const EType &r = src.ConstRef();
785  const ShapeType rShape = r.GetShape();
786  for ( int i = 0; i < Dimension; ++i )
787  {
788  if (rShape[i]!=m_Shape[i])
789  return false;
790  }
791  return true;
792  }
793 
794 
795  UTL_ALWAYS_INLINE bool IsSameShape(const ShapeType& shape) const
796  {
797  // utl::PrintContainer(m_Shape, m_Shape+Dimension, "m_Shape", " ");
798  // utl::PrintContainer(shape, shape+Dimension, "shape", " ");
799  for ( int i = 0; i < Dimension; ++i )
800  {
801  if (shape[i]!=m_Shape[i])
802  return false;
803  }
804  return true;
805  }
806 
807  UTL_ALWAYS_INLINE bool IsSameSize(const ShapeType& shape) const
808  {
809  return Size() == std::accumulate(shape, shape+Dim, 0);
810  }
811 
814  NDArrayBase<T,Dim>& ElementAdd(T* const vec, T* outVec=NULL)
815  { utl::vAdd(Size(), m_Data, vec, outVec?outVec:m_Data); return *this; }
816 
817  NDArrayBase<T,Dim>& ElementSubstract(T* const vec, T* outVec=NULL)
818  { utl::vSub(Size(), m_Data, vec, outVec?outVec:m_Data); return *this; }
819 
820  NDArrayBase<T,Dim>& ElementMultiply(T* const vec, T* outVec=NULL)
821  { utl::vMul(Size(), m_Data, vec, outVec?outVec:m_Data); return *this; }
823  NDArrayBase<T,Dim>& ElementDivide(T* const vec, T* outVec=NULL)
824  { utl::vDiv(Size(), m_Data, vec, outVec?outVec:m_Data); return *this; }
825 
826  NDArrayBase<T,Dim>& ElementExp(T* outVec=NULL)
827  { utl::vExp(Size(), m_Data, outVec?outVec:m_Data); return *this; }
829  { vec.Resize(m_Shape); ElementExp(vec.m_Data); return *this; }
831  { return NDArrayBase<T,Dim>(*this).ElementExp(); }
832 
833  NDArrayBase<T,Dim>& ElementCos(T* outVec=NULL)
834  { utl::vCos(Size(), m_Data, outVec?outVec:m_Data); return *this; }
836  { vec.Resize(m_Shape); ElementCos(vec.m_Data); return *this; }
838  { return NDArrayBase<T,Dim>(*this).ElementCos(); }
839 
840  NDArrayBase<T,Dim>& ElementSin(T* outVec=NULL)
841  { utl::vSin(Size(), m_Data, outVec?outVec:m_Data); return *this; }
843  { vec.Resize(m_Shape); ElementSin(vec.m_Data); return *this; }
845  { return NDArrayBase<T,Dim>(*this).ElementSin(); }
846 
847  NDArrayBase<T,Dim>& ElementAbsolute(T* outVec=NULL)
848  { utl::vAbs(Size(), m_Data, outVec?outVec:m_Data); return *this; }
850  { vec.Resize(m_Shape); ElementAbsolute(vec.m_Data); return *this; }
852  { return NDArrayBase<T,Dim>(*this).ElementAbsolute(); }
853 
854  NDArrayBase<T,Dim>& ElementInverse(T* outVec=NULL)
855  { utl::vInv(Size(), m_Data, outVec?outVec:m_Data); return *this; }
857  { vec.Resize(m_Shape); ElementInverse(vec.m_Data); return *this; }
859  { return NDArrayBase<T,Dim>(*this).ElementInverse(); }
860 
861  NDArrayBase<T,Dim>& ElementSqrt(T* outVec=NULL)
862  { utl::vSqrt(Size(), m_Data, outVec?outVec:m_Data); return *this; }
864  { vec.Resize(m_Shape); ElementSqrt(vec.m_Data); return *this; }
866  { return NDArrayBase<T,Dim>(*this).ElementSqrt(); }
867 
868  NDArrayBase<T,Dim>& ElementSquare(T* outVec=NULL)
869  { utl::vSqr(Size(), m_Data, outVec?outVec:m_Data); return *this; }
871  { vec.Resize(m_Shape); ElementSquare(vec.m_Data); return *this; }
873  { return NDArrayBase<T,Dim>(*this).ElementSquare(); }
874 
876  NDArrayBase<T,Dim>& ElementAxpby(T* const vec, const T alpha, const T beta)
877  { utl::cblas_axpby(Size(), alpha, vec, 1, beta, m_Data, 1); return *this; }
878 
879  NDArrayBase<T,Dim>& Scale(const T a)
880  {
881  if (std::abs(a-1.0)>1e-10)
882  cblas_scal<T>(Size(),a,m_Data,1);
883  return *this;
884  }
885 
887  {
888  utlException(!IsSameShape(vec), "wrong shape");
889  utlSAException(vec.Size()!=Size())(Size())(vec.Size()).msg("wrong size");
890  ElementAdd(vec.m_Data);
891  return *this;
892  }
894  {
895  utlException(!IsSameShape(vec), "wrong shape");
896  utlSAException(vec.Size()!=Size())(Size())(vec.Size()).msg("wrong size");
898  return *this;
899  }
900  // [>* use % for multiplication <]
902  {
903  utlSAException(vec.Size()!=Size())(Size())(vec.Size()).msg("wrong size");
904  ElementMultiply(vec.m_Data);
905  return *this;
906  }
908  {
909  utlSAException(vec.Size()!=Size())(Size())(vec.Size()).msg("wrong size");
910  ElementDivide(vec.m_Data);
911  return *this;
912  }
913 
914  NDArrayBase<T,Dim>& operator%=(const T val)
915  {
916  Scale(val);
917  return *this;
918  }
919  NDArrayBase<T,Dim>& operator/=(const T val)
920  {
921  Scale(1.0/val);
922  return *this;
923  }
924 
928  void Fill(const T& value)
929  {
930  std::fill(Begin(), End(), value);
931  }
932 
934  NDArrayBase<T,Dim>& CopyIn(T const * ptr, const int size, const int start=0)
935  {
936  utlException(size+start>Size(), "wrong size");
937  utl::cblas_copy(size, ptr, 1, m_Data+start, 1);
938  return *this;
939  }
940 
942  void CopyOut(T * ptr, const int size, const int start=0) const // from vector to array[].
943  {
944  utlException(size+start>Size(), "wrong size");
945  utl::cblas_copy(size, m_Data+start, 1, ptr, 1);
946  }
947 
948 
950  template<typename FuncT>
951  void Apply(const FuncT& func, NDArrayBase<T,Dim>& vec) const
952  {
953  vec.ReSize(m_Shape);
954  for (SizeType i = 0; i < Size(); ++i)
955  vec[i] = func(m_Data[i]);
956  }
957  void Apply(T (*f)(T), NDArrayBase<T,Dim>& vec) const
958  {
959  vec.ReSize(m_Shape);
960  for (SizeType i = 0; i < Size(); ++i)
961  vec[i] = f(m_Data[i]);
962  }
963  void Apply(T (*f)(T const&), NDArrayBase<T,Dim>& vec) const
964  {
965  vec.ReSize(m_Shape);
966  for (SizeType i = 0; i < Size(); ++i)
967  vec[i] = f(m_Data[i]);
968  }
970  unsigned ArgMax() const
971  {
972  return utl::argmax(Begin(), End());
973  }
974 
975  T MaxValue() const
976  {
977  return *std::max_element(Begin(), End());
978  }
979 
980  unsigned ArgMin() const
981  {
982  return utl::argmin(Begin(), End());
983  }
984 
985  T MinValue() const
986  {
987  return *std::min_element(Begin(), End());
988  }
990  unsigned ArgAbsoluteMax() const
991  {
992  return utl::cblas_iamax<T>(Size(), m_Data, 1);
993  }
994 
996  {
997  unsigned index = ArgAbsoluteMax();
998  return m_Data[index];
999  }
1000 
1001  unsigned ArgAbsoluteMin() const
1002  {
1003  return utl::cblas_iamin(Size(), m_Data, 1);
1004  }
1005  T AbsoluteMinValue() const
1006  {
1007  unsigned index = ArgAbsoluteMin();
1008  return m_Data[index];
1009  }
1010 
1012  double GetInfNorm( ) const
1013  {
1014  double absMax = std::abs(AbsoluteMaxValue());
1015  return absMax;
1016  }
1019  double GetTwoNorm( ) const
1020  {
1021  return utl::cblas_nrm2(Size(), m_Data, 1);
1022  }
1023  double GetSquaredTwoNorm( ) const
1024  {
1025  double norm = GetTwoNorm();
1026  return norm*norm;
1027  }
1028  double GetRootMeanSquares( ) const
1029  {
1030  return GetTwoNorm()/std::sqrt(double(Size()));
1031  }
1032 
1034  double GetOneNorm( ) const
1035  {
1036  return utl::cblas_asum(Size(), m_Data, 1);
1037  }
1038 
1040  int GetZeroNorm( const double eps=1e-10 ) const
1041  {
1042  return NNZ(eps);
1043  }
1044 
1046  T GetSum() const
1047  {
1048  T tot(0);
1049  for (ConstIterator p = Begin(); p!= End(); ++p)
1050  tot += *p;
1051  return tot;
1052  }
1053 
1055  T GetMean() const
1056  {
1057  return GetSum()/(T)Size();
1058  }
1059 
1060  T GetMedian() const
1061  {
1063  const unsigned int N = vec.Size();
1064  std::nth_element(vec.Begin(),vec.Begin()+N/2,vec.End());
1065  return vec[N/2];
1066  }
1067 
1069  {
1070  std::swap(m_IsShared, vec.m_IsShared);
1071  std::swap(m_Shape, vec.m_Shape);
1072  std::swap(m_OffSetTable, vec.m_OffSetTable);
1073  std::swap(m_Data, vec.m_Data);
1074  }
1075 
1077  {
1078  for (unsigned i=0; i<Size()/2; i++)
1079  std::swap(m_Data[i], m_Data[Size()-1-i]);
1080  return *this;
1081  }
1082 
1083  bool IsZero() const
1084  {
1085  T const zero(0);
1086  for (unsigned i = 0; i < Size();++i)
1087  if ( !( m_Data[i] == zero) )
1088  return false;
1089  return true;
1090  }
1091 
1092  bool IsEmpty() const
1093  { return Size()==0; }
1094 
1096  int NNZ(const double eps=1e-10) const
1097  {
1098  int sum=0;
1099  for (int i = 0; i<Size(); ++i)
1100  {
1101  if (std::abs(m_Data[i])<eps)
1102  ++sum;
1103  }
1104  return sum;
1105  }
1106 
1107  void SoftThreshold(const double threshold)
1108  {
1109  for (int i = 0; i<Size(); ++i)
1110  {
1111  if (m_Data[i] > threshold)
1112  m_Data[i] -= threshold;
1113  else if (m_Data[i] < -threshold)
1114  m_Data[i] += threshold;
1115  else
1116  m_Data[i] = 0.0;
1117  }
1118  }
1119 
1120  void HardThreshold(const double threshold)
1121  {
1122  for (int i = 0; i<Size(); ++i)
1123  {
1124  if (!(m_Data[i] > threshold || m_Data[i] < -threshold))
1125  m_Data[i] = 0;
1126  }
1127  }
1128 
1129  ValueType InnerProduct(const NDArrayBase<T,Dim>& vec) const
1130  { return utl::InnerProduct(*this, vec); }
1131 
1132  void
1133  PrintInfo(std::ostream & os, const char* separate=" ") const
1134  {
1135  utlOSPrintVar(true, os, Dimension, m_IsShared, m_Data);
1136  utl::PrintContainer(m_Shape, m_Shape+Dimension, "m_Shape", separate, os);
1137  utl::PrintContainer(m_OffSetTable, m_OffSetTable+Dimension,"m_OffSetTable", separate, os);
1138  }
1139 
1140  void
1141  Print(std::ostream & os, const char* separate=" ") const
1142  {
1143  PrintInfo(os, separate);
1144  utl::PrintContainer(m_Data, m_Data+Size(), "m_Data", separate, os);
1145  }
1146 
1147  void
1148  PrintWithIndex(std::ostream & os, const char* separate=" ") const
1149  {
1150  PrintVar1(true, Dimension, os);
1151  utl::PrintContainer(m_Shape, m_Shape+Dimension, "m_Shape", separate, os);
1152  utl::PrintContainer(m_OffSetTable, m_OffSetTable+Dimension,"m_OffSetTable", separate, os);
1153  unsigned index[Dimension];
1154  for ( int i = 0; i < Size(); ++i )
1155  {
1156  GetIndex(i, index);
1157  std::ostringstream oss;
1158  oss << "m_Data (";
1159  for ( int j = 0; j < Dimension; ++j )
1160  {
1161  oss << index[j];
1162  if (j<Dimension-1)
1163  oss << " ";
1164  }
1165  oss << ") : ";
1166  os << oss.str() << "[ " << m_Data[i] << " ];"<< std::endl;
1167  }
1168  }
1169 
1170 
1171 protected:
1172 
1173  SizeType m_OffSetTable[Dimension];
1174  SizeType m_Shape[Dimension];
1175 
1177  bool m_IsShared;
1178 
1180  T* m_Data;
1181 
1183  {
1184  if (!m_IsShared && Size()>0)
1185  {
1186  delete [] m_Data;
1187  m_Data=NULL;
1188  }
1189  }
1191  {
1192  for ( int i = 0; i < Dimension; ++i )
1193  m_Shape[i]=0, m_OffSetTable[i]=0;
1194  }
1195 
1197  {
1198  for ( int i = Dimension-1; i >= 0; i-- )
1199  {
1200  if (i==Dimension-1)
1201  m_OffSetTable[i]=m_Shape[i];
1202  else
1203  m_OffSetTable[i]=m_Shape[i]*m_OffSetTable[i+1];
1204  }
1205  }
1206 
1207 };
1208 
1211 }
1212 
1213 #include "utlVector.h"
1214 #include "utlMatrix.h"
1215 #include "utl4thOrderTensor.h"
1216 
1217 
1218 #endif
const ValueType * ConstIterator
Definition: utlNDArray.h:171
NDArray is a N-Dimensional array class (row-major, c version)
Definition: utlFunctors.h:131
ConstReverseIterator crBegin() const
Definition: utlNDArray.h:634
NDArrayBase< T, Dim > & Flip()
Definition: utlNDArray.h:1070
NDArrayBase< T, Dim > GetElementAbsolute() const
Definition: utlNDArray.h:845
NDArray<T,1> is a vector class which uses blas mkl.
Definition: utlVector.h:36
NDArrayBase< T, Dim > & ElementCos(T *outVec=NULL)
Definition: utlNDArray.h:827
void PrintContainer(IteratorType v1, IteratorType v2, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
Definition: utlCore.h:1068
typename remove_complex< T >::type remove_complex_t
Definition: utlTypeinfo.h:67
Reference operator[](short index)
Definition: utlNDArray.h:544
void vMul(int n, T *vecIn, T *vecIn2, T *vecOut)
interface to v*Mul
Definition: utlCoreMKL.h:307
unsigned int argmin(Iterator i1, Iterator i2)
Definition: utlCore.h:212
T AbsoluteMaxValue() const
Definition: utlNDArray.h:989
T min_element(const std::vector< T > &v)
Definition: utlCore.h:199
void vSub(int n, T *vecIn, T *vecIn2, T *vecOut)
interface to v*Sub
Definition: utlCoreMKL.h:279
Reference operator[](unsigned long long index)
Definition: utlNDArray.h:570
Superclass::SizeType SizeType
Definition: utlNDArray.h:71
void cblas_copy(const INTT N, const T *X, const INTT incX, T *Y, const INTT incY)
base class for expression
Definition: utlExpression.h:36
NDArrayBase< T, Dim > & ElementSubstract(T *const vec, T *outVec=NULL)
Definition: utlNDArray.h:811
#define PrintVar1(cond, var, os)
Definition: utlCoreMacro.h:447
NDArrayBase< T, Dim > & ElementSquare(T *outVec=NULL)
Definition: utlNDArray.h:862
T GetMedian() const
Definition: utlNDArray.h:1054
void vSqr(int n, T *vecIn, T *vecOut)
interface to v*Sqr
Definition: utlCoreMKL.h:259
bool IsZero() const
Definition: utlNDArray.h:1077
double GetInfNorm() const
Definition: utlNDArray.h:1006
SizeType m_Shape[Dimension]
Definition: utlNDArray.h:1168
Created "07-04-2016.
NDArrayBase< T, Dim > & ElementMultiply(T *const vec, T *outVec=NULL)
Definition: utlNDArray.h:814
bool GetIsShared() const
Definition: utlNDArray.h:363
ValueType * Pointer
Definition: utlNDArray.h:174
NDArrayBase Self
Definition: utlNDArray.h:146
void Print(std::ostream &os, const char *separate=" ") const
Definition: utlNDArray.h:1135
bool IsSameShape(const EType &src) const
Definition: utlNDArray.h:771
NDArrayBase< T, Dim > & CopyIn(T const *ptr, const int size, const int start=0)
Definition: utlNDArray.h:928
NDArray(const Expr< EType, typename EType::ValueType > &expr)
Definition: utlNDArray.h:99
Iterator Begin()
Definition: utlNDArray.h:582
const ValueType & operator*() const
Definition: utlNDArray.h:217
void CopyOut(T *ptr, const int size, const int start=0) const
Definition: utlNDArray.h:936
Superclass::ConstPointer ConstPointer
Definition: utlNDArray.h:77
NDArrayBase< T, Dim > & ElementSin(T *outVec=NULL)
Definition: utlNDArray.h:834
NDArrayBase< T, Dim > & ElementInverse(T *outVec=NULL)
Definition: utlNDArray.h:848
void vAbs(int n, T *vecIn, T *vecOut)
interface to v*Abs
Definition: utlCoreMKL.h:321
Reference operator[](long index)
Definition: utlNDArray.h:564
#define __Array_Saver_Expr(saver, saverReal)
Definition: utlNDArray.h:369
ValueType & operator*() const
Definition: utlNDArray.h:195
#define utlException(cond, expout)
Definition: utlCoreMacro.h:548
NDArrayBase< T, Dim > & operator%=(const Expr< EType, typename EType::ValueType > &src)
Definition: utlNDArray.h:386
static constexpr SizeType SubDimension
Definition: utlNDArray.h:162
ValueType & Reference
Definition: utlNDArray.h:178
bool operator==(const ConstReverseIterator &rit) const
Definition: utlNDArray.h:219
NDArray(NDArray< T, Dim > &&vec)
Definition: utlNDArray.h:93
void vAdd(int n, T *vecIn, T *vecIn2, T *vecOut)
interface to v*Add
Definition: utlCoreMKL.h:300
T AbsoluteMinValue() const
Definition: utlNDArray.h:999
bool IsSameValues(const NDArrayBase< T, Dim > &r, const double eps) const
Definition: utlNDArray.h:521
NDArray<T,2> is a row-major matrix.
Definition: utlMatrix.h:37
void cblas_axpby(const INTT N, const T alpha, const T *X, const INTT incX, const T beta, T *Y, const INTT incY)
Definition: utlBlas.h:413
bool ReSize(const ShapeType &shape)
Definition: utlNDArray.h:697
void vSin(int n, T *vecIn, T *vecOut)
interface to v*Sin
void HardThreshold(const double threshold)
Definition: utlNDArray.h:1114
bool IsSameSize(const ShapeType &shape) const
Definition: utlNDArray.h:801
NDArrayBase< T, Dim > & operator+=(const Expr< EType, typename EType::ValueType > &src)
Definition: utlNDArray.h:385
NDArrayBase< T, Dim > & ElementExp(T *outVec=NULL)
Definition: utlNDArray.h:820
const ValueType & ConstReference
Definition: utlNDArray.h:179
NDArrayBase< T, Dim > GetElementSqrt() const
Definition: utlNDArray.h:859
T MaxValue() const
Definition: utlNDArray.h:969
static SizeType GetDimension()
Definition: utlExpression.h:78
T MinValue() const
Definition: utlNDArray.h:979
double GetTwoNorm() const
Definition: utlNDArray.h:1013
NDArray(const NDArray< TValue, Dim > &r)
Definition: utlNDArray.h:114
NDArrayBase(const NDArrayBase< TValue, Dim > &r)
Definition: utlNDArray.h:283
bool operator==(const NDArrayBase< T, Dim > &r) const
Definition: utlNDArray.h:480
unsigned ArgMin() const
Definition: utlNDArray.h:974
NDArrayBase< T, Dim > & ElementDivide(T *const vec, T *outVec=NULL)
Definition: utlNDArray.h:817
void SetData(T *const data, const ShapeType &shape)
Definition: utlNDArray.h:677
NDArray< T, Dim > & operator=(const NDArray< T, Dim > &r)
Definition: utlNDArray.h:116
unsigned int argmax(Iterator i1, Iterator i2)
Definition: utlCore.h:222
unsigned ArgAbsoluteMin() const
Definition: utlNDArray.h:995
NDArray(const ShapeType &shape)
Definition: utlNDArray.h:89
unsigned ArgAbsoluteMax() const
Definition: utlNDArray.h:984
Created "06-21-2016.
ReverseIterator rEnd()
Definition: utlNDArray.h:642
bool IsEqual(const NDArrayBase< T, Dim > &r, const double eps) const
Definition: utlNDArray.h:502
NDArray< T, SubDimension > GetRefSubArray(const int i) const
Definition: utlNDArray.h:732
T Eval(int i) const
Definition: utlNDArray.h:313
void SetElement(unsigned short index, ConstReference value)
Definition: utlNDArray.h:660
NDArray(const NDArray< T, Dim > &vec)
Definition: utlNDArray.h:91
Superclass::ShapeType ShapeType
Definition: utlNDArray.h:72
double GetOneNorm() const
Definition: utlNDArray.h:1028
ValueType * Iterator
Definition: utlNDArray.h:168
NDArrayBase< T, Dim > GetElementSquare() const
Definition: utlNDArray.h:866
#define UTL_ALWAYS_INLINE
Definition: utlCoreMacro.h:76
NDArrayBase(const T *vec, const ShapeType &shape)
Definition: utlNDArray.h:267
ConstIterator cBegin() const
Definition: utlNDArray.h:594
SizeType m_OffSetTable[Dimension]
Definition: utlNDArray.h:1167
T abs(const T x)
template version of the fabs function
Base class for utl::NDArray.
Definition: utlMatrix.h:22
void PrintInfo(std::ostream &os, const char *separate=" ") const
Definition: utlNDArray.h:1127
NDArrayBase< T, Dim > GetElementCos() const
Definition: utlNDArray.h:831
ReverseIterator rBegin()
Definition: utlNDArray.h:622
functors in utl
ConstReference GetElement(unsigned short index) const
Definition: utlNDArray.h:662
Superclass::Iterator Iterator
Definition: utlNDArray.h:74
ConstReverseIterator crEnd() const
Definition: utlNDArray.h:654
double GetSquaredTwoNorm() const
Definition: utlNDArray.h:1017
Definition: utl.h:90
void SoftThreshold(const double threshold)
Definition: utlNDArray.h:1101
Superclass::SizeType SizeType
Definition: utlNDArray.h:154
void ComputeOffSetTable()
Definition: utlNDArray.h:1190
void Fill(const T &value)
Definition: utlNDArray.h:922
SizeType GetOffset(const ShapeType &shapeIndex) const
Definition: utlNDArray.h:338
void Apply(T(*f)(T const &), NDArrayBase< T, Dim > &vec) const
Definition: utlNDArray.h:957
bool IsEmpty() const
Definition: utlNDArray.h:1086
A const reverse iterator through an array.
Definition: utlNDArray.h:207
Reference Back()
Definition: utlNDArray.h:576
void vSqrt(int n, T *vecIn, T *vecOut)
interface to v*Sqrt
Definition: utlCoreMKL.h:265
bool operator==(const ReverseIterator &rit) const
Definition: utlNDArray.h:197
bool operator!=(const NDArrayBase< T, Dim > &r) const
Definition: utlNDArray.h:499
#define utlSAException(expr)
Definition: utlCoreMacro.h:543
void Apply(T(*f)(T), NDArrayBase< T, Dim > &vec) const
Definition: utlNDArray.h:951
Reference operator()(const ShapeType &shape)
Definition: utlNDArray.h:573
NDArrayBase(const NDArrayBase< T, Dim > &vec)
Definition: utlNDArray.h:240
void Swap(NDArrayBase< T, Dim > &vec)
Definition: utlNDArray.h:1062
NDArrayBase(const Expr< EType, typename EType::ValueType > &expr)
Definition: utlNDArray.h:255
int NNZ(const double eps=1e-10) const
Definition: utlNDArray.h:1090
NDArrayBase< T, Dim > & ElementSqrt(T *outVec=NULL)
Definition: utlNDArray.h:855
NDArrayBase< T, Dim > & operator-=(const Expr< EType, typename EType::ValueType > &src)
Definition: utlNDArray.h:385
Superclass::ConstReference ConstReference
Definition: utlNDArray.h:79
NDArrayBase< T, Dim > & ReShape(const ShapeType &shape)
Definition: utlNDArray.h:722
T cblas_asum(const INTT N, const T *X, const INTT incX)
SizeType GetSize() const
Definition: utlNDArray.h:325
int cblas_iamin(const INTT N, const T *X, const INTT incX)
interface to cblas_i*amin
Definition: utlBlas.h:170
Expr< NDArrayBase< T, Dim >, T > Superclass
Definition: utlNDArray.h:152
void vCos(int n, T *vecIn, T *vecOut)
interface to v*Cos
NDArrayBase< T, Dim > & ElementAdd(T *const vec, T *outVec=NULL)
Definition: utlNDArray.h:808
void vExp(int n, T *vecIn, T *vecOut)
interface to v*Exp
Definition: utlCoreMKL.h:293
const NDArrayBase< T, Dim > & ConstRef(void) const
Definition: utlExpression.h:69
Iterator End()
Definition: utlNDArray.h:602
Created "07-03-2016.
unsigned ArgMax() const
Definition: utlNDArray.h:964
const SizeType * GetOffSetTable() const
Definition: utlNDArray.h:358
void PrintWithIndex(std::ostream &os, const char *separate=" ") const
Definition: utlNDArray.h:1142
utl::NDArray<T,2> class which uses blas mkl
NDArray(const T *vec, const ShapeType &shape)
Definition: utlNDArray.h:106
void Apply(const FuncT &func, NDArrayBase< T, Dim > &vec) const
Definition: utlNDArray.h:945
const ValueType * ConstPointer
Definition: utlNDArray.h:175
NDArrayBase< T, Dim > & operator/=(const Expr< EType, typename EType::ValueType > &src)
Definition: utlNDArray.h:386
ConstReverseIterator(const ReverseIterator &rit)
Definition: utlNDArray.h:211
NDArrayBase< T, Dim > GetElementSin() const
Definition: utlNDArray.h:838
NDArray< T, Dim > & operator=(NDArray< T, Dim > &&r)
Definition: utlNDArray.h:122
ValueType InnerProduct(const NDArrayBase< T, Dim > &vec) const
Definition: utlNDArray.h:1123
static constexpr SizeType GetDimension()
Definition: utlNDArray.h:335
NDArrayBase< T, Dim > GetElementInverse() const
Definition: utlNDArray.h:852
NDArrayBase< T, Dim > & ElementAbsolute(T *outVec=NULL)
Definition: utlNDArray.h:841
void GetIndex(const SizeType offset, SizeType index[Dimension]) const
Definition: utlNDArray.h:347
A reverse iterator through an array.
Definition: utlNDArray.h:186
bool operator!=(const ReverseIterator &rit) const
Definition: utlNDArray.h:196
NDArrayBase< T, Dim > & Scale(const T a)
Definition: utlNDArray.h:873
ConstReference operator[](unsigned long long index) const
Definition: utlNDArray.h:571
double InnerProduct(const TVector1 &v1, const TVector2 &v2, const int N1)
Definition: utlMath.h:1322
__Array_Saver_Scalar(+=) __Array_Saver_Scalar(-
NDArrayBase< T, Dim > Superclass
Definition: utlNDArray.h:65
NDArray Self
Definition: utlNDArray.h:64
utl::NDArray<T,1> class which uses blas mkl
const ShapeType GetShape() const
Definition: utlNDArray.h:330
T GetSum() const
Definition: utlNDArray.h:1040
NDArrayBase(const ShapeType &shape)
Definition: utlNDArray.h:235
NDArrayBase(NDArrayBase< T, Dim > &&vec)
Definition: utlNDArray.h:246
void vDiv(int n, T *vecIn, T *vecIn2, T *vecOut)
interface to v*Div
Definition: utlCoreMKL.h:314
#define utlOSPrintVar(cond, os,...)
Definition: utlCoreMacro.h:308
double GetRootMeanSquares() const
Definition: utlNDArray.h:1022
Superclass::Pointer Pointer
Definition: utlNDArray.h:76
macros for utlCore
SizeType Size() const
Definition: utlNDArray.h:321
int GetZeroNorm(const double eps=1e-10) const
Definition: utlNDArray.h:1034
NDArrayBase< T, Dim > & operator=(const Expr< EType, typename EType::ValueType > &src)
Definition: utlNDArray.h:385
Superclass::ValueType ValueType
Definition: utlNDArray.h:68
void vInv(int n, T *vecIn, T *vecOut)
interface to v*Inv
Definition: utlCoreMKL.h:286
utl::remove_complex_t< T > ScalarValueType
Definition: utlNDArray.h:165
Superclass::ScalarValueType ScalarValueType
Definition: utlNDArray.h:69
T cblas_nrm2(const INTT N, const T *X, const INTT incX)
ConstIterator cEnd() const
Definition: utlNDArray.h:614
NDArray(const ShapeType &shape, const T r)
Definition: utlNDArray.h:111
Superclass::ShapeType ShapeType
Definition: utlNDArray.h:155
T max_element(const std::vector< T > &v)
Definition: utlCore.h:205
NDArrayBase(const ShapeType &shape, const T r)
Definition: utlNDArray.h:276
T GetMean() const
Definition: utlNDArray.h:1049
ConstIterator operator->() const
Definition: utlNDArray.h:216
bool operator!=(const ConstReverseIterator &rit) const
Definition: utlNDArray.h:218
Superclass::ConstIterator ConstIterator
Definition: utlNDArray.h:75
NDArrayBase< T, Dim > & ElementAxpby(T *const vec, const T alpha, const T beta)
Definition: utlNDArray.h:870
#define __utl_ndarray_alloc_blah(shape)
Definition: utlNDArray.h:30
void CopyData(T *const data, const ShapeType &shape)
Definition: utlNDArray.h:689
NDArrayBase< T, Dim > GetElementExp() const
Definition: utlNDArray.h:824
Superclass::Reference Reference
Definition: utlNDArray.h:78