Author: mattip <[email protected]>
Branch: ufuncapi
Changeset: r72692:08c63a7da2da
Date: 2014-08-04 22:00 +0300
http://bitbucket.org/pypy/pypy/changeset/08c63a7da2da/
Log: start to handle signature
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py
b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -214,6 +214,9 @@
assert res.get_scalar_value().imag == 4.
def test_Ufunc_FromFuncAndDataAndSignature(self. space, api):
+ PyUFuncGenericFunction funcs[] = {&double_times2, &int_times2};
+ char types[] = { NPY_DOUBLE,NPY_DOUBLE, NPY_INT, NPY_INT };
+ void *array_data[] = {NULL, NULL};
ufunc = api._PyUFunc_FromFuncAndDataAndSignature(space, funcs, data,
types, ntypes, nin, nout, identity, doc, check_return,
signature)
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
@@ -16,6 +16,8 @@
def decode_w_dtype(space, w_dtype):
if space.is_none(w_dtype):
return None
+ if isinstance(w_dtype, W_Dtype):
+ return w_dtype
return space.interp_w(
W_Dtype, space.call_function(space.gettypefor(W_Dtype), w_dtype))
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
@@ -150,16 +150,17 @@
def setup_class(cls):
BaseNumpyAppTest.setup_class.im_func(cls)
if cfuncs:
+ print 'cfuncs.int_times2',cfuncs.int_times2
def int_times2(space, __args__):
args, kwargs = __args__.unpack()
arr = map(space.unwrap, args)
# Assume arr is contiguous
- addr = cfuncs.new('char *[2]')
+ addr = ffi.new('char *[3]')
addr[0] = arr[0].data
addr[1] = arr[1].data
- dims = cfuncs.new('int *[1]')
+ dims = ffi.new('int *[1]')
dims[0] = arr[0].size
- steps = cfuncs.new('int *[1]')
+ steps = ffi.new('int *[1]')
steps[0] = arr[0].strides[-1]
cfuncs.int_times2(addr, dims, steps, 0)
def double_times2(space, __args__):
@@ -175,10 +176,11 @@
steps[0] = arr[0].strides[-1]
cfuncs.double_times2(addr, dims, steps, 0)
if option.runappdirect:
- times2 = cls.space.wrap([double_times2, int_times2])
+ times2 = cls.space.wrap([int_times2, double_times2])
else:
- times2 = cls.space.wrap([interp2app(double_times2),
- interp2app(int_times2)])
+ times2 = cls.space.wrap([interp2app(int_times2),
+ interp2app(double_times2),
+ ])
else:
times2 = None
cls.w_times2 = cls.space.wrap(times2)
@@ -233,13 +235,15 @@
def test_from_cffi_func(self):
import sys
- if '__pypy__' not in sys.builtin_module_names:
- skip('pypy-only test')
+ #if '__pypy__' not in sys.builtin_module_names:
+ # skip('pypy-only test')
from numpy import frompyfunc, dtype, arange
if self.times2 is None:
skip('cffi not available')
ufunc = frompyfunc(self.times2, 1, 1, signature='()->()',
- dtypes=[dtype(float), dtype(float), dtype(int),
dtype(int)],
+ dtypes=[dtype(int), dtype(int),
+ dtype(float), dtype(float)
+ ]
)
f = arange(10, dtype=int)
f2 = ufunc(f)
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
@@ -542,10 +542,21 @@
outargs[i] = out
index = self.type_resolver(space, inargs, outargs)
self.alloc_outargs(space, index, inargs, outargs)
- # XXX handle inner-loop indexing
new_shape = inargs[0].get_shape()
assert isinstance(outargs[0], W_NDimArray)
res_dtype = outargs[0].get_dtype()
+ # XXX handle inner-loop indexing
+ sign_parts = self.signature.split('->')
+ if len(sign_parts) == 2 and sign_parts[0].strip() == '()' \
+ and sign_parts[1].strip() == '()':
+
+ arglist = space.newlist(inargs + outargs)
+ func = self.funcs[index]
+ # XXXX TODO in test_ufuncs's test_from_cffi_func,
+ # XXXX func is an app-level python function,
+ # XXXX how do we call it?
+ assert False
+ return
if len(outargs) < 2:
return loop.call_many_to_one(space, new_shape, self.funcs[index],
res_dtype, inargs, outargs[0])
@@ -968,7 +979,6 @@
if not space.is_true(space.callable(w_func)):
raise oefmt(space.w_TypeError, 'func must be callable')
func = [w_func]
-
match_dtypes = False
if space.is_none(w_dtypes) and not signature:
raise oefmt(space.w_NotImplementedError,
@@ -976,13 +986,15 @@
elif (space.isinstance_w(w_dtypes, space.w_tuple) or
space.isinstance_w(w_dtypes, space.w_list)):
_dtypes = space.listview(w_dtypes)
- if space.str_w(_dtypes[0]) == 'match':
+ if space.isinstance_w(_dtypes[0], space.w_str) and
space.str_w(_dtypes[0]) == 'match':
dtypes = []
match_dtypes = True
else:
dtypes = [None]*len(_dtypes)
for i in range(len(dtypes)):
+ print 'decoding',_dtypes[i]
dtypes[i] = descriptor.decode_w_dtype(space, _dtypes[i])
+ print 'got',dtypes[i]
else:
raise oefmt(space.w_ValueError,
'dtypes must be None or a list of dtypes')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit