[Scipy-svn] r2322 - trunk/Lib/sandbox/numexpr
scipy-svn at scipy.org
scipy-svn at scipy.org
Thu Nov 16 23:52:52 EST 2006
Author: cookedm
Date: 2006-11-16 22:52:49 -0600 (Thu, 16 Nov 2006)
New Revision: 2322
Modified:
trunk/Lib/sandbox/numexpr/compiler.py
trunk/Lib/sandbox/numexpr/interpreter.c
Log:
[numexpr] more whitespace, and fix compiler warnings with Python 2.5 (use Py_ssize_t)
Modified: trunk/Lib/sandbox/numexpr/compiler.py
===================================================================
--- trunk/Lib/sandbox/numexpr/compiler.py 2006-11-16 20:19:52 UTC (rev 2321)
+++ trunk/Lib/sandbox/numexpr/compiler.py 2006-11-17 04:52:49 UTC (rev 2322)
@@ -114,7 +114,7 @@
basesig = ''.join(x.typecode() for x in list(ast.children))
# Find some operation that will work on an acceptable casting of args.
for sig in sigPerms(basesig):
- value = ast.value + '_' + retsig + sig
+ value = ast.value + '_' + retsig + sig
if value in interpreter.opcodes:
break
else:
@@ -215,9 +215,9 @@
c = compile(s, '<expr>', 'eval')
# make VariableNode's for the names
names = {}
- for name in c.co_names:
- if name == "None":
- names[name] = None
+ for name in c.co_names:
+ if name == "None":
+ names[name] = None
else:
t = types.get(name, float)
names[name] = expr.VariableNode(name, type_to_kind[t])
@@ -228,10 +228,10 @@
ex = expr.ConstantNode(ex, expressions.getKind(ex))
return ex
-
-def isReduction(ast):
- return ast.value.startswith('sum_') or ast.value.startswith('prod_')
+def isReduction(ast):
+ return ast.value.startswith('sum_') or ast.value.startswith('prod_')
+
def getInputOrder(ast, input_order=None):
"""Derive the input order of the variables in an expression.
"""
@@ -315,12 +315,12 @@
def optimizeTemporariesAllocation(ast):
"""Attempt to minimize the number of temporaries needed, by
reusing old ones.
- """
+ """
nodes = list(x for x in ast.postorderWalk() if x.reg.temporary)
- users_of = dict((n.reg, set()) for n in nodes)
- if nodes and nodes[-1] is not ast:
- for c in ast.children:
- if c.reg.temporary:
+ users_of = dict((n.reg, set()) for n in nodes)
+ if nodes and nodes[-1] is not ast:
+ for c in ast.children:
+ if c.reg.temporary:
users_of[c.reg].add(ast)
for n in reversed(nodes):
for c in n.children:
Modified: trunk/Lib/sandbox/numexpr/interpreter.c
===================================================================
--- trunk/Lib/sandbox/numexpr/interpreter.c 2006-11-16 20:19:52 UTC (rev 2321)
+++ trunk/Lib/sandbox/numexpr/interpreter.c 2006-11-17 04:52:49 UTC (rev 2322)
@@ -483,7 +483,7 @@
static int
last_opcode(PyObject *program_object) {
- int n;
+ Py_ssize_t n;
unsigned char *program;
PyString_AsStringAndSize(program_object, (char **)&program, &n);
return program[n-4];
@@ -506,7 +506,8 @@
check_program(NumExprObject *self)
{
unsigned char *program;
- int prog_len, rno, pc, arg, argloc, argno, n_buffers, n_inputs;
+ Py_ssize_t prog_len, n_buffers, n_inputs;
+ int rno, pc, arg, argloc, argno;
char sig, *fullsig, *signature;
if (PyString_AsStringAndSize(self->program, (char **)&program,
@@ -915,14 +916,16 @@
struct index_data *index_data, int *pc_error)
{
int r;
+ Py_ssize_t plen;
unsigned int blen1, blen2;
struct vm_params params;
*pc_error = -1;
if (PyString_AsStringAndSize(self->program, (char **)&(params.program),
- &(params.prog_len)) < 0) {
+ &plen) < 0) {
return -1;
}
+ params.prog_len = plen;
if ((params.n_inputs = PyObject_Length(self->signature)) == -1)
return -1;
params.output = output;
@@ -952,7 +955,8 @@
{
PyObject *output = NULL, *a_inputs = NULL;
struct index_data *inddata = NULL;
- unsigned int n_inputs, n_dimensions = 0, shape[MAX_DIMS];
+ unsigned int n_inputs, n_dimensions = 0;
+ int shape[MAX_DIMS];
int i, j, size, r, pc_error;
char **inputs = NULL;
intp strides[MAX_DIMS]; /* clean up XXX */
@@ -1134,7 +1138,8 @@
j += 1;
}
}
- output = PyArray_SimpleNew(n_dimensions-1, dims, typecode_from_char(retsig));
+ output = PyArray_SimpleNew(n_dimensions-1, dims,
+ typecode_from_char(retsig));
if (!output) goto cleanup_and_exit;
for (i = j = 0; i < n_dimensions; i++) {
if (i != axis) {
@@ -1162,11 +1167,11 @@
if (last_opcode(self->program) >= OP_SUM &&
last_opcode(self->program) < OP_PROD) {
PyObject *zero = PyInt_FromLong(0);
- PyArray_FillWithScalar(output, zero);
+ PyArray_FillWithScalar((PyArrayObject *)output, zero);
Py_DECREF(zero);
} else {
PyObject *one = PyInt_FromLong(1);
- PyArray_FillWithScalar(output, one);
+ PyArray_FillWithScalar((PyArrayObject *)output, one);
Py_DECREF(one);
}
}
More information about the Scipy-svn
mailing list