10 #ifndef __utl4thOrderTensor_h 11 #define __utl4thOrderTensor_h 57 using Superclass::operator();
58 using Superclass::operator=;
59 using Superclass::operator+=;
60 using Superclass::operator-=;
61 using Superclass::operator%=;
62 using Superclass::operator/=;
68 template<
typename EType>
72 template<
typename TMatrixValueType >
81 explicit NDArray(
const ShapeType& shape) : Superclass(shape) { }
83 NDArray(
const T* vec,
const SizeType s0,
const SizeType s1,
const SizeType s2,
const SizeType s3) : Superclass()
86 shape[0]=s0, shape[1]=s1, shape[2]=s2, shape[3]=s3;
88 utl::cblas_copy<T>(this->
Size(), vec, 1, this->
m_Data, 1);
91 NDArray(
const SizeType s0,
const SizeType s1,
const SizeType s2,
const SizeType s3) : Superclass()
94 shape[0]=s0, shape[1]=s1, shape[2]=s2, shape[3]=s3;
98 NDArray(
const SizeType s0,
const SizeType s1,
const SizeType s2,
const SizeType s3,
const T r) : Superclass()
101 shape[0]=s0, shape[1]=s1, shape[2]=s2, shape[3]=s3;
111 NDArray(
const T* vec,
const ShapeType& shape) : Superclass(vec,shape) { }
116 NDArray(
const ShapeType& shape,
const T r) : Superclass(shape, r) { }
141 inline bool ReSize(
const SizeType s0,
const SizeType s1,
const SizeType s2,
const SizeType s3)
144 shape[0]=s0, shape[1]=s1, shape[2]=s2, shape[3]=s3;
152 index[0]=i, index[1]=j, index[2]=0, index[3]=0;
167 for (
int i = 0; i < size; ++i )
168 for (
int j = 0; j < size; ++j )
169 for (
int k = 0; k < size; ++k )
170 for (
int l = 0; l < size; ++l )
173 index1[0]=i, index1[1]=j, index1[2]=k, index1[3]=l;
174 index2[0]=k, index2[1]=l, index2[2]=i, index2[3]=j;
175 if (isFilled(index1)==0 || isFilled(index2)==0)
177 T val = ((*this)(index1) + (*
this)(index2))/2.0;
194 for (
int i = 0; i < size; ++i )
195 for (
int j = 0; j < size; ++j )
196 for (
int k = 0; k < size; ++k )
197 for (
int l = 0; l < size; ++l )
199 index1[0]=i, index1[1]=j, index1[2]=k, index1[3]=l;
200 index2[0]=k, index2[1]=l, index2[2]=i, index2[3]=j;
201 if (isFilled(index1)==0 || isFilled(index2)==0)
203 T val1 = (*this)(index1);
204 T val2 = (*this)(index2);
226 for (
int i = 0; i < size; ++i )
227 for (
int j = 0; j < size; ++j )
228 for (
int k = 0; k < size; ++k )
229 for (
int l = 0; l < size; ++l )
232 index1[0]=i, index1[1]=j, index1[2]=k, index1[3]=l;
233 index2[0]=j, index2[1]=i, index2[2]=k, index2[3]=l;
234 index3[0]=i, index3[1]=j, index3[2]=l, index3[3]=k;
235 index4[0]=j, index4[1]=i, index4[2]=l, index4[3]=k;
237 if (isFilled(index1)==0 || isFilled(index2)==0 || isFilled(index3)==0 || isFilled(index4)==0)
239 T val1 = (*this)(index1),
240 val2 = (*
this)(index2),
241 val3 = (*
this)(index3),
242 val4 = (*
this)(index4);
243 (*this)(index1) = (val1+val2+val3+val4)/4.0;
244 (*this)(index2) = (val1+val2+val3+val4)/4.0;
245 (*this)(index3) = (val1+val2+val3+val4)/4.0;
246 (*this)(index4) = (val1+val2+val3+val4)/4.0;
263 for (
int i = 0; i < size; ++i )
264 for (
int j = 0; j < size; ++j )
265 for (
int k = 0; k < size; ++k )
266 for (
int l = 0; l < size; ++l )
268 index1[0]=i, index1[1]=j, index1[2]=k, index1[3]=l;
269 index2[0]=j, index2[1]=i, index2[2]=k, index2[3]=l;
270 index3[0]=i, index3[1]=j, index3[2]=l, index3[3]=k;
271 index4[0]=j, index4[1]=i, index4[2]=l, index4[3]=k;
273 if (isFilled(index1)==0 || isFilled(index2)==0 || isFilled(index3)==0 || isFilled(index4)==0)
275 T val1 = (*this)(index1),
276 val2 = (*
this)(index2),
277 val3 = (*
this)(index3),
278 val4 = (*
this)(index4);
305 matRealR.resize(6); matImgR.resize(6);
310 for (
int i = 0; i < valReal.
Size(); ++i )
312 for (
int j = 0; j < 6; ++j )
313 vecTmp[j] = vecRealR(j,i);
315 for (
int j = 0; j < 6; ++j )
316 vecTmp[j] = vecImgR(j,i);
321 void EigenDecompositionWithMinorSymmetry (
NDArray<T,1>& valReal,
NDArray<T,1>& valImg, std::vector<
NDArray<T,2> >& matRealR, std::vector<
NDArray<T,2> >& matImgR, std::vector<
NDArray<T,2> >& matRealL, std::vector<
NDArray<T,2> >& matImgL)
const 324 matRealR.resize(6); matImgR.resize(6);
325 matRealL.resize(6); matImgL.resize(6);
330 for (
int i = 0; i < valReal.
Size(); ++i )
332 for (
int j = 0; j < 6; ++j )
333 vecTmp[j] = vecRealR(j,i);
335 for (
int j = 0; j < 6; ++j )
336 vecTmp[j] = vecImgR(j,i);
339 for (
int j = 0; j < 6; ++j )
340 vecTmp[j] = vecRealL(j,i);
342 for (
int j = 0; j < 6; ++j )
343 vecTmp[j] = vecImgL(j,i);
const ValueType * ConstIterator
Reference operator()(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
Superclass::Reference Reference
NDArray is a N-Dimensional array class (row-major, c version)
NDArray(const SizeType s0, const SizeType s1, const SizeType s2, const SizeType s3, const T r)
NDArray<T,1> is a vector class which uses blas mkl.
void EigenDecompositionWithMinorSymmetry(NDArray< T, 1 > &valReal, NDArray< T, 1 > &valImg, std::vector< NDArray< T, 2 > > &matRealR, std::vector< NDArray< T, 2 > > &matImgR) const
base class for expression
SizeType m_Shape[Dimension]
bool ReSize(const SizeType s0, const SizeType s1, const SizeType s2, const SizeType s3)
void EigenDecompositionWithMinorSymmetry(NDArray< T, 1 > &valReal, NDArray< T, 1 > &valImg) const
void Convert4To2Tensor(const utl::NDArray< T, 4 > &tensor, utl::NDArray< T, 2 > &mat)
NDArray(const T *vec, const SizeType s0, const SizeType s1, const SizeType s2, const SizeType s3)
#define utlException(cond, expout)
static constexpr SizeType SubDimension
Superclass::ConstPointer ConstPointer
NDArray<T,2> is a row-major matrix.
bool ReSize(const ShapeType &shape)
const ValueType & ConstReference
Superclass::ConstReference ConstReference
ConstReference operator()(unsigned int i, unsigned int j, unsigned int k, unsigned int l) const
NDArray(const Expr< EType, typename EType::ValueType > &expr)
void SetData(T *const data, const ShapeType &shape)
NDArray< T, Dim > & operator=(const NDArray< T, Dim > &r)
NDArray(const SizeType s0, const SizeType s1, const SizeType s2, const SizeType s3)
#define UTL_ALWAYS_INLINE
NDArray(const ShapeType &shape)
SizeType m_OffSetTable[Dimension]
NDArray(const NDArray< TMatrixValueType, 4 > &r)
Superclass::Pointer Pointer
Base class for utl::NDArray.
Superclass::ScalarValueType ScalarValueType
bool IsMinorSymmetric() const
Superclass::SizeType SizeType
void Fill(const T &value)
SizeType GetOffset(const ShapeType &shapeIndex) const
NDArray(const NDArray< T, 4 > &mat)
NDArray< T, 4 > & operator=(NDArray< T, 4 > &&r)
void Swap(NDArrayBase< T, Dim > &vec)
NDArray(NDArray< T, 4 > &&r)
Superclass::SizeType SizeType
bool IsMajorSymmetric() const
const ValueType * ConstPointer
NDArray< T, 2 > GetRefSubMatrix(const int i, const int j) const
NDArray(const ShapeType &shape, const T r)
bool IsSame(const T &value, const T &v0, const double eps=1e-10)
void EigenDecompositionNonSymmetricMatrix(NDArray< T, 1 > &valReal, NDArray< T, 1 > &valImg) const
Superclass::ShapeType ShapeType
void Convert1To2Tensor(const utl::NDArray< T, 1 > &vec, utl::NDArray< T, 2 > &mat)
void EigenDecompositionWithMinorSymmetry(NDArray< T, 1 > &valReal, NDArray< T, 1 > &valImg, std::vector< NDArray< T, 2 > > &matRealR, std::vector< NDArray< T, 2 > > &matImgR, std::vector< NDArray< T, 2 > > &matRealL, std::vector< NDArray< T, 2 > > &matImgL) const
Superclass::Iterator Iterator
NDArrayBase< T, Dim > & operator=(const Expr< EType, typename EType::ValueType > &src)
NDArray(const T *vec, const ShapeType &shape)
utl::remove_complex_t< T > ScalarValueType
void SetData(T *const data, const unsigned rows, const unsigned cols)
Superclass::ConstIterator ConstIterator
Superclass::ValueType ValueType
Superclass::ShapeType ShapeType
NDArray< T, 4 > & operator=(NDArray< T, 4 > &r)
#define __utl_ndarray_alloc_blah(shape)
void CopyData(T *const data, const ShapeType &shape)
NDArray<T,4> is a 4th order tensor.
NDArrayBase< T, 4 > Superclass