[pypy-commit] pypy ufuncapi: fix after merge, wip
mattip
noreply at buildbot.pypy.org
Fri Dec 5 12:19:09 CET 2014
Author: mattip <matti.picus at gmail.com>
Branch: ufuncapi
Changeset: r74828:1453b5101ed2
Date: 2014-12-05 11:56 +0200
http://bitbucket.org/pypy/pypy/changeset/1453b5101ed2/
Log: fix after merge, wip
diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py
--- a/pypy/module/micronumpy/nditer.py
+++ b/pypy/module/micronumpy/nditer.py
@@ -173,11 +173,9 @@
def __init__(self, array, size, shape, strides, backstrides,
op_flags, base):
OperandIter.__init__(self, array, size, shape, strides, backstrides)
- self.slice_shape = 1
- self.slice_stride = -1
- if strides:
- self.slice_stride = strides[-1]
- self.slice_backstride = 1
+ self.slice_shape =[]
+ self.slice_stride = []
+ self.slice_backstride = []
if op_flags.rw == 'r':
self.operand_type = concrete.ConcreteNonWritableArrayWithBase
else:
@@ -209,8 +207,8 @@
def getoperand(self, state):
assert state.iterator is self
impl = self.operand_type
- arr = impl(state.offset, [self.slice_stride], [self.slice_backstride],
- [self.slice_shape], self.array, self.base)
+ arr = impl(state.offset, self.slice_stride, self.slice_backstride,
+ self.slice_shape, self.array, self.base)
return arr
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -120,11 +120,13 @@
c128_dtype, c128_dtype],
'')
f32_array = W_NDimArray(VoidBoxStorage(0, f32_dtype))
- index, dtypes = ufunc.type_resolver(space, [f32_array], [None], 'd->D')
+ index, dtypes = ufunc.type_resolver(space, [f32_array], [None],
+ 'd->D', ufunc.dtypes)
#needs to cast input type, create output type
assert index == 1
assert dtypes == [f64_dtype, c128_dtype]
- index, dtypes = ufunc.type_resolver(space, [f32_array], [None], '')
+ index, dtypes = ufunc.type_resolver(space, [f32_array], [None],
+ '', ufunc.dtypes)
assert index == 0
assert dtypes == [f32_dtype, c64_dtype]
@@ -229,7 +231,7 @@
)
ai = arange(18, dtype=int).reshape(2,3,3)
exc = raises(ValueError, ufunc, ai[:,:,0])
- assert "Operand 0 has a mismatch in its core dimension 1" in exc.value.message
+ assert "perand 0 has a mismatch in its core dimension 1" in exc.value.message
ai3 = ufunc(ai[0,:,:])
ai2 = ufunc(ai)
assert (ai2 == ai * 2).all()
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -590,11 +590,12 @@
# func is going to do all the work, it must accept W_NDimArray args
inargs0 = inargs[0]
assert isinstance(inargs0, W_NDimArray)
- outarg_shapes = [inargs0.get_shape()] * self.nargs
+ arg_shapes = [inargs0.get_shape()] * self.nargs
inargs, outargs, need_to_cast = self.alloc_args(space, inargs, outargs,
- dtypes, outarg_shapes)
- if any(need_to_cast):
- raise oefmt(space.w_NotImplementedError, "casting not supported yet")
+ dtypes, arg_shapes)
+ for tf in need_to_cast:
+ if tf:
+ raise oefmt(space.w_NotImplementedError, "casting not supported yet")
if self.stack_inputs:
arglist = space.newlist(list(inargs + outargs))
space.call_args(func, Arguments.frompacked(space, arglist))
@@ -608,8 +609,9 @@
iter_shape, arg_shapes, matched_dims = self.verify_args(space, inargs, outargs)
inargs, outargs, need_to_cast = self.alloc_args(space, inargs, outargs, dtypes,
arg_shapes)
- if any(need_to_cast):
- raise oefmt(space.w_NotImplementedError, "casting not supported yet")
+ for tf in need_to_cast:
+ if tf:
+ raise oefmt(space.w_NotImplementedError, "casting not supported yet")
w_flags = space.w_None # NOT 'external_loop', we do coalescing by core_num_dims
w_op_flags = space.newtuple([space.wrap(r) for r in ['readonly'] * len(inargs)] + \
[space.wrap(r) for r in ['readwrite'] * len(outargs)])
@@ -786,15 +788,18 @@
if len(arg_shapes[i]) != curarg.ndims():
# XXX reshape (after merge with default)
pass
- need_to_cast.append(curarg.get_dtype() == dtypes[i])
+ need_to_cast.append(curarg.get_dtype() != dtypes[i])
for i in range(len(outargs)):
j = self.nin + i
- if outargs[i] is None:
- outargs[i] = W_NDimArray.from_shape(space, outarg_shapes[j], dtypes[j], order)
+ curarg = outargs[i]
+ assert isinstance(curarg, W_NDimArray)
+ if not isinstance(curarg, W_NDimArray):
+ outargs[i] = W_NDimArray.from_shape(space, arg_shapes[j], dtypes[j], order)
+ curarg = outargs[i]
elif len(arg_shapes[i]) != curarg.ndims():
# XXX reshape (after merge with default)
pass
- need_to_cast.append(curarg.get_dtype() == dtypes[j])
+ need_to_cast.append(curarg.get_dtype() != dtypes[j])
return inargs, outargs, need_to_cast
def verify_args(self, space, inargs, outargs):
@@ -814,13 +819,13 @@
name = 'Input'
curarg = inargs[i]
else:
- _i = i + self.nin
+ _i = i - self.nin
name = 'Output'
curarg = outargs[_i]
dim_offset = self.core_offsets[i]
num_dims = self.core_num_dims[i]
if not isinstance(curarg, W_NDimArray):
- arg_shape = iter_shape
+ arg_shape = iter_shape[:]
for j in range(num_dims):
core_dim_index = self.core_dim_ixs[dim_offset + j]
if matched_dims[core_dim_index] < 0:
@@ -839,11 +844,11 @@
num_dims+n, self.signature, num_dims)
dims_to_match = curarg.get_shape()[n:]
dims_to_broadcast = curarg.get_shape()[:n]
- offset = len(dims_to_broadcast) - len(iter_shape)
- if offset >= 0:
+ offset = n - len(iter_shape)
+ if offset > 0:
# Prepend extra dimensions to iter_shape, matched_dims
iter_shape = dims_to_broadcast[:offset] + iter_shape
- outarg_shapes = [dims_to_broadcast[:offset] + asp for asp in outarg_shapes]
+ arg_shapes = [dims_to_broadcast[:offset] + asp for asp in arg_shapes]
offset = 0
# Make sure iter_shape[offset:] matches dims_to_broadcast
offset = abs(offset) # for translation
@@ -856,7 +861,8 @@
"(size %d is different from %d)",
self.name, name, _i, j, x, y)
iter_shape[offset + j] = max(x, y)
- # Find or verify signature ixs
+ #print 'Find or verify signature ixs',self.core_dim_ixs,
+ #print 'starting',dim_offset,'n',num_dims,'matching',dims_to_match
for j in range(num_dims):
core_dim_index = self.core_dim_ixs[dim_offset + j]
if core_dim_index > len(dims_to_match):
@@ -865,12 +871,12 @@
"signature %s (index is larger than input shape)",
self.name, name, _i, j, self.signature, core_dim_index)
if matched_dims[core_dim_index] < 0:
- matched_dims[core_dim_index] = dims_to_match[core_dim_index]
- elif matched_dims[core_dim_index] != dims_to_match[core_dim_index]:
+ matched_dims[core_dim_index] = dims_to_match[j]
+ elif matched_dims[core_dim_index] != dims_to_match[j]:
raise oefmt(space.w_ValueError, "%s: %s operand %d has a "
"mismatch in its core dimension %d, with gufunc "
"signature %s (expected %d, got %d)",
- self.name, name, _i, core_dim_index + num_dims,
+ self.name, name, _i, j,
self.signature, matched_dims[core_dim_index],
dims_to_match[core_dim_index])
arg_shapes.append(iter_shape + dims_to_match)
@@ -881,6 +887,7 @@
# TODO parse and handle subok
# TODO handle flags, op_flags
+ #print 'iter_shape',iter_shape,'arg_shapes',arg_shapes,'matched_dims',matched_dims
return iter_shape, arg_shapes, matched_dims
W_Ufunc.typedef = TypeDef("numpy.ufunc",
More information about the pypy-commit
mailing list