Table of Contents

Mojo struct

Matrix

@memory_only
struct Matrix[Type: DType]

Aliases

  • __del__is_trivial = True

Parameters

  • Type (DType)

Fields

  • data (UnsafePointer[Scalar[Type], MutAnyOrigin])
  • layout (Layout)

Implemented traits

AnyType, ImplicitlyDestructible

Methods

__init__

fn __init__(out self, shape: Tuple[Int, Int])

Args:

  • shape (Tuple)
  • self (Self)

Returns:

Self

fn __init__(out self, data: UnsafePointer[Scalar[Type], MutAnyOrigin], var layout: Layout)

Args:

  • data (UnsafePointer)
  • layout (Layout)
  • self (Self)

Returns:

Self

fn __init__(out self, data: UnsafePointer[Scalar[Type], MutAnyOrigin], shape: Tuple[Int, Int])

Args:

  • data (UnsafePointer)
  • shape (Tuple)
  • self (Self)

Returns:

Self

__getitem__

fn __getitem__(ref self, i: Int, j: Int) -> ref [self] Scalar[Type]

Args:

  • self (Self)
  • i (Int)
  • j (Int)

Returns:

ref

slice

fn slice(self, i: Int, j: Int, ir: Int, jr: Int) -> Self

Args:

  • self (Self)
  • i (Int)
  • j (Int)
  • ir (Int)
  • jr (Int)

Returns:

Self

shape

fn shape[dim: Int](self) -> Int

Parameters:

  • dim (Int)

Args:

  • self (Self)

Returns:

Int

stride

fn stride[dim: Int](self) -> Int

Parameters:

  • dim (Int)

Args:

  • self (Self)

Returns:

Int

rand

fn rand(mut self)

Args:

  • self (Self)

load

fn load[width: Int, *, dim: Int](self, i: Int, j: Int) -> SIMD[Type, width]

Parameters:

  • width (Int)
  • dim (Int)

Args:

  • self (Self)
  • i (Int)
  • j (Int)

Returns:

SIMD

store

fn store[width: Int, *, dim: Int](self, value: SIMD[Type, width], i: Int, j: Int)

Parameters:

  • width (Int)
  • dim (Int)

Args:

  • self (Self)
  • value (SIMD)
  • i (Int)
  • j (Int)

write_to

fn write_to[W: Writer](self, mut writer: W)

Parameters:

  • W (Writer)

Args:

  • self (Self)
  • writer (W)