MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / mm_read_mtx_crd

Function mm_read_mtx_crd

test/mmio/mmio.c:279–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277************************************************************************/
278
279int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J,
280 double **val, MM_typecode *matcode) {
281 int ret_code;
282 FILE *f;
283
284 if (strcmp(fname, "stdin") == 0)
285 f = stdin;
286 else if ((f = fopen(fname, "r")) == NULL)
287 return MM_COULD_NOT_READ_FILE;
288
289 if ((ret_code = mm_read_banner(f, matcode)) != 0) return ret_code;
290
291 if (!(mm_is_valid(*matcode) && mm_is_sparse(*matcode) &&
292 mm_is_matrix(*matcode)))
293 return MM_UNSUPPORTED_TYPE;
294
295 if ((ret_code = mm_read_mtx_crd_size(f, M, N, nz)) != 0) return ret_code;
296
297 *I = (int *)malloc(*nz * sizeof(int));
298 *J = (int *)malloc(*nz * sizeof(int));
299 *val = NULL;
300
301 if (mm_is_complex(*matcode)) {
302 *val = (double *)malloc(*nz * 2 * sizeof(double));
303 ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode);
304 if (ret_code != 0) return ret_code;
305 } else if (mm_is_real(*matcode)) {
306 *val = (double *)malloc(*nz * sizeof(double));
307 ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode);
308 if (ret_code != 0) return ret_code;
309 }
310
311 else if (mm_is_pattern(*matcode)) {
312 ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode);
313 if (ret_code != 0) return ret_code;
314 }
315
316 if (f != stdin) fclose(f);
317 return 0;
318}
319
320int mm_write_banner(FILE *f, MM_typecode matcode) {
321 char *str = mm_typecode_to_str(matcode);

Callers

nothing calls this directly

Calls 4

mm_read_bannerFunction · 0.85
mm_is_validFunction · 0.85
mm_read_mtx_crd_sizeFunction · 0.85
mm_read_mtx_crd_dataFunction · 0.85

Tested by

no test coverage detected