提交 3545ffdf authored 作者: lamblin's avatar lamblin

Merge pull request #625 from nouiz/mixed

Mixed
......@@ -8,5 +8,5 @@ Python tutorial
In this documentation, we suppose that reader know python. Here is a small list of python tutorials/exercices if you know know it or need a refresher:
* `Python Challenge <http://www.pythonchallenge.com/>`__
* `Dive into Python <http://diveintopython.org/>`__
* `Dive into Python <http://diveintopython.net/>`__
* `Google Python Class <http://code.google.com/edu/languages/google-python-class/index.html>`__
......@@ -190,6 +190,7 @@ if __name__ == "__main__":
GTX580/3.2 0.20s
GTX480/3.2 0.24s
GTX480/3.0 0.27s
M2070/4.1 0.27s
GTX470/3.2 0.29s
M2070/3.2 0.32s
GTX470/3.0 0.34s
......
......@@ -61,9 +61,9 @@ def test_pycuda_elemwise_source_module():
val1 = numpy.asarray(numpy.random.rand(*shape), dtype='float32')
val2 = numpy.asarray(numpy.random.rand(*shape), dtype='float32')
assert (f(val1, val2) == f2(val1, val2)).all()
assert (f(val1, val2) == f3(val1, val2)).all()
assert (f(val1, val2) == f4(val1, val2)).all()
assert numpy.allclose(f(val1, val2), f2(val1, val2))
assert numpy.allclose(f(val1, val2), f3(val1, val2))
assert numpy.allclose(f(val1, val2), f4(val1, val2))
#print f(val1,val2)
#print f2(val1,val2)
......
......@@ -704,6 +704,14 @@ class CSM(gof.Op):
g_data = csm_grad(self.kmap)(data, csm_data(g_out), csm_indices(g_out))
return [g_data, None, None, None]
def infer_shape(self, node, shapes):
if self.kmap is None:
# node.inputs[3] is of lenght as we only support sparse matrix.
return [(node.inputs[3][0], node.inputs[3][1])]
else:
return node.env.shape_feature.default_infer_shape(node, shapes)
CSC = CSM('csc')
CSR = CSM('csr')
......
......@@ -153,6 +153,22 @@ class SparseInferShapeTester(utt.InferShapeTester):
config.floatX, 3))],
GetItemScalar)
def test_csm(self):
for sparsetype in ('csr', 'csc'):
x = tensor.vector()
y = tensor.ivector()
z = tensor.ivector()
s = tensor.ivector()
call = getattr(sp, sparsetype + '_matrix')
spm = call(random_lil((300, 400), config.floatX, 5))
out = CSM(sparsetype)(x, y, z, s)
self._compile_and_check([x, y, z, s],
[out],
[spm.data, spm.indices, spm.indptr,
spm.shape],
CSM
)
def test_csm_grad(self):
for sparsetype in ('csr', 'csc'):
x = tensor.vector()
......@@ -262,10 +278,6 @@ class SparseInferShapeTester(utt.InferShapeTester):
config.floatX, 3))],
StructuredDot)
def test_csm(self):
# We also need the grad of CSM to be implemetned.
raise SkipTest('infer_shape not implemented for CSM')
def test_structured_dot_grad(self):
# We also need the grad of CSM to be implemetned.
raise SkipTest('infer_shape not implemented for the grad'
......
......@@ -2441,10 +2441,14 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
n = self.shared(numpy.asarray(5, dtype=self.dtype))
self.assertRaises(TypeError, n.__getitem__, [0,0])
def test_err_invalid_2list(self):
# TODO the error message is not clear
n = self.shared(numpy.ones((3,3), dtype=self.dtype)*5)
self.assertRaises(TypeError, n.__getitem__, ([0,0],[1,1]))
def test_err_invalid_not_2d(self):
n = self.shared(numpy.ones((3, 3, 3), dtype=self.dtype) * 5)
self.assertRaises(NotImplementedError, n.__getitem__,
([0, 0, 0], [1, 1, 1], [2, 2, 2]))
def test_err_invalid_2list_dtype(self):
n = self.shared(numpy.ones((3, 3), dtype=self.dtype) * 5)
self.assertRaises(TypeError, n.__getitem__, ([0., 0], [1, 1]))
def test_err_bound_list(self):
n = self.shared(numpy.ones((2,3),dtype=self.dtype)*5)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论