提交 c46741e0 authored 作者: sentient07's avatar sentient07

Removed __eq__ __hash__ and __str__ from redundant places

上级 7885227c
...@@ -121,6 +121,15 @@ class GpuFromHost(GpuOp): ...@@ -121,6 +121,15 @@ class GpuFromHost(GpuOp):
check_input = False check_input = False
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return hash(type(self))
def __str__(self):
return 'GpuFromHost'
def make_node(self, x): def make_node(self, x):
if not isinstance(x.type, tensor.TensorType): if not isinstance(x.type, tensor.TensorType):
...@@ -312,13 +321,18 @@ class GpuDimShuffle(GpuOp): ...@@ -312,13 +321,18 @@ class GpuDimShuffle(GpuOp):
check_broadcast = False check_broadcast = False
__props__ = ("input_broadcastable", "new_order") __props__ = ("input_broadcastable", "new_order", "inplace")
def __init__(self, input_broadcastable, new_order): def __init__(self, input_broadcastable, new_order, inplace=True):
input_broadcastable = tuple(input_broadcastable) input_broadcastable = tuple(input_broadcastable)
self.input_broadcastable = input_broadcastable self.input_broadcastable = input_broadcastable
self.new_order = tuple(new_order) self.new_order = tuple(new_order)
self.inplace = int(inplace) self.inplace = int(inplace)
if inplace is True:
self.inplace = inplace
self._props_dict().pop('inplace')
else:
raise ValueError("DimShuffle is inplace by default and hence the inplace for DimShuffle must be true")
for i, b in enumerate(input_broadcastable): for i, b in enumerate(input_broadcastable):
if i not in new_order: if i not in new_order:
...@@ -374,24 +388,12 @@ class GpuDimShuffle(GpuOp): ...@@ -374,24 +388,12 @@ class GpuDimShuffle(GpuOp):
ob.append(ib[value]) ob.append(ib[value])
return Apply(self, [input], [CudaNdarrayType(broadcastable=ob)()]) return Apply(self, [input], [CudaNdarrayType(broadcastable=ob)()])
def __eq__(self, other):
# it's probably not necessary to compare input_broadcastable
return type(self) == type(other) \
and self.new_order == other.new_order \
and self.input_broadcastable == other.input_broadcastable
def _rehash(self): def _rehash(self):
self._hashval = (hash(type(self).__name__) ^ self._hashval = (hash(type(self).__name__) ^
hash(type(self).__module__) ^ hash(type(self).__module__) ^
hash(self.new_order) ^ hash(self.new_order) ^
hash(self.input_broadcastable)) hash(self.input_broadcastable))
def __hash__(self):
return self._hashval
def __str__(self):
return "GpuDimShuffle{%s}" % ",".join(str(x) for x in self.new_order)
def c_code(self, node, name, inp, out, sub): def c_code(self, node, name, inp, out, sub):
input, = inp input, = inp
res, = out res, = out
...@@ -575,14 +577,6 @@ class GpuCAReduce(GpuOp): ...@@ -575,14 +577,6 @@ class GpuCAReduce(GpuOp):
if pre_scalar_op: if pre_scalar_op:
assert pre_scalar_op.nin == 1 assert pre_scalar_op.nin == 1
def __str__(self):
pre = ""
if self.pre_scalar_op:
pre = "pre=%s,red=" % str(self.pre_scalar_op)
return "GpuCAReduce{%s%s}{%s}" % (
pre, str(self.scalar_op),
','.join(str(i) for i in self.reduce_mask))
def __setstate__(self, d): def __setstate__(self, d):
self.__dict__.update(d) self.__dict__.update(d)
# For unpickling of old ops. # For unpickling of old ops.
...@@ -3641,8 +3635,6 @@ class GpuAllocEmpty(GpuOp): ...@@ -3641,8 +3635,6 @@ class GpuAllocEmpty(GpuOp):
""" """
__props__ = ()
@staticmethod @staticmethod
def validate_shape(shape): def validate_shape(shape):
sh = [tensor.as_tensor_variable(s) for s in shape] sh = [tensor.as_tensor_variable(s) for s in shape]
...@@ -3740,14 +3732,6 @@ class GpuAlloc(GpuAllocEmpty): ...@@ -3740,14 +3732,6 @@ class GpuAlloc(GpuAllocEmpty):
def __init__(self, memset_0=False): def __init__(self, memset_0=False):
self.memset_0 = memset_0 self.memset_0 = memset_0
def __str__(self):
# Hide the memset parameter when not used to prevent confusion.
if self.memset_0:
s = "%s{memset_0=%s}" % (self.__class__.__name__, self.memset_0)
else:
s = self.__class__.__name__
return s
def make_node(self, value, *shape): def make_node(self, value, *shape):
# if there is unneeded transfert generated by the next line # if there is unneeded transfert generated by the next line
# the optimizer will remove them. # the optimizer will remove them.
...@@ -3851,7 +3835,6 @@ class CopyOnNegativeStrides(GpuOp): ...@@ -3851,7 +3835,6 @@ class CopyOnNegativeStrides(GpuOp):
view_map = {0: [0]} view_map = {0: [0]}
check_input = False check_input = False
__props__ = ()
def grad(self, inputs, dout): def grad(self, inputs, dout):
......
...@@ -898,12 +898,6 @@ class BaseGpuCorrMM(GpuOp): ...@@ -898,12 +898,6 @@ class BaseGpuCorrMM(GpuOp):
return self.border_mode return self.border_mode
return (0, 0) return (0, 0)
def __str__(self):
return '%s{%s, %s, %s}' % (
self.__class__.__name__,
self.border_mode,
str(self.subsample),
str(self.filter_dilation))
def flops(self, inp, outp): def flops(self, inp, outp):
""" """
...@@ -1413,13 +1407,6 @@ class BaseGpuCorr3dMM(GpuOp): ...@@ -1413,13 +1407,6 @@ class BaseGpuCorr3dMM(GpuOp):
raise ValueError("pad must be 'half', 'full', or have three elements") raise ValueError("pad must be 'half', 'full', or have three elements")
self.pad = pad self.pad = pad
def __str__(self):
return '%s{%s, %s, pad=%r}' % (
self.__class__.__name__,
self.border_mode,
str(self.subsample),
self.pad)
def flops(self, inp, outp): def flops(self, inp, outp):
""" Useful with the hack in profilemode to print the MFlops""" """ Useful with the hack in profilemode to print the MFlops"""
# if the output shape is correct, then this gives the correct # if the output shape is correct, then this gives the correct
...@@ -2214,18 +2201,6 @@ class GpuDownsampleFactorMax(GpuOp): ...@@ -2214,18 +2201,6 @@ class GpuDownsampleFactorMax(GpuOp):
self.ds = tuple(ds) self.ds = tuple(ds)
self.ignore_border = ignore_border self.ignore_border = ignore_border
def __eq__(self, other):
return (type(self) == type(other) and
self.ds == other.ds and
self.ignore_border == other.ignore_border)
def __hash__(self):
return hash(type(self)) ^ hash(self.ds) ^ hash(self.ignore_border)
def __str__(self):
return '%s{%s,%s}' % (self.__class__.__name__,
self.ds,
self.ignore_border)
def make_node(self, x): def make_node(self, x):
if not isinstance(x.type, CudaNdarrayType): if not isinstance(x.type, CudaNdarrayType):
......
...@@ -1912,7 +1912,7 @@ def local_gpu_downsample_factor_max(node): ...@@ -1912,7 +1912,7 @@ def local_gpu_downsample_factor_max(node):
if (pad) != (0, 0) or node.op.mode != 'max' or stride != ws: if (pad) != (0, 0) or node.op.mode != 'max' or stride != ws:
return return
if (x.owner and isinstance(x.owner.op, HostFromGpu)): if (x.owner and isinstance(x.owner.op, HostFromGpu)):
gpu_ds = GpuDownsampleFactorMax(**node.op._props_dict()) gpu_ds = GpuDownsampleFactorMax(node.op.ds, node.op.ignore_border)
return [host_from_gpu(gpu_ds(x.owner.inputs[0]))] return [host_from_gpu(gpu_ds(x.owner.inputs[0]))]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论