提交 b9eaaf7e authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Very basic starter test.

上级 0e2f02dd
from nose.plugins.skip import SkipTest
import numpy
import theano.tensor as T
import theano.sandbox.gpuarray
if theano.sandbox.gpuarray.pygpu is None:
raise SkipTest("pygpu disabled")
from theano.sandbox.gpuarray.type import GpuArrayType
from theano.sandbox.gpuarray.basic_ops import (host_from_gpu, gpu_from_host)
from pygpu import gpuarray
def rand_gpuarray(shape, dtype):
return gpuarray.array(numpy.random.rand(*shape), dtype=dtype)
def test_transfer():
a = T.fmatrix('a')
g = GpuArrayType(dtype='float32', broadcastable=(False, False))('g')
av = numpy.asarray(numpy.random.rand(5, 4), dtype='float32')
gv = gpuarray.array(av, kind=g.type.kind, context=g.type.context)
f = theano.function([a], gpu_from_host(a))
fv = f(av)
assert numpy.allclose(fv, gv)
f = theano.function([g], host_from_gpu(g))
fv = f(gv)
assert numpy.allclose(fv, av)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论