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

Function mm_read_unsymmetric_sparse

test/mmio/mmio.c:16–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "mmio.h"
15
16int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
17 double **val_, int **I_, int **J_) {
18 FILE *f;
19 MM_typecode matcode;
20 int M, N, nz;
21 int i;
22 double *val;
23 int *I, *J;
24
25 if ((f = fopen(fname, "r")) == NULL) return -1;
26
27 if (mm_read_banner(f, &matcode) != 0) {
28 printf("mm_read_unsymetric: Could not process Matrix Market banner ");
29 printf(" in file [%s]\n", fname);
30 return -1;
31 }
32
33 if (!(mm_is_real(matcode) && mm_is_matrix(matcode) &&
34 mm_is_sparse(matcode))) {
35 fprintf(stderr, "Sorry, this application does not support ");
36 fprintf(stderr, "Market Market type: [%s]\n",
37 mm_typecode_to_str(matcode));
38 return -1;
39 }
40
41 /* find out size of sparse matrix: M, N, nz .... */
42
43 if (mm_read_mtx_crd_size(f, &M, &N, &nz) != 0) {
44 fprintf(stderr,
45 "read_unsymmetric_sparse(): could not parse matrix size.\n");
46 return -1;
47 }
48
49 *M_ = M;
50 *N_ = N;
51 *nz_ = nz;
52
53 /* reseve memory for matrices */
54
55 I = (int *)malloc(nz * sizeof(int));
56 J = (int *)malloc(nz * sizeof(int));
57 val = (double *)malloc(nz * sizeof(double));
58
59 *val_ = val;
60 *I_ = I;
61 *J_ = J;
62
63 /* NOTE: when reading in doubles, ANSI C requires the use of the "l" */
64 /* specifier as in "%lg", "%lf", "%le", otherwise errors will occur */
65 /* (ANSI C X3.159-1989, Sec. 4.9.6.2, p. 136 lines 13-15) */
66
67 for (i = 0; i < nz; i++) {
68 fscanf(f, "%d %d %lg\n", &I[i], &J[i], &val[i]);
69 I[i]--; /* adjust from 1-based to 0-based */
70 J[i]--;
71 }
72 fclose(f);
73

Callers

nothing calls this directly

Calls 3

mm_read_bannerFunction · 0.85
mm_typecode_to_strFunction · 0.85
mm_read_mtx_crd_sizeFunction · 0.85

Tested by

no test coverage detected