提交 d3479239 authored 作者: Nicolas Bouchard's avatar Nicolas Bouchard

Wrap arctan from numpy, elemwise.

上级 14118e11
......@@ -2075,6 +2075,25 @@ class Tan(UnaryScalarOp):
tan = Tan(upgrade_to_float, name='tan')
class Arctan(UnaryScalarOp):
def impl(self, x):
return numpy.arctan(x)
def grad(self, (x,), (gz,)):
if gz.type in complex_types:
raise NotImplementedError()
if x.type in float_types:
return gz / (numpy.cast[x.type](1) + sqr(x)),
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 = atan(%(x)s);" % locals()
arctan = Arctan(upgrade_to_float, name='arctan')
class Cosh(UnaryScalarOp):
"""
cosh(x) = (exp(x) + exp(-x)) / 2
......
......@@ -2585,6 +2585,10 @@ def arcsin(a):
def tan(a):
"""tangent of a"""
@_scal_elemwise_with_nfunc('arctan', 1, 1)
def arctan(a):
"""arctangent of a"""
@_scal_elemwise_with_nfunc('cosh', 1, 1)
def cosh(a):
......
......@@ -159,6 +159,10 @@ def arcsin_inplace(a):
def tan_inplace(a):
"""tangent of `a` (inplace on `a`)"""
@_scal_inplace
def arctan_inplace(a):
"""arctangent of `a` (inplace on `a`)"""
@_scal_inplace
def cosh_inplace(a):
"""hyperbolic cosine of `a` (inplace on `a`)"""
......
......@@ -1084,6 +1084,7 @@ if config.floatX=='float32':
#We raise the relative tolerence for the grad as their is error in float32
#This is probably caused by our way of computing the gradient error.
tan_grad_rtol = 0.052
TanTester = makeBroadcastTester(op = tensor.tan,
expected = numpy.tan,
good = dict(normal = (rand_ranged(-3.14, 3.14, (2, 3)),),
......@@ -1101,6 +1102,21 @@ TanInplaceTester = makeBroadcastTester(op = inplace.tan_inplace,
inplace = True)
ArctanTester = makeBroadcastTester(op = tensor.tan,
expected = numpy.tan,
good = _good_broadcast_unary_wide,
grad = _grad_broadcast_unary_wide,
grad_rtol=tan_grad_rtol)
ArctanInplaceTester = makeBroadcastTester(op = inplace.tan_inplace,
expected = numpy.tan,
good = _good_broadcast_unary_wide,
grad = _grad_broadcast_unary_wide,
grad_rtol=tan_grad_rtol,
inplace = True)
CoshTester = makeBroadcastTester(op = tensor.cosh,
expected = numpy.cosh,
good = _good_broadcast_unary_normal,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论