Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67994:592629fa85f2 Date: 2013-11-12 16:29 -0500 http://bitbucket.org/pypy/pypy/changeset/592629fa85f2/
Log: provide flags for scalars also diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py --- a/pypy/module/micronumpy/interp_boxes.py +++ b/pypy/module/micronumpy/interp_boxes.py @@ -11,6 +11,7 @@ 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 @@ -113,7 +114,7 @@ class W_GenericBox(W_Root): - _attrs_ = [] + _attrs_ = ['w_flags'] def descr__new__(space, w_subtype, __args__): raise operationerrfmt(space.w_TypeError, @@ -292,6 +293,12 @@ 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") @@ -550,6 +557,7 @@ 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, diff --git a/pypy/module/micronumpy/test/test_flagsobj.py b/pypy/module/micronumpy/test/test_flagsobj.py --- a/pypy/module/micronumpy/test/test_flagsobj.py +++ b/pypy/module/micronumpy/test/test_flagsobj.py @@ -7,7 +7,7 @@ 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 @@ -15,3 +15,8 @@ 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit