Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67842:adc554f83b04 Date: 2013-11-04 22:03 -0500 http://bitbucket.org/pypy/pypy/changeset/adc554f83b04/
Log: provide astype/nbytes for scalars 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 @@ -249,6 +249,12 @@ v = self.convert_to(self.get_dtype(space)) return self.get_dtype(space).itemtype.round(v, decimals) + def descr_astype(self, space, w_dtype): + from pypy.module.micronumpy.interp_dtype import W_Dtype + dtype = space.interp_w(W_Dtype, + space.call_function(space.gettypefor(W_Dtype), w_dtype)) + return self.convert_to(dtype) + def descr_view(self, space, w_dtype): from pypy.module.micronumpy.interp_dtype import W_Dtype dtype = space.interp_w(W_Dtype, @@ -516,10 +522,12 @@ ravel = interp2app(W_GenericBox.descr_ravel), round = interp2app(W_GenericBox.descr_round), conjugate = interp2app(W_GenericBox.descr_conjugate), + astype = interp2app(W_GenericBox.descr_astype), view = interp2app(W_GenericBox.descr_view), dtype = GetSetProperty(W_GenericBox.descr_get_dtype), itemsize = GetSetProperty(W_GenericBox.descr_get_itemsize), + nbytes = GetSetProperty(W_GenericBox.descr_get_itemsize), shape = GetSetProperty(W_GenericBox.descr_get_shape), ndim = GetSetProperty(W_GenericBox.descr_get_ndim), ) diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -56,11 +56,21 @@ assert b.round() == 1.0 assert b.round(decimals=5) is b + def test_astype(self): + import numpy as np + a = np.bool_(True).astype(np.float32) + assert type(a) is np.float32 + assert a == 1.0 + a = np.bool_(True).astype('int32') + assert type(a) is np.int32 + assert a == 1 + def test_attributes(self): import numpypy as np value = np.dtype('int64').type(12345) assert value.dtype == np.dtype('int64') assert value.itemsize == 8 + assert value.nbytes == 8 assert value.shape == () assert value.ndim == 0 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit