提交 ceb2d5f8 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

PEP8

上级 90764f70
...@@ -515,8 +515,8 @@ def get_constant_value(v): ...@@ -515,8 +515,8 @@ def get_constant_value(v):
# TODO: implement the case where we take a scalar in a matrix # TODO: implement the case where we take a scalar in a matrix
assert len(v.owner.op.idx_list) == v.owner.inputs[0].ndim assert len(v.owner.op.idx_list) == v.owner.inputs[0].ndim
#Needed to make better graph in this test. # Needed to make better graph in this test in theano/tensor/tests:
#theano/tensor/tests/test_sharedvar.py:test_shared_options.test_specify_shape_partial # test_sharedvar.py:test_shared_options.test_specify_shape_partial
if (v.owner.inputs[0].owner and if (v.owner.inputs[0].owner and
isinstance(v.owner.inputs[0].owner.op, Join) and isinstance(v.owner.inputs[0].owner.op, Join) and
# Ensure the Join is joining only scalar variables (so that # Ensure the Join is joining only scalar variables (so that
...@@ -956,9 +956,9 @@ class TensorType(Type): ...@@ -956,9 +956,9 @@ class TensorType(Type):
return """ return """
%(name)s = NULL; %(name)s = NULL;
if (py_%(name)s == Py_None) { if (py_%(name)s == Py_None) {
// We can either fail here or set %(name)s to NULL and rely on Ops using // We can either fail here or set %(name)s to NULL and rely on Ops
// tensors to handle the NULL case, but if they fail to do so they'll end up // using tensors to handle the NULL case, but if they fail to do so
// with nasty segfaults, so this is public service. // they'll end up with nasty segfaults, so this is public service.
PyErr_SetString(PyExc_ValueError, "expected an ndarray, not None"); PyErr_SetString(PyExc_ValueError, "expected an ndarray, not None");
%(fail)s %(fail)s
} }
...@@ -966,15 +966,19 @@ class TensorType(Type): ...@@ -966,15 +966,19 @@ class TensorType(Type):
PyErr_SetString(PyExc_ValueError, "expected an ndarray"); PyErr_SetString(PyExc_ValueError, "expected an ndarray");
%(fail)s %(fail)s
} }
type_num_%(name)s = ((PyArrayObject*)py_%(name)s)->descr->type_num; //we expect %(type_num)s // We expect %(type_num)s
type_num_%(name)s = ((PyArrayObject*)py_%(name)s)->descr->type_num;
if (!PyArray_ISALIGNED(py_%(name)s)) { if (!PyArray_ISALIGNED(py_%(name)s)) {
PyErr_Format(PyExc_NotImplementedError, PyErr_Format(PyExc_NotImplementedError,
"expected an aligned array of type %%d (%(type_num)s), got non-aligned array of type %%d", "expected an aligned array of type %%d "
"(%(type_num)s), got non-aligned array of type %%d",
%(type_num)s, type_num_%(name)s); %(type_num)s, type_num_%(name)s);
%(fail)s %(fail)s
} }
if (type_num_%(name)s != %(type_num)s) { if (type_num_%(name)s != %(type_num)s) {
PyErr_Format(PyExc_ValueError, "expected type_num %%d (%(type_num)s) got %%d", %(type_num)s, type_num_%(name)s); PyErr_Format(PyExc_ValueError,
"expected type_num %%d (%(type_num)s) got %%d",
%(type_num)s, type_num_%(name)s);
%(fail)s %(fail)s
} }
%(name)s = (PyArrayObject*)(py_%(name)s); %(name)s = (PyArrayObject*)(py_%(name)s);
...@@ -2713,12 +2717,12 @@ if 0: ...@@ -2713,12 +2717,12 @@ if 0:
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE ## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
class Filler(gof.Op): class Filler(gof.Op):
"""WRITEME""" """WRITEME"""
def __init__(self, value, ndim, dtype = 'float64'): def __init__(self, value, ndim, dtype='float64'):
self.value = value self.value = value
self.ndim = ndim self.ndim = ndim
self.dtype = dtype self.dtype = dtype
self.type = TensorType(dtype = dtype, self.type = TensorType(dtype=dtype,
broadcastable = (False,)*ndim) broadcastable=(False,) * ndim)
def make_node(self, dims): def make_node(self, dims):
dims = as_tensor_variable(dims) dims = as_tensor_variable(dims)
...@@ -2728,21 +2732,22 @@ if 0: ...@@ -2728,21 +2732,22 @@ if 0:
dims, = inp dims, = inp
out, = out_ out, = out_
if out[0] is not None: if out[0] is not None:
out[0].resize(dims, refcheck = 0) out[0].resize(dims, refcheck=0)
out[0].fill(self.value) out[0].fill(self.value)
else: else:
if self.value == 0: if self.value == 0:
out[0] = numpy.zeros(dims, dtype = self.dtype) out[0] = numpy.zeros(dims, dtype=self.dtype)
elif self.value == 1: elif self.value == 1:
out[0] = numpy.ones(dims, dtype = self.dtype) out[0] = numpy.ones(dims, dtype=self.dtype)
else: else:
out[0] = numpy.ones(dims, dtype = self.dtype) * self.value out[0] = numpy.ones(dims, dtype=self.dtype) * self.value
def grad(self, inp, grads): def grad(self, inp, grads):
return None, return None,
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) and self.ndim == other.ndim and self.dtype == other.dtype return (type(self) == type(other) and self.ndim == other.ndim and
self.dtype == other.dtype)
def __hash__(self): def __hash__(self):
return hash(self.ndim) ^ hash(self.dtype) return hash(self.ndim) ^ hash(self.dtype)
...@@ -2765,8 +2770,14 @@ if 0: ...@@ -2765,8 +2770,14 @@ if 0:
"""WRITEME""" """WRITEME"""
return Ones(0)([]) return Ones(0)([])
pprint.assign(lambda pstate, r: r.owner and isinstance(r.owner.op, Filler) and r.owner.op.value == 0, printing.FunctionPrinter('zeros')) pprint.assign(lambda pstate, r: r.owner and
pprint.assign(lambda pstate, r: r.owner and isinstance(r.owner.op, Filler) and r.owner.op.value == 1, printing.FunctionPrinter('ones')) isinstance(r.owner.op, Filler) and
r.owner.op.value == 0,
printing.FunctionPrinter('zeros'))
pprint.assign(lambda pstate, r: r.owner and
isinstance(r.owner.op, Filler) and
r.owner.op.value == 1,
printing.FunctionPrinter('ones'))
class Alloc(gof.Op): class Alloc(gof.Op):
...@@ -3106,17 +3117,19 @@ if 0: ...@@ -3106,17 +3117,19 @@ if 0:
assert repeats.type == iscalar assert repeats.type == iscalar
assert axis.type == iscalar assert axis.type == iscalar
broadcastable = [] broadcastable = []
for i,x in enumerate(input.broadcastable): for i, x in enumerate(input.broadcastable):
if i==axis: if i == axis:
broadcastable += [False] broadcastable += [False]
else: else:
broadcastable += [x] broadcastable += [x]
type = TensorType(dtype = input.type.dtype, broadcastable = \ type = TensorType(dtype=input.type.dtype,
broadcastable) broadcastable=broadcastable)
#backport #backport
#type = TensorType(dtype = input.type.dtype, #type = TensorType(dtype=input.type.dtype,
# broadcastable = [False if i==axis else x for i, x in enumerate(input.broadcastable)]) # broadcastable=[
# False if i==axis else x
# for i, x in enumerate(input.broadcastable)])
return gof.Apply(self, [inputs, repeats, axis], [type()]) return gof.Apply(self, [inputs, repeats, axis], [type()])
def perform(self, node, inp, out_): def perform(self, node, inp, out_):
...@@ -3807,7 +3820,8 @@ class Subtensor(Op): ...@@ -3807,7 +3820,8 @@ class Subtensor(Op):
if (!step) if (!step)
{ {
Py_DECREF(xview); Py_DECREF(xview);
PyErr_Format(PyExc_ValueError, "slice step cannot be zero"); PyErr_Format(PyExc_ValueError,
"slice step cannot be zero");
%(fail)s; %(fail)s;
} }
...@@ -4209,7 +4223,8 @@ class IncSubtensor(Op): ...@@ -4209,7 +4223,8 @@ class IncSubtensor(Op):
else else
{ {
if (%(z)s) Py_DECREF(%(z)s); if (%(z)s) Py_DECREF(%(z)s);
%(z)s = (PyArrayObject*)PyArray_FromAny(py_%(x)s, NULL, 0, 0, NPY_ENSURECOPY, NULL); %(z)s = (PyArrayObject*)PyArray_FromAny(py_%(x)s, NULL, 0, 0,
NPY_ENSURECOPY, NULL);
} }
""" % locals() """ % locals()
...@@ -5532,8 +5547,8 @@ def inverse_permutation(perm): ...@@ -5532,8 +5547,8 @@ def inverse_permutation(perm):
# Advanced indexing # Advanced indexing
######################### #########################
# #
# Should reproduce numpy's behaviour: # Should reproduce numpy's behaviour, see url:
# http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing # docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing
class AdvancedSubtensor1(Op): class AdvancedSubtensor1(Op):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论