提交 0144d305 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Adapted threshold for log1p.

上级 08a6b966
...@@ -330,12 +330,14 @@ class ScalarSoftplus(scalar.UnaryScalarOp): ...@@ -330,12 +330,14 @@ class ScalarSoftplus(scalar.UnaryScalarOp):
def c_code(self, node, name, inp, out, sub): def c_code(self, node, name, inp, out, sub):
x, = inp x, = inp
z, = out z, = out
if (node.inputs[0].type == scalar.float32 or # These constants were obtained by looking at the output of
node.inputs[0].type == scalar.float16): # python commands like:
# These constants were obtained by looking at the output of python commands like:
# for i in xrange(750): # for i in xrange(750):
# print i, repr( numpy.log1p(numpy.exp(theano._asarray([i,-i], dtype=dt)))) # print i, repr(numpy.log1p(numpy.exp(theano._asarray([i,-i], dtype=dt))))
# the boundary checks prevent us from generating inf # the boundary checks prevent us from generating inf
if node.inputs[0].type == scalar.float16:
return """%(z)s = %(x)s < -17.0f ? 0.0 : %(x)s > 6.0f ? %(x)s : log1p(exp(%(x)s));""" % locals()
elif node.inputs[0].type == scalar.float32:
return """%(z)s = %(x)s < -103.0f ? 0.0 : %(x)s > 14.0f ? %(x)s : log1p(exp(%(x)s));""" % locals() return """%(z)s = %(x)s < -103.0f ? 0.0 : %(x)s > 14.0f ? %(x)s : log1p(exp(%(x)s));""" % locals()
elif node.inputs[0].type == scalar.float64: elif node.inputs[0].type == scalar.float64:
return """%(z)s = %(x)s < -745.0 ? 0.0 : %(x)s > 16.0 ? %(x)s : log1p(exp(%(x)s));""" % locals() return """%(z)s = %(x)s < -745.0 ? 0.0 : %(x)s > 16.0 ? %(x)s : log1p(exp(%(x)s));""" % locals()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论