Trait rustml::ops_inplace::VectorVectorOpsInPlace [] [src]

pub trait VectorVectorOpsInPlace<T> {
    fn iadd(&mut self, rhs: &[T]);
    fn isub(&mut self, rhs: &[T]);
    fn imul(&mut self, rhs: &[T]);
    fn idiv(&mut self, rhs: &[T]);
    fn nrm2(&self) -> T;
}

Trait for inplace vector-vector operations.

Required Methods

fn iadd(&mut self, rhs: &[T])

Adds the given vector rhs to self inplace.

This operation uses BLAS for high performance for vectors with elements of type f32 and f64. Panics if the dimensions of the vectors do not match.

Example

use rustml::*;

let mut v = vec![1.0, 2.0];
let y = vec![3.0, 8.0];
v.iadd(&y);
assert_eq!(v, vec![4.0, 10.0]);

fn isub(&mut self, rhs: &[T])

Substracts the given vector rhs from self inplace.

This operation uses BLAS for high performance for vectors with elements of type f32 and f64. Panics if the dimensions of the vectors do not match.

Example

use rustml::*;

let mut v = vec![1.0, 2.0];
let y = vec![3.0, 8.0];
v.isub(&y);
assert_eq!(v, vec![-2.0, -6.0]);

fn imul(&mut self, rhs: &[T])

Computes an element-wise vector-vector multiplication and stores the result in self.

Panics if the dimensions of the vectors do not match.

Implementation details

This operation does not use BLAS. Instead a simple loop is used to compute the element-wise vector-vector multiplication.

Example

use rustml::*;

let mut v = vec![3.0, 2.0];
let y = vec![3.0, 8.0];
v.imul(&y);
assert_eq!(v, vec![9.0, 16.0]);

fn idiv(&mut self, rhs: &[T])

Computes an element-wise vector-vector division and stores the result in self.

For all elements in self the element at index i in self is divided by the element in rhs at the same index.

Panics if the dimensions of the vectors do not match.

Implementation details

This operation does not use BLAS. Instead a simple loop is used to compute the element-wise vector-vector division.

Example

use rustml::*;

let mut v = vec![3.0, 2.0];
let y = vec![2.0, 8.0];
v.idiv(&y);
assert_eq!(v, vec![1.5, 0.25]);

fn nrm2(&self) -> T

Computes the L2 norm (i.e. the euclidean norm) of the vector.

Implementation details

This operation is optimized via BLAS.

Example


use rustml::*;

let v = vec![3.0, 2.0, 4.0];
assert!(num::abs(v.nrm2() - 5.3852) <= 0.0001);

Implementors