Author: mattip <[email protected]>
Branch: numpypy.float16
Changeset: r58552:7bfd4719be6c
Date: 2012-10-29 05:56 +0200
http://bitbucket.org/pypy/pypy/changeset/7bfd4719be6c/
Log: flesh out Float16 type
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
@@ -922,13 +922,11 @@
class Float16(BaseType, Float):
_attrs_ = ()
T = rffi.USHORT
+ _COMPUTATION_T = rffi.FLOAT
BoxType = interp_boxes.W_Float16Box
format_code = "e"
- def _coerce(self, space, w_item):
- return self.box(space.float_w(space.call_function(space.w_float,
w_item)))
-
def str_format(self, box):
return float2string(self.for_computation(self.unbox(box)), "g",
rfloat.DTSF_STR_PRECISION)
@@ -941,7 +939,24 @@
@specialize.argtype(1)
def box(self, value):
- xxx
+ return self.BoxType(
+ rffi.cast(self._COMPUTATION_T, value))
+
+ def unbox(self, box):
+ assert isinstance(box, self.BoxType)
+ return box.tofloat()
+
+ def store(self, arr, i, offset, box):
+ raw_storage_setitem(arr.storage, i+offset, box.tobytes())
+
+ def _read(self, storage, i, offset):
+ byte_rep = raw_storage_getitem(self.T, storage, i + offset)
+ return self.BoxType.val_to_float(byte_rep)
+
+ def read(self, arr, i, offset, dtype=None):
+ val = self._read(arr.storage, i, offset)
+ return self.BoxType(val)
+
class NonNativeFloat16(BaseType, NonNativeFloat):
_attrs_ = ()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit