fn

cumprod

Tensor
cumprod(input: Tensor, dim: DimLike = ...)
source

Return the cumulative product of elements along dim.

Produces a tensor of the same shape as the input whose i-th element along dim is the product of all input elements up to and including position i. This is the prefix product and is the multiplicative analogue of cumsum.

Parameters

inputTensor
Source tensor.
dimDimLike= ...
Dimension along which to accumulate.

Returns

Tensor

Same shape as input.

Notes

yi  =  k=0ixk.y_i \;=\; \prod_{k=0}^{i} x_k .

The reduction is not numerically stable for long sequences of values much greater than 1 (overflow) or much less than 1 (underflow); consider accumulating in log-space when range is large.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0, 4.0])
>>> lucid.cumprod(x, dim=0)
Tensor([ 1.,  2.,  6., 24.])