]> granicus.if.org Git - graphviz/commitdiff
sparse SparseMatrix_get_submatrix: use cgraph wrappers for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 15 Sep 2022 01:10:43 +0000 (18:10 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 20 Sep 2022 14:36:59 +0000 (07:36 -0700)
The lib/cgraph/alloc.h wrappers are similar to the older lib/common/memory.h
wrappers except (1) they are header-only and (2) they live in a directory
(cgraph) that is at the root of the dependency tree. The long term plan is to
replace all use of lib/common/memory.h with lib/cgraph/alloc.h.

lib/sparse/SparseMatrix.c

index 321958796f307054b17a70540f6a1944609188a3..b67a9cfcea5c4771b5004b9e8fe04a6dbfece89f 100644 (file)
@@ -2185,8 +2185,8 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int
 
   
 
-  rmask = MALLOC(sizeof(int)*((size_t)m));
-  cmask = MALLOC(sizeof(int)*((size_t)n));
+  rmask = gv_calloc((size_t)m, sizeof(int));
+  cmask = gv_calloc((size_t)n, sizeof(int));
   for (i = 0; i < m; i++) rmask[i] = -1;
   for (i = 0; i < n; i++) cmask[i] = -1;
 
@@ -2227,9 +2227,9 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int
   case MATRIX_TYPE_REAL:{
     double *a = (double*) A->a;
     double *val;
-    irn = MALLOC(sizeof(int)*((size_t)nz));
-    jcn = MALLOC(sizeof(int)*((size_t)nz));
-    val = MALLOC(sizeof(double)*((size_t)nz));
+    irn = gv_calloc((size_t)nz, sizeof(int));
+    jcn = gv_calloc((size_t)nz, sizeof(int));
+    val = gv_calloc((size_t)nz, sizeof(double));
 
     nz = 0;
     for (i = 0; i < m; i++){
@@ -2248,9 +2248,9 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int
     double *a = (double*) A->a;
     double *val;
 
-    irn = MALLOC(sizeof(int)*((size_t)nz));
-    jcn = MALLOC(sizeof(int)*((size_t)nz));
-    val = MALLOC(sizeof(double)*2*((size_t)nz));
+    irn = gv_calloc((size_t)nz, sizeof(int));
+    jcn = gv_calloc((size_t)nz, sizeof(int));
+    val = gv_calloc(2 * (size_t)nz, sizeof(double));
 
     nz = 0;
     for (i = 0; i < m; i++){
@@ -2271,9 +2271,9 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int
     int *a = (int*) A->a;
     int *val;
 
-    irn = MALLOC(sizeof(int)*((size_t)nz));
-    jcn = MALLOC(sizeof(int)*((size_t)nz));
-    val = MALLOC(sizeof(int)*((size_t)nz));
+    irn = gv_calloc((size_t)nz, sizeof(int));
+    jcn = gv_calloc((size_t)nz, sizeof(int));
+    val = gv_calloc((size_t)nz, sizeof(int));
 
     nz = 0;
     for (i = 0; i < m; i++){
@@ -2290,8 +2290,8 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int
     break;
   }
   case MATRIX_TYPE_PATTERN:
-    irn = MALLOC(sizeof(int)*((size_t)nz));
-    jcn = MALLOC(sizeof(int)*((size_t)nz));
+    irn = gv_calloc((size_t)nz, sizeof(int));
+    jcn = gv_calloc((size_t)nz, sizeof(int));
     nz = 0;
      for (i = 0; i < m; i++){
       if (rmask[i] < 0) continue;