提交 f2608775 authored 作者: David Warde-Farley's avatar David Warde-Farley

Merge pull request #126 from nouiz/join_test

Split/Join tests
...@@ -881,8 +881,8 @@ def local_gpu_join(node): ...@@ -881,8 +881,8 @@ def local_gpu_join(node):
#print "OPT: axis_and_tensors=", axis_and_tensors #print "OPT: axis_and_tensors=", axis_and_tensors
matches = [not t.owner is None and t.owner.op == host_from_gpu for t in axis_and_tensors[1:]] matches = [(not t.owner is None and t.owner.op == host_from_gpu) or
isinstance(t, gof.Constant) for t in axis_and_tensors[1:]]
#print "OPT: matches =", matches #print "OPT: matches =", matches
# if all input tensors are host_from_gpu'ified # if all input tensors are host_from_gpu'ified
......
...@@ -646,76 +646,6 @@ def test_hostfromgpu_shape_i(): ...@@ -646,76 +646,6 @@ def test_hostfromgpu_shape_i():
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
import theano.sandbox.cuda as cuda_ndarray import theano.sandbox.cuda as cuda_ndarray
from theano.sandbox.cuda.basic_ops import gpu_join, GpuDimShuffle
def test_gpujoin_concatenate_one_element():
m = T.fmatrix()
c = T.concatenate([m])
f = theano.function(inputs=[m], outputs=[c], mode=mode_with_gpu)
topo = f.maker.env.toposort()
assert len(topo)==1
assert isinstance(topo[0].op,theano.compile.DeepCopyOp)
def test_gpujoin_twomatrices_joincolumns():
_a = numpy.asarray([[1,2],[3,4]],dtype='float32')
_b = numpy.asarray([[5,6,7],[8,9,10]],dtype='float32')
a = tcn.shared_constructor(_a)
b = tcn.shared_constructor(_b)
c = gpu_join(1,a,b)
f = theano.function([], c)
assert numpy.all(f() == numpy.concatenate([_a,_b], axis=1))
def test_gpujoin_twomatrices_badshapes():
_a = numpy.asarray([[1,2],[3,4]],dtype='float32')
_b = numpy.asarray([[5,6,7],[8,9,10]],dtype='float32')
a = tcn.shared_constructor(_a)
b = tcn.shared_constructor(_b)
# try to join on dimension 0 where they don't agree (2!=3)
c = gpu_join(0,a,b)
f = theano.function([], c)
try:
f()
assert False
except ValueError:
assert True
def test_gpujoin_preserves_broadcasting():
_a = numpy.asarray([[1,2],[3,4]],dtype='float32')
_b = numpy.asarray([[5,6,7],[8,9,10]],dtype='float32')
a = tcn.shared_constructor(_a)
b = tcn.shared_constructor(_b)
# [0,0] : the two original dims were non-broadcastable
# [1,x,0]: new order and broadcastability
gpu_dimshuffle = GpuDimShuffle([0,0], [1,'x',0])
a_shuffled = gpu_dimshuffle(a)
b_shuffled = gpu_dimshuffle(b)
c = gpu_join(0,a_shuffled,b_shuffled)
assert c.type.broadcastable == (False,True,False)
f = theano.function([], c, mode=mode_with_gpu)
res = f()
a_reshaped = numpy.asarray([[[1,3]],[[2,4]]], dtype='float32')
b_reshaped = numpy.asarray([[[5,8]],[[6,9]],[[7,10]]], dtype='float32')
concat = numpy.concatenate([a_reshaped,b_reshaped], axis=0)
assert numpy.all(res == concat)
def test_gpujoin_assert_cndas(): def test_gpujoin_assert_cndas():
# this will end up being an ndarray, as it's float64 # this will end up being an ndarray, as it's float64
...@@ -723,7 +653,7 @@ def test_gpujoin_assert_cndas(): ...@@ -723,7 +653,7 @@ def test_gpujoin_assert_cndas():
a = theano.shared(_a) a = theano.shared(_a)
try: try:
c = gpu_join(1,a) c = cuda.basic_ops.gpu_join(1, a)
# can't "assert False" here, as we want the assertion # can't "assert False" here, as we want the assertion
# error from gpu_join # error from gpu_join
except AssertionError: except AssertionError:
...@@ -792,6 +722,21 @@ def test_gpualloc_output_to_gpu(): ...@@ -792,6 +722,21 @@ def test_gpualloc_output_to_gpu():
assert numpy.allclose(f(5),f_gpu(5)) assert numpy.allclose(f(5),f_gpu(5))
import theano.tensor.tests.test_basic import theano.tensor.tests.test_basic
class T_Join_and_Split(theano.tensor.tests.test_basic.T_Join_and_Split):
def setUp(self):
utt.seed_rng()
self.mode = mode_with_gpu.excluding('constant_folding')
self.join_op = cuda.GpuJoin
# No gpu split.
self.split_op = tensor.Split
# No Make vector on the gpu, Join used instead
self.make_vector_op = cuda.GpuJoin
self.floatX = "float32"
# In FAST_COMPILE mode, we force the FAST_RUN mode for optimization.
self.hide_error = theano.config.mode not in ['DebugMode', 'DEBUG_MODE']
self.shared = cuda.shared_constructor
# This is to don't duplicate test. # This is to don't duplicate test.
class T_subtensor(theano.tensor.tests.test_basic.T_subtensor): class T_subtensor(theano.tensor.tests.test_basic.T_subtensor):
shared=staticmethod(cuda.shared_constructor) shared=staticmethod(cuda.shared_constructor)
......
...@@ -2892,8 +2892,9 @@ def extract_constant(x): ...@@ -2892,8 +2892,9 @@ def extract_constant(x):
This function is basically a call to tensor.get_constant_value. The This function is basically a call to tensor.get_constant_value. The
main difference is the behaviour in case of failure. While main difference is the behaviour in case of failure. While
get_constant_value raises an TypeError, this function returns x, get_constant_value raises an TypeError, this function returns x,
as a tensor ( by removing the last scalar_from_tensor ) if needed as a tensor if possible. If x is a ScalarVariable from a
or None if that is the value of x. scalar_from_tensor, we remove the conversion. If x is just a
ScalarVariable, we convert it to a tensor with tensor_from_scalar.
''' '''
try: try:
x = get_constant_value(x) x = get_constant_value(x)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论