提交 5b366b70 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Make sure that expected outputs have right dtype

上级 61f4f3b7
...@@ -612,10 +612,22 @@ if config.floatX=='float32': ...@@ -612,10 +612,22 @@ if config.floatX=='float32':
# This is probably caused by our way of computing the gradient error. # This is probably caused by our way of computing the gradient error.
div_grad_rtol=0.025 div_grad_rtol=0.025
def _numpy_true_div(x, y):
"""Performs true division, and cast the result in the type we expect.
We define that function so we can use it in TrueDivTester.expected,
because simply calling numpy.true_divide could cause a dtype mismatch.
"""
out = numpy.true_divide(x, y)
# Use floatX as the result of int / int
if x.dtype in tensor.discrete_dtypes and y.dtype in tensor.discrete_dtypes:
out = theano._asarray(out, dtype=config.floatX)
return out
TrueDivTester = makeBroadcastTester( TrueDivTester = makeBroadcastTester(
op=tensor.true_div, op=tensor.true_div,
expected = (lambda x, y: expected=_numpy_true_div,
check_floatX((x, y), numpy.true_divide(x, y))),
good=_good_broadcast_div_mod_normal_float, good=_good_broadcast_div_mod_normal_float,
grad=_grad_broadcast_div_mod_normal, grad=_grad_broadcast_div_mod_normal,
grad_rtol=div_grad_rtol, grad_rtol=div_grad_rtol,
...@@ -623,7 +635,7 @@ TrueDivTester = makeBroadcastTester( ...@@ -623,7 +635,7 @@ TrueDivTester = makeBroadcastTester(
TrueDivInplaceTester = makeBroadcastTester( TrueDivInplaceTester = makeBroadcastTester(
op=inplace.true_div_inplace, op=inplace.true_div_inplace,
expected=(lambda x, y: numpy.true_divide(x, y)), expected=_numpy_true_div,
good=copymod( good=copymod(
_good_broadcast_div_mod_normal_float_inplace, _good_broadcast_div_mod_normal_float_inplace,
# The output is now in float, we cannot work inplace on an int. # The output is now in float, we cannot work inplace on an int.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论