提交 8efd2f21 authored 作者: Frederic Bastien's avatar Frederic Bastien

some backport to python2.4

上级 d33fa296
...@@ -12,7 +12,7 @@ import traceback ...@@ -12,7 +12,7 @@ import traceback
######## ########
# Type # # Type #
######## ########
from .op import CLinkerObject from theano.gof.op import CLinkerObject
class CLinkerType(CLinkerObject): class CLinkerType(CLinkerObject):
"""Interface specification for Types that can be arguments to a `CLinkerOp`. """Interface specification for Types that can be arguments to a `CLinkerOp`.
......
...@@ -279,7 +279,12 @@ class TensorType(Type): ...@@ -279,7 +279,12 @@ class TensorType(Type):
self.dtype_specs() # error checking is done there self.dtype_specs() # error checking is done there
self.name = name self.name = name
if shape is None: if shape is None:
self.shape = tuple((1 if b else None) for b in self.broadcastable) #backport self.shape = tuple((1 if b else None) for b in self.broadcastable)
l=[]
for b in self.broadcastable:
if b: l.append(1)
else: l.append(None)
self.shape = tuple(l)
else: else:
self.shape = tuple(shape) self.shape = tuple(shape)
if len(self.shape) != len(self.broadcastable): if len(self.shape) != len(self.broadcastable):
...@@ -291,8 +296,12 @@ class TensorType(Type): ...@@ -291,8 +296,12 @@ class TensorType(Type):
#add shape when unpickling old pickled things #add shape when unpickling old pickled things
if 'shape' not in dct: if 'shape' not in dct:
self.shape = tuple(1 if b else None for b in self.broadcastable) l=[]
for b in self.broadcastable:
if b: l.append(1)
else: l.append(None)
self.shape = tuple(l)
#backport self.shape = tuple(1 if b else None for b in self.broadcastable)
def filter(self, data, strict = False): def filter(self, data, strict = False):
"""Convert `data` to something which can be associated to a `TensorVariable`. """Convert `data` to something which can be associated to a `TensorVariable`.
...@@ -1684,8 +1693,11 @@ class Default(gof.Op): ...@@ -1684,8 +1693,11 @@ class Default(gof.Op):
assert x.type == default.type assert x.type == default.type
return gof.Apply(self, [x, default], [default.type()]) return gof.Apply(self, [x, default], [default.type()])
def perform(self, node, (x, default), (out, )): def perform(self, node, (x, default), (out, )):
out[0] = default.copy() if x is None else x if x is None:
out[0] = default.copy()
else:
out[0] = x
#backport out[0] = default.copy() if x is None else x
default = Default() default = Default()
setdefault = default # legacy setdefault = default # legacy
...@@ -2300,7 +2312,11 @@ class Join(Op): ...@@ -2300,7 +2312,11 @@ class Join(Op):
outputs = [tensor(dtype = out_dtype, outputs = [tensor(dtype = out_dtype,
broadcastable = bcastable)] broadcastable = bcastable)]
node = Apply(self, inputs, outputs) node = Apply(self, inputs, outputs)
node.tag.shape_zero = None if any(not x.type.broadcastable[0] for x in orig) else len(orig) if any(not x.type.broadcastable[0] for x in orig):
node.tag.shape_zero = None
else:
node.tag.shape_zero = len(orig)
#backport node.tag.shape_zero = None if any(not x.type.broadcastable[0] for x in orig) else len(orig)
return node return node
def perform(self, node, axis_and_tensors, (out, )): def perform(self, node, axis_and_tensors, (out, )):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论