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 MatrixViewNon-owning 2D view over a contiguous or strided matrix memory buffer.
Constructors
Section titled “Constructors”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 |
— |
Methods Overview
Section titled “Methods Overview”| 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. |
Method Details
Section titled “Method Details”MatrixView.num_rows()
Section titled “MatrixView.num_rows()”def num_rows(self) -> IntReturn the number of rows.
Returns: Int
MatrixView.num_cols()
Section titled “MatrixView.num_cols()”def num_cols(self) -> IntReturn the number of columns.
Returns: Int
MatrixView.num_elements()
Section titled “MatrixView.num_elements()”def num_elements(self) -> IntReturn the total number of elements (rows * cols).
Returns: Int
MatrixView.shape()
Section titled “MatrixView.shape()”def shape(self) -> Tuple[Int, Int]Return the (rows, cols) dimensions tuple.
Returns: Tuple[Int, Int]
MatrixView.slice_rows()
Section titled “MatrixView.slice_rows()”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]
MatrixView.slice_cols()
Section titled “MatrixView.slice_cols()”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]
MatrixView.slice_2d()
Section titled “MatrixView.slice_2d()”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]
MatrixView.to_matrix()
Section titled “MatrixView.to_matrix()”def to_matrix(self) -> Matrix[Self.dtype]Materialize the view into an owning dense Matrix.
Returns: Matrix[Self.dtype]