MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / read_matrix

Function read_matrix

deps/GraphBLAS/Demo/Source/read_matrix.c:52–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50//------------------------------------------------------------------------------
51
52GB_PUBLIC
53GrB_Info read_matrix // read a double-precision or boolean matrix
54(
55 GrB_Matrix *A_output, // handle of matrix to create
56 FILE *f, // file to read the tuples from
57 bool make_symmetric, // if true, return A as symmetric
58 bool no_self_edges, // if true, then remove self edges from A
59 bool one_based, // if true, input matrix is 1-based
60 bool boolean, // if true, input is GrB_BOOL, otherwise GrB_FP64
61 bool pr // if true, print status to stdout
62)
63{
64
65 int64_t len = 256 ;
66 int64_t ntuples = 0 ;
67 double x ;
68 GrB_Index nvals ;
69
70 //--------------------------------------------------------------------------
71 // set all pointers to NULL so that FREE_ALL can free everything safely
72 //--------------------------------------------------------------------------
73
74 GrB_Matrix C = NULL, A = NULL, B = NULL ;
75 GrB_Descriptor dt1 = NULL, dt2 = NULL ;
76 GrB_UnaryOp scale2_op = NULL ;
77
78 //--------------------------------------------------------------------------
79 // allocate initial space for tuples
80 //--------------------------------------------------------------------------
81
82 size_t xsize = ((boolean) ? sizeof (bool) : sizeof (double)) ;
83 GrB_Index *I = (GrB_Index *) malloc (len * sizeof (GrB_Index)), *I2 = NULL ;
84 GrB_Index *J = (GrB_Index *) malloc (len * sizeof (GrB_Index)), *J2 = NULL ;
85 void *X = malloc (len * xsize) ;
86 bool *Xbool ;
87 double *Xdouble ;
88 void *X2 = NULL ;
89 if (I == NULL || J == NULL || X == NULL)
90 {
91 // out of memory
92 if (pr) printf ("out of memory for initial tuples\n") ;
93 FREE_ALL ;
94 return (GrB_OUT_OF_MEMORY) ;
95 }
96
97 Xbool = (bool *) X ;
98 Xdouble = (double *) X ;
99
100 //--------------------------------------------------------------------------
101 // read in the tuples from stdin, one per line
102 //--------------------------------------------------------------------------
103
104 // format warnings vary with compilers, so read in as double
105 double i2, j2 ;
106 while (fscanf (f, "%lg %lg %lg\n", &i2, &j2, &x) != EOF)
107 {
108 int64_t i = (int64_t) i2 ;
109 int64_t j = (int64_t) j2 ;

Callers 3

get_matrixFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 10

GrB_Matrix_newFunction · 0.85
GrB_Descriptor_newFunction · 0.85
GrB_Descriptor_setFunction · 0.85
GrB_Matrix_freeFunction · 0.85
GrB_Matrix_applyFunction · 0.85
GrB_UnaryOp_freeFunction · 0.85
GrB_Matrix_assignFunction · 0.85
GrB_Matrix_nvalsFunction · 0.85
GxB_Matrix_fprintFunction · 0.85

Tested by

no test coverage detected