Skip to main content
Log in

Mojo function

prefix_product2

prefix_product2(a: IntTuple[origin], init: IntTuple[origin]) -> IntTuple

Implementation of exclusive prefix product computation.

Computes the exclusive prefix product of elements in the input IntTuple. For nested tuples, the function is applied recursively.

The function handles four cases:

  1. tuple-tuple: Apply prefix_product2 element-wise when dimensions match
  2. tuple-int: Apply prefix_product2 to each element with updated init value.
  3. int-tuple: Not allowed, will abort
  4. int-int: Return the init value

Note: If dimensions of tuple inputs don't match or if int-tuple case is encountered, abort() will be called.

Args:

  • a (IntTuple[origin]): The input IntTuple to compute the prefix product for.
  • init (IntTuple[origin]): The initial value(s) for the prefix product.

Returns:

A new IntTuple containing the exclusive prefix product of the input.