提交 41c1330d authored 作者: Nicolas Bouchard's avatar Nicolas Bouchard

Wrap arcsinh from numpy, elemwise.

上级 35a37e39
...@@ -2157,6 +2157,25 @@ class Sinh(UnaryScalarOp): ...@@ -2157,6 +2157,25 @@ class Sinh(UnaryScalarOp):
sinh = Sinh(upgrade_to_float, name='sinh') sinh = Sinh(upgrade_to_float, name='sinh')
class ArcSinh(UnaryScalarOp):
def impl(self, x):
return numpy.arcsinh(x)
def grad(self, (x, ), (gz, )):
if x.type in complex_types:
raise NotImplementedError()
if x.type in float_types:
return gz / sqrt(sqr(x) + numpy.cast[x.type](1)),
else:
return None,
def c_code(self, node, name, (x, ), (z, ), sub):
if node.inputs[0].type in complex_types:
raise NotImplementedError('type not supported', type)
return "%(z)s = asinh(%(x)s);" % locals()
arcsinh = ArcSinh(upgrade_to_float, name='arcsinh')
class Tanh(UnaryScalarOp): class Tanh(UnaryScalarOp):
""" """
tanh(x) = sinh(x) / cosh(x) tanh(x) = sinh(x) / cosh(x)
......
...@@ -2606,6 +2606,11 @@ def sinh(a): ...@@ -2606,6 +2606,11 @@ def sinh(a):
"""hyperbolic sine of a""" """hyperbolic sine of a"""
@_scal_elemwise_with_nfunc('arcsinh', 1, 1)
def arcsinh(a):
"""hyperbolic arc sine of a"""
@_scal_elemwise_with_nfunc('tanh', 1, 1) @_scal_elemwise_with_nfunc('tanh', 1, 1)
def tanh(a): def tanh(a):
"""hyperbolic tangent of a""" """hyperbolic tangent of a"""
......
...@@ -175,6 +175,10 @@ def arccosh_inplace(a): ...@@ -175,6 +175,10 @@ def arccosh_inplace(a):
def sinh_inplace(a): def sinh_inplace(a):
"""hyperbolic sine of `a` (inplace on `a`)""" """hyperbolic sine of `a` (inplace on `a`)"""
@_scal_inplace
def arcsinh_inplace(a):
"""hyperbolic arc sine of `a` (inplace on `a`)"""
@_scal_inplace @_scal_inplace
def tanh_inplace(a): def tanh_inplace(a):
"""hyperbolic tangent of `a` (inplace on `a`)""" """hyperbolic tangent of `a` (inplace on `a`)"""
......
...@@ -1156,6 +1156,18 @@ SinhInplaceTester = makeBroadcastTester(op = inplace.sinh_inplace, ...@@ -1156,6 +1156,18 @@ SinhInplaceTester = makeBroadcastTester(op = inplace.sinh_inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
ArcsinhTester = makeBroadcastTester(op = tensor.arcsinh,
expected = numpy.arcsinh,
good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal)
ArcsinhInplaceTester = makeBroadcastTester(op = inplace.arcsinh_inplace,
expected = numpy.arcsinh,
good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal,
inplace = True)
TanhTester = makeBroadcastTester(op = tensor.tanh, TanhTester = makeBroadcastTester(op = tensor.tanh,
expected = numpy.tanh, expected = numpy.tanh,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论