提交 6c77f4a6 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Add test to check that the inplace opts are working.

上级 93879ae4
...@@ -6,7 +6,11 @@ import numpy ...@@ -6,7 +6,11 @@ import numpy
from numpy.random import randn from numpy.random import randn
from theano.sandbox.cuda.blocksparse import (sparse_block_dot_SS, from theano.sandbox.cuda.blocksparse import (sparse_block_dot_SS,
sparse_block_gemv_ss) sparse_block_gemv_ss,
sparse_block_gemv_ss_inplace)
sparse_block_outer_ss,
sparse_block_outer_ss_inplace)
def blocksparse_data(): def blocksparse_data():
nInputBlock = 128 nInputBlock = 128
...@@ -93,3 +97,26 @@ def test_blocksparse_grad_shape(): ...@@ -93,3 +97,26 @@ def test_blocksparse_grad_shape():
assert b_g.shape == b_val.shape assert b_g.shape == b_val.shape
assert h_g.shape == h_val.shape assert h_g.shape == h_val.shape
assert W_g.shape == W_val.shape assert W_g.shape == W_val.shape
class TestBlockSparseDot(TestCase, utt.TestOptimizationMixin):
def test_opt_inplace(self):
b = tensor.fmatrix()
W = tensor.ftensor4()
h = tensor.fmatrix()
iIdx = tensor.lvector()
oIdx = tensor.lvector()
o = sparse_block_dot_SS(W, h, iIdx, b, oIdx)
f = theano.function([W, h, iIdx, b, oIdx], o)
self.assertFunctionContains0(f, sparse_block_gemv_ss)
self.assertFunctionContains1(f, sparse_block_gemv_ss_inplace)
gW = theano.grad(o.sum(), [W])
f = theano.function([W, h, iIdx, b, oIdx], gW)
self.assertFunctionContains0(f, sparse_block_outer_ss)
self.assertFunctionContains1(f, sparse_block_outer_ss_inplace)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论