提交 c195a8d7 authored 作者: ChienliMa's avatar ChienliMa

move TypeError into make_node, consequently changed the test a little. Add a…

move TypeError into make_node, consequently changed the test a little. Add a note to declarethe difference between fill_diagonal and fill_diagonal_offset
上级 086a2092
......@@ -760,6 +760,11 @@ class FillDiagonalOffset(gof.Op):
if val.dtype != a.dtype:
raise TypeError('%s: type of second parameter must be the same'
' as the first\'s' % self.__class__.__name__)
elif offset.dtype[:3] != 'int':
raise TypeError('%s: type of third parameter must be as integer'
' use theano.tensor.cast( input, \'int32/int64\')' \
% self.__class__.__name__)
return gof.Apply(self, [a, val, offset], [a.type()])
......@@ -770,11 +775,6 @@ class FillDiagonalOffset(gof.Op):
offset = inputs[2]
height, width = a.shape
# offset should be an integer
if offset % 1 != 0:
raise ValueError('%s: third parameter must be an integer'\
% self.__class__.__name__)
"""
Note: The fill_diagonal only support rectangular matrix. The output
of tall matrix is "wrapped", which is an option in numpy 1.9.0
......
......@@ -422,11 +422,11 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
x = tensor.matrix()
y = tensor.scalar()
z = tensor.scalar()
z_in = tensor.cast( z, "int32")
test_offset = numpy.array(numpy.random.randint(-5,5),
dtype = config.floatX)
test_offset = numpy.random.randint(-5,5)
f = function([x, y, z], fill_diagonal_offset(x, y, z))
f = function([x, y, z_in], fill_diagonal_offset(x, y, z_in))
for shp in [(8, 8), (5, 8), (8, 5)]:
a = numpy.random.rand(*shp).astype(config.floatX)
val = numpy.cast[config.floatX](numpy.random.rand())
......@@ -443,8 +443,7 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
a.shape[0]+test_offset )
def test_gradient(self):
test_offset = numpy.array(numpy.random.randint(-5,5),
dtype = config.floatX)
test_offset = numpy.random.randint(-5,5)
# input 'offset' will not be tested
def fill_diagonal_with_fix_offset( a, val):
return fill_diagonal_offset( a, val, test_offset)
......@@ -460,10 +459,9 @@ class TestFillDiagonalOffset(utt.InferShapeTester):
x = tensor.dmatrix()
y = tensor.dscalar()
z = tensor.dscalar()
test_offset = numpy.array(numpy.random.randint(-5,5),
dtype = config.floatX)
self._compile_and_check([x, y, z], [self.op(x, y, z)],
z_in = tensor.cast( z, "int32")
self._compile_and_check([x, y, z_in], [self.op(x, y, z_in)],
[numpy.random.rand(8, 5),
numpy.random.rand(),
test_offset],
self.op_class)
numpy.random.randint(-5,5)],
self.op_class )
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论