[pypy-commit] pypy numpy-refactor: call1 support
fijal
noreply at buildbot.pypy.org
Thu Aug 30 15:43:59 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r56939:d430ec66c5b5
Date: 2012-08-30 15:43 +0200
http://bitbucket.org/pypy/pypy/changeset/d430ec66c5b5/
Log: call1 support
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -135,7 +135,7 @@
def reduce(self, space, w_obj, multidim, promote_to_largest, w_axis,
keepdims=False, out=None):
- from pypy.module.micronumpy.interp_numarray import convert_to_array, \
+ from pypy.module.micronumpy.interp_numarray import \
Scalar, ReduceArray, W_NDimArray
if self.argcount != 2:
raise OperationError(space.w_ValueError, space.wrap("reduce only "
@@ -227,8 +227,7 @@
self.bool_result = bool_result
def call(self, space, args_w):
- from pypy.module.micronumpy.interp_numarray import (Call1, BaseArray,
- convert_to_array, Scalar, shape_agreement)
+ from pypy.module.micronumpy.interp_numarray import W_NDimArray
if len(args_w)<2:
[w_obj] = args_w
out = None
@@ -238,11 +237,11 @@
out = None
w_obj = convert_to_array(space, w_obj)
calc_dtype = find_unaryop_result_dtype(space,
- w_obj.find_dtype(),
+ w_obj.get_dtype(),
promote_to_float=self.promote_to_float,
promote_bools=self.promote_bools)
if out:
- if not isinstance(out, BaseArray):
+ if not isinstance(out, W_NDimArray):
raise OperationError(space.w_TypeError, space.wrap(
'output must be an array'))
res_dtype = out.find_dtype()
@@ -250,7 +249,8 @@
res_dtype = interp_dtype.get_dtype_cache(space).w_booldtype
else:
res_dtype = calc_dtype
- if isinstance(w_obj, Scalar):
+ if w_obj.is_scalar():
+ xxx
arr = self.func(calc_dtype, w_obj.value.convert_to(calc_dtype))
if isinstance(out,Scalar):
out.value = arr
@@ -259,25 +259,21 @@
else:
out = arr
return space.wrap(out)
- if out:
- assert isinstance(out, BaseArray) # For translation
- broadcast_shape = shape_agreement(space, w_obj.shape, out.shape)
- if not broadcast_shape or broadcast_shape != out.shape:
+ if not out:
+ out = W_NDimArray(w_obj.get_shape(), res_dtype)
+ else:
+ assert isinstance(out, W_NDimArray) # For translation
+ broadcast_shape = shape_agreement(space, w_obj.get_shape(),
+ out.get_shape())
+ if not broadcast_shape or broadcast_shape != out.get_shape():
raise operationerrfmt(space.w_ValueError,
'output parameter shape mismatch, could not broadcast [%s]' +
' to [%s]',
- ",".join([str(x) for x in w_obj.shape]),
- ",".join([str(x) for x in out.shape]),
+ ",".join([str(x) for x in w_obj.get_shape()]),
+ ",".join([str(x) for x in out.get_shape()]),
)
- w_res = Call1(self.func, self.name, out.shape, calc_dtype,
- res_dtype, w_obj, out)
- #Force it immediately
- w_res.get_concrete()
- else:
- w_res = Call1(self.func, self.name, w_obj.shape, calc_dtype,
- res_dtype, w_obj)
- w_obj.add_invalidates(space, w_res)
- return w_res
+ return loop.call1(self.func, self.name, calc_dtype, res_dtype,
+ w_obj, out)
class W_Ufunc2(W_Ufunc):
@@ -346,8 +342,7 @@
)
if out is None:
out = W_NDimArray(new_shape, res_dtype)
- return loop.call2(self.func, self.name,
- new_shape, calc_dtype,
+ return loop.call2(self.func, self.name, calc_dtype,
res_dtype, w_lhs, w_rhs, out)
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
@@ -3,7 +3,7 @@
signatures
"""
-def call2(func, name, shape, calc_dtype, res_dtype, w_lhs, w_rhs, out):
+def call2(func, name, calc_dtype, res_dtype, w_lhs, w_rhs, out):
left_iter = w_lhs.create_iter()
right_iter = w_rhs.create_iter()
out_iter = out.create_iter()
@@ -17,6 +17,16 @@
out_iter.next()
return out
+def call1(func, name , calc_dtype, res_dtype, w_obj, out):
+ obj_iter = w_obj.create_iter()
+ out_iter = out.create_iter()
+ while not out_iter.done():
+ elem = obj_iter.getitem().convert_to(calc_dtype)
+ out_iter.setitem(func(calc_dtype, elem).convert_to(res_dtype))
+ out_iter.next()
+ obj_iter.next()
+ return out
+
# from pypy.rlib.jit import JitDriver, hint, unroll_safe, promote
# from pypy.module.micronumpy.interp_iter import ConstantIterator
More information about the pypy-commit
mailing list