model-layer/scalable-tf-module/FTcom/util.cpp
/* Save the factor matrices and the core tensor in the result path */
Save the factor matrices and the core tensor in the result path
Save the factor matrices and the core tensor in the result path
void Print(double ***FactorMat, Tensor &G, int *Dims) {
	printf("Writing all the factor matrices and the core tensor to file ... ");
	char temp[1024];
	int i, j, k = 0;
	char *ResultPath = Option::resultPath;
	int order = Option::tensorOrder;
	for (i = 0; i < order; i++) {
		sprintf(temp, "%s/FACTOR%d", ResultPath, i);
		FILE *fp_factor = fopen(temp, "w");
		for (j = 0; j < Dims[i]; j++) {
			for (k = 0; k < G.Dims[i]; k++) {
				fprintf(fp_factor, "%e\t", FactorMat[i][j][k]);
			}
			fprintf(fp_factor, "\n");
		}
	}
	sprintf(temp, "%s/CORETENSOR", ResultPath);
	FILE *fp_core = fopen(temp, "w");
	for (i = 0; i < G.nnz; i++) {
		for (j = 0; j < order; j++) {
			fprintf(fp_core, "%d\t", G.IndexMat[i][j]);
		}
		fprintf(fp_core, "%e\n", G.val[i]);
	}
	printf("Done\n");
	free(Dims);
}
void Print ( double * * * FactorMat , Tensor & G , int * Dims ) { printf ( " " ) ; char temp [ 1024 ] ; int i , j , k = 0 ; char * ResultPath = Option :: resultPath ; int order = Option :: tensorOrder ; for ( i = 0 ; i < order ; i ++ ) { sprintf ( temp , " " , ResultPath , i ) ; FILE * fp_factor = fopen ( temp , " " ) ; for ( j = 0 ; j < Dims [ i ] ; j ++ ) { for ( k = 0 ; k < G . Dims [ i ] ; k ++ ) { fprintf ( fp_factor , " \t " , FactorMat [ i ] [ j ] [ k ] ) ; } fprintf ( fp_factor , " \n " ) ; } } sprintf ( temp , " " , ResultPath ) ; FILE * fp_core = fopen ( temp , " " ) ; for ( i = 0 ; i < G . nnz ; i ++ ) { for ( j = 0 ; j < order ; j ++ ) { fprintf ( fp_core , " \t " , G . IndexMat [ i ] [ j ] ) ; } fprintf ( fp_core , " \n " , G . val [ i ] ) ; } printf ( " \n " ) ; free ( Dims ) ; }
Save the factor matrices and the core tensor in the result path
Save the factor matrices and the core tensor in the result path