model-layer/scalable-tf-module/FTcom/Tensor.cpp
/* Complete all the internal structures of a tensor */
Complete all the internal structures of a tensor
Complete all the internal structures of a tensor
void Tensor::assignTensorIndex() {
	int n, i, j;
	int cntSize = 0;
	for (i = 0; i < order; i++)
		cntSize += Dims[i] + 1;
	int **tempMat = (int **)malloc(sizeof(int *)*order);
	tempMat[0] = (int *)malloc(sizeof(int)*cntSize);
	for(i = 1; i < order; i++) tempMat[i] = tempMat[i-1] + Dims[i-1] + 1;
	memset(CountMat[0], 0, sizeof(int)*cntSize);
	memset(tempMat[0], 0, sizeof(int)*cntSize);
	for (n = 0; n < nnz; n++) {
		for (i = 0; i < order; i++) {
			j = IndexMat[n][i];
			CountMat[i][j+1]++;
			tempMat[i][j+1]++;
		}
	}
	for (i = 0; i < order; i++) {
		for (j = 1; j < Dims[i] + 1; j++) {
			CountMat[i][j] += CountMat[i][j-1];
			tempMat[i][j] += tempMat[i][j-1];
		}
	}
	for (n = 0; n < nnz; n++) {
		for (i = 0; i < order; i++) {
			j = IndexMat[n][i];
			int now = tempMat[i][j];
			WhereMat[i][now] = n;
			tempMat[i][j]++;
		}
	}
	free(tempMat[0]); free(tempMat);
}
void Tensor :: assignTensorIndex ( ) { int n , i , j ; int cntSize = 0 ; for ( i = 0 ; i < order ; i ++ ) cntSize += Dims [ i ] + 1 ; int * * tempMat = ( int * * ) malloc ( sizeof ( int * ) * order ) ; tempMat [ 0 ] = ( int * ) malloc ( sizeof ( int ) * cntSize ) ; for ( i = 1 ; i < order ; i ++ ) tempMat [ i ] = tempMat [ i - 1 ] + Dims [ i - 1 ] + 1 ; memset ( CountMat [ 0 ] , 0 , sizeof ( int ) * cntSize ) ; memset ( tempMat [ 0 ] , 0 , sizeof ( int ) * cntSize ) ; for ( n = 0 ; n < nnz ; n ++ ) { for ( i = 0 ; i < order ; i ++ ) { j = IndexMat [ n ] [ i ] ; CountMat [ i ] [ j + 1 ] ++ ; tempMat [ i ] [ j + 1 ] ++ ; } } for ( i = 0 ; i < order ; i ++ ) { for ( j = 1 ; j < Dims [ i ] + 1 ; j ++ ) { CountMat [ i ] [ j ] += CountMat [ i ] [ j - 1 ] ; tempMat [ i ] [ j ] += tempMat [ i ] [ j - 1 ] ; } } for ( n = 0 ; n < nnz ; n ++ ) { for ( i = 0 ; i < order ; i ++ ) { j = IndexMat [ n ] [ i ] ; int now = tempMat [ i ] [ j ] ; WhereMat [ i ] [ now ] = n ; tempMat [ i ] [ j ] ++ ; } } free ( tempMat [ 0 ] ) ; free ( tempMat ) ; }
Complete all the internal structures of a tensor
Complete all the internal structures of a tensor