pytaco.exp

pytaco.exp(e1)

Calculate the exponential of all elements in an index expression.

The index expression must have a floating point type. If necessary, a user may cast() the input expression before applying the function as shown in sqrt().

This must be assigned to a tensor for the computation to be performed.

Parameters
e1: index_expression

Input index expression

Returns
exp_expr: index_expression

An index expression representing the element wise exponent of the input expression.

Examples

We show computing the standard softmax function as an example.

>>> import pytaco as pt
>>> t = pt.as_tensor([[4, 0.3], [2,  7]])
>>> t = pt.as_type(t, pt.float32)
>>> exp_sum = pt.tensor([t.shape[0]], pt.dense)
>>> i, j = pt.get_index_vars(2)
>>> exp_sum[i] = pt.exp(t[i, j]) # sum across the rows and exp
>>> soft_max_t = pt.tensor(t.shape, pt.dense)
>>> soft_max_t[i, j] = pt.exp(t[i, j]) / exp_sum[i] # divide each row by its sum
>>> print(soft_max_t.to_array())
[[0.975873   0.02412702]
 [0.00669285 0.9933072 ]]