Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r77927:34dee90d9ae5
Date: 2015-06-06 19:29 +0100
http://bitbucket.org/pypy/pypy/changeset/34dee90d9ae5/
Log: Create W_Dtype.runpack_str() and simplify its callers
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -369,13 +369,11 @@
if dtype.elsize != self.get_dtype(space).elsize:
raise OperationError(space.w_ValueError, space.wrap(
"new type not compatible with array."))
- if dtype.is_str_or_unicode():
- return dtype.coerce(space, space.wrap(self.raw_str()))
- elif dtype.is_record():
+ if dtype.is_record():
raise OperationError(space.w_NotImplementedError, space.wrap(
"viewing scalar as record not implemented"))
else:
- return dtype.itemtype.runpack_str(space, self.raw_str())
+ return dtype.runpack_str(space, self.raw_str())
def descr_self(self, space):
return self
diff --git a/pypy/module/micronumpy/descriptor.py
b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -397,6 +397,11 @@
return space.wrap(0)
return space.wrap(len(self.fields))
+ def runpack_str(self, space, s):
+ if self.is_str_or_unicode():
+ return self.coerce(space, space.wrap(s))
+ return self.itemtype.runpack_str(space, s)
+
def descr_reduce(self, space):
w_class = space.type(self)
builder_args = space.newtuple([
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
@@ -566,10 +566,7 @@
while not ai.done(state):
fromstring_driver.jit_merge_point(dtype=dtype, itemsize=itemsize)
sub = s[i*itemsize:i*itemsize + itemsize]
- if dtype.is_str_or_unicode():
- val = dtype.coerce(space, space.wrap(sub))
- else:
- val = dtype.itemtype.runpack_str(space, sub)
+ val = dtype.runpack_str(space, sub)
ai.setitem(state, val)
state = ai.next(state)
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
@@ -1149,13 +1149,13 @@
return ''.join(['(', real_str, op, imag_str, ')'])
def runpack_str(self, space, s):
- comp = self.ComponentBoxType._get_dtype(space).itemtype
+ comp = self.ComponentBoxType._get_dtype(space)
l = len(s) // 2
real = comp.runpack_str(space, s[:l])
imag = comp.runpack_str(space, s[l:])
if not self.native:
- real = comp.byteswap(real)
- imag = comp.byteswap(imag)
+ real = comp.itemtype.byteswap(real)
+ imag = comp.itemtype.byteswap(imag)
return self.composite(real, imag)
@staticmethod
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit