提交 4936e630 authored 作者: Ramana.S's avatar Ramana.S

Test added, code made complaint with pep8 standards

上级 db6fc48d
...@@ -509,7 +509,7 @@ class FromFunctionOp(gof.Op): ...@@ -509,7 +509,7 @@ class FromFunctionOp(gof.Op):
self.infer_shape = self._infer_shape self.infer_shape = self._infer_shape
def __eq__(self, other): def __eq__(self, other):
return (type(self) == type(other) and return (isinstance(self, type(other)) and
self.__fn == other.__fn) self.__fn == other.__fn)
def __hash__(self): def __hash__(self):
...@@ -523,9 +523,9 @@ class FromFunctionOp(gof.Op): ...@@ -523,9 +523,9 @@ class FromFunctionOp(gof.Op):
if not self.itypes: if not self.itypes:
raise NotImplementedError("itypes not defined") raise NotImplementedError("itypes not defined")
if not self.otypes : if not self.otypes:
raise NotImplementedError("otypes not defined") raise NotImplementedError("otypes not defined")
if len(inputs) != len(self.itypes): if len(inputs) != len(self.itypes):
raise ValueError("We expected %d inputs but got %d." % raise ValueError("We expected %d inputs but got %d." %
(len(self.itypes), len(inputs))) (len(self.itypes), len(inputs)))
......
...@@ -16,7 +16,7 @@ import pickle ...@@ -16,7 +16,7 @@ import pickle
# reachable from pickle (as in it cannot be defined inline) # reachable from pickle (as in it cannot be defined inline)
@as_op([dmatrix, dmatrix], dmatrix) @as_op([dmatrix, dmatrix], dmatrix)
def mul(a, b): def mul(a, b):
return a*b return a * b
class OpDecoratorTests(utt.InferShapeTester): class OpDecoratorTests(utt.InferShapeTester):
......
差异被折叠。
...@@ -29,7 +29,7 @@ class MyType(Type): ...@@ -29,7 +29,7 @@ class MyType(Type):
self.thingy = thingy self.thingy = thingy
def __eq__(self, other): def __eq__(self, other):
return type(other) == type(self) and other.thingy == self.thingy return isinstance(other, type(self)) and other.thingy == self.thingy
def __str__(self): def __str__(self):
return str(self.thingy) return str(self.thingy)
...@@ -58,7 +58,7 @@ class MyType(Type): ...@@ -58,7 +58,7 @@ class MyType(Type):
class MyOp(Op): class MyOp(Op):
__props__ = () __props__ = ()
def make_node(self, *inputs): def make_node(self, *inputs):
inputs = list(map(as_variable, inputs)) inputs = list(map(as_variable, inputs))
for input in inputs: for input in inputs:
...@@ -157,6 +157,7 @@ class TestOp: ...@@ -157,6 +157,7 @@ class TestOp:
class TestMakeThunk(unittest.TestCase): class TestMakeThunk(unittest.TestCase):
def test_no_c_code(self): def test_no_c_code(self):
class IncOnePython(Op): class IncOnePython(Op):
"""An Op with only a Python (perform) implementation""" """An Op with only a Python (perform) implementation"""
...@@ -234,6 +235,28 @@ class TestMakeThunk(unittest.TestCase): ...@@ -234,6 +235,28 @@ class TestMakeThunk(unittest.TestCase):
self.assertRaises((NotImplementedError, utils.MethodNotDefined), self.assertRaises((NotImplementedError, utils.MethodNotDefined),
thunk) thunk)
def test_no_make_node(self):
class IncOne(Op):
"""An Op without make_node"""
__props__ = ()
itypes = [T.fmatrix]
otypes = [T.fmatrix]
def perform(self, node, inputs, outputs):
input, = inputs
output, = outputs
output[0] = input + 1
x_input = T.fmatrix('x')
o = IncOne()(x_input)
# Confirming that make_node method is implemented
try:
self.assertRaises((NotImplementedError, utils.MethodNotDefined),
o.owner.op.make_node, x_input)
except AssertionError:
pass
def test_test_value_python_objects(): def test_test_value_python_objects():
for x in ([0, 1, 2], 0, 0.5, 1): for x in ([0, 1, 2], 0, 0.5, 1):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论