提交 6664a048 authored 作者: Frederic Bastien's avatar Frederic Bastien

make GpuElemwise work with empty tensor. Add tests for this.

上级 6922a69c
...@@ -37,7 +37,7 @@ def get_str_list_logical_scalar(node, value_str='ii_i%i_value', data_str='ii_i%i ...@@ -37,7 +37,7 @@ def get_str_list_logical_scalar(node, value_str='ii_i%i_value', data_str='ii_i%i
class NaiveAlgo(object): class NaiveAlgo(object):
verbose = 0 # 1, 2 or 3 for more verbose output. verbose = 0 # 1, 2 or 3 for more verbose output.
cache_version = () cache_version = ()
cache_version = ('debug', 9, verbose) cache_version = ('debug', 10, verbose)
def __init__(self, scalar_op, sync=True): def __init__(self, scalar_op, sync=True):
""" """
...@@ -787,6 +787,7 @@ nd_collapse_[i]=0; ...@@ -787,6 +787,7 @@ nd_collapse_[i]=0;
""" %locals() """ %locals()
else: else:
print >> sio, " return 0; " %locals() print >> sio, " return 0; " %locals()
print >> sio, "if(numEls==0) return 0;"
print >> sio, "switch (nd_collapse==0?0:min(%(nd)s,nd_collapse)) {"%locals() print >> sio, "switch (nd_collapse==0?0:min(%(nd)s,nd_collapse)) {"%locals()
print >> sio, "case 0: {" print >> sio, "case 0: {"
launch_Ccontiguous(nodename, id_self, scalar_op, self.sync) launch_Ccontiguous(nodename, id_self, scalar_op, self.sync)
......
...@@ -146,6 +146,20 @@ def test_reshape(): ...@@ -146,6 +146,20 @@ def test_reshape():
return T.Reshape(2)(v, theano._asarray([2,3], dtype='int32')) return T.Reshape(2)(v, theano._asarray([2,3], dtype='int32'))
utt.verify_grad(just_vals, [a_val]) utt.verify_grad(just_vals, [a_val])
def test_elemwise_empty():
#test with 0 element
a = tcn.shared_constructor(theano._asarray(numpy.random.rand(0,0), dtype='float32'), 'a')
b = tensor.fmatrix()
f = pfunc([b], [], updates=[(a, a+b)], mode=mode_with_gpu)
f2 = pfunc([b], [], updates=[(a, a+b)], mode=mode_without_gpu)
a0 = a.value * 1.0
f(numpy.ones((0,0)))
assert numpy.all(a0 + 1.0 == a.value)
def test_elemwise0(): def test_elemwise0():
a = tcn.shared_constructor(theano._asarray(numpy.random.rand(4,4), dtype='float32'), 'a') a = tcn.shared_constructor(theano._asarray(numpy.random.rand(4,4), dtype='float32'), 'a')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论