Skip to content

Commit

Permalink
Merge pull request #3352 from niboshi/optimize-log2-log10-backward
Browse files Browse the repository at this point in the history
Optimize backward of log2 and log10
  • Loading branch information
okuta committed Sep 11, 2017
2 parents 8d4f957 + 6e83ce3 commit 6bd1230
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions chainer/functions/math/exponential.py
@@ -1,3 +1,5 @@
import math

import numpy

from chainer import cuda
Expand Down Expand Up @@ -77,10 +79,9 @@ def forward(self, x):
return utils.force_array(xp.log2(x[0])),

def backward(self, x, gy):
xp = cuda.get_array_module(*x)
gx = utils.force_array(xp.reciprocal(x[0]))
gx /= xp.log(2)
gx *= gy[0]
gx = gy[0].copy()
gx /= x[0]
gx *= 1 / math.log(2)
return gx,


Expand Down Expand Up @@ -114,10 +115,9 @@ def forward(self, x):
return utils.force_array(xp.log10(x[0])),

def backward(self, x, gy):
xp = cuda.get_array_module(*x)
gx = utils.force_array(xp.reciprocal(x[0]))
gx /= xp.log(10)
gx *= gy[0]
gx = gy[0].copy()
gx /= x[0]
gx *= 1 / math.log(10)
return gx,


Expand Down

0 comments on commit 6bd1230

Please sign in to comment.