提交 92b5bbdb authored 作者: ChienliMa's avatar ChienliMa

Delete extra line; Add grad for round op

上级 7bfa5330
......@@ -2056,6 +2056,14 @@ class RoundHalfToEven(UnaryScalarOp):
def impl(self, x):
return numpy.round(x)
def grad(self, (x,), (gz,)):
rval = x.zeros_like()
if rval.type.dtype in discrete_types:
rval = rval.astype(theano.config.floatX)
return [rval]
def c_code___(self, node, name, (x, ), (z, ), sub):
typ = node.outputs[0].type.dtype
if not typ in ['float32', 'float64']:
......@@ -2138,9 +2146,16 @@ class RoundHalfAwayFromZero(UnaryScalarOp):
See http://en.wikipedia.org/wiki/Rounding for more detail
"""
def impl(self, x):
return round_half_away_from_zero_vec(x)
def grad(self, (x,), (gz,)):
rval = x.zeros_like()
if rval.type.dtype in discrete_types:
rval = rval.astype(theano.config.floatX)
return [rval]
def c_code(self, node, name, (x, ), (z, ), sub):
if node.outputs[0].type.dtype in ['float32', 'float64']:
return "%(z)s = round(%(x)s);" % locals()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论