From 806e022edf5689f4e29e6017a180c45a23cdbaa5 Mon Sep 17 00:00:00 2001 From: Andrew Fasano Date: Thu, 5 Sep 2019 16:46:21 -0400 Subject: [PATCH] Bugfix in tinyexpr makefile --- scripts/utils.py | 42 ++++++++++++++++++++++++++++++++ target_bins/tinyexpr-pre.tar.gz | Bin 27937 -> 27941 bytes 2 files changed, 42 insertions(+) create mode 100644 scripts/utils.py diff --git a/scripts/utils.py b/scripts/utils.py new file mode 100644 index 00000000..ef423481 --- /dev/null +++ b/scripts/utils.py @@ -0,0 +1,42 @@ +def bad_bin_search(args, fun): + ''' + Given a list of items and a function that takes a list, + do a binary search to remove all items that cause fun to fail + + Assumes args starts with > 1 element + + Returns a list of OK args + ''' + if len(args) <= 1: # Already failed on this arg, don't retry it + return [] + + mid = len(args)/2 + left = args[:mid] + right = args[mid:] + + if len(left): + try: # If left still fails, reduce farther + fun(left) + except (AssertionError, RuntimeError): + left = bad_bin_search(left, fun) + + if len(right): + try: # If right still fails, reduce farther + fun(right) + except (AssertionError, RuntimeError): + right = bad_bin_search(right, fun) + + return left + right + +if __name__ == "__main__": + def test_fn(l): + for item in l: + if item % 3 == 0: + raise RuntimeError("Test_fn: no factors of 3 allowed") + return l + + orig_list = [1,2,3,4,5,6,7,8,9] + r = bad_bin_search(orig_list, test_fn) + assert (r == [1,2,4,5,7,8]), "bad_bin_search is broken" + + print("All utility tests pass") diff --git a/target_bins/tinyexpr-pre.tar.gz b/target_bins/tinyexpr-pre.tar.gz index 451dfba714bd3978f813f8151b715ce22529c9c1..27747a9107f088b8810b0f25ea2821f9d6d4e445 100644 GIT binary patch delta 420 zcmV;V0bBl|+5x570S6z82nafJaj^%GYk%!R`@g-p)!prE?RKI4-`wr)JZ=Ba<8$pA zG$#jxLH+ify<4w*#oa3t*ALd9@~wvsw+;FeQ{26CO-eCPQxF;-{?MH(sw+{yas8FM zSJuXpdi@%PeJ*o{VO-TLb1aJ#yFB$LHEL zXig3WgZk||d$(Tsin~`Pt{<#H<1gyt~DL_pJdl`*7lsW(D~q(!=w1n8;>1t za2Pr(AN+Ehz>2-0v*tM~@di@Z*jQ=SpC!+H=fcLDU%KH8F92%2zJ7P_+O3-(dil=B zFV~-ErN{gR3+IPKvh#Z$Y>kJVK2$>vbPP_fW$1 zXQPR;7LA;-d*rUM$Mt6?4~Kr_tWA~28~dQ8X9rVfeM8cLo?@e3AB;UWxST;6AC6=t ze(*8cz$uhkDnlKQY?sK4oaET^lAG?eF-?Z{*rZ>Z{!;Q