Skip to content

MatrixView

Module: strata.core • Kind: struct • Traits: ArrayLike, Copyable, Movable
Source: strata/core/view.mojo

struct MatrixView[dtype: DType, origin: Origin](ArrayLike, Copyable, Movable)
from strata.core import MatrixView

Non-owning 2D view over a contiguous or strided matrix memory buffer.


def __init__(
out self,
ptr: Pointer[Scalar[Self.dtype], Self.origin],
rows: Int,
cols: Int,
row_stride: Int,
col_stride: Int = 1,
)
Argument Type Description
ptr Pointer[Scalar[Self.dtype], Self.origin] —
rows Int —
cols Int —
row_stride Int —
col_stride Int —

Method Description
MatrixView.num_rows() Return the number of rows.
MatrixView.num_cols() Return the number of columns.
MatrixView.num_elements() Return the total number of elements (rows * cols).
MatrixView.shape() Return the (rows, cols) dimensions tuple.
MatrixView.slice_rows() Return a non-owning view of a row range.
MatrixView.slice_cols() Return a non-owning view of a column range.
MatrixView.slice_2d() Return a non-owning 2D sub-matrix view.
MatrixView.to_matrix() Materialize the view into an owning dense Matrix.

def num_rows(self) -> Int

Return the number of rows.

Returns: Int


def num_cols(self) -> Int

Return the number of columns.

Returns: Int


def num_elements(self) -> Int

Return the total number of elements (rows * cols).

Returns: Int


def shape(self) -> Tuple[Int, Int]

Return the (rows, cols) dimensions tuple.

Returns: Tuple[Int, Int]


def slice_rows(
self,
start_row: Int,
end_row: Int,
) -> MatrixView[Self.dtype, Self.origin]

Return a non-owning view of a row range.

Parameter Type Description
start_row Int —
end_row Int —

Returns: MatrixView[Self.dtype, Self.origin]


def slice_cols(
self,
start_col: Int,
end_col: Int,
) -> MatrixView[Self.dtype, Self.origin]

Return a non-owning view of a column range.

Parameter Type Description
start_col Int —
end_col Int —

Returns: MatrixView[Self.dtype, Self.origin]


def slice_2d(
self,
start_row: Int,
end_row: Int,
start_col: Int,
end_col: Int,
) -> MatrixView[Self.dtype, Self.origin]

Return a non-owning 2D sub-matrix view.

Parameter Type Description
start_row Int —
end_row Int —
start_col Int —
end_col Int —

Returns: MatrixView[Self.dtype, Self.origin]


def to_matrix(self) -> Matrix[Self.dtype]

Materialize the view into an owning dense Matrix.

Returns: Matrix[Self.dtype]