#ifndef __TENS_0NE_D_H__ #define __TENS_0NE_D_H__ #include #include #include //#include "tensor.h" //#include "cudatensor.h" //#include "/home/fanasina/progr_/ptens0neD/dimension/dimension.h" //#include "/home/fanasina/progr_/ptens0neD/permutation/permutation.h" //#include "/home/fanasina/progr_/ptens0neD/tensor/tensCuda/tensCuda.h" #include "dimension/dimension.h" #include "permutation/permutation.h" #include "tensor/tensCuda/tensCuda.h" template struct Tensor { struct dimension Dim; T* elements; Tensor(struct dimension dm = dimension(1)) { Dim = dm; //elements = new T[Dim.size]; elements = (T*)malloc(Dim.size * sizeof(T)); } void initTensor() { //delete[]elements; //elements = new T[Dim.size]; if (elements != NULL) free(elements); elements = (T*)malloc(Dim.size * sizeof(T)); } void initVal(T val); // { for (int i = 0; i < Dim.size; i++) elements[i] = val + 0.001f * i; } void print(); Tensor& operator=(const Tensor& M); Tensor& operator*=(const T& val); template friend Tensor& operator*(const Tensor& M0, const Tensor& M1); // M[x0,x1,x3..xn] X M[y0,y1,y3..ym] = M[z0,z1...zp] (deep = l > 0) /exists 1<= l<...=n-l alor p=n+m-2l // M[x0,x1,x3..xl x{l+1}...xn] X M[xn,x{n-1},x{n-2}...xl y{l+1} ..ym] = M[x0,x1..xly{l+1}...y{n+m-2l}] (deep = l > 0) template friend void tensorContractnProd(Tensor& M, const Tensor& M0, const Tensor& M1, int nestingDepth); // M[x0,x1,x3..xn] X M[y0,y1,y3..ym] = M[z0,z1...zp] (deep = l > 0) /exists 1<= l<...=n-l alor p=n+m-2l // M[x0,x1,x3..xl x{l+1}..xn] X M[xn,x{n-1},..x{l+1}xl y{l+1}..ym] = M[x0,x1..xly{l+1}...y{n+m-2l}] (deep = l > 0) template friend void tensorContractnReverseProd(Tensor& M, const Tensor& M0, const Tensor& M1, int nestingDepth); template friend void cudaTensorContractNestProd(Tensor& M, const Tensor& M0, const Tensor& M1, int nestingDepth, bool strict); /*template friend void cudaTensorContractnProd(Tensor& M, const Tensor& M0, const Tensor& M1, int nestingDepth); */ template friend void tensorProd(Tensor& M, const Tensor& M0, const Tensor& M1); template friend void cudaTensorProd(Tensor& M, const Tensor& M0, const Tensor& M1); template friend void cudaTensorProdEnd(Tensor& M, const Tensor& M0, const Tensor& M1); template friend void permuteTensor(Tensor& M, const Tensor& M0, permutation p); template friend void permuteTensorDef(Tensor& M, const Tensor& M0, permutation p); template friend bool scanPermuteMatchContractTensorfromSrcToDst(int* perm, const Tensor& Msecond, const Tensor& Mfirst, int contractNest); //template //friend void cudapermuteTensor(Tensor& M, const Tensor& M0, permutation p); }; template void transform(Tensor& Dst, const Tensor& Src, int* perm, int sz); template Tensor& operator*(const Tensor& M0, const Tensor& M1); void subArray(int* dst, int* src, int debDst, int finDst, int debSrc); void concatArray(int* dst, int* src0, int* src1, int debDst, int debSrc0, int finSrc0, int debSrc1, int finSrc1); void reverseArray(int* arr, int sz); template void tensorProd(Tensor& M, const Tensor& M1, const Tensor& M0); bool checkMatchProdTensor(const dimension& d0, const dimension& d1, int nestingDepth); void extractDimNestingDepth(dimension& dM, const dimension& d0, const dimension& d1, int nestingDepth); // M[x0,x1,x3..xn] X M[y0,y1,y3..ym] = M[z0,z1...zp] (deep = l > 0) /exists 1<= l<...=n-l alor p=n+m-2l //M[[i][j]]=sum_{[k]}M0[[i][k]]*M[[k][j]] template void tensorContractnProd(Tensor& M, const Tensor& M0, const Tensor& M1, int nestingDepth); // M[x0,x1,x3..xn] X M[y0,y1,y3..ym] = M[z0,z1...zp] (deep = l > 0) /exists 1<= l<...=n-l alor p=n+m-2l //M[[i][j]]=sum_{[k]}M0[[i][k]]*M[[k][j]] template void tensorContractnReverseProd(Tensor& M, const Tensor& M0, const Tensor& M1, int nestingDepth); #endif