From: Matthew Fernandez Date: Wed, 10 Nov 2021 02:28:51 +0000 (-0800) Subject: remove 'real' abstraction X-Git-Tag: 2.50.0~34^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f259b55c076b55eb0e910a34ebc70c94ec7824c;p=graphviz remove 'real' abstraction This was not configurable and always mapped to the type `double`. There were also implicit assumptions that `real` and `double` were interchangeable. This alias is removed to avoid future confusion. The diff appears large, but it is just removing two #defines of `real` and propagating their definition (`double`) to all usage sites. --- diff --git a/cmd/edgepaint/edgepaintmain.c b/cmd/edgepaint/edgepaintmain.c index 3ef6d5e2d..279052fe7 100644 --- a/cmd/edgepaint/edgepaintmain.c +++ b/cmd/edgepaint/edgepaintmain.c @@ -100,7 +100,7 @@ static bool strprefix(const char *s1, const char *s2) { return strncmp(s1, s2, strlen(s2)) == 0; } -static void init(int argc, char *argv[], real *angle, real *accuracy, int *check_edges_with_same_endpoint, int *seed, char **color_scheme, char **lightness){ +static void init(int argc, char *argv[], double *angle, double *accuracy, int *check_edges_with_same_endpoint, int *seed, char **color_scheme, char **lightness){ char* cmd = argv[0]; outfile = NULL; @@ -258,7 +258,7 @@ static void init(int argc, char *argv[], real *angle, real *accuracy, int *check } -static int clarify(Agraph_t* g, real angle, real accuracy, int check_edges_with_same_endpoint, int seed, char *color_scheme, char *lightness){ +static int clarify(Agraph_t* g, double angle, double accuracy, int check_edges_with_same_endpoint, int seed, char *color_scheme, char *lightness){ if (checkG(g)) { agerr (AGERR, "Graph %s contains loops or multiedges\n", agnameof(g)); @@ -280,8 +280,8 @@ static Agraph_t *gread(FILE * fp) int main(int argc, char *argv[]) { - real accuracy; - real angle; + double accuracy; + double angle; int check_edges_with_same_endpoint, seed; char *color_scheme = NULL; char *lightness = NULL; diff --git a/cmd/gvmap/country_graph_coloring.c b/cmd/gvmap/country_graph_coloring.c index 38a49fb59..cf7ebb928 100644 --- a/cmd/gvmap/country_graph_coloring.c +++ b/cmd/gvmap/country_graph_coloring.c @@ -18,7 +18,7 @@ #include static void get_local_12_norm(int n, int i, const int *ia, const int *ja, - const int *p, real *norm){ + const int *p, double *norm){ int j, nz = 0; norm[0] = n; norm[1] = 0; for (j = ia[i]; j < ia[i+1]; j++){ @@ -29,13 +29,13 @@ static void get_local_12_norm(int n, int i, const int *ia, const int *ja, } if (nz > 0) norm[1] /= nz; } -static void get_12_norm(int n, int *ia, int *ja, int *p, real *norm){ +static void get_12_norm(int n, int *ia, int *ja, int *p, double *norm){ /* norm[0] := antibandwidth norm[1] := (\sum_{{i,j}\in E} |p[i] - p[j]|)/|E| norm[2] := (\sum_{i\in V} (Min_{{j,i}\in E} |p[i] - p[j]|)/|V| */ int i, j, nz = 0; - real tmp; + double tmp; norm[0] = n; norm[1] = 0; norm[2] = 0; for (i = 0; i < n; i++){ tmp = n; @@ -55,8 +55,8 @@ static void get_12_norm(int n, int *ia, int *ja, int *p, real *norm){ void improve_antibandwidth_by_swapping(SparseMatrix A, int *p){ bool improved = true; int cnt = 1, n = A->m, i, j, *ia = A->ia, *ja = A->ja; - real norm1[3], norm2[3], norm11[3], norm22[3]; - real pi, pj; + double norm1[3], norm2[3], norm11[3], norm22[3]; + double pi, pj; clock_t start = clock(); FILE *fp = NULL; @@ -109,9 +109,9 @@ static void country_graph_coloring_internal(int seed, SparseMatrix A, int **p){ SparseMatrix L, A2; int *ia = A->ia, *ja = A->ja; int a = -1; - real nrow; - real *v = NULL; - real norm1[3]; + double nrow; + double *v = NULL; + double norm1[3]; clock_t start, start2; start = clock(); @@ -136,7 +136,7 @@ static void country_graph_coloring_internal(int seed, SparseMatrix A, int **p){ /* largest eigen vector */ { - real eig; + double eig; power_method(L, L->n, 1, seed, &v, &eig); } diff --git a/cmd/gvmap/gvmap.c b/cmd/gvmap/gvmap.c index 1c5ed5840..1cf66ff6b 100644 --- a/cmd/gvmap/gvmap.c +++ b/cmd/gvmap/gvmap.c @@ -35,19 +35,19 @@ typedef struct { char **infiles; FILE* outfile; int dim; - real shore_depth_tol; + double shore_depth_tol; int nrandom; int show_points; - real bbox_margin[2]; + double bbox_margin[2]; int useClusters; int clusterMethod; bool plotedges; int color_scheme; - real line_width; + double line_width; char *color_scheme_str; const char *opacity; char *plot_label; - real *bg_color; + double *bg_color; int improve_contiguity_n; int nart; bool color_optimize; @@ -148,7 +148,7 @@ init(int argc, char **argv, params_t* pm) { char* cmd = argv[0]; int c; - real s; + double s; int v, r; char stmp[3]; /* two character string plus '\0' */ @@ -284,7 +284,7 @@ init(int argc, char **argv, params_t* pm) case 'g': { gvcolor_t color; if (colorxlate(optarg, &color, RGBA_DOUBLE) == COLOR_OK) { - if (!pm->bg_color) pm->bg_color = N_NEW(3,real); + if (!pm->bg_color) pm->bg_color = N_NEW(3,double); pm->bg_color[0] = color.u.RGBA[0]; pm->bg_color[1] = color.u.RGBA[1]; pm->bg_color[2] = color.u.RGBA[2]; @@ -340,15 +340,15 @@ validateCluster (int n, int* grouping, int clust_num) } static void -makeMap (SparseMatrix graph, int n, real* x, real* width, int* grouping, +makeMap (SparseMatrix graph, int n, double* x, double* width, int* grouping, char** labels, float* fsz, float* rgb_r, float* rgb_g, float* rgb_b, params_t* pm, Agraph_t* g ) { int dim = pm->dim; int i, flag = 0; SparseMatrix poly_lines, polys, poly_point_map; - real edge_bridge_tol = 0.; + double edge_bridge_tol = 0.; int npolys, nverts, *polys_groups, exclude_random; - real *x_poly, *xcombined; + double *x_poly, *xcombined; SparseMatrix country_graph; int improve_contiguity_n = pm->improve_contiguity_n; #ifdef TIME @@ -382,7 +382,7 @@ makeMap (SparseMatrix graph, int n, real* x, real* width, int* grouping, } #ifdef TIME - fprintf(stderr, "map making time = %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC); + fprintf(stderr, "map making time = %f\n",((double) (clock() - cpu)) / CLOCKS_PER_SEC); #endif @@ -432,8 +432,8 @@ static void mapFromGraph (Agraph_t* g, params_t* pm) { SparseMatrix graph; int n; - real* width = NULL; - real* x; + double* width = NULL; + double* x; char** labels = NULL; int* grouping; float* rgb_r; diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index 188f33e5b..3c2a8fb50 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -31,7 +31,7 @@ #include #include -void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A0, real accuracy, int seed, +void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A0, double accuracy, int seed, float **rgb_r, float **rgb_g, float **rgb_b){ /* for a graph A, get a distinctive color of its nodes so that the color distanmce among all nodes are maximized. Here @@ -50,14 +50,14 @@ void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMat /*color: On input an array of size n*cdim, if NULL, will be allocated. On exit the final color assignment for node i is [cdim*i,cdim*(i+1)), in RGB (between 0 to 1) */ - real *colors = NULL; + double *colors = NULL; int n = A0->m, i, cdim; SparseMatrix A; int weightedQ = TRUE; int iter_max = 100; - {real *dist = NULL; + {double *dist = NULL; A = SparseMatrix_symmetrize(A0, FALSE); SparseMatrix_distance_matrix(A, 0, &dist); SparseMatrix_delete(A); @@ -106,25 +106,25 @@ static int get_poly_id(int ip, SparseMatrix point_poly_map){ return point_poly_map->ja[point_poly_map->ia[ip]]; } -void improve_contiguity(int n, int dim, int *grouping, SparseMatrix poly_point_map, real *x, SparseMatrix graph){ +void improve_contiguity(int n, int dim, int *grouping, SparseMatrix poly_point_map, double *x, SparseMatrix graph){ /* grouping: which group each of the vertex belongs to poly_point_map: a matrix of dimension npolys x (n + nrandom), poly_point_map[i,j] != 0 if polygon i contains the point j. . If j < n, it is the original point, otherwise it is artificial point (forming the rectangle around a label) or random points. */ int i, j, *ia, *ja, u, v; - real *a; + double *a; SparseMatrix point_poly_map, D; - real dist; + double dist; int nbad = 0, flag; int maxit = 10; - real tol = 0.001; + double tol = 0.001; D = SparseMatrix_get_real_adjacency_matrix_symmetrized(graph); assert(graph->m == n); ia = D->ia; ja = D->ja; - a = (real*) D->a; + a = (double*) D->a; /* point_poly_map: each row i has only 1 entry at column j, which says that point i is in polygon j */ point_poly_map = SparseMatrix_transpose(poly_point_map); @@ -146,7 +146,7 @@ void improve_contiguity(int n, int dim, int *grouping, SparseMatrix poly_point_m } } - if (Verbose) fprintf(stderr,"ratio (edges among discontiguous regions vs total edges)=%f\n",((real) nbad)/ia[n]); + if (Verbose) fprintf(stderr,"ratio (edges among discontiguous regions vs total edges)=%f\n",((double) nbad)/ia[n]); stress_model(dim, D, D, &x, FALSE, maxit, tol, &flag); assert(!flag); @@ -157,10 +157,10 @@ void improve_contiguity(int n, int dim, int *grouping, SparseMatrix poly_point_m struct Triangle { int vertices[3];/* 3 points */ - real center[2]; /* center of the triangle */ + double center[2]; /* center of the triangle */ }; -static void normal(real v[], real normal[]){ +static void normal(double v[], double normal[]){ if (v[0] == 0){ normal[0] = 1; normal[1] = 0; } else { @@ -169,7 +169,7 @@ static void normal(real v[], real normal[]){ } } -static void triangle_center(real x[], real y[], real z[], real c[]){ +static void triangle_center(double x[], double y[], double z[], double c[]){ /* find the "center" c, which is the intersection of the 3 vectors that are normal to each of the edges respectively, and which passes through the center of the edges respectively center[{x_, y_, z_}] := Module[ @@ -184,7 +184,7 @@ static void triangle_center(real x[], real y[], real z[], real c[]){ ] */ - real xy[2], yz[2], nxy[2], nyz[2], ymx[2], ymz[2], beta, bot; + double xy[2], yz[2], nxy[2], nyz[2], ymx[2], ymz[2], beta, bot; int i; for (i = 0; i < 2; i++) ymx[i] = y[i] - x[i]; @@ -229,7 +229,7 @@ static void plot_dot_edges(FILE *f, SparseMatrix A){ } } -static void plot_dot_labels(FILE *f, int n, int dim, real *x, char **labels, float *fsz){ +static void plot_dot_labels(FILE *f, int n, int dim, double *x, char **labels, float *fsz){ int i; for (i = 0; i < n; i++){ @@ -242,7 +242,7 @@ static void plot_dot_labels(FILE *f, int n, int dim, real *x, char **labels, flo } -static void dot_polygon(agxbuf *sbuff, int np, float *xp, float *yp, real line_width, +static void dot_polygon(agxbuf *sbuff, int np, float *xp, float *yp, double line_width, int fill, const char *cstring){ if (np > 0){ @@ -263,14 +263,14 @@ static void dot_polygon(agxbuf *sbuff, int np, float *xp, float *yp, real line_w } } -static void dot_one_poly(agxbuf *sbuff, real line_width, int fill, int np, +static void dot_one_poly(agxbuf *sbuff, double line_width, int fill, int np, float *xp, float *yp, const char *cstring) { dot_polygon(sbuff, np, xp, yp, line_width, fill, cstring); } -static void plot_dot_polygons(agxbuf *sbuff, real line_width, +static void plot_dot_polygons(agxbuf *sbuff, double line_width, const char *line_color, SparseMatrix polys, - real *x_poly, int *polys_groups, float *r, + double *x_poly, int *polys_groups, float *r, float *g, float *b, const char *opacity) { int i, j, *ia = polys->ia, *ja = polys->ja, *a = (int*) polys->a, npolys = polys->m, nverts = polys->n, ipoly,first; int np = 0, maxlen = 0; @@ -311,9 +311,9 @@ static void plot_dot_polygons(agxbuf *sbuff, real line_width, free(yp); } -void plot_dot_map(Agraph_t* gr, int n, int dim, real *x, SparseMatrix polys, - SparseMatrix poly_lines, real line_width, - const char *line_color, real *x_poly, int *polys_groups, +void plot_dot_map(Agraph_t* gr, int n, int dim, double *x, SparseMatrix polys, + SparseMatrix poly_lines, double line_width, + const char *line_color, double *x_poly, int *polys_groups, char **labels, float *fsz, float *r, float *g, float *b, const char* opacity, SparseMatrix A, FILE* f) { /* if graph object exist, we just modify some attributes, otherwise we dump the whole graph */ @@ -368,7 +368,7 @@ void plot_dot_map(Agraph_t* gr, int n, int dim, real *x, SparseMatrix polys, agxbfree(&sbuff); } -static void get_tri(int n, int dim, real *x, int *nt, struct Triangle **T, SparseMatrix *E) { +static void get_tri(int n, int dim, double *x, int *nt, struct Triangle **T, SparseMatrix *E) { /* always contains a self edge and is symmetric. input: n: number of points @@ -636,9 +636,9 @@ static void get_poly_lines(int exclude_random, int nt, SparseMatrix graph, Spars free(elist); } -static void plot_cycle(int head, int *cycle, int *edge_table, real *x){ +static void plot_cycle(int head, int *cycle, int *edge_table, double *x){ int cur, next; - real x1, x2, y1, y2; + double x1, x2, y1, y2; printf("Graphics[{"); cur = head; @@ -685,7 +685,7 @@ static int same_edge(int ecur, int elast, int *edge_table){ } static void get_polygon_solids(int nt, SparseMatrix E, int ncomps, int *comps_ptr, int *comps, - int *mask, real *x_poly, SparseMatrix *polys){ + int *mask, double *x_poly, SparseMatrix *polys){ /*============================================================ polygon slids that will be colored @@ -944,7 +944,7 @@ static void get_polygon_solids(int nt, SparseMatrix E, int ncomps, int *comps_pt } static void get_polygons(int exclude_random, int n, int nrandom, int dim, SparseMatrix graph, int *grouping, - int nt, struct Triangle *Tp, SparseMatrix E, int *nverts, real **x_poly, + int nt, struct Triangle *Tp, SparseMatrix E, int *nverts, double **x_poly, int *npolys, SparseMatrix *poly_lines, SparseMatrix *polys, int **polys_groups, SparseMatrix *poly_point_map, SparseMatrix *country_graph){ int i, j; int *mask; @@ -998,7 +998,7 @@ static void get_polygons(int exclude_random, int n, int nrandom, int dim, Sparse } *npolys = ncomps; - *x_poly = MALLOC(sizeof(real)*dim*nt); + *x_poly = MALLOC(sizeof(double)*dim*nt); for (i = 0; i < nt; i++){ for (j = 0; j < dim; j++){ (*x_poly)[i*dim+j] = Tp[i].center[j]; @@ -1027,23 +1027,23 @@ static void get_polygons(int exclude_random, int n, int nrandom, int dim, Sparse } static int make_map_internal(int exclude_random, int include_OK_points, - int n, int dim, real *x0, int *grouping0, SparseMatrix graph, real bounding_box_margin[], int *nrandom, int nedgep, - real shore_depth_tol, real **xcombined, int *nverts, real **x_poly, + int n, int dim, double *x0, int *grouping0, SparseMatrix graph, double bounding_box_margin[], int *nrandom, int nedgep, + double shore_depth_tol, double **xcombined, int *nverts, double **x_poly, int *npolys, SparseMatrix *poly_lines, SparseMatrix *polys, int **polys_groups, SparseMatrix *poly_point_map, SparseMatrix *country_graph, int highlight_cluster, int *flag){ - real xmax[2], xmin[2], area, *x = x0; + double xmax[2], xmin[2], area, *x = x0; int i, j; QuadTree qt; int dim2 = 2, nn = 0; int max_qtree_level = 10; - real ymin[2], min; + double ymin[2], min; int imin, nz, nzok = 0, nzok0 = 0, nt; - real *xran, point[2]; + double *xran, point[2]; struct Triangle *Tp; SparseMatrix E; - real boxsize[2]; + double boxsize[2]; int INCLUDE_OK_POINTS = include_OK_points;/* OK points are random points inserted and found to be within shore_depth_tol of real/artificial points, including them instead of throwing away increase realism of boundary */ int *grouping = grouping0; @@ -1076,7 +1076,7 @@ static int make_map_internal(int exclude_random, int include_OK_points, *nrandom -= 4; } - if (shore_depth_tol < 0) shore_depth_tol = sqrt(area/(real) n); /* set to average distance for random distribution */ + if (shore_depth_tol < 0) shore_depth_tol = sqrt(area/(double) n); /* set to average distance for random distribution */ if (Verbose) fprintf(stderr,"nrandom=%d shore_depth_tol=%.08f\n",*nrandom, shore_depth_tol); @@ -1084,12 +1084,12 @@ static int make_map_internal(int exclude_random, int include_OK_points, two connected components be separated due to small shore depth */ { int nz; - real *y; + double *y; int k, t, np=nedgep; if (graph && np){ fprintf(stderr,"add art np = %d\n",np); nz = graph->nz; - y = MALLOC(sizeof(real)*(dim*n + dim*nz*np)); + y = MALLOC(sizeof(double)*(dim*n + dim*nz*np)); for (i = 0; i < n*dim; i++) y[i] = x[i]; grouping = MALLOC(sizeof(int)*(n + nz*np)); for (i = 0; i < n; i++) grouping[i] = grouping0[i]; @@ -1100,10 +1100,10 @@ static int make_map_internal(int exclude_random, int include_OK_points, if (!HIGHLIGHT_SET || (grouping[i] == grouping[graph->ja[j]] && grouping[i] == HIGHLIGHT_SET)){ for (t = 0; t < np; t++){ for (k = 0; k < dim; k++){ - y[nz*dim+k] = t/((real) np)*x[i*dim+k] + (1-t/((real) np))*x[(graph->ja[j])*dim + k]; + y[nz*dim+k] = t/((double) np)*x[i*dim+k] + (1-t/((double) np))*x[(graph->ja[j])*dim + k]; } assert(n + (nz-n)*np + t < n + nz*np && n + (nz-n)*np + t >= 0); - if (t/((real) np) > 0.5){ + if (t/((double) np) > 0.5){ grouping[nz] = grouping[i]; } else { grouping[nz] = grouping[graph->ja[j]]; @@ -1139,8 +1139,8 @@ static int make_map_internal(int exclude_random, int include_OK_points, } } if (Verbose) { - real bbm0 = bounding_box_margin[0]; - real bbm1 = bounding_box_margin[1]; + double bbm0 = bounding_box_margin[0]; + double bbm1 = bounding_box_margin[1]; if (bbm0 > 0) fprintf (stderr, "bounding box margin: %.06f", bbm0); else if (bbm0 < 0) @@ -1155,14 +1155,14 @@ static int make_map_internal(int exclude_random, int include_OK_points, fprintf (stderr, " %.06f\n", MAX(boxsize[1]*0.2, 2*shore_depth_tol)); } if (*nrandom < 0) { - real n1, n2, area2; + double n1, n2, area2; area2 = (xmax[1] - xmin[1])*(xmax[0] - xmin[0]); n1 = (int) area2/(shore_depth_tol*shore_depth_tol); n2 = n*((int) area2/area); *nrandom = MAX(n1, n2); } srand(123); - xran = MALLOC(sizeof(real)*(*nrandom + 4)*dim2); + xran = MALLOC(sizeof(double)*(*nrandom + 4)*dim2); nz = 0; if (INCLUDE_OK_POINTS){ nzok0 = nzok = *nrandom - 1;/* points that are within tolerance of real or artificial points */ @@ -1203,7 +1203,7 @@ static int make_map_internal(int exclude_random, int include_OK_points, *nrandom = nz; if (Verbose) fprintf( stderr, "nn nrandom=%d\n",*nrandom); } else { - xran = MALLOC(sizeof(real)*4*dim2); + xran = MALLOC(sizeof(double)*4*dim2); } @@ -1223,9 +1223,9 @@ static int make_map_internal(int exclude_random, int include_OK_points, if (INCLUDE_OK_POINTS){ - *xcombined = MALLOC(sizeof(real)*(nn+*nrandom)*dim2); + *xcombined = MALLOC(sizeof(double)*(nn+*nrandom)*dim2); } else { - *xcombined = MALLOC(sizeof(real)*(n+*nrandom)*dim2); + *xcombined = MALLOC(sizeof(double)*(n+*nrandom)*dim2); } for (i = 0; i < n; i++) { for (j = 0; j < dim2; j++) (*xcombined)[i*dim2+j] = x[i*dim+j]; @@ -1244,10 +1244,10 @@ static int make_map_internal(int exclude_random, int include_OK_points, { int nz, nh = 0;/* the set to highlight */ - real *xtemp; + double *xtemp; if (HIGHLIGHT_SET){ if (Verbose) fprintf(stderr," highlight cluster %d, n = %d\n",HIGHLIGHT_SET, n); - xtemp = MALLOC(sizeof(real)*n*dim); + xtemp = MALLOC(sizeof(double)*n*dim); /* shift set to the beginning */ nz = 0; for (i = 0; i < n; i++){ @@ -1272,7 +1272,7 @@ static int make_map_internal(int exclude_random, int include_OK_points, for (i = nh; i < n; i++){ grouping[i] = 2; } - memcpy(*xcombined, xtemp, n*dim*sizeof(real)); + memcpy(*xcombined, xtemp, n*dim*sizeof(double)); *nrandom += n - nh;/* count everything except cluster HIGHLIGHT_SET as random */ n = nh; if (Verbose) fprintf(stderr,"nh = %d\n",nh); @@ -1292,11 +1292,11 @@ static int make_map_internal(int exclude_random, int include_OK_points, return 0; } -static void add_point(int *n, int igrp, real **x, int *nmax, real point[], int **groups){ +static void add_point(int *n, int igrp, double **x, int *nmax, double point[], int **groups){ if (*n >= *nmax){ *nmax = MAX((int) 0.2*(*n), 20) + *n; - *x = REALLOC(*x, sizeof(real)*2*(*nmax)); + *x = REALLOC(*x, sizeof(double)*2*(*nmax)); *groups = REALLOC(*groups, sizeof(int)*(*nmax)); } @@ -1306,7 +1306,7 @@ static void add_point(int *n, int igrp, real **x, int *nmax, real point[], int * (*n)++; } -static void get_boundingbox(int n, int dim, real *x, real *width, real *bbox){ +static void get_boundingbox(int n, int dim, double *x, double *width, double *bbox){ int i; bbox[0] = bbox[1] = x[0]; bbox[2] = bbox[3] = x[1]; @@ -1320,10 +1320,10 @@ static void get_boundingbox(int n, int dim, real *x, real *width, real *bbox){ } int make_map_from_rectangle_groups(int exclude_random, int include_OK_points, - int n, int dim, real *x, real *sizes, - int *grouping, SparseMatrix graph0, real bounding_box_margin[], int *nrandom, int *nart, int nedgep, - real shore_depth_tol, real edge_bridge_tol, - real **xcombined, int *nverts, real **x_poly, + int n, int dim, double *x, double *sizes, + int *grouping, SparseMatrix graph0, double bounding_box_margin[], int *nrandom, int *nart, int nedgep, + double shore_depth_tol, double edge_bridge_tol, + double **xcombined, int *nverts, double **x_poly, int *npolys, SparseMatrix *poly_lines, SparseMatrix *polys, int **polys_groups, SparseMatrix *poly_point_map, SparseMatrix *country_graph, int highlight_cluster, int *flag){ @@ -1386,18 +1386,18 @@ int make_map_from_rectangle_groups(int exclude_random, int include_OK_points, */ - real dist, avgdist; - real *X; + double dist, avgdist; + double *X; int N, nmax, i, j, k, igrp; int *groups, K = *nart;/* average number of points added per side of rectangle */ - real avgsize[2], avgsz, h[2], p1, p0; - real point[2]; + double avgsize[2], avgsz, h[2], p1, p0; + double point[2]; int nadded[2]; int res; - real delta[2]; + double delta[2]; SparseMatrix graph = graph0; - real bbox[4]; + double bbox[4]; if (K < 0){ K = (int) 10/(1+n/400.);/* 0 if n > 3600*/ @@ -1432,7 +1432,7 @@ int make_map_from_rectangle_groups(int exclude_random, int include_OK_points, if (Verbose) fprintf(stderr, "avgsize = {%f, %f}\n",avgsize[0], avgsize[1]); nmax = 2*n; - X = MALLOC(sizeof(real)*dim*(n+nmax)); + X = MALLOC(sizeof(double)*dim*(n+nmax)); groups = MALLOC(sizeof(int)*(n+nmax)); for (i = 0; i < n; i++) { groups[i] = grouping[i]; @@ -1445,10 +1445,10 @@ int make_map_from_rectangle_groups(int exclude_random, int include_OK_points, if (shore_depth_tol < 0) { shore_depth_tol = -(shore_depth_tol)*avgsz; } else if (shore_depth_tol == 0){ - real area; + double area; get_boundingbox(n, dim, x, sizes, bbox); area = (bbox[1] - bbox[0])*(bbox[3] - bbox[2]); - shore_depth_tol = sqrt(area/(real) n); + shore_depth_tol = sqrt(area/(double) n); if (Verbose) fprintf(stderr,"setting shore length ======%f\n",shore_depth_tol); } else { } diff --git a/cmd/gvmap/make_map.h b/cmd/gvmap/make_map.h index 17b129a77..ff2900127 100644 --- a/cmd/gvmap/make_map.h +++ b/cmd/gvmap/make_map.h @@ -13,22 +13,22 @@ #include #include -int make_map_from_rectangle_groups(int exclude_random, int include_OK_points, int n, int dim, real *x, real *sizes, - int *grouping, SparseMatrix graph, real bounding_box_margin[], int *nrandom,int *nart, int nedgep, - real shore_depth_tol, real edge_bridge_tol, real **xcombined, int *nverts, real **x_poly, +int make_map_from_rectangle_groups(int exclude_random, int include_OK_points, int n, int dim, double *x, double *sizes, + int *grouping, SparseMatrix graph, double bounding_box_margin[], int *nrandom,int *nart, int nedgep, + double shore_depth_tol, double edge_bridge_tol, double **xcombined, int *nverts, double **x_poly, int *npolys, SparseMatrix *poly_lines, SparseMatrix *polys, int **polys_groups, SparseMatrix *poly_point_map, SparseMatrix *country_graph, int highlight_cluster, int *flag); -void improve_contiguity(int n, int dim, int *grouping, SparseMatrix poly_point_map, real *x, SparseMatrix graph); +void improve_contiguity(int n, int dim, int *grouping, SparseMatrix poly_point_map, double *x, SparseMatrix graph); -void plot_dot_map(Agraph_t* gr, int n, int dim, real *x, SparseMatrix polys, - SparseMatrix poly_lines, real line_width, - const char *line_color, real *x_poly, int *polys_groups, +void plot_dot_map(Agraph_t* gr, int n, int dim, double *x, SparseMatrix polys, + SparseMatrix poly_lines, double line_width, + const char *line_color, double *x_poly, int *polys_groups, char **labels, float *fsz, float *r, float *g, float *b, const char* opacity, SparseMatrix A, FILE*); void map_optimal_coloring(int seed, SparseMatrix A, float *rgb_r, float *rgb_g, float *rgb_b); -void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A, real accuracy, int seed, float **rgb_r, float **rgb_g, float **rgb_b); +void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A, double accuracy, int seed, float **rgb_r, float **rgb_g, float **rgb_b); enum {POLY_LINE_REAL_EDGE, POLY_LINE_NOT_REAL_EDGE}; #define neighbor(t, i, edim, elist) elist[(edim)*(t)+i] diff --git a/cmd/gvmap/power.c b/cmd/gvmap/power.c index 2a229aec9..af92ee701 100644 --- a/cmd/gvmap/power.c +++ b/cmd/gvmap/power.c @@ -15,10 +15,10 @@ static const int maxit = 100; // Accuracy control (convergence criterion) for power_method -static const real tolerance = 0.00001; +static const double tolerance = 0.00001; void power_method(void *A, int n, int K, int random_seed, - real **eigv, real *eigs){ + double **eigv, double *eigs){ /* find k-largest eigenvectors of a matrix A. Result in eigv. if eigv == NULL; memory will be allocated. This converges only if the largest eigenvectors/values are real (e.g., if A is symmetric) and the @@ -54,20 +54,20 @@ void power_method(void *A, int n, int K, int random_seed, end for return v1,v2,... */ - real **v, *u, *vv; + double **v, *u, *vv; int iter = 0; - real res, unorm; + double res, unorm; int i, j, k; - real uij; + double uij; K = MAX(0, MIN(n, K)); assert(K <= n && K > 0); - if (!(*eigv)) *eigv = MALLOC(sizeof(real)*n*K); - v = MALLOC(sizeof(real*)*K); + if (!(*eigv)) *eigv = MALLOC(sizeof(double)*n*K); + v = MALLOC(sizeof(double*)*K); - vv = MALLOC(sizeof(real)*n); - u = MALLOC(sizeof(real)*n); + vv = MALLOC(sizeof(double)*n); + u = MALLOC(sizeof(double)*n); srand(random_seed); diff --git a/cmd/gvmap/power.h b/cmd/gvmap/power.h index 342cce1a2..1ab1cf520 100644 --- a/cmd/gvmap/power.h +++ b/cmd/gvmap/power.h @@ -13,4 +13,4 @@ #include void power_method(void *A, int n, int K, int random_seed, - real **eigv, real *eigs); + double **eigv, double *eigs); diff --git a/cmd/mingle/minglemain.c b/cmd/mingle/minglemain.c index 4523941df..caffbfc03 100644 --- a/cmd/mingle/minglemain.c +++ b/cmd/mingle/minglemain.c @@ -37,12 +37,12 @@ typedef struct { int outer_iter; int method; int compatibility_method; - real K; + double K; fmt_t fmt; int nneighbors; int max_recursion; - real angle_param; - real angle; + double angle_param; + double angle; } opts_t; static char *fname; @@ -109,7 +109,7 @@ static void init(int argc, char *argv[], opts_t* opts) { int c; char* cmd = argv[0]; - real s; + double s; int i; opterr = 0; @@ -240,10 +240,10 @@ genBundleSpline (pedge edge, agxbuf* xb) { int k, j, mm, kk; int dim = edge->dim; - real* x = edge->x; - real tt1[3]={0.15,0.5,0.85}; - real tt2[4]={0.15,0.4,0.6,0.85}; - real t, *tt; + double* x = edge->x; + double tt1[3]={0.15,0.5,0.85}; + double tt2[4]={0.15,0.4,0.6,0.85}; + double t, *tt; for (j = 0; j < edge->npoints; j++){ if (j != 0) { @@ -278,7 +278,7 @@ genBundleInfo (pedge edge, agxbuf* xb) { int k, j; int dim = edge->dim; - real* x = edge->x; + double* x = edge->x; for (j = 0; j < edge->npoints; j++){ if (j != 0) agxbputc(xb, ':'); @@ -294,13 +294,13 @@ genBundleInfo (pedge edge, agxbuf* xb) } static void -genBundleColors (pedge edge, agxbuf* xb, real maxwgt) +genBundleColors (pedge edge, agxbuf* xb, double maxwgt) { int k, j, r, g, b; - real len, t, len_total0 = 0; + double len, t, len_total0 = 0; int dim = edge->dim; - real* x = edge->x; - real* lens = MALLOC(sizeof(real)*edge->npoints); + double* x = edge->x; + double* lens = MALLOC(sizeof(double)*edge->npoints); for (j = 0; j < edge->npoints - 1; j++){ len = 0; @@ -332,7 +332,7 @@ export_dot (FILE* fp, int ne, pedge *edges, Agraph_t* g) Agnode_t* n; Agedge_t* e; int i, j; - real maxwgt = 0; + double maxwgt = 0; pedge edge; agxbuf xbuf; unsigned char buf[BUFSIZ]; @@ -372,14 +372,14 @@ export_dot (FILE* fp, int ne, pedge *edges, Agraph_t* g) static int bundle (Agraph_t* g, opts_t* opts) { - real *x = NULL; - real *label_sizes = NULL; + double *x = NULL; + double *label_sizes = NULL; int n_edge_label_nodes; int dim = 2; SparseMatrix A; SparseMatrix B; pedge* edges; - real *xx, eps = 0.; + double *xx, eps = 0.; int nz = 0; int *ia, *ja, i, j, k; int rv = 0; @@ -437,7 +437,7 @@ bundle (Agraph_t* g, opts_t* opts) ia = A->ia; ja = A->ja; nz = A->nz; - xx = MALLOC(sizeof(real)*nz*4); + xx = MALLOC(sizeof(double)*nz*4); nz = 0; dim = 4; for (i = 0; i < A->m; i++){ diff --git a/cmd/tools/matrix_market.c b/cmd/tools/matrix_market.c index 464fa8ef7..1b8ad43c3 100644 --- a/cmd/tools/matrix_market.c +++ b/cmd/tools/matrix_market.c @@ -57,7 +57,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) { int ret_code, type; MM_typecode matcode; - real *val = NULL, *v; + double *val = NULL, *v; int *vali = NULL, i, m, n, *I = NULL, *J = NULL, nz; void *vp = NULL; SparseMatrix A = NULL; @@ -114,7 +114,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) type = mm_get_type(matcode); switch (type) { case MATRIX_TYPE_REAL: - val = malloc(nz * sizeof(real)); + val = malloc(nz * sizeof(double)); for (i = 0; i < nz; i++) { fscanf(f, "%d %d %lg\n", &I[i], &J[i], &val[i]); I[i]--; /* adjust from 1-based to 0-based */ @@ -123,7 +123,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) if (mm_is_symmetric(matcode)) { I = REALLOC(I, 2 * sizeof(int) * nz); J = REALLOC(J, 2 * sizeof(int) * nz); - val = REALLOC(val, 2 * sizeof(real) * nz); + val = REALLOC(val, 2 * sizeof(double) * nz); nzold = nz; for (i = 0; i < nzold; i++) { if (I[i] != J[i]) { @@ -135,7 +135,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) } else if (mm_is_skew(matcode)) { I = REALLOC(I, 2 * sizeof(int) * nz); J = REALLOC(J, 2 * sizeof(int) * nz); - val = REALLOC(val, 2 * sizeof(real) * nz); + val = REALLOC(val, 2 * sizeof(double) * nz); nzold = nz; for (i = 0; i < nzold; i++) { assert(I[i] != J[i]); /* skew symm has no diag */ @@ -204,7 +204,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) } break; case MATRIX_TYPE_COMPLEX: - val = malloc(2 * nz * sizeof(real)); + val = malloc(2 * nz * sizeof(double)); v = val; for (i = 0; i < nz; i++) { fscanf(f, "%d %d %lg %lg\n", &I[i], &J[i], &v[0], &v[1]); @@ -215,7 +215,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) if (mm_is_symmetric(matcode)) { I = REALLOC(I, 2 * sizeof(int) * nz); J = REALLOC(J, 2 * sizeof(int) * nz); - val = REALLOC(val, 4 * sizeof(real) * nz); + val = REALLOC(val, 4 * sizeof(double) * nz); nzold = nz; for (i = 0; i < nzold; i++) { if (I[i] != J[i]) { @@ -229,7 +229,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) } else if (mm_is_skew(matcode)) { I = REALLOC(I, 2 * sizeof(int) * nz); J = REALLOC(J, 2 * sizeof(int) * nz); - val = REALLOC(val, 4 * sizeof(real) * nz); + val = REALLOC(val, 4 * sizeof(double) * nz); nzold = nz; for (i = 0; i < nzold; i++) { assert(I[i] != J[i]); /* skew symm has no diag */ @@ -243,7 +243,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) } else if (mm_is_hermitian(matcode)) { I = REALLOC(I, 2 * sizeof(int) * nz); J = REALLOC(J, 2 * sizeof(int) * nz); - val = REALLOC(val, 4 * sizeof(real) * nz); + val = REALLOC(val, 4 * sizeof(double) * nz); nzold = nz; for (i = 0; i < nzold; i++) { if (I[i] != J[i]) { @@ -263,7 +263,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) if (format == FORMAT_CSR) { A = SparseMatrix_from_coordinate_arrays(nz, m, n, I, J, vp, - type, sizeof(real)); + type, sizeof(double)); } else { A = SparseMatrix_new(m, n, 1, type, FORMAT_COORD); A = SparseMatrix_coordinate_form_add_entries(A, nz, I, J, vp); diff --git a/cmd/tools/mm2gv.c b/cmd/tools/mm2gv.c index 637660f4b..a952fad78 100644 --- a/cmd/tools/mm2gv.c +++ b/cmd/tools/mm2gv.c @@ -25,7 +25,6 @@ #define MALLOC malloc #define test_flag(a, flag) ((a)&(flag)) -#define real double #define BUFS 1024 typedef struct { @@ -37,7 +36,7 @@ typedef struct { static char *cmd; -static real Hue2RGB(real v1, real v2, real H) +static double Hue2RGB(double v1, double v2, double H) { if (H < 0.0) H += 1.0; @@ -52,9 +51,9 @@ static real Hue2RGB(real v1, real v2, real H) return v1; } -static char *hue2rgb(real hue, char *color) +static char *hue2rgb(double hue, char *color) { - real v1, v2, lightness = .5, saturation = 1; + double v1, v2, lightness = .5, saturation = 1; int red, blue, green; if (lightness < 0.5) @@ -72,7 +71,7 @@ static char *hue2rgb(real hue, char *color) } static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim, - real * x, int with_color, int with_label, int with_val) + double * x, int with_color, int with_label, int with_val) { Agraph_t *g; Agnode_t *n; @@ -85,9 +84,9 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim, Agsym_t *sym, *sym2 = NULL, *sym3 = NULL; int *ia = A->ia; int *ja = A->ja; - real *val = (real *) (A->a); + double *val = (double *) (A->a); Agnode_t **arr = N_NEW(A->m, Agnode_t *); - real *color = NULL; + double *color = NULL; char cstring[8]; name = strip_dir(name); @@ -127,14 +126,14 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim, } if (with_color) { - real maxdist = 0.; - real mindist = 0.; + double maxdist = 0.; + double mindist = 0.; int first = TRUE; sym2 = agattr(g, AGEDGE, "color", ""); sym3 = agattr(g, AGEDGE, "wt", ""); agattr(g, AGRAPH, "bgcolor", "black"); - color = N_NEW(A->nz, real); + color = N_NEW(A->nz, double); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { i = ND_id(n); if (A->type != MATRIX_TYPE_REAL) { diff --git a/lib/edgepaint/edge_distinct_coloring.c b/lib/edgepaint/edge_distinct_coloring.c index f0cd13e18..6ab87c6a1 100644 --- a/lib/edgepaint/edge_distinct_coloring.c +++ b/lib/edgepaint/edge_distinct_coloring.c @@ -18,7 +18,7 @@ #include static int splines_intersect(int dim, int u1, int v1, int u2, int v2, - real cos_critical, int check_edges_with_same_endpoint, + double cos_critical, int check_edges_with_same_endpoint, char *xsplines1, char *xsplines2){ /* u1, v2 an u2, v2: the node index of the two edn points of two edges. cos_critical: cos of critical angle @@ -29,15 +29,15 @@ static int splines_intersect(int dim, int u1, int v1, int u2, int v2, */ int itmp; int len1 = 100, len2 = 100; - real *x1, *x2; + double *x1, *x2; int ns1 = 0, ns2 = 0; int i, j, iter1 = 0, iter2 = 0; - real cos_a, tmp[2]; + double cos_a, tmp[2]; int endp1 = 0, endp2 = 0; tmp[0] = tmp[1] = 0; - x1 = MALLOC(sizeof(real)*len1); - x2 = MALLOC(sizeof(real)*len2); + x1 = MALLOC(sizeof(double)*len1); + x2 = MALLOC(sizeof(double)*len2); assert(dim <= 3); /* if two end points are the same, make sure they are the first in each edge */ @@ -75,14 +75,14 @@ static int splines_intersect(int dim, int u1, int v1, int u2, int v2, xsplines1++; if (ns1*dim >= len1){ len1 = ns1*dim + (int)MAX(10, 0.2*ns1*dim); - x1 = REALLOC(x1, sizeof(real)*len1); + x1 = REALLOC(x1, sizeof(double)*len1); } } if (endp1){/* pad the end point at the last position */ ns1++; if (ns1*dim >= len1){ len1 = ns1*dim + (int)MAX(10, 0.2*ns1*dim); - x1 = REALLOC(x1, sizeof(real)*len1); + x1 = REALLOC(x1, sizeof(double)*len1); } x1[(ns1-1)*dim] = tmp[0]; x1[(ns1-1)*dim + 1] = tmp[1]; } @@ -113,14 +113,14 @@ static int splines_intersect(int dim, int u1, int v1, int u2, int v2, xsplines2++; if (ns2*dim >= len2){ len2 = ns2*dim + (int)MAX(10, 0.2*ns2*dim); - x2 = REALLOC(x2, sizeof(real)*len2); + x2 = REALLOC(x2, sizeof(double)*len2); } } if (endp2){/* pad the end point at the last position */ ns2++; if (ns2*dim >= len2){ len2 = ns2*dim + (int)MAX(10, 0.2*ns2*dim); - x2 = REALLOC(x2, sizeof(real)*len2); + x2 = REALLOC(x2, sizeof(double)*len2); } x2[(ns2-1)*dim] = tmp[0]; x2[(ns2-1)*dim + 1] = tmp[1]; } @@ -142,7 +142,7 @@ for (i = 0; i < ns1 - 1; i++){ } -Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* g, real angle, real accuracy, int check_edges_with_same_endpoint, int seed){ +Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* g, double angle, double accuracy, int check_edges_with_same_endpoint, int seed){ /* color the edges of a graph so that conflicting edges are as dinstrinct in color as possibl. color_scheme: rgb, lab, gray, or a list of comma separaterd RGB colors in hex, like #ff0000,#00ff00 lightness: of the form 0,70, specifying the range of lightness of LAB color. Ignored if scheme is not COLOR_LAB. @@ -155,13 +155,13 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* . are not consider conflict. seed: random_seed. If negative, consider -seed as the number of random start iterations */ - real *x = NULL; + double *x = NULL; int dim = 2; SparseMatrix A, B, C; int *irn, *jcn, nz, nz2 = 0; - real cos_critical = cos(angle/180*3.14159), cos_a; + double cos_critical = cos(angle/180*3.14159), cos_a; int u1, v1, u2, v2, i, j; - real *colors = NULL; + double *colors = NULL; int flag, ne; char **xsplines = NULL; int cdim; @@ -205,7 +205,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* } } #ifdef TIME - fprintf(stderr, "cpu for dual graph =%10.3f", ((real) (clock() - start))/CLOCKS_PER_SEC); + fprintf(stderr, "cpu for dual graph =%10.3f", ((double) (clock() - start))/CLOCKS_PER_SEC); #endif } else { @@ -227,7 +227,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* } } #ifdef TIME - fprintf(stderr, "cpu for dual graph (splines) =%10.3f\n", ((real) (clock() - start))/CLOCKS_PER_SEC); + fprintf(stderr, "cpu for dual graph (splines) =%10.3f\n", ((double) (clock() - start))/CLOCKS_PER_SEC); #endif } C = SparseMatrix_from_coordinate_format(B); @@ -242,7 +242,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* flag = node_distinct_coloring(color_scheme, lightness, weightedQ, C, accuracy, iter_max, seed, &cdim, &colors); if (flag) goto RETURN; #ifdef TIME - fprintf(stderr, "cpu for color assignmment =%10.3f\n", ((real) (clock() - start))/CLOCKS_PER_SEC); + fprintf(stderr, "cpu for color assignmment =%10.3f\n", ((double) (clock() - start))/CLOCKS_PER_SEC); #endif } diff --git a/lib/edgepaint/edge_distinct_coloring.h b/lib/edgepaint/edge_distinct_coloring.h index e9b25096e..527214371 100644 --- a/lib/edgepaint/edge_distinct_coloring.h +++ b/lib/edgepaint/edge_distinct_coloring.h @@ -10,4 +10,4 @@ #pragma once -Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* g, real angle, real accuracy, int check_edges_with_same_endpoint, int seed); +Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* g, double angle, double accuracy, int check_edges_with_same_endpoint, int seed); diff --git a/lib/edgepaint/furtherest_point.c b/lib/edgepaint/furtherest_point.c index 425c64614..86985bd58 100644 --- a/lib/edgepaint/furtherest_point.c +++ b/lib/edgepaint/furtherest_point.c @@ -12,17 +12,17 @@ #include #include -static real dist(int dim, real *x, real *y){ +static double dist(int dim, double *x, double *y){ int k; - real d = 0; + double d = 0; for (k = 0; k < dim; k++) d += (x[k] - y[k])*(x[k]-y[k]); return sqrt(d); } -static real distance_to_group(int k, int dim, real *wgt, real *pts, real *center, real (*usr_dist)(int, real*, real*)){ +static double distance_to_group(int k, int dim, double *wgt, double *pts, double *center, double (*usr_dist)(int, double*, double*)){ int i; - real distance = -1, dist_min = 0; + double distance = -1, dist_min = 0; if (!wgt){ for (i = 0; i < k; i++){ distance = (*usr_dist)(dim, &(pts[i*dim]), center); @@ -45,7 +45,7 @@ static real distance_to_group(int k, int dim, real *wgt, real *pts, real *center return dist_min; } -void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real width, int max_level, real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax){ +void furtherest_point(int k, int dim, double *wgt, double *pts, double *center, double width, int max_level, double (*usr_dist)(int, double*, double*), double *dist_max, double **argmax){ /* Assume that in the box defined by {center, width} are feasible; find, in the, a point "furtherest_point" that is furtherest away from a group of k-points pts, using quadtree, with up to max_level. Here the distance of a point to a group of point is defined as the minimum @@ -72,10 +72,10 @@ void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real w QuadTree *candidates, *ctmp;/* a cadidate array of quadtrees */ int ncandidates2 = 10, ncandidates2_max = 10; QuadTree *candidates2;/* a cadidate array of quadtrees */ - real distance; + double distance; int level = 0; int i, ii, j, pruned; - real wmax = 0; + double wmax = 0; if (!usr_dist) usr_dist = dist; if (wgt){ @@ -87,8 +87,8 @@ void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real w qt0 = qt = QuadTree_new(dim, center, width, max_level); qt->total_weight = *dist_max = distance_to_group(k, dim, wgt, pts, center, usr_dist);/* store distance in total_weight */ - if (!(*argmax)) *argmax = MALLOC(sizeof(real)*dim); - memcpy(*argmax, center, sizeof(real)*dim); + if (!(*argmax)) *argmax = MALLOC(sizeof(double)*dim); + memcpy(*argmax, center, sizeof(double)*dim); candidates = MALLOC(sizeof(qt)*ncandidates_max); candidates2 = MALLOC(sizeof(qt)*ncandidates2_max); @@ -116,7 +116,7 @@ void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real w } distance = qt->total_weight;/* total_weight is used to store the distance from the center to the group */ - if (distance + wmax*sqrt(((real) dim))*qt->width < *dist_max) continue;/* this could happen if this candidate was entered into the list earlier than a better one later in the list */ + if (distance + wmax*sqrt(((double) dim))*qt->width < *dist_max) continue;/* this could happen if this candidate was entered into the list earlier than a better one later in the list */ qt->qts = MALLOC(sizeof(QuadTree)*(1<qts[ii] = QuadTree_new_in_quadrant(qt->dim, qt->center, (qt->width)/2, max_level, ii); @@ -129,8 +129,8 @@ void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real w for (j = 0; j < dim; j++) fprintf(stderr,"%f, ", qt->qts[ii]->center[j]); fprintf(stderr,"}\n"); } - memcpy(*argmax, qt->qts[ii]->center, sizeof(real)*dim); - } else if (distance + wmax*sqrt(((real) dim))*(qt->width)/2 < *dist_max){ + memcpy(*argmax, qt->qts[ii]->center, sizeof(double)*dim); + } else if (distance + wmax*sqrt(((double) dim))*(qt->width)/2 < *dist_max){ pruned = TRUE; } if (!pruned){ @@ -171,8 +171,8 @@ void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real w } -void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, int max_level, - real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax){ +void furtherest_point_in_list(int k, int dim, double *wgt, double *pts, QuadTree qt, int max_level, + double (*usr_dist)(int, double*, double*), double *dist_max, double **argmax){ /* Given a list of points in the Euclidean space contained in the quadtree qt (called the feasible points), find among them one that is closest to another list of point {dim, k, pts}. @@ -202,11 +202,11 @@ void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, QuadTree *candidates, *ctmp;/* a candidate array of quadtrees */ int ncandidates2 = 10, ncandidates2_max = 10; QuadTree *candidates2;/* a candidate array of quadtrees */ - real distance; + double distance; int level = 0; int i, ii, j, pruned; - real *average; - real wmax = 0.; + double *average; + double wmax = 0.; if (!usr_dist) usr_dist = dist; @@ -218,8 +218,8 @@ void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, average = qt->average; qt->total_weight = *dist_max = distance_to_group(k, dim, wgt, pts, average, usr_dist);/* store distance in total_weight */ - if (!(*argmax)) *argmax = MALLOC(sizeof(real)*dim); - memcpy(*argmax, average, sizeof(real)*dim); + if (!(*argmax)) *argmax = MALLOC(sizeof(double)*dim); + memcpy(*argmax, average, sizeof(double)*dim); candidates = MALLOC(sizeof(qt)*ncandidates_max); candidates2 = MALLOC(sizeof(qt)*ncandidates2_max); @@ -244,7 +244,7 @@ void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, } distance = qt->total_weight;/* total_weight is used to store the distance from average feasible points to the group */ - if (qt->n == 1 || distance + wmax*2*sqrt(((real) dim))*qt->width < *dist_max) continue;/* this could happen if this candidate was entered into the list earlier than a better one later in the list. Since the distance + if (qt->n == 1 || distance + wmax*2*sqrt(((double) dim))*qt->width < *dist_max) continue;/* this could happen if this candidate was entered into the list earlier than a better one later in the list. Since the distance is from the average of the feasible points in the square which may not be at the center */ if (!(qt->qts)) continue; @@ -260,8 +260,8 @@ void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, for (j = 0; j < dim; j++) fprintf(stderr,"%f, ", qt->qts[ii]->average[j]); fprintf(stderr,"}\n"); } - memcpy(*argmax, qt->qts[ii]->average, sizeof(real)*dim); - } else if (distance + wmax*sqrt(((real) dim))*(qt->width) < *dist_max){/* average feasible point in this square is too close to the point set */ + memcpy(*argmax, qt->qts[ii]->average, sizeof(double)*dim); + } else if (distance + wmax*sqrt(((double) dim))*(qt->width) < *dist_max){/* average feasible point in this square is too close to the point set */ pruned = TRUE; } if (!pruned){ diff --git a/lib/edgepaint/furtherest_point.h b/lib/edgepaint/furtherest_point.h index f20281d83..c39b154c8 100644 --- a/lib/edgepaint/furtherest_point.h +++ b/lib/edgepaint/furtherest_point.h @@ -10,6 +10,6 @@ #pragma once -void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real width, int max_level, real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax); -void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, int max_level, - real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax); +void furtherest_point(int k, int dim, double *wgt, double *pts, double *center, double width, int max_level, double (*usr_dist)(int, double*, double*), double *dist_max, double **argmax); +void furtherest_point_in_list(int k, int dim, double *wgt, double *pts, QuadTree qt, int max_level, + double (*usr_dist)(int, double*, double*), double *dist_max, double **argmax); diff --git a/lib/edgepaint/intersection.c b/lib/edgepaint/intersection.c index a039569d5..846d89e55 100644 --- a/lib/edgepaint/intersection.c +++ b/lib/edgepaint/intersection.c @@ -10,7 +10,7 @@ #include #include -static real cross(real *u, real *v){ +static double cross(double *u, double *v){ return u[0]*v[1] - u[1]*v[0]; } @@ -56,19 +56,19 @@ of line segments if 0 <= t <= 1 and 0 <= u <= 1. */ -static real dist(int dim, real *x, real *y){ +static double dist(int dim, double *x, double *y){ int k; - real d = 0; + double d = 0; for (k = 0; k < dim; k++) d += (x[k] - y[k])*(x[k]-y[k]); return sqrt(d); } -static real point_line_distance(real *p, real *q, real *r){ +static double point_line_distance(double *p, double *q, double *r){ /* distance between point p and line q--r */ enum {dim = 2}; - real t = 0, b = 0; + double t = 0, b = 0; int i; - real tmp; + double tmp; /* t = ((p - q).(r - q))/((r - q).(r - q)) gives the position of the project of p on line r--q */ for (i = 0; i < dim; i++){ @@ -96,9 +96,9 @@ static real point_line_distance(real *p, real *q, real *r){ } -static real line_segments_distance(real *p1, real *p2, real *q1, real *q2){ +static double line_segments_distance(double *p1, double *p2, double *q1, double *q2){ /* distance between line segments p1--p2 and q1--q2 */ - real t1, t2, t3, t4; + double t1, t2, t3, t4; t1 = point_line_distance(p1, q1, q2); t2 = point_line_distance(p2, q1, q2); t3 = point_line_distance(q1, p1, p2); @@ -109,7 +109,7 @@ static real line_segments_distance(real *p1, real *p2, real *q1, real *q2){ } -real intersection_angle(real *p1, real *p2, real *q1, real *q2){ +double intersection_angle(double *p1, double *p2, double *q1, double *q2){ /* give two lines p1--p2 and q1--q2, find their intersection agle and return Abs[Cos[theta]] of that angle. @@ -123,14 +123,14 @@ real intersection_angle(real *p1, real *p2, real *q1, real *q2){ . from -1 to 1. */ enum {dim = 2}; - real r[dim], s[dim], qp[dim]; - real rnorm = 0, snorm = 0, b, t, u; - // real epsilon = sqrt(MACHINEACC), close = 0.01; - //this may be better. Apply to ngk10_4 and look at double edge between 28 and 43. real epsilon = sin(10/180.), close = 0.1; - real epsilon = sin(1/180.), close = 0.01; + double r[dim], s[dim], qp[dim]; + double rnorm = 0, snorm = 0, b, t, u; + // double epsilon = sqrt(MACHINEACC), close = 0.01; + //this may be better. Apply to ngk10_4 and look at double edge between 28 and 43. double epsilon = sin(10/180.), close = 0.1; + double epsilon = sin(1/180.), close = 0.01; int line_dist_close; int i; - real res; + double res; for (i = 0; i < dim; i++) { r[i] = p2[i] - p1[i]; @@ -156,7 +156,7 @@ real intersection_angle(real *p1, real *p2, real *q1, real *q2){ u = cross(qp, r)/b; if ((t >= 0 && t <= 1 && u >= 0 && u <= 1) /* they intersect */ || line_dist_close){/* or lines are close */ - real rs = 0; + double rs = 0; if (rnorm*snorm < MACHINEACC) return 0; for (i = 0; i < dim; i++){ rs += r[i]*s[i]; diff --git a/lib/edgepaint/intersection.h b/lib/edgepaint/intersection.h index 6ce45a687..a6bda7950 100644 --- a/lib/edgepaint/intersection.h +++ b/lib/edgepaint/intersection.h @@ -10,4 +10,4 @@ #pragma once -real intersection_angle(real *p1, real *p2, real *q1, real *q2); +double intersection_angle(double *p1, double *p2, double *q1, double *q2); diff --git a/lib/edgepaint/lab.c b/lib/edgepaint/lab.c index a985f8966..673348538 100644 --- a/lib/edgepaint/lab.c +++ b/lib/edgepaint/lab.c @@ -68,7 +68,7 @@ color_lab RGB2LAB(color_rgb color){ return color_lab_init(L, A, B); } -void LAB2RGB_real_01(real *color){ +void LAB2RGB_real_01(double *color){ /* convert an array[3] of LAB colors to RGB between 0 to 1, in place */ color_rgb rgb; color_lab lab; diff --git a/lib/edgepaint/lab.h b/lib/edgepaint/lab.h index d3740f2bc..7df6c1031 100644 --- a/lib/edgepaint/lab.h +++ b/lib/edgepaint/lab.h @@ -28,7 +28,7 @@ typedef struct lab_struct color_lab; color_xyz RGB2XYZ(color_rgb color); color_rgb XYZ2RGB(color_xyz color); color_lab RGB2LAB(color_rgb color); -void LAB2RGB_real_01(real *color); /* convert an array[3] of LAB colors to RGB between 0 to 1, in place */ +void LAB2RGB_real_01(double *color); /* convert an array[3] of LAB colors to RGB between 0 to 1, in place */ color_rgb LAB2RGB(color_lab color); color_rgb color_rgb_init(double r, double g, double b); color_xyz color_xyz_init(double x, double y, double z); diff --git a/lib/edgepaint/node_distinct_coloring.c b/lib/edgepaint/node_distinct_coloring.c index 5f16b2427..741419970 100644 --- a/lib/edgepaint/node_distinct_coloring.c +++ b/lib/edgepaint/node_distinct_coloring.c @@ -16,31 +16,31 @@ #include #include -static real mydist(int dim, real *x, real *y){ +static double mydist(int dim, double *x, double *y){ int k; - real d = 0; + double d = 0; for (k = 0; k < dim; k++) d += (x[k] - y[k])*(x[k]-y[k]); return sqrt(d); } -static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weightedQ, SparseMatrix A, int cdim, real accuracy, int iter_max, int seed, real *colors, - real *color_diff0, real *color_diff_sum0){ +static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weightedQ, SparseMatrix A, int cdim, double accuracy, int iter_max, int seed, double *colors, + double *color_diff0, double *color_diff_sum0){ /* here we assume the graph is connected. And that the matrix is symmetric */ int i, j, *ia, *ja, n, k = 0; int max_level; - real center[3]; - real width; - real *a = NULL; - real *x; - real dist_max; - real color_diff = 0, color_diff_old; - real color_diff_sum = 0, color_diff_sum_old, *cc; + double center[3]; + double width; + double *a = NULL; + double *x; + double dist_max; + double color_diff = 0, color_diff_old; + double color_diff_sum = 0, color_diff_sum_old, *cc; int iter = 0; - real cspace_size = 0.7; - real red[3], black[3], min; + double cspace_size = 0.7; + double red[3], black[3], min; int flag = 0, imin; - real *wgt = NULL; + double *wgt = NULL; assert(accuracy > 0); max_level = MAX(1, -log(accuracy)/log(2.)); @@ -89,7 +89,7 @@ static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weight ia = A->ia; ja = A->ja; if (A->type == MATRIX_TYPE_REAL && A->a){ - a = (real*) A->a; + a = (double*) A->a; } /* cube [0, cspace_size]^3: only uised if not LAB */ @@ -100,8 +100,8 @@ static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weight srand(seed); for (i = 0; i < n*cdim; i++) colors[i] = cspace_size*drand(); - x = MALLOC(sizeof(real)*cdim*n); - if (weightedQ) wgt = MALLOC(sizeof(real)*n); + x = MALLOC(sizeof(double)*cdim*n); + if (weightedQ) wgt = MALLOC(sizeof(double)*n); color_diff = 0; color_diff_old = -1; color_diff_sum = 0; color_diff_sum_old = -1; @@ -113,7 +113,7 @@ static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weight k = 0; for (j = ia[i]; j < ia[i+1]; j++){ if (ja[j] == i) continue; - memcpy(&(x[k*cdim]), &(colors[ja[j]*cdim]), sizeof(real)*cdim); + memcpy(&(x[k*cdim]), &(colors[ja[j]*cdim]), sizeof(double)*cdim); if (wgt && a) wgt[k] = a[j]; k++; } @@ -154,14 +154,14 @@ static void node_distinct_coloring_internal2(int scheme, QuadTree qt, int weight free(x); } -static void node_distinct_coloring_internal(int scheme, QuadTree qt, int weightedQ, SparseMatrix A, int cdim, real accuracy, int iter_max, int seed, real *colors){ +static void node_distinct_coloring_internal(int scheme, QuadTree qt, int weightedQ, SparseMatrix A, int cdim, double accuracy, int iter_max, int seed, double *colors){ int i; - real color_diff; - real color_diff_sum; + double color_diff; + double color_diff_sum; if (seed < 0) { /* do multiple iterations and pick the best */ int iter, seed_max = -1; - real color_diff_max = -1; + double color_diff_max = -1; srand(123); iter = -seed; for (i = 0; i < iter; i++){ @@ -177,7 +177,7 @@ static void node_distinct_coloring_internal(int scheme, QuadTree qt, int weighte } -int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A0, real accuracy, int iter_max, int seed, int *cdim0, real **colors){ +int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A0, double accuracy, int iter_max, int seed, int *cdim0, double **colors){ /* for a graph A, get a distinctive color of its nodes so that the color distance among all neighboring nodes are maximized. Here color distance on a node is defined as the minimum of color differences between a node and its neighbors (or the minimum of weighted color differences if weightedQ = true, @@ -197,7 +197,7 @@ int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, S SparseMatrix B, A = A0; int ncomps, *comps = NULL, *comps_ptr = NULL; int nn, n; - real *ctmp; + double *ctmp; int i, j, jj, nnodes = 0; QuadTree qt = NULL; int cdim; @@ -245,9 +245,9 @@ int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, S } if (!(*colors)) { - *colors = MALLOC(sizeof(real)*cdim*n); + *colors = MALLOC(sizeof(double)*cdim*n); } - ctmp = MALLOC(sizeof(real)*cdim*n); + ctmp = MALLOC(sizeof(double)*cdim*n); B = SparseMatrix_symmetrize(A, FALSE); A = B; @@ -264,7 +264,7 @@ int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, S for (j = comps_ptr[i]; j < comps_ptr[i+1]; j++){ jj = j - comps_ptr[i]; - memcpy(&((*colors)[comps[j]*cdim]), &(ctmp[jj*cdim]), cdim*sizeof(real)); + memcpy(&((*colors)[comps[j]*cdim]), &(ctmp[jj*cdim]), cdim*sizeof(double)); } SparseMatrix_delete(B); } diff --git a/lib/edgepaint/node_distinct_coloring.h b/lib/edgepaint/node_distinct_coloring.h index e624889ca..b8550eb55 100644 --- a/lib/edgepaint/node_distinct_coloring.h +++ b/lib/edgepaint/node_distinct_coloring.h @@ -12,4 +12,4 @@ enum {COLOR_RGB, COLOR_GRAY, COLOR_LAB}; enum {ERROR_BAD_COLOR_SCHEME = -9}; -int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A, real accuracy, int iter_max, int seed, int *cdim, real **colors); +int node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A, double accuracy, int iter_max, int seed, int *cdim, double **colors); diff --git a/lib/mingle/agglomerative_bundling.c b/lib/mingle/agglomerative_bundling.c index 048ee0fc6..0449d8c83 100644 --- a/lib/mingle/agglomerative_bundling.c +++ b/lib/mingle/agglomerative_bundling.c @@ -46,12 +46,12 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_init(SparseMatrix A grid->R = NULL; grid->next = NULL; grid->prev = NULL; - grid->inks = MALLOC(sizeof(real)*(A->m)); + grid->inks = MALLOC(sizeof(double)*(A->m)); grid->edges = edges; grid->delete_top_level_A = 0; grid->total_ink = -1; if (level == 0){ - real total_ink = 0; + double total_ink = 0; for (i = 0; i < n; i++) { (grid->inks)[i] = ink1(edges[i]); total_ink += (grid->inks)[i]; @@ -80,7 +80,7 @@ static void Agglomerative_Ink_Bundling_delete(Agglomerative_Ink_Bundling grid){ free(grid); } -static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomerative_Ink_Bundling grid, int *pick, real angle_param, real angle){ +static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomerative_Ink_Bundling grid, int *pick, double angle_param, double angle){ /* pick is a work array of dimension n, with n the total number of original edges */ int *matching; SparseMatrix A = grid->A; @@ -89,17 +89,17 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera int i, j, k, jj, jc, jmax, ni, nj, npicks; int *mask; pedge *edges = grid->edges; - real *inks = grid->inks, *cinks, inki, inkj; - real gain, maxgain, minink, total_gain = 0; + double *inks = grid->inks, *cinks, inki, inkj; + double gain, maxgain, minink, total_gain = 0; int *ip = NULL, *jp = NULL, ie; Vector *cedges;/* a table listing the content of bundled edges in the coarsen grid. cedges[i] contain the list of origonal edges that make up the bundle i in the next level */ - real ink0, ink1, grand_total_ink = 0, grand_total_gain = 0; + double ink0, ink1, grand_total_ink = 0, grand_total_gain = 0; point_t meet1, meet2; if (Verbose > 1) fprintf(stderr,"level ===================== %d, n = %d\n",grid->level, n); cedges = MALLOC(sizeof(Vector)*n); - cinks = MALLOC(sizeof(real)*n); + cinks = MALLOC(sizeof(double)*n); for (i = 0; i < n; i++) cedges[i] = Vector_new(1, sizeof(int), NULL); if (grid->level > 0){ @@ -108,7 +108,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera } matching = MALLOC(sizeof(int)*n); - mask = MALLOC(sizeof(real)*n); + mask = MALLOC(sizeof(double)*n); for (i = 0; i < n; i++) mask[i] = -1; assert(n == A->n); @@ -239,7 +239,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera if (nc >= 1 && total_gain > 0){ /* now set up restriction and prolongation operator */ SparseMatrix P, R, R1, R0, B, cA; - real one = 1.; + double one = 1.; Agglomerative_Ink_Bundling cgrid; R1 = SparseMatrix_new(nc, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); @@ -295,7 +295,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera return grid; } -static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_new(SparseMatrix A0, pedge *edges, real angle_param, real angle){ +static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_new(SparseMatrix A0, pedge *edges, double angle_param, double angle){ /* give a link of edges and their nearest neighbor graph, return a multilevel of edge bundling based on ink saving */ Agglomerative_Ink_Bundling grid; int *pick; @@ -316,17 +316,17 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_new(SparseMatrix A0 return grid; } -static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge* edges, int nneighbors, int *recurse_level, int MAX_RECURSE_LEVEL, real angle_param, real angle, int open_gl, real *current_ink, real *ink00, int *flag){ +static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge* edges, int nneighbors, int *recurse_level, int MAX_RECURSE_LEVEL, double angle_param, double angle, int open_gl, double *current_ink, double *ink00, int *flag){ int i, j, jj, k; int *ia, *ja; int *pick; Agglomerative_Ink_Bundling grid, cgrid; SparseMatrix R; - real ink0, ink1; + double ink0, ink1; point_t meet1, meet2; pedge e; - real TOL = 0.0001, wgt_all; + double TOL = 0.0001, wgt_all; clock_t start; (*recurse_level)++; @@ -339,7 +339,7 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge start = clock(); grid = Agglomerative_Ink_Bundling_new(A, edges, angle_param, angle); if (Verbose > 1) - fprintf(stderr, "CPU for agglomerative bundling %f\n", ((real) (clock() - start))/CLOCKS_PER_SEC); + fprintf(stderr, "CPU for agglomerative bundling %f\n", ((double) (clock() - start))/CLOCKS_PER_SEC); ink0 = grid->total_ink; /* find coarsest */ @@ -384,7 +384,7 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge improved later */ e = edges[jj] = pedge_double(edges[jj]); - e->wgts = REALLOC(e->wgts, sizeof(real)*4); + e->wgts = REALLOC(e->wgts, sizeof(double)*4); e->x[1*dim] = meet1.x; e->x[1*dim+1] = meet1.y; e->x[2*dim] = meet2.x; @@ -406,10 +406,10 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge } } else { pedge *mid_edges, midedge;/* middle section of edges that will be bundled again */ - real *xx; + double *xx; int ne, npp, l; SparseMatrix A_mid; - real eps = 0., wgt, total_wgt = 0; + double eps = 0., wgt, total_wgt = 0; /* make new edges using meet1 and meet2. @@ -424,7 +424,7 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge ja = R->ja; ne = R->m; mid_edges = MALLOC(sizeof(pedge)*ne); - xx = MALLOC(sizeof(real)*4*ne); + xx = MALLOC(sizeof(double)*4*ne); for (i = 0; i < R->m; i++){ pick = &(ja[ia[i]]); wgt = 0.; @@ -507,9 +507,9 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge } -pedge* agglomerative_ink_bundling(int dim, SparseMatrix A, pedge* edges, int nneighbor, int MAX_RECURSE_LEVEL, real angle_param, real angle, int open_gl, int *flag){ +pedge* agglomerative_ink_bundling(int dim, SparseMatrix A, pedge* edges, int nneighbor, int MAX_RECURSE_LEVEL, double angle_param, double angle, int open_gl, int *flag){ int recurse_level = 0; - real current_ink = -1, ink0; + double current_ink = -1, ink0; pedge *edges2; ink_count = 0; @@ -517,6 +517,6 @@ pedge* agglomerative_ink_bundling(int dim, SparseMatrix A, pedge* edges, int nne if (Verbose > 1) - fprintf(stderr,"initial total ink = %f, final total ink = %f, inksaving = %f percent, total ink_calc = %f, avg ink_calc per edge = %f\n", ink0, current_ink, (ink0-current_ink)/ink0, ink_count, ink_count/(real) A->m); + fprintf(stderr,"initial total ink = %f, final total ink = %f, inksaving = %f percent, total ink_calc = %f, avg ink_calc per edge = %f\n", ink0, current_ink, (ink0-current_ink)/ink0, ink_count, ink_count/(double) A->m); return edges2; } diff --git a/lib/mingle/agglomerative_bundling.h b/lib/mingle/agglomerative_bundling.h index 2553ab18e..d3c6222a8 100644 --- a/lib/mingle/agglomerative_bundling.h +++ b/lib/mingle/agglomerative_bundling.h @@ -22,10 +22,10 @@ struct Agglomerative_Ink_Bundling_struct { SparseMatrix R;/* striction mtrix from level to level + 1*/ Agglomerative_Ink_Bundling next; Agglomerative_Ink_Bundling prev; - real *inks; /* amount of ink needed to draw this edge/bundle. Dimension n. */ - real total_ink; /* amount of ink needed to draw this edge/bundle. Dimension n. */ + double *inks; /* amount of ink needed to draw this edge/bundle. Dimension n. */ + double total_ink; /* amount of ink needed to draw this edge/bundle. Dimension n. */ pedge* edges; /* the original edge info. This does not vary level to level and is of dimenion n0, where n0 is the number of original edges */ int delete_top_level_A;/*whether the top level matrix should be deleted on garbage collecting the grid */ }; -pedge* agglomerative_ink_bundling(int dim, SparseMatrix A, pedge* edges, int nneighbor, int max_recursion, real angle_param, real angle, int open_gl, int *flag); +pedge* agglomerative_ink_bundling(int dim, SparseMatrix A, pedge* edges, int nneighbor, int max_recursion, double angle_param, double angle, int open_gl, int *flag); diff --git a/lib/mingle/edge_bundling.c b/lib/mingle/edge_bundling.c index 60d26c6f2..85120c92c 100644 --- a/lib/mingle/edge_bundling.c +++ b/lib/mingle/edge_bundling.c @@ -30,40 +30,40 @@ extern pedge *edges_global; extern int *clusters_global; #endif -static real norm(int n, real *x){ - real res = 0; +static double norm(int n, double *x){ + double res = 0; int i; for (i = 0; i < n; i++) res += x[i]*x[i]; return sqrt(res); } -static real sqr_dist(int dim, real *x, real *y){ +static double sqr_dist(int dim, double *x, double *y){ int i; - real res = 0; + double res = 0; for (i = 0; i < dim; i++) res += (x[i] - y[i])*(x[i] - y[i]); return res; } -static real dist(int dim, real *x, real *y){ +static double dist(int dim, double *x, double *y){ return sqrt(sqr_dist(dim,x,y)); } -pedge pedge_new(int np, int dim, real *x){ +pedge pedge_new(int np, int dim, double *x){ pedge e; e = MALLOC(sizeof(struct pedge_struct)); e->npoints = np; e->dim = dim; e->len = np; - e->x = MALLOC(dim*e->len*sizeof(real)); - memcpy(e->x, x, dim*e->len*sizeof(real)); + e->x = MALLOC(dim*e->len*sizeof(double)); + memcpy(e->x, x, dim*e->len*sizeof(double)); e->edge_length = dist(dim, &x[0*dim], &x[(np-1)*dim]); e->wgt = 1.; e->wgts = NULL; return e; } -pedge pedge_wgt_new(int np, int dim, real *x, real wgt){ +pedge pedge_wgt_new(int np, int dim, double *x, double wgt){ pedge e; int i; @@ -71,11 +71,11 @@ pedge pedge_wgt_new(int np, int dim, real *x, real wgt){ e->npoints = np; e->dim = dim; e->len = np; - e->x = MALLOC(dim*e->len*sizeof(real)); - memcpy(e->x, x, dim*e->len*sizeof(real)); + e->x = MALLOC(dim*e->len*sizeof(double)); + memcpy(e->x, x, dim*e->len*sizeof(double)); e->edge_length = dist(dim, &x[0*dim], &x[(np-1)*dim]); e->wgt = wgt; - e->wgts = MALLOC(sizeof(real)*(np - 1)); + e->wgts = MALLOC(sizeof(double)*(np - 1)); for (i = 0; i < np - 1; i++) e->wgts[i] = wgt; return e; @@ -87,26 +87,26 @@ void pedge_delete(pedge e){ pedge pedge_flip(pedge e){ /* flip the polyline so that last point becomes the first, second last the second, etc*/ - real *y; - real *x = e->x; + double *y; + double *x = e->x; int i, dim = e->dim; int n = e->npoints; - y = MALLOC(sizeof(real)*e->dim); + y = MALLOC(sizeof(double)*e->dim); for (i = 0; i < e->npoints/2; i++){ - memcpy(y, &x[i*dim], sizeof(real)*dim); - memcpy(&x[(n-1-i)*dim], &x[i*dim], sizeof(real)*dim); - memcpy(&x[i*dim], y, sizeof(real)*dim); + memcpy(y, &x[i*dim], sizeof(double)*dim); + memcpy(&x[(n-1-i)*dim], &x[i*dim], sizeof(double)*dim); + memcpy(&x[i*dim], y, sizeof(double)*dim); } free(y); return e; } -static real edge_compatibility(pedge e1, pedge e2){ +static double edge_compatibility(pedge e1, pedge e2){ /* two edges are u1->v1, u2->v2. return 1 if two edges are exactly the same, 0 if they are very different. */ - real *u1, *v1, *u2, *v2, *u, dist1, dist2, len1, len2; + double *u1, *v1, *u2, *v2, *u, dist1, dist2, len1, len2; int dim = e1->dim, flipped = FALSE; u1 = e1->x; @@ -132,13 +132,13 @@ static real edge_compatibility(pedge e1, pedge e2){ } } -static real edge_compatibility_full(pedge e1, pedge e2){ +static double edge_compatibility_full(pedge e1, pedge e2){ /* two edges are u1->v1, u2->v2. return 1 if two edges are exactly the same, 0 if they are very different. This is based on Holten and van Wijk's paper */ - real *u1, *v1, *u2, *v2, *u, dist1, dist2, len1, len2, len; - real tmp, ca, cp, cs; + double *u1, *v1, *u2, *v2, *u, dist1, dist2, len1, len2, len; + double tmp, ca, cp, cs; int dim = e1->dim, flipped = FALSE, i; u1 = e1->x; @@ -216,13 +216,13 @@ static void fprint_rgb(FILE* fp, int r, int g, int b, int alpha){ void pedge_export_gv(FILE *fp, int ne, pedge *edges){ pedge edge; - real *x, t; + double *x, t; int i, j, k, kk, dim, sta, sto; - real maxwgt = 0, len, len_total, len_total0; + double maxwgt = 0, len, len_total, len_total0; int r, g, b; - real tt1[3]={0.15,0.5,0.85}; - real tt2[4]={0.15,0.4,0.6,0.85}; - real *tt; + double tt1[3]={0.15,0.5,0.85}; + double tt2[4]={0.15,0.4,0.6,0.85}; + double *tt; fprintf(fp,"strict graph{\n"); /* points */ @@ -337,7 +337,7 @@ void pedge_export_gv(FILE *fp, int ne, pedge *edges){ void pedge_export_mma(FILE *fp, int ne, pedge *edges){ pedge edge; - real *x; + double *x; int i, j, k, dim; fprintf(fp,"Graphics[{"); @@ -409,8 +409,8 @@ static void pedge_print(char *comments, pedge e){ pedge pedge_realloc(pedge e, int n){ if (n <= e->npoints) return e; - e->x = REALLOC(e->x, e->dim*n*sizeof(real)); - if (e->wgts) e->wgts = REALLOC(e->wgts, (n-1)*sizeof(real)); + e->x = REALLOC(e->x, e->dim*n*sizeof(double)); + if (e->wgts) e->wgts = REALLOC(e->wgts, (n-1)*sizeof(double)); e->len = n; return e; } @@ -418,12 +418,12 @@ pedge pedge_wgts_realloc(pedge e, int n){ /* diff from pedge_alloc: allocate wgts if do not exist and initialize to wgt */ int i; if (n <= e->npoints) return e; - e->x = REALLOC(e->x, e->dim*n*sizeof(real)); + e->x = REALLOC(e->x, e->dim*n*sizeof(double)); if (!(e->wgts)){ - e->wgts = REALLOC(e->wgts, (n-1)*sizeof(real)); + e->wgts = REALLOC(e->wgts, (n-1)*sizeof(double)); for (i = 0; i < e->npoints; i++) e->wgts[i] = e->wgt; } else { - e->wgts = REALLOC(e->wgts, (n-1)*sizeof(real)); + e->wgts = REALLOC(e->wgts, (n-1)*sizeof(double)); } e->len = n; return e; @@ -433,13 +433,13 @@ pedge pedge_wgts_realloc(pedge e, int n){ pedge pedge_double(pedge e){ /* double the number of points (more precisely, add a point between two points in the polyline */ int npoints = e->npoints, len = e->len, i, dim = e->dim; - real *x; + double *x; int j, ii, ii2, np; assert(npoints >= 2); if (npoints*2-1 > len){ len = 3*npoints; - e->x = REALLOC(e->x, dim*len*sizeof(real)); + e->x = REALLOC(e->x, dim*len*sizeof(double)); } x = e->x; @@ -464,12 +464,12 @@ pedge pedge_double(pedge e){ return e; } -static void edge_tension_force(real *force, pedge e){ - real *x = e->x; +static void edge_tension_force(double *force, pedge e){ + double *x = e->x; int dim = e->dim; int np = e->npoints; int i, left, right, j; - real s; + double s; /* tention force = ((np-1)*||2x-xleft-xright||)/||e||, so the force is norminal and unitless */ @@ -482,14 +482,14 @@ static void edge_tension_force(real *force, pedge e){ } } -static void edge_attraction_force(real similarity, pedge e1, pedge e2, real *force){ +static void edge_attraction_force(double similarity, pedge e1, pedge e2, double *force){ /* attrractive force from x2 applied to x1 */ - real *x1 = e1->x, *x2 = e2->x; + double *x1 = e1->x, *x2 = e2->x; int dim = e1->dim; int np = e1->npoints; int i, j; - real dist, s, ss; - real edge_length = e1->edge_length; + double dist, s, ss; + double edge_length = e1->edge_length; assert(e1->npoints == e2->npoints); @@ -519,22 +519,22 @@ static void edge_attraction_force(real similarity, pedge e1, pedge e2, real *fo } -static pedge* force_directed_edge_bundling(SparseMatrix A, pedge* edges, int maxit, real step0, real K, int open_gl){ +static pedge* force_directed_edge_bundling(SparseMatrix A, pedge* edges, int maxit, double step0, double K, int open_gl){ int i, j, ne = A->n, k; int *ia = A->ia, *ja = A->ja, iter = 0; - real *a = (real*) A->a; + double *a = (double*) A->a; pedge e1, e2; - real *force_t, *force_a; + double *force_t, *force_a; int np = edges[0]->npoints, dim = edges[0]->dim; - real *x; - real step = step0; - real fnorm_a, fnorm_t, edge_length, start; + double *x; + double step = step0; + double fnorm_a, fnorm_t, edge_length, start; if (Verbose > 1) - fprintf(stderr, "total interaction pairs = %d out of %d, avg neighbors per edge = %f\n",A->nz, A->m*A->m, A->nz/(real) A->m); + fprintf(stderr, "total interaction pairs = %d out of %d, avg neighbors per edge = %f\n",A->nz, A->m*A->m, A->nz/(double) A->m); - force_t = MALLOC(sizeof(real)*dim*np); - force_a = MALLOC(sizeof(real)*dim*np); + force_t = MALLOC(sizeof(double)*dim*np); + force_a = MALLOC(sizeof(double)*dim*np); while (step > 0.001 && iter < maxit){ start = clock(); iter++; @@ -563,7 +563,7 @@ static pedge* force_directed_edge_bundling(SparseMatrix A, pedge* edges, int max } step = step*0.9; if (Verbose > 1) - fprintf(stderr, "iter ==== %d cpu = %f npoints = %d\n",iter, ((real) (clock() - start))/CLOCKS_PER_SEC, np - 2); + fprintf(stderr, "iter ==== %d cpu = %f npoints = %d\n",iter, ((double) (clock() - start))/CLOCKS_PER_SEC, np - 2); #ifdef OPENGL if (open_gl){ @@ -579,13 +579,13 @@ static pedge* force_directed_edge_bundling(SparseMatrix A, pedge* edges, int max return edges; } -static pedge* modularity_ink_bundling(int dim, int ne, SparseMatrix B, pedge* edges, real angle_param, real angle){ +static pedge* modularity_ink_bundling(int dim, int ne, SparseMatrix B, pedge* edges, double angle_param, double angle){ int *assignment = NULL, flag, nclusters; - real modularity; + double modularity; int *clusterp, *clusters; SparseMatrix D, C; point_t meet1, meet2; - real ink0, ink1; + double ink0, ink1; pedge e; int i, j, jj; int use_value_for_clustering = TRUE; @@ -643,12 +643,12 @@ static pedge* modularity_ink_bundling(int dim, int ne, SparseMatrix B, pedge* ed return edges; } -static SparseMatrix check_compatibility(SparseMatrix A, int ne, pedge *edges, int compatibility_method, real tol){ +static SparseMatrix check_compatibility(SparseMatrix A, int ne, pedge *edges, int compatibility_method, double tol){ /* go through the links and make sure edges are compatible */ SparseMatrix B, C; int *ia, *ja, i, j, jj; - real start; - real dist; + double start; + double dist; B = SparseMatrix_new(1, 1, 1, MATRIX_TYPE_REAL, FORMAT_COORD); ia = A->ia; ja = A->ja; @@ -673,12 +673,12 @@ static SparseMatrix check_compatibility(SparseMatrix A, int ne, pedge *edges, in SparseMatrix_delete(B); B = C; if (Verbose > 1) - fprintf(stderr, "edge compatibilitu time = %f\n",((real) (clock() - start))/CLOCKS_PER_SEC); + fprintf(stderr, "edge compatibilitu time = %f\n",((double) (clock() - start))/CLOCKS_PER_SEC); return B; } -pedge* edge_bundling(SparseMatrix A0, int dim, real *x, int maxit_outer, real K, int method, int nneighbor, int compatibility_method, - int max_recursion, real angle_param, real angle, int open_gl){ +pedge* edge_bundling(SparseMatrix A0, int dim, double *x, int maxit_outer, double K, int method, int nneighbor, int compatibility_method, + int max_recursion, double angle_param, double angle, int open_gl){ /* bundle edges. A: edge graph x: edge i is at {p,q}, @@ -697,9 +697,9 @@ pedge* edge_bundling(SparseMatrix A0, int dim, real *x, int maxit_outer, real K, pedge *edges; SparseMatrix A = A0, B = NULL; int i; - real tol = 0.001; + double tol = 0.001; int k; - real step0 = 0.1, start = 0.0; + double step0 = 0.1, start = 0.0; int maxit = 10; int flag; @@ -751,7 +751,7 @@ pedge* edge_bundling(SparseMatrix A0, int dim, real *x, int maxit_outer, real K, assert(0); } if (Verbose) - fprintf(stderr, "total edge bundling cpu = %f\n",((real) (clock() - start))/CLOCKS_PER_SEC); + fprintf(stderr, "total edge bundling cpu = %f\n",((double) (clock() - start))/CLOCKS_PER_SEC); if (B != A) SparseMatrix_delete(B); if (A != A0) SparseMatrix_delete(A); diff --git a/lib/mingle/edge_bundling.h b/lib/mingle/edge_bundling.h index 34da8876e..002312a15 100644 --- a/lib/mingle/edge_bundling.h +++ b/lib/mingle/edge_bundling.h @@ -13,18 +13,18 @@ #include struct pedge_struct { - real wgt; /* weight, telling how many original edges this edge represent. If this edge consists of multiple sections of different weights then this is a lower bound. This only applied for agglomerative bundling */ + double wgt; /* weight, telling how many original edges this edge represent. If this edge consists of multiple sections of different weights then this is a lower bound. This only applied for agglomerative bundling */ int npoints;/* number of poly points */ int len;/* length of arra x. len >= npoints */ int dim;/* dim >= 2. Point i is stored from x[i*dim]*/ - real edge_length; - real *x;/* coordinates of the npoints poly points. Dimension dim*npoints */ - real *wgts;/* number of original edges each section represnet. Dimension npoint - 1. This only applied for agglomerative bundling Null for other methods */ + double edge_length; + double *x;/* coordinates of the npoints poly points. Dimension dim*npoints */ + double *wgts;/* number of original edges each section represnet. Dimension npoint - 1. This only applied for agglomerative bundling Null for other methods */ }; typedef struct pedge_struct* pedge; -pedge* edge_bundling(SparseMatrix A, int dim, real *x, int maxit_outer, real K, int method, int nneighbor, int compatibility_method, int max_recursion, real angle_param, real angle, int open_gl); +pedge* edge_bundling(SparseMatrix A, int dim, double *x, int maxit_outer, double K, int method, int nneighbor, int compatibility_method, int max_recursion, double angle_param, double angle, int open_gl); void pedge_delete(pedge e); pedge pedge_realloc(pedge e, int np); pedge pedge_wgts_realloc(pedge e, int n); @@ -32,8 +32,8 @@ void pedge_export_mma(FILE *fp, int ne, pedge *edges); void pedge_export_gv(FILE *fp, int ne, pedge *edges); enum {METHOD_NONE = -1, METHOD_FD, METHOD_INK_AGGLOMERATE, METHOD_INK}; enum {COMPATIBILITY_DIST = 0, COMPATIBILITY_FULL}; -pedge pedge_new(int np, int dim, real *x); -pedge pedge_wgt_new(int np, int dim, real *x, real wgt); +pedge pedge_new(int np, int dim, double *x); +pedge pedge_wgt_new(int np, int dim, double *x, double wgt); pedge pedge_double(pedge e); /* flip the polyline so that last point becomes the first, second last the second, etc*/ diff --git a/lib/mingle/ink.c b/lib/mingle/ink.c index 00e19fdd5..be43ba3e1 100644 --- a/lib/mingle/ink.c +++ b/lib/mingle/ink.c @@ -48,7 +48,7 @@ static const point_t Origin; /* sumLengths: */ -static double sumLengths_avoid_bad_angle(point_t* points, int npoints, point_t end, point_t meeting, real angle_param) +static double sumLengths_avoid_bad_angle(point_t* points, int npoints, point_t end, point_t meeting, double angle_param) { /* avoid sharp turns, we want cos_theta to be as close to -1 as possible */ int i; @@ -94,7 +94,7 @@ static double sumLengths(point_t* points, int npoints, point_t end, point_t meet /* bestInk: */ -static double bestInk(point_t* points, int npoints, point_t begin, point_t end, double prec, point_t *meet, real angle_param) +static double bestInk(point_t* points, int npoints, point_t begin, point_t end, double prec, point_t *meet, double angle_param) { point_t first, second, third, fourth, diff, meeting; double value1, value2, value3, value4; @@ -172,7 +172,7 @@ static double bestInk(point_t* points, int npoints, point_t begin, point_t end, } -static double project_to_line(point_t pt, point_t left, point_t right, real angle){ +static double project_to_line(point_t pt, point_t left, point_t right, double angle){ /* pt ^ ^ . \ \ @@ -199,8 +199,8 @@ static double project_to_line(point_t pt, point_t left, point_t right, real angl point_t b, a; - real bnorm, dnorm; - real alpha, ccord; + double bnorm, dnorm; + double alpha, ccord; if (angle <=0 || angle >= M_PI) return 2;/* return outside of the interval which should be handled as a sign of infeasible turning angle */ alpha = angle; @@ -222,12 +222,12 @@ static double project_to_line(point_t pt, point_t left, point_t right, real angl * Compute minimal ink used the input edges are bundled. * Assumes tails all occur on one side and heads on the other. */ -double ink(pedge* edges, int numEdges, int *pick, double *ink0, point_t *meet1, point_t *meet2, real angle_param, real angle) +double ink(pedge* edges, int numEdges, int *pick, double *ink0, point_t *meet1, point_t *meet2, double angle_param, double angle) { int i; point_t begin, end, mid, diff; pedge e; - real *x; + double *x; point_t* sources = N_NEW(numEdges, point_t); point_t* targets = N_NEW(numEdges, point_t); double inkUsed; @@ -322,9 +322,9 @@ double ink(pedge* edges, int numEdges, int *pick, double *ink0, point_t *meet1, } double ink1(pedge e){ - real *x, xx, yy; + double *x, xx, yy; - real ink0 = 0; + double ink0 = 0; x = e->x; xx = x[0] - x[e->dim*e->npoints - e->dim]; diff --git a/lib/mingle/ink.h b/lib/mingle/ink.h index 062cc2d23..2f8c2ba85 100644 --- a/lib/mingle/ink.h +++ b/lib/mingle/ink.h @@ -28,7 +28,7 @@ typedef struct { meet1, meet2: meeting point return: best ink needed if bundled. */ -double ink(pedge* edges, int numEdges, int *pick, double *ink0, point_t *meet1, point_t *meet2, real angle_param, real angle); +double ink(pedge* edges, int numEdges, int *pick, double *ink0, point_t *meet1, point_t *meet2, double angle_param, double angle); double ink1(pedge e); extern double ink_count; diff --git a/lib/mingle/nearest_neighbor_graph.c b/lib/mingle/nearest_neighbor_graph.c index 5f0c277fb..1de680376 100644 --- a/lib/mingle/nearest_neighbor_graph.c +++ b/lib/mingle/nearest_neighbor_graph.c @@ -27,7 +27,7 @@ SparseMatrix nearest_neighbor_graph(int nPts, int num_neigbors, double *x, doubl */ int *irn = NULL, *jcn = NULL, nz; - real *val = NULL; + double *val = NULL; SparseMatrix A; int k = num_neigbors; @@ -39,7 +39,7 @@ SparseMatrix nearest_neighbor_graph(int nPts, int num_neigbors, double *x, doubl #ifdef HAVE_ANN nearest_neighbor_graph_ann(nPts, num_neigbors, eps, x, &nz, &irn, &jcn, &val); - A = SparseMatrix_from_coordinate_arrays(nz, nPts, nPts, irn, jcn, val, MATRIX_TYPE_REAL, sizeof(real)); + A = SparseMatrix_from_coordinate_arrays(nz, nPts, nPts, irn, jcn, val, MATRIX_TYPE_REAL, sizeof(double)); #else A = NULL; #endif diff --git a/lib/neatogen/adjust.c b/lib/neatogen/adjust.c index 364c26921..29d09c6bc 100644 --- a/lib/neatogen/adjust.c +++ b/lib/neatogen/adjust.c @@ -627,7 +627,7 @@ static void updateGraph(void) double *getSizes(Agraph_t * g, pointf pad, int* n_elabels, int** elabels) { Agnode_t *n; - real *sizes = N_GNEW(Ndim * agnnodes(g), real); + double *sizes = N_GNEW(Ndim * agnnodes(g), double); int i, nedge_nodes = 0; int* elabs; @@ -668,11 +668,11 @@ SparseMatrix makeMatrix(Agraph_t* g, SparseMatrix *D) int i, row; int *I; int *J; - real *val; - real v; + double *val; + double v; int type = MATRIX_TYPE_REAL; Agsym_t* symD = NULL; - real* valD = NULL; + double* valD = NULL; if (!g) return NULL; @@ -686,12 +686,12 @@ SparseMatrix makeMatrix(Agraph_t* g, SparseMatrix *D) I = N_GNEW(nedges, int); J = N_GNEW(nedges, int); - val = N_GNEW(nedges, real); + val = N_GNEW(nedges, double); sym = agfindedgeattr(g, "weight"); if (D) { symD = agfindedgeattr(g, "len"); - valD = N_NEW(nedges, real); + valD = N_NEW(nedges, double); } i = 0; @@ -713,9 +713,9 @@ SparseMatrix makeMatrix(Agraph_t* g, SparseMatrix *D) } A = SparseMatrix_from_coordinate_arrays(nedges, nnodes, nnodes, I, J, - val, type, sizeof(real)); + val, type, sizeof(double)); - if (D) *D = SparseMatrix_from_coordinate_arrays(nedges, nnodes, nnodes, I, J, valD, type, sizeof(real)); + if (D) *D = SparseMatrix_from_coordinate_arrays(nedges, nnodes, nnodes, I, J, valD, type, sizeof(double)); free(I); free(J); @@ -731,8 +731,8 @@ fdpAdjust (graph_t* g, adjust_data* am) { SparseMatrix A0 = makeMatrix(g, NULL); SparseMatrix A = A0; - real *sizes; - real *pos = N_NEW(Ndim * agnnodes(g), real); + double *sizes; + double *pos = N_NEW(Ndim * agnnodes(g), double); Agnode_t *n; int flag = 0, i; expand_t sep = sepFactor(g); @@ -748,7 +748,7 @@ fdpAdjust (graph_t* g, adjust_data* am) sizes = getSizes(g, pad, NULL, NULL); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { - real* npos = pos + Ndim * ND_id(n); + double* npos = pos + Ndim * ND_id(n); for (i = 0; i < Ndim; i++) { npos[i] = ND_pos(n)[i]; } @@ -764,7 +764,7 @@ fdpAdjust (graph_t* g, adjust_data* am) ELSCHEME_NONE, 0, NULL, NULL, mapBool (agget(g, "overlap_shrink"), TRUE)); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { - real *npos = pos + Ndim * ND_id(n); + double *npos = pos + Ndim * ND_id(n); for (i = 0; i < Ndim; i++) { ND_pos(n)[i] = npos[i]; } diff --git a/lib/neatogen/call_tri.c b/lib/neatogen/call_tri.c index 6e93407b5..67e8bcbf0 100644 --- a/lib/neatogen/call_tri.c +++ b/lib/neatogen/call_tri.c @@ -16,15 +16,15 @@ #include #include -SparseMatrix call_tri(int n, int dim, real * x) +SparseMatrix call_tri(int n, int dim, double * x) { - real one = 1; + double one = 1; int i, ii, jj; SparseMatrix A; SparseMatrix B; int* edgelist = NULL; - real* xv = N_GNEW(n, real); - real* yv = N_GNEW(n, real); + double* xv = N_GNEW(n, double); + double* yv = N_GNEW(n, double); int numberofedges = 0; for (i = 0; i < n; i++) { @@ -62,16 +62,16 @@ 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, double * xx) { - real *x, *y; + double *x, *y; v_data *delaunay; int i, j; SparseMatrix A; SparseMatrix B; - real one = 1; - x = N_GNEW(n, real); - y = N_GNEW(n, real); + double one = 1; + x = N_GNEW(n, double); + y = N_GNEW(n, double); for (i = 0; i < n; i++) { x[i] = xx[dim * i]; diff --git a/lib/neatogen/call_tri.h b/lib/neatogen/call_tri.h index a87af2f14..c6aaaeff5 100644 --- a/lib/neatogen/call_tri.h +++ b/lib/neatogen/call_tri.h @@ -10,5 +10,5 @@ #pragma once -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, double * x); +SparseMatrix call_tri2(int n, int dim, double * x); diff --git a/lib/neatogen/overlap.c b/lib/neatogen/overlap.c index f5573518a..c3d8ebee1 100644 --- a/lib/neatogen/overlap.c +++ b/lib/neatogen/overlap.c @@ -22,7 +22,7 @@ #include #include -static void ideal_distance_avoid_overlap(int dim, SparseMatrix A, real *x, real *width, real *ideal_distance, real *tmax, real *tmin){ +static void ideal_distance_avoid_overlap(int dim, SparseMatrix A, double *x, double *width, double *ideal_distance, double *tmax, double *tmin){ /* if (x1>x2 && y1 > y2) we want either x1 + t (x1-x2) - x2 > (width1+width2), or y1 + t (y1-y2) - y2 > (height1+height2), hence t = MAX(expandmin, MIN(expandmax, (width1+width2)/(x1-x2) - 1, (height1+height2)/(y1-y2) - 1)), and new ideal distance = (1+t) old_distance. t can be negative sometimes. @@ -30,8 +30,8 @@ static void ideal_distance_avoid_overlap(int dim, SparseMatrix A, real *x, real */ int i, j, jj; int *ia = A->ia, *ja = A->ja; - real dist, dx, dy, wx, wy, t; - real expandmax = 1.5, expandmin = 1; + double dist, dx, dy, wx, wy, t; + double expandmax = 1.5, expandmin = 1; *tmax = 0; *tmin = 1.e10; @@ -77,7 +77,7 @@ enum {INTV_OPEN, INTV_CLOSE}; struct scan_point_struct{ int node; - real x; + double x; int status; }; @@ -122,14 +122,14 @@ static void InfoPrint(void* a) { static void InfoDest(void *a){ } -static SparseMatrix get_overlap_graph(int dim, int n, real *x, real *width, int check_overlap_only){ +static SparseMatrix get_overlap_graph(int dim, int n, double *x, double *width, int check_overlap_only){ /* if check_overlap_only = TRUE, we only check whether there is one overlap */ scan_point *scanpointsx, *scanpointsy; int i, k, neighbor; SparseMatrix A = NULL, B = NULL; rb_red_blk_node *newNode, *newNode0, *newNode2 = NULL; rb_red_blk_tree* treey; - real one = 1; + double one = 1; A = SparseMatrix_new(n, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); @@ -180,7 +180,7 @@ static SparseMatrix get_overlap_graph(int dim, int n, real *x, real *width, int RBTreeInsert(treey, &(scanpointsy[k+n]), NULL); } else { - real bsta, bbsta, bsto, bbsto; int ii; + double bsta, bbsta, bsto, bbsto; int ii; assert(scanpointsx[i].node >= n); @@ -280,14 +280,14 @@ static relative_position_constraints relative_position_constraints_new(SparseMat return data; } -static void scale_coord(int dim, int m, real *x, real scale){ +static void scale_coord(int dim, int m, double *x, double scale){ int i; for (i = 0; i < dim*m; i++) { x[i] *= scale; } } -real overlap_scaling(int dim, int m, real *x, real *width, real scale_sta, real scale_sto, real epsilon, int maxiter){ +double overlap_scaling(int dim, int m, double *x, double *width, double scale_sta, double scale_sto, double epsilon, int maxiter){ /* do a bisection between scale_sta and scale_sto, up to maxiter iterations or till interval <= epsilon, to find the best scaling to avoid overlap m: number of points x: the coordinates @@ -298,11 +298,11 @@ real overlap_scaling(int dim, int m, real *x, real *width, real scale_sta, real - for shrinking down a layout to reduce white space, we will assume scale_sta and scale_sto are both given and positive, and scale_sta is the current guess. - for scaling up, we assume scale_sta, scale_sto <= 0 */ - real scale = -1, scale_best = -1; + double scale = -1, scale_best = -1; SparseMatrix C = NULL; int check_overlap_only = 1; int overlap = 0; - real two = 2; + double two = 2; int iter = 0; assert(epsilon > 0); @@ -362,14 +362,14 @@ real overlap_scaling(int dim, int m, real *x, real *width, real scale_sta, real } OverlapSmoother OverlapSmoother_new(SparseMatrix A, int m, - int dim, real lambda0, real *x, real *width, int include_original_graph, int neighborhood_only, - real *max_overlap, real *min_overlap, + int dim, double lambda0, double *x, double *width, int include_original_graph, int neighborhood_only, + double *max_overlap, double *min_overlap, int edge_labeling_scheme, int n_constr_nodes, int *constr_nodes, SparseMatrix A_constr, int shrink ){ OverlapSmoother sm; int i, j, k, *iw, *jw, jdiag; SparseMatrix B; - real *lambda, *d, *w, diag_d, diag_w, dist; + double *lambda, *d, *w, diag_d, diag_w, dist; assert((!A) || SparseMatrix_is_symmetric(A, FALSE)); @@ -386,7 +386,7 @@ OverlapSmoother OverlapSmoother_new(SparseMatrix A, int m, sm->tol_cg = 0.01; sm->maxit_cg = sqrt((double) A->m); - lambda = sm->lambda = N_GNEW(m,real); + lambda = sm->lambda = N_GNEW(m,double); for (i = 0; i < m; i++) sm->lambda[i] = lambda0; B= call_tri(m, dim, x); @@ -423,11 +423,11 @@ OverlapSmoother OverlapSmoother_new(SparseMatrix A, int m, assert((sm->Lwd)->type == MATRIX_TYPE_REAL); - ideal_distance_avoid_overlap(dim, sm->Lwd, x, width, (real*) (sm->Lwd->a), max_overlap, min_overlap); + ideal_distance_avoid_overlap(dim, sm->Lwd, x, width, (double*) (sm->Lwd->a), max_overlap, min_overlap); /* no overlap at all! */ if (*max_overlap < 1 && shrink){ - real scale_sta = MIN(1, *max_overlap*1.0001), scale_sto = 1; + double scale_sta = MIN(1, *max_overlap*1.0001), scale_sto = 1; if (Verbose) fprintf(stderr," no overlap (overlap = %f), rescale to shrink\n", *max_overlap - 1); @@ -438,7 +438,7 @@ OverlapSmoother OverlapSmoother_new(SparseMatrix A, int m, } iw = sm->Lw->ia; jw = sm->Lw->ja; - w = (real*) sm->Lw->a; d = (real*) sm->Lwd->a; + w = (double*) sm->Lw->a; d = (double*) sm->Lwd->a; for (i = 0; i < m; i++){ diag_d = diag_w = 0; @@ -478,10 +478,10 @@ void OverlapSmoother_delete(OverlapSmoother sm){ } -real OverlapSmoother_smooth(OverlapSmoother sm, int dim, real *x){ +double OverlapSmoother_smooth(OverlapSmoother sm, int dim, double *x){ int maxit_sm = 1;/* only using 1 iteration of stress majorization is found to give better results and save time! */ - real res = StressMajorizationSmoother_smooth(sm, dim, x, maxit_sm, 0.001); + double res = StressMajorizationSmoother_smooth(sm, dim, x, maxit_sm, 0.001); #ifdef DEBUG {FILE *fp; fp = fopen("/tmp/222","w"); @@ -493,8 +493,8 @@ real OverlapSmoother_smooth(OverlapSmoother sm, int dim, real *x){ /*================================= end OverlapSmoother =============*/ -static void scale_to_edge_length(int dim, SparseMatrix A, real *x, real avg_label_size){ - real dist; +static void scale_to_edge_length(int dim, SparseMatrix A, double *x, double avg_label_size){ + double dist; int i; if (!A) return; @@ -507,12 +507,12 @@ static void scale_to_edge_length(int dim, SparseMatrix A, real *x, real avg_labe for (i = 0; i < dim*A->m; i++) x[i] *= dist; } -static void print_bounding_box(int n, int dim, real *x){ - real *xmin, *xmax; +static void print_bounding_box(int n, int dim, double *x){ + double *xmin, *xmax; int i, k; - xmin = N_GNEW(dim,real); - xmax = N_GNEW(dim,real); + xmin = N_GNEW(dim,double); + xmax = N_GNEW(dim,double); for (i = 0; i < dim; i++) xmin[i]=xmax[i] = x[i]; @@ -530,12 +530,12 @@ static void print_bounding_box(int n, int dim, real *x){ free(xmax); } -static int check_convergence(real max_overlap, real res, int has_penalty_terms, real epsilon){ +static int check_convergence(double max_overlap, double res, int has_penalty_terms, double epsilon){ if (!has_penalty_terms) return (max_overlap <= 1); return res < epsilon; } -void remove_overlap(int dim, SparseMatrix A, real *x, real *label_sizes, int ntry, real initial_scaling, +void remove_overlap(int dim, SparseMatrix A, double *x, double *label_sizes, int ntry, double initial_scaling, int edge_labeling_scheme, int n_constr_nodes, int *constr_nodes, SparseMatrix A_constr, int do_shrinking){ /* edge_labeling_scheme: if ELSCHEME_NONE, n_constr_nodes/constr_nodes/A_constr are not used @@ -549,15 +549,15 @@ void remove_overlap(int dim, SparseMatrix A, real *x, real *label_sizes, int ntr */ - real lambda = 0.00; + double lambda = 0.00; OverlapSmoother sm; int include_original_graph = 0, i; - real LARGE = 100000; - real avg_label_size, res = LARGE; - real max_overlap = 0, min_overlap = 999; + double LARGE = 100000; + double avg_label_size, res = LARGE; + double max_overlap = 0, min_overlap = 999; int neighborhood_only = TRUE; int has_penalty_terms = FALSE; - real epsilon = 0.005; + double epsilon = 0.005; int shrink = 0; #ifdef TIME @@ -659,14 +659,14 @@ void remove_overlap(int dim, SparseMatrix A, real *x, real *label_sizes, int ntr } #endif #ifdef TIME - fprintf(stderr, "post processing %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC); + fprintf(stderr, "post processing %f\n",((double) (clock() - cpu)) / CLOCKS_PER_SEC); #endif } #else #include #include -void remove_overlap(int dim, SparseMatrix A, real *x, real *label_sizes, int ntry, real initial_scaling, +void remove_overlap(int dim, SparseMatrix A, double *x, double *label_sizes, int ntry, double initial_scaling, int edge_labeling_scheme, int n_constr_nodes, int *constr_nodes, SparseMatrix A_constr, int do_shrinking) { static int once; diff --git a/lib/neatogen/overlap.h b/lib/neatogen/overlap.h index 108f89a90..e23e2c891 100644 --- a/lib/neatogen/overlap.h +++ b/lib/neatogen/overlap.h @@ -19,15 +19,15 @@ typedef StressMajorizationSmoother OverlapSmoother; void OverlapSmoother_delete(OverlapSmoother sm); OverlapSmoother OverlapSmoother_new(SparseMatrix A, int m, - int dim, real lambda0, real *x, real *width, int include_original_graph, int neighborhood_only, - real *max_overlap, real *min_overlap, + int dim, double lambda0, double *x, double *width, int include_original_graph, int neighborhood_only, + double *max_overlap, double *min_overlap, int edge_labeling_scheme, int n_constr_nodes, int *constr_nodes, SparseMatrix A_constr, int shrink ); enum {ELSCHEME_NONE = 0, ELSCHEME_PENALTY, ELSCHEME_PENALTY2, ELSCHEME_STRAIGHTLINE_PENALTY, ELSCHEME_STRAIGHTLINE_PENALTY2}; struct relative_position_constraints_struct{ - real constr_penalty; /* penalty parameter used in making edge labels as much on the line as possible */ + double constr_penalty; /* penalty parameter used in making edge labels as much on the line as possible */ int edge_labeling_scheme;/* specifying whether to treat node of the form |edgelabel|* as a special node representing an edge label. 0 (no action, default), 1 (penalty based method to make that kind of node close to the center of its neighbor), 2 (penalty based method to make that kind of node close to the "old" center of its neighbor), @@ -37,7 +37,7 @@ struct relative_position_constraints_struct{ int *constr_nodes;/*constr_nodes: a list of nodes that need to be constrained. If NULL, unused.*/ int *irn;/* working arrays to hold the Laplacian of the constrain graph */ int *jcn; - real *val; + double *val; SparseMatrix A_constr; /*A_constr: neighbors of node i are in the row i of this matrix. i needs to sit in between these neighbors as much as possible. this must not be NULL if constr_nodes != NULL.*/ @@ -46,8 +46,8 @@ struct relative_position_constraints_struct{ typedef struct relative_position_constraints_struct* relative_position_constraints; -real OverlapSmoother_smooth(OverlapSmoother sm, int dim, real *x); +double OverlapSmoother_smooth(OverlapSmoother sm, int dim, double *x); -void remove_overlap(int dim, SparseMatrix A, real *x, real *label_sizes, int ntry, real initial_scaling, +void remove_overlap(int dim, SparseMatrix A, double *x, double *label_sizes, int ntry, double initial_scaling, int edge_labeling_scheme, int n_constr_nodes, int *constr_nodes, SparseMatrix A_constr, int doShrink); -real overlap_scaling(int dim, int m, real *x, real *width, real scale_sta, real scale_sto, real epsilon, int maxiter); +double overlap_scaling(int dim, int m, double *x, double *width, double scale_sta, double scale_sto, double epsilon, int maxiter); diff --git a/lib/patchwork/tree_map.c b/lib/patchwork/tree_map.c index 77345b29f..561b639b5 100644 --- a/lib/patchwork/tree_map.c +++ b/lib/patchwork/tree_map.c @@ -11,8 +11,8 @@ #include #include -static void squarify(int n, real *area, rectangle *recs, int nadded, real maxarea, real minarea, real totalarea, - real asp, rectangle fillrec){ +static void squarify(int n, double *area, rectangle *recs, int nadded, double maxarea, double minarea, double totalarea, + double asp, rectangle fillrec){ /* add a list of area in fillrec using squarified treemap alg. n: number of items to add area: area of these items, Sum to 1 (?). @@ -22,7 +22,7 @@ static void squarify(int n, real *area, rectangle *recs, int nadded, real maxare asp: current worst aspect ratio of the already added items so far fillrec: the rectangle to be filled in. */ - real w = MIN(fillrec.size[0], fillrec.size[1]); + double w = MIN(fillrec.size[0], fillrec.size[1]); int i; if (n <= 0) return; @@ -39,7 +39,7 @@ static void squarify(int n, real *area, rectangle *recs, int nadded, real maxare totalarea = area[0]; squarify(n, area, recs, nadded, maxarea, minarea, totalarea, asp, fillrec); } else { - real newmaxarea, newminarea, s, h, maxw, minw, newasp, hh, ww, xx, yy; + double newmaxarea, newminarea, s, h, maxw, minw, newasp, hh, ww, xx, yy; if (nadded < n){ newmaxarea = MAX(maxarea, area[nadded]); newminarea = MIN(minarea, area[nadded]); @@ -95,11 +95,11 @@ static void squarify(int n, real *area, rectangle *recs, int nadded, real maxare * fillred - rectangle to be filled * return array of rectangles */ -rectangle* tree_map(int n, real *area, rectangle fillrec){ +rectangle* tree_map(int n, double *area, rectangle fillrec){ /* fill a rectangle rec with n items, each item i has area[i] area. */ rectangle *recs; int i; - real total = 0, minarea = 1., maxarea = 0., asp = 1, totalarea = 0; + double total = 0, minarea = 1., maxarea = 0., asp = 1, totalarea = 0; int nadded = 0; for (i = 0; i < n; i++) total += area[i]; @@ -115,7 +115,7 @@ rectangle* tree_map(int n, real *area, rectangle fillrec){ /* rectangle_new: * Create and initialize a new rectangle structure */ -rectangle rectangle_new(real x, real y, real width, real height){ +rectangle rectangle_new(double x, double y, double width, double height){ rectangle r; r.x[0] = x; r.x[1] = y; diff --git a/lib/patchwork/tree_map.h b/lib/patchwork/tree_map.h index 349fdc1e1..367ac3e0a 100644 --- a/lib/patchwork/tree_map.h +++ b/lib/patchwork/tree_map.h @@ -13,10 +13,10 @@ #include typedef struct rectangle_struct { - real x[2];/* center */ - real size[2]; /* total width/height*/ + double x[2];/* center */ + double size[2]; /* total width/height*/ } rectangle; -extern rectangle* tree_map(int n, real *area, rectangle fillrec); +extern rectangle* tree_map(int n, double *area, rectangle fillrec); -extern rectangle rectangle_new(real x, real y, real width, real height); +extern rectangle rectangle_new(double x, double y, double width, double height); diff --git a/lib/sfdpgen/Multilevel.c b/lib/sfdpgen/Multilevel.c index 32e6d99a3..e54cfdf4f 100644 --- a/lib/sfdpgen/Multilevel.c +++ b/lib/sfdpgen/Multilevel.c @@ -42,7 +42,7 @@ void Multilevel_control_delete(Multilevel_control ctrl){ free(ctrl); } -static Multilevel Multilevel_init(SparseMatrix A, SparseMatrix D, real *node_weights){ +static Multilevel Multilevel_init(SparseMatrix A, SparseMatrix D, double *node_weights){ Multilevel grid; if (!A) return NULL; assert(A->m == A->n); @@ -244,7 +244,7 @@ static void maximal_independent_edge_set(SparseMatrix A, int randomize, int **ma 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; + double *a, amax = 0; int first = TRUE, jamax = 0; assert(A); @@ -261,7 +261,7 @@ static void maximal_independent_edge_set_heavest_edge_pernode(SparseMatrix A, in assert(SparseMatrix_is_symmetric(A, FALSE)); assert(A->type == MATRIX_TYPE_REAL); - a = (real*) A->a; + a = (double*) A->a; if (!randomize){ for (i = 0; i < m; i++){ first = TRUE; @@ -326,7 +326,7 @@ static void maximal_independent_edge_set_heavest_edge_pernode(SparseMatrix A, in static void 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; NOTUSED(n); - real *a, amax = 0; + double *a, amax = 0; int first = TRUE, jamax = 0; int *matched, nz, ncmax = 0, nz0, nzz,k ; enum {UNMATCHED = -2, MATCHED = -1}; @@ -350,7 +350,7 @@ static void maximal_independent_edge_set_heavest_edge_pernode_leaves_first(Spars *ncluster = 0; (*clusterp)[0] = 0; nz = 0; - a = (real*) A->a; + a = (double*) A->a; if (!randomize){ for (i = 0; i < m; i++){ if (matched[i] == MATCHED || node_degree(i) != 1) continue; @@ -502,7 +502,7 @@ static void maximal_independent_edge_set_heavest_edge_pernode_leaves_first(Spars static void maximal_independent_edge_set_heavest_edge_pernode_supernodes_first(SparseMatrix A, int randomize, int **cluster, int **clusterp, int *ncluster){ int i, ii, j, *ia, *ja, m, n, *p = NULL; NOTUSED(n); - real *a, amax = 0; + double *a, amax = 0; int first = TRUE, jamax = 0; int *matched, nz, nz0; enum {UNMATCHED = -2, MATCHED = -1}; @@ -529,7 +529,7 @@ static void maximal_independent_edge_set_heavest_edge_pernode_supernodes_first(S *ncluster = 0; (*clusterp)[0] = 0; nz = 0; - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < nsuper; i++){ if (superp[i+1] - superp[i] <= 1) continue; @@ -631,9 +631,9 @@ static void maximal_independent_edge_set_heavest_edge_pernode_supernodes_first(S } static int scomp(const void *s1, const void *s2){ - const real *ss1, *ss2; - ss1 = (const real*) s1; - ss2 = (const real*) s2; + const double *ss1, *ss2; + ss1 = (const double*) s1; + ss2 = (const double*) s2; if ((ss1)[1] > (ss2)[1]){ return -1; @@ -647,10 +647,10 @@ static void maximal_independent_edge_set_heavest_cluster_pernode_leaves_first(Sp int randomize, int **cluster, int **clusterp, int *ncluster){ int i, ii, j, *ia, *ja, m, n, *p = NULL, q, iv; NOTUSED(n); - real *a; + double *a; int *matched, nz, nz0, nzz,k, nv; enum {UNMATCHED = -2, MATCHED = -1}; - real *vlist; + double *vlist; assert(A); assert(SparseMatrix_known_strucural_symmetric(A)); @@ -662,7 +662,7 @@ static void maximal_independent_edge_set_heavest_cluster_pernode_leaves_first(Sp *cluster = N_GNEW(m,int); *clusterp = N_GNEW((m+1),int); matched = N_GNEW(m,int); - vlist = N_GNEW(2*m,real); + vlist = N_GNEW(2*m,double); for (i = 0; i < m; i++) matched[i] = i; @@ -672,7 +672,7 @@ static void maximal_independent_edge_set_heavest_cluster_pernode_leaves_first(Sp *ncluster = 0; (*clusterp)[0] = 0; nz = 0; - a = (real*) A->a; + a = (double*) A->a; p = random_permutation(m); for (ii = 0; ii < m; ii++){ @@ -716,7 +716,7 @@ static void maximal_independent_edge_set_heavest_cluster_pernode_leaves_first(Sp } } if (nv > 0){ - qsort(vlist, nv, sizeof(real)*2, scomp); + qsort(vlist, nv, sizeof(double)*2, scomp); for (j = 0; j < MIN(csize - 1, nv); j++){ iv = (int) vlist[2*j]; matched[iv] = MATCHED; @@ -742,7 +742,7 @@ static void maximal_independent_edge_set_heavest_cluster_pernode_leaves_first(Sp } static void maximal_independent_edge_set_heavest_edge_pernode_scaled(SparseMatrix A, int randomize, int **matching, int *nmatch){ int i, ii, j, *ia, *ja, m, n, *p = NULL; - real *a, amax = 0; + double *a, amax = 0; int first = TRUE, jamax = 0; assert(A); @@ -759,7 +759,7 @@ static void maximal_independent_edge_set_heavest_edge_pernode_scaled(SparseMatri assert(SparseMatrix_is_symmetric(A, FALSE)); assert(A->type == MATRIX_TYPE_REAL); - a = (real*) A->a; + a = (double*) A->a; if (!randomize){ for (i = 0; i < m; i++){ first = TRUE; @@ -833,11 +833,11 @@ static SparseMatrix DistanceMatrix_restrict_filtering(int *mask, int is_C, int i } static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, SparseMatrix D, SparseMatrix *cD, - real *node_wgt, real **cnode_wgt, + double *node_wgt, double **cnode_wgt, SparseMatrix *P, SparseMatrix *R, Multilevel_control ctrl, int *coarsen_scheme_used){ int *matching = NULL, nmatch = 0, nc, nzc, n, i; int *irn = NULL, *jcn = NULL, *ia = NULL, *ja = NULL; - real *val = NULL; + double *val = NULL; SparseMatrix B = NULL; int *vset = NULL, nvset, ncov, j; int *cluster=NULL, *clusterp=NULL, ncluster; @@ -919,7 +919,7 @@ static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, Sparse } irn = N_GNEW(n,int); jcn = N_GNEW(n,int); - val = N_GNEW(n,real); + val = N_GNEW(n,double); nzc = 0; for (i = 0; i < ncluster; i++){ for (j = clusterp[i]; j < clusterp[i+1]; j++){ @@ -930,7 +930,7 @@ static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, Sparse } } assert(nzc == n); - *P = SparseMatrix_from_coordinate_arrays(nzc, n, nc, irn, jcn, (void *) val, MATRIX_TYPE_REAL, sizeof(real)); + *P = SparseMatrix_from_coordinate_arrays(nzc, n, nc, irn, jcn, (void *) val, MATRIX_TYPE_REAL, sizeof(double)); *R = SparseMatrix_transpose(*P); *cD = DistanceMatrix_restrict_cluster(ncluster, clusterp, cluster, *P, *R, D); @@ -971,7 +971,7 @@ static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, Sparse } irn = N_GNEW(n,int); jcn = N_GNEW(n,int); - val = N_GNEW(n,real); + val = N_GNEW(n,double); nzc = 0; nc = 0; for (i = 0; i < n; i++){ if (matching[i] >= 0){ @@ -994,7 +994,7 @@ static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, Sparse } assert(nc == nmatch); assert(nzc == n); - *P = SparseMatrix_from_coordinate_arrays(nzc, n, nc, irn, jcn, (void *) val, MATRIX_TYPE_REAL, sizeof(real)); + *P = SparseMatrix_from_coordinate_arrays(nzc, n, nc, irn, jcn, (void *) val, MATRIX_TYPE_REAL, sizeof(double)); *R = SparseMatrix_transpose(*P); *cA = SparseMatrix_multiply3(*R, A, *P); /* @@ -1033,7 +1033,7 @@ static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, Sparse } irn = N_GNEW(nzc,int); jcn = N_GNEW(nzc,int); - val = N_GNEW(nzc,real); + val = N_GNEW(nzc,double); nzc = 0; for (i = 0; i < n; i++){ if (vset[i] == MAX_IND_VTX_SET_F){ @@ -1059,7 +1059,7 @@ static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, Sparse } } - *P = SparseMatrix_from_coordinate_arrays(nzc, n, nc, irn, jcn, (void *) val, MATRIX_TYPE_REAL, sizeof(real)); + *P = SparseMatrix_from_coordinate_arrays(nzc, n, nc, irn, jcn, (void *) val, MATRIX_TYPE_REAL, sizeof(double)); *R = SparseMatrix_transpose(*P); *cA = SparseMatrix_multiply3(*R, A, *P); if (!*cA) goto RETURN; @@ -1085,10 +1085,10 @@ static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, Sparse free(clusterp); } -void Multilevel_coarsen(SparseMatrix A, SparseMatrix *cA, SparseMatrix D, SparseMatrix *cD, real *node_wgt, real **cnode_wgt, +void Multilevel_coarsen(SparseMatrix A, SparseMatrix *cA, SparseMatrix D, SparseMatrix *cD, double *node_wgt, double **cnode_wgt, SparseMatrix *P, SparseMatrix *R, Multilevel_control ctrl, int *coarsen_scheme_used){ SparseMatrix cA0 = A, cD0 = NULL, P0 = NULL, R0 = NULL, M; - real *cnode_wgt0 = NULL; + double *cnode_wgt0 = NULL; int nc = 0, n; *P = NULL; *R = NULL; *cA = NULL; *cnode_wgt = NULL, *cD = NULL; @@ -1140,7 +1140,7 @@ void print_padding(int n){ static Multilevel Multilevel_establish(Multilevel grid, Multilevel_control ctrl){ Multilevel cgrid; int coarsen_scheme_used; - real *cnode_weights = NULL; + double *cnode_weights = NULL; SparseMatrix P, R, A, cA, D, cD; #ifdef DEBUG_PRINT @@ -1178,7 +1178,7 @@ static Multilevel Multilevel_establish(Multilevel grid, Multilevel_control ctrl) } -Multilevel Multilevel_new(SparseMatrix A0, SparseMatrix D0, real *node_weights, Multilevel_control ctrl){ +Multilevel Multilevel_new(SparseMatrix A0, SparseMatrix D0, double *node_weights, Multilevel_control ctrl){ /* A: the weighting matrix. D: the distance matrix, could be NULL. If not null, the two matrices must have the same sparsity pattern */ Multilevel grid; SparseMatrix A = A0, D = D0; diff --git a/lib/sfdpgen/Multilevel.h b/lib/sfdpgen/Multilevel.h index d05c0c79e..b501c50be 100644 --- a/lib/sfdpgen/Multilevel.h +++ b/lib/sfdpgen/Multilevel.h @@ -22,7 +22,7 @@ struct Multilevel_struct { but different entry values. For spring-electrical method, D = NULL. */ SparseMatrix P; SparseMatrix R; - real *node_weights; + double *node_weights; Multilevel next; Multilevel prev; int delete_top_level_A; @@ -39,7 +39,7 @@ enum {COARSEN_MODE_GENTLE, COARSEN_MODE_FORCEFUL}; struct Multilevel_control_struct { int minsize; - real min_coarsen_factor; + double min_coarsen_factor; int maxlevel; int randomize; int coarsen_scheme; @@ -54,7 +54,7 @@ void Multilevel_control_delete(Multilevel_control ctrl); void Multilevel_delete(Multilevel grid); -Multilevel Multilevel_new(SparseMatrix A, SparseMatrix D, real *node_weights, Multilevel_control ctrl); +Multilevel Multilevel_new(SparseMatrix A, SparseMatrix D, double *node_weights, Multilevel_control ctrl); Multilevel Multilevel_get_coarsest(Multilevel grid); @@ -63,5 +63,5 @@ void print_padding(int n); #define Multilevel_is_finest(grid) (!((grid)->prev)) #define Multilevel_is_coarsest(grid) (!((grid)->next)) -void Multilevel_coarsen(SparseMatrix A, SparseMatrix *cA, SparseMatrix D, SparseMatrix *cD, real *node_wgt, real **cnode_wgt, +void Multilevel_coarsen(SparseMatrix A, SparseMatrix *cA, SparseMatrix D, SparseMatrix *cD, double *node_wgt, double **cnode_wgt, SparseMatrix *P, SparseMatrix *R, Multilevel_control ctrl, int *coarsen_scheme_used); diff --git a/lib/sfdpgen/post_process.c b/lib/sfdpgen/post_process.c index 9e08cbe0c..557783b86 100644 --- a/lib/sfdpgen/post_process.c +++ b/lib/sfdpgen/post_process.c @@ -28,14 +28,14 @@ #define node_degree(i) (ia[(i)+1] - ia[(i)]) -static SparseMatrix ideal_distance_matrix(SparseMatrix A, int dim, real *x){ +static SparseMatrix ideal_distance_matrix(SparseMatrix A, int dim, double *x){ /* find the ideal distance between edges, either 1, or |N[i] \Union N[j]| - |N[i] \Intersection N[j]| */ SparseMatrix D; int *ia, *ja, i, j, k, l, nz; - real *d; + double *d; int *mask = NULL; - real len, di, sum, sumd; + double len, di, sum, sumd; assert(SparseMatrix_is_symmetric(A, FALSE)); @@ -45,9 +45,9 @@ static SparseMatrix ideal_distance_matrix(SparseMatrix A, int dim, real *x){ if (D->type != MATRIX_TYPE_REAL){ free(D->a); D->type = MATRIX_TYPE_REAL; - D->a = N_GNEW(D->nz,real); + D->a = N_GNEW(D->nz,double); } - d = (real*) D->a; + d = (double*) D->a; mask = N_GNEW(D->m,int); for (i = 0; i < D->m; i++) mask[i] = -1; @@ -97,7 +97,7 @@ static SparseMatrix ideal_distance_matrix(SparseMatrix A, int dim, real *x){ } -StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int dim, real lambda0, real *x, +StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int dim, double lambda0, double *x, int ideal_dist_scheme){ /* use up to dist 2 neighbor */ /* use up to dist 2 neighbor. This is used in overcoming pherical effect with ideal distance of @@ -106,8 +106,8 @@ StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int d 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, dist, s = 0, stop = 0, sbot = 0; + double *d, *w, *lambda; + double *avg_dist, diag_d, diag_w, dist, s = 0, stop = 0, sbot = 0; SparseMatrix ID; assert(SparseMatrix_is_symmetric(A, FALSE)); @@ -121,11 +121,11 @@ StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int d sm->tol_cg = 0.01; sm->maxit_cg = (int)sqrt((double) A->m); - lambda = sm->lambda = N_GNEW(m,real); + lambda = sm->lambda = N_GNEW(m,double); for (i = 0; i < m; i++) sm->lambda[i] = lambda0; mask = N_GNEW(m,int); - avg_dist = N_GNEW(m,real); + avg_dist = N_GNEW(m,double); for (i = 0; i < m ;i++){ avg_dist[i] = 0; @@ -172,7 +172,7 @@ StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int d iw = sm->Lw->ia; jw = sm->Lw->ja; - w = (real*) sm->Lw->a; d = (real*) sm->Lwd->a; + w = (double*) sm->Lw->a; d = (double*) sm->Lwd->a; id = sm->Lwd->ia; jd = sm->Lwd->ja; iw[0] = id[0] = 0; @@ -290,7 +290,7 @@ StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int d return sm; } -StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, int dim, real lambda0, real *x, +StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, int dim, double lambda0, double *x, int weighting_scheme, int scale_initial_coord){ /* solve a stress model to achieve the ideal distance among a sparse set of edges recorded in A. A must be a real matrix. @@ -298,9 +298,9 @@ StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, StressMajorizationSmoother sm; int i, j, k, m = A->m, *ia, *ja, *iw, *jw, *id, *jd; int nz; - real *d, *w, *lambda; - real diag_d, diag_w, *a, dist, s = 0, stop = 0, sbot = 0; - real xdot = 0; + double *d, *w, *lambda; + double diag_d, diag_w, *a, dist, s = 0, stop = 0, sbot = 0; + double xdot = 0; assert(SparseMatrix_is_symmetric(A, FALSE) && A->type == MATRIX_TYPE_REAL); @@ -312,7 +312,7 @@ StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, ia = A->ia; ja = A->ja; - a = (real*) A->a; + a = (double*) A->a; sm = MALLOC(sizeof(struct StressMajorizationSmoother_struct)); @@ -323,7 +323,7 @@ StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, sm->tol_cg = 0.01; sm->maxit_cg = (int)sqrt((double) A->m); - lambda = sm->lambda = MALLOC(sizeof(real)*m); + lambda = sm->lambda = MALLOC(sizeof(double)*m); for (i = 0; i < m; i++) sm->lambda[i] = lambda0; nz = A->nz; @@ -337,7 +337,7 @@ StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, iw = sm->Lw->ia; jw = sm->Lw->ja; id = sm->Lwd->ia; jd = sm->Lwd->ja; - w = (real*) sm->Lw->a; d = (real*) sm->Lwd->a; + w = (double*) sm->Lw->a; d = (double*) sm->Lwd->a; iw[0] = id[0] = 0; nz = 0; @@ -412,8 +412,8 @@ StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, return sm; } -static real total_distance(int m, int dim, real* x, real* y){ - real total = 0, dist = 0; +static double total_distance(int m, int dim, double* x, double* y){ + double total = 0, dist = 0; int i, j; for (i = 0; i < m; i++){ @@ -434,23 +434,23 @@ void SparseStressMajorizationSmoother_delete(SparseStressMajorizationSmoother sm } -real SparseStressMajorizationSmoother_smooth(SparseStressMajorizationSmoother sm, int dim, real *x, int maxit_sm, real tol){ +double SparseStressMajorizationSmoother_smooth(SparseStressMajorizationSmoother sm, int dim, double *x, int maxit_sm, double tol){ return StressMajorizationSmoother_smooth(sm, dim, x, maxit_sm, tol); } -static void get_edge_label_matrix(relative_position_constraints data, int m, int dim, real *x, SparseMatrix *LL, real **rhs){ +static void get_edge_label_matrix(relative_position_constraints data, int m, int dim, double *x, SparseMatrix *LL, double **rhs){ int edge_labeling_scheme = data->edge_labeling_scheme; int n_constr_nodes = data->n_constr_nodes; int *constr_nodes = data->constr_nodes; SparseMatrix A_constr = data->A_constr; int *ia = A_constr->ia, *ja = A_constr->ja, ii, jj, nz, l, ll, i, j; int *irn = data->irn, *jcn = data->jcn; - real *val = data->val, dist, kk, k; - real *x00 = NULL; + double *val = data->val, dist, kk, k; + double *x00 = NULL; SparseMatrix Lc = NULL; - real constr_penalty = data->constr_penalty; + double constr_penalty = data->constr_penalty; if (edge_labeling_scheme == ELSCHEME_PENALTY || edge_labeling_scheme == ELSCHEME_STRAIGHTLINE_PENALTY){ /* for an node with two neighbors j--i--k, and assume i needs to be between j and k, then the contribution to P is @@ -505,7 +505,7 @@ static void get_edge_label_matrix(relative_position_constraints data, int m, int } } } - Lc = SparseMatrix_from_coordinate_arrays(nz, m, m, irn, jcn, val, MATRIX_TYPE_REAL, sizeof(real)); + Lc = SparseMatrix_from_coordinate_arrays(nz, m, m, irn, jcn, val, MATRIX_TYPE_REAL, sizeof(double)); } else if (edge_labeling_scheme == ELSCHEME_PENALTY2 || edge_labeling_scheme == ELSCHEME_STRAIGHTLINE_PENALTY2){ /* for an node with two neighbors j--i--k, and assume i needs to be between the old position of j and k, then the contribution to P is 1/d_jk, and to the right hand side: {0,...,average_position_of_i's neighbor if i is an edge node,...} @@ -517,7 +517,7 @@ static void get_edge_label_matrix(relative_position_constraints data, int m, int jcn = data->jcn = MALLOC(sizeof(int)*nz); val = data->val = MALLOC(sizeof(double)*nz); } - x00 = MALLOC(sizeof(real)*m*dim); + x00 = MALLOC(sizeof(double)*m*dim); for (i = 0; i < m*dim; i++) x00[i] = 0; nz = 0; for (i = 0; i < n_constr_nodes; i++){ @@ -535,16 +535,16 @@ static void get_edge_label_matrix(relative_position_constraints data, int m, int x00[ii*dim+l] *= constr_penalty/(dist)/(ia[ii+1] - ia[ii]); } } - Lc = SparseMatrix_from_coordinate_arrays(nz, m, m, irn, jcn, val, MATRIX_TYPE_REAL, sizeof(real)); + Lc = SparseMatrix_from_coordinate_arrays(nz, m, m, irn, jcn, val, MATRIX_TYPE_REAL, sizeof(double)); } *LL = Lc; *rhs = x00; } -real get_stress(int m, int dim, int *iw, int *jw, real *w, real *d, real *x, real scaling, void *data, int weighted){ +double get_stress(int m, int dim, int *iw, int *jw, double *w, double *d, double *x, double scaling, void *data, int weighted){ int i, j; - real res = 0., dist; + double res = 0., dist; /* we use the fact that d_ij = w_ij*graph_dist(i,j). Also, d_ij and x are scalinged by *scaling, so divide by it to get actual unscaled streee. */ for (i = 0; i < m; i++){ for (j = iw[i]; j < iw[i+1]; j++){ @@ -563,9 +563,9 @@ real get_stress(int m, int dim, int *iw, int *jw, real *w, real *d, real *x, rea } -static void uniform_stress_augment_rhs(int m, int dim, real *x, real *y, real alpha, real M){ +static void uniform_stress_augment_rhs(int m, int dim, double *x, double *y, double alpha, double M){ int i, j, k; - real dist, distij; + double dist, distij; for (i = 0; i < m; i++){ for (j = i+1; j < m; j++){ dist = distance_cropped(x, dim, i, j); @@ -578,7 +578,7 @@ static void uniform_stress_augment_rhs(int m, int dim, real *x, real *y, real al } } -static real uniform_stress_solve(SparseMatrix Lw, real alpha, int dim, real *x0, real *rhs, real tol, int maxit){ +static double uniform_stress_solve(SparseMatrix Lw, double alpha, int dim, double *x0, double *rhs, double tol, int maxit){ Operator Ax; Operator Precon; @@ -589,27 +589,27 @@ static real uniform_stress_solve(SparseMatrix Lw, real alpha, int dim, real *x0, } -real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, real *x, int maxit_sm, real tol) { +double StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, double *x, int maxit_sm, double tol) { SparseMatrix Lw = sm->Lw, Lwd = sm->Lwd, Lwdd = NULL; int i, j, k, m, *id, *jd, *iw, *jw, idiag, flag = 0, iter = 0; - real *w, *dd, *d, *y = NULL, *x0 = NULL, *x00 = NULL, diag, diff = 1, *lambda = sm->lambda, alpha = 0., M = 0.; + double *w, *dd, *d, *y = NULL, *x0 = NULL, *x00 = NULL, diag, diff = 1, *lambda = sm->lambda, alpha = 0., M = 0.; SparseMatrix Lc = NULL; - real dij, dist; + double dij, dist; Lwdd = SparseMatrix_copy(Lwd); m = Lw->m; - x0 = calloc(dim*m, sizeof(real)); + x0 = calloc(dim*m, sizeof(double)); if (!x0) goto RETURN; - memcpy(x0, x, sizeof(real)*dim*m); - y = calloc(dim*m, sizeof(real)); + memcpy(x0, x, sizeof(double)*dim*m); + y = calloc(dim*m, sizeof(double)); if (!y) goto RETURN; id = Lwd->ia; jd = Lwd->ja; - d = (real*) Lwd->a; - dd = (real*) Lwdd->a; - w = (real*) Lw->a; + d = (double*) Lwd->a; + dd = (double*) Lwdd->a; + w = (double*) Lw->a; iw = Lw->ia; jw = Lw->ja; #ifdef DEBUG_PRINT @@ -623,8 +623,8 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r get_edge_label_matrix(sm->data, m, dim, x, &Lc, &x00); if (Lc) Lw = SparseMatrix_add(Lw, Lc); } else if (sm->scheme == SM_SCHEME_UNIFORM_STRESS){ - alpha = ((real*) (sm->data))[0]; - M = ((real*) (sm->data))[1]; + alpha = ((double*) (sm->data))[0]; + M = ((double*) (sm->data))[1]; } while (iter++ < maxit_sm && diff > tol){ @@ -719,7 +719,7 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r #endif - memcpy(x, y, sizeof(real)*m*dim); + memcpy(x, y, sizeof(double)*m*dim); } #ifdef DEBUG @@ -754,16 +754,16 @@ void StressMajorizationSmoother_delete(StressMajorizationSmoother sm){ } -TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, real lambda0, real *x, int use_triangularization){ +TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, double lambda0, double *x, int use_triangularization){ TriangleSmoother sm; int i, j, k, m = A->m, *ia = A->ia, *ja = A->ja, *iw, *jw, jdiag, nz; SparseMatrix B; - real *avg_dist, *lambda, *d, *w, diag_d, diag_w, dist; - real s = 0, stop = 0, sbot = 0; + double *avg_dist, *lambda, *d, *w, diag_d, diag_w, dist; + double s = 0, stop = 0, sbot = 0; assert(SparseMatrix_is_symmetric(A, FALSE)); - avg_dist = N_GNEW(m,real); + avg_dist = N_GNEW(m,double); for (i = 0; i < m ;i++){ avg_dist[i] = 0; @@ -784,7 +784,7 @@ TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, real lambda0, rea sm->tol_cg = 0.01; sm->maxit_cg = (int)sqrt((double) A->m); - lambda = sm->lambda = N_GNEW(m,real); + lambda = sm->lambda = N_GNEW(m,double); for (i = 0; i < m; i++) sm->lambda[i] = lambda0; if (m > 2){ @@ -810,7 +810,7 @@ TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, real lambda0, rea iw = sm->Lw->ia; jw = sm->Lw->ja; - w = (real*) sm->Lw->a; d = (real*) sm->Lwd->a; + w = (double*) sm->Lw->a; d = (double*) sm->Lwd->a; for (i = 0; i < m; i++){ diag_d = diag_w = 0; @@ -859,7 +859,7 @@ void TriangleSmoother_delete(TriangleSmoother sm){ } -void TriangleSmoother_smooth(TriangleSmoother sm, int dim, real *x){ +void TriangleSmoother_smooth(TriangleSmoother sm, int dim, double *x){ StressMajorizationSmoother_smooth(sm, dim, x, 50, 0.001); } @@ -868,23 +868,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, real *x){ +SpringSmoother SpringSmoother_new(SparseMatrix A, int dim, spring_electrical_control ctrl, double *x){ 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; + double *d, *dd; + double *avg_dist; SparseMatrix ID = NULL; assert(SparseMatrix_is_symmetric(A, FALSE)); ID = ideal_distance_matrix(A, dim, x); - dd = (real*) ID->a; + dd = (double*) ID->a; sm = N_GNEW(1,struct SpringSmoother_struct); mask = N_GNEW(m,int); - avg_dist = N_GNEW(m,real); + avg_dist = N_GNEW(m,double); for (i = 0; i < m ;i++){ avg_dist[i] = 0; @@ -929,7 +929,7 @@ SpringSmoother SpringSmoother_new(SparseMatrix A, int dim, spring_electrical_con } id = sm->D->ia; jd = sm->D->ja; - d = (real*) sm->D->a; + d = (double*) sm->D->a; id[0] = 0; nz = 0; @@ -985,7 +985,7 @@ void SpringSmoother_delete(SpringSmoother sm){ -void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A, real *node_weights, int dim, real *x){ +void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A, double *node_weights, int dim, double *x){ int flag = 0; spring_electrical_spring_embedding(dim, A, sm->D, sm->ctrl, node_weights, x, &flag); @@ -995,7 +995,7 @@ void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A, real *node_weights /*=============================== end of spring and spring-electrical based smoother =========== */ -void post_process_smoothing(int dim, SparseMatrix A, spring_electrical_control ctrl, real *node_weights, real *x, int *flag){ +void post_process_smoothing(int dim, SparseMatrix A, spring_electrical_control ctrl, double *node_weights, double *x, int *flag){ #ifdef TIME clock_t cpu; #endif @@ -1059,6 +1059,6 @@ void post_process_smoothing(int dim, SparseMatrix A, spring_electrical_control c }/* end switch between smoothing methods */ #ifdef TIME - if (Verbose) fprintf(stderr, "post processing %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC); + if (Verbose) fprintf(stderr, "post processing %f\n",((double) (clock() - cpu)) / CLOCKS_PER_SEC); #endif } diff --git a/lib/sfdpgen/post_process.h b/lib/sfdpgen/post_process.h index 7d4c02680..0a4284054 100644 --- a/lib/sfdpgen/post_process.h +++ b/lib/sfdpgen/post_process.h @@ -18,12 +18,12 @@ struct StressMajorizationSmoother_struct { SparseMatrix D;/* distance matrix. The diagonal is removed hence the ia, ja structure is different from Lw and Lwd!! */ SparseMatrix Lw;/* the weighted laplacian. with offdiag = -1/w_ij */ SparseMatrix Lwd;/* the laplacian like matrix with offdiag = -scaling*d_ij/w_ij. RHS in stress majorization = Lwd.x */ - real* lambda; + double* lambda; void (*data_deallocator)(void*); void *data; int scheme; - real scaling;/* scaling. It is multiplied to Lwd. need to divide coordinate x at the end of the stress majorization process */ - real tol_cg;/* tolerance and maxit for conjugate gradient that solves the Laplacian system. + double scaling;/* scaling. It is multiplied to Lwd. need to divide coordinate x at the end of the stress majorization process */ + double tol_cg;/* tolerance and maxit for conjugate gradient that solves the Laplacian system. typically the Laplacian only needs to be solved very crudely as it is part of an outer iteration.*/ int maxit_cg; @@ -34,9 +34,9 @@ typedef struct StressMajorizationSmoother_struct *StressMajorizationSmoother; void StressMajorizationSmoother_delete(StressMajorizationSmoother sm); enum {IDEAL_GRAPH_DIST, IDEAL_AVG_DIST, IDEAL_POWER_DIST}; -StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int dim, real lambda, real *x, int ideal_dist_scheme); +StressMajorizationSmoother StressMajorizationSmoother2_new(SparseMatrix A, int dim, double lambda, double *x, int ideal_dist_scheme); -real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, real *x, int maxit, real tol); +double StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, double *x, int maxit, double tol); /*-------------------- triangle/neirhborhood graph based smoother ------------------- */ typedef StressMajorizationSmoother TriangleSmoother; @@ -44,9 +44,9 @@ typedef StressMajorizationSmoother TriangleSmoother; void TriangleSmoother_delete(TriangleSmoother sm); -TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, real lambda, real *x, int use_triangularization); +TriangleSmoother TriangleSmoother_new(SparseMatrix A, int dim, double lambda, double *x, int use_triangularization); -void TriangleSmoother_smooth(TriangleSmoother sm, int dim, real *x); +void TriangleSmoother_smooth(TriangleSmoother sm, int dim, double *x); @@ -59,14 +59,14 @@ struct SpringSmoother_struct { typedef struct SpringSmoother_struct *SpringSmoother; -SpringSmoother SpringSmoother_new(SparseMatrix A, int dim, spring_electrical_control ctrl, real *x); +SpringSmoother SpringSmoother_new(SparseMatrix A, int dim, spring_electrical_control ctrl, double *x); void SpringSmoother_delete(SpringSmoother sm); -void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A, real *node_weights, int dim, real *x); +void SpringSmoother_smooth(SpringSmoother sm, SparseMatrix A, double *node_weights, int dim, double *x); /*------------------------------------------------------------------*/ -void post_process_smoothing(int dim, SparseMatrix A, spring_electrical_control ctrl, real *node_weights, real *x, int *flag); +void post_process_smoothing(int dim, SparseMatrix A, spring_electrical_control ctrl, double *node_weights, double *x, int *flag); /*-------------------- sparse stress majorizationp ------------------- */ typedef StressMajorizationSmoother SparseStressMajorizationSmoother; @@ -76,11 +76,11 @@ typedef StressMajorizationSmoother SparseStressMajorizationSmoother; void SparseStressMajorizationSmoother_delete(SparseStressMajorizationSmoother sm); enum {WEIGHTING_SCHEME_NONE, WEIGHTING_SCHEME_INV_DIST, WEIGHTING_SCHEME_SQR_DIST}; -SparseStressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, int dim, real lambda, real *x, +SparseStressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, int dim, double lambda, double *x, int weighting_scheme, int scale_initial_coord); -real SparseStressMajorizationSmoother_smooth(SparseStressMajorizationSmoother sm, int dim, real *x, int maxit_sm, real tol); +double SparseStressMajorizationSmoother_smooth(SparseStressMajorizationSmoother sm, int dim, double *x, int maxit_sm, double tol); -real get_stress(int m, int dim, int *iw, int *jw, real *w, real *d, real *x, real scaling, void *data, int weighted); +double get_stress(int m, int dim, int *iw, int *jw, double *w, double *d, double *x, double scaling, void *data, int weighted); /*--------------------------------------------------------------*/ diff --git a/lib/sfdpgen/sfdpinit.c b/lib/sfdpgen/sfdpinit.c index c36d5cdff..71a28f0e1 100644 --- a/lib/sfdpgen/sfdpinit.c +++ b/lib/sfdpgen/sfdpinit.c @@ -57,10 +57,10 @@ static void sfdp_init_graph(Agraph_t * g) /* getPos: */ -static real *getPos(Agraph_t * g) +static double *getPos(Agraph_t * g) { Agnode_t *n; - real *pos = N_NEW(Ndim * agnnodes(g), real); + double *pos = N_NEW(Ndim * agnnodes(g), double); int ix, i; if (agfindnodeattr(g, "pos") == NULL) @@ -81,8 +81,8 @@ static real *getPos(Agraph_t * g) static void sfdpLayout(graph_t * g, spring_electrical_control ctrl, int hops, pointf pad) { - real *sizes; - real *pos; + double *sizes; + double *pos; Agnode_t *n; int flag, i; int n_edge_label_nodes = 0, *edge_label_nodes = NULL; @@ -114,7 +114,7 @@ static void sfdpLayout(graph_t * g, spring_electrical_control ctrl, break; case METHOD_STRESS:{ int maxit = 200; - real tol = 0.001; + double tol = 0.001; int weighted = TRUE; if (!D){ @@ -141,7 +141,7 @@ static void sfdpLayout(graph_t * g, spring_electrical_control ctrl, } for (n = agfstnode(g); n; n = agnxtnode(g, n)) { - real *npos = pos + (Ndim * ND_id(n)); + double *npos = pos + (Ndim * ND_id(n)); for (i = 0; i < Ndim; i++) { ND_pos(n)[i] = npos[i]; } diff --git a/lib/sfdpgen/sparse_solve.c b/lib/sfdpgen/sparse_solve.c index 274eaa244..d98da8186 100644 --- a/lib/sfdpgen/sparse_solve.c +++ b/lib/sfdpgen/sparse_solve.c @@ -22,15 +22,15 @@ /* #define DEBUG_PRINT */ struct uniform_stress_matmul_data{ - real alpha; + double alpha; SparseMatrix A; }; -static real *Operator_uniform_stress_matmul_apply(Operator o, real *x, real *y){ +static double *Operator_uniform_stress_matmul_apply(Operator o, double *x, double *y){ struct uniform_stress_matmul_data *d = (struct uniform_stress_matmul_data*) (o->data); SparseMatrix A = d->A; - real alpha = d->alpha; - real xsum = 0.; + double alpha = d->alpha; + double xsum = 0.; int m = A->m, i; SparseMatrix_multiply_vector(A, x, &y, FALSE); @@ -45,7 +45,7 @@ static real *Operator_uniform_stress_matmul_apply(Operator o, real *x, real *y){ -Operator Operator_uniform_stress_matmul(SparseMatrix A, real alpha){ +Operator Operator_uniform_stress_matmul(SparseMatrix A, double alpha){ Operator o; struct uniform_stress_matmul_data *d; @@ -58,7 +58,7 @@ Operator Operator_uniform_stress_matmul(SparseMatrix A, real alpha){ } -static real *Operator_matmul_apply(Operator o, real *x, real *y){ +static double *Operator_matmul_apply(Operator o, double *x, double *y){ SparseMatrix A = (SparseMatrix) o->data; SparseMatrix_multiply_vector(A, x, &y, FALSE); return y; @@ -79,9 +79,9 @@ static void Operator_matmul_delete(Operator o){ } -static real* Operator_diag_precon_apply(Operator o, real *x, real *y){ +static double* Operator_diag_precon_apply(Operator o, double *x, double *y){ int i, m; - real *diag = (real*) o->data; + double *diag = (double*) o->data; m = (int) diag[0]; diag++; for (i = 0; i < m; i++) y[i] = x[i]*diag[i]; @@ -89,19 +89,19 @@ static real* Operator_diag_precon_apply(Operator o, real *x, real *y){ } -Operator Operator_uniform_stress_diag_precon_new(SparseMatrix A, real alpha){ +Operator Operator_uniform_stress_diag_precon_new(SparseMatrix A, double alpha){ Operator o; - real *diag; + double *diag; int i, j, m = A->m, *ia = A->ia, *ja = A->ja; - real *a = (real*) A->a; + double *a = (double*) A->a; assert(A->type == MATRIX_TYPE_REAL); assert(a); o = MALLOC(sizeof(struct Operator_struct)); - o->data = MALLOC(sizeof(real)*(m + 1)); - diag = (real*) o->data; + o->data = MALLOC(sizeof(double)*(m + 1)); + diag = (double*) o->data; diag[0] = m; diag++; @@ -120,17 +120,17 @@ Operator Operator_uniform_stress_diag_precon_new(SparseMatrix A, real alpha){ static Operator Operator_diag_precon_new(SparseMatrix A){ Operator o; - real *diag; + double *diag; int i, j, m = A->m, *ia = A->ia, *ja = A->ja; - real *a = (real*) A->a; + double *a = (double*) A->a; assert(A->type == MATRIX_TYPE_REAL); assert(a); o = N_GNEW(1,struct Operator_struct); - o->data = N_GNEW((A->m + 1),real); - diag = (real*) o->data; + o->data = N_GNEW((A->m + 1),double); + diag = (double*) o->data; diag[0] = m; diag++; @@ -151,17 +151,17 @@ static void Operator_diag_precon_delete(Operator o){ free(o); } -static real conjugate_gradient(Operator A, Operator precon, int n, real *x, real *rhs, real tol, int maxit){ - real *z, *r, *p, *q, res = 10*tol, alpha; - real rho = 1.0e20, rho_old = 1, res0, beta; - real* (*Ax)(Operator o, real *in, real *out) = A->Operator_apply; - real* (*Minvx)(Operator o, real *in, real *out) = precon->Operator_apply; +static double conjugate_gradient(Operator A, Operator precon, int n, double *x, double *rhs, double tol, int maxit){ + double *z, *r, *p, *q, res = 10*tol, alpha; + double rho = 1.0e20, rho_old = 1, res0, beta; + double* (*Ax)(Operator o, double *in, double *out) = A->Operator_apply; + double* (*Minvx)(Operator o, double *in, double *out) = precon->Operator_apply; int iter = 0; - z = N_GNEW(n,real); - r = N_GNEW(n,real); - p = N_GNEW(n,real); - q = N_GNEW(n,real); + z = N_GNEW(n,double); + r = N_GNEW(n,double); + p = N_GNEW(n,double); + q = N_GNEW(n,double); r = Ax(A, x, r); r = vector_subtract_to(n, rhs, r); @@ -181,7 +181,7 @@ static real conjugate_gradient(Operator A, Operator precon, int n, real *x, real beta = rho/rho_old; p = vector_saxpy(n, z, p, beta); } else { - memcpy(p, z, sizeof(real)*n); + memcpy(p, z, sizeof(double)*n); } q = Ax(A, p, q); @@ -216,11 +216,11 @@ static real conjugate_gradient(Operator A, Operator precon, int n, real *x, real return res; } -real cg(Operator Ax, Operator precond, int n, int dim, real *x0, real *rhs, real tol, int maxit){ - real *x, *b, res = 0; +double cg(Operator Ax, Operator precond, int n, int dim, double *x0, double *rhs, double tol, int maxit){ + double *x, *b, res = 0; int k, i; - x = N_GNEW(n, real); - b = N_GNEW(n, real); + x = N_GNEW(n, double); + b = N_GNEW(n, double); for (k = 0; k < dim; k++){ for (i = 0; i < n; i++) { x[i] = x0[i*dim+k]; @@ -237,15 +237,15 @@ real cg(Operator Ax, Operator precond, int n, int dim, real *x0, real *rhs, real return res; } -static real* jacobi(SparseMatrix A, int dim, real *x0, real *rhs, int maxit, int *flag){ +static double* jacobi(SparseMatrix A, int dim, double *x0, double *rhs, int maxit, int *flag){ /* maxit iteration of jacobi */ - real *x, *y, *b, sum, diag, *a; + double *x, *y, *b, sum, diag, *a; int k, i, j, n = A->n, *ia, *ja, iter; - x = MALLOC(sizeof(real)*n); - y = MALLOC(sizeof(real)*n); - b = MALLOC(sizeof(real)*n); + x = MALLOC(sizeof(double)*n); + y = MALLOC(sizeof(double)*n); + b = MALLOC(sizeof(double)*n); assert(A->type == MATRIX_TYPE_REAL); - ia = A->ia; ja = A->ja; a = (real*) A->a; + ia = A->ia; ja = A->ja; a = (double*) A->a; for (k = 0; k < dim; k++){ for (i = 0; i < n; i++) { @@ -268,7 +268,7 @@ static real* jacobi(SparseMatrix A, int dim, real *x0, real *rhs, int maxit, int y[i] = (b[i] - sum)/diag; } - memcpy(x, y, sizeof(real)*n); + memcpy(x, y, sizeof(double)*n); } for (i = 0; i < n; i++) { @@ -283,10 +283,10 @@ static real* jacobi(SparseMatrix A, int dim, real *x0, real *rhs, int maxit, int return rhs; } -real SparseMatrix_solve(SparseMatrix A, int dim, real *x0, real *rhs, real tol, int maxit, int method, int *flag){ +double SparseMatrix_solve(SparseMatrix A, int dim, double *x0, double *rhs, double tol, int maxit, int method, int *flag){ Operator Ax, precond; int n = A->m; - real res = 0; + double res = 0; *flag = 0; switch (method){ diff --git a/lib/sfdpgen/sparse_solve.h b/lib/sfdpgen/sparse_solve.h index 8f6ba8258..69e743645 100644 --- a/lib/sfdpgen/sparse_solve.h +++ b/lib/sfdpgen/sparse_solve.h @@ -18,13 +18,13 @@ typedef struct Operator_struct *Operator; struct Operator_struct { void *data; - real* (*Operator_apply)(Operator o, real *in, real *out); + double* (*Operator_apply)(Operator o, double *in, double *out); }; -real cg(Operator Ax, Operator precond, int n, int dim, real *x0, real *rhs, real tol, int maxit); +double cg(Operator Ax, Operator precond, int n, int dim, double *x0, double *rhs, double tol, int maxit); -real SparseMatrix_solve(SparseMatrix A, int dim, real *x0, real *rhs, real tol, int maxit, int method, int *flag); +double SparseMatrix_solve(SparseMatrix A, int dim, double *x0, double *rhs, double tol, int maxit, int method, int *flag); -Operator Operator_uniform_stress_matmul(SparseMatrix A, real alpha); +Operator Operator_uniform_stress_matmul(SparseMatrix A, double alpha); -Operator Operator_uniform_stress_diag_precon_new(SparseMatrix A, real alpha); +Operator Operator_uniform_stress_diag_precon_new(SparseMatrix A, double alpha); diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index 14de37bc6..14d6a56aa 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -115,7 +115,7 @@ oned_optimizer oned_optimizer_new(int i){ return opt; } -void oned_optimizer_train(oned_optimizer opt, real work){ +void oned_optimizer_train(oned_optimizer opt, double work){ int i = opt->i; assert(i >= 0); @@ -158,8 +158,8 @@ int oned_optimizer_get(oned_optimizer opt){ } -real average_edge_length(SparseMatrix A, int dim, real *coord){ - real dist = 0, d; +double average_edge_length(SparseMatrix A, int dim, double *coord){ + double dist = 0, d; int *ia = A->ia, *ja = A->ja, i, j, k; assert(SparseMatrix_is_symmetric(A, TRUE)); @@ -177,7 +177,7 @@ real average_edge_length(SparseMatrix A, int dim, real *coord){ } #ifdef ENERGY -static real spring_electrical_energy(int dim, SparseMatrix A, real *x, real p, real CRK, real KP){ +static double spring_electrical_energy(int dim, SparseMatrix A, double *x, double p, double CRK, double 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) which should equal to -force (force = -gradient), hence energy for force ||x-y||^m (y-x) is ||x-y||^(m+2)*2/(m+2) where m != 2 @@ -186,7 +186,7 @@ static real spring_electrical_energy(int dim, SparseMatrix A, real *x, real p, r */ int i, j, k, *ia = A->ia, *ja = A->ja, n = A->m; - real energy = 0, dist; + double energy = 0, dist; for (i = 0; i < n; i++){ /* attractive force C^((2-p)/3) ||x_i-x_j||/K * (x_j - x_i) */ @@ -214,10 +214,10 @@ static real spring_electrical_energy(int dim, SparseMatrix A, real *x, real p, r #endif -void export_embedding(FILE *fp, int dim, SparseMatrix A, real *x, real *width){ +void export_embedding(FILE *fp, int dim, SparseMatrix A, double *x, double *width){ int i, j, k, *ia=A->ia, *ja = A->ja; int ne = 0; - real xsize, ysize, xmin, xmax, ymin, ymax; + double xsize, ysize, xmin, xmax, ymin, ymax; xmax = xmin = x[0]; ymax = ymin = x[1]; @@ -297,7 +297,7 @@ void export_embedding(FILE *fp, int dim, SparseMatrix A, real *x, real *width){ } -static real update_step(int adaptive_cooling, real step, real Fnorm, real Fnorm0, real cool){ +static double update_step(int adaptive_cooling, double step, double Fnorm, double Fnorm0, double cool){ if (!adaptive_cooling) { return cool*step; @@ -315,10 +315,10 @@ static real update_step(int adaptive_cooling, real step, real Fnorm, real Fnorm0 #define node_degree(i) (ia[(i)+1] - ia[(i)]) -static void check_real_array_size(real **a, int len, int *lenmax){ +static void check_real_array_size(double **a, int len, int *lenmax){ if (len >= *lenmax){ *lenmax = len + MAX((int) 0.2*len, 10); - *a = REALLOC(*a, sizeof(real)*(*lenmax)); + *a = REALLOC(*a, sizeof(double)*(*lenmax)); } } @@ -330,11 +330,11 @@ static void check_int_array_size(int **a, int len, int *lenmax){ } -static real get_angle(real *x, int dim, int i, int j){ +static double get_angle(double *x, int dim, int i, int j){ /* between [0, 2Pi)*/ int k; - real y[2], res; - real eps = 0.00001; + double y[2], res; + double eps = 0.00001; for (k = 0; k < 2; k++){ y[k] = x[j*dim+k] - x[i*dim+k]; } @@ -352,8 +352,8 @@ static real get_angle(real *x, int dim, int i, int j){ } static int comp_real(const void *x, const void *y){ - const real *xx = (const real*) x; - const real *yy = (const real*) y; + const double *xx = (const double*) x; + const double *yy = (const double*) y; if (*xx > *yy){ return 1; @@ -362,28 +362,28 @@ static int comp_real(const void *x, const void *y){ } return 0; } -static void sort_real(int n, real *a){ - qsort(a, n, sizeof(real), comp_real); +static void sort_real(int n, double *a){ + qsort(a, n, sizeof(double), comp_real); } -static void set_leaves(real *x, int dim, real dist, real ang, int i, int j){ +static void set_leaves(double *x, int dim, double dist, double ang, int i, int j){ x[dim*j] = cos(ang)*dist + x[dim*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, double *x){ int m = A->m, i, j, *ia = A->ia, *ja = A->ja, k; int p; - real dist; + double dist; int nleaves, nleaves_max = 10; - real *angles, maxang, ang1 = 0, ang2 = 0, pad, step; + double *angles, maxang, ang1 = 0, ang2 = 0, pad, step; int *leaves, nangles_max = 10, nangles; assert(!SparseMatrix_has_diagonal(A)); bool *checked = gcalloc(sizeof(bool), m); - angles = MALLOC(sizeof(real)*nangles_max); + angles = MALLOC(sizeof(double)*nangles_max); leaves = MALLOC(sizeof(int)*nleaves_max); @@ -445,7 +445,7 @@ ang1 = 0; ang2 = 2*PI; maxang = 2*PI; free(leaves); } -void force_print(FILE *fp, int n, int dim, real *x, real *force){ +void force_print(FILE *fp, int n, int dim, double *x, double *force){ int i, k; fprintf(fp,"Graphics[{"); @@ -482,23 +482,23 @@ void force_print(FILE *fp, int n, int dim, real *x, real *force){ } -void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrical_control ctrl, real *node_weights, real *x, int *flag){ +void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrical_control ctrl, double *node_weights, double *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. */ SparseMatrix A = A0; int m, n; int i, j, k; - real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; + double p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; int *ia = NULL, *ja = NULL; - real *xold = NULL; - real *f = NULL, dist, F, Fnorm = 0, Fnorm0; + double *xold = NULL; + double *f = NULL, dist, F, Fnorm = 0, Fnorm0; int iter = 0; int adaptive_cooling = ctrl->adaptive_cooling; QuadTree qt = NULL; - real counts[4], *force = NULL; + double counts[4], *force = NULL; #ifdef TIME clock_t start, end, start0; - real qtree_cpu = 0, qtree_cpu0 = 0, qtree_new_cpu = 0, qtree_new_cpu0 = 0; - real total_cpu = 0; + double qtree_cpu = 0, qtree_cpu0 = 0, qtree_new_cpu = 0, qtree_new_cpu0 = 0; + double total_cpu = 0; start0 = clock(); #endif int max_qtree_level = ctrl->max_qtree_level; @@ -533,8 +533,8 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica KP = pow(K, 1 - p); CRK = pow(C, (2.-p)/3.)/K; - xold = MALLOC(sizeof(real)*dim*n); - force = MALLOC(sizeof(real)*dim*n); + xold = MALLOC(sizeof(double)*dim*n); + force = MALLOC(sizeof(double)*dim*n); do { #ifdef TIME @@ -542,7 +542,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica #endif iter++; - memcpy(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(double)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; @@ -558,7 +558,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica } #ifdef TIME - qtree_new_cpu += ((real) (clock() - start))/CLOCKS_PER_SEC; + qtree_new_cpu += ((double) (clock() - start))/CLOCKS_PER_SEC; #endif /* repulsive force */ @@ -572,7 +572,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica #ifdef TIME end = clock(); - qtree_cpu += ((real) (end - start)) / CLOCKS_PER_SEC; + qtree_cpu += ((double) (end - start)) / CLOCKS_PER_SEC; #endif /* attractive force C^((2-p)/3) ||x_i-x_j||/K * (x_j - x_i) */ @@ -608,15 +608,15 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica QuadTree_delete(qt); #ifdef TIME end = clock(); - qtree_new_cpu += ((real) (end - start)) / CLOCKS_PER_SEC; + qtree_new_cpu += ((double) (end - start)) / CLOCKS_PER_SEC; #endif #ifdef TIME qtree_cpu0 = qtree_cpu - qtree_cpu0; qtree_new_cpu0 = qtree_new_cpu - qtree_new_cpu0; /* if (Verbose) fprintf(stderr, "\r iter=%d cpu=%.2f, quadtree=%.2f quad_force=%.2f other=%.2f counts={%.2f,%.2f,%.2f} step=%f Fnorm=%f nz=%d K=%f qtree_lev = %d", - iter, ((real) (clock() - start2)) / CLOCKS_PER_SEC, qtree_new_cpu0, - qtree_cpu0,((real) (clock() - start2))/CLOCKS_PER_SEC - qtree_cpu0 - qtree_new_cpu0, + iter, ((double) (clock() - start2)) / CLOCKS_PER_SEC, qtree_new_cpu0, + qtree_cpu0,((double) (clock() - start2))/CLOCKS_PER_SEC - qtree_cpu0 - qtree_new_cpu0, counts[0], counts[1], counts[2], step, Fnorm, A->nz,K,max_qtree_level); */ @@ -650,7 +650,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica if (ctrl->beautify_leaves) beautify_leaves(dim, A, x); #ifdef TIME - total_cpu += ((real) (clock() - start0)) / CLOCKS_PER_SEC; + total_cpu += ((double) (clock() - start0)) / CLOCKS_PER_SEC; if (Verbose) fprintf(stderr, "\n time for qtree = %f, qtree_force = %f, total cpu = %f\n",qtree_new_cpu, qtree_cpu, total_cpu); #endif @@ -664,27 +664,27 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica free(force); } -static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_electrical_control ctrl, real *node_weights, real *x, int *flag){ +static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_electrical_control ctrl, double *node_weights, double *x, int *flag){ /* a version that does vertex moves in one go, instead of one at a time, use for debugging the fast version. Quadtree is not used. */ /* 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; int m, n; int i, j, k; - real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; + double p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; int *ia = NULL, *ja = NULL; - real *xold = NULL; - real *f = NULL, dist, F, Fnorm = 0, Fnorm0; + double *xold = NULL; + double *f = NULL, dist, F, Fnorm = 0, Fnorm0; int iter = 0; int adaptive_cooling = ctrl->adaptive_cooling; QuadTree qt = NULL; int USE_QT = FALSE; int nsuper = 0, nsupermax = 10; - real *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0, counts_avg = 0; - real *force; + double *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0, counts_avg = 0; + double *force; #ifdef TIME clock_t start, end, start0, start2; - real qtree_cpu = 0, qtree_cpu0 = 0; - real total_cpu = 0; + double qtree_cpu = 0, qtree_cpu0 = 0; + double total_cpu = 0; start0 = clock(); #endif int max_qtree_level = ctrl->max_qtree_level; @@ -695,14 +695,14 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el m = A->m, n = A->n; if (n <= 0 || dim <= 0) return; - force = MALLOC(sizeof(real)*n*dim); + force = MALLOC(sizeof(double)*n*dim); if (n >= ctrl->quadtree_size) { USE_QT = TRUE; qtree_level_optimizer = oned_optimizer_new(max_qtree_level); - center = MALLOC(sizeof(real)*nsupermax*dim); - supernode_wgts = MALLOC(sizeof(real)*nsupermax); - distances = MALLOC(sizeof(real)*nsupermax); + center = MALLOC(sizeof(double)*nsupermax*dim); + supernode_wgts = MALLOC(sizeof(double)*nsupermax); + distances = MALLOC(sizeof(double)*nsupermax); } USE_QT = FALSE; *flag = 0; @@ -739,13 +739,13 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el } #endif - f = MALLOC(sizeof(real)*dim); - xold = MALLOC(sizeof(real)*dim*n); + f = MALLOC(sizeof(double)*dim); + xold = MALLOC(sizeof(double)*dim*n); do { for (i = 0; i < dim*n; i++) force[i] = 0; iter++; - memcpy(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(double)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; @@ -774,7 +774,7 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el ¢er, &supernode_wgts, &distances, &counts, flag); #ifdef TIME end = clock(); - qtree_cpu += ((real) (end - start)) / CLOCKS_PER_SEC; + qtree_cpu += ((double) (end - start)) / CLOCKS_PER_SEC; #endif counts_avg += counts; nsuper_avg += nsuper; @@ -845,7 +845,7 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el counts_avg /= n; #ifdef TIME qtree_cpu0 = qtree_cpu - qtree_cpu0; - if (Verbose && 0) fprintf(stderr, "\n cpu this outer iter = %f, quadtree time = %f other time = %f\n",((real) (clock() - start2)) / CLOCKS_PER_SEC, qtree_cpu0,((real) (clock() - start2))/CLOCKS_PER_SEC - qtree_cpu0); + if (Verbose && 0) fprintf(stderr, "\n cpu this outer iter = %f, quadtree time = %f other time = %f\n",((double) (clock() - start2)) / CLOCKS_PER_SEC, qtree_cpu0,((double) (clock() - start2))/CLOCKS_PER_SEC - qtree_cpu0); qtree_cpu0 = qtree_cpu; #endif if (Verbose && 0) fprintf(stderr, "nsuper_avg=%f, counts_avg = %f 2*nsuper+counts=%f\n",nsuper_avg,counts_avg, 2*nsuper_avg+counts_avg); @@ -893,7 +893,7 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el if (ctrl->beautify_leaves) beautify_leaves(dim, A, x); #ifdef TIME - total_cpu += ((real) (clock() - start0)) / CLOCKS_PER_SEC; + total_cpu += ((double) (clock() - start0)) / CLOCKS_PER_SEC; if (Verbose) fprintf(stderr, "time for supernode = %f, total cpu = %f\n",qtree_cpu, total_cpu); #endif @@ -913,25 +913,25 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el -void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_control ctrl, real *node_weights, real *x, int *flag){ +void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_control ctrl, double *node_weights, double *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. */ SparseMatrix A = A0; int m, n; int i, j, k; - real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; + double p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; int *ia = NULL, *ja = NULL; - real *xold = NULL; - real *f = NULL, dist, F, Fnorm = 0, Fnorm0; + double *xold = NULL; + double *f = NULL, dist, F, Fnorm = 0, Fnorm0; int iter = 0; int adaptive_cooling = ctrl->adaptive_cooling; QuadTree qt = NULL; int USE_QT = FALSE; int nsuper = 0, nsupermax = 10; - real *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0, counts_avg = 0; + double *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0, counts_avg = 0; #ifdef TIME clock_t start, end, start0, start2; - real qtree_cpu = 0, qtree_cpu0 = 0; - real total_cpu = 0; + double qtree_cpu = 0, qtree_cpu0 = 0; + double total_cpu = 0; start0 = clock(); #endif int max_qtree_level = ctrl->max_qtree_level; @@ -945,9 +945,9 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con if (n >= ctrl->quadtree_size) { USE_QT = TRUE; qtree_level_optimizer = oned_optimizer_new(max_qtree_level); - center = MALLOC(sizeof(real)*nsupermax*dim); - supernode_wgts = MALLOC(sizeof(real)*nsupermax); - distances = MALLOC(sizeof(real)*nsupermax); + center = MALLOC(sizeof(double)*nsupermax*dim); + supernode_wgts = MALLOC(sizeof(double)*nsupermax); + distances = MALLOC(sizeof(double)*nsupermax); } *flag = 0; if (m != n) { @@ -983,8 +983,8 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con } #endif - f = MALLOC(sizeof(real)*dim); - xold = MALLOC(sizeof(real)*dim*n); + f = MALLOC(sizeof(double)*dim); + xold = MALLOC(sizeof(double)*dim*n); do { //#define VIS_MULTILEVEL @@ -1001,7 +1001,7 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con #endif iter++; - memcpy(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(double)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; @@ -1043,7 +1043,7 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con #ifdef TIME end = clock(); - qtree_cpu += ((real) (end - start)) / CLOCKS_PER_SEC; + qtree_cpu += ((double) (end - start)) / CLOCKS_PER_SEC; #endif counts_avg += counts; nsuper_avg += nsuper; @@ -1092,7 +1092,7 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con counts_avg /= n; #ifdef TIME qtree_cpu0 = qtree_cpu - qtree_cpu0; - if (Verbose && 0) fprintf(stderr, "\n cpu this outer iter = %f, quadtree time = %f other time = %f\n",((real) (clock() - start2)) / CLOCKS_PER_SEC, qtree_cpu0,((real) (clock() - start2))/CLOCKS_PER_SEC - qtree_cpu0); + if (Verbose && 0) fprintf(stderr, "\n cpu this outer iter = %f, quadtree time = %f other time = %f\n",((double) (clock() - start2)) / CLOCKS_PER_SEC, qtree_cpu0,((double) (clock() - start2))/CLOCKS_PER_SEC - qtree_cpu0); qtree_cpu0 = qtree_cpu; #endif if (Verbose & 0) fprintf(stderr, "nsuper_avg=%f, counts_avg = %f 2*nsuper+counts=%f\n",nsuper_avg,counts_avg, 2*nsuper_avg+counts_avg); @@ -1140,7 +1140,7 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con if (ctrl->beautify_leaves) beautify_leaves(dim, A, x); #ifdef TIME - total_cpu += ((real) (clock() - start0)) / CLOCKS_PER_SEC; + total_cpu += ((double) (clock() - start0)) / CLOCKS_PER_SEC; if (Verbose) fprintf(stderr, "time for supernode = %f, total cpu = %f\n",qtree_cpu, total_cpu); #endif @@ -1157,9 +1157,9 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con free(distances); } -static void scale_coord(int n, int dim, real *x, int *id, int *jd, real *d, real dj){ +static void scale_coord(int n, int dim, double *x, int *id, int *jd, double *d, double dj){ int i, j, k; - real w_ij, dist, s = 0, stop = 0, sbot = 0., nz = 0; + double w_ij, dist, s = 0, stop = 0, sbot = 0., nz = 0; if (dj == 0.) return; for (i = 0; i < n; i++){ @@ -1184,8 +1184,8 @@ static void scale_coord(int n, int dim, real *x, int *id, int *jd, real *d, real fprintf(stderr,"scaling factor = %f\n",s); } -static real dmean_get(int n, int *id, real* d){ - real dmean = 0; +static double dmean_get(int n, int *id, double* d){ + double dmean = 0; int i, j; if (!d) return 1.; @@ -1194,10 +1194,10 @@ static real dmean_get(int n, int *id, real* d){ dmean += d[j]; } } - return dmean/((real) id[n]); + return dmean/((double) id[n]); } -static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_electrical_control ctrl, real *node_weights, real *x, real rho, int *flag){ +static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_electrical_control ctrl, double *node_weights, double *x, double rho, 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. Minimize \Sum_{(i,j)\in E} w_ij (||x_i-x_j||-d_ij)^2 - \rho \Sum_{(i,j)\NotIn E} Log ||x_i-x_j|| @@ -1220,18 +1220,18 @@ static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, sp SparseMatrix A = A0; int m, n; int i, j, k; - real p = ctrl->p, C = ctrl->C, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, w_ij, dj = 1.; + double p = ctrl->p, C = ctrl->C, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, w_ij, dj = 1.; int *ia = NULL, *ja = NULL; int *id = NULL, *jd = NULL; - real *d, dmean; - real *xold = NULL; - real *f = NULL, dist, F, Fnorm = 0, Fnorm0; + double *d, dmean; + double *xold = NULL; + double *f = NULL, dist, F, Fnorm = 0, Fnorm0; int iter = 0; int adaptive_cooling = ctrl->adaptive_cooling; QuadTree qt = NULL; int USE_QT = FALSE; int nsuper = 0, nsupermax = 10; - real *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0; + double *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0; int max_qtree_level = 10; #ifdef DEBUG double stress = 0; @@ -1243,9 +1243,9 @@ static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, sp if (ctrl->tscheme != QUAD_TREE_NONE && n >= ctrl->quadtree_size) { USE_QT = TRUE; - center = MALLOC(sizeof(real)*nsupermax*dim); - supernode_wgts = MALLOC(sizeof(real)*nsupermax); - distances = MALLOC(sizeof(real)*nsupermax); + center = MALLOC(sizeof(double)*nsupermax*dim); + supernode_wgts = MALLOC(sizeof(double)*nsupermax); + distances = MALLOC(sizeof(double)*nsupermax); } *flag = 0; @@ -1262,13 +1262,13 @@ static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, sp if (D){ id = D->ia; jd = D->ja; - d = (real*) D->a; + d = (double*) D->a; } else { id = ia; jd = ja; d = NULL; } if (rho < 0) { dmean = dmean_get(n, id, d); - rho = rho*(id[n]/((((real) n)*((real) n)) - id[n]))/pow(dmean, p+1); + rho = rho*(id[n]/((((double) n)*((double) n)) - id[n]))/pow(dmean, p+1); fprintf(stderr,"dmean = %f, rho = %f\n",dmean, rho); } @@ -1302,11 +1302,11 @@ static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, sp } #endif - f = MALLOC(sizeof(real)*dim); - xold = MALLOC(sizeof(real)*dim*n); + f = MALLOC(sizeof(double)*dim); + xold = MALLOC(sizeof(double)*dim*n); do { iter++; - memcpy(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(double)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; @@ -1441,25 +1441,25 @@ static void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, sp -void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_electrical_control ctrl, real *node_weights, real *x, int *flag){ +void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_electrical_control ctrl, double *node_weights, double *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; int m, n; int i, j, k; - real p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; + double p = ctrl->p, K = ctrl->K, C = ctrl->C, CRK, tol = ctrl->tol, maxiter = ctrl->maxiter, cool = ctrl->cool, step = ctrl->step, KP; int *ia = NULL, *ja = NULL; int *id = NULL, *jd = NULL; - real *d; - real *xold = NULL; - real *f = NULL, dist, F, Fnorm = 0, Fnorm0; + double *d; + double *xold = NULL; + double *f = NULL, dist, F, Fnorm = 0, Fnorm0; int iter = 0; int adaptive_cooling = ctrl->adaptive_cooling; QuadTree qt = NULL; int USE_QT = FALSE; int nsuper = 0, nsupermax = 10; - real *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0; + double *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0; int max_qtree_level = 10; if (!A || maxiter <= 0) return; @@ -1468,9 +1468,9 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D if (n >= ctrl->quadtree_size) { USE_QT = TRUE; - center = MALLOC(sizeof(real)*nsupermax*dim); - supernode_wgts = MALLOC(sizeof(real)*nsupermax); - distances = MALLOC(sizeof(real)*nsupermax); + center = MALLOC(sizeof(double)*nsupermax*dim); + supernode_wgts = MALLOC(sizeof(double)*nsupermax); + distances = MALLOC(sizeof(double)*nsupermax); } *flag = 0; if (m != n) { @@ -1483,7 +1483,7 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D ja = A->ja; id = D->ia; jd = D->ja; - d = (real*) D->a; + d = (double*) D->a; if (ctrl->random_start){ srand(ctrl->random_seed); @@ -1509,11 +1509,11 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D } #endif - f = MALLOC(sizeof(real)*dim); - xold = MALLOC(sizeof(real)*dim*n); + f = MALLOC(sizeof(double)*dim); + xold = MALLOC(sizeof(double)*dim*n); do { iter++; - memcpy(xold, x, sizeof(real)*dim*n); + memcpy(xold, x, sizeof(double)*dim*n); Fnorm0 = Fnorm; Fnorm = 0.; nsuper_avg = 0; @@ -1639,7 +1639,7 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D -void print_matrix(real *x, int n, int dim){ +void print_matrix(double *x, int n, int dim){ int i, k; printf("{"); for (i = 0; i < n; i++){ @@ -1654,11 +1654,11 @@ void print_matrix(real *x, int n, int dim){ printf("}\n"); } -void interpolate_coord(int dim, SparseMatrix A, real *x){ +void interpolate_coord(int dim, SparseMatrix A, double *x){ int i, j, k, *ia = A->ia, *ja = A->ja, nz; - real alpha = 0.5, beta, *y; + double alpha = 0.5, beta, *y; - y = MALLOC(sizeof(real)*dim); + y = MALLOC(sizeof(double)*dim); for (i = 0; i < A->m; i++){ for (k = 0; k < dim; k++) y[k] = 0; nz = 0; @@ -1677,7 +1677,7 @@ void interpolate_coord(int dim, SparseMatrix A, real *x){ free(y); } -static void prolongate(int dim, SparseMatrix A, SparseMatrix P, SparseMatrix R, real *x, real *y, int coarsen_scheme_used, real delta){ +static void prolongate(int dim, SparseMatrix A, SparseMatrix P, SparseMatrix R, double *x, double *y, int coarsen_scheme_used, double delta){ int nc, *ia, *ja, i, j, k; SparseMatrix_multiply_dense(P, x, &y, dim); @@ -1723,9 +1723,9 @@ int power_law_graph(SparseMatrix A){ return res; } -void pcp_rotate(int n, int dim, real *x){ +void pcp_rotate(int n, int dim, double *x){ int i, k,l; - real y[4], axis[2], center[2], dist, x0, x1; + double y[4], axis[2], center[2], dist, x0, x1; assert(dim == 2); for (i = 0; i < dim*dim; i++) y[i] = 0; @@ -1775,10 +1775,10 @@ void pcp_rotate(int n, int dim, real *x){ } -static void rotate(int n, int dim, real *x, real angle){ +static void rotate(int n, int dim, double *x, double angle){ int i, k; - real axis[2], center[2], x0, x1; - real radian = 3.14159/180; + double axis[2], center[2], x0, x1; + double radian = 3.14159/180; assert(dim == 2); for (i = 0; i < dim; i++) center[i] = 0; @@ -1805,11 +1805,11 @@ static void rotate(int n, int dim, real *x, real angle){ } -static void attach_edge_label_coordinates(int dim, SparseMatrix A, int n_edge_label_nodes, int *edge_label_nodes, real *x, real *x2){ +static void attach_edge_label_coordinates(int dim, SparseMatrix A, int n_edge_label_nodes, int *edge_label_nodes, double *x, double *x2){ int *mask; int i, ii, j, k; int nnodes = 0; - real len; + double len; mask = MALLOC(sizeof(int)*A->m); @@ -1911,7 +1911,7 @@ static SparseMatrix shorting_edge_label_nodes(SparseMatrix A, int n_edge_label_n } } - B = SparseMatrix_from_coordinate_arrays(nz, id, id, irn, jcn, NULL, MATRIX_TYPE_PATTERN, sizeof(real)); + B = SparseMatrix_from_coordinate_arrays(nz, id, id, irn, jcn, NULL, MATRIX_TYPE_PATTERN, sizeof(double)); free(irn); free(jcn); @@ -1920,15 +1920,15 @@ static SparseMatrix shorting_edge_label_nodes(SparseMatrix A, int n_edge_label_n } -static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0, SparseMatrix D0, spring_electrical_control ctrl, real *node_weights, real *label_sizes, - real *x, int n_edge_label_nodes, int *edge_label_nodes, int *flag){ +static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0, SparseMatrix D0, spring_electrical_control ctrl, double *node_weights, double *label_sizes, + double *x, int n_edge_label_nodes, int *edge_label_nodes, int *flag){ Multilevel_control mctrl = NULL; int n, plg, coarsen_scheme_used; SparseMatrix A = A0, D = D0, P = NULL; Multilevel grid, grid0; - real *xc = NULL, *xf = NULL; + double *xc = NULL, *xf = NULL; struct spring_electrical_control_struct ctrl0; #ifdef TIME clock_t cpu; @@ -1966,7 +1966,7 @@ static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0 && n_edge_label_nodes > 0){ SparseMatrix A2; - real *x2 = MALLOC(sizeof(real)*(A->m)*dim); + double *x2 = MALLOC(sizeof(double)*(A->m)*dim); A2 = shorting_edge_label_nodes(A, n_edge_label_nodes, edge_label_nodes); multilevel_spring_electrical_embedding(dim, A2, NULL, ctrl, NULL, NULL, x2, 0, NULL, flag); @@ -1989,7 +1989,7 @@ static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0 if (Multilevel_is_finest(grid)){ xc = x; } else { - xc = MALLOC(sizeof(real)*grid->n*dim); + xc = MALLOC(sizeof(double)*grid->n*dim); } plg = power_law_graph(A); @@ -2057,7 +2057,7 @@ static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0 if (Multilevel_is_finest(grid)){ xf = x; } else { - xf = MALLOC(sizeof(real)*grid->n*dim); + xf = MALLOC(sizeof(double)*grid->n*dim); } prolongate(dim, grid->A, P, grid->R, xc, xf, coarsen_scheme_used, (ctrl->K)*0.001); free(xc); @@ -2075,7 +2075,7 @@ static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0 #ifdef TIME if (Verbose) - fprintf(stderr, "layout time %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC); + fprintf(stderr, "layout time %f\n",((double) (clock() - cpu)) / CLOCKS_PER_SEC); cpu = clock(); #endif @@ -2101,7 +2101,7 @@ static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0 Multilevel_delete(grid0); } -void multilevel_spring_electrical_embedding(int dim, SparseMatrix A, SparseMatrix D, spring_electrical_control ctrl, real *node_weights, real *label_sizes, - real *x, int n_edge_label_nodes, int *edge_label_nodes, int *flag){ +void multilevel_spring_electrical_embedding(int dim, SparseMatrix A, SparseMatrix D, spring_electrical_control ctrl, double *node_weights, double *label_sizes, + double *x, int n_edge_label_nodes, int *edge_label_nodes, int *flag){ multilevel_spring_electrical_embedding_core(dim, A, D, ctrl, node_weights, label_sizes, x, n_edge_label_nodes, edge_label_nodes, flag); } diff --git a/lib/sfdpgen/spring_electrical.h b/lib/sfdpgen/spring_electrical.h index 53aaca8a6..894dbf3b8 100644 --- a/lib/sfdpgen/spring_electrical.h +++ b/lib/sfdpgen/spring_electrical.h @@ -26,21 +26,21 @@ enum {QUAD_TREE_NONE = 0, QUAD_TREE_NORMAL, QUAD_TREE_FAST, QUAD_TREE_HYBRID}; enum {METHOD_STA = -1, METHOD_SPRING_ELECTRICAL, METHOD_SPRING_MAXENT, METHOD_STRESS_MAXENT, METHOD_STRESS_APPROX, METHOD_STRESS, METHOD_UNIFORM_STRESS, METHOD_FULL_STRESS, METHOD_NONE, METHOD_STO}; struct spring_electrical_control_struct { - real p;/*a negativve real number default to -1. repulsive force = dist^p */ - real q;/*a positive real number default to 2. attractive force = dist^q */ + double p;/*a negativve real number default to -1. repulsive force = dist^p */ + double q;/*a positive real number default to 2. attractive force = dist^q */ 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 */ - real C;/* another parameter. f_a(i,j) = C*dist(i,j)^2/K * d_ij, f_r(i,j) = K^(3-p)/dist(i,j)^(-p). By default C = 0.2. */ + double K;/* the natural distance. If K < 0, K will be set to the average distance of an edge */ + double C;/* another parameter. f_a(i,j) = C*dist(i,j)^2/K * d_ij, f_r(i,j) = K^(3-p)/dist(i,j)^(-p). By default C = 0.2. */ int multilevels;/* if <=1, single level */ int multilevel_coarsen_scheme;/* pass on to Multilevel_control->coarsen_scheme */ int multilevel_coarsen_mode;/* pass on to Multilevel_control->coarsen_mode */ int quadtree_size;/* cut off size above which quadtree approximation is used */ int max_qtree_level;/* max level of quadtree */ - real bh;/* Barnes-Hutt constant, if width(snode)/dist[i,snode] < bh, treat snode as a supernode. default 0.2*/ - real tol;/* minimum different between two subsequence config before terminating. ||x-xold|| < tol */ + double bh;/* Barnes-Hutt constant, if width(snode)/dist[i,snode] < bh, treat snode as a supernode. default 0.2*/ + double tol;/* minimum different between two subsequence config before terminating. ||x-xold|| < tol */ int maxiter; - real cool;/* default 0.9 */ - real step;/* initial step size */ + double cool;/* default 0.9 */ + double step;/* initial step size */ int adaptive_cooling; int random_seed; int beautify_leaves; @@ -50,11 +50,11 @@ struct spring_electrical_control_struct { int do_shrinking; int tscheme; /* octree scheme. 0 (no octree), 1 (normal), 2 (fast) */ int method;/* spring_electical, spring_maxent */ - real initial_scaling;/* how to scale the layout of the graph before passing to overlap removal algorithm. + double initial_scaling;/* how to scale the layout of the graph before passing to overlap removal algorithm. positive values are absolute in points, negative values are relative to average label size. */ - real rotation;/* degree of rotation */ + double rotation;/* degree of rotation */ int edge_labeling_scheme; /* specifying whether to treat node of the form |edgelabel|* as a special node representing an edge label. 0 (no action, default), 1 (penalty based method to make that kind of node close to the center of its neighbor), 1 (penalty based method to make that kind of node close to the old center of its neighbor), @@ -66,32 +66,32 @@ typedef struct spring_electrical_control_struct *spring_electrical_control; spring_electrical_control spring_electrical_control_new(void); void spring_electrical_control_print(spring_electrical_control ctrl); -void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_control ctrl, real *node_weights, real *x, int *flag); -void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrical_control ctrl, real *node_weights, real *x, int *flag); +void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_control ctrl, double *node_weights, double *x, int *flag); +void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrical_control ctrl, double *node_weights, double *x, int *flag); -void multilevel_spring_electrical_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_electrical_control ctrl, real *node_weights, real *label_sizes, - real *x, int n_edge_label_nodes, int *edge_label_nodes, int *flag); +void multilevel_spring_electrical_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_electrical_control ctrl, double *node_weights, double *label_sizes, + double *x, int n_edge_label_nodes, int *edge_label_nodes, int *flag); -void export_embedding(FILE *fp, int dim, SparseMatrix A, real *x, real *width); +void export_embedding(FILE *fp, int dim, SparseMatrix A, double *x, double *width); void spring_electrical_control_delete(spring_electrical_control ctrl); -void print_matrix(real *x, int n, int dim); +void print_matrix(double *x, int n, int dim); -real average_edge_length(SparseMatrix A, int dim, real *coord); +double average_edge_length(SparseMatrix A, int dim, double *coord); -void spring_electrical_spring_embedding(int dim, SparseMatrix A, SparseMatrix D, spring_electrical_control ctrl, real *node_weights, real *x, int *flag); -void force_print(FILE *fp, int n, int dim, real *x, real *force); +void spring_electrical_spring_embedding(int dim, SparseMatrix A, SparseMatrix D, spring_electrical_control ctrl, double *node_weights, double *x, int *flag); +void force_print(FILE *fp, int n, int dim, double *x, double *force); enum {MAX_I = 20, OPT_UP = 1, OPT_DOWN = -1, OPT_INIT = 0}; struct oned_optimizer_struct{ int i; - real work[MAX_I+1]; + double work[MAX_I+1]; int direction; }; typedef struct oned_optimizer_struct *oned_optimizer; void oned_optimizer_delete(oned_optimizer opt); oned_optimizer oned_optimizer_new(int i); -void oned_optimizer_train(oned_optimizer opt, real work); +void oned_optimizer_train(oned_optimizer opt, double work); int oned_optimizer_get(oned_optimizer opt); -void interpolate_coord(int dim, SparseMatrix A, real *x); +void interpolate_coord(int dim, SparseMatrix A, double *x); int power_law_graph(SparseMatrix A); -void pcp_rotate(int n, int dim, real *x); +void pcp_rotate(int n, int dim, double *x); diff --git a/lib/sfdpgen/stress_model.c b/lib/sfdpgen/stress_model.c index 70799a62f..93fb50ba8 100644 --- a/lib/sfdpgen/stress_model.c +++ b/lib/sfdpgen/stress_model.c @@ -4,10 +4,10 @@ #include #include -static void stress_model_core(int dim, SparseMatrix B, real **x, int edge_len_weighted, int maxit_sm, real tol, int *flag){ +static void stress_model_core(int dim, SparseMatrix B, double **x, int edge_len_weighted, int maxit_sm, double tol, int *flag){ int m; SparseStressMajorizationSmoother sm; - real lambda = 0; + double lambda = 0; int i; SparseMatrix A = B; @@ -24,7 +24,7 @@ static void stress_model_core(int dim, SparseMatrix B, real **x, int edge_len_we *flag = 0; m = A->m; if (!x) { - *x = MALLOC(sizeof(real)*m*dim); + *x = MALLOC(sizeof(double)*m*dim); srand(123); for (i = 0; i < dim*m; i++) (*x)[i] = drand(); } @@ -53,6 +53,6 @@ static void stress_model_core(int dim, SparseMatrix B, real **x, int edge_len_we if (A != B) SparseMatrix_delete(A); } -void stress_model(int dim, SparseMatrix A, SparseMatrix D, real **x, int edge_len_weighted, int maxit_sm, real tol, int *flag){ +void stress_model(int dim, SparseMatrix A, SparseMatrix D, double **x, int edge_len_weighted, int maxit_sm, double tol, int *flag){ stress_model_core(dim, D, x, edge_len_weighted, maxit_sm, tol, flag); } diff --git a/lib/sfdpgen/stress_model.h b/lib/sfdpgen/stress_model.h index dba3d0214..add265102 100644 --- a/lib/sfdpgen/stress_model.h +++ b/lib/sfdpgen/stress_model.h @@ -1,3 +1,3 @@ #pragma once -void stress_model(int dim, SparseMatrix A, SparseMatrix D, real **x, int edge_len_weighted, int maxit, real tol, int *flag); +void stress_model(int dim, SparseMatrix A, SparseMatrix D, double **x, int edge_len_weighted, int maxit, double tol, int *flag); diff --git a/lib/sfdpgen/uniform_stress.c b/lib/sfdpgen/uniform_stress.c index 33d659d0e..2bb70c653 100644 --- a/lib/sfdpgen/uniform_stress.c +++ b/lib/sfdpgen/uniform_stress.c @@ -25,12 +25,12 @@ This is somewhat similar to the binary stress model */ -UniformStressSmoother UniformStressSmoother_new(int dim, SparseMatrix A, real *x, real alpha, real M, int *flag){ +UniformStressSmoother UniformStressSmoother_new(int dim, SparseMatrix A, double *x, double alpha, double M, int *flag){ UniformStressSmoother sm; int i, j, k, m = A->m, *ia = A->ia, *ja = A->ja, *iw, *jw, *id, *jd; int nz; - real *d, *w, *a = (real*) A->a; - real diag_d, diag_w, dist, epsilon = 0.01; + double *d, *w, *a = (double*) A->a; + double diag_d, diag_w, dist, epsilon = 0.01; assert(SparseMatrix_is_symmetric(A, FALSE)); @@ -38,9 +38,9 @@ UniformStressSmoother UniformStressSmoother_new(int dim, SparseMatrix A, real *x sm->data = NULL; sm->scheme = SM_SCHEME_UNIFORM_STRESS; sm->lambda = NULL; - sm->data = MALLOC(sizeof(real)*2); - ((real*) sm->data)[0] = alpha; - ((real*) sm->data)[1] = M; + sm->data = MALLOC(sizeof(double)*2); + ((double*) sm->data)[0] = alpha; + ((double*) sm->data)[1] = M; sm->data_deallocator = free; sm->tol_cg = 0.01; sm->maxit_cg = (int)sqrt((double) A->m); @@ -56,7 +56,7 @@ UniformStressSmoother UniformStressSmoother_new(int dim, SparseMatrix A, real *x iw = sm->Lw->ia; jw = sm->Lw->ja; id = sm->Lwd->ia; jd = sm->Lwd->ja; - w = (real*) sm->Lw->a; d = (real*) sm->Lwd->a; + w = (double*) sm->Lw->a; d = (double*) sm->Lwd->a; iw[0] = id[0] = 0; nz = 0; @@ -98,17 +98,17 @@ void UniformStressSmoother_delete(UniformStressSmoother sm){ } -static real UniformStressSmoother_smooth(UniformStressSmoother sm, int dim, real *x, int maxit_sm) { +static double UniformStressSmoother_smooth(UniformStressSmoother sm, int dim, double *x, int maxit_sm) { return StressMajorizationSmoother_smooth(sm, dim, x, maxit_sm, 0.001); } -static SparseMatrix get_distance_matrix(SparseMatrix A, real scaling){ +static SparseMatrix get_distance_matrix(SparseMatrix A, double scaling){ /* get a distance matrix from a graph, at the moment we just symmetrize the matrix. At the moment if the matrix is not real, we just assume distance of 1 among edges. Then we apply scaling to the entire matrix */ SparseMatrix B; - real *val; + double *val; int i; if (A->type == MATRIX_TYPE_REAL){ @@ -116,16 +116,16 @@ static SparseMatrix get_distance_matrix(SparseMatrix A, real scaling){ } else { B = SparseMatrix_get_real_adjacency_matrix_symmetrized(A); } - val = (real*) B->a; + val = (double*) B->a; if (scaling != 1) for (i = 0; i < B->nz; i++) val[i] *= scaling; return B; } -extern void scale_to_box(real xmin, real ymin, real xmax, real ymax, int n, int dim, real *x); +extern void scale_to_box(double xmin, double ymin, double xmax, double ymax, int n, int dim, double *x); -void uniform_stress(int dim, SparseMatrix A, real *x, int *flag){ +void uniform_stress(int dim, SparseMatrix A, double *x, int *flag){ UniformStressSmoother sm; - real lambda0 = 10.1, M = 100, scaling = 1.; + double lambda0 = 10.1, M = 100, scaling = 1.; int maxit = 300, samepoint = TRUE, i, k, n = A->m; SparseMatrix B = NULL; diff --git a/lib/sfdpgen/uniform_stress.h b/lib/sfdpgen/uniform_stress.h index 1ee9825dd..c0491d718 100644 --- a/lib/sfdpgen/uniform_stress.h +++ b/lib/sfdpgen/uniform_stress.h @@ -18,6 +18,6 @@ typedef StressMajorizationSmoother UniformStressSmoother; void UniformStressSmoother_delete(UniformStressSmoother sm); -UniformStressSmoother UniformStressSmoother_new(int dim, SparseMatrix A, real *x, real alpha, real M, int *flag); +UniformStressSmoother UniformStressSmoother_new(int dim, SparseMatrix A, double *x, double alpha, double M, int *flag); -void uniform_stress(int dim, SparseMatrix A, real *x, int *flag); +void uniform_stress(int dim, SparseMatrix A, double *x, int *flag); diff --git a/lib/sparse/DotIO.c b/lib/sparse/DotIO.c index 165d6c462..fd19bb270 100644 --- a/lib/sparse/DotIO.c +++ b/lib/sparse/DotIO.c @@ -28,7 +28,7 @@ typedef struct { #define ND_id(n) (((Agnodeinfo_t*)((n)->base.data))->id) -static void color_string(int slen, char *buf, int dim, real *color){ +static void color_string(int slen, char *buf, int dim, double *color){ if (dim > 3 || dim < 1){ fprintf(stderr,"can only 1, 2 or 3 dimensional color space. with color value between 0 to 1\n"); assert(0); @@ -46,7 +46,7 @@ static void color_string(int slen, char *buf, int dim, real *color){ } } -void attach_edge_colors(Agraph_t* g, int dim, real *colors){ +void attach_edge_colors(Agraph_t* g, int dim, double *colors){ /* colors is array of dim*nedges, with color for edge i at colors[dim*i, dim(i+1)) */ Agsym_t* sym = agattr(g, AGEDGE, "color", 0); @@ -78,7 +78,7 @@ void attach_edge_colors(Agraph_t* g, int dim, real *colors){ * but not a->b and a->b */ SparseMatrix -SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int *n_edge_label_nodes, int **edge_label_nodes, int format, SparseMatrix *D) +SparseMatrix_import_dot (Agraph_t* g, int dim, double **label_sizes, double **x, int *n_edge_label_nodes, int **edge_label_nodes, int format, SparseMatrix *D) { SparseMatrix A = 0; Agnode_t* n; @@ -90,10 +90,10 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int int i, row; int* I; int* J; - real *val, *valD = NULL; - real v; + double *val, *valD = NULL; + double v; int type = MATRIX_TYPE_REAL; - real padding = 10; + double padding = 10; int nedge_nodes = 0; @@ -116,17 +116,17 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int A->nz = nedges; I = A->ia; J = A->ja; - val = (real*) A->a; + val = (double*) A->a; } else { I = N_NEW(nedges, int); J = N_NEW(nedges, int); - val = N_NEW(nedges, real); + val = N_NEW(nedges, double); } sym = agattr(g, AGEDGE, "weight", NULL); if (D) { symD = agattr(g, AGEDGE, "len", NULL); - valD = N_NEW(nedges, real); + valD = N_NEW(nedges, double); } i = 0; for (n = agfstnode (g); n; n = agnxtnode (g, n)) { @@ -166,9 +166,9 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int } - if (label_sizes) *label_sizes = MALLOC(sizeof(real)*2*nnodes); + if (label_sizes) *label_sizes = MALLOC(sizeof(double)*2*nnodes); for (n = agfstnode (g); n; n = agnxtnode (g, n)) { - real sz; + double sz; i = ND_id(n); if (edge_label_nodes && strncmp(agnameof(n), "|edgelabel|",11)==0) { (*edge_label_nodes)[nedge_nodes++] = i; @@ -190,11 +190,11 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int bool has_positions = true; char* pval; if (!(*x)) { - *x = MALLOC(sizeof(real)*dim*nnodes); + *x = MALLOC(sizeof(double)*dim*nnodes); assert(*x); } for (n = agfstnode (g); n && has_positions; n = agnxtnode (g, n)) { - real xx,yy, zz,ww; + double xx,yy, zz,ww; int nitems; i = ND_id(n); if ((pval = agxget(n, psym)) && *pval) { @@ -248,7 +248,7 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int else if (x) agerr (AGERR, "Error: graph %s has missing \"pos\" information", agnameof(g)); - size_t sz = sizeof(real); + size_t sz = sizeof(double); if (format == FORMAT_CSR) A = SparseMatrix_from_coordinate_arrays(nedges, nnodes, nnodes, I, J, val, type, sz); if (edge_label_nodes) *n_edge_label_nodes = nedge_nodes; @@ -337,7 +337,7 @@ void Dot_SetClusterColor(Agraph_t* g, float *rgb_r, float *rgb_g, float *rgb_b } } -SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim, int *nn, real **label_sizes, real **x, int **clusters, float **rgb_r, float **rgb_g, float **rgb_b, float **fsz, char ***labels, int default_color_scheme, int clustering_scheme, int useClusters){ +SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim, int *nn, double **label_sizes, double **x, int **clusters, float **rgb_r, float **rgb_g, float **rgb_b, float **fsz, char ***labels, int default_color_scheme, int clustering_scheme, int useClusters){ SparseMatrix A = 0; Agnode_t* n; Agedge_t* e; @@ -349,8 +349,8 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim int i, row, ic,nc, j; int* I; int* J; - real* val; - real v; + double* val; + double v; int type = MATRIX_TYPE_REAL; char scluster[100]; float ff; @@ -416,7 +416,7 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim /* form matrix */ I = N_NEW(nedges, int); J = N_NEW(nedges, int); - val = N_NEW(nedges, real); + val = N_NEW(nedges, double); sym = agattr(g, AGEDGE, "weight", NULL); clust_sym = agattr(g, AGNODE, "cluster", NULL); @@ -438,7 +438,7 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim } } A = SparseMatrix_from_coordinate_arrays(nedges, nnodes, nnodes, I, J, val, - type, sizeof(real)); + type, sizeof(double)); /* get clustering info */ *clusters = MALLOC(sizeof(int)*nnodes); @@ -494,7 +494,7 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim if (noclusterinfo) { int use_value = TRUE, flag = 0; - real modularity; + double modularity; if (!clust_sym) clust_sym = agattr(g,AGNODE,"cluster","-1"); if (clustering_scheme == CLUSTERING_MQ){ @@ -519,7 +519,7 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim } } - *label_sizes = MALLOC(sizeof(real)*dim*nnodes); + *label_sizes = MALLOC(sizeof(double)*dim*nnodes); if (pal || (!noclusterinfo && clust_clr_sym)){ *rgb_r = MALLOC(sizeof(float)*(1+MAX_GRPS)); *rgb_g = MALLOC(sizeof(float)*(1+MAX_GRPS)); @@ -534,7 +534,7 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim for (n = agfstnode (g); n; n = agnxtnode (g, n)) { gvcolor_t color; - real sz; + double sz; i = ND_id(n); if (agget(n, "width") && agget(n, "height")){ sscanf(agget(n, "width"), "%lf", &sz); @@ -594,9 +594,9 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim if (x){ bool has_position = false; - *x = MALLOC(sizeof(real)*dim*nnodes); + *x = MALLOC(sizeof(double)*dim*nnodes); for (n = agfstnode (g); n; n = agnxtnode (g, n)) { - real xx,yy; + double xx,yy; i = ND_id(n); if (agget(n, "pos")){ has_position = true; @@ -633,10 +633,10 @@ void attached_clustering(Agraph_t* g, int maxcluster, int clustering_scheme){ int i, row,nc; int* I; int* J; - real* val; - real v; + double* val; + double v; int type = MATRIX_TYPE_REAL; - size_t sz = sizeof(real); + size_t sz = sizeof(double); int *clusters; @@ -654,7 +654,7 @@ void attached_clustering(Agraph_t* g, int maxcluster, int clustering_scheme){ /* form matrix */ I = N_NEW(nedges, int); J = N_NEW(nedges, int); - val = N_NEW(nedges, real); + val = N_NEW(nedges, double); sym = agattr(g, AGEDGE, "weight", NULL); clust_sym = agattr(g, AGNODE, "cluster", NULL); @@ -681,7 +681,7 @@ void attached_clustering(Agraph_t* g, int maxcluster, int clustering_scheme){ { int use_value = TRUE, flag = 0; - real modularity; + double modularity; if (!clust_sym) clust_sym = agattr(g,AGNODE,"cluster","-1"); if (clustering_scheme == CLUSTERING_MQ){ diff --git a/lib/sparse/DotIO.h b/lib/sparse/DotIO.h index aa9a4dca2..fd20204a2 100644 --- a/lib/sparse/DotIO.h +++ b/lib/sparse/DotIO.h @@ -19,13 +19,13 @@ extern void initDotIO (Agraph_t *g); extern void setDotNodeID (Agnode_t* n, int v); extern int getDotNodeID (Agnode_t* n); -extern void attach_edge_colors(Agraph_t* g, int dim, real *colors); +extern void attach_edge_colors(Agraph_t* g, int dim, double *colors); -extern SparseMatrix SparseMatrix_import_dot(Agraph_t* g, int dim, real **label_sizes, real **x, int *n_edge_label_nodes, +extern SparseMatrix SparseMatrix_import_dot(Agraph_t* g, int dim, double **label_sizes, double **x, int *n_edge_label_nodes, int **edge_label_nodes, int format, SparseMatrix *D); -char * hue2rgb(real hue, char *color); +char * hue2rgb(double hue, char *color); -SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim, int *nn, real **label_sizes, real **x, int **clusters, float **rgb_r, float **rgb_g, float **rgb_b, float **fsz, char ***labels, int default_color_scheme, int clustering_scheme, int useClusters); +SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim, int *nn, double **label_sizes, double **x, int **clusters, float **rgb_r, float **rgb_g, float **rgb_b, float **fsz, char ***labels, int default_color_scheme, int clustering_scheme, int useClusters); void Dot_SetClusterColor(Agraph_t* g, float *rgb_r, float *rgb_g, float *rgb_b, int *clustering); void attached_clustering(Agraph_t* g, int maxcluster, int clustering_scheme); diff --git a/lib/sparse/QuadTree.c b/lib/sparse/QuadTree.c index 468e020f5..eeb909249 100644 --- a/lib/sparse/QuadTree.c +++ b/lib/sparse/QuadTree.c @@ -15,24 +15,24 @@ #include #include -extern real distance_cropped(real *x, int dim, int i, int j); +extern double distance_cropped(double *x, int dim, int i, int j); struct node_data_struct { - real node_weight; - real *coord; - real id; + double node_weight; + double *coord; + double id; void *data; }; typedef struct node_data_struct *node_data; -static node_data node_data_new(int dim, real weight, real *coord, int id){ +static node_data node_data_new(int dim, double weight, double *coord, int id){ node_data nd; int i; nd = MALLOC(sizeof(struct node_data_struct)); nd->node_weight = weight; - nd->coord = MALLOC(sizeof(real)*dim); + nd->coord = MALLOC(sizeof(double)*dim); nd->id = id; for (i = 0; i < dim; i++) nd->coord[i] = coord[i]; nd->data = NULL; @@ -46,12 +46,12 @@ static void node_data_delete(void *d){ free(nd); } -static real node_data_get_weight(void *d){ +static double node_data_get_weight(void *d){ node_data nd = (node_data) d; return nd->node_weight; } -static real* node_data_get_coord(void *d){ +static double* node_data_get_coord(void *d){ node_data nd = (node_data) d; return nd->coord; } @@ -64,19 +64,19 @@ static int node_data_get_id(void *d){ #define node_data_get_data(d) (((node_data) (d))->data) -static void check_or_realloc_arrays(int dim, int *nsuper, int *nsupermax, real **center, real **supernode_wgts, real **distances){ +static void check_or_realloc_arrays(int dim, int *nsuper, int *nsupermax, double **center, double **supernode_wgts, double **distances){ if (*nsuper >= *nsupermax) { *nsupermax = *nsuper + MAX(10, (int) 0.2*(*nsuper)); - *center = REALLOC(*center, sizeof(real)*(*nsupermax)*dim); - *supernode_wgts = REALLOC(*supernode_wgts, sizeof(real)*(*nsupermax)); - *distances = REALLOC(*distances, sizeof(real)*(*nsupermax)); + *center = REALLOC(*center, sizeof(double)*(*nsupermax)*dim); + *supernode_wgts = REALLOC(*supernode_wgts, sizeof(double)*(*nsupermax)); + *distances = REALLOC(*distances, sizeof(double)*(*nsupermax)); } } -static 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){ +static void QuadTree_get_supernodes_internal(QuadTree qt, double bh, double *point, int nodeid, int *nsuper, int *nsupermax, double **center, double **supernode_wgts, double **distances, double *counts, int *flag){ SingleLinkedList l; - real *coord, dist; + double *coord, dist; int dim, i; (*counts)++; @@ -120,8 +120,8 @@ static void QuadTree_get_supernodes_internal(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){ +void QuadTree_get_supernodes(QuadTree qt, double bh, double *point, int nodeid, int *nsuper, + int *nsupermax, double **center, double **supernode_wgts, double **distances, double *counts, int *flag){ int dim = qt->dim; (*counts) = 0; @@ -130,41 +130,41 @@ void QuadTree_get_supernodes(QuadTree qt, real bh, real *point, int nodeid, int *flag = 0; *nsupermax = 10; - if (!*center) *center = MALLOC(sizeof(real)*(*nsupermax)*dim); - if (!*supernode_wgts) *supernode_wgts = MALLOC(sizeof(real)*(*nsupermax)); - if (!*distances) *distances = MALLOC(sizeof(real)*(*nsupermax)); + if (!*center) *center = MALLOC(sizeof(double)*(*nsupermax)*dim); + if (!*supernode_wgts) *supernode_wgts = MALLOC(sizeof(double)*(*nsupermax)); + if (!*distances) *distances = MALLOC(sizeof(double)*(*nsupermax)); QuadTree_get_supernodes_internal(qt, bh, point, nodeid, nsuper, nsupermax, center, supernode_wgts, distances, counts, flag); } -static real *get_or_assign_node_force(real *force, int i, SingleLinkedList l, int dim){ +static double *get_or_assign_node_force(double *force, int i, SingleLinkedList l, int dim){ - real *f = (real*) node_data_get_data(SingleLinkedList_get_data(l)); + double *f = (double*) node_data_get_data(SingleLinkedList_get_data(l)); if (!f){ node_data_get_data(SingleLinkedList_get_data(l)) = &(force[i*dim]); - f = (real*) node_data_get_data(SingleLinkedList_get_data(l)); + f = (double*) node_data_get_data(SingleLinkedList_get_data(l)); } return f; } -static real *get_or_alloc_force_qt(QuadTree qt, int dim){ +static double *get_or_alloc_force_qt(QuadTree qt, int dim){ int i; - real *force = (real*) qt->data; + double *force = (double*) qt->data; if (!force){ - qt->data = MALLOC(sizeof(real)*dim); - force = (real*) qt->data; + qt->data = MALLOC(sizeof(double)*dim); + force = (double*) qt->data; for (i = 0; i < dim; i++) force[i] = 0.; } return force; } -static void QuadTree_repulsive_force_interact(QuadTree qt1, QuadTree qt2, real *x, real *force, real bh, real p, real KP, real *counts){ +static void QuadTree_repulsive_force_interact(QuadTree qt1, QuadTree qt2, double *x, double *force, double bh, double p, double KP, double *counts){ /* calculate the all to all reopulsive force and accumulate on each node of the quadtree if an interaction is possible. force[i*dim+j], j=1,...,dim is the force on node i */ SingleLinkedList l1, l2; - real *x1, *x2, dist, wgt1, wgt2, f, *f1, *f2, w1, w2; + double *x1, *x2, dist, wgt1, wgt2, f, *f1, *f2, w1, w2; int dim, i, j, i1, i2, k; QuadTree qt11, qt12; @@ -272,10 +272,10 @@ static void QuadTree_repulsive_force_interact(QuadTree qt1, QuadTree qt2, real * } } -static void QuadTree_repulsive_force_accumulate(QuadTree qt, real *force, real *counts){ +static void QuadTree_repulsive_force_accumulate(QuadTree qt, double *force, double *counts){ /* push down forces on cells into the node level */ - real wgt, wgt2; - real *f, *f2; + double wgt, wgt2; + double *f, *f2; SingleLinkedList l = qt->l; int i, k, dim; QuadTree qt2; @@ -311,7 +311,7 @@ static void QuadTree_repulsive_force_accumulate(QuadTree qt, real *force, real * } -void QuadTree_get_repulsive_force(QuadTree qt, real *force, real *x, real bh, real p, real KP, real *counts, int *flag){ +void QuadTree_get_repulsive_force(QuadTree qt, double *force, double *x, double bh, double p, double KP, double *counts, int *flag){ /* get repulsice force by a more efficient algortihm: we consider two cells, if they are well separated, we calculate the overall repulsive force on the cell level, if not well separated, we divide one of the cell. If both cells are at the leaf level, we calcuaulate repulsicve force among individual nodes. Finally @@ -341,18 +341,18 @@ void QuadTree_get_repulsive_force(QuadTree qt, real *force, real *x, real bh, re for (i = 0; i < 4; i++) counts[i] /= n; } -QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, real *coord, real *weight){ +QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, double *coord, double *weight){ /* form a new QuadTree data structure from a list of coordinates of n points coord: of length n*dim, point i sits at [i*dim, i*dim+dim - 1] weight: node weight of lentgth n. If NULL, unit weight assumed. */ - real *xmin, *xmax, *center, width; + double *xmin, *xmax, *center, width; QuadTree qt = NULL; int i, k; - xmin = MALLOC(sizeof(real)*dim); - xmax = MALLOC(sizeof(real)*dim); - center = MALLOC(sizeof(real)*dim); + xmin = MALLOC(sizeof(double)*dim); + xmax = MALLOC(sizeof(double)*dim); + center = MALLOC(sizeof(double)*dim); if (!xmin || !xmax || !center) { free(xmin); free(xmax); @@ -396,13 +396,13 @@ QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, real *coord return qt; } -QuadTree QuadTree_new(int dim, real *center, real width, int max_level){ +QuadTree QuadTree_new(int dim, double *center, double width, int max_level){ QuadTree q; int i; q = MALLOC(sizeof(struct QuadTree_struct)); q->dim = dim; q->n = 0; - q->center = MALLOC(sizeof(real)*dim); + q->center = MALLOC(sizeof(double)*dim); for (i = 0; i < dim; i++) q->center[i] = center[i]; assert(width > 0); q->width = width; @@ -432,7 +432,7 @@ void QuadTree_delete(QuadTree q){ free(q); } -static int QuadTree_get_quadrant(int dim, real *center, real *coord){ +static int QuadTree_get_quadrant(int dim, double *center, double *coord){ /* find the quadrant that a point of coordinates coord is going into with reference to the center. if coord - center == {+,-,+,+} = {1,0,1,1}, then it will sit in the i-quadrant where i's binary representation is 1011 (that is, decimal 11). @@ -449,7 +449,7 @@ static int QuadTree_get_quadrant(int dim, real *center, real *coord){ return d; } -QuadTree QuadTree_new_in_quadrant(int dim, real *center, real width, int max_level, int i){ +QuadTree QuadTree_new_in_quadrant(int dim, double *center, double width, int max_level, int i){ /* a new quadtree in quadrant i of the original cell. The original cell is centered at 'center". The new cell have width "width". */ @@ -471,7 +471,7 @@ QuadTree QuadTree_new_in_quadrant(int dim, real *center, real width, int max_lev return qt; } -static QuadTree QuadTree_add_internal(QuadTree q, real *coord, real weight, int id, int level){ +static QuadTree QuadTree_add_internal(QuadTree q, double *coord, double weight, int id, int level){ int i, dim = q->dim, ii; node_data nd = NULL; @@ -493,7 +493,7 @@ static QuadTree QuadTree_add_internal(QuadTree q, real *coord, real weight, int /* if this node is empty right now */ q->n = 1; q->total_weight = weight; - q->average = MALLOC(sizeof(real)*dim); + q->average = MALLOC(sizeof(double)*dim); for (i = 0; i < q->dim; i++) q->average[i] = coord[i]; nd = node_data_new(q->dim, weight, coord, id); assert(!(q->l)); @@ -548,13 +548,13 @@ static QuadTree QuadTree_add_internal(QuadTree q, real *coord, real weight, int } -QuadTree QuadTree_add(QuadTree q, real *coord, real weight, int id){ +QuadTree QuadTree_add(QuadTree q, double *coord, double weight, int id){ if (!q) return q; return QuadTree_add_internal(q, coord, weight, id, 0); } -static void draw_polygon(FILE *fp, int dim, real *center, real width){ +static void draw_polygon(FILE *fp, int dim, double *center, double width){ /* pliot the enclosing square */ if (dim < 2 || dim > 3) return; fprintf(fp,"(*in c*){Line[{"); @@ -612,7 +612,7 @@ static void draw_polygon(FILE *fp, int dim, real *center, real width){ static void QuadTree_print_internal(FILE *fp, QuadTree q, int level){ /* dump a quad tree in Mathematica format. */ SingleLinkedList l, l0; - real *coord; + double *coord; int i, dim; if (!q) return; @@ -668,13 +668,13 @@ void QuadTree_print(FILE *fp, QuadTree q){ -static void QuadTree_get_nearest_internal(QuadTree qt, real *x, real *y, real *min, int *imin, int tentative, int *flag){ +static void QuadTree_get_nearest_internal(QuadTree qt, double *x, double *y, double *min, int *imin, int tentative, int *flag){ /* get the narest point years to {x[0], ..., x[dim]} and store in y.*/ SingleLinkedList l; - real *coord, dist; + double *coord, dist; int dim, i, iq = -1; - real qmin; - real *point = x; + double qmin; + double *point = x; *flag = 0; if (!qt) return; @@ -695,7 +695,7 @@ static void QuadTree_get_nearest_internal(QuadTree qt, real *x, real *y, real *m if (qt->qts){ dist = point_distance(qt->center, point, dim); - if (*min >= 0 && (dist - sqrt((real) dim) * qt->width > *min)){ + if (*min >= 0 && (dist - sqrt((double) dim) * qt->width > *min)){ return; } else { if (tentative){/* quick first approximation*/ @@ -721,7 +721,7 @@ static void QuadTree_get_nearest_internal(QuadTree qt, real *x, real *y, real *m } -void QuadTree_get_nearest(QuadTree qt, real *x, real *ymin, int *imin, real *min, int *flag){ +void QuadTree_get_nearest(QuadTree qt, double *x, double *ymin, int *imin, double *min, int *flag){ *flag = 0; *min = -1; diff --git a/lib/sparse/QuadTree.h b/lib/sparse/QuadTree.h index 3f9f0c9a8..90d2cbe51 100644 --- a/lib/sparse/QuadTree.h +++ b/lib/sparse/QuadTree.h @@ -21,12 +21,12 @@ struct QuadTree_struct { 2^dim QuadTrees qts. At the last level, all coordinates are stored in a single linked list l. total_weight is the combined weights of the nodes */ int n;/* number of items */ - real total_weight; + double total_weight; int dim; - real *center;/* center of the bounding box, array of dimension dim. Allocated inside */ - real width;/* center +/- width gives the lower/upper bound, so really width is the + double *center;/* center of the bounding box, array of dimension dim. Allocated inside */ + double 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 */ + double *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; int max_level; @@ -34,24 +34,24 @@ struct QuadTree_struct { }; -QuadTree QuadTree_new(int dim, real *center, real width, int max_level); +QuadTree QuadTree_new(int dim, double *center, double width, int max_level); 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, double *coord, double weight, int id);/* coord is copied in */ void QuadTree_print(FILE *fp, QuadTree q); -QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, real *coord, real *weight); +QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, double *coord, double *weight); -real point_distance(real *p1, real *p2, int dim); +double point_distance(double *p1, double *p2, int dim); -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); +void QuadTree_get_supernodes(QuadTree qt, double bh, double *point, int nodeid, int *nsuper, + int *nsupermax, double **center, double **supernode_wgts, double **distances, double *counts, int *flag); -void QuadTree_get_repulsive_force(QuadTree qt, real *force, real *x, real bh, real p, real KP, real *counts, int *flag); +void QuadTree_get_repulsive_force(QuadTree qt, double *force, double *x, double bh, double p, double KP, double *counts, int *flag); /* find the nearest point and put in ymin, index in imin and distance in min */ -void QuadTree_get_nearest(QuadTree qt, real *x, real *ymin, int *imin, real *min, int *flag); +void QuadTree_get_nearest(QuadTree qt, double *x, double *ymin, int *imin, double *min, int *flag); -QuadTree QuadTree_new_in_quadrant(int dim, real *center, real width, int max_level, int i); +QuadTree QuadTree_new_in_quadrant(int dim, double *center, double width, int max_level, int i); diff --git a/lib/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index 2e3746323..8315cc780 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -24,10 +24,10 @@ static size_t size_of_matrix_type(int type){ size_t size = 0; switch (type){ case MATRIX_TYPE_REAL: - size = sizeof(real); + size = sizeof(double); break; case MATRIX_TYPE_COMPLEX: - size = 2*sizeof(real); + size = 2*sizeof(double); break; case MATRIX_TYPE_INTEGER: size = sizeof(int); @@ -86,8 +86,8 @@ SparseMatrix SparseMatrix_transpose(SparseMatrix A){ switch (A->type){ case MATRIX_TYPE_REAL:{ - real *a = (real*) A->a; - real *b = (real*) B->a; + double *a = (double*) A->a; + double *b = (double*) B->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ jb[ib[ja[j]]] = i; @@ -97,8 +97,8 @@ SparseMatrix SparseMatrix_transpose(SparseMatrix A){ break; } case MATRIX_TYPE_COMPLEX:{ - real *a = (real*) A->a; - real *b = (real*) B->a; + double *a = (double*) A->a; + double *b = (double*) B->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ jb[ib[ja[j]]] = i; @@ -203,8 +203,8 @@ int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only){ switch (type){ case MATRIX_TYPE_REAL:{ - real *a = (real*) A->a; - real *b = (real*) B->a; + double *a = (double*) A->a; + double *b = (double*) B->a; for (i = 0; i <= m; i++) if (ia[i] != ib[i]) goto RETURN; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -221,8 +221,8 @@ int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only){ break; } case MATRIX_TYPE_COMPLEX:{ - real *a = (real*) A->a; - real *b = (real*) B->a; + double *a = (double*) A->a; + double *b = (double*) B->a; for (i = 0; i <= m; i++) if (ia[i] != ib[i]) goto RETURN; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -414,7 +414,7 @@ void SparseMatrix_delete(SparseMatrix A){ } static void SparseMatrix_print_csr(char *c, SparseMatrix A){ int *ia, *ja; - real *a; + double *a; int *ai; int i, j, m = A->m; @@ -425,7 +425,7 @@ static void SparseMatrix_print_csr(char *c, SparseMatrix A){ a = A->a; switch (A->type){ case MATRIX_TYPE_REAL: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ printf("{%d, %d}->%f",i+1, ja[j]+1, a[j]); @@ -434,7 +434,7 @@ static void SparseMatrix_print_csr(char *c, SparseMatrix A){ } break; case MATRIX_TYPE_COMPLEX: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ printf("{%d, %d}->%f + %f I",i+1, ja[j]+1, a[2*j], a[2*j+1]); @@ -475,7 +475,7 @@ static void SparseMatrix_print_csr(char *c, SparseMatrix A){ static void SparseMatrix_print_coord(char *c, SparseMatrix A){ int *ia, *ja; - real *a; + double *a; int *ai; int i, m = A->m; @@ -486,7 +486,7 @@ static void SparseMatrix_print_coord(char *c, SparseMatrix A){ a = A->a; switch (A->type){ case MATRIX_TYPE_REAL: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < A->nz; i++){ printf("{%d, %d}->%f",ia[i]+1, ja[i]+1, a[i]); if (i != A->nz - 1) printf(","); @@ -494,7 +494,7 @@ static void SparseMatrix_print_coord(char *c, SparseMatrix A){ printf("\n"); break; case MATRIX_TYPE_COMPLEX: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < A->nz; i++){ printf("{%d, %d}->%f + %f I",ia[i]+1, ja[i]+1, a[2*i], a[2*i+1]); if (i != A->nz - 1) printf(","); @@ -551,7 +551,7 @@ void SparseMatrix_print(char *c, SparseMatrix A){ static void SparseMatrix_export_csr(FILE *f, SparseMatrix A){ int *ia, *ja; - real *a; + double *a; int *ai; int i, j, m = A->m; @@ -580,7 +580,7 @@ static void SparseMatrix_export_csr(FILE *f, SparseMatrix A){ a = A->a; switch (A->type){ case MATRIX_TYPE_REAL: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ fprintf(f, "%d %d %16.8g\n",i+1, ja[j]+1, a[j]); @@ -588,7 +588,7 @@ static void SparseMatrix_export_csr(FILE *f, SparseMatrix A){ } break; case MATRIX_TYPE_COMPLEX: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ fprintf(f, "%d %d %16.8g %16.8g\n",i+1, ja[j]+1, a[2*j], a[2*j+1]); @@ -620,7 +620,7 @@ static void SparseMatrix_export_csr(FILE *f, SparseMatrix A){ static void SparseMatrix_export_coord(FILE *f, SparseMatrix A){ int *ia, *ja; - real *a; + double *a; int *ai; int i; @@ -649,13 +649,13 @@ static void SparseMatrix_export_coord(FILE *f, SparseMatrix A){ a = A->a; switch (A->type){ case MATRIX_TYPE_REAL: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < A->nz; i++){ fprintf(f, "%d %d %16.8g\n",ia[i]+1, ja[i]+1, a[i]); } break; case MATRIX_TYPE_COMPLEX: - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < A->nz; i++){ fprintf(f, "%d %d %16.8g %16.8g\n",ia[i]+1, ja[i]+1, a[2*i], a[2*i+1]); } @@ -740,7 +740,7 @@ static SparseMatrix SparseMatrix_from_coordinate_arrays_internal(int nz, int m, SparseMatrix A = NULL; int *ia, *ja; - real *a, *val; + double *a, *val; int *ai, *vali; int i; @@ -759,8 +759,8 @@ static SparseMatrix SparseMatrix_from_coordinate_arrays_internal(int nz, int m, switch (type){ case MATRIX_TYPE_REAL: - val = (real*) val0; - a = (real*) A->a; + val = (double*) val0; + a = (double*) A->a; for (i = 0; i < nz; i++){ if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) { assert(0); @@ -777,8 +777,8 @@ static SparseMatrix SparseMatrix_from_coordinate_arrays_internal(int nz, int m, ia[0] = 0; break; case MATRIX_TYPE_COMPLEX: - val = (real*) val0; - a = (real*) A->a; + val = (double*) val0; + a = (double*) A->a; for (i = 0; i < nz; i++){ if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) { assert(0); @@ -896,9 +896,9 @@ SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B){ ic[0] = 0; switch (A->type){ case MATRIX_TYPE_REAL:{ - real *a = (real*) A->a; - real *b = (real*) B->a; - real *c = (real*) C->a; + double *a = (double*) A->a; + double *b = (double*) B->a; + double *c = (double*) C->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ mask[ja[j]] = nz; @@ -919,9 +919,9 @@ SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B){ break; } case MATRIX_TYPE_COMPLEX:{ - real *a = (real*) A->a; - real *b = (real*) B->a; - real *c = (real*) C->a; + double *a = (double*) A->a; + double *b = (double*) B->a; + double *c = (double*) C->a; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ mask[ja[j]] = nz; @@ -999,21 +999,21 @@ SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B){ return C; } -static void SparseMatrix_multiply_dense1(SparseMatrix A, real *v, real **res, int dim){ +static void SparseMatrix_multiply_dense1(SparseMatrix A, double *v, double **res, int dim){ /* A v where v a dense matrix of second dimension dim. Real only for now. */ int i, j, k, *ia, *ja, m; - real *a, *u; + double *a, *u; assert(A->format == FORMAT_CSR); assert(A->type == MATRIX_TYPE_REAL); - a = (real*) A->a; + a = (double*) A->a; ia = A->ia; ja = A->ja; m = A->m; u = *res; - if (!u) u = MALLOC(sizeof(real)*((size_t) m)*((size_t) dim)); + if (!u) u = MALLOC(sizeof(double)*((size_t) m)*((size_t) dim)); for (i = 0; i < m; i++){ for (k = 0; k < dim; k++) u[i*dim+k] = 0.; for (j = ia[i]; j < ia[i+1]; j++){ @@ -1024,17 +1024,17 @@ static void SparseMatrix_multiply_dense1(SparseMatrix A, real *v, real **res, in *res = u; } -void SparseMatrix_multiply_dense(SparseMatrix A, real *v, real **res, int dim){ +void SparseMatrix_multiply_dense(SparseMatrix A, double *v, double **res, int dim){ /* A * V, with A dimension m x n, with V of dimension n x dim. v[i*dim+j] gives V[i,j]. Result of dimension m x dim */ SparseMatrix_multiply_dense1(A, v, res, dim); } -void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int transposed){ +void SparseMatrix_multiply_vector(SparseMatrix A, double *v, double **res, int transposed){ /* A v or A^T v. Real only for now. */ int i, j, *ia, *ja, n, m; - real *a, *u = NULL; + double *a, *u = NULL; int *ai; assert(A->format == FORMAT_CSR); assert(A->type == MATRIX_TYPE_REAL || A->type == MATRIX_TYPE_INTEGER); @@ -1047,10 +1047,10 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans switch (A->type){ case MATRIX_TYPE_REAL: - a = (real*) A->a; + a = (double*) A->a; if (v){ if (!transposed){ - if (!u) u = MALLOC(sizeof(real)*((size_t)m)); + if (!u) u = MALLOC(sizeof(double)*((size_t)m)); for (i = 0; i < m; i++){ u[i] = 0.; for (j = ia[i]; j < ia[i+1]; j++){ @@ -1058,7 +1058,7 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans } } } else { - if (!u) u = MALLOC(sizeof(real)*((size_t)n)); + if (!u) u = MALLOC(sizeof(double)*((size_t)n)); for (i = 0; i < n; i++) u[i] = 0.; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1069,7 +1069,7 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans } else { /* v is assumed to be all 1's */ if (!transposed){ - if (!u) u = MALLOC(sizeof(real)*((size_t)m)); + if (!u) u = MALLOC(sizeof(double)*((size_t)m)); for (i = 0; i < m; i++){ u[i] = 0.; for (j = ia[i]; j < ia[i+1]; j++){ @@ -1077,7 +1077,7 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans } } } else { - if (!u) u = MALLOC(sizeof(real)*((size_t)n)); + if (!u) u = MALLOC(sizeof(double)*((size_t)n)); for (i = 0; i < n; i++) u[i] = 0.; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1091,7 +1091,7 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans ai = (int*) A->a; if (v){ if (!transposed){ - if (!u) u = MALLOC(sizeof(real)*((size_t)m)); + if (!u) u = MALLOC(sizeof(double)*((size_t)m)); for (i = 0; i < m; i++){ u[i] = 0.; for (j = ia[i]; j < ia[i+1]; j++){ @@ -1099,7 +1099,7 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans } } } else { - if (!u) u = MALLOC(sizeof(real)*((size_t)n)); + if (!u) u = MALLOC(sizeof(double)*((size_t)n)); for (i = 0; i < n; i++) u[i] = 0.; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1110,7 +1110,7 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans } else { /* v is assumed to be all 1's */ if (!transposed){ - if (!u) u = MALLOC(sizeof(real)*((size_t)m)); + if (!u) u = MALLOC(sizeof(double)*((size_t)m)); for (i = 0; i < m; i++){ u[i] = 0.; for (j = ia[i]; j < ia[i+1]; j++){ @@ -1118,7 +1118,7 @@ void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int trans } } } else { - if (!u) u = MALLOC(sizeof(real)*((size_t)n)); + if (!u) u = MALLOC(sizeof(double)*((size_t)n)); for (i = 0; i < n; i++) u[i] = 0.; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1189,9 +1189,9 @@ SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B){ switch (type){ case MATRIX_TYPE_REAL: { - real *a = (real*) A->a; - real *b = (real*) B->a; - real *c = (real*) C->a; + double *a = (double*) A->a; + double *b = (double*) B->a; + double *c = (double*) C->a; ic[0] = 0; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1214,12 +1214,12 @@ SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B){ break; case MATRIX_TYPE_COMPLEX: { - real *a = (real*) A->a; - real *b = (real*) B->a; - real *c = (real*) C->a; - a = (real*) A->a; - b = (real*) B->a; - c = (real*) C->a; + double *a = (double*) A->a; + double *b = (double*) B->a; + double *c = (double*) C->a; + a = (double*) A->a; + b = (double*) B->a; + c = (double*) C->a; ic[0] = 0; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1359,10 +1359,10 @@ SparseMatrix SparseMatrix_multiply3(SparseMatrix A, SparseMatrix B, SparseMatrix switch (type){ case MATRIX_TYPE_REAL: { - real *a = (real*) A->a; - real *b = (real*) B->a; - real *c = (real*) C->a; - real *d = (real*) D->a; + double *a = (double*) A->a; + double *b = (double*) B->a; + double *c = (double*) C->a; + double *d = (double*) D->a; id[0] = 0; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1388,10 +1388,10 @@ SparseMatrix SparseMatrix_multiply3(SparseMatrix A, SparseMatrix B, SparseMatrix break; case MATRIX_TYPE_COMPLEX: { - real *a = (real*) A->a; - real *b = (real*) B->a; - real *c = (real*) C->a; - real *d = (real*) D->a; + double *a = (double*) A->a; + double *b = (double*) B->a; + double *c = (double*) C->a; + double *d = (double*) D->a; id[0] = 0; for (i = 0; i < m; i++){ for (j = ia[i]; j < ia[i+1]; j++){ @@ -1498,7 +1498,7 @@ SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A, int what_to_sum){ switch (type){ case MATRIX_TYPE_REAL: { - real *a = (real*) A->a; + double *a = (double*) A->a; nz = 0; sta = ia[0]; for (i = 0; i < A->m; i++){ @@ -1519,7 +1519,7 @@ SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A, int what_to_sum){ break; case MATRIX_TYPE_COMPLEX: { - real *a = (real*) A->a; + double *a = (double*) A->a; if (what_to_sum == SUM_REPEATED_ALL){ nz = 0; sta = ia[0]; @@ -1628,7 +1628,7 @@ SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A){ sta = ia[0]; switch (A->type){ case MATRIX_TYPE_REAL:{ - real *a = (real*) A->a; + double *a = (double*) A->a; for (i = 0; i < A->m; i++){ for (j = sta; j < ia[i+1]; j++){ if (ja[j] != i){ @@ -1643,7 +1643,7 @@ SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A){ break; } case MATRIX_TYPE_COMPLEX:{ - real *a = (real*) A->a; + double *a = (double*) A->a; for (i = 0; i < A->m; i++){ for (j = sta; j < ia[i+1]; j++){ if (ja[j] != i){ @@ -1708,7 +1708,7 @@ SparseMatrix SparseMatrix_remove_upper(SparseMatrix A){/* remove diag and upper sta = ia[0]; switch (A->type){ case MATRIX_TYPE_REAL:{ - real *a = (real*) A->a; + double *a = (double*) A->a; for (i = 0; i < A->m; i++){ for (j = sta; j < ia[i+1]; j++){ if (ja[j] < i){ @@ -1723,7 +1723,7 @@ SparseMatrix SparseMatrix_remove_upper(SparseMatrix A){/* remove diag and upper break; } case MATRIX_TYPE_COMPLEX:{ - real *a = (real*) A->a; + double *a = (double*) A->a; for (i = 0; i < A->m; i++){ for (j = sta; j < ia[i+1]; j++){ if (ja[j] < i){ @@ -1785,7 +1785,7 @@ SparseMatrix SparseMatrix_remove_upper(SparseMatrix A){/* remove diag and upper SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A){ int i, j, *ia, *ja; - real deg; + double deg; if (!A) return A; @@ -1793,7 +1793,7 @@ SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A){ ja = A->ja; switch (A->type){ case MATRIX_TYPE_REAL:{ - real *a = (real*) A->a; + double *a = (double*) A->a; for (i = 0; i < A->m; i++){ deg = ia[i+1] - ia[i]; for (j = ia[i]; j < ia[i+1]; j++){ @@ -1803,7 +1803,7 @@ SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A){ break; } case MATRIX_TYPE_COMPLEX:{ - real *a = (real*) A->a; + double *a = (double*) A->a; for (i = 0; i < A->m; i++){ deg = ia[i+1] - ia[i]; for (j = ia[i]; j < ia[i+1]; j++){ @@ -1835,7 +1835,7 @@ SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A){ SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A){ /* symmetric, all entries to 1, diaginal removed */ int i, *ia, *ja, nz, m, n; - real *a; + double *a; SparseMatrix B; if (!A) return A; @@ -1857,17 +1857,17 @@ SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A){ A = SparseMatrix_symmetrize(B, TRUE); SparseMatrix_delete(B); A = SparseMatrix_remove_diagonal(A); - A->a = MALLOC(sizeof(real)*((size_t)(A->nz))); - a = (real*) A->a; + A->a = MALLOC(sizeof(double)*((size_t)(A->nz))); + a = (double*) A->a; for (i = 0; i < A->nz; i++) a[i] = 1.; A->type = MATRIX_TYPE_REAL; - A->size = sizeof(real); + A->size = sizeof(double); return A; } SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double (*fun)(double x)){ int i, j; - real *a; + double *a; if (!A) return A; @@ -1879,7 +1879,7 @@ SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double (*fun)(double x)){ } - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < A->m; i++){ for (j = A->ia[i]; j < A->ia[i+1]; j++){ a[j] = fun(a[j]); @@ -2009,7 +2009,7 @@ void SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int * struct nodedata_struct { - real dist;/* distance to root */ + double dist;/* distance to root */ int id;/*node id */ }; typedef struct nodedata_struct* nodedata; @@ -2028,7 +2028,7 @@ static int cmp(void*i, void*j){ return 0; } -static int Dijkstra_internal(SparseMatrix A, int root, real *dist, int *nlist, int *list, real *dist_max, int *mask){ +static int Dijkstra_internal(SparseMatrix A, int root, double *dist, int *nlist, int *list, double *dist_max, int *mask){ /* Find the shortest path distance of all nodes to root. If khops >= 0, the shortest ath is of distance <= khops, A: the nxn connectivity matrix. Entries are assumed to be nonnegative. Absolute value will be taken if @@ -2045,7 +2045,7 @@ static int Dijkstra_internal(SparseMatrix A, int root, real *dist, int *nlist, i int m = A->m, i, j, jj, *ia = A->ia, *ja = A->ja, heap_id; BinaryHeap h; - real *a = NULL, *aa; + double *a = NULL, *aa; int *ai; nodedata ndata, ndata_min; enum {UNVISITED = -2, FINISHED = -1}; @@ -2059,20 +2059,20 @@ static int Dijkstra_internal(SparseMatrix A, int root, real *dist, int *nlist, i switch (A->type){ case MATRIX_TYPE_COMPLEX: - aa = (real*) A->a; - a = MALLOC(sizeof(real)*((size_t)(A->nz))); + aa = (double*) A->a; + a = MALLOC(sizeof(double)*((size_t)(A->nz))); for (i = 0; i < A->nz; i++) a[i] = aa[i*2]; break; case MATRIX_TYPE_REAL: - a = (real*) A->a; + a = (double*) A->a; break; case MATRIX_TYPE_INTEGER: ai = (int*) A->a; - a = MALLOC(sizeof(real)*((size_t)(A->nz))); - for (i = 0; i < A->nz; i++) a[i] = (real) ai[i]; + a = MALLOC(sizeof(double)*((size_t)(A->nz))); + for (i = 0; i < A->nz; i++) a[i] = (double) ai[i]; break; case MATRIX_TYPE_PATTERN: - a = MALLOC(sizeof(real)*((size_t)A->nz)); + a = MALLOC(sizeof(double)*((size_t)A->nz)); for (i = 0; i < A->nz; i++) a[i] = 1.; break; default: @@ -2139,11 +2139,11 @@ static int Dijkstra_internal(SparseMatrix A, int root, real *dist, int *nlist, i } } -static int Dijkstra(SparseMatrix A, int root, real *dist, int *nlist, int *list, real *dist_max){ +static int Dijkstra(SparseMatrix A, int root, double *dist, int *nlist, int *list, double *dist_max){ return Dijkstra_internal(A, root, dist, nlist, list, dist_max, NULL); } -static int Dijkstra_masked(SparseMatrix A, int root, real *dist, int *nlist, int *list, real *dist_max, int *mask){ +static int Dijkstra_masked(SparseMatrix A, int root, double *dist, int *nlist, int *list, double *dist_max, int *mask){ /* this makes the algorithm only consider nodes that are masked. nodes are masked as 1, 2, ..., mask_max, which is (the number of hops from root)+1. Only paths consists of nodes that are masked are allowed. */ @@ -2370,11 +2370,11 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int switch (A->type){ case MATRIX_TYPE_REAL:{ - real *a = (real*) A->a; - real *val; + double *a = (double*) A->a; + double *val; irn = MALLOC(sizeof(int)*((size_t)nz)); jcn = MALLOC(sizeof(int)*((size_t)nz)); - val = MALLOC(sizeof(real)*((size_t)nz)); + val = MALLOC(sizeof(double)*((size_t)nz)); nz = 0; for (i = 0; i < m; i++){ @@ -2390,12 +2390,12 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int break; } case MATRIX_TYPE_COMPLEX:{ - real *a = (real*) A->a; - real *val; + double *a = (double*) A->a; + double *val; irn = MALLOC(sizeof(int)*((size_t)nz)); jcn = MALLOC(sizeof(int)*((size_t)nz)); - val = MALLOC(sizeof(real)*2*((size_t)nz)); + val = MALLOC(sizeof(double)*2*((size_t)nz)); nz = 0; for (i = 0; i < m; i++){ @@ -2470,30 +2470,30 @@ SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int } SparseMatrix SparseMatrix_set_entries_to_real_one(SparseMatrix A){ - real *a; + double *a; int i; free(A->a); - A->a = MALLOC(sizeof(real)*((size_t)A->nz)); - a = (real*) (A->a); + A->a = MALLOC(sizeof(double)*((size_t)A->nz)); + a = (double*) (A->a); for (i = 0; i < A->nz; i++) a[i] = 1.; A->type = MATRIX_TYPE_REAL; - A->size = sizeof(real); + A->size = sizeof(double); return A; } -SparseMatrix SparseMatrix_from_dense(int m, int n, real *x){ +SparseMatrix SparseMatrix_from_dense(int m, int n, double *x){ /* wrap a mxn matrix into a sparse matrix. the {i,j} entry of the matrix is in x[i*n+j], 0<=iia[0] = 0; for (i = 1; i <= m; i++) (A->ia)[i] = (A->ia)[i-1] + n; ja = A->ja; - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < m; i++){ for (j = 0; j < n; j++) { ja[j] = j; @@ -2507,7 +2507,7 @@ SparseMatrix SparseMatrix_from_dense(int m, int n, real *x){ } -int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, real **dist0){ +int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, double **dist0){ /* Input: D: the graph. If weighted, the entry values is used. @@ -2519,10 +2519,10 @@ int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, real **dist0){ SparseMatrix D = D0; int m = D->m, n = D->n; int *levelset_ptr = NULL, *levelset = NULL, *mask = NULL; - real *dist = NULL; + double *dist = NULL; int nlist, *list = NULL; int flag = 0, i, j, k, nlevel; - real dmax; + double dmax; if (!SparseMatrix_is_symmetric(D, FALSE)){ D = SparseMatrix_symmetrize(D, FALSE); @@ -2530,7 +2530,7 @@ int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, real **dist0){ assert(m == n); - if (!(*dist0)) *dist0 = MALLOC(sizeof(real)*n*n); + if (!(*dist0)) *dist0 = MALLOC(sizeof(double)*n*n); for (i = 0; i < n*n; i++) (*dist0)[i] = -1; if (!weighted){ @@ -2573,10 +2573,10 @@ SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix D0, int SparseMatrix D = D0, B, C; int m = D->m, n = D->n; int *levelset_ptr = NULL, *levelset = NULL, *mask = NULL; - real *dist = NULL; + double *dist = NULL; int nlist, *list = NULL; int flag = 0, i, j, k, itmp, nlevel; - real dmax, dtmp; + double dmax, dtmp; if (!SparseMatrix_is_symmetric(D, FALSE)){ D = SparseMatrix_symmetrize(D, FALSE); @@ -2598,7 +2598,7 @@ SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix D0, int } } else { list = MALLOC(sizeof(int)*n); - dist = MALLOC(sizeof(real)*n); + dist = MALLOC(sizeof(double)*n); /* Dijkstra_khops(khops, D, 60, dist, &nlist, list, &dmax); for (j = 0; j < nlist; j++){ diff --git a/lib/sparse/SparseMatrix.h b/lib/sparse/SparseMatrix.h index ea5a43505..609391350 100644 --- a/lib/sparse/SparseMatrix.h +++ b/lib/sparse/SparseMatrix.h @@ -68,12 +68,12 @@ int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only); SparseMatrix SparseMatrix_transpose(SparseMatrix A); SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, int pattern_symmetric_only); SparseMatrix SparseMatrix_symmetrize_nodiag(SparseMatrix A); -void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int transposed);/* if v = NULL, v is assumed to be {1,1,...,1}*/ +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); 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 */ -void SparseMatrix_multiply_dense(SparseMatrix A, real *v, real **res, int dim); +void SparseMatrix_multiply_dense(SparseMatrix A, double *v, double **res, 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); @@ -98,10 +98,10 @@ SparseMatrix SparseMatrix_sort(SparseMatrix A); SparseMatrix SparseMatrix_set_entries_to_real_one(SparseMatrix A); -int SparseMatrix_distance_matrix(SparseMatrix A, int weighted, real **dist_matrix); +int SparseMatrix_distance_matrix(SparseMatrix A, int weighted, double **dist_matrix); SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix A, int weighted); -SparseMatrix SparseMatrix_from_dense(int m, int n, real *x); +SparseMatrix SparseMatrix_from_dense(int m, int n, double *x); #define SparseMatrix_set_undirected(A) set_flag((A)->property, MATRIX_UNDIRECTED) #define SparseMatrix_set_symmetric(A) set_flag((A)->property, MATRIX_SYMMETRIC) diff --git a/lib/sparse/clustering.c b/lib/sparse/clustering.c index 904457711..b2323a967 100644 --- a/lib/sparse/clustering.c +++ b/lib/sparse/clustering.c @@ -33,22 +33,22 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_init(Sp grid->next = NULL; grid->prev = NULL; grid->delete_top_level_A = FALSE; - grid->matching = MALLOC(sizeof(real)*(n)); + grid->matching = MALLOC(sizeof(double)*(n)); grid->deg = NULL; grid->agglomerate_regardless = FALSE; if (level == 0){ - real modularity = 0; + double modularity = 0; int *ia = A->ia, *ja = A->ja, n = A->n; - real deg_total = 0; - real *deg, *a = (real*) (A->a); - real *indeg; + double deg_total = 0; + double *deg, *a = (double*) (A->a); + double *indeg; grid->deg_total = 0.; - grid->deg = MALLOC(sizeof(real)*(n)); + grid->deg = MALLOC(sizeof(double)*(n)); deg = grid->deg; - indeg = MALLOC(sizeof(real)*n); + indeg = MALLOC(sizeof(double)*n); for (i = 0; i < n; i++){ deg[i] = 0; indeg[i] = 0.; @@ -94,21 +94,21 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_establi int *matching = grid->matching; SparseMatrix A = grid->A; int n = grid->n, level = grid->level, nc = 0; - real modularity = 0; + double modularity = 0; int *ia = A->ia, *ja = A->ja; - real *a; - real *deg = grid->deg; - real *deg_new; + double *a; + double *deg = grid->deg; + double *deg_new; int i, j, jj, jc, jmax; - real inv_deg_total = 1./(grid->deg_total); - real *deg_inter, gain; + double inv_deg_total = 1./(grid->deg_total); + double *deg_inter, gain; int *mask; - real maxgain; - real total_gain = 0; + double maxgain; + double total_gain = 0; modularity = grid->modularity; - deg_new = MALLOC(sizeof(real)*n); - deg_inter = MALLOC(sizeof(real)*n); + deg_new = MALLOC(sizeof(double)*n); + deg_inter = MALLOC(sizeof(double)*n); mask = MALLOC(sizeof(int)*n); for (i = 0; i < n; i++) mask[i] = -1; @@ -118,7 +118,7 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_establi /* gain in merging node i into cluster j is deg(i,j)/deg_total - 2*deg(i)*deg(j)/deg_total^2 */ - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < n; i++){ if (matching[i] != UNMATCHED) continue; /* accumulate connections between i and clusters */ @@ -208,7 +208,7 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_establi if (nc >= 1 && (total_gain > 0 || nc < n)){ /* now set up restriction and prolongation operator */ SparseMatrix P, R, R0, B, cA; - real one = 1.; + double one = 1.; Multilevel_Modularity_Clustering cgrid; R0 = SparseMatrix_new(nc, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); @@ -234,7 +234,7 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_establi grid->R = R; level++; cgrid = Multilevel_Modularity_Clustering_init(cA, level); - deg_new = REALLOC(deg_new, nc*sizeof(real)); + deg_new = REALLOC(deg_new, nc*sizeof(double)); cgrid->deg = deg_new; cgrid->modularity = grid->modularity + total_gain; cgrid->deg_total = grid->deg_total; @@ -286,7 +286,7 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_new(Spa static void hierachical_modularity_clustering(SparseMatrix A, int ncluster_target, - int *nclusters, int **assignment, real *modularity, int *flag){ + int *nclusters, int **assignment, double *modularity, int *flag){ /* find a clustering of vertices by maximize modularity A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1. @@ -305,7 +305,7 @@ static void hierachical_modularity_clustering(SparseMatrix A, int ncluster_targe Multilevel_Modularity_Clustering grid, cgrid; int *matching, i; SparseMatrix P; - real *u; + double *u; assert(A->m == A->n); *modularity = 0.; @@ -321,13 +321,13 @@ static void hierachical_modularity_clustering(SparseMatrix A, int ncluster_targe } /* project clustering up */ - u = MALLOC(sizeof(real)*cgrid->n); - for (i = 0; i < cgrid->n; i++) u[i] = (real) (cgrid->matching)[i]; + u = MALLOC(sizeof(double)*cgrid->n); + for (i = 0; i < cgrid->n; i++) u[i] = (double) (cgrid->matching)[i]; *nclusters = cgrid->n; *modularity = cgrid->modularity; while (cgrid->prev){ - real *v = NULL; + double *v = NULL; P = cgrid->prev->P; SparseMatrix_multiply_vector(P, u, &v, FALSE); free(u); @@ -350,7 +350,7 @@ static void hierachical_modularity_clustering(SparseMatrix A, int ncluster_targe void modularity_clustering(SparseMatrix A, int inplace, int ncluster_target, int use_value, - int *nclusters, int **assignment, real *modularity, int *flag){ + int *nclusters, int **assignment, double *modularity, int *flag){ /* find a clustering of vertices by maximize modularity A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1. inplace: whether A can e modified. If true, A will be modified by removing diagonal. diff --git a/lib/sparse/clustering.h b/lib/sparse/clustering.h index 79417913e..a8db9eece 100644 --- a/lib/sparse/clustering.h +++ b/lib/sparse/clustering.h @@ -22,9 +22,9 @@ struct Multilevel_Modularity_Clustering_struct { Multilevel_Modularity_Clustering prev; int delete_top_level_A; int *matching; /* dimension n. matching[i] is the clustering assignment of node i */ - real modularity; - real deg_total; /* total edge weights, including self-edges */ - real *deg;/* dimension n. deg[i] equal to the sum of edge weights connected to vertex i. I.e., sum of row i */ + double modularity; + double deg_total; /* total edge weights, including self-edges */ + double *deg;/* dimension n. deg[i] equal to the sum of edge weights connected to vertex i. I.e., sum of row i */ int agglomerate_regardless;/* whether to agglomerate nodes even if this causes modularity reduction. This is used if we want to force agglomeration so as to get less clusters */ @@ -48,4 +48,4 @@ enum {CLUSTERING_MODULARITY = 0, CLUSTERING_MQ}; modularity: achieve modularity */ void modularity_clustering(SparseMatrix A, int inplace, int maxcluster, int use_value, - int *nclusters, int **assignment, real *modularity, int *flag); + int *nclusters, int **assignment, double *modularity, int *flag); diff --git a/lib/sparse/colorutil.c b/lib/sparse/colorutil.c index adb7a12e4..b909eef4b 100644 --- a/lib/sparse/colorutil.c +++ b/lib/sparse/colorutil.c @@ -29,7 +29,7 @@ void rgb2hex(float r, float g, float b, char *cstring, const char *opacity) { } } -static real Hue2RGB(real v1, real v2, real H) { +static double Hue2RGB(double v1, double v2, double H) { if(H < 0.0) H += 1.0; if(H > 1.0) H -= 1.0; if((6.0*H) < 1.0) return (v1 + (v2 - v1) * 6.0 * H); @@ -38,8 +38,8 @@ static real Hue2RGB(real v1, real v2, real H) { return v1; } -char * hue2rgb(real hue, char *color){ - real v1, v2, lightness = .5, saturation = 1; +char * hue2rgb(double hue, char *color){ + double v1, v2, lightness = .5, saturation = 1; int red, blue, green; if(lightness < 0.5) diff --git a/lib/sparse/colorutil.h b/lib/sparse/colorutil.h index a34205e46..981eca407 100644 --- a/lib/sparse/colorutil.h +++ b/lib/sparse/colorutil.h @@ -17,4 +17,4 @@ extern int colorxlate(char *str, gvcolor_t * color, color_type_t target_type); void rgb2hex(float r, float g, float b, char *cstring, const char* opacity); /* dimension of cstring must be >=7 */ -char* hue2rgb(real hue, char *color); +char* hue2rgb(double hue, char *color); diff --git a/lib/sparse/general.c b/lib/sparse/general.c index 579d711f7..4e89704b1 100644 --- a/lib/sparse/general.c +++ b/lib/sparse/general.c @@ -17,8 +17,8 @@ double _statistics[10]; #endif -real drand(){ - return rand()/(real) RAND_MAX; +double drand(){ + return rand()/(double) RAND_MAX; } int irand(int n){ @@ -47,34 +47,34 @@ int *random_permutation(int n){ } -real* vector_subtract_to(int n, real *x, real *y){ +double* vector_subtract_to(int n, double *x, double *y){ /* y = x-y */ int i; for (i = 0; i < n; i++) y[i] = x[i] - y[i]; return y; } -real vector_product(int n, real *x, real *y){ - real res = 0; +double vector_product(int n, double *x, double *y){ + double res = 0; int i; for (i = 0; i < n; i++) res += x[i]*y[i]; return res; } -real* vector_saxpy(int n, real *x, real *y, real beta){ +double* vector_saxpy(int n, double *x, double *y, double beta){ /* y = x+beta*y */ int i; for (i = 0; i < n; i++) y[i] = x[i] + beta*y[i]; return y; } -real* vector_saxpy2(int n, real *x, real *y, real beta){ +double* vector_saxpy2(int n, double *x, double *y, double beta){ /* x = x+beta*y */ int i; for (i = 0; i < n; i++) x[i] = x[i] + beta*y[i]; return x; } -void vector_print(char *s, int n, real *x){ +void vector_print(char *s, int n, double *x){ int i; printf("%s{",s); for (i = 0; i < n; i++) { @@ -98,8 +98,8 @@ void vector_float_take(int n, float *v, int m, int *p, float **u){ } static int comp_ascend(const void *s1, const void *s2){ - const real *ss1 = s1; - const real *ss2 = s2; + const double *ss1 = s1; + const double *ss2 = s2; if ((ss1)[0] > (ss2)[0]){ return 1; @@ -121,23 +121,23 @@ static int comp_ascend_int(const void *s1, const void *s2){ return 0; } -void vector_ordering(int n, real *v, int **p){ +void vector_ordering(int n, double *v, int **p){ /* give the position of the smallest, second smallest etc in vector v. results in p. If *p == NULL, p is assigned. */ - real *u; + double *u; int i; if (!*p) *p = MALLOC(sizeof(int)*n); - u = MALLOC(sizeof(real)*2*n); + u = MALLOC(sizeof(double)*2*n); for (i = 0; i < n; i++) { u[2*i+1] = i; u[2*i] = v[i]; } - qsort(u, n, sizeof(real)*2, comp_ascend); + qsort(u, n, sizeof(double)*2, comp_ascend); for (i = 0; i < n; i++) (*p)[i] = (int) u[2*i+1]; free(u); @@ -147,25 +147,25 @@ void vector_sort_int(int n, int *v){ qsort(v, n, sizeof(int), comp_ascend_int); } -real distance_cropped(real *x, int dim, int i, int j){ +double distance_cropped(double *x, int dim, int i, int j){ int k; - real dist = 0.; + double dist = 0.; for (k = 0; k < dim; k++) dist += (x[i*dim+k] - x[j*dim + k])*(x[i*dim+k] - x[j*dim + k]); dist = sqrt(dist); return MAX(dist, MINDIST); } -real distance(real *x, int dim, int i, int j){ +double distance(double *x, int dim, int i, int j){ int k; - real dist = 0.; + double dist = 0.; for (k = 0; k < dim; k++) dist += (x[i*dim+k] - x[j*dim + k])*(x[i*dim+k] - x[j*dim + k]); dist = sqrt(dist); return dist; } -real point_distance(real *p1, real *p2, int dim){ +double point_distance(double *p1, double *p2, int dim){ int i; - real dist; + double dist; dist = 0; for (i = 0; i < dim; i++) dist += (p1[i] - p2[i])*(p1[i] - p2[i]); return sqrt(dist); @@ -187,8 +187,8 @@ char *strip_dir(char *s){ return s; } -void scale_to_box(real xmin, real ymin, real xmax, real ymax, int n, int dim, real *x){ - real min[3], max[3], min0[3], ratio = 1; +void scale_to_box(double xmin, double ymin, double xmax, double ymax, int n, int dim, double *x){ + double min[3], max[3], min0[3], ratio = 1; int i, k; for (i = 0; i < dim; i++) { diff --git a/lib/sparse/general.h b/lib/sparse/general.h index 9e2efad79..4828d5ef6 100644 --- a/lib/sparse/general.h +++ b/lib/sparse/general.h @@ -27,8 +27,6 @@ #include #endif /* STANDALONE */ -#define real double - #define set_flag(a, flag) ((a)=((a)|(flag))) #define test_flag(a, flag) ((a)&(flag)) #define clear_flag(a, flag) ((a) &=(~(flag))) @@ -72,18 +70,18 @@ extern double _statistics[10]; extern int irand(int n); -extern real drand(void); +extern double drand(void); extern int *random_permutation(int n);/* random permutation of 0 to n-1 */ -real* vector_subtract_to(int n, real *x, real *y);/* y = x-y */ +double* vector_subtract_to(int n, double *x, double *y);/* y = x-y */ -real vector_product(int n, real *x, real *y); +double vector_product(int n, double *x, double *y); -real* vector_saxpy(int n, real *x, real *y, real beta); /* y = x+beta*y */ +double* vector_saxpy(int n, double *x, double *y, double beta); /* y = x+beta*y */ -real* vector_saxpy2(int n, real *x, real *y, real beta);/* x = x+beta*y */ +double* vector_saxpy2(int n, double *x, double *y, double beta);/* x = x+beta*y */ /* take m elements v[p[i]]],i=1,...,m and oput in u. u will be assigned if *u = NULL */ void vector_float_take(int n, float *v, int m, int *p, float **u); @@ -91,10 +89,10 @@ void vector_float_take(int n, float *v, int m, int *p, float **u); /* give the position of the smallest, second smallest etc in vector v. results in p. If *p == NULL, p is assigned. */ -void vector_ordering(int n, real *v, int **p); +void vector_ordering(int n, double *v, int **p); void vector_sort_int(int n, int *v); -void vector_print(char *s, int n, real *x); +void vector_print(char *s, int n, double *x); #define MACHINEACC 1.0e-16 #define SQRT_MACHINEACC 1.0e-8 @@ -104,11 +102,11 @@ void vector_print(char *s, int n, real *x); enum {UNMATCHED = -1}; -real distance(real *x, int dim, int i, int j); -real distance_cropped(real *x, int dim, int i, int j); +double distance(double *x, int dim, int i, int j); +double distance_cropped(double *x, int dim, int i, int j); -real point_distance(real *p1, real *p2, int dim); +double point_distance(double *p1, double *p2, int dim); char *strip_dir(char *s); -void scale_to_box(real xmin, real ymin, real xmax, real ymax, int n, int dim, real *x); +void scale_to_box(double xmin, double ymin, double xmax, double ymax, int n, int dim, double *x); diff --git a/lib/sparse/mq.c b/lib/sparse/mq.c index cd34e4dd4..59275f3b1 100644 --- a/lib/sparse/mq.c +++ b/lib/sparse/mq.c @@ -62,7 +62,7 @@ #include #include -static real get_mq(SparseMatrix A, int *assignment, int *ncluster0, real *mq_in0, real *mq_out0, real **dout0){ +static double get_mq(SparseMatrix A, int *assignment, int *ncluster0, double *mq_in0, double *mq_out0, double **dout0){ /* given a symmetric matrix representation of a graph and an assignment of nodes into clusters, calculate the modularity quality. assignment: assignmenet[i] gives the cluster assignment of node i. 0 <= assignment[i] < ncluster. ncluster: number of clusters @@ -74,14 +74,14 @@ static real get_mq(SparseMatrix A, int *assignment, int *ncluster0, real *mq_in0 int n = A->m; int test_pattern_symmetry_only = FALSE; int *counts, *ia = A->ia, *ja = A->ja, k, i, j, jj; - real mq_in = 0, mq_out = 0, *a = NULL, Vi, Vj; + double mq_in = 0, mq_out = 0, *a = NULL, Vi, Vj; int c; - real *dout; + double *dout; assert(SparseMatrix_is_symmetric(A, test_pattern_symmetry_only)); assert(A->n == n); - if (A->type == MATRIX_TYPE_REAL) a = (real*) A->a; + if (A->type == MATRIX_TYPE_REAL) a = (double*) A->a; counts = CALLOC(n, sizeof(int)); @@ -121,16 +121,16 @@ static real get_mq(SparseMatrix A, int *assignment, int *ncluster0, real *mq_in0 } /* calculate scaled out degree */ - dout = MALLOC(sizeof(real)*n); + dout = MALLOC(sizeof(double)*n); for (i = 0; i < n; i++){ dout[i] = 0; for (j = ia[i]; j < ia[i+1]; j++){ jj = ja[j]; if (jj == i) continue; if (a){ - dout[i] += a[j]/(real) counts[assignment[jj]]; + dout[i] += a[j]/(double) counts[assignment[jj]]; } else { - dout[i] += 1./(real) counts[assignment[jj]]; + dout[i] += 1./(double) counts[assignment[jj]]; } } } @@ -167,20 +167,20 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_init(SparseMatrix A, in grid->next = NULL; grid->prev = NULL; grid->delete_top_level_A = FALSE; - matching = grid->matching = MALLOC(sizeof(real)*(n)); + matching = grid->matching = MALLOC(sizeof(double)*(n)); grid->deg_intra = NULL; grid->dout = NULL; grid->wgt = NULL; if (level == 0){ - real mq = 0, mq_in, mq_out; + double mq = 0, mq_in, mq_out; int n = A->n, ncluster; - real *deg_intra, *wgt, *dout; + double *deg_intra, *wgt, *dout; - grid->deg_intra = MALLOC(sizeof(real)*(n)); + grid->deg_intra = MALLOC(sizeof(double)*(n)); deg_intra = grid->deg_intra; - grid->wgt = MALLOC(sizeof(real)*n); + grid->wgt = MALLOC(sizeof(double)*n); wgt = grid->wgt; for (i = 0; i < n; i++){ @@ -225,16 +225,16 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ int *matching = grid->matching; SparseMatrix A = grid->A; int n = grid->n, level = grid->level, nc = 0, nclusters = n; - real mq = 0, mq_in = 0, mq_out = 0, mq_new, mq_in_new, mq_out_new, mq_max = 0, mq_in_max = 0, mq_out_max = 0; + double mq = 0, mq_in = 0, mq_out = 0, mq_new, mq_in_new, mq_out_new, mq_max = 0, mq_in_max = 0, mq_out_max = 0; int *ia = A->ia, *ja = A->ja; - real *a, amax = 0; - real *deg_intra = grid->deg_intra, *wgt = grid->wgt; - real *deg_intra_new, *wgt_new = NULL; + double *a, amax = 0; + double *deg_intra = grid->deg_intra, *wgt = grid->wgt; + double *deg_intra_new, *wgt_new = NULL; int i, j, k, jj, jc, jmax; - real *deg_inter, gain = 0, *dout = grid->dout, *dout_new, deg_in_i, deg_in_j, wgt_i, wgt_j, a_ij, dout_i, dout_j, dout_max = 0, wgt_jmax = 0; + double *deg_inter, gain = 0, *dout = grid->dout, *dout_new, deg_in_i, deg_in_j, wgt_i, wgt_j, a_ij, dout_i, dout_j, dout_max = 0, wgt_jmax = 0; int *mask; - real maxgain = 0; - real total_gain = 0; + double maxgain = 0; + double total_gain = 0; SingleLinkedList *neighbors = NULL, lst; @@ -245,11 +245,11 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ mq_in = grid->mq_in; mq_out = grid->mq_out; - deg_intra_new = MALLOC(sizeof(real)*n); - wgt_new = MALLOC(sizeof(real)*n); - deg_inter = MALLOC(sizeof(real)*n); + deg_intra_new = MALLOC(sizeof(double)*n); + wgt_new = MALLOC(sizeof(double)*n); + deg_inter = MALLOC(sizeof(double)*n); mask = MALLOC(sizeof(int)*n); - dout_new = MALLOC(sizeof(real)*n); + dout_new = MALLOC(sizeof(double)*n); for (i = 0; i < n; i++) mask[i] = -1; assert(n == A->n); @@ -279,7 +279,7 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ mq_new = mq_in_new/(k-1) - mq_out_new/((k-1)*(k-2)) gain = mq_new - mq */ - a = (real*) A->a; + a = (double*) A->a; for (i = 0; i < n; i++){ if (matching[i] != UNMATCHED) continue; /* accumulate connections between i and clusters */ @@ -336,7 +336,7 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ double mq2, mq_in2, mq_out2, *dout2; int *matching2, nc2 = nc; matching2 = MALLOC(sizeof(int)*A->m); - memcpy(matching2, matching, sizeof(real)*A->m); + memcpy(matching2, matching, sizeof(double)*A->m); if (jc != UNMATCHED) { matching2[i] = jc; } else { @@ -454,7 +454,7 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ if (nc >= 1 && (total_gain > 0 || nc < n)){ /* now set up restriction and prolongation operator */ SparseMatrix P, R, R0, B, cA; - real one = 1.; + double one = 1.; Multilevel_MQ_Clustering cgrid; R0 = SparseMatrix_new(nc, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD); @@ -484,12 +484,12 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ grid->R = R; level++; cgrid = Multilevel_MQ_Clustering_init(cA, level); - deg_intra_new = REALLOC(deg_intra_new, nc*sizeof(real)); - wgt_new = REALLOC(wgt_new, nc*sizeof(real)); + deg_intra_new = REALLOC(deg_intra_new, nc*sizeof(double)); + wgt_new = REALLOC(wgt_new, nc*sizeof(double)); cgrid->deg_intra = deg_intra_new; cgrid->mq = grid->mq + total_gain; cgrid->wgt = wgt_new; - dout_new = REALLOC(dout_new, nc*sizeof(real)); + dout_new = REALLOC(dout_new, nc*sizeof(double)); cgrid->dout = dout_new; cgrid = Multilevel_MQ_Clustering_establish(cgrid, maxcluster); @@ -534,7 +534,7 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_new(SparseMatrix A0, in static void hierachical_mq_clustering(SparseMatrix A, int maxcluster, - int *nclusters, int **assignment, real *mq, int *flag){ + int *nclusters, int **assignment, double *mq, int *flag){ /* find a clustering of vertices by maximize mq A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1. maxcluster: used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters @@ -546,7 +546,7 @@ static void hierachical_mq_clustering(SparseMatrix A, int maxcluster, Multilevel_MQ_Clustering grid, cgrid; int *matching, i; SparseMatrix P; - real *u; + double *u; assert(A->m == A->n); *mq = 0.; @@ -562,13 +562,13 @@ static void hierachical_mq_clustering(SparseMatrix A, int maxcluster, } /* project clustering up */ - u = MALLOC(sizeof(real)*cgrid->n); - for (i = 0; i < cgrid->n; i++) u[i] = (real) (cgrid->matching)[i]; + u = MALLOC(sizeof(double)*cgrid->n); + for (i = 0; i < cgrid->n; i++) u[i] = (double) (cgrid->matching)[i]; *nclusters = cgrid->n; *mq = cgrid->mq; while (cgrid->prev){ - real *v = NULL; + double *v = NULL; P = cgrid->prev->P; SparseMatrix_multiply_vector(P, u, &v, FALSE); free(u); @@ -591,7 +591,7 @@ static void hierachical_mq_clustering(SparseMatrix A, int maxcluster, void mq_clustering(SparseMatrix A, int inplace, int maxcluster, int use_value, - int *nclusters, int **assignment, real *mq, int *flag){ + int *nclusters, int **assignment, double *mq, int *flag){ /* find a clustering of vertices by maximize mq A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1. inplace: whether A can e modified. If true, A will be modified by removing diagonal. diff --git a/lib/sparse/mq.h b/lib/sparse/mq.h index d2b3795b9..5563e0002 100644 --- a/lib/sparse/mq.h +++ b/lib/sparse/mq.h @@ -31,13 +31,13 @@ struct Multilevel_MQ_Clustering_struct { . = mq_in/k - mq_out/(k*(k-1)) */ - real mq; - real mq_in, mq_out;/* mqs(A) = deg_in(A)/|A|^2 - deg_out(A)/|A|/(|V|-|A|) */ + double mq; + double mq_in, mq_out;/* mqs(A) = deg_in(A)/|A|^2 - deg_out(A)/|A|/(|V|-|A|) */ int ncluster; /* number of clusters */ - real *deg_intra;/* dimension n. deg[i] equal to the sum of edge weights within cluster i */ - real *dout;/* dimension n, dout[i] = \sum_{j -- i} a(i,j)/|j| is the scaled sum of outdegree */ - real *wgt; /* total vertex weight each coarse grid vertex represent */ + double *deg_intra;/* dimension n. deg[i] equal to the sum of edge weights within cluster i */ + double *dout;/* dimension n, dout[i] = \sum_{j -- i} a(i,j)/|j| is the scaled sum of outdegree */ + double *wgt; /* total vertex weight each coarse grid vertex represent */ }; /* find a clustering of vertices by maximize modularity quality @@ -54,4 +54,4 @@ struct Multilevel_MQ_Clustering_struct { mq: achieve modularity */ void mq_clustering(SparseMatrix A, int inplace, int maxcluster, int use_value, - int *nclusters, int **assignment, real *mq, int *flag); + int *nclusters, int **assignment, double *mq, int *flag);