]> granicus.if.org Git - graphviz/commitdiff
use fabs() instead of ABS() for taking the absolute value of reals
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 26 Aug 2020 00:50:39 +0000 (17:50 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 1 Sep 2020 00:11:57 +0000 (17:11 -0700)
The type real is #defined to double, so we can use the same replacement as in
b88ebe0548dd412ea415d6cfc410d91117270277 to simplify this code.

cmd/tools/mm2gv.c
lib/edgepaint/edge_distinct_coloring.c
lib/edgepaint/intersection.c
lib/mingle/agglomerative_bundling.c
lib/mingle/edge_bundling.c
lib/neatogen/overlap.c
lib/sfdpgen/sparse_solve.c
lib/sfdpgen/spring_electrical.c
lib/sfdpgen/uniform_stress.c
lib/sparse/DotIO.c
lib/sparse/SparseMatrix.c

index 9bd0baa9d07cffed535da9ceed2156e98f1e7682..b4c3300efe6e866e972c203d8fca0597a6d79395 100644 (file)
@@ -305,7 +305,7 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim,
                }
            } else {
                for (j = ia[i]; j < ia[i + 1]; j++) {
-                   if (val) color[j] = ABS(val[j]);
+                   if (val) color[j] = fabs(val[j]);
                    else color[j] = 1;
                    if (i != ja[j]) {
                        if (first) {
index f5b4d175d8bf3ceaf556dcfcee9cac22db0f330c..72916b2b9172dcb61f93b26147147620095a0d0d 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: See CVS logs. Details at http://www.graphviz.org/
  *************************************************************************/
 #include "general.h"
+#include <math.h>
 #include "time.h"
 #include "SparseMatrix.h"
 #include "node_distinct_coloring.h"
@@ -142,7 +143,7 @@ static int splines_intersect(int dim, int u1, int v1, int u2, int v2,
 for (i = 0; i < ns1 - 1; i++){
     for (j = 0; j < ns2 - 1; j++){
       cos_a = intersection_angle(&(x1[dim*i]), &(x1[dim*(i + 1)]), &(x2[dim*j]), &(x2[dim*(j+1)]));
-      if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = ABS(cos_a);
+      if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = fabs(cos_a);
       if (cos_a > cos_critical) {
        return 1;
       }
@@ -235,7 +236,7 @@ Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t*
       for (j = i+1; j < nz2; j++){
        u2 = irn[j]; v2 = jcn[j];
        cos_a = intersection_angle(&(x[dim*u1]), &(x[dim*v1]), &(x[dim*u2]), &(x[dim*v2]));
-       if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = ABS(cos_a);
+       if (!check_edges_with_same_endpoint && cos_a >= -1) cos_a = fabs(cos_a);
        if (cos_a > cos_critical) {
          B = SparseMatrix_coordinate_form_add_entries(B, 1, &i, &j, &cos_a);
        }
index 1c946e789d0ec3a46f50865dc7a397dfad6687fd..4e18a4772041f25dd45766b96225c20b239e7137 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: See CVS logs. Details at http://www.graphviz.org/
  *************************************************************************/
 #include "general.h"
+#include <math.h>
 
 static real cross(real *u, real *v){
   return u[0]*v[1] - u[1]*v[0];
@@ -144,7 +145,7 @@ real intersection_angle(real *p1, real *p2, real *q1, real *q2){
   snorm = sqrt(snorm);
   b = cross(r, s);
   line_dist_close = (line_segments_distance(p1, p2, q1, q2)  <= close*MAX(rnorm, snorm));
-  if (ABS(b) <= epsilon*snorm*rnorm){/* parallel */
+  if (fabs(b) <= epsilon*snorm*rnorm){/* parallel */
     if (line_dist_close) {/* two parallel lines that are close */
       return 1;
     }
@@ -173,7 +174,7 @@ real intersection_angle(real *p1, real *p2, real *q1, real *q2){
     }
 
     /* normal case of intersect or very close */
-    return ABS(res);
+    return fabs(res);
   }
   return -2;/* no intersection, and lines are not even close */
 }
index c3cdd3a7713bae33da72dd9f50f6e9bdc94c50fd..a3bed7f977714f83fb8ffd04519dda485fe46287 100644 (file)
@@ -11,6 +11,7 @@
 #include "types.h"
 #include "globals.h"
 #include "general.h"
+#include <math.h>
 #include "time.h"
 #include "SparseMatrix.h"
 #include "vector.h"
@@ -276,7 +277,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_establish(Agglomera
 
     if (Verbose > 1) fprintf(stderr,"level %d->%d, edges %d -> %d, ink %f->%f , gain = %f, or %f\n", grid->level, cgrid->level, grid->n, 
                         cgrid->n, grid->total_ink, grand_total_ink, grid->total_ink - grand_total_ink, grand_total_gain);       
-    assert(ABS(grid->total_ink - cgrid->total_ink - grand_total_gain) <= 0.0001*grid->total_ink);
+    assert(fabs(grid->total_ink - cgrid->total_ink - grand_total_gain) <= 0.0001*grid->total_ink);
 
     cgrid = Agglomerative_Ink_Bundling_establish(cgrid, pick, angle_param, angle);
     grid->next = cgrid;
@@ -524,7 +525,7 @@ static Agglomerative_Ink_Bundling Agglomerative_Ink_Bundling_aggressive_establis
 
     if (Verbose > 1) fprintf(stderr,"level %d->%d, edges %d -> %d, ink %f->%f , gain = %f, or %f\n", grid->level, cgrid->level, grid->n, 
                         cgrid->n, grid->total_ink, grand_total_ink, grid->total_ink - grand_total_ink, grand_total_gain);       
-    assert(ABS(grid->total_ink - cgrid->total_ink - grand_total_gain) <= 0.0001*grid->total_ink);
+    assert(fabs(grid->total_ink - cgrid->total_ink - grand_total_gain) <= 0.0001*grid->total_ink);
 
     cgrid = Agglomerative_Ink_Bundling_aggressive_establish(cgrid, pick, angle_param, angle);
     grid->next = cgrid;
@@ -623,7 +624,7 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge
        if (Verbose && DEBUG) fprintf(stderr,"calling ink2...\n");
        ink1 = ink(edges, ia[i+1]-ia[i], pick, &ink0, &meet1, &meet2, angle_param, angle);
        if (Verbose && DEBUG) fprintf(stderr,"finish calling ink2...\n");
-       assert(ABS(ink1 - cgrid->inks[i])<=MAX(TOL, TOL*ink1) && ink1 - ink0 <= TOL);
+       assert(fabs(ink1 - cgrid->inks[i])<=MAX(TOL, TOL*ink1) && ink1 - ink0 <= TOL);
        wgt_all = 0.;
        if (ia[i+1]-ia[i] > 1){
          for (j = ia[i]; j < ia[i+1]; j++){
@@ -682,7 +683,7 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge
       if (Verbose && DEBUG) fprintf(stderr,"calling ink3...\n");
       ink1 = ink(edges, ia[i+1]-ia[i], pick, &ink0, &meet1, &meet2, angle_param, angle);
       if (Verbose && DEBUG) fprintf(stderr,"done calling ink3...\n");
-      assert(ABS(ink1 - cgrid->inks[i])<=MAX(TOL, TOL*ink1) && ink1 - ink0 <= TOL);
+      assert(fabs(ink1 - cgrid->inks[i])<=MAX(TOL, TOL*ink1) && ink1 - ink0 <= TOL);
       xx[i*4 + 0] = meet1.x;
       xx[i*4 + 1] = meet1.y;
       xx[i*4 + 2] = meet2.x;
index 4cfb157c2b8054308a695296041b4284ef516313..fb3d5c18309c885ea599bf90640be499748e5615 100644 (file)
@@ -13,6 +13,7 @@
 #include "types.h"
 #include "globals.h"
 #include "general.h"
+#include <math.h>
 #include "SparseMatrix.h"
 #include "edge_bundling.h"
 #include <time.h>
@@ -162,7 +163,7 @@ static real edge_compatibility_full(pedge e1, pedge e2){
   ca = 0;
   for (i = 0; i < dim; i++) 
     ca += (v1[i]-u1[i])*(v2[i]-u2[i]);
-  ca = ABS(ca/(len1*len2));
+  ca = fabs(ca/(len1*len2));
   assert(ca > -0.001);
 
   /* scale compatibility */
@@ -634,13 +635,6 @@ static pedge* force_directed_edge_bundling(SparseMatrix A, pedge* edges, int max
   return edges;
 }
 
-static real absfun(real x){
-  return ABS(x);
-}
-
-
-
-
 static pedge* modularity_ink_bundling(int dim, int ne, SparseMatrix B, pedge* edges, real angle_param, real angle){
   int *assignment = NULL, flag, nclusters;
   real modularity;
@@ -658,7 +652,7 @@ static pedge* modularity_ink_bundling(int dim, int ne, SparseMatrix B, pedge* ed
 
   /* B may contain negative entries */
   BB = SparseMatrix_copy(B);
-  BB = SparseMatrix_apply_fun(BB, absfun);
+  BB = SparseMatrix_apply_fun(BB, fabs);
   modularity_clustering(BB, TRUE, 0, use_value_for_clustering, &nclusters, &assignment, &modularity, &flag);
   SparseMatrix_delete(BB);
 
@@ -735,7 +729,7 @@ static SparseMatrix check_compatibility(SparseMatrix A, int ne, pedge *edges, in
       fprintf(stderr,"compatibility=%f\n",dist);
       */
 
-      if (ABS(dist) > tol){
+      if (fabs(dist) > tol){
        B = SparseMatrix_coordinate_form_add_entries(B, 1, &i, &jj, &dist);
        B = SparseMatrix_coordinate_form_add_entries(B, 1, &jj, &i, &dist);
       }
index 7e7b48fc42b88d9224498d91fe805a06e2c579a4..a6a10c4d38aeabe5647ddcbaead36d308baf2fb0 100644 (file)
@@ -20,6 +20,7 @@
 #include "call_tri.h"
 #include "red_black_tree.h"
 #include "types.h"
+#include <math.h>
 #include "memory.h"
 #include "globals.h"
 #include <time.h>
@@ -43,8 +44,8 @@ static void ideal_distance_avoid_overlap(int dim, SparseMatrix A, real *x, real
       jj = ja[j];
       if (jj == i) continue;
       dist = distance(x, dim, i, jj);
-      dx = ABS(x[i*dim] - x[jj*dim]);
-      dy = ABS(x[i*dim+1] - x[jj*dim+1]);
+      dx = fabs(x[i*dim] - x[jj*dim]);
+      dy = fabs(x[i*dim+1] - x[jj*dim+1]);
       wx = width[i*dim]+width[jj*dim];
       wy = width[i*dim+1]+width[jj*dim+1];
       if (dx < MACHINEACC*wx && dy < MACHINEACC*wy){
@@ -212,7 +213,7 @@ static SparseMatrix get_overlap_graph(int dim, int n, real *x, real *width, int
        fprintf(stderr," predecessor is node %d y = %f\n", ((scan_point *)newNode->key)->node, ((scan_point *)newNode->key)->x);
 #endif
        if (neighbor != k){
-         if (ABS(0.5*(bsta+bsto) - 0.5*(bbsta+bbsto)) < 0.5*(bsto-bsta) + 0.5*(bbsto-bbsta)){/* if the distance of the centers of the interval is less than sum of width, we have overlap */
+         if (fabs(0.5*(bsta+bsto) - 0.5*(bbsta+bbsto)) < 0.5*(bsto-bsta) + 0.5*(bbsto-bbsta)){/* if the distance of the centers of the interval is less than sum of width, we have overlap */
            A = SparseMatrix_coordinate_form_add_entries(A, 1, &neighbor, &k, &one);
 #ifdef DEBUG_RBTREE
            fprintf(stderr,"======================================  %d %d\n",k,neighbor);
index e4fe63dc0bd235729c015aeb7f130a5b84708aaa..1a81ab6ef1e004fe107f5245f819c9120a7f1c2d 100644 (file)
@@ -116,7 +116,7 @@ Operator Operator_uniform_stress_diag_precon_new(SparseMatrix A, real alpha){
   for (i = 0; i < m; i++){
     diag[i] = 1./(m-1);
     for (j = ia[i]; j < ia[i+1]; j++){
-      if (i == ja[j] && ABS(a[j]) > 0) diag[i] = 1./((m-1)*alpha+a[j]);
+      if (i == ja[j] && fabs(a[j]) > 0) diag[i] = 1./((m-1)*alpha+a[j]);
     }
   }
 
@@ -145,7 +145,7 @@ static Operator Operator_diag_precon_new(SparseMatrix A){
   for (i = 0; i < m; i++){
     diag[i] = 1.;
     for (j = ia[i]; j < ia[i+1]; j++){
-      if (i == ja[j] && ABS(a[j]) > 0) diag[i] = 1./a[j];
+      if (i == ja[j] && fabs(a[j]) > 0) diag[i] = 1./a[j];
     }
   }
 
index d0c4d48942a3f9d74ced48372db9062aae29aa94..e44bc684d347672bd7f6d357fb3f5c0ca3ee049c 100644 (file)
@@ -339,7 +339,7 @@ static real get_angle(real *x, int dim, int i, int j){
   for (k = 0; k < 2; k++){
     y[k] = x[j*dim+k] - x[i*dim+k];
   }
-  if (ABS(y[0]) <= ABS(y[1])*eps){
+  if (fabs(y[0]) <= fabs(y[1])*eps){
     if (y[1] > 0) return 0.5*PI;
     return 1.5*PI;
   }
index 1fc19b2082559ce2e45d01d1c705536e1c3df1ce..20e6f9b395df61d0a84a2fd8a6040accbc8f8ece 100644 (file)
@@ -12,6 +12,7 @@
  *************************************************************************/
 
 #include "general.h"
+#include <math.h>
 #include "SparseMatrix.h"
 #include "spring_electrical.h"
 #include "post_process.h"
@@ -70,7 +71,7 @@ UniformStressSmoother UniformStressSmoother_new(int dim, SparseMatrix A, real *x
     for (j = ia[i]; j < ia[i+1]; j++){
       k = ja[j];
       if (k != i){
-       dist = MAX(ABS(a[j]), epsilon);
+       dist = MAX(fabs(a[j]), epsilon);
        jd[nz] = jw[nz] = k;
        w[nz] = -1/(dist*dist);
        w[nz] = -1.;
@@ -144,7 +145,7 @@ void uniform_stress(int dim, SparseMatrix A, real *x, int *flag){
   /* make sure x is not all at the same point */
   for (i = 1; i < n; i++){
     for (k = 0; k < dim; k++) {
-      if (ABS(x[0*dim+k] - x[i*dim+k]) > MACHINEACC){
+      if (fabs(x[0*dim+k] - x[i*dim+k]) > MACHINEACC){
        samepoint = FALSE;
        i = n;
        break;
index ad80d5882c8643ba08238b0256660af087d4c20a..68c9dde59c7484216ece685adc729364b1e9a227 100644 (file)
@@ -15,6 +15,7 @@
 #include "general.h"
 #include "DotIO.h"
 #include "clustering.h"
+#include <math.h>
 #include "mq.h"
 /* #include "spring_electrical.h" */
 #include "color_palette.h"
@@ -566,7 +567,7 @@ makeDotGraph (SparseMatrix A, char *name, int dim, real *x, int with_color, int
        }
       } else {
        for (j = ia[i]; j < ia[i+1]; j++) {
-         color[j] = ABS(val[j]);
+         color[j] = fabs(val[j]);
          if (i != ja[j]){
            if (first){
              mindist = color[j];
index 2f89f7336901f67ff3e1469815812007db47c8b2..07565c9d0c5acbc359210f73ab5b05e895396244 100644 (file)
@@ -219,7 +219,7 @@ int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only){
        if (mask[jb[j]] < ia[i]) goto RETURN;
       }
       for (j = ib[i]; j < ib[i+1]; j++){
-       if (ABS(b[j] - a[mask[jb[j]]]) > SYMMETRY_EPSILON) goto RETURN;
+       if (fabs(b[j] - a[mask[jb[j]]]) > SYMMETRY_EPSILON) goto RETURN;
       }
     }
     res = TRUE;
@@ -237,8 +237,8 @@ int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only){
        if (mask[jb[j]] < ia[i]) goto RETURN;
       }
       for (j = ib[i]; j < ib[i+1]; j++){
-       if (ABS(b[2*j] - a[2*mask[jb[j]]]) > SYMMETRY_EPSILON) goto RETURN;
-       if (ABS(b[2*j+1] - a[2*mask[jb[j]]+1]) > SYMMETRY_EPSILON) goto RETURN;
+       if (fabs(b[2*j] - a[2*mask[jb[j]]]) > SYMMETRY_EPSILON) goto RETURN;
+       if (fabs(b[2*j+1] - a[2*mask[jb[j]]+1]) > SYMMETRY_EPSILON) goto RETURN;
       }
     }
     res = TRUE;
@@ -2285,7 +2285,7 @@ SparseMatrix SparseMatrix_normalize_by_row(SparseMatrix A){
   for (i = 0; i < A->m; i++){
     max = 0;
     for (j = A->ia[i]; j < A->ia[i+1]; j++){
-      max = MAX(ABS(a[j]), max);
+      max = MAX(fabs(a[j]), max);
     }
     if (max != 0){
       for (j = A->ia[i]; j < A->ia[i+1]; j++){
@@ -2413,7 +2413,7 @@ SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon){
     real *a = (real*) A->a;
     for (i = 0; i < A->m; i++){
       for (j = sta; j < ia[i+1]; j++){
-       if (ABS(a[j]) > epsilon){
+       if (fabs(a[j]) > epsilon){
          ja[nz] = ja[j];
          a[nz++] = a[j];
        }
@@ -2445,7 +2445,7 @@ SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon){
     int *a = (int*) A->a;
     for (i = 0; i < A->m; i++){
       for (j = sta; j < ia[i+1]; j++){
-       if (ABS(a[j]) > epsilon){
+       if (fabs(a[j]) > epsilon){
          ja[nz] = ja[j];
          a[nz++] = a[j];
        }
@@ -2688,14 +2688,14 @@ static int Dijkstra_internal(SparseMatrix A, int root, real *dist, int *nlist, i
 
       if (heap_id == UNVISITED){
        ndata = MALLOC(sizeof(struct nodedata_struct));
-       ndata->dist = ABS(a[j]) + ndata_min->dist;
+       ndata->dist = fabs(a[j]) + ndata_min->dist;
        ndata->id = jj;
        heap_ids[jj] = BinaryHeap_insert(h, ndata);
        //fprintf(stderr," set neighbor id=%d, dist=%f, hid = %d, a[%d]=%f, dist=%f\n",jj, ndata->dist, heap_ids[jj], jj, a[j], ndata->dist);
 
       } else {
        ndata = BinaryHeap_get_item(h, heap_id);
-       ndata->dist = MIN(ndata->dist, ABS(a[j]) + ndata_min->dist);
+       ndata->dist = MIN(ndata->dist, fabs(a[j]) + ndata_min->dist);
        assert(ndata->id == jj);
        BinaryHeap_reset(h, heap_id, ndata); 
        //fprintf(stderr," reset neighbor id=%d, dist=%f, hid = %d, a[%d]=%f, dist=%f\n",jj, ndata->dist,heap_id, jj, a[j], ndata->dist);
@@ -2760,7 +2760,7 @@ real SparseMatrix_pseudo_diameter_weighted(SparseMatrix A0, int root, int aggres
   } while (dist_max > dist0);
 
   *connectedQ = (!flag);
-  assert((dist_max - dist0)/MAX(1, MAX(ABS(dist0), ABS(dist_max))) < 1.e-10);
+  assert((dist_max - dist0)/MAX(1, MAX(fabs(dist0), fabs(dist_max))) < 1.e-10);
 
   *end1 = root;
   *end2 = list[nlist-1];
@@ -4131,7 +4131,7 @@ void SparseMatrix_page_rank(SparseMatrix A, real teleport_probablity, int weight
     for (i = 0; i < n; i++){
       for (j = ia[i]; j < ia[i+1]; j++){
        if (ja[j] == i) continue;
-       diag[i] += ABS(a[j]);
+       diag[i] += fabs(a[j]);
       }
     }
   } else {
@@ -4176,7 +4176,7 @@ void SparseMatrix_page_rank(SparseMatrix A, real teleport_probablity, int weight
     */
 
     res = 0;
-    for (i = 0; i < n; i++) res += ABS(x[i] - y[i]);
+    for (i = 0; i < n; i++) res += fabs(x[i] - y[i]);
     if (Verbose) fprintf(stderr,"page rank iter -- %d, res = %f\n",iter, res);
     memcpy(x, y, sizeof(real)*n);
   } while (res > epsilon);