Skip to content

Commit 3053d32

Browse files
committed
Try rounding numerically to avoid discrepancies in float rendering
1 parent cd49f71 commit 3053d32

File tree

7 files changed

+2232
-2229
lines changed

7 files changed

+2232
-2229
lines changed

arrayjit/lib/ndarray.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,12 @@ let log_debug_info ~from_log_level:_level _nd =
445445
has_neg_inf || Float.(v = neg_infinity))
446446
: bool)]]]]
447447

448+
let round_to_precision x prec =
449+
let factor = 10.0 **. Float.of_int prec in
450+
Float.round (x *. factor) /. factor
451+
448452
let concise_float ~prec v =
453+
let v = round_to_precision v prec in
449454
let s = Printf.sprintf "%.*e" prec v in
450455
(* The C99 standard requires at least two digits for the exponent, but the leading zero is a waste
451456
of space. Also handle dangling e+ for 0.0 *)

test/einsum_trivia.ml

Lines changed: 1264 additions & 1264 deletions
Large diffs are not rendered by default.

test/hello_world_op.ml

Lines changed: 375 additions & 376 deletions
Large diffs are not rendered by default.

test/micrograd_demo.ml

Lines changed: 160 additions & 160 deletions
Large diffs are not rendered by default.

test/ocannl_config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
randomness_lib=for_tests
22
log_main_domain_to_stdout=true
33
backend=cc
4-
log_level=0
5-
print_decimals_precision=5
4+
log_level=0

test/primitive_ops.ml

Lines changed: 225 additions & 225 deletions
Large diffs are not rendered by default.

test/zero2hero_1of7.ml

Lines changed: 202 additions & 202 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)