summaryrefslogtreecommitdiff
path: root/weave/examples/functional.py
diff options
context:
space:
mode:
authorEric Jones <eric@enthought.com>2002-09-30 08:31:56 +0000
committerEric Jones <eric@enthought.com>2002-09-30 08:31:56 +0000
commit920b35a1c9a88595384d4ff0f4a90ddf594ffedd (patch)
treea51766420a2f1af289892b5c6f5f635dddec4712 /weave/examples/functional.py
parentc3ba22da35f011595b2643e894db1f797e7f2fec (diff)
downloadnumpy-920b35a1c9a88595384d4ff0f4a90ddf594ffedd.tar.gz
This checkin has quite a few changes. Most are augmentations to the
py::object class' capabilities and unit tests to check them and changes to test cases/examples to use the new features. There is also one other BIG change. return_val has been changed from a PyObject* to a py::object. This removes the need to handle reference counting almost completely from inline() code. I am very happy about this. :-) All tests pass on win32, but the examples still need some work.
Diffstat (limited to 'weave/examples/functional.py')
-rw-r--r--weave/examples/functional.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/weave/examples/functional.py b/weave/examples/functional.py
index 67641bff6..1c18cbc32 100644
--- a/weave/examples/functional.py
+++ b/weave/examples/functional.py
@@ -19,14 +19,15 @@ def c_list_map(func,seq):
assert(type(func) in [FunctionType,MethodType,type(len)])
code = """
#line 12 "functional.py"
- PWOTuple args(1);
- PWOList result(seq.len());
- for(int i = 0; i < seq.len();i++)
+ py::tuple = args(1);
+ int N = seq.len();
+ py::list result(N);
+ for(int i = 0; i < N;i++)
{
- args.setItem(0,seq[i]);
+ args[0] = seq[i];
result[i] = func.call(args);
}
- return_val = result.disOwn();
+ return_val = result;
"""
return inline_tools.inline(code,['func','seq'])
@@ -37,13 +38,14 @@ def c_list_map2(func,seq):
assert(type(func) in [FunctionType,MethodType,type(len)])
code = """
#line 32 "functional.py"
- PWOTuple args(1);
+ py::tuple args(1);
PyObject* py_args = (PyObject*)args;
- PWOList result(seq.len());
+ py::list result(seq.len());
PyObject* py_result = (PyObject*)result;
PyObject* item = NULL;
PyObject* this_result = NULL;
- for(int i = 0; i < seq.len();i++)
+ int N = seq.len();
+ for(int i = 0; i < N;i++)
{
item = PyList_GET_ITEM(py_seq,i);
Py_INCREF(item);
@@ -51,7 +53,7 @@ def c_list_map2(func,seq):
this_result = PyEval_CallObject(py_func,py_args);
PyList_SetItem(py_result,i,this_result);
}
- return_val = result.disOwn();
+ return_val = result;
"""
return inline_tools.inline(code,['func','seq'])