提交 c3f571f8 authored 作者: Frederic's avatar Frederic

add test for the grad of theano.sparse.col_scale

上级 c4a12dcb
...@@ -17,6 +17,7 @@ import theano ...@@ -17,6 +17,7 @@ import theano
from theano.sparse.sandbox import sp from theano.sparse.sandbox import sp
from theano.sparse.tests.test_basic import random_lil from theano.sparse.tests.test_basic import random_lil
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.sparse import verify_grad_sparse
class TestSP(unittest.TestCase): class TestSP(unittest.TestCase):
...@@ -528,15 +529,12 @@ def test_col_scale(): ...@@ -528,15 +529,12 @@ def test_col_scale():
x = theano.sparse.csc_dmatrix() x = theano.sparse.csc_dmatrix()
s = theano.tensor.dvector() s = theano.tensor.dvector()
def d(x,s):
return sp.sp_sum(sp.col_scale(x, s), sparse_grad=True)
rng = numpy.random.RandomState(8723) rng = numpy.random.RandomState(8723)
R = 5 R = 5
C = 8 C = 8
x_val_dense = numpy.zeros((R, C),dtype='d') x_val_dense = numpy.zeros((R, C), dtype='d')
for idx in [(0,0), (4, 1), (2,1), (3, 3), (4, 4), (3, 7), (2, 7)]: for idx in [(0, 0), (4, 1), (2, 1), (3, 3), (4, 4), (3, 7), (2, 7)]:
x_val_dense.__setitem__(idx, rng.randn()) x_val_dense.__setitem__(idx, rng.randn())
x_val = scipy.sparse.csc_matrix(x_val_dense) x_val = scipy.sparse.csc_matrix(x_val_dense)
...@@ -549,11 +547,7 @@ def test_col_scale(): ...@@ -549,11 +547,7 @@ def test_col_scale():
assert numpy.all(f(x_val, s_val).toarray() == (x_val_dense * s_val)) assert numpy.all(f(x_val, s_val).toarray() == (x_val_dense * s_val))
if 0: verify_grad_sparse(sp.col_scale, [x_val, s_val], structured=False)
tensor.verify_grad(None, d, [x_val, s_val],
mode=theano.Mode(linker='py', optimizer='fast_compile'))
else:
print >> sys.stderr, "WARNING: skipping gradient test because verify_grad doesn't support sparse arguments"
if __name__ == '__main__': if __name__ == '__main__':
if 0: if 0:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论