From e65edd17a627b98c7264ea5c6ebe275fff300341 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 22 May 2022 17:54:34 -0700 Subject: [PATCH] sparse: take 'jcn' as a value instead of pointer --- cmd/gvmap/country_graph_coloring.c | 4 ++-- cmd/gvmap/make_map.c | 30 +++++++++++++------------- lib/edgepaint/edge_distinct_coloring.c | 4 ++-- lib/mingle/agglomerative_bundling.cpp | 2 +- lib/mingle/edge_bundling.cpp | 6 +++--- lib/neatogen/call_tri.c | 12 +++++------ lib/neatogen/overlap.c | 2 +- lib/sparse/SparseMatrix.c | 10 ++++----- lib/sparse/SparseMatrix.h | 2 +- lib/sparse/clustering.c | 2 +- lib/sparse/mq.c | 2 +- 11 files changed, 37 insertions(+), 39 deletions(-) diff --git a/cmd/gvmap/country_graph_coloring.c b/cmd/gvmap/country_graph_coloring.c index 0102ddad2..f5ad497e5 100644 --- a/cmd/gvmap/country_graph_coloring.c +++ b/cmd/gvmap/country_graph_coloring.c @@ -127,10 +127,10 @@ static void country_graph_coloring_internal(int seed, SparseMatrix A, int **p){ jj = ja[j]; if (jj != i){ nrow ++; - L = SparseMatrix_coordinate_form_add_entry(L, i, &jj, &a); + L = SparseMatrix_coordinate_form_add_entry(L, i, jj, &a); } } - L = SparseMatrix_coordinate_form_add_entry(L, i, &i, &nrow); + L = SparseMatrix_coordinate_form_add_entry(L, i, i, &nrow); } L = SparseMatrix_from_coordinate_format(L); diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index 3cac241c5..602808711 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -207,8 +207,8 @@ static SparseMatrix matrix_add_entry(SparseMatrix A, int i, int j, int val){ if (i < j) { i1 = j; j1 = i; } - A = SparseMatrix_coordinate_form_add_entry(A, j1, &i1, &val); - return SparseMatrix_coordinate_form_add_entry(A, i1, &j1, &val); + A = SparseMatrix_coordinate_form_add_entry(A, j1, i1, &val); + return SparseMatrix_coordinate_form_add_entry(A, i1, j1, &val); } static void plot_dot_edges(FILE *f, SparseMatrix A){ @@ -428,12 +428,12 @@ static SparseMatrix get_country_graph(int n, SparseMatrix A, int *groups, int GR ja = A->ja; for (i = 0; i < n; i++){ ig1 = groups[i]-1;/* add a diagonal entry */ - SparseMatrix_coordinate_form_add_entry(B, ig1, &ig1, &one); + SparseMatrix_coordinate_form_add_entry(B, ig1, ig1, &one); for (j = ia[i]; j < ia[i+1]; j++){ jj = ja[j]; if (i != jj && groups[i] != groups[jj] && groups[jj] != GRP_RANDOM && groups[jj] != GRP_BBOX){ ig1 = groups[i]-1; ig2 = groups[jj]-1; - SparseMatrix_coordinate_form_add_entry(B, ig1, &ig2, &one); + SparseMatrix_coordinate_form_add_entry(B, ig1, ig2, &one); } } } @@ -456,7 +456,7 @@ static void conn_comp(int n, SparseMatrix A, int *groups, SparseMatrix *poly_poi for (j = ia[i]; j < ia[i+1]; j++){ jj = ja[j]; if (i != jj && groups[i] == groups[jj]){ - SparseMatrix_coordinate_form_add_entry(B, i, &jj, &one); + SparseMatrix_coordinate_form_add_entry(B, i, jj, &one); } } } @@ -591,7 +591,7 @@ static void get_poly_lines(int exclude_random, int nt, SparseMatrix graph, Spars } else { ipoly2 = ipoly; } - SparseMatrix_coordinate_form_add_entry(*poly_lines, i, &cur, &ipoly2); + SparseMatrix_coordinate_form_add_entry(*poly_lines, i, cur, &ipoly2); while (next != sta){ mask[next] = i; @@ -600,7 +600,7 @@ static void get_poly_lines(int exclude_random, int nt, SparseMatrix graph, Spars } else { ipoly2 = ipoly; } - SparseMatrix_coordinate_form_add_entry(*poly_lines, i, &next, &ipoly2); + SparseMatrix_coordinate_form_add_entry(*poly_lines, i, next, &ipoly2); nn = neighbor(next, 0, edim, elist); nlink = 0; @@ -619,7 +619,7 @@ static void get_poly_lines(int exclude_random, int nt, SparseMatrix graph, Spars } else { ipoly2 = ipoly; } - SparseMatrix_coordinate_form_add_entry(*poly_lines, i, &sta, &ipoly2);/* complete a cycle by adding starting point */ + SparseMatrix_coordinate_form_add_entry(*poly_lines, i, sta, &ipoly2);/* complete a cycle by adding starting point */ ipoly++; } @@ -732,14 +732,14 @@ static void get_polygon_solids(int nt, SparseMatrix E, int ncomps, int *comps_pt assert(jj < n); edge_table[ne*2] = t1;/*t1->t2*/ edge_table[ne*2+1] = t2; - half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, i, &jj, &ne); - half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, jj, &i, &ne); + half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, i, jj, &ne); + half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, jj, i, &ne); ne++; edge_table[ne*2] = t2;/*t2->t1*/ edge_table[ne*2+1] = t1; - half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, i, &jj, &ne); - half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, jj, &i, &ne); + half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, i, jj, &ne); + half_edges = SparseMatrix_coordinate_form_add_entry(half_edges, jj, i, &ne); ne++; @@ -918,13 +918,13 @@ static void get_polygon_solids(int nt, SparseMatrix E, int ncomps, int *comps_pt while ((enext = cycle_next(ecur)) != cycle_head){ edge_cycle_map[ecur] = NOT_ON_CYCLE; head = edge_head(ecur); - SparseMatrix_coordinate_form_add_entry(*polys, i, &head, &i); + SparseMatrix_coordinate_form_add_entry(*polys, i, head, &i); ecur = enext; } edge_cycle_map[ecur] = NOT_ON_CYCLE; head = edge_head(ecur); tail = edge_tail(ecur); - SparseMatrix_coordinate_form_add_entry(*polys, i, &head, &i); - SparseMatrix_coordinate_form_add_entry(*polys, i, &tail, &i); + SparseMatrix_coordinate_form_add_entry(*polys, i, head, &i); + SparseMatrix_coordinate_form_add_entry(*polys, i, tail, &i); /* unset edge_map */ diff --git a/lib/edgepaint/edge_distinct_coloring.c b/lib/edgepaint/edge_distinct_coloring.c index 123c5b1d5..317045961 100644 --- a/lib/edgepaint/edge_distinct_coloring.c +++ b/lib/edgepaint/edge_distinct_coloring.c @@ -200,7 +200,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* for (j = i+1; j < nz2; j++){ u2 = irn[j]; v2 = jcn[j]; if (splines_intersect(dim, u1, v1, u2, v2, cos_critical, check_edges_with_same_endpoint, xsplines[i], xsplines[j])){ - B = SparseMatrix_coordinate_form_add_entry(B, i, &j, &cos_a); + B = SparseMatrix_coordinate_form_add_entry(B, i, j, &cos_a); } } } @@ -222,7 +222,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* cos_a = intersection_angle(&(x[dim*u1]), &(x[dim*v1]), &(x[dim*u2]), &(x[dim*v2])); if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = fabs(cos_a); if (cos_a > cos_critical) { - B = SparseMatrix_coordinate_form_add_entry(B, i, &j, &cos_a); + B = SparseMatrix_coordinate_form_add_entry(B, i, j, &cos_a); } } } diff --git a/lib/mingle/agglomerative_bundling.cpp b/lib/mingle/agglomerative_bundling.cpp index db6cc0cf7..3420279f4 100644 --- a/lib/mingle/agglomerative_bundling.cpp +++ b/lib/mingle/agglomerative_bundling.cpp @@ -240,7 +240,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera R1 = SparseMatrix_new(nc, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); for (i = 0; i < n; i++){ jj = matching[i]; - SparseMatrix_coordinate_form_add_entry(R1, jj, &i, &one); + SparseMatrix_coordinate_form_add_entry(R1, jj, i, &one); } R = SparseMatrix_from_coordinate_format(R1); SparseMatrix_delete(R1); diff --git a/lib/mingle/edge_bundling.cpp b/lib/mingle/edge_bundling.cpp index 97c854405..0d232e73e 100644 --- a/lib/mingle/edge_bundling.cpp +++ b/lib/mingle/edge_bundling.cpp @@ -535,7 +535,7 @@ static pedge* modularity_ink_bundling(int dim, int ne, SparseMatrix B, pedge* ed for (i = 0; i < ne; i++){ jj = assignment[i]; - SparseMatrix_coordinate_form_add_entry(C, jj, &i, NULL); + SparseMatrix_coordinate_form_add_entry(C, jj, i, NULL); } D = SparseMatrix_from_coordinate_format(C); @@ -590,8 +590,8 @@ static SparseMatrix check_compatibility(SparseMatrix A, int ne, pedge *edges, in } if (fabs(dist) > tol){ - B = SparseMatrix_coordinate_form_add_entry(B, i, &jj, &dist); - B = SparseMatrix_coordinate_form_add_entry(B, jj, &i, &dist); + B = SparseMatrix_coordinate_form_add_entry(B, i, jj, &dist); + B = SparseMatrix_coordinate_form_add_entry(B, jj, i, &dist); } } } diff --git a/lib/neatogen/call_tri.c b/lib/neatogen/call_tri.c index 24ec0a61c..419ef40de 100644 --- a/lib/neatogen/call_tri.c +++ b/lib/neatogen/call_tri.c @@ -41,15 +41,15 @@ SparseMatrix call_tri(int n, int dim, double * x) for (i = 0; i < numberofedges; i++) { ii = edgelist[i * 2]; jj = edgelist[i * 2 + 1]; - SparseMatrix_coordinate_form_add_entry(A, ii, &(jj), &one); + SparseMatrix_coordinate_form_add_entry(A, ii, jj, &one); } if (n == 2) { /* if two points, add edge i->j */ ii = 0; jj = 1; - SparseMatrix_coordinate_form_add_entry(A, ii, &(jj), &one); + SparseMatrix_coordinate_form_add_entry(A, ii, jj, &one); } for (i = 0; i < n; i++) { - SparseMatrix_coordinate_form_add_entry(A, i, &i, &one); + SparseMatrix_coordinate_form_add_entry(A, i, i, &one); } B = SparseMatrix_from_coordinate_format(A); SparseMatrix_delete(A); @@ -85,13 +85,11 @@ SparseMatrix call_tri2(int n, int dim, double * xx) for (i = 0; i < n; i++) { for (j = 1; j < delaunay[i].nedges; j++) { - SparseMatrix_coordinate_form_add_entry(A, i, - &(delaunay[i]. - edges[j]), &one); + SparseMatrix_coordinate_form_add_entry(A, i, delaunay[i].edges[j], &one); } } for (i = 0; i < n; i++) { - SparseMatrix_coordinate_form_add_entry(A, i, &i, &one); + SparseMatrix_coordinate_form_add_entry(A, i, i, &one); } B = SparseMatrix_from_coordinate_format(A); B = SparseMatrix_symmetrize(B, false); diff --git a/lib/neatogen/overlap.c b/lib/neatogen/overlap.c index 52a93755e..45999ee70 100644 --- a/lib/neatogen/overlap.c +++ b/lib/neatogen/overlap.c @@ -204,7 +204,7 @@ static SparseMatrix get_overlap_graph(int dim, int n, double *x, double *width, #endif if (neighbor != k){ if (fabs(0.5*(bsta+bsto) - 0.5*(bbsta+bbsto)) < 0.5*(bsto-bsta) + 0.5*(bbsto-bbsta)){/* if the distance of the centers of the interval is less than sum of width, we have overlap */ - A = SparseMatrix_coordinate_form_add_entry(A, neighbor, &k, &one); + A = SparseMatrix_coordinate_form_add_entry(A, neighbor, k, &one); #ifdef DEBUG_RBTREE fprintf(stderr,"====================================== %d %d\n",k,neighbor); #endif diff --git a/lib/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index c7ea69f89..f05d9a74c 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -1596,7 +1596,7 @@ SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A, int what_to_sum){ } SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn, - int *jcn, void *val) { + int jcn, void *val) { int nz, nzmax; static const int nentries = 1; @@ -1610,10 +1610,10 @@ SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn, A = SparseMatrix_realloc(A, nzmax); } A->ia[nz] = irn; - A->ja[nz] = *jcn; + A->ja[nz] = jcn; if (A->size) memcpy((char*) A->a + ((size_t)nz)*A->size/sizeof(char), val, A->size*((size_t)nentries)); if (irn >= A->m) A->m = irn + 1; - if (jcn[0] >= A->n) A->n = jcn[0] + 1; + if (jcn >= A->n) A->n = jcn + 1; A->nz += nentries; return A; } @@ -2594,7 +2594,7 @@ SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix D0, int for (i = 0; i < nlevel; i++) { for (j = levelset_ptr[i]; j < levelset_ptr[i+1]; j++){ itmp = levelset[j]; dtmp = i; - if (k != itmp) B = SparseMatrix_coordinate_form_add_entry(B, k, &itmp, &dtmp); + if (k != itmp) B = SparseMatrix_coordinate_form_add_entry(B, k, itmp, &dtmp); } } } @@ -2629,7 +2629,7 @@ SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix D0, int } for (j = 0; j < nlist; j++){ itmp = list[j]; dtmp = dist[itmp]; - if (k != itmp) B = SparseMatrix_coordinate_form_add_entry(B, k, &itmp, &dtmp); + if (k != itmp) B = SparseMatrix_coordinate_form_add_entry(B, k, itmp, &dtmp); } } } diff --git a/lib/sparse/SparseMatrix.h b/lib/sparse/SparseMatrix.h index ce03b89e3..7c0840a0c 100644 --- a/lib/sparse/SparseMatrix.h +++ b/lib/sparse/SparseMatrix.h @@ -69,7 +69,7 @@ SparseMatrix SparseMatrix_multiply3(SparseMatrix A, SparseMatrix B, SparseMatrix enum {SUM_REPEATED_NONE = 0, SUM_REPEATED_ALL, }; SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A, int what_to_sum); SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn, - int *jcn, void *val); + int jcn, void *val); int SparseMatrix_is_symmetric(SparseMatrix A, bool test_pattern_symmetry_only); SparseMatrix SparseMatrix_transpose(SparseMatrix A); SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, diff --git a/lib/sparse/clustering.c b/lib/sparse/clustering.c index 7e41b39e1..3aa64e41c 100644 --- a/lib/sparse/clustering.c +++ b/lib/sparse/clustering.c @@ -214,7 +214,7 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_establi R0 = SparseMatrix_new(nc, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); for (i = 0; i < n; i++){ jj = matching[i]; - SparseMatrix_coordinate_form_add_entry(R0, jj, &i, &one); + SparseMatrix_coordinate_form_add_entry(R0, jj, i, &one); } R = SparseMatrix_from_coordinate_format(R0); SparseMatrix_delete(R0); diff --git a/lib/sparse/mq.c b/lib/sparse/mq.c index 9e3ee3201..4f611f9fc 100644 --- a/lib/sparse/mq.c +++ b/lib/sparse/mq.c @@ -461,7 +461,7 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ R0 = SparseMatrix_new(nc, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); for (i = 0; i < n; i++){ jj = matching[i]; - SparseMatrix_coordinate_form_add_entry(R0, jj, &i, &one); + SparseMatrix_coordinate_form_add_entry(R0, jj, i, &one); } R = SparseMatrix_from_coordinate_format(R0); SparseMatrix_delete(R0); -- 2.40.0