IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo function

shape_div

def shape_div[check: Bool = False](a: IntTuple, b: IntTuple) -> 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.

Parameters:

  • โ€‹check (Bool): Whether to check for incompatible shapes.

Args:

  • โ€‹a (IntTuple): The dividend IntTuple.
  • โ€‹b (IntTuple): The divisor IntTuple.

Returns:

IntTuple: A new IntTuple containing the result of the division operation

Was this page helpful?