Commits

Oliver Gu committed a15511e

Use explicit loop in Stats.calc_scc to speed up computation.

Comments (0)

Files changed (1)

 
   let calc_scc ~expected ~predicted =
     check_dimension expected predicted ~location:"calc_scc";
-    let array_x = Vec.to_array predicted in
-    let array_y = Vec.to_array expected in   (* true values *)
+    let l = Vec.dim expected in
+    let x = predicted in
+    let y = expected  in  (* true values *)
     let sum_x  = ref 0. in
     let sum_y  = ref 0. in
     let sum_xx = ref 0. in
     let sum_yy = ref 0. in
     let sum_xy = ref 0. in
-    Array.iter2_exn array_x array_y ~f:(fun x y ->
-      sum_x  := !sum_x  +. x;
-      sum_y  := !sum_y  +. y;
-      sum_xx := !sum_xx +. x *. x;
-      sum_yy := !sum_yy +. y *. y;
-      sum_xy := !sum_xy +. x *. y;
-    );
+    for i = 1 to l do
+      sum_x  := !sum_x  +. x.{i};
+      sum_y  := !sum_y  +. y.{i};
+      sum_xx := !sum_xx +. x.{i} *. x.{i};
+      sum_yy := !sum_yy +. y.{i} *. y.{i};
+      sum_xy := !sum_xy +. x.{i} *. y.{i};
+    done;
     let sqr x = x *. x in
-    let l = float (Vec.dim expected) in
+    let l = float l in
     Float.(sqr (l * !sum_xy - !sum_x * !sum_y) /
              ((l * !sum_xx - sqr !sum_x) * (l * !sum_yy - sqr !sum_y)))
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.