提交 83356200 authored 作者: Valentin Bisson's avatar Valentin Bisson

Merge test_sp.py.

......@@ -240,7 +240,7 @@ class Remove0(Op):
if self.inplace:
l.append('inplace')
return self.__class__.__name__+'{%s}'%', '.join(l)
def make_node(self, x):
return gof.Apply(self, [x], [x.type()])
......
......@@ -438,11 +438,12 @@ def test_remove0():
print 'config: format=\'%(format)s\', matrix_class=%(matrix_class)s'%locals()
# real
origin = (numpy.arange(9) + 1).reshape((3, 3)).astype(theano.config.floatX)
with0 = matrix_class(origin).astype(theano.config.floatX)
with0[0,1] = with0[1,0] = with0[2,2] = 0
assert with0.size == 9
mat = matrix_class(origin).astype(theano.config.floatX)
mat[0,1] = mat[1,0] = mat[2,2] = 0
assert mat.size == 9
# symbolic
x = theano.sparse.SparseType(format=format, dtype=theano.config.floatX)()
# the In thingy has to be there because theano has as rule not to optimize inputs
......@@ -453,12 +454,12 @@ def test_remove0():
nodes = f.maker.env.toposort()
v = [True for node in nodes if isinstance(node.op, sp.Remove0) and node.op.inplace]
assert len(v), 'Inplacing optimization should have been applied.'
# checking
# makes sense to change its name
target = with0
result = f(with0)
with0.eliminate_zeros()
target = mat
result = f(mat)
mat.eliminate_zeros()
assert result.size == target.size, 'Matrices sizes differ. Have zeros been removed ?'
def test_diagonal():
......
......@@ -731,7 +731,7 @@ class ShapeFeature(object):
def default_infer_shape(self, node, i_shapes):
"""Return a list of shape tuple or None for the outputs of node.
This function is used for Ops that don't implement infer_shape.
Ops that do implement infer_shape should use the i_shapes parameter,
but this default implementation ignores it.
......@@ -746,7 +746,7 @@ class ShapeFeature(object):
def unpack(self, s_i):
"""Return a symbolic integer scalar for the shape element s_i.
The s_i argument was produced by the infer_shape() of an Op subclass.
"""
# unpack the s_i that the Op returned
......@@ -777,7 +777,7 @@ class ShapeFeature(object):
def set_shape(self, r, s):
"""Assign the shape `s` to previously un-shaped variable `r`.
:type r: a variable
:type s: None or a tuple of symbolic integers
"""
......@@ -1951,6 +1951,7 @@ compile.optdb.register('local_inplace_incsubtensor1',
@gof.local_optimizer([None])
def local_inplace_remove0(node):
"""
Optimization to insert inplace versions of Remove0.
"""
if isinstance(node.op, theano.sparse.sandbox.sp.Remove0) and not node.op.inplace:
new_op = node.op.__class__(inplace=True)
......@@ -1960,7 +1961,7 @@ def local_inplace_remove0(node):
compile.optdb.register('local_inplace_remove0',
TopoOptimizer(local_inplace_remove0,
failure_callback=TopoOptimizer.warn_inplace), 60,
'fast_run', 'inplace') # DEBUG
'fast_run', 'inplace')
@register_canonicalize
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论