提交 dc7cd4c9 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Thomas Wiecki

Implement __eq__ for RandomStateType and RandomGeneratorType

上级 9e7aea88
......@@ -93,6 +93,12 @@ class RandomStateType(RandomType):
return _eq(sa, sb)
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return hash(type(self))
# Register `RandomStateType`'s C code for `ViewOp`.
aesara.compile.register_view_op_c_code(
......@@ -174,6 +180,12 @@ class RandomGeneratorType(RandomType):
return _eq(sa, sb)
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return hash(type(self))
# Register `RandomGeneratorType`'s C code for `ViewOp`.
aesara.compile.register_view_op_c_code(
......
......@@ -39,8 +39,9 @@ class TestRandomStateType:
rng_pkl = pickle.dumps(rng_r)
rng_unpkl = pickle.loads(rng_pkl)
assert isinstance(rng_unpkl, type(rng_r))
assert isinstance(rng_unpkl.type, type(rng_r.type))
assert rng_r != rng_unpkl
assert rng_r.type == rng_unpkl.type
assert hash(rng_r.type) == hash(rng_unpkl.type)
def test_repr(self):
assert repr(random_state_type) == "RandomStateType"
......@@ -129,8 +130,9 @@ class TestRandomGeneratorType:
rng_pkl = pickle.dumps(rng_r)
rng_unpkl = pickle.loads(rng_pkl)
assert isinstance(rng_unpkl, type(rng_r))
assert isinstance(rng_unpkl.type, type(rng_r.type))
assert rng_r != rng_unpkl
assert rng_r.type == rng_unpkl.type
assert hash(rng_r.type) == hash(rng_unpkl.type)
def test_repr(self):
assert repr(random_generator_type) == "RandomGeneratorType"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论