[][src]Trait peroxide::traits::sugar::Scalable

pub trait Scalable {
    type Vec;
    pub fn resize(&self, size: (usize, usize), shape: Shape) -> Matrix;
pub fn add_col(&self, v: &Self::Vec) -> Matrix;
pub fn add_row(&self, v: &Self::Vec) -> Matrix; }

Associated Types

Loading content...

Required methods

pub fn resize(&self, size: (usize, usize), shape: Shape) -> Matrix[src]

pub fn add_col(&self, v: &Self::Vec) -> Matrix[src]

pub fn add_row(&self, v: &Self::Vec) -> Matrix[src]

Loading content...

Implementations on Foreign Types

impl Scalable for Vec<f64>[src]

type Vec = Self

pub fn resize(&self, (r, c): (usize, usize), shape: Shape) -> Matrix[src]

Vector to Matrix

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = c!(1,2,3,4,5,6);
    let b1 = a.resize((3,2), Row);
    let b2 = a.resize((3,2), Col);
    assert_eq!(b1, ml_matrix("1 2;3 4;5 6"));
    assert_eq!(b2, ml_matrix("1 4;2 5;3 6"));
}

pub fn add_row(&self, v: &Self::Vec) -> Matrix[src]

Vector + Vector = Matrix

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = c!(1,2,3);
    let b = c!(4,5,6);
    let c1 = a.add_row(&b);
    let c2 = a.add_col(&b);
    assert_eq!(c1, ml_matrix("1 2 3;4 5 6"));
    assert_eq!(c2, ml_matrix("1 4;2 5;3 6"));
}

pub fn add_col(&self, v: &Self::Vec) -> Matrix[src]

Vector + Vector = Matrix

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = c!(1,2,3);
    let b = c!(4,5,6);
    let c1 = a.add_row(&b);
    let c2 = a.add_col(&b);
    assert_eq!(c1, ml_matrix("1 2 3;4 5 6"));
    assert_eq!(c2, ml_matrix("1 4;2 5;3 6"));
}
Loading content...

Implementors

impl Scalable for Matrix[src]

Modify Matrix

type Vec = Vec<f64>

pub fn resize(&self, (r, c): (usize, usize), shape: Shape) -> Matrix[src]

Resize matrix

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2 3;4 5 6"); // ml_matrix has shape `Col`
    let b1 = a.resize((3, 2), Row);
    let b2 = a.resize((3, 2), Col);
    assert_eq!(b1, ml_matrix("1 2;3 4;5 6"));
    assert_eq!(b2, ml_matrix("1 4;2 5;3 6"));
}

pub fn add_row(&self, v: &Self::Vec) -> Matrix[src]

Add row

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2 3;4 5 6");
    let b = c!(7,8,9);
    let c = a.add_row(&b);
    assert_eq!(c, ml_matrix("1 2 3;4 5 6;7 8 9"));
}

pub fn add_col(&self, v: &Self::Vec) -> Matrix[src]

Add column

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2 3;4 5 6");
    let b = c!(7,8);
    let c = a.add_col(&b);
    assert_eq!(c, ml_matrix("1 2 3 7;4 5 6 8"));
}
Loading content...