oa::matrix::Matrix

Device-visible numeric storage with explicit shape and dtype semantics. Arithmetic operators delegate to crate::matrix and return Result<Matrix>: use let sum = (&left + &right)?;. They preserve validation, allocation, and recording failures without panicking. Multiplication is elementwise; use crate::matrix::mat_mul_nt for matrix multiplication.

StRust public API

Declaration

pub struct Matrix { /* private fields */ }
Public Rust declaration.

Public Methods

pub fn shape(&self) -> &[usize]
pub const fn dtype(&self) -> DType
pub const fn num_elements(&self) -> usize
pub fn reshape(&self, shape: impl Into<Vec<usize>>) -> Result<Self>
pub fn flatten(&self) -> Result<Self>
pub fn unsqueeze(&self, dim: usize) -> Result<Self>
pub fn squeeze(&self, dim: usize) -> Result<Self>
pub fn add(&self, rhs: &Self) -> Result<Self>
pub fn sub(&self, rhs: &Self) -> Result<Self>
pub fn mul(&self, rhs: &Self) -> Result<Self>
pub fn div(&self, rhs: &Self) -> Result<Self>
pub fn mat_mul(&self, rhs: &Self) -> Result<Self>
pub fn transpose(&self, dim0: i32, dim1: i32) -> Result<Self>
pub fn read_f32(&self) -> Result<Vec<f32>>
pub fn try_read_f32(&self) -> Result<Vec<f32>>
pub fn read<T: Element>(&self) -> Result<Vec<T>>
pub fn try_read<T: Element>(&self) -> Result<Vec<T>>
fn add(self, rhs: &Matrix) -> Result<Matrix>
fn add(self, rhs: &Matrix) -> Result<Matrix>
fn add(self, rhs: f32) -> Result<Matrix>
fn clone(&self) -> Matrix
fn div(self, rhs: &Matrix) -> Result<Matrix>
fn div(self, rhs: f32) -> Result<Matrix>
fn mul(self, rhs: &Matrix) -> Result<Matrix>
fn mul(self, rhs: &Matrix) -> Result<Matrix>
fn mul(self, rhs: f32) -> Result<Matrix>
fn neg(self) -> Result<Matrix>
fn neg(self) -> Result<Matrix>
fn sub(self, rhs: &Matrix) -> Result<Matrix>
fn sub(self, rhs: f32) -> Result<Matrix>

Associated Functions

pub fn from_slice<T: Element>( engine: &Engine, shape: impl Into<Vec<usize>>, values: &[T], ) -> Result<Self>
pub fn from_f32( engine: &Engine, shape: impl Into<Vec<usize>>, values: &[f32], ) -> Result<Self>

Public Method Documentation

pub fn shape( &self ) -> &[usize]
No public source comment is attached to this declaration.
pub const fn dtype( &self ) -> DType
No public source comment is attached to this declaration.
pub const fn num_elements( &self ) -> usize
No public source comment is attached to this declaration.
pub fn reshape( &self, shape: impl Into<Vec<usize>> ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn flatten( &self ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn unsqueeze( &self, dim: usize ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn squeeze( &self, dim: usize ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn add( &self, rhs: &Self ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn sub( &self, rhs: &Self ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn mul( &self, rhs: &Self ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn div( &self, rhs: &Self ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn mat_mul( &self, rhs: &Self ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn transpose( &self, dim0: i32, dim1: i32 ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn read_f32( &self ) -> Result<Vec<f32>>
No public source comment is attached to this declaration.
pub fn try_read_f32( &self ) -> Result<Vec<f32>>
No public source comment is attached to this declaration.
pub fn read<T: Element>( &self ) -> Result<Vec<T>>
No public source comment is attached to this declaration.
pub fn try_read<T: Element>( &self ) -> Result<Vec<T>>
No public source comment is attached to this declaration.
fn add( self, rhs: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn add( self, rhs: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn add( self, rhs: f32 ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn clone( &self ) -> Matrix
No public source comment is attached to this declaration.
fn div( self, rhs: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn div( self, rhs: f32 ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn mul( self, rhs: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn mul( self, rhs: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn mul( self, rhs: f32 ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn neg( self ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn neg( self ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn sub( self, rhs: &Matrix ) -> Result<Matrix>
No public source comment is attached to this declaration.
fn sub( self, rhs: f32 ) -> Result<Matrix>
No public source comment is attached to this declaration.
pub fn from_slice<T: Element>( engine: &Engine, shape: impl Into<Vec<usize>>, values: &[T] ) -> Result<Self>
No public source comment is attached to this declaration.
pub fn from_f32( engine: &Engine, shape: impl Into<Vec<usize>>, values: &[f32] ) -> Result<Self>
No public source comment is attached to this declaration.