Log1p

This example implements and tests the log1p operator - ie. element-wise log(1 + x), which is equivalent to that defined for numpy.

log1p(x)

Define the log1p operator by defining the its operator function to be

\[out_{i} = log(1.0 + x_{i})\]
Parameters:x – The input tensor
Returns:Element-wise log(1 + x)
Examples:
>>> import numpy as np
>>> from opveclib import evaluate
>>> from opveclib.examples import log1p
>>> a = np.array([1e-99, -1e-99])
>>> evaluate(log1p(a))
array([  1.00000000e-99,  -1.00000000e-99])
>>> np.log1p(a)
array([  1.00000000e-99,  -1.00000000e-99])
>>> ones = np.ones_like(a)
>>> np.log(ones + a)
array([ 0.,  0.])
log1p_grad(x, grad)

Define the log1p gradient operator by defining the its operator function to be

\[out_{i} = 1.0 / (x_{i} + 1.0) * grad_{i}\]
Parameters:
  • x – The input tensor argument
  • grad – The input gradient tensor to the gradient operator
Returns:

Element-wise gradient of the original operator