From 705bf512925b1cbb18d0de45e3f1a5e668b972dc Mon Sep 17 00:00:00 2001 From: James Stevens <jdsteve2@illinois.edu> Date: Wed, 13 May 2015 13:49:32 -0500 Subject: [PATCH] added getitem, setitem to TypeToOpCountMap --- loopy/statistics.py | 9 +++++++++ test/test_statistics.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/loopy/statistics.py b/loopy/statistics.py index d1108dd2a..a1e8c7648 100755 --- a/loopy/statistics.py +++ b/loopy/statistics.py @@ -64,6 +64,15 @@ class TypeToOpCountMap: __rmul__ = __mul__ + def __getitem__(self, index): + try: + return self.dict[index] + except KeyError: + return isl.PwQPolynomial('{ 0 }') + + def __setitem__(self, index, value): + self.dict[index] = value + def __str__(self): return str(self.dict) diff --git a/test/test_statistics.py b/test/test_statistics.py index 54d08a498..e68700833 100644 --- a/test/test_statistics.py +++ b/test/test_statistics.py @@ -143,7 +143,9 @@ def test_op_counter_bitwise(ctx_factory): m = 256 l = 128 i32 = poly.dict[np.dtype(np.int32)].eval_with_dict({'n': n, 'm': m, 'l': l}) + not_there = poly[np.dtype(np.float64)].eval_with_dict({'n': n, 'm': m, 'l': l}) assert i32 == 3*n*m+n*m*l + assert not_there == 0 if __name__ == "__main__": if len(sys.argv) > 1: -- GitLab