Brian Kearns avatar Brian Kearns committed 592629f

provide flags for scalars also

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_boxes.py

 from rpython.rtyper.lltypesystem import rffi
 from rpython.tool.sourcetools import func_with_new_name
 from pypy.module.micronumpy.arrayimpl.voidbox import VoidBoxStorage
+from pypy.module.micronumpy.interp_flagsobj import W_FlagsObject
 from pypy.interpreter.mixedmodule import MixedModule
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rlib.rstring import StringBuilder
 
 
 class W_GenericBox(W_Root):
-    _attrs_ = []
+    _attrs_ = ['w_flags']
 
     def descr__new__(space, w_subtype, __args__):
         raise operationerrfmt(space.w_TypeError,
     def descr_copy(self, space):
         return self.convert_to(self.get_dtype(space))
 
+    w_flags = None
+    def descr_get_flags(self, space):
+        if self.w_flags is None:
+            self.w_flags = W_FlagsObject(self)
+        return self.w_flags
+
 class W_BoolBox(W_GenericBox, PrimitiveBox):
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter("bool")
 
     strides = GetSetProperty(W_GenericBox.descr_get_shape),
     ndim = GetSetProperty(W_GenericBox.descr_get_ndim),
     T = GetSetProperty(W_GenericBox.descr_self),
+    flags = GetSetProperty(W_GenericBox.descr_get_flags),
 )
 
 W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,

pypy/module/micronumpy/test/test_flagsobj.py

         a = np.array([1,2,3])
         assert repr(type(a.flags)) == "<type 'numpy.flagsobj'>"
 
-    def test_flags(self):
+    def test_array_flags(self):
         import numpy as np
         a = np.array([1,2,3])
         assert a.flags.c_contiguous == True
         raises(KeyError, "a.flags['blah']")
         raises(KeyError, "a.flags['C_CONTIGUOUS'] = False")
         raises((TypeError, AttributeError), "a.flags.c_contiguous = False")
+
+    def test_scalar_flags(self):
+        import numpy as np
+        a = np.int32(2)
+        assert a.flags.c_contiguous == True
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.