当前位置: 首页>>代码示例>>Python>>正文


Python config.compute_test_value方法代码示例

本文整理汇总了Python中theano.config.compute_test_value方法的典型用法代码示例。如果您正苦于以下问题:Python config.compute_test_value方法的具体用法?Python config.compute_test_value怎么用?Python config.compute_test_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.config的用法示例。


在下文中一共展示了config.compute_test_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test1_err_bounds

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test1_err_bounds(self):
        n = self.shared(numpy.ones(3, dtype=self.dtype))
        ctv_backup = config.compute_test_value
        config.compute_test_value = 'off'
        try:
            t = n[7]
        finally:
            config.compute_test_value = ctv_backup
        self.assertTrue(isinstance(t.owner.op, Subtensor))
        # Silence expected error messages
        _logger = logging.getLogger('theano.gof.opt')
        oldlevel = _logger.level
        _logger.setLevel(logging.CRITICAL)
        try:
            try:
                self.eval_output_and_check(t)
            except IndexError as e:
                return
            self.fail()
        finally:
            _logger.setLevel(oldlevel) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:23,代码来源:test_subtensor.py

示例2: test2_err_bounds0

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test2_err_bounds0(self):
        n = self.shared(numpy.ones((2, 3), dtype=self.dtype) * 5)
        ctv_backup = config.compute_test_value
        config.compute_test_value = 'off'
        try:
            for idx in [(0, 4), (0, -4)]:
                t = n[idx]
                self.assertTrue(isinstance(t.owner.op, Subtensor))
                # Silence expected warnings
                _logger = logging.getLogger('theano.gof.opt')
                oldlevel = _logger.level
                _logger.setLevel(logging.CRITICAL)
                try:
                    self.assertRaises(IndexError,
                                      self.eval_output_and_check, [t])
                finally:
                    _logger.setLevel(oldlevel)
        finally:
            config.compute_test_value = ctv_backup 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:test_subtensor.py

示例3: missing_test_message

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def missing_test_message(msg):
    """
    Displays msg, a message saying that some test_value is missing,
    in the appropriate form based on config.compute_test_value:

        off: The interactive debugger is off, so we do nothing.
        ignore: The interactive debugger is set to ignore missing inputs,
                so do nothing.
        warn: Display msg as a warning.

    Raises
    ------
    AttributeError
        With msg as the exception text.

    """
    action = config.compute_test_value
    if action == 'raise':
        raise AttributeError(msg)
    elif action == 'warn':
        warnings.warn(msg, stacklevel=2)
    else:
        assert action in ['ignore', 'off'] 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:25,代码来源:op.py

示例4: debug_error_message

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def debug_error_message(msg):
    """
    Displays a message saying that an error was found in some
    test_values. Becomes a warning or a ValueError depending on
    config.compute_test_value.

    """
    action = config.compute_test_value

    # this message should never be called when the debugger is off
    assert action != 'off'

    if action in ['raise', 'ignore']:
        raise ValueError(msg)
    else:
        assert action == 'warn'
        warnings.warn(msg, stacklevel=2) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:19,代码来源:op.py

示例5: test_variable_only

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_variable_only(self):
        orig_compute_test_value = theano.config.compute_test_value
        try:
            theano.config.compute_test_value = 'raise'

            x = T.matrix('x')
            x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
            y = T.matrix('y')
            y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)

            # should work
            z = T.dot(x, y)
            assert hasattr(z.tag, 'test_value')
            f = theano.function([x, y], z)
            assert _allclose(f(x.tag.test_value, y.tag.test_value),
                             z.tag.test_value)

            # this test should fail
            y.tag.test_value = numpy.random.rand(6, 5).astype(config.floatX)
            self.assertRaises(ValueError, T.dot, x, y)
        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:24,代码来源:test_compute_test_value.py

示例6: test_shared

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_shared(self):
        orig_compute_test_value = theano.config.compute_test_value
        try:
            theano.config.compute_test_value = 'raise'

            x = T.matrix('x')
            x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
            y = theano.shared(numpy.random.rand(4, 6).astype(config.floatX),
                              'y')

            # should work
            z = T.dot(x, y)
            assert hasattr(z.tag, 'test_value')
            f = theano.function([x], z)
            assert _allclose(f(x.tag.test_value), z.tag.test_value)

            # this test should fail
            y.set_value(numpy.random.rand(5, 6).astype(config.floatX))
            self.assertRaises(ValueError, T.dot, x, y)
        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:23,代码来源:test_compute_test_value.py

示例7: test_empty_elemwise

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_empty_elemwise(self):
        orig_compute_test_value = theano.config.compute_test_value
        try:
            theano.config.compute_test_value = 'raise'

            x = theano.shared(numpy.random.rand(0, 6).astype(config.floatX),
                              'x')

            # should work
            z = (x + 2) * 3
            assert hasattr(z.tag, 'test_value')
            f = theano.function([], z)
            assert _allclose(f(), z.tag.test_value)

        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:18,代码来源:test_compute_test_value.py

示例8: test_constant

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_constant(self):
        orig_compute_test_value = theano.config.compute_test_value
        try:
            theano.config.compute_test_value = 'raise'

            x = T.constant(numpy.random.rand(2, 3), dtype=config.floatX)
            y = theano.shared(numpy.random.rand(3, 6).astype(config.floatX),
                              'y')

            # should work
            z = T.dot(x, y)
            assert hasattr(z.tag, 'test_value')
            f = theano.function([], z)
            assert _allclose(f(), z.tag.test_value)

            # this test should fail
            x = T.constant(numpy.random.rand(2, 4), dtype=config.floatX)
            self.assertRaises(ValueError, T.dot, x, y)
        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:22,代码来源:test_compute_test_value.py

示例9: test_no_perform

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_no_perform(self):
        if not theano.config.cxx:
            raise SkipTest("G++ not available, so we need to skip this test.")

        orig_compute_test_value = theano.config.compute_test_value
        try:
            theano.config.compute_test_value = 'raise'

            i = scalar.int32('i')
            i.tag.test_value = 3

            # Class IncOneC is defined outside of the TestComputeTestValue
            # so it can be pickled and unpickled
            o = IncOneC()(i)

            # Check that the perform function is not implemented
            self.assertRaises((NotImplementedError, utils.MethodNotDefined),
                              o.owner.op.perform,
                              o.owner, 0, [None])

            assert hasattr(o.tag, 'test_value')
            assert o.tag.test_value == 4

        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:27,代码来源:test_compute_test_value.py

示例10: init_H_hat

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def init_H_hat(self, V):
        """
        .. todo::

            WRITEME
        """

        if self.model.recycle_q:
            rval = self.model.prev_H

            if config.compute_test_value != 'off':
                if rval.get_value().shape[0] != V.tag.test_value.shape[0]:
                    raise Exception('E step given wrong test batch size', rval.get_value().shape, V.tag.test_value.shape)
        else:
            #just use the prior
            value =  T.nnet.sigmoid(self.model.bias_hid)
            rval = T.alloc(value, V.shape[0], value.shape[0])

            for rval_value, V_value in get_debug_values(rval, V):
                if rval_value.shape[0] != V_value.shape[0]:
                    debug_error_message("rval.shape = %s, V.shape = %s, element 0 should match but doesn't", str(rval_value.shape), str(V_value.shape))

        return rval 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:25,代码来源:s3c.py

示例11: make_theano_batch

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def make_theano_batch(self, name=None, dtype=None, batch_size=None):

        dtype = self._clean_dtype_arg(dtype)
        broadcastable = [False] * 3
        broadcastable[1] = (batch_size == 1)
        broadcastable[2] = (self.dim == 1)
        broadcastable = tuple(broadcastable)

        rval = TensorType(dtype=dtype,
                          broadcastable=broadcastable
                          )(name=name)

        if config.compute_test_value != 'off':
            if batch_size == 1:
                n = 1
            else:
                # TODO: try to extract constant scalar value from batch_size
                n = 4
            rval.tag.test_value = self.get_origin_batch(batch_size=n,
                                                        dtype=dtype)

        return rval 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:24,代码来源:__init__.py

示例12: test_compute_flag

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_compute_flag(self):
        orig_compute_test_value = theano.config.compute_test_value
        try:
            x = T.matrix('x')
            y = T.matrix('y')
            y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)

            # should skip computation of test value
            theano.config.compute_test_value = 'off'
            z = T.dot(x, y)
            assert not hasattr(z.tag, 'test_value')

            # should fail when asked by user
            theano.config.compute_test_value = 'raise'
            self.assertRaises(ValueError, T.dot, x, y)

            # test that a warning is raised if required
            theano.config.compute_test_value = 'warn'
            warnings.simplefilter('error', UserWarning)
            try:
                self.assertRaises(UserWarning, T.dot, x, y)
            finally:
                # Restore the default behavior.
                # TODO There is a cleaner way to do this in Python 2.6, once
                # Theano drops support of Python 2.4 and 2.5.
                warnings.simplefilter('default', UserWarning)
        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:30,代码来源:test_compute_test_value.py

示例13: test_string_var

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_string_var(self):
        orig_compute_test_value = theano.config.compute_test_value
        try:
            theano.config.compute_test_value = 'raise'

            x = T.matrix('x')
            x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
            y = T.matrix('y')
            y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)

            z = theano.shared(numpy.random.rand(5, 6).astype(config.floatX))

            # should work
            out = T.dot(T.dot(x, y), z)
            assert hasattr(out.tag, 'test_value')
            tf = theano.function([x, y], out)
            assert _allclose(
                tf(x.tag.test_value, y.tag.test_value),
                out.tag.test_value)

            def f(x, y, z):
                return T.dot(T.dot(x, y), z)

            # this test should fail
            z.set_value(numpy.random.rand(7, 6).astype(config.floatX))
            self.assertRaises(ValueError, f, x, y, z)
        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:30,代码来源:test_compute_test_value.py

示例14: test_incorrect_type

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_incorrect_type(self):
        orig_compute_test_value = theano.config.compute_test_value
        try:
            theano.config.compute_test_value = 'raise'

            x = T.fmatrix('x')
            # Incorrect dtype (float64) for test_value
            x.tag.test_value = numpy.random.rand(3, 4)
            y = T.dmatrix('y')
            y.tag.test_value = numpy.random.rand(4, 5)

            self.assertRaises(TypeError, T.dot, x, y)
        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:16,代码来源:test_compute_test_value.py

示例15: test_overided_function

# 需要导入模块: from theano import config [as 别名]
# 或者: from theano.config import compute_test_value [as 别名]
def test_overided_function(self):
        # We need to test those as they mess with Exception
        # And we don't want the exception to be changed.
        orig_compute_test_value = theano.config.compute_test_value
        try:
            config.compute_test_value = "raise"
            x = T.matrix()
            x.tag.test_value = numpy.zeros((2, 3), dtype=config.floatX)
            y = T.matrix()
            y.tag.test_value = numpy.zeros((2, 2), dtype=config.floatX)
            self.assertRaises(ValueError, x.__mul__, y)
        finally:
            theano.config.compute_test_value = orig_compute_test_value 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:15,代码来源:test_compute_test_value.py


注:本文中的theano.config.compute_test_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。