提交 3357f441 authored 作者: Olivier Breuleux's avatar Olivier Breuleux

using sqr(_) instead of pow(_, 2) in gradients

上级 cd247b21
...@@ -670,7 +670,7 @@ class Tan(UnaryScalarOp): ...@@ -670,7 +670,7 @@ class Tan(UnaryScalarOp):
def impl(self, x): def impl(self, x):
return math.tan(x) return math.tan(x)
def grad(self, (x, ), (gz, )): def grad(self, (x, ), (gz, )):
return gz / (cos(x) ** 2), return gz / sqr(cos(x)),
def c_code(self, node, name, (x, ), (z, ), sub): def c_code(self, node, name, (x, ), (z, ), sub):
return "%(z)s = tan(%(x)s);" % locals() return "%(z)s = tan(%(x)s);" % locals()
tan = Tan(upgrade_to_float, name = 'tan') tan = Tan(upgrade_to_float, name = 'tan')
...@@ -707,7 +707,7 @@ class Tanh(UnaryScalarOp): ...@@ -707,7 +707,7 @@ class Tanh(UnaryScalarOp):
def impl(self, x): def impl(self, x):
return math.tanh(x) return math.tanh(x)
def grad(self, (x, ), (gz, )): def grad(self, (x, ), (gz, )):
return gz * (1 - tanh(x)**2), return gz * (1 - sqr(tanh(x))),
def c_code(self, node, name, (x, ), (z, ), sub): def c_code(self, node, name, (x, ), (z, ), sub):
return "%(z)s = tanh(%(x)s);" % locals() return "%(z)s = tanh(%(x)s);" % locals()
tanh = Tanh(upgrade_to_float, name = 'tanh') tanh = Tanh(upgrade_to_float, name = 'tanh')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论