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
matrix_band_part
def matrix_band_part[dtype: DType, int_type: DType, cond_type: DType, rank: Int, simd_width: Int, InputFnType: def[width: Int, rank: Int](IndexList[rank]) -> SIMD[dtype, width] & ImplicitlyCopyable & RegisterPassable, target: StringSlice[ImmStaticOrigin] = StringSlice("cpu")](input_0_fn: InputFnType, input_shape: IndexList[rank], num_lower: TileTensor[int_type, Storage=num_lower.Storage, address_space=num_lower.address_space, linear_idx_type=num_lower.linear_idx_type], num_upper: TileTensor[int_type, Storage=num_upper.Storage, address_space=num_upper.address_space, linear_idx_type=num_upper.linear_idx_type], exclude: TileTensor[cond_type, Storage=exclude.Storage, address_space=exclude.address_space, linear_idx_type=exclude.linear_idx_type], output: TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type], ctx: DeviceContext) where (eq InputFnType.dtype, dtype)
Copies a band of input_0_fn into output, zeroing elements outside the band defined by num_lower and num_upper.
Reads the lower and upper diagonal counts and the exclude flag from the
supplied tensors, then dispatches to the implementation with the exclude
flag specialized at compile time via unswitch.
Parameters:
- βdtype (
DType): ElementDTypeof the input and output tensors. - βint_type (
DType):DTypeof thenum_lowerandnum_uppercount tensors. - βcond_type (
DType):DTypeof theexcludeflag tensor. - βrank (
Int): Number of dimensions in the input tensor (must be at least 2). - βsimd_width (
Int): SIMD width for the elementwise kernel launch. - βInputFnType (
def[width: Int, rank: Int](IndexList[rank]) -> SIMD[dtype, width]&ImplicitlyCopyable&RegisterPassable): Callable type returning the input element at a given index as aSIMDvector. - βtarget (
StringSlice[ImmStaticOrigin]): Target device for the elementwise kernel (defaults to"cpu").
Args:
- βinput_0_fn (
InputFnType): Function returning the input element at a given index. - βinput_shape (
IndexList[rank]): Shape of the input tensor. - βnum_lower (
TileTensor[int_type, Storage=num_lower.Storage, address_space=num_lower.address_space, linear_idx_type=num_lower.linear_idx_type]): Scalar tensor giving the number of lower subdiagonals to keep. - βnum_upper (
TileTensor[int_type, Storage=num_upper.Storage, address_space=num_upper.address_space, linear_idx_type=num_upper.linear_idx_type]): Scalar tensor giving the number of upper superdiagonals to keep. - βexclude (
TileTensor[cond_type, Storage=exclude.Storage, address_space=exclude.address_space, linear_idx_type=exclude.linear_idx_type]): Scalar tensor flag that, when nonzero, inverts the band mask. - βoutput (
TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): Mutable output tensor receiving the band-part result. - βctx (
DeviceContext): Device context used to launch the elementwise kernel.