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

sum

def sum[axis: Int](inp: TileTensor[Engine=inp.Engine, address_space=inp.address_space, linear_idx_type=inp.linear_idx_type], outp: TileTensor[Engine=outp.Engine, address_space=outp.address_space, linear_idx_type=outp.linear_idx_type])

Computes lane-wise sums along one outer dimension.

Constraints:

Shapes must be static. The surviving dimension and SIMD element width must match between input and output.

Parameters:

  • ​axis (Int): The outer dimension to reduce, either 0 or 1.

Args:

def sum[axis: Int](inp: TileTensor[Engine=inp.Engine, address_space=inp.address_space, linear_idx_type=inp.linear_idx_type]) -> TileTensor[inp.dtype, Layout[TypeList[ComptimeInt[(Int((add (mul Coord[inp.LayoutType.__shape_types[SIMDLength((Int(1) - axis))]].static_product, inp.Engine.element_size), inp.Engine.element_size, -1)) // inp.Engine.element_size)]](), TypeList[ComptimeInt[inp.Engine.element_size]]()], MutUntrackedOrigin, Engine=DefaultEngine[element_width=Coord[ComptimeInt[inp.Engine.element_size]].static_product], address_space=inp.address_space, linear_idx_type=_get_index_type[Layout[TypeList[ComptimeInt[(Coord[inp.LayoutType.__shape_types[SIMDLength((Int(1) - axis))]].static_product * inp.Engine.element_size)]](), TypeList[ComptimeInt[Int(1)]]()]](inp.address_space)]

Computes lane-wise sums into a new contiguous tensor.

Examples:

from std.collections import Array
from layout import TileTensor, row_major
from layout.math import sum

var data: Array[Int32, 6] = [0, 1, 2, 3, 4, 5]
var tensor = TileTensor(data, row_major[2, 3]())
var result = sum[0](tensor)
print(result[0], result[1], result[2])  # 3 5 7

Parameters:

  • ​axis (Int): The outer dimension to reduce, either 0 or 1.

Args:

Returns:

TileTensor[inp.dtype, Layout[TypeList[ComptimeInt[(Int((add (mul Coord[inp.LayoutType.__shape_types[SIMDLength((Int(1) - axis))]].static_product, inp.Engine.element_size), inp.Engine.element_size, -1)) // inp.Engine.element_size)]](), TypeList[ComptimeInt[inp.Engine.element_size]]()], MutUntrackedOrigin, Engine=DefaultEngine[element_width=Coord[ComptimeInt[inp.Engine.element_size]].static_product], address_space=inp.address_space, linear_idx_type=_get_index_type[Layout[TypeList[ComptimeInt[(Coord[inp.LayoutType.__shape_types[SIMDLength((Int(1) - axis))]].static_product * inp.Engine.element_size)]](), TypeList[ComptimeInt[Int(1)]]()]](inp.address_space)]: A rank-1 tensor with the input dtype and SIMD element width. Adjacent elements have disjoint storage.

Was this page helpful?