From: erg Date: Thu, 1 May 2008 21:23:00 +0000 (+0000) Subject: Revert to pointer object syntax X-Git-Tag: LAST_LIBGRAPH~32^2~4106 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7bf237846a84497bbc0a501455f98a32ca098247;p=graphviz Revert to pointer object syntax --- diff --git a/lib/sfdpgen/LinkedList.c b/lib/sfdpgen/LinkedList.c index b2d509576..ecd6c7c1c 100644 --- a/lib/sfdpgen/LinkedList.c +++ b/lib/sfdpgen/LinkedList.c @@ -16,19 +16,19 @@ #include "LinkedList.h" #include "memory.h" -SingleLinkedList *SingleLinkedList_new(void *data) +SingleLinkedList SingleLinkedList_new(void *data) { - SingleLinkedList *head; - head = GNEW(SingleLinkedList); + SingleLinkedList head; + head = GNEW(struct SingleLinkedList_s); head->data = data; head->next = NULL; return head; } -void SingleLinkedList_delete(SingleLinkedList * head, +void SingleLinkedList_delete(SingleLinkedList head, void (*linklist_deallocator) (void *)) { - SingleLinkedList *next; + SingleLinkedList next; if (!head) return; @@ -44,20 +44,20 @@ void SingleLinkedList_delete(SingleLinkedList * head, } -SingleLinkedList *SingleLinkedList_prepend(SingleLinkedList * l, +SingleLinkedList SingleLinkedList_prepend(SingleLinkedList l, void *data) { - SingleLinkedList *head = SingleLinkedList_new(data); + SingleLinkedList head = SingleLinkedList_new(data); head->next = l; return head; } -void *SingleLinkedList_get_data(SingleLinkedList * l) +void *SingleLinkedList_get_data(SingleLinkedList l) { return l->data; } -SingleLinkedList *SingleLinkedList_get_next(SingleLinkedList * l) +SingleLinkedList SingleLinkedList_get_next(SingleLinkedList l) { return l->next; } diff --git a/lib/sfdpgen/LinkedList.h b/lib/sfdpgen/LinkedList.h index bd2cf3cba..f0568c2c7 100644 --- a/lib/sfdpgen/LinkedList.h +++ b/lib/sfdpgen/LinkedList.h @@ -16,19 +16,21 @@ #ifndef LINKED_LIST_H #define LINKED_LIST_H -typedef struct SingleLinkedList_s { +struct SingleLinkedList_s { void *data; struct SingleLinkedList_s *next; -} SingleLinkedList; +}; -SingleLinkedList *SingleLinkedList_new(void *data); -void SingleLinkedList_delete(SingleLinkedList * head, +typedef struct SingleLinkedList_s* SingleLinkedList; + +SingleLinkedList SingleLinkedList_new(void *data); +void SingleLinkedList_delete(SingleLinkedList head, void (*linklist_deallocator) (void *)); -SingleLinkedList *SingleLinkedList_prepend(SingleLinkedList * l, +SingleLinkedList SingleLinkedList_prepend(SingleLinkedList l, void *data); -void *SingleLinkedList_get_data(SingleLinkedList * l); +void *SingleLinkedList_get_data(SingleLinkedList l); -SingleLinkedList *SingleLinkedList_get_next(SingleLinkedList * l); +SingleLinkedList SingleLinkedList_get_next(SingleLinkedList l); #endif diff --git a/lib/sfdpgen/Multilevel.c b/lib/sfdpgen/Multilevel.c index ea719bbcd..ee6e2fb5b 100644 --- a/lib/sfdpgen/Multilevel.c +++ b/lib/sfdpgen/Multilevel.c @@ -19,11 +19,11 @@ #include "assert.h" #include "arith.h" -Multilevel_control *Multilevel_control_new() +Multilevel_control Multilevel_control_new() { - Multilevel_control *ctrl; + Multilevel_control ctrl; - ctrl = GNEW(Multilevel_control); + ctrl = GNEW(struct Multilevel_control_s); ctrl->minsize = 4; ctrl->min_coarsen_factor = 0.75; ctrl->maxlevel = 1 << 30; @@ -34,18 +34,18 @@ Multilevel_control *Multilevel_control_new() return ctrl; } -void Multilevel_control_delete(Multilevel_control * ctrl) +void Multilevel_control_delete(Multilevel_control ctrl) { free(ctrl); } -static Multilevel *Multilevel_init(SparseMatrix * A, real * node_weights) +static Multilevel Multilevel_init(SparseMatrix A, real * node_weights) { - Multilevel *grid; + Multilevel grid; if (!A) return NULL; assert(A->m == A->n); - grid = GNEW(Multilevel); + grid = GNEW(struct Multilevel_s); grid->level = 0; grid->n = A->n; grid->A = A; @@ -58,7 +58,7 @@ static Multilevel *Multilevel_init(SparseMatrix * A, real * node_weights) return grid; } -void Multilevel_delete(Multilevel * grid) +void Multilevel_delete(Multilevel grid) { if (!grid) return; @@ -106,7 +106,7 @@ static int *random_permutation(int n) return p; } -static void maximal_independent_vertex_set(SparseMatrix * A, int randomize, +static void maximal_independent_vertex_set(SparseMatrix A, int randomize, int **vset, int *nvset, int *nzc) { @@ -156,7 +156,7 @@ static void maximal_independent_vertex_set(SparseMatrix * A, int randomize, } -static void maximal_independent_edge_set(SparseMatrix * A, int randomize, +static void maximal_independent_edge_set(SparseMatrix A, int randomize, int **matching, int *nmatch) { int i, ii, j, *ia, *ja, m, n, *p = NULL; @@ -202,15 +202,9 @@ static void maximal_independent_edge_set(SparseMatrix * A, int randomize, } } - - -static void maximal_independent_edge_set_heavest_edge_pernode(SparseMatrix - * A, - int - randomize, - int - **matching, - int *nmatch) +static void +maximal_independent_edge_set_heavest_edge_pernode(SparseMatrix A, + int randomize, int **matching, int *nmatch) { int i, ii, j, *ia, *ja, m, n, *p = NULL; real *a, amax = 0; @@ -297,16 +291,12 @@ static void maximal_independent_edge_set_heavest_edge_pernode(SparseMatrix #define node_degree(i) (ia[(i)+1] - ia[(i)]) static void -maximal_independent_edge_set_heavest_edge_pernode_leaves_first(SparseMatrix - * A, - int - randomize, - int - **cluster, - int - **clusterp, - int - *ncluster) +maximal_independent_edge_set_heavest_edge_pernode_leaves_first( + SparseMatrix A, + int randomize, + int **cluster, + int **clusterp, + int *ncluster) { int i, ii, j, *ia, *ja, m, n, *p = NULL, q; real *a, amax = 0; @@ -497,7 +487,7 @@ maximal_independent_edge_set_heavest_edge_pernode_leaves_first(SparseMatrix static void maximal_independent_edge_set_heavest_edge_pernode_supernodes_first -(SparseMatrix * A, int randomize, int **cluster, int **clusterp, int *ncluster) +(SparseMatrix A, int randomize, int **cluster, int **clusterp, int *ncluster) { int i, ii, j, *ia, *ja, m, n, *p = NULL; real *a, amax = 0; @@ -651,7 +641,7 @@ static int scomp(const void *s1, const void *s2) static void maximal_independent_edge_set_heavest_cluster_pernode_leaves_first -(SparseMatrix * A, int csize, int randomize, int **cluster, int **clusterp, +(SparseMatrix A, int csize, int randomize, int **cluster, int **clusterp, int *ncluster) { int i, ii, j, *ia, *ja, m, n, *p = NULL, q, iv, ncmax; @@ -755,7 +745,7 @@ int *ncluster) free(matched); } static void -maximal_independent_edge_set_heavest_edge_pernode_scaled(SparseMatrix * A, +maximal_independent_edge_set_heavest_edge_pernode_scaled(SparseMatrix A, int randomize, int **matching, int *nmatch) @@ -850,16 +840,16 @@ maximal_independent_edge_set_heavest_edge_pernode_scaled(SparseMatrix * A, } } -static void Multilevel_coarsen(SparseMatrix * A, SparseMatrix * *cA, +static void Multilevel_coarsen(SparseMatrix A, SparseMatrix *cA, real * node_wgt, real ** cnode_wgt, - SparseMatrix * *P, SparseMatrix * *R, - Multilevel_control * ctrl, + SparseMatrix *P, SparseMatrix *R, + Multilevel_control ctrl, int *coarsen_scheme_used) { int *matching = NULL, nmatch, nc, nzc, n, i; int *irn = NULL, *jcn = NULL, *ia = NULL, *ja = NULL; real *val = NULL; - SparseMatrix *B = NULL; + SparseMatrix B = NULL; int *vset = NULL, nvset, ncov, j; int *cluster, *clusterp, ncluster; @@ -1131,13 +1121,13 @@ void print_padding(int n) for (i = 0; i < n; i++) fputs(" ", stderr); } -static Multilevel *Multilevel_establish(Multilevel * grid, - Multilevel_control * ctrl) +static Multilevel Multilevel_establish(Multilevel grid, + Multilevel_control ctrl) { - Multilevel *cgrid; + Multilevel cgrid; int coarsen_scheme_used; real *cnode_weights = NULL; - SparseMatrix *P, *R, *A, *cA; + SparseMatrix P, R, A, cA; #ifdef DEBUG_PRINT if (Verbose) { @@ -1176,11 +1166,11 @@ static Multilevel *Multilevel_establish(Multilevel * grid, } -Multilevel *Multilevel_new(SparseMatrix * A0, real * node_weights, - Multilevel_control * ctrl) +Multilevel Multilevel_new(SparseMatrix A0, real * node_weights, + Multilevel_control ctrl) { - Multilevel *grid; - SparseMatrix *A = A0; + Multilevel grid; + SparseMatrix A = A0; if (!SparseMatrix_is_symmetric(A, FALSE) || A->type != MATRIX_TYPE_REAL) { @@ -1194,7 +1184,7 @@ Multilevel *Multilevel_new(SparseMatrix * A0, real * node_weights, } -Multilevel *Multilevel_get_coarsest(Multilevel * grid) +Multilevel Multilevel_get_coarsest(Multilevel grid) { while (grid->next) { grid = grid->next; diff --git a/lib/sfdpgen/Multilevel.h b/lib/sfdpgen/Multilevel.h index a1299f2df..cc8f56b88 100644 --- a/lib/sfdpgen/Multilevel.h +++ b/lib/sfdpgen/Multilevel.h @@ -18,18 +18,20 @@ #include "SparseMatrix.h" -typedef struct Multilevel_s { +struct Multilevel_s { int level; /* 0, 1, ... */ int n; - SparseMatrix *A; - SparseMatrix *P; - SparseMatrix *R; + SparseMatrix A; + SparseMatrix P; + SparseMatrix R; real *node_weights; struct Multilevel_s *next; struct Multilevel_s *prev; int delete_top_level_A; int coarsen_scheme_used; /* to get from previous level to here */ -} Multilevel; +}; + +typedef struct Multilevel_s* Multilevel; enum { MAX_IND_VTX_SET_0 = -100, MAX_IND_VTX_SET_U = -1, MAX_IND_VTX_SET_C = 0 }; @@ -46,25 +48,26 @@ enum { EDGE_BASED_STA, COARSEN_INDEPENDENT_EDGE_SET, VERTEX_BASED_STO, COARSEN_HYBRID }; -typedef struct { +struct Multilevel_control_s { int minsize; real min_coarsen_factor; int maxlevel; int randomize; int coarsen_scheme; -} Multilevel_control; +}; +typedef struct Multilevel_control_s* Multilevel_control; -Multilevel_control *Multilevel_control_new(); +Multilevel_control Multilevel_control_new(); -void Multilevel_control_delete(Multilevel_control * ctrl); +void Multilevel_control_delete(Multilevel_control ctrl); -void Multilevel_delete(Multilevel * grid); +void Multilevel_delete(Multilevel grid); -Multilevel *Multilevel_new(SparseMatrix * A, real * node_weights, - Multilevel_control * ctrl); +Multilevel Multilevel_new(SparseMatrix A, real * node_weights, + Multilevel_control ctrl); -Multilevel *Multilevel_get_coarsest(Multilevel * grid); +Multilevel Multilevel_get_coarsest(Multilevel grid); void print_padding(int n); diff --git a/lib/sfdpgen/QuadTree.c b/lib/sfdpgen/QuadTree.c index 43cad8dbe..01810f2bc 100644 --- a/lib/sfdpgen/QuadTree.c +++ b/lib/sfdpgen/QuadTree.c @@ -87,14 +87,14 @@ int check_or_realloc_arrays(int dim, int nsuper, int nsupermax, return nsupermax; } -void QuadTree_get_supernodes_internal(QuadTree * qt, real bh, real * point, +void QuadTree_get_supernodes_internal(QuadTree qt, real bh, real * point, int nodeid, int *nsuper, int *nsupermax, real ** center, real ** supernode_wgts, real ** distances, real * counts, int *flag) { - SingleLinkedList *l; + SingleLinkedList l; real *coord, dist; int dim = qt->dim, i; @@ -144,7 +144,7 @@ void QuadTree_get_supernodes_internal(QuadTree * qt, real bh, real * point, } -void QuadTree_get_supernodes(QuadTree * qt, real bh, real * point, +void QuadTree_get_supernodes(QuadTree qt, real bh, real * point, int nodeid, int *nsuper, int *nsupermax, real ** center, real ** supernode_wgts, real ** distances, double *counts, int *flag) @@ -171,7 +171,7 @@ void QuadTree_get_supernodes(QuadTree * qt, real bh, real * point, -QuadTree *QuadTree_new_from_point_list(int dim, int n, int max_level, +QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, real * coord, real * weight) { /* form a new QuadTree data structure from a list of coordinates of n points @@ -179,7 +179,7 @@ QuadTree *QuadTree_new_from_point_list(int dim, int n, int max_level, weight: node weight of lentgth n. If NULL, unit weight assumed. */ real *xmin, *xmax, *center, width; - QuadTree *qt = NULL; + QuadTree qt = NULL; int i, k; xmin = N_GNEW(dim, real); @@ -225,11 +225,11 @@ QuadTree *QuadTree_new_from_point_list(int dim, int n, int max_level, return qt; } -QuadTree *QuadTree_new(int dim, real * center, real width, int max_level) +QuadTree QuadTree_new(int dim, real * center, real width, int max_level) { - QuadTree *q; + QuadTree q; int i; - q = GNEW(QuadTree); + q = GNEW(struct QuadTree_s); q->dim = dim; q->n = 0; q->center = N_GNEW(dim, real); @@ -245,7 +245,7 @@ QuadTree *QuadTree_new(int dim, real * center, real width, int max_level) return q; } -void QuadTree_delete(QuadTree * q) +void QuadTree_delete(QuadTree q) { int i, dim = q->dim; if (!q) @@ -281,7 +281,7 @@ static int QuadTree_get_quadrant(int dim, real * center, real * coord) return d; } -static QuadTree *QuadTree_add_internal(QuadTree * q, real * coord, +static QuadTree QuadTree_add_internal(QuadTree q, real * coord, real weight, int id, int level) { int i, dim = q->dim, ii, k; @@ -313,7 +313,7 @@ static QuadTree *QuadTree_add_internal(QuadTree * q, real * coord, q->average[i] = ((q->average[i]) * q->n + coord[i]) / (q->n + 1); if (!q->qts) { - q->qts = N_GNEW(1 << dim, QuadTree *); + q->qts = N_GNEW(1 << dim, QuadTree ); for (i = 0; i < 1 << dim; i++) { width = (q->width) / 2; q->qts[i] = @@ -375,7 +375,7 @@ static QuadTree *QuadTree_add_internal(QuadTree * q, real * coord, } -QuadTree *QuadTree_add(QuadTree * q, real * coord, real weight, int id) +QuadTree QuadTree_add(QuadTree q, real * coord, real weight, int id) { if (!q) return q; @@ -458,11 +458,11 @@ static void draw_polygon(FILE * fp, int dim, real * center, real width) } -static void QuadTree_print_internal(FILE * fp, QuadTree * q, int level) +static void QuadTree_print_internal(FILE * fp, QuadTree q, int level) { /* dump a quad tree in Mathematica format. */ - SingleLinkedList *l; - SingleLinkedList *l0; + SingleLinkedList l; + SingleLinkedList l0; real *coord; int i, dim = q->dim; @@ -498,7 +498,7 @@ static void QuadTree_print_internal(FILE * fp, QuadTree * q, int level) } -void QuadTree_print(FILE * fp, QuadTree * q) +void QuadTree_print(FILE * fp, QuadTree q) { if (!fp) return; diff --git a/lib/sfdpgen/QuadTree.h b/lib/sfdpgen/QuadTree.h index 643a8a928..07387892b 100644 --- a/lib/sfdpgen/QuadTree.h +++ b/lib/sfdpgen/QuadTree.h @@ -20,9 +20,9 @@ #include "sfdpinternal.h" #include -typedef struct QuadTree_struct QuadTree; +typedef struct QuadTree_s* QuadTree; -struct QuadTree_struct { +struct QuadTree_s { /* a data structure containing coordinates of n items, their average is in "average". The current level is a square or cube of width "width", which is subdivided into 2^dim QuadTrees qts. At the last level, all coordinates are stored in a single linked list l. @@ -34,26 +34,26 @@ struct QuadTree_struct { real width; /* center +/- width gives the lower/upper bound, so really width is the "radius" */ real *average; /* the average coordinates. Array of length dim. Allocated inside */ - QuadTree **qts; /* subtree . If dim = 2, there are 4, dim = 3 gives 8 */ - SingleLinkedList *l; + QuadTree *qts; /* subtree . If dim = 2, there are 4, dim = 3 gives 8 */ + SingleLinkedList l; int max_level; }; -QuadTree *QuadTree_new(int dim, real * center, real width, int max_level); +QuadTree QuadTree_new(int dim, real * center, real width, int max_level); -void QuadTree_delete(QuadTree * q); +void QuadTree_delete(QuadTree q); -QuadTree *QuadTree_add(QuadTree * q, real * coord, real weight, int id); /* coord is copied in */ +QuadTree QuadTree_add(QuadTree q, real * coord, real weight, int id); /* coord is copied in */ -void QuadTree_print(FILE * fp, QuadTree * q); +void QuadTree_print(FILE * fp, QuadTree q); -QuadTree *QuadTree_new_from_point_list(int dim, int n, int max_level, +QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, real * coord, real * weight); real point_distance(real * p1, real * p2, int dim); -void QuadTree_get_supernodes(QuadTree * qt, real bh, real * point, +void QuadTree_get_supernodes(QuadTree qt, real bh, real * point, int nodeid, int *nsuper, int *nsupermax, real ** center, real ** supernode_wgts, real ** distances, real * counts, int *flag); diff --git a/lib/sfdpgen/SparseMatrix.c b/lib/sfdpgen/SparseMatrix.c index bb1659b68..bb016d5a3 100644 --- a/lib/sfdpgen/SparseMatrix.c +++ b/lib/sfdpgen/SparseMatrix.c @@ -48,20 +48,20 @@ static size_t size_of_matrix_type(int type) return size; } -SparseMatrix *SparseMatrix_make_undirected(SparseMatrix * A) +SparseMatrix SparseMatrix_make_undirected(SparseMatrix A) { /* make it strictly low diag only, and set flag to undirected */ - SparseMatrix *B; + SparseMatrix B; B = SparseMatrix_symmetrize(A, FALSE); SparseMatrix_set_undirected(B); return SparseMatrix_remove_upper(B); } -SparseMatrix *SparseMatrix_transpose(SparseMatrix * A) +SparseMatrix SparseMatrix_transpose(SparseMatrix A) { int *ia = A->ia, *ja = A->ja, *ib, *jb, nz = A->nz, m = A->m, n = A->n, type = A->type, format = A->format; - SparseMatrix *B; + SparseMatrix B; int i, j; if (!A) @@ -144,10 +144,10 @@ SparseMatrix *SparseMatrix_transpose(SparseMatrix * A) return B; } -SparseMatrix *SparseMatrix_symmetrize(SparseMatrix * A, +SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, int pattern_symmetric_only) { - SparseMatrix *B; + SparseMatrix B; if (SparseMatrix_is_symmetric(A, pattern_symmetric_only)) return SparseMatrix_copy(A); B = SparseMatrix_transpose(A); @@ -160,11 +160,11 @@ SparseMatrix *SparseMatrix_symmetrize(SparseMatrix * A, return A; } -int SparseMatrix_is_symmetric(SparseMatrix * A, +int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only) { /* assume no repeated entries! */ - SparseMatrix *B; + SparseMatrix B; int *ia, *ja, *ib, *jb, type, m; int *mask; int res = FALSE; @@ -300,11 +300,11 @@ int SparseMatrix_is_symmetric(SparseMatrix * A, return res; } -static SparseMatrix *SparseMatrix_init(int m, int n, int type, int format) +static SparseMatrix SparseMatrix_init(int m, int n, int type, int format) { - SparseMatrix *A; + SparseMatrix A; - A = GNEW(SparseMatrix); + A = GNEW(struct SparseMatrix_s); A->m = m; A->n = n; A->nz = 0; @@ -331,7 +331,7 @@ static SparseMatrix *SparseMatrix_init(int m, int n, int type, int format) return A; } -static SparseMatrix *SparseMatrix_alloc(SparseMatrix * A, int nz) +static SparseMatrix SparseMatrix_alloc(SparseMatrix A, int nz) { int type = A->type, format = A->format; @@ -354,7 +354,7 @@ static SparseMatrix *SparseMatrix_alloc(SparseMatrix * A, int nz) return A; } -static SparseMatrix *SparseMatrix_realloc(SparseMatrix * A, int nz) +static SparseMatrix SparseMatrix_realloc(SparseMatrix A, int nz) { int type = A->type, format = A->format; switch (format) { @@ -386,11 +386,11 @@ static SparseMatrix *SparseMatrix_realloc(SparseMatrix * A, int nz) return A; } -SparseMatrix *SparseMatrix_new(int m, int n, int nz, int type, int format) +SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format) { /* return a sparse matrix skeleton with row dimension m and storage nz. If nz == 0, only row pointers are allocated */ - SparseMatrix *A; + SparseMatrix A; A = SparseMatrix_init(m, n, type, format); if (nz > 0) @@ -399,7 +399,7 @@ SparseMatrix *SparseMatrix_new(int m, int n, int nz, int type, int format) } -void SparseMatrix_delete(SparseMatrix * A) +void SparseMatrix_delete(SparseMatrix A) { /* return a sparse matrix skeleton with row dimension m and storage nz. If nz == 0, only row pointers are allocated */ @@ -413,7 +413,7 @@ void SparseMatrix_delete(SparseMatrix * A) free(A->a); free(A); } -void SparseMatrix_print_csr(char *c, SparseMatrix * A) +void SparseMatrix_print_csr(char *c, SparseMatrix A) { int *ia, *ja; real *a; @@ -479,7 +479,7 @@ void SparseMatrix_print_csr(char *c, SparseMatrix * A) -void SparseMatrix_print_coord(char *c, SparseMatrix * A) +void SparseMatrix_print_coord(char *c, SparseMatrix A) { int *ia, *ja; real *a; @@ -539,7 +539,7 @@ void SparseMatrix_print_coord(char *c, SparseMatrix * A) -void SparseMatrix_print(char *c, SparseMatrix * A) +void SparseMatrix_print(char *c, SparseMatrix A) { switch (A->format) { case FORMAT_CSR: @@ -561,7 +561,7 @@ void SparseMatrix_print(char *c, SparseMatrix * A) -static void SparseMatrix_export_csr(FILE * f, SparseMatrix * A) +static void SparseMatrix_export_csr(FILE * f, SparseMatrix A) { int *ia, *ja; real *a; @@ -613,7 +613,7 @@ static void SparseMatrix_export_csr(FILE * f, SparseMatrix * A) } -void SparseMatrix_export_binary(char *name, SparseMatrix * A, int *flag) +void SparseMatrix_export_binary(char *name, SparseMatrix A, int *flag) { FILE *f; @@ -642,9 +642,9 @@ void SparseMatrix_export_binary(char *name, SparseMatrix * A, int *flag) } -SparseMatrix *SparseMatrix_import_binary(char *name) +SparseMatrix SparseMatrix_import_binary(char *name) { - SparseMatrix *A = NULL; + SparseMatrix A = NULL; int m, n, nz, nzmax, type, format, property; FILE *f; @@ -676,7 +676,7 @@ SparseMatrix *SparseMatrix_import_binary(char *name) return A; } -static void SparseMatrix_export_coord(FILE * f, SparseMatrix * A) +static void SparseMatrix_export_coord(FILE * f, SparseMatrix A) { int *ia, *ja; real *a; @@ -721,7 +721,7 @@ static void SparseMatrix_export_coord(FILE * f, SparseMatrix * A) -void SparseMatrix_export(FILE * f, SparseMatrix * A) +void SparseMatrix_export(FILE * f, SparseMatrix A) { switch (A->format) { @@ -741,7 +741,7 @@ void SparseMatrix_export(FILE * f, SparseMatrix * A) } -SparseMatrix *SparseMatrix_from_coordinate_format(SparseMatrix * A) +SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A) { /* convert a sparse matrix in coordinate form to one in compressed row form. */ int *irn, *jcn; @@ -759,7 +759,7 @@ SparseMatrix *SparseMatrix_from_coordinate_format(SparseMatrix * A) } -SparseMatrix *SparseMatrix_from_coordinate_arrays(int nz, int m, int n, +SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val0, int type) { @@ -771,7 +771,7 @@ SparseMatrix *SparseMatrix_from_coordinate_arrays(int nz, int m, int n, type: matrix type */ - SparseMatrix *A = NULL; + SparseMatrix A = NULL; int *ia, *ja; real *a, *val; int *ai, *vali; @@ -884,10 +884,10 @@ SparseMatrix *SparseMatrix_from_coordinate_arrays(int nz, int m, int n, } -SparseMatrix *SparseMatrix_add(SparseMatrix * A, SparseMatrix * B) +SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B) { int m, n; - SparseMatrix *C = NULL; + SparseMatrix C = NULL; int *mask = NULL; int *ia = A->ia, *ja = A->ja, *ib = B->ia, *jb = B->ja, *ic, *jc; int i, j, nz, nzmax; @@ -1040,7 +1040,7 @@ static void dense_transpose(real * v, int m, int n) } -static void SparseMatrix_multiply_dense1(SparseMatrix * A, real * v, +static void SparseMatrix_multiply_dense1(SparseMatrix A, real * v, real ** res, int dim, int transposed, int res_transposed) @@ -1092,7 +1092,7 @@ static void SparseMatrix_multiply_dense1(SparseMatrix * A, real * v, } -static void SparseMatrix_multiply_dense2(SparseMatrix * A, real * v, +static void SparseMatrix_multiply_dense2(SparseMatrix A, real * v, real ** res, int dim, int transposed, int res_transposed) @@ -1136,7 +1136,7 @@ static void SparseMatrix_multiply_dense2(SparseMatrix * A, real * v, -void SparseMatrix_multiply_dense(SparseMatrix * A, int ATransposed, +void SparseMatrix_multiply_dense(SparseMatrix A, int ATransposed, real * v, int vTransposed, real ** res, int res_transposed, int dim) { @@ -1166,7 +1166,7 @@ void SparseMatrix_multiply_dense(SparseMatrix * A, int ATransposed, -void SparseMatrix_multiply_vector(SparseMatrix * A, real * v, real ** res, +void SparseMatrix_multiply_vector(SparseMatrix A, real * v, real ** res, int transposed) { /* A v or A^T v. Real only for now. */ @@ -1232,7 +1232,7 @@ void SparseMatrix_multiply_vector(SparseMatrix * A, real * v, real ** res, -SparseMatrix *SparseMatrix_scaled_by_vector(SparseMatrix * A, real * v, +SparseMatrix SparseMatrix_scaled_by_vector(SparseMatrix A, real * v, int apply_to_row) { /* A SCALED BY VECOTR V IN ROW/COLUMN. Real only for now. */ @@ -1266,7 +1266,7 @@ SparseMatrix *SparseMatrix_scaled_by_vector(SparseMatrix * A, real * v, } -SparseMatrix *SparseMatrix_multiply_by_scaler(SparseMatrix * A, real s) +SparseMatrix SparseMatrix_multiply_by_scaler(SparseMatrix A, real s) { /* A scaled by a number */ int i, j, *ia, m; @@ -1294,10 +1294,10 @@ SparseMatrix *SparseMatrix_multiply_by_scaler(SparseMatrix * A, real s) } -SparseMatrix *SparseMatrix_multiply(SparseMatrix * A, SparseMatrix * B) +SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B) { int m, n; - SparseMatrix *C = NULL; + SparseMatrix C = NULL; int *mask = NULL; int *ia = A->ia, *ja = A->ja, *ib = B->ia, *jb = B->ja, *ic, *jc; int i, j, k, jj, type, nz; @@ -1460,7 +1460,7 @@ SparseMatrix *SparseMatrix_multiply(SparseMatrix * A, SparseMatrix * B) } -SparseMatrix *SparseMatrix_sum_repeat_entries(SparseMatrix * A) +SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A) { /* sum repeated entries in the same row, i.e., {1,1}->1, {1,1}->2 becomes {1,1}->3 */ int *ia = A->ia, *ja = A->ja, type = A->type, n = A->n; @@ -1566,7 +1566,7 @@ SparseMatrix *SparseMatrix_sum_repeat_entries(SparseMatrix * A) return A; } -SparseMatrix *SparseMatrix_coordinate_form_add_entries(SparseMatrix * A, +SparseMatrix SparseMatrix_coordinate_form_add_entries(SparseMatrix A, int nentries, int *irn, int *jcn, void *val) @@ -1597,7 +1597,7 @@ SparseMatrix *SparseMatrix_coordinate_form_add_entries(SparseMatrix * A, } -SparseMatrix *SparseMatrix_remove_diagonal(SparseMatrix * A) +SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A) { int i, j, *ia, *ja, nz, sta; @@ -1679,7 +1679,7 @@ SparseMatrix *SparseMatrix_remove_diagonal(SparseMatrix * A) } -SparseMatrix *SparseMatrix_remove_upper(SparseMatrix * A) +SparseMatrix SparseMatrix_remove_upper(SparseMatrix A) { /* remove diag and upper diag */ int i, j, *ia, *ja, nz, sta; @@ -1767,7 +1767,7 @@ SparseMatrix *SparseMatrix_remove_upper(SparseMatrix * A) -SparseMatrix *SparseMatrix_divide_row_by_degree(SparseMatrix * A) +SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A) { int i, j, *ia, *ja; real deg; @@ -1819,12 +1819,12 @@ SparseMatrix *SparseMatrix_divide_row_by_degree(SparseMatrix * A) SparseMatrix - *SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix * A) +SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A) { /* symmetric, all entries to 1, diaginal removed */ int i, *ia, *ja, nz, m, n; real *a; - SparseMatrix *B; + SparseMatrix B; if (!A) return A; @@ -1857,7 +1857,7 @@ SparseMatrix -SparseMatrix *SparseMatrix_normalize_to_rowsum1(SparseMatrix * A) +SparseMatrix SparseMatrix_normalize_to_rowsum1(SparseMatrix A) { int i, j; real sum, *a; @@ -1888,7 +1888,7 @@ SparseMatrix *SparseMatrix_normalize_to_rowsum1(SparseMatrix * A) -SparseMatrix *SparseMatrix_normalize_by_row(SparseMatrix * A) +SparseMatrix SparseMatrix_normalize_by_row(SparseMatrix A) { int i, j; real max, *a; @@ -1918,7 +1918,7 @@ SparseMatrix *SparseMatrix_normalize_by_row(SparseMatrix * A) } -SparseMatrix *SparseMatrix_apply_fun(SparseMatrix * A, +SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double (*fun) (double x)) { int i, j; @@ -1943,7 +1943,7 @@ SparseMatrix *SparseMatrix_apply_fun(SparseMatrix * A, } -SparseMatrix *SparseMatrix_crop(SparseMatrix * A, real epsilon) +SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon) { int i, j, *ia, *ja, nz, sta; @@ -2016,9 +2016,9 @@ SparseMatrix *SparseMatrix_crop(SparseMatrix * A, real epsilon) return A; } -SparseMatrix *SparseMatrix_copy(SparseMatrix * A) +SparseMatrix SparseMatrix_copy(SparseMatrix A) { - SparseMatrix *B; + SparseMatrix B; if (!A) return A; B = SparseMatrix_new(A->m, A->n, A->nz, A->type, A->format); @@ -2031,7 +2031,7 @@ SparseMatrix *SparseMatrix_copy(SparseMatrix * A) return B; } -int SparseMatrix_has_diagonal(SparseMatrix * A) +int SparseMatrix_has_diagonal(SparseMatrix A) { int i, j, m = A->m, *ia = A->ia, *ja = A->ja; @@ -2045,7 +2045,7 @@ int SparseMatrix_has_diagonal(SparseMatrix * A) return FALSE; } -void SparseMatrix_level_sets(SparseMatrix * A, int root, int *nlevel, +void SparseMatrix_level_sets(SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, int reinitialize_mask) { @@ -2099,11 +2099,11 @@ void SparseMatrix_level_sets(SparseMatrix * A, int root, int *nlevel, (*mask)[(*levelset)[i]] = UNMASKED; } -void SparseMatrix_weakly_connected_components(SparseMatrix * A0, +void SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int **comps, int **comps_ptr) { - SparseMatrix *A = A0; + SparseMatrix A = A0; int *levelset_ptr = NULL, *levelset = NULL, *mask = NULL, nlevel; int m = A->m, i, nn; @@ -2133,12 +2133,12 @@ void SparseMatrix_weakly_connected_components(SparseMatrix * A0, free(mask); } -int SparseMatrix_pseudo_diameter(SparseMatrix * A0, int root, +int SparseMatrix_pseudo_diameter(SparseMatrix A0, int root, int aggressive, int *end1, int *end2, int *connectedQ) { /* assume unit edge length, unsymmetric matrix ill be symmetrized */ - SparseMatrix *A = A0; + SparseMatrix A = A0; int m = A->m, i; int nlevel; int *levelset_ptr = NULL, *levelset = NULL, *mask = NULL; @@ -2193,18 +2193,18 @@ int SparseMatrix_pseudo_diameter(SparseMatrix * A0, int root, return nlevel0; } -int SparseMatrix_pseudo_diameter_only(SparseMatrix * A) +int SparseMatrix_pseudo_diameter_only(SparseMatrix A) { int end1, end2, connectedQ; return SparseMatrix_pseudo_diameter(A, 0, FALSE, &end1, &end2, &connectedQ); } -int SparseMatrix_connectedQ(SparseMatrix * A0) +int SparseMatrix_connectedQ(SparseMatrix A0) { int root = 0, nlevel, *levelset_ptr = NULL, *levelset = NULL, *mask = NULL, connected; - SparseMatrix *A = A0; + SparseMatrix A = A0; if (!SparseMatrix_is_symmetric(A, TRUE)) { A = SparseMatrix_symmetrize(A, TRUE); @@ -2224,7 +2224,7 @@ int SparseMatrix_connectedQ(SparseMatrix * A0) } -void SparseMatrix_decompose_to_supervariables(SparseMatrix * A, +void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp) { diff --git a/lib/sfdpgen/SparseMatrix.h b/lib/sfdpgen/SparseMatrix.h index dac9d265f..28cf7d3e6 100644 --- a/lib/sfdpgen/SparseMatrix.h +++ b/lib/sfdpgen/SparseMatrix.h @@ -27,7 +27,7 @@ enum { MATRIX_PATTERN_SYMMETRIC = 1 << 0, MATRIX_SYMMETRIC = 1 << 3, MATRIX_UNDIRECTED = 1 << 4 }; -typedef struct { +struct SparseMatrix_s { int m; /* row dimension */ int n; /* column dimension */ int nz; /* The actual length used is nz, for CSR/CSC matrix this is the same as ia[n] */ @@ -38,71 +38,73 @@ typedef struct { void *a; /* entry values. If NULL, pattern matrix */ int format; /* whether it is CSR, CSC, COORD. By default it is in CSR format */ int property; /* pattern_symmetric/symmetric/skew/hermitian */ -} SparseMatrix; +}; + +typedef struct SparseMatrix_s* SparseMatrix; enum { MATRIX_TYPE_REAL = 1 << 0, MATRIX_TYPE_COMPLEX = 1 << 1, MATRIX_TYPE_INTEGER = 1 << 2, MATRIX_TYPE_PATTERN = 1 << 3, MATRIX_TYPE_UNKNOWN = 1 << 4 }; -SparseMatrix *SparseMatrix_new(int m, int n, int nz, int type, int format); +SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format); -SparseMatrix *SparseMatrix_from_coordinate_format(SparseMatrix * A); +SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A); -SparseMatrix *SparseMatrix_from_coordinate_arrays(int nz, int m, int n, +SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val, int type); -void SparseMatrix_print(char *, SparseMatrix * A); /*print to stdout in Mathematica format */ +void SparseMatrix_print(char *, SparseMatrix A); /*print to stdout in Mathematica format */ -void SparseMatrix_export(FILE * f, SparseMatrix * A); /* export into MM format except the header */ +void SparseMatrix_export(FILE * f, SparseMatrix A); /* export into MM format except the header */ -SparseMatrix *SparseMatrix_import_binary(char *name); +SparseMatrix SparseMatrix_import_binary(char *name); -void SparseMatrix_export_binary(char *name, SparseMatrix * A, int *flag); +void SparseMatrix_export_binary(char *name, SparseMatrix A, int *flag); -void SparseMatrix_delete(SparseMatrix * A); +void SparseMatrix_delete(SparseMatrix A); -SparseMatrix *SparseMatrix_add(SparseMatrix * A, SparseMatrix * B); -SparseMatrix *SparseMatrix_multiply(SparseMatrix * A, SparseMatrix * B); -SparseMatrix *SparseMatrix_sum_repeat_entries(SparseMatrix * A); -SparseMatrix *SparseMatrix_coordinate_form_add_entries(SparseMatrix * A, +SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B); +SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B); +SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A); +SparseMatrix SparseMatrix_coordinate_form_add_entries(SparseMatrix A, int nentries, int *irn, int *jcn, void *val); -int SparseMatrix_is_symmetric(SparseMatrix * A, +int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only); -SparseMatrix *SparseMatrix_transpose(SparseMatrix * A); -SparseMatrix *SparseMatrix_symmetrize(SparseMatrix * A, +SparseMatrix SparseMatrix_transpose(SparseMatrix A); +SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, int pattern_symmetric_only); -void SparseMatrix_multiply_vector(SparseMatrix * A, real * v, real ** res, int transposed); /* if v = NULL, v is assumed to be {1,1,...,1} */ -SparseMatrix *SparseMatrix_remove_diagonal(SparseMatrix * A); -SparseMatrix *SparseMatrix_remove_upper(SparseMatrix * A); /* remove diag and upper diag */ -SparseMatrix *SparseMatrix_divide_row_by_degree(SparseMatrix * A); -SparseMatrix *SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix * A); /* symmetric, all entries to 1, diaginal removed */ -SparseMatrix *SparseMatrix_normalize_to_rowsum1(SparseMatrix * A); /* for real only! */ -void SparseMatrix_multiply_dense(SparseMatrix * A, int ATranspose, +void SparseMatrix_multiply_vector(SparseMatrix A, real * v, real ** res, int transposed); /* if v = NULL, v is assumed to be {1,1,...,1} */ +SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A); +SparseMatrix SparseMatrix_remove_upper(SparseMatrix A); /* remove diag and upper diag */ +SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A); +SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A); /* symmetric, all entries to 1, diaginal removed */ +SparseMatrix SparseMatrix_normalize_to_rowsum1(SparseMatrix A); /* for real only! */ +void SparseMatrix_multiply_dense(SparseMatrix A, int ATranspose, real * v, int vTransposed, real ** res, int res_transpose, int dim); -SparseMatrix *SparseMatrix_apply_fun(SparseMatrix * A, double (*fun) (double x)); /* for real only! */ -SparseMatrix *SparseMatrix_copy(SparseMatrix * A); -int SparseMatrix_has_diagonal(SparseMatrix * A); -SparseMatrix *SparseMatrix_normalize_by_row(SparseMatrix * A); /* divide by max of each row */ -SparseMatrix *SparseMatrix_crop(SparseMatrix * A, real epsilon); /*remove any entry <= epsilon */ -SparseMatrix *SparseMatrix_scaled_by_vector(SparseMatrix * A, real * v, +SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double (*fun) (double x)); /* for real only! */ +SparseMatrix SparseMatrix_copy(SparseMatrix A); +int SparseMatrix_has_diagonal(SparseMatrix A); +SparseMatrix SparseMatrix_normalize_by_row(SparseMatrix A); /* divide by max of each row */ +SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon); /*remove any entry <= epsilon */ +SparseMatrix SparseMatrix_scaled_by_vector(SparseMatrix A, real * v, int apply_to_row); -SparseMatrix *SparseMatrix_multiply_by_scaler(SparseMatrix * A, real s); -SparseMatrix *SparseMatrix_make_undirected(SparseMatrix * A); /* make it strictly low diag only, and set flag to undirected */ -int SparseMatrix_connectedQ(SparseMatrix * A); -int SparseMatrix_pseudo_diameter_only(SparseMatrix * A); -int SparseMatrix_pseudo_diameter(SparseMatrix * A0, int root, int aggressive, int *end1, int *end2, int *connectedQ); /* assume unit edge length, unsymmetric matrix ill be symmetrized */ -void SparseMatrix_level_sets(SparseMatrix * A, int root, int *nlevel, +SparseMatrix SparseMatrix_multiply_by_scaler(SparseMatrix A, real s); +SparseMatrix SparseMatrix_make_undirected(SparseMatrix A); /* make it strictly low diag only, and set flag to undirected */ +int SparseMatrix_connectedQ(SparseMatrix A); +int SparseMatrix_pseudo_diameter_only(SparseMatrix A); +int SparseMatrix_pseudo_diameter(SparseMatrix A0, int root, int aggressive, int *end1, int *end2, int *connectedQ); /* assume unit edge length, unsymmetric matrix ill be symmetrized */ +void SparseMatrix_level_sets(SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, int reintialize_mask); -void SparseMatrix_weakly_connected_components(SparseMatrix * A0, +void SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int **comps, int **comps_ptr); -void SparseMatrix_decompose_to_supervariables(SparseMatrix * A, +void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp); diff --git a/lib/sfdpgen/call_tri.c b/lib/sfdpgen/call_tri.c index 126669452..904f545ee 100644 --- a/lib/sfdpgen/call_tri.c +++ b/lib/sfdpgen/call_tri.c @@ -22,12 +22,12 @@ #include "memory.h" #include "delaunay.h" -SparseMatrix *call_tri(int n, int dim, real * x) +SparseMatrix call_tri(int n, int dim, real * x) { real one = 1; int i, ii, jj; - SparseMatrix *A; - SparseMatrix *B; + SparseMatrix A; + SparseMatrix B; int* edgelist = NULL; real* xv = N_GNEW(n, real); real* yv = N_GNEW(n, real); @@ -68,13 +68,13 @@ SparseMatrix *call_tri(int n, int dim, real * x) return B; } -SparseMatrix *call_tri2(int n, int dim, real * xx) +SparseMatrix call_tri2(int n, int dim, real * xx) { real *x, *y; v_data *delaunay; int i, j; - SparseMatrix *A; - SparseMatrix *B; + SparseMatrix A; + SparseMatrix B; real one = 1; x = N_GNEW(n, real); y = N_GNEW(n, real); diff --git a/lib/sfdpgen/call_tri.h b/lib/sfdpgen/call_tri.h index 6a59571e7..639dca16b 100644 --- a/lib/sfdpgen/call_tri.h +++ b/lib/sfdpgen/call_tri.h @@ -16,7 +16,7 @@ #ifndef CALL_TRI_H #define CALL_TRI_H -SparseMatrix *call_tri(int n, int dim, real * x); -SparseMatrix *call_tri2(int n, int dim, real * x); +SparseMatrix call_tri(int n, int dim, real * x); +SparseMatrix call_tri2(int n, int dim, real * x); #endif diff --git a/lib/sfdpgen/overlap.c b/lib/sfdpgen/overlap.c index 12d2d0813..ac6067354 100644 --- a/lib/sfdpgen/overlap.c +++ b/lib/sfdpgen/overlap.c @@ -24,7 +24,7 @@ #define MACHINEACC 1.0e-16 -static void ideal_distance_avoid_overlap(int dim, SparseMatrix * A, +static void ideal_distance_avoid_overlap(int dim, SparseMatrix A, real * x, real * width, real * ideal_distance, real * tmax, real * tmin) @@ -146,13 +146,13 @@ void InfoDest(void *a) ; } -static SparseMatrix *get_overlap_graph(int dim, int n, real * x, +static SparseMatrix get_overlap_graph(int dim, int n, real * x, real * width) { scan_point *scanpointsx, *scanpointsy; int i, k, neighbor; - SparseMatrix *A = NULL; - SparseMatrix *B = NULL; + SparseMatrix A = NULL; + SparseMatrix B = NULL; rb_red_blk_node *newNode, *newNode0; rb_red_blk_tree *treey; real one = 1; @@ -267,22 +267,23 @@ static SparseMatrix *get_overlap_graph(int dim, int n, real * x, /* ============================== label overlap smoother ==================*/ +#define OverlapSmoother_s StressMajorizationSmoother_s -OverlapSmoother *OverlapSmoother_new(SparseMatrix * A, int dim, +OverlapSmoother OverlapSmoother_new(SparseMatrix A, int dim, real lambda0, real * x, real * width, int include_original_graph, int neighborhood_only, real * max_overlap, real * min_overlap) { - OverlapSmoother *sm; + OverlapSmoother sm; int i, j, k, m = A->m, *iw, *jw, *id, *jd, jdiag; - SparseMatrix *B; + SparseMatrix B; real *lambda, *d, *w, diag_d, diag_w, dist; assert((!A) || SparseMatrix_is_symmetric(A, FALSE)); - sm = GNEW(OverlapSmoother); + sm = GNEW(struct OverlapSmoother_s); lambda = sm->lambda = N_GNEW(m, real); for (i = 0; i < m; i++) sm->lambda[i] = lambda0; @@ -290,8 +291,8 @@ OverlapSmoother *OverlapSmoother_new(SparseMatrix * A, int dim, B = call_tri(m, dim, x); if (!neighborhood_only) { - SparseMatrix *C; - SparseMatrix *D; + SparseMatrix C; + SparseMatrix D; C = get_overlap_graph(dim, A->m, x, width); D = SparseMatrix_add(B, C); SparseMatrix_delete(B); @@ -378,14 +379,14 @@ OverlapSmoother *OverlapSmoother_new(SparseMatrix * A, int dim, return sm; } -void OverlapSmoother_delete(OverlapSmoother * sm) +void OverlapSmoother_delete(OverlapSmoother sm) { StressMajorizationSmoother_delete(sm); } -void OverlapSmoother_smooth(OverlapSmoother * sm, int dim, real * x) +void OverlapSmoother_smooth(OverlapSmoother sm, int dim, real * x) { int maxit_sm = 1; /* only using 1 iteration of stress majorization is found to give better results and save time! */ @@ -402,7 +403,7 @@ void OverlapSmoother_smooth(OverlapSmoother * sm, int dim, real * x) /*================================= end OverlapSmoother =============*/ -static void scale_to_edge_length(int dim, SparseMatrix * A, real * x, +static void scale_to_edge_length(int dim, SparseMatrix A, real * x, real avg_label_size) { real dist; @@ -448,11 +449,11 @@ static void print_bounding_box(int n, int dim, real * x) free(xmax); } -int remove_overlap(int dim, SparseMatrix * A, real * x, +int remove_overlap(int dim, SparseMatrix A, real * x, real * label_sizes, int ntry) { real lambda = 0.00; - OverlapSmoother *sm; + OverlapSmoother sm; int include_original_graph = 0, i; real avg_label_size; real max_overlap = 0, min_overlap = 999; diff --git a/lib/sfdpgen/overlap.h b/lib/sfdpgen/overlap.h index efec82997..b10ea3dd2 100644 --- a/lib/sfdpgen/overlap.h +++ b/lib/sfdpgen/overlap.h @@ -21,19 +21,19 @@ typedef StressMajorizationSmoother OverlapSmoother; -void OverlapSmoother_delete(OverlapSmoother * sm); +void OverlapSmoother_delete(OverlapSmoother sm); -OverlapSmoother *OverlapSmoother_new(SparseMatrix * A, int dim, +OverlapSmoother OverlapSmoother_new(SparseMatrix A, int dim, real lambda0, real * x, real * width, int include_original_graph, int neighborhood_only, real * max_overlap, real * min_overlap); -void OverlapSmoother_smooth(OverlapSmoother * sm, int dim, real * x); +void OverlapSmoother_smooth(OverlapSmoother sm, int dim, real * x); -int remove_overlap(int dim, SparseMatrix * A, real * x, +int remove_overlap(int dim, SparseMatrix A, real * x, real * label_sizes, int ntry); #endif diff --git a/lib/sfdpgen/post_process.c b/lib/sfdpgen/post_process.c index f89247c5f..7462747dd 100644 --- a/lib/sfdpgen/post_process.c +++ b/lib/sfdpgen/post_process.c @@ -27,11 +27,11 @@ #define node_degree(i) (ia[(i)+1] - ia[(i)]) -SparseMatrix *ideal_distance_matrix(SparseMatrix * A, int dim, real * x) +SparseMatrix ideal_distance_matrix(SparseMatrix A, int dim, real * x) { /* find the ideal distance between edges, either 1, or |N[i] \Union N[j]| - |N[i] \Intersection N[j]| */ - SparseMatrix *D; + SparseMatrix D; int *ia, *ja, i, j, k, l, nz; real *d; int *mask = NULL; @@ -104,26 +104,26 @@ SparseMatrix *ideal_distance_matrix(SparseMatrix * A, int dim, real * x) return D; } -StressMajorizationSmoother *StressMajorizationSmoother_new(SparseMatrix * +StressMajorizationSmoother StressMajorizationSmoother_new(SparseMatrix A, int dim, real lambda0, real * x, int ideal_dist_scheme) { - StressMajorizationSmoother *sm; + StressMajorizationSmoother sm; int i, j, k, l, m = A->m, *ia = A->ia, *ja = A->ja, *iw, *jw, *id, *jd; int *mask, nz; real *d, *w, *lambda; real *avg_dist, diag_d, diag_w, *dd, dist, s = 0, stop = 0, sbot = 0; - SparseMatrix *ID; + SparseMatrix ID; assert(SparseMatrix_is_symmetric(A, FALSE)); ID = ideal_distance_matrix(A, dim, x); dd = (real *) ID->a; - sm = GNEW(StressMajorizationSmoother); + sm = GNEW(struct StressMajorizationSmoother_s); lambda = sm->lambda = N_GNEW(m, real); for (i = 0; i < m; i++) sm->lambda[i] = lambda0; @@ -318,12 +318,12 @@ static real total_distance(int m, int dim, real * x, real * y) -void StressMajorizationSmoother_smooth(StressMajorizationSmoother * sm, +void StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, real * x, int maxit_sm) { - SparseMatrix *Lw = sm->Lw; - SparseMatrix *Lwd = sm->Lwd; - SparseMatrix *Lwdd = NULL; + SparseMatrix Lw = sm->Lw; + SparseMatrix Lwd = sm->Lwd; + SparseMatrix Lwdd = NULL; int i, j, m, *id, *jd, idiag, flag = 0, iter = 0; real *dd, *d, *y = NULL, *x0 = NULL, diag, diff = 1, tol = 0.001, *lambda = sm->lambda, maxit, res; @@ -399,7 +399,7 @@ void StressMajorizationSmoother_smooth(StressMajorizationSmoother * sm, free(y); } -void StressMajorizationSmoother_delete(StressMajorizationSmoother * sm) +void StressMajorizationSmoother_delete(StressMajorizationSmoother sm) { if (!sm) return; @@ -412,14 +412,16 @@ void StressMajorizationSmoother_delete(StressMajorizationSmoother * sm) } -TriangleSmoother *TriangleSmoother_new(SparseMatrix * A, int dim, +#define TriangleSmoother_s StressMajorizationSmoother_s + +TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, real lambda0, real * x, int use_triangularization) { - TriangleSmoother *sm; + TriangleSmoother sm; int i, j, k, m = A->m, *ia = A->ia, *ja = A->ja, *iw, *jw, *id, *jd, jdiag, nz; - SparseMatrix *B; + SparseMatrix B; real *avg_dist, *lambda, *d, *w, diag_d, diag_w, dist; real s = 0, stop = 0, sbot = 0; @@ -440,7 +442,7 @@ TriangleSmoother *TriangleSmoother_new(SparseMatrix * A, int dim, avg_dist[i] /= nz; } - sm = GNEW(TriangleSmoother); + sm = GNEW(struct TriangleSmoother_s); lambda = sm->lambda = N_GNEW(m, real); for (i = 0; i < m; i++) sm->lambda[i] = lambda0; @@ -521,14 +523,14 @@ TriangleSmoother *TriangleSmoother_new(SparseMatrix * A, int dim, return sm; } -void TriangleSmoother_delete(TriangleSmoother * sm) +void TriangleSmoother_delete(TriangleSmoother sm) { StressMajorizationSmoother_delete(sm); } -void TriangleSmoother_smooth(TriangleSmoother * sm, int dim, real * x) +void TriangleSmoother_smooth(TriangleSmoother sm, int dim, real * x) { StressMajorizationSmoother_smooth(sm, dim, x, 50); @@ -538,23 +540,23 @@ void TriangleSmoother_smooth(TriangleSmoother * sm, int dim, real * x) /* ================================ spring and spring-electrical based smoother ================ */ -SpringSmoother *SpringSmoother_new(SparseMatrix * A, int dim, - spring_electrical_control * ctrl, +SpringSmoother SpringSmoother_new(SparseMatrix A, int dim, + spring_electrical_control ctrl, real * x) { - SpringSmoother *sm; + SpringSmoother sm; int i, j, k, l, m = A->m, *ia = A->ia, *ja = A->ja, *id, *jd; int *mask, nz; real *d, *dd; real *avg_dist; - SparseMatrix *ID = NULL; + SparseMatrix ID = NULL; assert(SparseMatrix_is_symmetric(A, FALSE)); ID = ideal_distance_matrix(A, dim, x); dd = (real *) ID->a; - sm = GNEW(SpringSmoother); + sm = GNEW(struct SpringSmoother_s); mask = N_GNEW(m, int); avg_dist = N_GNEW(m, real); @@ -654,7 +656,7 @@ SpringSmoother *SpringSmoother_new(SparseMatrix * A, int dim, } -void SpringSmoother_delete(SpringSmoother * sm) +void SpringSmoother_delete(SpringSmoother sm) { if (!sm) return; @@ -667,7 +669,7 @@ void SpringSmoother_delete(SpringSmoother * sm) -void SpringSmoother_smooth(SpringSmoother * sm, SparseMatrix * A, +void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A, real * node_weights, int dim, real * x) { int flag = 0; @@ -680,8 +682,8 @@ void SpringSmoother_smooth(SpringSmoother * sm, SparseMatrix * A, /*=============================== end of spring and spring-electrical based smoother =========== */ -int post_process_smoothing(int dim, SparseMatrix * A, - spring_electrical_control * ctrl, +int post_process_smoothing(int dim, SparseMatrix A, + spring_electrical_control ctrl, real * node_weights, real * x) { #ifdef DEBUG @@ -693,7 +695,7 @@ int post_process_smoothing(int dim, SparseMatrix * A, switch (ctrl->smoothing) { case SMOOTHING_RNG: case SMOOTHING_TRIANGLE:{ - TriangleSmoother *sm; + TriangleSmoother sm; if (ctrl->smoothing == SMOOTHING_RNG) { sm = TriangleSmoother_new(A, dim, 0, x, FALSE); @@ -708,7 +710,7 @@ int post_process_smoothing(int dim, SparseMatrix * A, case SMOOTHING_STRESS_MAJORIZATION_POWER_DIST: case SMOOTHING_STRESS_MAJORIZATION_AVG_DIST: { - StressMajorizationSmoother *sm; + StressMajorizationSmoother sm; int k, dist_scheme = IDEAL_AVG_DIST; if (ctrl->smoothing == @@ -731,7 +733,7 @@ int post_process_smoothing(int dim, SparseMatrix * A, break; } case SMOOTHING_SPRING:{ - SpringSmoother *sm; + SpringSmoother sm; int k; for (k = 0; k < 1; k++) { diff --git a/lib/sfdpgen/post_process.h b/lib/sfdpgen/post_process.h index 5c3932ef9..080f9ab46 100644 --- a/lib/sfdpgen/post_process.h +++ b/lib/sfdpgen/post_process.h @@ -18,58 +18,59 @@ #include -typedef struct { - SparseMatrix *Lw; - SparseMatrix *Lwd; +struct StressMajorizationSmoother_s { + SparseMatrix Lw; + SparseMatrix Lwd; real *lambda; -} StressMajorizationSmoother; +}; -void StressMajorizationSmoother_delete(StressMajorizationSmoother * sm); +typedef struct StressMajorizationSmoother_s* StressMajorizationSmoother; + +void StressMajorizationSmoother_delete(StressMajorizationSmoother sm); enum { IDEAL_GRAPH_DIST, IDEAL_AVG_DIST, IDEAL_POWER_DIST }; -StressMajorizationSmoother *StressMajorizationSmoother_new(SparseMatrix * +StressMajorizationSmoother StressMajorizationSmoother_new(SparseMatrix A, int dim, real lambda, real * x, int ideal_dist_scheme); -void StressMajorizationSmoother_smooth(StressMajorizationSmoother * sm, +void StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, real * x, int maxit); /*-------------------- triangle/neirhborhood graph based smoother ------------------- */ typedef StressMajorizationSmoother TriangleSmoother; -/* #define TriangleSmoother_struct StressMajorizationSmoother_struct */ - -void TriangleSmoother_delete(TriangleSmoother * sm); +void TriangleSmoother_delete(TriangleSmoother sm); -TriangleSmoother *TriangleSmoother_new(SparseMatrix * A, int dim, +TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, real lambda, real * x, int use_triangularization); -void TriangleSmoother_smooth(TriangleSmoother * sm, int dim, real * x); +void TriangleSmoother_smooth(TriangleSmoother sm, int dim, real * x); /*------------------ spring and spring-electrical based smoother */ -typedef struct { - SparseMatrix *D; - spring_electrical_control *ctrl; -} SpringSmoother; +struct SpringSmoother_s { + SparseMatrix D; + spring_electrical_control ctrl; +}; +typedef struct SpringSmoother_s* SpringSmoother; -SpringSmoother *SpringSmoother_new(SparseMatrix * A, int dim, - spring_electrical_control * ctrl, +SpringSmoother SpringSmoother_new(SparseMatrix A, int dim, + spring_electrical_control ctrl, real * x); -void SpringSmoother_delete(SpringSmoother * sm); +void SpringSmoother_delete(SpringSmoother sm); -void SpringSmoother_smooth(SpringSmoother * sm, SparseMatrix * A, +void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A, real * node_weights, int dim, real * x); /*------------------------------------------------------------------*/ -int post_process_smoothing(int dim, SparseMatrix * A, - spring_electrical_control * ctrl, +int post_process_smoothing(int dim, SparseMatrix A, + spring_electrical_control ctrl, real * node_weights, real * x); #endif diff --git a/lib/sfdpgen/sfdpinit.c b/lib/sfdpgen/sfdpinit.c index 329084e87..10b06e600 100644 --- a/lib/sfdpgen/sfdpinit.c +++ b/lib/sfdpgen/sfdpinit.c @@ -117,9 +117,9 @@ static real *getSizes(Agraph_t * g, pointf pad) * Assumes g is connected and simple, i.e., we can have a->b and b->a * but not a->b and a->b */ -static SparseMatrix *makeMatrix(Agraph_t * g, int dim) +static SparseMatrix makeMatrix(Agraph_t * g, int dim) { - SparseMatrix *A = 0; + SparseMatrix A = 0; Agnode_t *n; Agedge_t *e; Agsym_t *sym; @@ -173,7 +173,7 @@ static SparseMatrix *makeMatrix(Agraph_t * g, int dim) int fdpAdjust (graph_t* g) { - SparseMatrix *A = makeMatrix(g, Ndim); + SparseMatrix A = makeMatrix(g, Ndim); real *sizes; real *pos = N_NEW(Ndim * agnnodes(g), real); Agnode_t *n; @@ -213,7 +213,7 @@ fdpAdjust (graph_t* g) return flag; } -static void sfdpLayout(graph_t * g, spring_electrical_control * ctrl, +static void sfdpLayout(graph_t * g, spring_electrical_control ctrl, pointf pad) { real *sizes; @@ -221,7 +221,7 @@ static void sfdpLayout(graph_t * g, spring_electrical_control * ctrl, Agnode_t *n; int flag, i; - SparseMatrix *A = makeMatrix(g, Ndim); + SparseMatrix A = makeMatrix(g, Ndim); if (ctrl->overlap) sizes = getSizes(g, pad); else @@ -295,7 +295,7 @@ late_smooth (graph_t* g, Agsym_t* sym, smooth_t dflt) * ctrl->use_node_weights */ static void -tuneControl (graph_t* g, spring_electrical_control* ctrl) +tuneControl (graph_t* g, spring_electrical_control ctrl) { ctrl->p = -1.0*late_double(g, agfindattr(g, "K"), -AUTOP, 0.0); ctrl->multilevels = late_int(g, agfindattr(g, "maxiter"), INT_MAX, 0); @@ -313,7 +313,7 @@ void sfdp_layout(graph_t * g) int i; expand_t sep; pointf pad; - spring_electrical_control *ctrl = spring_electrical_control_new(); + spring_electrical_control ctrl = spring_electrical_control_new(); tuneControl (g, ctrl); diff --git a/lib/sfdpgen/sparse_solve.c b/lib/sfdpgen/sparse_solve.c index e785b0cb0..854374c12 100644 --- a/lib/sfdpgen/sparse_solve.c +++ b/lib/sfdpgen/sparse_solve.c @@ -54,26 +54,26 @@ static real vector_product(int n, real *x, real *y){ return res; } -real *Operator_matmul_apply(Operator * o, real * x, real * y) +real *Operator_matmul_apply(Operator o, real * x, real * y) { - SparseMatrix *A = (SparseMatrix *) o->data; + SparseMatrix A = (SparseMatrix) o->data; SparseMatrix_multiply_vector(A, x, &y, FALSE); return y; } -Operator *Operator_matmul_new(SparseMatrix * A) +Operator Operator_matmul_new(SparseMatrix A) { - Operator *o = GNEW(Operator); + Operator o = GNEW(struct Operator_s); o->data = (void *) A; o->Operator_apply = Operator_matmul_apply; return o; } -void Operator_matmul_delete(Operator * o) +void Operator_matmul_delete(Operator o) { } -real *Operator_diag_precon_apply(Operator * o, real * x, real * y) +real *Operator_diag_precon_apply(Operator o, real * x, real * y) { int i, m; real *diag = (real *) o->data; @@ -84,9 +84,9 @@ real *Operator_diag_precon_apply(Operator * o, real * x, real * y) return y; } -Operator *Operator_diag_precon_new(SparseMatrix * A) +Operator Operator_diag_precon_new(SparseMatrix A) { - Operator *o; + Operator o; real *diag; int i, j, m = A->m, *ia = A->ia, *ja = A->ja; real *a = (real *) A->a; @@ -95,7 +95,7 @@ Operator *Operator_diag_precon_new(SparseMatrix * A) assert(a); - o = GNEW(Operator); + o = GNEW(struct Operator_s); o->data = N_GNEW(A->m + 1, real); diag = (real *) o->data; @@ -114,12 +114,12 @@ Operator *Operator_diag_precon_new(SparseMatrix * A) return o; } -void Operator_diag_precon_delete(Operator * o) +void Operator_diag_precon_delete(Operator o) { free(o->data); } -static real conjugate_gradient(Operator * A, Operator * precon, int n, real * x, +static real conjugate_gradient(Operator A, Operator precon, int n, real * x, real * rhs, real tol, int maxit, int *flag) { real *z, *r, *p, *q, res = 10 * tol, alpha; @@ -185,11 +185,11 @@ static real conjugate_gradient(Operator * A, Operator * precon, int n, real * x, return res; } -real SparseMatrix_solve(SparseMatrix * A, int dim, real * x0, real * rhs, +real SparseMatrix_solve(SparseMatrix A, int dim, real * x0, real * rhs, real tol, int maxit, int method, int *flag) { - Operator *Ax; - Operator *precond; + Operator Ax; + Operator precond; real *x, *b, res = 0; int n = A->m, k, i; diff --git a/lib/sfdpgen/sparse_solve.h b/lib/sfdpgen/sparse_solve.h index c29b7cd2f..dfe502aee 100644 --- a/lib/sfdpgen/sparse_solve.h +++ b/lib/sfdpgen/sparse_solve.h @@ -21,16 +21,16 @@ enum { SOLVE_METHOD_CG }; -typedef struct Operator_struct Operator; +typedef struct Operator_s* Operator; -typedef real *(*op_apply_fn) (Operator * o, real * in, real * out); +typedef real *(*op_apply_fn) (Operator o, real * in, real * out); -struct Operator_struct { +struct Operator_s { void *data; op_apply_fn Operator_apply; }; -real SparseMatrix_solve(SparseMatrix * A, int dim, real * x0, real * rhs, +real SparseMatrix_solve(SparseMatrix A, int dim, real * x0, real * rhs, real tol, int maxit, int method, int *flag); #endif diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index 2c9ec2fef..ae2621c8a 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -29,10 +29,10 @@ #define drand() (rand()/(real) RAND_MAX) -spring_electrical_control *spring_electrical_control_new() +spring_electrical_control spring_electrical_control_new() { - spring_electrical_control *ctrl; - ctrl = GNEW(spring_electrical_control); + spring_electrical_control ctrl; + ctrl = GNEW(struct spring_electrical_control_s); ctrl->p = AUTOP; /*a negativve number default to -1. repulsive force = dist^p */ ctrl->random_start = TRUE; /* whether to apply SE from a random layout, or from exisiting layout */ ctrl->K = -1; /* the natural distance. If K < 0, K will be set to the average distance of an edge */ @@ -55,7 +55,7 @@ spring_electrical_control *spring_electrical_control_new() return ctrl; } -void spring_electrical_control_delete(spring_electrical_control * ctrl) +void spring_electrical_control_delete(spring_electrical_control ctrl) { free(ctrl); } @@ -128,7 +128,7 @@ static int oned_optimizer_get(oned_optimizer * opt) } -real average_edge_length(SparseMatrix * A, int dim, real * coord) +real average_edge_length(SparseMatrix A, int dim, real * coord) { real dist = 0, d; int *ia = A->ia, *ja = A->ja, i, j, k; @@ -175,7 +175,7 @@ real distance(real * x, int dim, int i, int j) } #ifdef ENERGY -static real spring_electrical_energy(int dim, SparseMatrix * A, real * x, +static real spring_electrical_energy(int dim, SparseMatrix A, real * x, real p, real CRK, real KP) { /* 1. Grad[||x-y||^k,x] = k||x-y||^(k-1)*0.5*(x-y)/||x-y|| = k/2*||x-y||^(k-2) (x-y) @@ -216,7 +216,7 @@ static real spring_electrical_energy(int dim, SparseMatrix * A, real * x, #endif -void export_embedding(FILE * fp, int dim, SparseMatrix * A, real * x, +void export_embedding(FILE * fp, int dim, SparseMatrix A, real * x, real * width) { int i, j, k, *ia = A->ia, *ja = A->ja; @@ -388,7 +388,7 @@ static void set_leaves(real * x, int dim, real dist, real ang, int i, x[dim * j + 1] = sin(ang) * dist + x[dim * i + 1]; } -static void beautify_leaves(int dim, SparseMatrix * A, real * x) +static void beautify_leaves(int dim, SparseMatrix A, real * x) { int m = A->m, i, j, *ia = A->ia, *ja = A->ja, k; int *checked, p; @@ -472,16 +472,16 @@ static void beautify_leaves(int dim, SparseMatrix * A, real * x) free(leaves); } -void spring_electrical_spring_embedding(int dim, SparseMatrix * A0, - SparseMatrix * D, - spring_electrical_control * ctrl, +void spring_electrical_spring_embedding(int dim, SparseMatrix A0, + SparseMatrix D, + spring_electrical_control ctrl, real * node_weights, real * x, int *flag) { /* x is a point to a 1D array, x[i*dim+j] gives the coordinate of the i-th node at dimension j. Same as the spring-electrical except we also introduce force due to spring length */ - SparseMatrix *A = A0; + SparseMatrix A = A0; int m, n; int i, j, k; real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = @@ -494,7 +494,7 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix * A0, real *f = NULL, dist, F, Fnorm = 0, Fnorm0; int iter = 0; int adaptive_cooling = ctrl->adaptive_cooling; - QuadTree *qt = NULL; + QuadTree qt = NULL; int USE_QT = FALSE; int nsuper = 0, nsupermax = 10; real *center = NULL, *supernode_wgts = NULL, *distances = @@ -747,12 +747,12 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix * A0, } -int spring_electrical_embedding(int dim, SparseMatrix * A0, - spring_electrical_control * ctrl, +int spring_electrical_embedding(int dim, SparseMatrix A0, + spring_electrical_control ctrl, real * node_weights, real * x) { /* x is a point to a 1D array, x[i*dim+j] gives the coordinate of the i-th node at dimension j. */ - SparseMatrix *A = A0; + SparseMatrix A = A0; int m, n; int i, j, k; real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = @@ -763,7 +763,7 @@ int spring_electrical_embedding(int dim, SparseMatrix * A0, real *f = NULL, dist, F, Fnorm = 0, Fnorm0; int iter = 0; int adaptive_cooling = ctrl->adaptive_cooling; - QuadTree *qt = NULL; + QuadTree qt = NULL; int USE_QT = FALSE; int nsuper = 0, nsupermax = 10; real *center = NULL, *supernode_wgts = NULL, *distances = @@ -1079,7 +1079,7 @@ void print_matrix(real * x, int n, int dim) } -static void interpolate(int dim, SparseMatrix * A, real * x) +static void interpolate(int dim, SparseMatrix A, real * x) { int i, j, k, *ia = A->ia, *ja = A->ja, nz; real alpha = 0.5, beta, *y; @@ -1107,8 +1107,8 @@ static void interpolate(int dim, SparseMatrix * A, real * x) free(y); } -static void prolongate(int dim, SparseMatrix * A, SparseMatrix * P, - SparseMatrix * R, real * x, real * y, +static void prolongate(int dim, SparseMatrix A, SparseMatrix P, + SparseMatrix R, real * x, real * y, int coarsen_scheme_used, real delta) { int nc, *ia, *ja, i, j, k; @@ -1133,7 +1133,7 @@ static void prolongate(int dim, SparseMatrix * A, SparseMatrix * P, -int power_law_graph(SparseMatrix * A) +int power_law_graph(SparseMatrix A) { int *mask, m, max = 0, i, *ia = A->ia, *ja = A->ja, j, deg; int res = FALSE; @@ -1221,17 +1221,17 @@ void pcp_rotate(int n, int dim, real * x) } -int multilevel_spring_electrical_embedding(int dim, SparseMatrix * A0, - spring_electrical_control * +int multilevel_spring_electrical_embedding(int dim, SparseMatrix A0, + spring_electrical_control ctrl, real * node_weights, real * label_sizes, real * x) { - Multilevel_control *mctrl = NULL; + Multilevel_control mctrl = NULL; int n, plg, coarsen_scheme_used; - SparseMatrix *A = A0; - SparseMatrix *P = NULL; - Multilevel *grid; - Multilevel *grid0; + SparseMatrix A = A0; + SparseMatrix P = NULL; + Multilevel grid; + Multilevel grid0; real *xc = NULL, *xf = NULL; int flag = 0; #ifdef DEBUG diff --git a/lib/sfdpgen/spring_electrical.h b/lib/sfdpgen/spring_electrical.h index a1ee2e16a..646a55f33 100644 --- a/lib/sfdpgen/spring_electrical.h +++ b/lib/sfdpgen/spring_electrical.h @@ -35,7 +35,7 @@ typedef enum { SMOOTHING_RNG } smooth_t; -typedef struct { +struct spring_electrical_control_s { real p; /*a negative number default to -1. repulsive force = dist^p */ int random_start; /* whether to apply SE from a random layout, or from exisiting layout */ real K; /* the natural distance. If K < 0, K will be set to the average distance of an edge */ @@ -54,30 +54,32 @@ typedef struct { int use_node_weights; int smoothing; int overlap; -} spring_electrical_control; +}; -spring_electrical_control *spring_electrical_control_new(); -int spring_electrical_embedding(int dim, SparseMatrix * A0, - spring_electrical_control * ctrl, +typedef struct spring_electrical_control_s* spring_electrical_control; + +spring_electrical_control spring_electrical_control_new(); +int spring_electrical_embedding(int dim, SparseMatrix A0, + spring_electrical_control ctrl, real * node_weights, real * x); -int multilevel_spring_electrical_embedding(int dim, SparseMatrix * A0, - spring_electrical_control * +int multilevel_spring_electrical_embedding(int dim, SparseMatrix A0, + spring_electrical_control ctrl0, real * node_weights, real * label_sizes, real * x); -void export_embedding(FILE * fp, int dim, SparseMatrix * A, real * x, +void export_embedding(FILE * fp, int dim, SparseMatrix A, real * x, real * width); -void spring_electrical_control_delete(spring_electrical_control *); +void spring_electrical_control_delete(spring_electrical_control); void print_matrix(real * x, int n, int dim); real distance(real * x, int dim, int i, int j); real distance_cropped(real * x, int dim, int i, int j); -real average_edge_length(SparseMatrix * A, int dim, real * coord); +real average_edge_length(SparseMatrix A, int dim, real * coord); -void spring_electrical_spring_embedding(int dim, SparseMatrix * A, - SparseMatrix * D, - spring_electrical_control * ctrl, +void spring_electrical_spring_embedding(int dim, SparseMatrix A, + SparseMatrix D, + spring_electrical_control ctrl, real * node_weights, real * x, int *flag);