]> granicus.if.org Git - graphviz/commitdiff
inline and fuse a number of loops in majorization code
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 15 Oct 2020 02:32:58 +0000 (19:32 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 22 Oct 2020 00:08:43 +0000 (17:08 -0700)
This accelerates the Neato example from #1652 by ~9.5%.

lib/neatogen/stress.c

index f43ecb39b3bab82c59bda2c497874db419b9a404..8d840e8952cdda56763bd310e95d1cfe4c2101cb 100644 (file)
@@ -1166,12 +1166,11 @@ int stress_majorization_kD_mkernel(vtx_data * graph,    /* Input graph in sparse re
 
            /* put into 'dist_accumulator' all squared distances between 'i' and 'i'+1,...,'n'-1 */
            for (k = 0; k < dim; k++) {
-               set_vector_valf(len, coords[k][i], tmp_coords);
-               vectors_mult_additionf(len, tmp_coords, -1,
-                                      coords[k] + i + 1);
-               square_vec(len, tmp_coords);
-               vectors_additionf(len, tmp_coords, dist_accumulator,
-                                 dist_accumulator);
+               size_t x;
+               for (x = 0; x < (size_t)len; ++x) {
+                   float tmp = coords[k][i] + -1.0f * (coords[k] + i + 1)[x];
+                   dist_accumulator[x] += tmp * tmp;
+               }
            }
 
            /* convert to 1/d_{ij} */