提交 3968c266 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

fixed Clip.grad

上级 906dba3b
...@@ -1605,13 +1605,21 @@ class Clip(ScalarOp): ...@@ -1605,13 +1605,21 @@ class Clip(ScalarOp):
def c_code(self, node, name, (x, min, max), (z, ), sub): def c_code(self, node, name, (x, min, max), (z, ), sub):
return "%(z)s = %(x)s < %(min)s ? %(min)s : %(x)s > %(max)s ? %(max)s : %(x)s;" % locals() return "%(z)s = %(x)s < %(min)s ? %(min)s : %(x)s > %(max)s ? %(max)s : %(x)s;" % locals()
def grad(self, (x, min, max), (gz, )): def grad(self, (x, mn, mx), (gz, )):
assert gz.type not in complex_types assert gz.type not in complex_types
gx = ((x > min) & (x < max)) * gz gx = ((x > mn) & (x < mx)) * gz
if x.type in float_types: gmn = (x < mn) * gz
return gx, None, None gmx = (x > mx) * gz
else:
return None, None, None out = self(x, mn, mx)
def handle_int(v):
if out.type in int_types:
return v.zeros_like().astype(config.floatX)
return v
return map(handle_int, [gx, gmn, gmx])
# Don't allow complex even if numpy do # Don't allow complex even if numpy do
# As there is no mathematical reason for this function on complex # As there is no mathematical reason for this function on complex
clip = Clip(upcast_out_no_complex, name='clip') clip = Clip(upcast_out_no_complex, name='clip')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论