BaseOps

Trait BaseOps 

Source
pub trait BaseOps<T, S: Shape = (), D: Device = Self>: Device {
    // Required methods
    fn add(
        &self,
        lhs: &Matrix<'_, T, D, S>,
        rhs: &Matrix<'_, T, D, S>,
    ) -> Matrix<'_, T, Self, S>;
    fn sub(
        &self,
        lhs: &Matrix<'_, T, D, S>,
        rhs: &Matrix<'_, T, D, S>,
    ) -> Matrix<'_, T, Self, S>;
    fn mul(
        &self,
        lhs: &Matrix<'_, T, D, S>,
        rhs: &Matrix<'_, T, D, S>,
    ) -> Matrix<'_, T, Self, S>;
    fn div(
        &self,
        lhs: &Matrix<'_, T, D, S>,
        rhs: &Matrix<'_, T, D, S>,
    ) -> Matrix<'_, T, Self, S>;
}
Expand description

Element-wise +, -, *, / operations for matrices.

§Examples

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

let device = CPU::new();
let a = Matrix::from((&device, (2, 3), [2, 4, 6, 8, 10, 12]));
let b = Matrix::from((&device, (2, 3), [12, 4, 3, 1, -5, -3]));

let c = &a + &b;
assert_eq!(c.read(), vec![14, 8, 9, 9, 5, 9]);

use custos_math::BaseOps;
let sub = device.sub(&a, &b);
assert_eq!(sub.read(), vec![-10, 0, 3, 7, 15, 15]);

Required Methods§

Source

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

Element-wise addition

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

let device = CPU::new();
let a = Matrix::from((&device, 2, 3, [2, 4, 6, 8, 10, 12]));
let b = Matrix::from((&device, 2, 3, [12, 4, 3, 1, -5, -3]));

let c = a + b;
assert_eq!(c.read(), vec![14, 8, 9, 9, 5, 9]);
Source

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

Element-wise subtraction

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

let device = CPU::new();
let a = Matrix::from((&device, 2, 3, [2, 4, 6, 8, 10, 12]));
let b = Matrix::from((&device, 2, 3, [12, 4, 3, 1, -5, -3]));

let sub = device.sub(&a, &b);
assert_eq!(sub.read(), vec![-10, 0, 3, 7, 15, 15]);
Source

fn mul( &self, lhs: &Matrix<'_, T, D, S>, rhs: &Matrix<'_, T, D, S>, ) -> Matrix<'_, T, Self, S>

Element-wise multiplication

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

let device = CPU::new();
let a = Matrix::from((&device, 2, 3, [2, 4, 6, 8, 10, 12]));
let b = Matrix::from((&device, 2, 3, [12, 4, 3, 1, -5, -3]));

let mul = a * b;
assert_eq!(mul.read(), vec![24, 16, 18, 8, -50, -36]);
Source

fn div( &self, lhs: &Matrix<'_, T, D, S>, rhs: &Matrix<'_, T, D, S>, ) -> Matrix<'_, T, Self, S>

Element-wise division

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

let device = CPU::new();
let a = Matrix::from((&device, 2, 3, [2, 4, 6, 8, 10, 12]));
let b = Matrix::from((&device, 2, 3, [12, 4, 3, 1, -5, -3]));

let div = device.div(&a, &b);
assert_eq!(div.read(), vec![0, 1, 2, 8, -2, -4]);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, S, D> BaseOps<T, S, D> for CPU
where T: Number, S: Shape, D: MainMemory,

Available on crate feature cpu only.
Source§

impl<T: CDatatype> BaseOps<T> for OpenCL

Available on crate feature opencl only.