Matrix

Struct Matrix 

Source
pub struct Matrix<'a, T = f32, D: Device = CPU, S: Shape = ()> {
    pub data: Buffer<'a, T, D, S>,
    pub dims: (usize, usize),
}
Expand description

A matrix using Buffer described with rows and columns

§Example

The following example creates a zeroed (or values set to default) Matrix with the given dimensions.

use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();
let m = Matrix::<i32>::new(&device, (5, 8));

assert_eq!(m.rows(), 5);
assert_eq!(m.cols(), 8);
assert_eq!(m.size(), 5*8);
assert_eq!(m.read(), vec![0; 5*8])

Fields§

§data: Buffer<'a, T, D, S>§dims: (usize, usize)

Implementations§

Source§

impl<'a, T, D: Device, S: Shape> Matrix<'a, T, D, S>

Source

pub fn new(device: &'a D, dims: (usize, usize)) -> Matrix<'a, T, D, S>
where D: Alloc<'a, T, S>,

Returns an empty matrix with the specified dimensions (rows, cols).

§Example
use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();
let m = Matrix::<f64>::new(&device, (20, 10));

assert_eq!(m.size(), 20*10);
assert_eq!(m.read(), vec![0.0; 20*10])
Examples found in repository?
examples/cpu_device.rs (line 8)
6fn main() {
7    let device = CPU::new();
8    let a = Matrix::<f32>::new(&device, (5, 5));
9    let b = Matrix::from((&device, (5, 5), vec![1.3; 5 * 5]));
10
11    let out = device.add(&a, &b);
12
13    assert_eq!(device.read(&out), vec![1.3; 5 * 5]);
14}
More examples
Hide additional examples
examples/cpu_cache.rs (line 9)
6fn main() {
7    let device = CPU::new();
8
9    let a = Matrix::<i16>::new(&device, (100, 100));
10    let b = Matrix::<i16>::new(&device, (100, 100));
11
12    let out = a + b;
13    let ptr = {
14        let cache = device.cache.borrow();
15        let mut node = Ident::new(100 * 100);
16        node.idx = 0;
17        cache.nodes.get(&node).unwrap().ptr
18    };
19
20    assert!(ptr == out.as_buf().ptr.ptr as *mut u8);
21}
Source

pub fn device(&self) -> &'a D

Source

pub fn as_buf(&self) -> &Buffer<'a, T, D, S>

Returns a reference to the underlying buffer.

§Example
use custos::{CPU, Read};
use custos_math::Matrix;

let device = CPU::new();
let a = Matrix::from((&device, (2, 3), [1., 2., 3., 3., 2., 1.,]));
let read = a.read();
assert_eq!(vec![1., 2., 3., 3., 2., 1.,], read);
Examples found in repository?
examples/cpu_cache.rs (line 20)
6fn main() {
7    let device = CPU::new();
8
9    let a = Matrix::<i16>::new(&device, (100, 100));
10    let b = Matrix::<i16>::new(&device, (100, 100));
11
12    let out = a + b;
13    let ptr = {
14        let cache = device.cache.borrow();
15        let mut node = Ident::new(100 * 100);
16        node.idx = 0;
17        cache.nodes.get(&node).unwrap().ptr
18    };
19
20    assert!(ptr == out.as_buf().ptr.ptr as *mut u8);
21}
Source

pub fn to_buf(self) -> Buffer<'a, T, D, S>

Source

pub fn as_buf_mut(&mut self) -> &mut Buffer<'a, T, D, S>

Returns a mutable reference to the underlying buffer.

Source

pub fn dims(&self) -> (usize, usize)

Source

pub fn reshape(&mut self, dims: (usize, usize))

Source

pub fn rows(&self) -> usize

Returns the row count of the matrix.

§Example
use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();
let matrix = Matrix::<i32>::new(&device, (2, 5));
assert_eq!(matrix.rows(), 2)
Source

pub fn cols(&self) -> usize

Returns the column count of the matrix.

§Example
use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();
let matrix = Matrix::<i32>::new(&device, (2, 5));
assert_eq!(matrix.cols(), 5)
Source

pub fn size(&self) -> usize

Returns the number of elements in the matrix: rows * cols

§Example
use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();
let matrix = Matrix::<u16>::new(&device, (4, 12));
assert_eq!(matrix.size(), 48)
Source

pub fn as_slice(&self) -> &[T]
where D: MainMemory,

Source

pub fn as_mut_slice(&mut self) -> &mut [T]
where D: MainMemory,

Source

pub fn read(&'a self) -> D::Read<'a>
where T: Default + Copy, D: Read<T, D, S>,

Uses VecRead and current global device to read Matrix

§Example
use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();

let a = Matrix::from((&device, (2, 2), [5, 7, 2, 10,]));
assert_eq!(a.read(), vec![5, 7, 2, 10])
Examples found in repository?
examples/simple.rs (line 22)
17fn with_select(cpu: &CPU) {
18    let a: Matrix<i32> = Matrix::from((cpu, (2, 3), [1, 2, 3, 4, 5, 6]));
19    let b = Matrix::from((cpu, (2, 3), [6, 5, 4, 3, 2, 1]));
20
21    let c = a + b;
22    assert_eq!(c.read(), vec![7, 7, 7, 7, 7, 7]);
23}
24
25fn specify_device(cpu: &CPU) {
26    //device is specified in every operation
27    let a = Matrix::from((cpu, (2, 2), [0.25f32, 0.5, 0.75, 1.]));
28    let b = Matrix::from((cpu, (2, 2), [1., 2., 3., 4.]));
29
30    let c_cpu = cpu.mul(&a, &b);
31    assert_eq!(cpu.read(&c_cpu), vec![0.25, 1., 2.25, 4.,]);
32}
33
34fn using_opencl() -> custos::Result<()> {
35    //OpenCL device (GPU)
36    let cl = OpenCL::new(0)?;
37
38    let a = Matrix::from((&cl, (2, 2), [0.25f32, 0.5, 0.75, 1.]));
39    let b = Matrix::from((&cl, (2, 2), [1., 2., 3., 4.]));
40
41    let c = a * b;
42    assert_eq!(c.read(), vec![0.25, 1., 2.25, 4.,]);
43    Ok(())
44}
More examples
Hide additional examples
examples/gemm.rs (line 12)
3fn main() {
4    let device = CPU::new();
5
6    let a = Matrix::from((&device, (2, 3), [1., 2., 3., 4., 5., 6.]));
7    let b = Matrix::from((&device, (3, 2), [6., 5., 4., 3., 2., 1.]));
8
9    let c = a.gemm(&b);
10    println!("c: {c:?}");
11
12    assert_eq!(c.read(), vec![20., 14., 56., 41.,]);
13}
Source

pub fn read_to_vec(&self) -> Vec<T>
where T: Default + Copy, D: Read<T, D, S>,

Uses VecRead and current global device to read Matrix

§Example
use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();

let a = Matrix::from((&device, (2, 2), [5, 7, 2, 10,]));
assert_eq!(a.read(), vec![5, 7, 2, 10])
Source

pub fn shallow(&self) -> Matrix<'a, T, D, S>
where D::Ptr<T, S>: ShallowCopy,

Creates a shallow copy of &self.

Source

pub fn shallow_or_clone(&self) -> Matrix<'a, T, D, S>
where T: Clone, D::Ptr<T, S>: ShallowCopy, D: CloneBuf<'a, T, S>,

Creates a shallow copy or a deep copy of &self, depening on whether the realloc feature is activated.

Source§

impl<'a, T, D: Device, S: Shape> Matrix<'a, T, D, S>

Source

pub fn to_dims<O: Shape>(self) -> Matrix<'a, T, D, O>
where D: ToDim<T, S, O>,

Converts a (non stack allocated) Buffer with no shape to a Buffer with shape O.

Source§

impl<T, D: IsShapeIndep, S: Shape> Matrix<'_, T, D, S>

Source

pub fn as_dims<'b, O: Shape>(&self) -> &Matrix<'b, T, D, O>

Source

pub fn as_dims_mut<'b, O: Shape>(&mut self) -> &mut Matrix<'b, T, D, O>

Source§

impl<'a, T, D: ActivationOps<T, S>, S: Shape> Matrix<'a, T, D, S>

Source

pub fn tanh(&self) -> Matrix<'a, T, D, S>

Source

pub fn tanh_grad(&self) -> Matrix<'a, T, D, S>

Source

pub fn relu(&self) -> Matrix<'a, T, D, S>

Source

pub fn relu_mut(&mut self)

Source

pub fn relu_grad(&self) -> Matrix<'a, T, D, S>

Source

pub fn relu_grad_mut(&mut self)

Source

pub fn sigmoid(&self) -> Matrix<'a, T, D, S>

Source

pub fn sigmoid_grad(&self) -> Matrix<'a, T, D, S>

uses pre-computed sigmoid activation

Source§

impl<'a, T, S: Shape, D: CCEOp<T, S>> Matrix<'a, T, D, S>

Source

pub fn cce(&self, targets: &Matrix<'a, T, D, S>) -> (T, Matrix<'a, T, D, S>)

Source

pub fn cce_loss(&self, targets: &Matrix<'_, T, D, S>) -> T

Source

pub fn cce_grad(&self, targets: &Matrix<'a, T, D, S>) -> Matrix<'a, T, D, S>

Source§

impl<'a, T, D: SoftmaxOps<T>> Matrix<'a, T, D>

Source

pub fn softmax(&self) -> Matrix<'a, T, D>

Source

pub fn softmax_grad(&self, activated: &Matrix<'_, T, D>) -> Matrix<'a, T, D>

Source§

impl<'a, T, S: Shape, D: ClipOp<T, S>> Matrix<'a, T, D, S>

Source

pub fn clip(&self, min: T, max: T) -> Matrix<'_, T, D, S>

Source§

impl<'a, T, D: DiagflatOp<T>> Matrix<'a, T, D>

Source

pub fn diagflat(&self) -> Matrix<'a, T, D>

Source§

impl<'a, T: Float, S: Shape, D: FnsOps<T, S, D>> Matrix<'a, T, D, S>

Source

pub fn exp(&self) -> Self

Source

pub fn ln(&self) -> Self

Source

pub fn neg(&self) -> Self

Source

pub fn powf(&self, rhs: T) -> Self

Source

pub fn powi(&self, rhs: i32) -> Self

Source§

impl<'a, T, D: Device, LS: Shape> Matrix<'a, T, D, LS>

Source

pub fn gemm<RS: Shape, OS: Shape>( &self, rhs: &Matrix<'a, T, D, RS>, ) -> Matrix<'a, T, D, OS>
where D: Gemm<T, LS, RS, OS, D>,

Matrix multiplication. Uses current global device.

§Example
use custos::CPU;
use custos_math::Matrix;

let device = CPU::new();

let a = Matrix::from((&device, (2, 3), [1., 2., 3., 4., 5., 6.,]));
let b = Matrix::from((&device, (3, 2), [6., 5., 4., 3., 2., 1.,]));

let c = a.gemm(&b);
println!("c: {c:?}");

assert_eq!(c.read(), vec![20., 14., 56., 41.,]);
Examples found in repository?
examples/gemm.rs (line 9)
3fn main() {
4    let device = CPU::new();
5
6    let a = Matrix::from((&device, (2, 3), [1., 2., 3., 4., 5., 6.]));
7    let b = Matrix::from((&device, (3, 2), [6., 5., 4., 3., 2., 1.]));
8
9    let c = a.gemm(&b);
10    println!("c: {c:?}");
11
12    assert_eq!(c.read(), vec![20., 14., 56., 41.,]);
13}
Source§

impl<'a, T, D: MaxOps<T>> Matrix<'a, T, D>

Source

pub fn max(&self) -> T

Source

pub fn max_rows(&self) -> Matrix<'a, T, D>

Source

pub fn max_cols(&self) -> Matrix<'a, T, D>

Source§

impl<'a, T, LS: Shape, D: Device> Matrix<'a, T, D, LS>

Source

pub fn add_row<RS: Shape>( &self, rhs: &Matrix<'_, T, D, RS>, ) -> Matrix<'a, T, D, LS>
where D: RowOp<T, LS, RS>,

Source

pub fn add_row_mut<RS: Shape>(&mut self, rhs: &Matrix<'a, T, D, RS>)
where D: RowOp<T, LS, RS>,

Source§

impl<'a, T, D, S> Matrix<'a, T, D, S>
where D: AdditionalOps<T, S>, S: Shape,

Source

pub fn adds(&self, rhs: T) -> Self

Source

pub fn subs(&self, rhs: T) -> Self

Source

pub fn muls(&self, rhs: T) -> Self

Source

pub fn divs(&self, rhs: T) -> Self

Source§

impl<'a, T, IS: Shape, D: SumOps<T, IS>> Matrix<'a, T, D, IS>

Source

pub fn sum(&self) -> T

Source

pub fn mean(&self) -> T

Source§

impl<'a, T, D: Device, IS: Shape> Matrix<'a, T, D, IS>

Source

pub fn sum_rows<OS: Shape>(&self) -> Matrix<'a, T, D, OS>
where D: SumOverOps<T, IS, OS>,

Source

pub fn sum_cols<OS: Shape>(&self) -> Matrix<'a, T, D, OS>
where D: SumOverOps<T, IS, OS>,

Source§

impl<'a, T, IS: Shape, D: Device> Matrix<'a, T, D, IS>

Source

pub fn T<OS: Shape>(&self) -> Matrix<'a, T, D, OS>
where D: TransposeOp<T, IS, OS>,

Methods from Deref<Target = Buffer<'a, T, D, S>>§

Source

pub fn device(&self) -> &'a D

Source

pub fn read(&'a self) -> <D as Read<T, D, S>>::Read<'a>
where T: Clone + Default, D: Read<T, D, S>,

Source

pub fn read_to_vec(&self) -> Vec<T>
where D: Read<T, D, S>, T: Default + Clone,

Reads the contents of the buffer and writes them into a vector. If it is certain whether a CPU, or an unified CPU + OpenCL Buffer, is used, calling .as_slice() (or deref/mut to &/mut [&T]) is probably preferred.

§Example
use custos::{CPU, Buffer};

let device = CPU::new();
let buf = Buffer::from((&device, [1, 2, 3, 4]));

assert_eq!(buf.read_to_vec(), vec![1, 2, 3, 4]);
Source

pub fn write(&mut self, data: &[T])
where T: Clone, D: WriteBuf<T, D, S>,

Writes a slice to the Buffer. With a CPU buffer, the slice is just copied to the slice of the buffer.

Source

pub fn len(&self) -> usize

Returns the number of elements contained in Buffer.

§Example
use custos::{CPU, Buffer};

let device = CPU::new();
let a = Buffer::<i32, _>::new(&device, 10);
assert_eq!(a.len(), 10)
Source

pub unsafe fn shallow(&self) -> Buffer<'a, T, D, S>
where <D as Device>::Ptr<T, S>: ShallowCopy,

Creates a shallow copy of &self.

§Safety

Itself, this function does not need to be unsafe. However, declaring this function as unsafe highlights the violation of creating two or more owners for one resource. Furthermore, the resulting Buffer can outlive self.

Source

pub unsafe fn shallow_or_clone(&self) -> Buffer<'a, T, D, S>
where <D as Device>::Ptr<T, S>: ShallowCopy, T: Clone, D: CloneBuf<'a, T, S>,

Returns a shallow copy of &self, if the realloc feature is deactivated. If the realloc feature is activated, it returns a deep copy / clone.

§Safety

Itself, this function does not need to be unsafe. However, declaring this function as unsafe highlights the violation of possibly creating two or more owners for one resource. Furthermore, the resulting Buffer can outlive self.

Source

pub fn id(&self) -> Ident

Source

pub fn as_dims<'b, O>(&self) -> &Buffer<'b, T, D, O>
where O: Shape,

Source

pub fn as_dims_mut<'b, O>(&mut self) -> &mut Buffer<'b, T, D, O>
where O: Shape,

Source

pub fn ptrs(&self) -> (*const T, *mut c_void, u64)

Returns all types of pointers. (host, OpenCL, CUDA)

Source

pub fn ptrs_mut(&mut self) -> (*mut T, *mut c_void, u64)

Returns all types of pointers. (host, OpenCL, CUDA)

Source

pub fn is_empty(&self) -> bool

Returns true if Buffer is created without a slice.

§Example
use custos::{CPU, Buffer};

let a = Buffer::<i32, ()>::from(5);
assert!(a.is_empty())
Source

pub fn clear(&mut self)
where D: ClearBuf<T>,

Sets all elements in Buffer to the default value.

Source

pub fn as_slice(&self) -> &[T]

Returns a CPU slice. This does not work with CUDA or raw OpenCL buffers.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable CPU slice.

Source

pub fn host_ptr(&self) -> *const T

Returns a non null host pointer

Source

pub fn host_ptr_mut(&mut self) -> *mut T

Returns a non null host pointer

Trait Implementations§

Source§

impl<'a, T, D, S: Shape> Add<&Matrix<'a, T, D, S>> for Matrix<'a, T, D, S>
where D: BaseOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T, D, S: Shape> Add<Matrix<'a, T, D, S>> for &Matrix<'a, T, D, S>
where D: BaseOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<'_, T, D, S>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T, D, S: Shape> Add<T> for &Matrix<'a, T, D, S>
where D: AdditionalOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T, D> Add<T> for Matrix<'a, T, D>
where D: AdditionalOps<T>,

Source§

type Output = Matrix<'a, T, D>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T, D, S: Shape> Add for &Matrix<'a, T, D, S>
where D: BaseOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T, D, S: Shape> Add for Matrix<'a, T, D, S>
where D: BaseOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, D, S: Shape> AddAssign<&Matrix<'_, T, D, S>> for Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
Source§

impl<'a, T, S, D> AddAssign<T> for Matrix<'a, T, D, S>
where S: Shape, D: ScalarAssign<T, S>,

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<T, D, S: Shape> AddAssign for Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<'a, T> AsClCvoidPtr for &Matrix<'a, T, OpenCL>

Source§

impl<'a, T> AsClCvoidPtr for Matrix<'a, T, OpenCL>

Source§

impl<'a, T, S, D> Clone for Matrix<'a, T, D, S>
where T: Clone, S: Shape, D: CloneBuf<'a, T, S>,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Default + Copy + Debug, D> Debug for Matrix<'a, T, D>
where D: Read<T, D> + 'a,

Available on non-crate feature no-std only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, D: Device> Default for Matrix<'_, T, D>
where D::Ptr<T, ()>: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T, D: Device, S: Shape> Deref for Matrix<'a, T, D, S>

Source§

type Target = Buffer<'a, T, D, S>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, T, D: Device, S: Shape> DerefMut for Matrix<'a, T, D, S>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'a, T, S: Shape, D: AdditionalOps<T, S>> Div<T> for &Matrix<'a, T, D, S>

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<'a, T, S: Shape, D: AdditionalOps<T, S>> Div<T> for Matrix<'a, T, D, S>

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<'a, T, S: Shape, D: BaseOps<T, S>> Div for &Matrix<'a, T, D, S>

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<T, S, D> DivAssign<T> for Matrix<'_, T, D, S>
where S: Shape, D: ScalarAssign<T, S>,

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<'a, T> From<(&'a CPU, *mut T, (usize, usize))> for Matrix<'a, T>

Available on crate feature cpu only.
Source§

fn from((cpu, ptr, dims): (&'a CPU, *mut T, (usize, usize))) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T>> From<(&'a D, (usize, usize))> for Matrix<'a, T, D>

Source§

fn from((device, dims): (&'a D, (usize, usize))) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T> + IsShapeIndep> From<(&'a D, (usize, usize), &[T])> for Matrix<'a, T, D>

Source§

fn from(dims_slice: (&'a D, (usize, usize), &[T])) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T> + IsShapeIndep> From<(&'a D, (usize, usize), &Vec<T>)> for Matrix<'a, T, D>

Available on non-crate feature no-std only.
Source§

fn from(dims_slice: (&'a D, (usize, usize), &Vec<T>)) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T> + IsShapeIndep, const N: usize> From<(&'a D, (usize, usize), [T; N])> for Matrix<'a, T, D>

Source§

fn from((device, dims, slice): (&'a D, (usize, usize), [T; N])) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T> + IsShapeIndep> From<(&'a D, (usize, usize), Vec<T>)> for Matrix<'a, T, D>

Available on non-crate feature no-std only.
Source§

fn from(dims_slice: (&'a D, (usize, usize), Vec<T>)) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T>> From<(&'a D, usize, usize)> for Matrix<'a, T, D>

Source§

fn from((device, rows, cols): (&'a D, usize, usize)) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T> + IsShapeIndep> From<(&'a D, usize, usize, &[T])> for Matrix<'a, T, D>

Source§

fn from(dims_slice: (&'a D, usize, usize, &[T])) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T> + IsShapeIndep, const N: usize> From<(&'a D, usize, usize, [T; N])> for Matrix<'a, T, D>

Source§

fn from(dims_slice: (&'a D, usize, usize, [T; N])) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy, D: Alloc<'a, T> + IsShapeIndep> From<(&'a D, usize, usize, Vec<T>)> for Matrix<'a, T, D>

Available on non-crate feature no-std only.
Source§

fn from(dims_slice: (&'a D, usize, usize, Vec<T>)) -> Self

Converts to this type from the input type.
Source§

impl<'a, 'b, T> From<(&'a OpenCL, Matrix<'b, T>)> for Matrix<'a, T, OpenCL>

Available on crate feature opencl only.
Source§

fn from((device, matrix): (&'a OpenCL, Matrix<'b, T>)) -> Self

Converts to this type from the input type.
Source§

impl<'a, T> From<(*mut T, (usize, usize))> for Matrix<'a, T>

Available on crate feature cpu only.
Source§

fn from((ptr, dims): (*mut T, (usize, usize))) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, D: Device, S: Shape> From<(Buffer<'a, T, D, S>, (usize, usize))> for Matrix<'a, T, D, S>

Source§

fn from((data, dims): (Buffer<'a, T, D, S>, (usize, usize))) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, D: Device, S: Shape> From<(Buffer<'a, T, D, S>, usize, usize)> for Matrix<'a, T, D, S>

Source§

fn from((data, rows, cols): (Buffer<'a, T, D, S>, usize, usize)) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, D, S: Shape> Mul<&Matrix<'a, T, D, S>> for Matrix<'a, T, D, S>
where D: BaseOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T: Copy, S: Shape, D: AdditionalOps<T, S>> Mul<&T> for Matrix<'a, T, D, S>

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &T) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T, S: Shape, D: AdditionalOps<T, S>> Mul<T> for &Matrix<'a, T, D, S>

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T, S: Shape, D: AdditionalOps<T, S>> Mul<T> for Matrix<'a, T, D, S>

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T, D, S: Shape> Mul for &Matrix<'a, T, D, S>
where D: BaseOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T, D, S: Shape> Mul for Matrix<'a, T, D, S>
where D: BaseOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, D, S: Shape> MulAssign<&Matrix<'_, T, D, S>> for Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn mul_assign(&mut self, rhs: &Self)

Performs the *= operation. Read more
Source§

impl<T, S, D> MulAssign<T> for Matrix<'_, T, D, S>
where S: Shape, D: ScalarAssign<T, S>,

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T, D, S: Shape> MulAssign for Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<'a, T, D, S> Sub<&Matrix<'a, T, D, S>> for Matrix<'a, T, D, S>
where D: BaseOps<T, S>, S: Shape,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T, D, S> Sub<Matrix<'a, T, D, S>> for &Matrix<'a, T, D, S>
where D: BaseOps<T, S>, S: Shape,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<'_, T, D, S>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T, D, S> Sub<T> for &Matrix<'a, T, D, S>
where S: Shape, D: AdditionalOps<T, S>,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T> Sub<T> for Matrix<'a, T>

Source§

type Output = Matrix<'a, T>

The resulting type after applying the - operator.
Source§

fn sub(self, _rhs: T) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T, D, S> Sub for &Matrix<'a, T, D, S>
where D: BaseOps<T, S>, S: Shape,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T, D, S> Sub for Matrix<'a, T, D, S>
where D: BaseOps<T, S>, S: Shape,

Source§

type Output = Matrix<'a, T, D, S>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, D, S: Shape> SubAssign<&Matrix<'_, T, D, S>> for &mut Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn sub_assign(&mut self, rhs: &Matrix<'_, T, D, S>)

Performs the -= operation. Read more
Source§

impl<T, D, S: Shape> SubAssign<&Matrix<'_, T, D, S>> for Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more
Source§

impl<T, D, S: Shape> SubAssign<Matrix<'_, T, D, S>> for &mut Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn sub_assign(&mut self, rhs: Matrix<'_, T, D, S>)

Performs the -= operation. Read more
Source§

impl<T, D, S: Shape> SubAssign for Matrix<'_, T, D, S>
where D: AssignOps<T, S, D>,

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'a, T, D, C, const B: usize, const A: usize> WithShape<&'a D, C> for Matrix<'a, T, D, Dim2<B, A>>
where D: Device, Buffer<'a, T, D, Dim2<B, A>>: WithShape<&'a D, C>,

Source§

fn with(device: &'a D, array: C) -> Self

Auto Trait Implementations§

§

impl<'a, T, D, S> Freeze for Matrix<'a, T, D, S>
where <D as Device>::Ptr<T, S>: Freeze,

§

impl<'a, T, D, S> RefUnwindSafe for Matrix<'a, T, D, S>
where <D as Device>::Ptr<T, S>: RefUnwindSafe, D: RefUnwindSafe,

§

impl<'a, T, D, S> Send for Matrix<'a, T, D, S>

§

impl<'a, T, D, S> Sync for Matrix<'a, T, D, S>

§

impl<'a, T, D, S> Unpin for Matrix<'a, T, D, S>
where <D as Device>::Ptr<T, S>: Unpin,

§

impl<'a, T, D, S> UnwindSafe for Matrix<'a, T, D, S>
where <D as Device>::Ptr<T, S>: UnwindSafe, D: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.