Commits

Anders Lehmann committed 1be7eb1

Fix compile.py to understand count_nonzero, fix the test

Comments (0)

Files changed (2)

pypy/module/micronumpy/compile.py

     pass
 
 SINGLE_ARG_FUNCTIONS = ["sum", "prod", "max", "min", "all", "any",
-                        "unegative", "flat", "tostring"]
+                        "unegative", "flat", "tostring","count_nonzero"]
 TWO_ARG_FUNCTIONS = ["dot", 'take']
 THREE_ARG_FUNCTIONS = ['where']
 
             elif self.name == "tostring":
                 arr.descr_tostring(interp.space)
                 w_res = None
+            elif self.name == "count_nonzero":
+                w_res = arr.descr_count_nonzero(interp.space)
             else:
                 assert False # unreachable code
         elif self.name in TWO_ARG_FUNCTIONS:
             return w_res
         if isinstance(w_res, FloatObject):
             dtype = get_dtype_cache(interp.space).w_float64dtype
+        elif isinstance(w_res, IntObject):
+            dtype = get_dtype_cache(interp.space).w_int64dtype
         elif isinstance(w_res, BoolObject):
             dtype = get_dtype_cache(interp.space).w_booldtype
         elif isinstance(w_res, interp_boxes.W_GenericBox):

pypy/module/micronumpy/test/test_zjit.py

     def define_count_nonzero():
         return """
         a = [[0, 2, 3, 4], [5, 6, 0, 8], [9, 10, 11, 0]]
-        c = count_nonzero(a)
+        count_nonzero(a) 
         """
 
     def test_count_nonzero(self):
         result = self.run("count_nonzero")
         assert result == 9
-        self.check_simple_loop({'arraylen_gc': 9,
-                                'float_add': 1,
-                                'float_mul': 1,
-                                'getinteriorfield_raw': 3,
-                                'guard_false': 3,
-                                'guard_true': 3,
-                                'int_add': 6,
-                                'int_lt': 6,
-                                'int_sub': 3,
-                                'jump': 1,
-                                'setinteriorfield_raw': 1})
+        self.check_simple_loop({'setfield_gc': 3, 
+                                'getinteriorfield_raw': 1, 
+                                'guard_false': 1, 
+                                'jump': 1, 
+                                'int_ge': 1, 
+                                'new_with_vtable': 1, 
+                                'int_add': 2, 
+                                'float_ne': 1})
 
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.