Example #1
0
def test_power(inputs):
    A, _ = inputs
    pow = funcs._Power(A, 2)

    # Test Forwardprop
    C = pow()
    assert isinstance(C, Tensor)
    assert (A.value**2 == C.value).all()

    # Test Backprop
    grad_A, grad_B = pow.backward(0, Tensor(1)), pow.backward(1, Tensor(1))

    assert isinstance(grad_A, Tensor)
    assert isinstance(grad_B, Tensor)

    # Test Derivative computation
    assert grad_A.shape == A.shape
    assert (grad_A == 2 * A).all()

    assert grad_B == 1
Example #2
0
def sqrt(x: Tensor) -> Tensor:
    return _Power(x, 1 / 2)()
Example #3
0
 def __rpow__(self, other):
     from nujo.autodiff._functions._elementary import _Power
     return _Power(other, self)()
Example #4
0
def exp(x: Tensor) -> Tensor:
    return _Power(e, x)()