提交 d53dd639 authored 作者: Frederic's avatar Frederic

Make Shape_i.__hash__ always return an int, not an numpy.int64 when i is such an object.

fix gh-2099
上级 5e9d4ed3
...@@ -314,15 +314,11 @@ class Shape_i(gof.Op): ...@@ -314,15 +314,11 @@ class Shape_i(gof.Op):
check_input = False check_input = False
__props__ = ("i",)
def __init__(self, i): def __init__(self, i):
self.i = i self.i = i
def __hash__(self):
return hash(type(self)) ^ self.i
def __eq__(self, other):
return type(self) == type(other) and self.i == other.i
def __str__(self): def __str__(self):
return '%s{%i}' % (self.__class__.__name__, self.i) return '%s{%i}' % (self.__class__.__name__, self.i)
......
...@@ -19,6 +19,7 @@ import pickle ...@@ -19,6 +19,7 @@ import pickle
def mul(a, b): def mul(a, b):
return a*b return a*b
class OpDecoratorTests(utt.InferShapeTester): class OpDecoratorTests(utt.InferShapeTester):
def test_1arg(self): def test_1arg(self):
x = dmatrix('x') x = dmatrix('x')
...@@ -77,3 +78,8 @@ class OpDecoratorTests(utt.InferShapeTester): ...@@ -77,3 +78,8 @@ class OpDecoratorTests(utt.InferShapeTester):
m2 = pickle.loads(s) m2 = pickle.loads(s)
assert m2.owner.op == m.owner.op assert m2.owner.op == m.owner.op
def test_shape_i_hash():
assert isinstance(theano.tensor.opt.Shape_i(np.int64(1)).__hash__(),
int)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论