From 43de6a281b0b8fa8d81ad57af4e04c384b9a24e4 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 16 Jan 2022 11:46:27 -0800 Subject: [PATCH] SparseMatrix_symmetrize: take a C99 bool instead of an int --- cmd/gvmap/country_graph_coloring.c | 2 +- cmd/gvmap/make_map.c | 4 ++-- cmd/mingle/minglemain.cpp | 2 +- lib/edgepaint/node_distinct_coloring.c | 2 +- lib/mingle/edge_bundling.cpp | 2 +- lib/neatogen/call_tri.c | 5 +++-- lib/neatogen/overlap.c | 2 +- lib/sfdpgen/spring_electrical.c | 10 +++++----- lib/sfdpgen/stress_model.c | 2 +- lib/sfdpgen/uniform_stress.c | 2 +- lib/sparse/SparseMatrix.c | 17 +++++++++-------- lib/sparse/SparseMatrix.h | 3 ++- lib/sparse/clustering.c | 2 +- lib/sparse/mq.c | 2 +- 14 files changed, 30 insertions(+), 27 deletions(-) diff --git a/cmd/gvmap/country_graph_coloring.c b/cmd/gvmap/country_graph_coloring.c index a01579abf..4af049b81 100644 --- a/cmd/gvmap/country_graph_coloring.c +++ b/cmd/gvmap/country_graph_coloring.c @@ -116,7 +116,7 @@ static void country_graph_coloring_internal(int seed, SparseMatrix A, int **p){ start = clock(); assert(A->m == A->n); - A2 = SparseMatrix_symmetrize(A, TRUE); + A2 = SparseMatrix_symmetrize(A, true); ia = A2->ia; ja = A2->ja; /* Laplacian */ diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index a1014cc6c..9d8783afd 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -54,7 +54,7 @@ void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMat int iter_max = 100; {double *dist = NULL; - A = SparseMatrix_symmetrize(A0, FALSE); + A = SparseMatrix_symmetrize(A0, false); SparseMatrix_distance_matrix(A, 0, &dist); SparseMatrix_delete(A); A = SparseMatrix_from_dense(n, n, dist); @@ -1523,7 +1523,7 @@ int make_map_from_rectangle_groups(int exclude_random, int include_OK_points, int *ia = graph->ia, *ja = graph->ja, nz = 0, jj; int KB; - graph = SparseMatrix_symmetrize(graph, TRUE); + graph = SparseMatrix_symmetrize(graph, true); ia = graph->ia; ja = graph->ja; dist=avgdist = 0.; for (i = 0; i < n; i++){ diff --git a/cmd/mingle/minglemain.cpp b/cmd/mingle/minglemain.cpp index 018359211..42e4f1def 100644 --- a/cmd/mingle/minglemain.cpp +++ b/cmd/mingle/minglemain.cpp @@ -402,7 +402,7 @@ bundle (Agraph_t* g, opts_t* opts) return 1; } - A = SparseMatrix_symmetrize(A, TRUE); + A = SparseMatrix_symmetrize(A, true); if (opts->fmt == FMT_GV) { PointMap* pm = newPM(); /* map from node id pairs to edge index */ Agnode_t* n; diff --git a/lib/edgepaint/node_distinct_coloring.c b/lib/edgepaint/node_distinct_coloring.c index 8cdf14907..0aae70d18 100644 --- a/lib/edgepaint/node_distinct_coloring.c +++ b/lib/edgepaint/node_distinct_coloring.c @@ -260,7 +260,7 @@ int node_distinct_coloring(char *color_scheme, char *lightness, bool weightedQ, } ctmp = MALLOC(sizeof(double)*cdim*n); - B = SparseMatrix_symmetrize(A, FALSE); + B = SparseMatrix_symmetrize(A, false); A = B; SparseMatrix_weakly_connected_components(A, &ncomps, &comps, &comps_ptr); diff --git a/lib/mingle/edge_bundling.cpp b/lib/mingle/edge_bundling.cpp index b328b801d..098e810bd 100644 --- a/lib/mingle/edge_bundling.cpp +++ b/lib/mingle/edge_bundling.cpp @@ -636,7 +636,7 @@ pedge* edge_bundling(SparseMatrix A0, int dim, double *x, int maxit_outer, doubl edges[i] = pedge_new(2, dim, &x[dim*2*i]); } - A = SparseMatrix_symmetrize(A0, TRUE); + A = SparseMatrix_symmetrize(A0, true); diff --git a/lib/neatogen/call_tri.c b/lib/neatogen/call_tri.c index 67e8bcbf0..2c97b361e 100644 --- a/lib/neatogen/call_tri.c +++ b/lib/neatogen/call_tri.c @@ -15,6 +15,7 @@ #include #include #include +#include SparseMatrix call_tri(int n, int dim, double * x) { @@ -52,7 +53,7 @@ SparseMatrix call_tri(int n, int dim, double * x) } B = SparseMatrix_from_coordinate_format(A); SparseMatrix_delete(A); - A = SparseMatrix_symmetrize(B, FALSE); + A = SparseMatrix_symmetrize(B, false); SparseMatrix_delete(B); B = A; @@ -93,7 +94,7 @@ SparseMatrix call_tri2(int n, int dim, double * xx) SparseMatrix_coordinate_form_add_entries(A, 1, &i, &i, &one); } B = SparseMatrix_from_coordinate_format(A); - B = SparseMatrix_symmetrize(B, FALSE); + B = SparseMatrix_symmetrize(B, false); SparseMatrix_delete(A); free (x); diff --git a/lib/neatogen/overlap.c b/lib/neatogen/overlap.c index c5f33bc47..f94b24343 100644 --- a/lib/neatogen/overlap.c +++ b/lib/neatogen/overlap.c @@ -244,7 +244,7 @@ check_overlap_RETURN: B = SparseMatrix_from_coordinate_format(A); SparseMatrix_delete(A); - A = SparseMatrix_symmetrize(B, FALSE); + A = SparseMatrix_symmetrize(B, false); SparseMatrix_delete(B); if (Verbose) fprintf(stderr, "found %d clashes\n", A->nz); return A; diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index d1c1dda6e..807c8d3c1 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -517,7 +517,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica goto RETURN; } assert(A->format == FORMAT_CSR); - A = SparseMatrix_symmetrize(A, TRUE); + A = SparseMatrix_symmetrize(A, true); ia = A->ia; ja = A->ja; @@ -711,7 +711,7 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el goto RETURN; } assert(A->format == FORMAT_CSR); - A = SparseMatrix_symmetrize(A, TRUE); + A = SparseMatrix_symmetrize(A, true); ia = A->ia; ja = A->ja; @@ -955,7 +955,7 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con goto RETURN; } assert(A->format == FORMAT_CSR); - A = SparseMatrix_symmetrize(A, TRUE); + A = SparseMatrix_symmetrize(A, true); ia = A->ia; ja = A->ja; @@ -1256,7 +1256,7 @@ static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, sp assert(A->format == FORMAT_CSR); - A = SparseMatrix_symmetrize(A, TRUE); + A = SparseMatrix_symmetrize(A, true); ia = A->ia; ja = A->ja; if (D){ @@ -1478,7 +1478,7 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D goto RETURN; } assert(A->format == FORMAT_CSR); - A = SparseMatrix_symmetrize(A, TRUE); + A = SparseMatrix_symmetrize(A, true); ia = A->ia; ja = A->ja; id = D->ia; diff --git a/lib/sfdpgen/stress_model.c b/lib/sfdpgen/stress_model.c index e1cfde98f..f7c978255 100644 --- a/lib/sfdpgen/stress_model.c +++ b/lib/sfdpgen/stress_model.c @@ -14,7 +14,7 @@ static void stress_model_core(int dim, SparseMatrix B, double **x, int edge_len_ if (!SparseMatrix_is_symmetric(A, false) || A->type != MATRIX_TYPE_REAL){ if (A->type == MATRIX_TYPE_REAL){ - A = SparseMatrix_symmetrize(A, FALSE); + A = SparseMatrix_symmetrize(A, false); A = SparseMatrix_remove_diagonal(A); } else { A = SparseMatrix_get_real_adjacency_matrix_symmetrized(A); diff --git a/lib/sfdpgen/uniform_stress.c b/lib/sfdpgen/uniform_stress.c index f06a091ce..ac3cd8153 100644 --- a/lib/sfdpgen/uniform_stress.c +++ b/lib/sfdpgen/uniform_stress.c @@ -113,7 +113,7 @@ static SparseMatrix get_distance_matrix(SparseMatrix A, double scaling){ int i; if (A->type == MATRIX_TYPE_REAL){ - B = SparseMatrix_symmetrize(A, FALSE); + B = SparseMatrix_symmetrize(A, false); } else { B = SparseMatrix_get_real_adjacency_matrix_symmetrized(A); } diff --git a/lib/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index 1625f40be..4f4d51859 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -58,7 +58,7 @@ SparseMatrix SparseMatrix_sort(SparseMatrix A){ SparseMatrix SparseMatrix_make_undirected(SparseMatrix A){ /* make it strictly low diag only, and set flag to undirected */ SparseMatrix B; - B = SparseMatrix_symmetrize(A, FALSE); + B = SparseMatrix_symmetrize(A, false); SparseMatrix_set_undirected(B); return SparseMatrix_remove_upper(B); } @@ -144,9 +144,10 @@ SparseMatrix SparseMatrix_transpose(SparseMatrix A){ return B; } -SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, int pattern_symmetric_only){ +SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, + bool pattern_symmetric_only) { SparseMatrix B; - if (SparseMatrix_is_symmetric(A, pattern_symmetric_only != 0)) return SparseMatrix_copy(A); + if (SparseMatrix_is_symmetric(A, pattern_symmetric_only)) return SparseMatrix_copy(A); B = SparseMatrix_transpose(A); if (!B) return NULL; A = SparseMatrix_add(A, B); @@ -1855,7 +1856,7 @@ SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A){ memcpy(B->ja, ja, sizeof(int)*((size_t)nz)); B->nz = A->nz; - A = SparseMatrix_symmetrize(B, TRUE); + A = SparseMatrix_symmetrize(B, true); SparseMatrix_delete(B); A = SparseMatrix_remove_diagonal(A); A->a = MALLOC(sizeof(double)*((size_t)(A->nz))); @@ -1984,7 +1985,7 @@ void SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int * int m = A->m, i, nn; if (!SparseMatrix_is_symmetric(A, true)){ - A = SparseMatrix_symmetrize(A, TRUE); + A = SparseMatrix_symmetrize(A, true); } if (!(*comps_ptr)) *comps_ptr = MALLOC(sizeof(int)*((size_t)(m+1))); @@ -2526,7 +2527,7 @@ int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, double **dist0){ double dmax; if (!SparseMatrix_is_symmetric(D, false)){ - D = SparseMatrix_symmetrize(D, FALSE); + D = SparseMatrix_symmetrize(D, false); } assert(m == n); @@ -2580,7 +2581,7 @@ SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix D0, int double dmax, dtmp; if (!SparseMatrix_is_symmetric(D, false)){ - D = SparseMatrix_symmetrize(D, FALSE); + D = SparseMatrix_symmetrize(D, false); } assert(m == n); @@ -2655,7 +2656,7 @@ SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix D0, int . may be there is a better way to ensure symmetric, but for now we just symmetrize it */ - D = SparseMatrix_symmetrize(C, FALSE); + D = SparseMatrix_symmetrize(C, false); SparseMatrix_delete(C); return D; diff --git a/lib/sparse/SparseMatrix.h b/lib/sparse/SparseMatrix.h index e4544c02d..e84628a12 100644 --- a/lib/sparse/SparseMatrix.h +++ b/lib/sparse/SparseMatrix.h @@ -71,7 +71,8 @@ SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A, int what_to_sum); SparseMatrix SparseMatrix_coordinate_form_add_entries(SparseMatrix A, int nentries, int *irn, 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, int pattern_symmetric_only); +SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, + bool pattern_symmetric_only); SparseMatrix SparseMatrix_symmetrize_nodiag(SparseMatrix A); void SparseMatrix_multiply_vector(SparseMatrix A, double *v, double **res, int transposed);/* if v = NULL, v is assumed to be {1,1,...,1}*/ SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A); diff --git a/lib/sparse/clustering.c b/lib/sparse/clustering.c index d6dcd4ebb..26501b8b9 100644 --- a/lib/sparse/clustering.c +++ b/lib/sparse/clustering.c @@ -370,7 +370,7 @@ void modularity_clustering(SparseMatrix A, int inplace, int ncluster_target, int assert(A->m == A->n); - B = SparseMatrix_symmetrize(A, FALSE); + B = SparseMatrix_symmetrize(A, false); if (!inplace && B == A) { B = SparseMatrix_copy(A); diff --git a/lib/sparse/mq.c b/lib/sparse/mq.c index e58ffc3e4..3e6d7235c 100644 --- a/lib/sparse/mq.c +++ b/lib/sparse/mq.c @@ -607,7 +607,7 @@ void mq_clustering(SparseMatrix A, int inplace, int maxcluster, int use_value, assert(A->m == A->n); - B = SparseMatrix_symmetrize(A, FALSE); + B = SparseMatrix_symmetrize(A, false); if (!inplace && B == A) { B = SparseMatrix_copy(A); -- 2.40.0