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

Add computation tests for sparse.Dot with a vector as input.

上级 155e2eb9
...@@ -1054,42 +1054,37 @@ class DotTests(utt.InferShapeTester): ...@@ -1054,42 +1054,37 @@ class DotTests(utt.InferShapeTester):
y = theano.tensor.matrix('y') y = theano.tensor.matrix('y')
v = theano.tensor.vector('v') v = theano.tensor.vector('v')
f_a = theano.function([x, y], theano.sparse.dot(x, y)) for (x, y, x_v, y_v) in [(x, y, self.x_csr, self.y),
f_b = lambda x, y: x * y (x, v, self.x_csr, self.v_100),
(v, x, self.v_10, self.x_csr)]:
assert _allclose(f_a(self.x_csr, self.y), f_b(self.x_csr, self.y)) f_a = theano.function([x, y], theano.sparse.dot(x, y))
f_b = lambda x, y: x * y
# Test infer_shape
self._compile_and_check([x, y], [theano.sparse.dot(x, y)], assert _allclose(f_a(x_v, y_v), f_b(x_v, y_v))
[self.x_csr, self.y],
(Dot, Usmm, UsmmCscDense)) # Test infer_shape
self._compile_and_check([v, x], [theano.sparse.dot(v, x)], self._compile_and_check([x, y], [theano.sparse.dot(x, y)],
[self.v_10, self.x_csr], [x_v, y_v],
(Dot, Usmm, UsmmCscDense)) (Dot, Usmm, UsmmCscDense))
self._compile_and_check([x, v], [theano.sparse.dot(x, v)],
[self.x_csr, self.v_100],
(Dot, Usmm, UsmmCscDense))
def test_csc_dense(self): def test_csc_dense(self):
x = theano.sparse.csc_matrix('x') x = theano.sparse.csc_matrix('x')
y = theano.tensor.matrix('y') y = theano.tensor.matrix('y')
v = theano.tensor.vector('v') v = theano.tensor.vector('v')
f_a = theano.function([x, y], theano.sparse.dot(x, y)) for (x, y, x_v, y_v) in [(x, y, self.x_csc, self.y),
f_b = lambda x, y: x * y (x, v, self.x_csc, self.v_100),
(v, x, self.v_10, self.x_csc)]:
assert _allclose(f_a(self.x_csc, self.y), f_b(self.x_csc, self.y))
f_a = theano.function([x, y], theano.sparse.dot(x, y))
# Test infer_shape f_b = lambda x, y: x * y
self._compile_and_check([x, y], [theano.sparse.dot(x, y)],
[self.x_csc, self.y], assert _allclose(f_a(x_v, y_v), f_b(x_v, y_v))
(Dot, Usmm, UsmmCscDense))
self._compile_and_check([v, x], [theano.sparse.dot(v, x)], # Test infer_shape
[self.v_10, self.x_csc], self._compile_and_check([x, y], [theano.sparse.dot(x, y)],
(Dot, Usmm, UsmmCscDense)) [x_v, y_v],
self._compile_and_check([x, v], [theano.sparse.dot(x, v)], (Dot, Usmm, UsmmCscDense))
[self.x_csc, self.v_100],
(Dot, Usmm, UsmmCscDense))
def test_sparse_sparse(self): def test_sparse_sparse(self):
for d1, d2 in [('float32', 'float32'), for d1, d2 in [('float32', 'float32'),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论