提交 bdc35e92 authored 作者: Frederic's avatar Frederic 提交者: Pascal Lamblin

Fix the tests newly broken and make it use verify_grad.

上级 86842b83
...@@ -857,27 +857,17 @@ class test_csm(unittest.TestCase): ...@@ -857,27 +857,17 @@ class test_csm(unittest.TestCase):
z = tensor.ivector() z = tensor.ivector()
s = tensor.ivector() s = tensor.ivector()
# Sparse advanced indexing produces unsorted sparse matrices # Sparse advanced indexing produces unsorted sparse matrices
a = sparse_random_inputs(format, (4, 3), a = sparse_random_inputs(format, (4, 3), out_dtype=dtype,
unsorted_indices=True)[1][0] unsorted_indices=True)[1][0]
# Make sure it's unsorted # Make sure it's unsorted
assert not a.has_sorted_indices assert not a.has_sorted_indices
a = as_sparse_variable(a) def my_op(x):
y = tensor.constant(a.indices)
f = theano.function([x, y, z, s], tensor.grad(tensor.sum( z = tensor.constant(a.indptr)
dense_from_sparse(a * CSM(format)(x, y, z, s))), x)) s = tensor.constant(a.shape)
return tensor.sum(
spmat = sp_types[format](random_lil((4, 3), dtype, dense_from_sparse(CSM(format)(x, y, z, s) * a))
12))[range(4)] verify_grad_sparse(my_op, [a.data])
assert not spmat.has_sorted_indices
res = f(spmat.data, spmat.indices, spmat.indptr,
numpy.asarray(spmat.shape, 'int32'))
col1 = sp_types[format]((res, spmat.indices, spmat.indptr),
shape=numpy.asarray(spmat.shape,
'int32'))[:, 1].data
assert numpy.all(col1 == 2)
def test_csm(self): def test_csm(self):
sp_types = {'csc': sp.csc_matrix, sp_types = {'csc': sp.csc_matrix,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论