提交 8cd973ad authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Disable DebugMode.check_isfinite when we know there are inf

上级 e8a8b936
from __future__ import absolute_import, print_function, division
from copy import copy
from unittest import TestCase
import numpy as np
import scipy.special
import theano
from theano import scalar, gof, tensor
from unittest import TestCase
from theano.compile import DebugMode
from theano.tests.unittest_tools import SkipTest, assert_allclose
from theano.tensor.tests import test_elemwise
......@@ -79,6 +82,19 @@ class TestMathErrorFunctions(TestCase):
self.expected_erfinv_outputs[dtype] = scipy.special.erfinv(numpy_array)
self.expected_erfcinv_outputs[dtype] = scipy.special.erfcinv(numpy_array)
# Since there are infinite values, we need to disable that check
# in DebugMode if needed
if isinstance(mode_with_gpu, DebugMode):
self.mode_with_gpu = copy(mode_with_gpu)
self.mode_with_gpu.check_isfinite = False
else:
self.mode_with_gpu = mode_with_gpu
if isinstance(mode_without_gpu, DebugMode):
self.mode_without_gpu = copy(mode_without_gpu)
self.mode_without_gpu.check_isfinite = False
else:
self.mode_without_gpu = mode_without_gpu
def check_gpu_scalar_op(self, theano_function, scalar_optype):
for node in theano_function.maker.fgraph.apply_nodes:
if isinstance(node.op, GpuElemwise) and isinstance(node.op.scalar_op, scalar_optype):
......@@ -90,8 +106,8 @@ class TestMathErrorFunctions(TestCase):
for dtype in self.dtypes:
vector = theano.tensor.vector(dtype=dtype)
output = theano.tensor.erfinv(vector)
f_host = theano.function([vector], output, name='HOST/erfinv/' + dtype, mode=mode_without_gpu)
f_gpu = theano.function([vector], output, name='GPU/erfinv/' + dtype, mode=mode_with_gpu)
f_host = theano.function([vector], output, name='HOST/erfinv/' + dtype, mode=self.mode_without_gpu)
f_gpu = theano.function([vector], output, name='GPU/erfinv/' + dtype, mode=self.mode_with_gpu)
assert len([n for n in f_host.maker.fgraph.apply_nodes if isinstance(n.op, GpuElemwise)]) == 0
if not theano.config.device.startswith('opencl'):
assert self.check_gpu_scalar_op(f_gpu, GpuErfinv), \
......@@ -108,8 +124,8 @@ class TestMathErrorFunctions(TestCase):
for dtype in self.dtypes:
vector = theano.tensor.vector(dtype=dtype)
output = theano.tensor.erfcinv(vector)
f_host = theano.function([vector], output, name='HOST/erfcinv/' + dtype, mode=mode_without_gpu)
f_gpu = theano.function([vector], output, name='GPU/erfcinv/' + dtype, mode=mode_with_gpu)
f_host = theano.function([vector], output, name='HOST/erfcinv/' + dtype, mode=self.mode_without_gpu)
f_gpu = theano.function([vector], output, name='GPU/erfcinv/' + dtype, mode=self.mode_with_gpu)
assert len([n for n in f_host.maker.fgraph.apply_nodes if isinstance(n.op, GpuElemwise)]) == 0
if not theano.config.device.startswith('opencl'):
assert self.check_gpu_scalar_op(f_gpu, GpuErfcinv), \
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论