Skip to main content
Log in

Mojo function

shape_div

shape_div(a: IntTuple[origin], b: IntTuple[origin]) -> IntTuple

Performs division operation between shape tuples.

Handles four cases:

  1. tuple-tuple: Performs shape_div element-wise when dimensions match
  2. tuple-int: Folds the division of b across each element of a Example: shape_div((4,5,6),40) -> shape_div((1,5,6),10) -> shape_div((1,1,6),2) -> (1,1,3)
  3. int-tuple: Returns shape_div(a, product(b))
  4. int-int: Enforces the divisibility condition a % b == 0 || b % a == 0 when possible Returns a / b with rounding away from 0 (that is, 1 or -1 when a < b)

Notes: - When tuple sizes don't match in the tuple-tuple case, abort() will be called. - When values are incompatible (neither divides the other) in the int-int case, abort() will be called.

Args:

  • a (IntTuple[origin]): The dividend IntTuple.
  • b (IntTuple[origin]): The divisor IntTuple.

Returns:

A new IntTuple containing the result of the division operation