提交 90cbc85f authored 作者: James Bergstra's avatar James Bergstra

added eq and hash functions to tutorial example op

上级 24a5fbd8
...@@ -41,6 +41,10 @@ An Op is any object which defines the following methods: ...@@ -41,6 +41,10 @@ An Op is any object which defines the following methods:
applied on these inputs, it must raise an appropriate applied on these inputs, it must raise an appropriate
exception. exception.
- The inputs of the Apply instance returned by this call must be ordered
correctly: a subsequent ``self.make_node(*apply.inputs)`` must produce
something equivalent to the first ``apply``.
- **__call__(*inputs)** - **__call__(*inputs)**
- Syntactic shortcut to make_node which returns the output Results - Syntactic shortcut to make_node which returns the output Results
...@@ -284,6 +288,12 @@ arithmetic operators: ...@@ -284,6 +288,12 @@ arithmetic operators:
def __init__(self, name, fn): def __init__(self, name, fn):
self.name = name self.name = name
self.fn = fn self.fn = fn
def __eq__(self, other):
return type(self) == type(other) and (self.name == other.name) and (self.fn == other.fn)
def __hash__(self):
return hash(type(self)) ^ hash(self.name) ^ hash(self.fn)
def make_node(self, x, y): def make_node(self, x, y):
if isinstance(x, (int, float)): if isinstance(x, (int, float)):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论