Commits

mattip  committed b08ace6

add a test, fix for numpy compatability

  • Participants
  • Parent commits 2d1f512
  • Branches python-numpy

Comments (0)

Files changed (2)

File lib_pypy/numpypy/multiarray/__init__.py

 
 def count_nonzero(a):
     if not hasattr(a,'flat'):
-        a = ndarray(a)
-    return sum(a.flat != 0)
+        try:
+            a = ndarray(a)
+            return sum(a.flat != 0)
+        except TypeError:
+            if isinstance(a, (tuple, list)):
+                return len(a)
+        return 1

File lib_pypy/numpypy/test/test_multiarray.py

+try:
+    import _numpypy as np
+    import numpypy.multiarray as multiarray
+except:
+    import numpy as np
+    from numpy.core import multiarray
+
+from py.test import raises
+
+def test_count_nonzero():
+   a = np.array([[1, 1], [1, 1]])
+   assert multiarray.count_nonzero(a) == 4
+   raises(TypeError, multiarray.count_nonzero, 'a')