本文整理汇总了Python中theano.sandbox.gpuarray.type.GpuArrayType.values_eq_approx方法的典型用法代码示例。如果您正苦于以下问题:Python GpuArrayType.values_eq_approx方法的具体用法?Python GpuArrayType.values_eq_approx怎么用?Python GpuArrayType.values_eq_approx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.sandbox.gpuarray.type.GpuArrayType
的用法示例。
在下文中一共展示了GpuArrayType.values_eq_approx方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_transfer_cuda_gpu
# 需要导入模块: from theano.sandbox.gpuarray.type import GpuArrayType [as 别名]
# 或者: from theano.sandbox.gpuarray.type.GpuArrayType import values_eq_approx [as 别名]
def test_transfer_cuda_gpu():
import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available == False:
raise SkipTest("Can't test interaction with cuda if cuda not present")
g = GpuArrayType(dtype='float32', broadcastable=(False, False))('g')
c = cuda_ndarray.CudaNdarrayType((False, False))('c')
av = theano._asarray(rng.rand(5, 4), dtype='float32')
gv = gpuarray.array(av)
cv = cuda_ndarray.CudaNdarray(av)
gvs = gv[:,::-2]
cvs = cv[:,::-2]
f = theano.function([c], gpu_from_cuda(c))
fv = f(cv)
assert GpuArrayType.values_eq_approx(fv, gv)
fvs = f(cvs)
assert GpuArrayType.values_eq_approx(fvs, gvs)
f = theano.function([g], cuda_from_gpu(g))
fv = f(gv)
assert cuda_ndarray.CudaNdarrayType.values_eq_approx(fv, cv)
fvs = f(gvs)
assert cuda_ndarray.CudaNdarrayType.values_eq_approx(fvs, cvs)
示例2: test_values_eq_approx
# 需要导入模块: from theano.sandbox.gpuarray.type import GpuArrayType [as 别名]
# 或者: from theano.sandbox.gpuarray.type.GpuArrayType import values_eq_approx [as 别名]
def test_values_eq_approx():
a = rand_gpuarray(20, dtype='float32')
g = GpuArrayType(dtype='float32', broadcastable=(False,))('g')
assert GpuArrayType.values_eq_approx(a, a)
b = a.copy()
b[0] = numpy.asarray(b[0]) + 1.
assert not GpuArrayType.values_eq_approx(a, b)
b = a.copy()
b[0] = -numpy.asarray(b[0])
assert not GpuArrayType.values_eq_approx(a, b)
示例3: values_eq_approx
# 需要导入模块: from theano.sandbox.gpuarray.type import GpuArrayType [as 别名]
# 或者: from theano.sandbox.gpuarray.type.GpuArrayType import values_eq_approx [as 别名]
def values_eq_approx(a, b):
"""This fct is needed to don't have DebugMode raise useless
error due to ronding error.
This happen as We reduce on the two last dimensions, so this
can raise the absolute error if the number of element we
reduce on is significant.
"""
assert a.ndim == 4
atol = None
if a.shape[-1] * a.shape[-2] > 100:
# For float32 the default atol is 1e-5
atol = 3e-5
return GpuArrayType.values_eq_approx(a, b, atol=atol)
示例4: makeTester
# 需要导入模块: from theano.sandbox.gpuarray.type import GpuArrayType [as 别名]
# 或者: from theano.sandbox.gpuarray.type.GpuArrayType import values_eq_approx [as 别名]
def makeTester(name, op, expected, good=None, bad_build=None, checks=None,
bad_runtime=None, mode=None, skip=False, eps=1e-10):
if good is None:
good = {}
if bad_build is None:
bad_build = {}
if bad_runtime is None:
bad_runtime = {}
if checks is None:
checks = {}
_op = op
_expected = expected
_good = good
_bad_build = bad_build
_bad_runtime = bad_runtime
_skip = skip
_checks = checks
class Checker(unittest.TestCase):
op = staticmethod(_op)
expected = staticmethod(_expected)
good = _good
bad_build = _bad_build
bad_runtime = _bad_runtime
skip = _skip
checks = _checks
def setUp(self):
eval(self.__class__.__module__ + '.' + self.__class__.__name__)
def test_good(self):
if skip:
raise SkipTest(skip)
for testname, inputs in good.items():
inputs = [copy(input) for input in inputs]
inputrs = [fake_shared(input) for input in inputs]
try:
node = safe_make_node(self.op, *inputrs)
except Exception, exc:
err_msg = ("Test %s::%s: Error occured while making "
"a node with inputs %s") % (self.op, testname,
inputs)
exc.args += (err_msg,)
raise
try:
f = inplace_func([], node.outputs, mode=mode,
name='test_good')
except Exception, exc:
err_msg = ("Test %s::%s: Error occured while trying to "
"make a Function") % (self.op, testname)
exc.args += (err_msg,)
raise
if isinstance(self.expected, dict) and \
testname in self.expected:
expecteds = self.expected[testname]
else:
expecteds = self.expected(*inputs)
if not isinstance(expecteds, (list, tuple)):
expecteds = (expecteds,)
try:
variables = f()
except Exception, exc:
err_msg = ("Test %s::%s: Error occured while calling "
"the Function on the inputs %s") % (self.op,
testname,
inputs)
exc.args += (err_msg,)
raise
for i, (variable, expected) in \
enumerate(izip(variables, expecteds)):
if variable.dtype != expected.dtype or \
variable.shape != expected.shape or \
not GpuArrayType.values_eq_approx(variable,
expected):
self.fail(("Test %s::%s: Output %s gave the wrong "
"value. With inputs %s, expected %s "
"(dtype %s), got %s (dtype %s).") % (
self.op, testname, i, inputs, expected,
expected.dtype, variable, variable.dtype))
for description, check in self.checks.items():
if not check(inputs, variables):
self.fail(("Test %s::%s: Failed check: %s "
"(inputs were %s, ouputs were %s)") %
(self.op, testname, description,
inputs, variables))