diff options
author | Roman Grundkiewicz <rgrundki@exseed.ed.ac.uk> | 2018-02-25 14:38:35 +0300 |
---|---|---|
committer | Roman Grundkiewicz <rgrundki@exseed.ed.ac.uk> | 2018-02-25 14:38:35 +0300 |
commit | 28cdc29e700a8905aec2331dd32b39d0543f5965 (patch) | |
tree | 7a05da1b46de23ddddaf8685aebcf39e31fff03b | |
parent | 7d7452aaff17436a7c3dfd45c91af48dc0509224 (diff) |
Add --abs option to diff-floats.py
-rw-r--r-- | tests/training/restart/adam_async.mt.expected | 2 | ||||
-rw-r--r-- | tests/training/restart/adam_async.vt.expected | 2 | ||||
-rw-r--r-- | tests/training/restart/test_saving_adam_params_async.sh | 4 | ||||
-rwxr-xr-x | tools/diff-floats.py | 15 |
4 files changed, 15 insertions, 8 deletions
diff --git a/tests/training/restart/adam_async.mt.expected b/tests/training/restart/adam_async.mt.expected index 119d79b..17642ad 100644 --- a/tests/training/restart/adam_async.mt.expected +++ b/tests/training/restart/adam_async.mt.expected @@ -1 +1 @@ -[[ 0.00309358 -0.00285356 0.0023213 ..., 0. 0. 0. ]] +[[-0.00327455 -0.00063717 0.00489796 ..., 0. 0. 0. ]] diff --git a/tests/training/restart/adam_async.vt.expected b/tests/training/restart/adam_async.vt.expected index 99e13d3..9abd4e1 100644 --- a/tests/training/restart/adam_async.vt.expected +++ b/tests/training/restart/adam_async.vt.expected @@ -1,2 +1,2 @@ -[[ 5.10732070e-06 4.67832115e-06 2.71009117e-06 ..., 0.00000000e+00 +[[ 4.05344281e-06 3.82874305e-07 1.35198152e-05 ..., 0.00000000e+00 0.00000000e+00 0.00000000e+00]] diff --git a/tests/training/restart/test_saving_adam_params_async.sh b/tests/training/restart/test_saving_adam_params_async.sh index f8e6b35..51e8331 100644 --- a/tests/training/restart/test_saving_adam_params_async.sh +++ b/tests/training/restart/test_saving_adam_params_async.sh @@ -31,8 +31,8 @@ diff adam_async.keys.out adam.keys.expected > adam_async.keys.diff python $MRT_MARIAN/scripts/contrib/model_info.py -m adam_async/model.npz.optimizer.npz -k "adam_mt" > adam_async.mt.out python $MRT_MARIAN/scripts/contrib/model_info.py -m adam_async/model.npz.optimizer.npz -k "adam_vt" > adam_async.vt.out -$MRT_TOOLS/diff-floats.py -p 0.0009 adam_async.mt.out adam_async.mt.expected > adam_async.mt.diff -$MRT_TOOLS/diff-floats.py -p 0.000009 adam_async.vt.out adam_async.vt.expected > adam_async.vt.diff +$MRT_TOOLS/diff-floats.py -a -p 0.01 adam_async.mt.out adam_async.mt.expected > adam_async.mt.diff +$MRT_TOOLS/diff-floats.py -p 0.001 adam_async.vt.out adam_async.vt.expected > adam_async.vt.diff # Exit with success code exit 0 diff --git a/tools/diff-floats.py b/tools/diff-floats.py index eba23b4..37fd758 100755 --- a/tools/diff-floats.py +++ b/tools/diff-floats.py @@ -21,13 +21,16 @@ def main(): for i, line1 in enumerate(args.file1): line2 = args.file2.next() - nums1 = [float(s) for s in line1.rstrip().split() if is_numeric(s)] - nums2 = [float(s) for s in line2.rstrip().split() if is_numeric(s)] + line1_toks = line1.rstrip().replace("[[-", "[[ -").split() + line2_toks = line2.rstrip().replace("[[-", "[[ -").split() + + nums1 = [float(s) for s in line1_toks if is_numeric(s)] + nums2 = [float(s) for s in line2_toks if is_numeric(s)] text1 = ' '.join(["<NUM>" if is_numeric(s) else s - for s in line1.rstrip().split()]) + for s in line1_toks]) text2 = ' '.join(["<NUM>" if is_numeric(s) else s - for s in line2.rstrip().split()]) + for s in line2_toks]) if text1 != text2: print "Line {}: different texts:\n< {}\n> {}".format(i, text1, text2) @@ -41,6 +44,9 @@ def main(): continue for j, (n1, n2) in enumerate(zip(nums1, nums2)): + if args.abs: + n1 = abs(n1) + n2 = abs(n2) if abs(n1 - n2) > args.precision: if max_diff_nums < 1: print "Line {}: {} != {}".format(i, n1, n2) @@ -63,6 +69,7 @@ def parse_user_args(): parser.add_argument("file2", type=argparse.FileType('r')) parser.add_argument("-p", "--precision", type=float, default=0.001) parser.add_argument("-n", "--max-diff-nums", type=int, default=0) + parser.add_argument("-a", "--abs", action="store_true") return parser.parse_args() |