提交 5b6448e2 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Type context for test_basic_ops.py

上级 6dc2aac4
...@@ -14,22 +14,17 @@ from theano.tensor.tests import test_basic ...@@ -14,22 +14,17 @@ from theano.tensor.tests import test_basic
from theano.tensor.tests.test_basic import rand, safe_make_node from theano.tensor.tests.test_basic import rand, safe_make_node
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
import theano.sandbox.gpuarray from ..type import (GpuArrayType, get_context,
from ..type import (GpuArrayType,
gpuarray_shared_constructor) gpuarray_shared_constructor)
from ..basic_ops import ( from ..basic_ops import (
host_from_gpu, gpu_from_host, HostFromGpu, GpuFromHost, GpuReshape, host_from_gpu, HostFromGpu, GpuFromHost, GpuReshape,
gpu_alloc, GpuAlloc, GpuAllocEmpty, GpuContiguous, GpuAlloc, GpuAllocEmpty, GpuContiguous,
gpu_join, GpuJoin, GpuSplit, GpuEye, gpu_contiguous) gpu_join, GpuJoin, GpuSplit, GpuEye, gpu_contiguous)
from ..subtensor import GpuSubtensor from ..subtensor import GpuSubtensor
from .config import mode_with_gpu, mode_without_gpu from .config import mode_with_gpu, mode_without_gpu, test_ctx_name
try: from pygpu import gpuarray
from pygpu import gpuarray
except:
pass
utt.seed_rng() utt.seed_rng()
rng = numpy.random.RandomState(seed=utt.fetch_seed()) rng = numpy.random.RandomState(seed=utt.fetch_seed())
...@@ -176,7 +171,7 @@ def test_transfer_cpu_gpu(): ...@@ -176,7 +171,7 @@ def test_transfer_cpu_gpu():
av = numpy.asarray(rng.rand(5, 4), dtype='float32') av = numpy.asarray(rng.rand(5, 4), dtype='float32')
gv = gpuarray.array(av) gv = gpuarray.array(av)
f = theano.function([a], gpu_from_host(a)) f = theano.function([a], GpuFromHost(None)(a))
fv = f(av) fv = f(av)
assert GpuArrayType.values_eq(fv, gv) assert GpuArrayType.values_eq(fv, gv)
...@@ -198,7 +193,7 @@ def test_transfer_strided(): ...@@ -198,7 +193,7 @@ def test_transfer_strided():
av = av[:, ::2] av = av[:, ::2]
gv = gv[:, ::2] gv = gv[:, ::2]
f = theano.function([a], gpu_from_host(a)) f = theano.function([a], GpuFromHost(None)(a))
fv = f(av) fv = f(av)
assert GpuArrayType.values_eq(fv, gv) assert GpuArrayType.values_eq(fv, gv)
...@@ -208,14 +203,14 @@ def test_transfer_strided(): ...@@ -208,14 +203,14 @@ def test_transfer_strided():
def gpu_alloc_expected(x, *shp): def gpu_alloc_expected(x, *shp):
g = gpuarray.empty(shp, dtype=x.dtype) g = gpuarray.empty(shp, dtype=x.dtype, context=get_context(test_ctx_name))
g[:] = x g[:] = x
return g return g
GpuAllocTester = makeTester( GpuAllocTester = makeTester(
name="GpuAllocTester", name="GpuAllocTester",
op=alloc, op=alloc,
gpu_op=gpu_alloc, gpu_op=GpuAlloc(test_ctx_name),
cases=dict( cases=dict(
correct01=(rand(), numpy.int32(7)), correct01=(rand(), numpy.int32(7)),
# just gives a DeepCopyOp with possibly wrong results on the CPU # just gives a DeepCopyOp with possibly wrong results on the CPU
...@@ -413,10 +408,10 @@ def test_hostfromgpu_shape_i(): ...@@ -413,10 +408,10 @@ def test_hostfromgpu_shape_i():
cv = gpuarray.asarray(numpy.random.rand(5, 4), cv = gpuarray.asarray(numpy.random.rand(5, 4),
dtype='float32') dtype='float32')
f = theano.function([a], gpu_from_host(a), mode=m) f = theano.function([a], GpuFromHost(None)(a), mode=m)
assert gpu_from_host in [x.op assert any([isinstance(x.op, GpuFromHost)
for x in f.maker.fgraph.toposort()] for x in f.maker.fgraph.toposort()])
f = theano.function([a], gpu_from_host(a).shape, mode=m) f = theano.function([a], GpuFromHost(None)(a).shape, mode=m)
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
assert isinstance(topo[0].op, T.opt.Shape_i) assert isinstance(topo[0].op, T.opt.Shape_i)
assert isinstance(topo[1].op, T.opt.Shape_i) assert isinstance(topo[1].op, T.opt.Shape_i)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论