提交 f8f641b3 authored 作者: James Bergstra's avatar James Bergstra

added log10

上级 8ef431d6
......@@ -710,6 +710,15 @@ class Log2(UnaryScalarOp):
return "%(z)s = log2(%(x)s);" % locals()
log2 = Log2(upgrade_to_float, name = 'log2')
class Log10(UnaryScalarOp):
def impl(self, x):
return numpy.log10(x)
def grad(self, (x, ), (gz, )):
return gz / (x * math.log(10.0)),
def c_code(self, node, name, (x, ), (z, ), sub):
return "%(z)s = log10(%(x)s);" % locals()
log10 = Log10(upgrade_to_float, name = 'log10')
class Exp(UnaryScalarOp):
def impl(self, x):
return math.exp(x)
......
......@@ -907,7 +907,8 @@ class MaxAndArgmax(Op):
g_x = eq(xmax_pad, x) * g_max_pad
return g_x, None
@_redefine_asRoutine(MaxAndArgmax())
_max_and_argmax = MaxAndArgmax()
@_redefine_asRoutine(_max_and_argmax)
def max_and_argmax(a):
pass
......@@ -1054,6 +1055,10 @@ def log(a):
def log2(a):
"""base 2 logarithm of a"""
@_scal_elemwise
def log10(a):
"""base 10 logarithm of a"""
@_scal_elemwise
def sgn(a):
"""sign of a"""
......
......@@ -434,6 +434,16 @@ Log2InplaceTester = makeBroadcastTester(op = inplace.log2_inplace,
grad = _grad_broadcast_unary_positive,
inplace = True)
Log10Tester = makeBroadcastTester(op = log10,
expected = numpy.log10,
good = _good_broadcast_unary_positive,
grad = _grad_broadcast_unary_positive)
Log10InplaceTester = makeBroadcastTester(op = inplace.log10_inplace,
expected = numpy.log10,
good = _good_broadcast_unary_positive,
grad = _grad_broadcast_unary_positive,
inplace = True)
SqrtTester = makeBroadcastTester(op = sqrt,
expected = numpy.sqrt,
good = _good_broadcast_unary_positive,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论