[pypy-commit] pypy numpy-refactor: fromstring
fijal
noreply at buildbot.pypy.org
Fri Sep 7 18:33:35 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r57223:4b705cdb6479
Date: 2012-09-07 18:00 +0200
http://bitbucket.org/pypy/pypy/changeset/4b705cdb6479/
Log: fromstring
diff --git a/pypy/module/micronumpy/interp_support.py b/pypy/module/micronumpy/interp_support.py
--- a/pypy/module/micronumpy/interp_support.py
+++ b/pypy/module/micronumpy/interp_support.py
@@ -1,9 +1,8 @@
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.gateway import unwrap_spec
from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.module.micronumpy import interp_dtype
+from pypy.module.micronumpy import interp_dtype, loop
from pypy.objspace.std.strutil import strip_spaces
-from pypy.rlib import jit
from pypy.rlib.rarithmetic import maxint
from pypy.module.micronumpy.base import W_NDimArray
@@ -54,9 +53,9 @@
a = W_NDimArray.from_shape([num_items], dtype=dtype)
ai = a.create_iter()
for val in items:
- a.dtype.setitem(a, ai.offset, val)
- ai = ai.next(1)
-
+ ai.setitem(val)
+ ai.next()
+
return space.wrap(a)
def _fromstring_bin(space, s, count, length, dtype):
@@ -73,24 +72,9 @@
"string is smaller than requested size"))
a = W_NDimArray.from_shape([count], dtype=dtype)
- fromstring_loop(a, dtype, itemsize, s)
+ loop.fromstring_loop(a, dtype, itemsize, s)
return space.wrap(a)
-fromstring_driver = jit.JitDriver(greens=[], reds=['i', 'itemsize',
- 'dtype', 'ai', 's', 'a'])
-
-def fromstring_loop(a, dtype, itemsize, s):
- i = 0
- ai = a.create_iter()
- while not ai.done():
- fromstring_driver.jit_merge_point(a=a, dtype=dtype,
- itemsize=itemsize, s=s, i=i,
- ai=ai)
- val = dtype.itemtype.runpack_str(s[i*itemsize:i*itemsize + itemsize])
- a.dtype.setitem(a, ai.offset, val)
- ai = ai.next(1)
- i += 1
-
@unwrap_spec(s=str, count=int, sep=str)
def fromstring(space, s, w_dtype=None, count=-1, sep=''):
dtype = space.interp_w(interp_dtype.W_Dtype,
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -208,3 +208,12 @@
val_iter.next()
# WTF numpy?
val_iter.reset()
+
+def fromstring_loop(a, dtype, itemsize, s):
+ i = 0
+ ai = a.create_iter()
+ while not ai.done():
+ val = dtype.itemtype.runpack_str(s[i*itemsize:i*itemsize + itemsize])
+ ai.setitem(val)
+ ai.next()
+ i += 1
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
@@ -279,7 +279,7 @@
return int(v)
def default_fromstring(self, space):
- return self.box(False)
+ return self.box(True)
@simple_binary_op
def bitwise_and(self, v1, v2):
More information about the pypy-commit
mailing list