提交 1b65de9a authored 作者: notoraptor's avatar notoraptor

Update tests for ParamsType.

Update ParamsType usage in `theano/gof/op.py`.
上级 42e7ed18
......@@ -808,7 +808,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
field = wrapper.fields[i]
_type = wrapper.types[i]
wrap_dict[field] = _type.filter(getattr(self, field), strict=False, allow_downcast=True)
return theano.gof.Params(wrapper, **wrap_dict)
return self.params_type.get_params(self)
raise theano.gof.utils.MethodNotDefined('get_params')
def prepare_node(self, node, storage_map, compute_map, impl):
......
......@@ -6,7 +6,7 @@ from theano.gof import Op, COp, Apply
from theano import Generic
from theano.scalar import Scalar
from theano.tensor import TensorType
from theano.gof import ParamsType, Params
from theano.gof import ParamsType, Params, EnumList
from theano import tensor
from theano.tests import unittest_tools as utt
......@@ -213,6 +213,27 @@ class TestParamsType(TestCase):
a3=2000.0 - 0.00000000000000001)
assert w.values_eq_approx(o1, o3)
def test_params_type_with_enums(self):
# Test that we fail if we create a wrapper with common enum names inside different enum types.
try:
w = ParamsType(enum1=EnumList('A', 'B', 'C'), enum2=EnumList('A', 'B', 'F'))
except AttributeError:
pass
else:
raise Exception('ParamsType should fail with common enum names inside different enum types.')
# Test that we can access enum values through wrapper directly.
w = ParamsType(enum1=EnumList('A', ('B', 'beta'), 'C'), enum2=EnumList(('D', 'delta'), 'E', 'F'))
assert w.A == 0 and w.B == 1 and w.C == 2
assert w.D == 0 and w.E == 1 and w.F == 2
# Test constants access through aliases.
assert w.enum_from_alias('beta') == w.B
assert w.enum_from_alias('delta') == w.D
assert w.enum_from_alias('C') == w.C # C is not an alias, so it should return a constant named C.
# Test that other regular wrapper attributes are still available.
assert len(w.fields) == len(w.types) == w.length
assert w.name
def test_op_params(self):
a, b, c = 2, 3, -7
x = tensor.matrix(dtype='float64')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论