void svdWriteDenseMatrix(DMat D, char *filename, int format) { SMat S = NULL; FILE *file = svd_writeFile(filename, FALSE); if (!file) { svd_error("svdWriteDenseMatrix: failed to write file %s\n", filename); return; } switch (format) { case SVD_F_STH: S = svdConvertDtoS(D); svdWriteSparseTextHBFile(S, file); break; case SVD_F_ST: S = svdConvertDtoS(D); svdWriteSparseTextFile(S, file); break; case SVD_F_SB: S = svdConvertDtoS(D); svdWriteSparseBinaryFile(S, file); break; case SVD_F_DT: svdWriteDenseTextFile(D, file); break; case SVD_F_DB: svdWriteDenseBinaryFile(D, file); break; default: svd_error("svdLoadSparseMatrix: unknown format %d", format); } svd_closeFile(file); if (S) svdFreeSMat(S); }
DMat svdLoadDenseMatrix(char *filename, int format) { SMat S = NULL; DMat D = NULL; FILE *file = svd_fatalReadFile(filename); switch (format) { case SVD_F_STH: S = svdLoadSparseTextHBFile(file); break; case SVD_F_ST: S = svdLoadSparseTextFile(file); break; case SVD_F_SB: S = svdLoadSparseBinaryFile(file); break; case SVD_F_DT: D = svdLoadDenseTextFile(file); break; case SVD_F_DB: D = svdLoadDenseBinaryFile(file); break; default: svd_error("svdLoadSparseMatrix: unknown format %d", format); } svd_closeFile(file); if (S) { D = svdConvertStoD(S); svdFreeSMat(S); } return D; }
double *svdLoadDenseArray(const char *filename, int *np, char binary) { int i, n; double *a; int nfound; FILE *file = svd_readFile(filename); if (!file) { svd_error("svdLoadDenseArray: failed to read %s", filename); return NULL; } if (binary) svd_readBinInt(file, np); else { nfound = fscanf(file, " %d", np); if (nfound == 0) svd_error("svdLoadDenseArray: didn't get np"); } n = *np; a = svd_doubleArray(n, FALSE, "svdLoadDenseArray: a"); if (!a) return NULL; if (binary) { float f; for (i = 0; i < n; i++) { svd_readBinFloat(file, &f); a[i] = f; } } else { for (i = 0; i < n; i++) { nfound = fscanf(file, " %lf\n", a + i); if (nfound == 0) svd_error("svdLoadDenseArray: didn't get value"); } } svd_closeFile(file); return a; }
double *svdLoadDenseArray(char *filename, int *np, char binary) { int i, n; double *a; FILE *file = svd_readFile(filename); if (!file) { svd_error("svdLoadDenseArray: failed to read %s", filename); return NULL; } if (binary) { svd_readBinInt(file, np); } else if (fscanf(file, " %d", np) != 1) { svd_error("svdLoadDenseArray: error reading %s", filename); svd_closeFile(file); return NULL; } n = *np; a = svd_doubleArray(n, FALSE, "svdLoadDenseArray: a"); if (!a) return NULL; if (binary) { float f; for (i = 0; i < n; i++) { svd_readBinFloat(file, &f); a[i] = f; } } else { for (i = 0; i < n; i++) { if (fscanf(file, " %lf\n", a + i) != 1) { svd_error("svdLoadDenseArray: error reading %s", filename); break; } } } svd_closeFile(file); return a; }
void svdWriteDenseArray(double *a, int n, char *filename, char binary) { int i; FILE *file = svd_writeFile(filename, FALSE); if (!file) return svd_error("svdWriteDenseArray: failed to write %s", filename); if (binary) { svd_writeBinInt(file, n); for (i = 0; i < n; i++) svd_writeBinFloat(file, (float) a[i]); } else { fprintf(file, "%d\n", n); for (i = 0; i < n; i++) fprintf(file, "%g\n", a[i]); } svd_closeFile(file); }