Skip to content

_exp

exp

Compute e^Tensor.

This method can be used with Numpy data:

n = np.array([-2, 2, 1])
b = fe.backend.exp(n)  # [0.1353, 7.3891, 2.7183]

This method can be used with TensorFlow tensors:

t = tf.constant([-2.0, 2, 1])
b = fe.backend.exp(t)  # [0.1353, 7.3891, 2.7183]

This method can be used with PyTorch tensors:

p = torch.tensor([-2.0, 2, 1])
b = fe.backend.exp(p)  # [0.1353, 7.3891, 2.7183]

Parameters:

Name Type Description Default
tensor Tensor

The input value.

required

Returns:

Type Description
Tensor

The exponentiated tensor.

Raises:

Type Description
ValueError

If tensor is an unacceptable data type.

Source code in fastestimator/fastestimator/backend/_exp.py
def exp(tensor: Tensor) -> Tensor:
    """Compute e^Tensor.

    This method can be used with Numpy data:
    ```python
    n = np.array([-2, 2, 1])
    b = fe.backend.exp(n)  # [0.1353, 7.3891, 2.7183]
    ```

    This method can be used with TensorFlow tensors:
    ```python
    t = tf.constant([-2.0, 2, 1])
    b = fe.backend.exp(t)  # [0.1353, 7.3891, 2.7183]
    ```

    This method can be used with PyTorch tensors:
    ```python
    p = torch.tensor([-2.0, 2, 1])
    b = fe.backend.exp(p)  # [0.1353, 7.3891, 2.7183]
    ```

    Args:
        tensor: The input value.

    Returns:
        The exponentiated `tensor`.

    Raises:
        ValueError: If `tensor` is an unacceptable data type.
    """
    if tf.is_tensor(tensor):
        return tf.exp(tensor)
    elif isinstance(tensor, torch.Tensor):
        return torch.exp(tensor)
    elif isinstance(tensor, np.ndarray):
        return np.exp(tensor)
    else:
        raise ValueError("Unrecognized tensor type {}".format(type(tensor)))