Author: Maciej Fijalkowski <[email protected]>
Branch: missing-ndarray-attributes
Changeset: r58577:2c7822df923e
Date: 2012-10-29 12:03 +0100
http://bitbucket.org/pypy/pypy/changeset/2c7822df923e/
Log: implement non-native floats
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -391,9 +391,16 @@
def descr_get_base(self, space):
return self.implementation.base()
- def descr_byteswap(self, space, w_inplace=False):
- raise OperationError(space.w_NotImplementedError, space.wrap(
- "byteswap not implemented yet"))
+ @unwrap_spec(inplace=bool)
+ def descr_byteswap(self, space, inplace=False):
+ raise OperationError(space.w_NotImplementedError, space.wrap("not
impl"))
+ if inplace:
+ loop.byteswap(self.implementation, self.implementation)
+ return self
+ else:
+ res = W_NDimArray.from_shape(self.get_shape(), self.get_dtype())
+ loop.byteswap(self.implementation, res.implementation)
+ return res
def descr_choose(self, space, w_choices, w_out=None, w_mode='raise'):
raise OperationError(space.w_NotImplementedError, space.wrap(
diff --git a/pypy/module/micronumpy/test/test_dtypes.py
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -684,9 +684,10 @@
else:
assert stor2[1] == '\x01'
assert stor2[0] == '\x00'
- cls.w_check_non_native = cls.space.wrap(interp2app(check_non_native))
if option.runappdirect:
- py.test.skip("not a direct test")
+ cls.w_check_non_native = lambda *args : None
+ else:
+ cls.w_check_non_native =
cls.space.wrap(interp2app(check_non_native))
def test_non_native(self):
from _numpypy import array
@@ -694,6 +695,12 @@
assert a[0] == 1
assert (a + a)[1] == 4
self.check_non_native(a, array([1, 2, 3], 'i2'))
+ a = array([1, 2, 3], dtype=self.non_native_prefix + 'f8')
+ assert a[0] == 1
+ assert (a + a)[1] == 4
+ a = array([1, 2, 3], dtype=self.non_native_prefix + 'f4')
+ assert a[0] == 1
+ assert (a + a)[1] == 4
class AppTestPyPyOnly(BaseNumpyAppTest):
def setup_class(cls):
diff --git a/pypy/module/micronumpy/test/test_numarray.py
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1591,6 +1591,10 @@
b = a[::2]
assert b.base is a
+ def test_byteswap(self):
+ from _numpypy import array
+ xxx
+
class AppTestMultiDim(BaseNumpyAppTest):
def test_init(self):
import _numpypy
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -910,16 +910,14 @@
def _read(self, storage, i, offset):
res = raw_storage_getitem(self.T, storage, i + offset)
- #return byteswap(res) XXX
- return res
+ return rffi.cast(lltype.Float, byteswap(res))
def _write(self, storage, i, offset, value):
- #value = byteswap(value) XXX
- raw_storage_setitem(storage, i + offset, value)
+ swapped_value = byteswap(rffi.cast(self.T, value))
+ raw_storage_setitem(storage, i + offset, swapped_value)
def pack_str(self, box):
- # XXX byteswap
- return struct.pack(self.format_code, self.unbox(box))
+ return struct.pack(self.format_code, byteswap(self.unbox(box)))
class Float32(BaseType, Float):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit