pub trait ArrayCreateFrom<N: Numeric>where
    Array<N>: Sized + Clone,{
    // Required methods
    fn diag(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>;
    fn diagflat(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>;
    fn tril(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>;
    fn triu(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>;
    fn vander(
        &self,
        n: Option<usize>,
        increasing: Option<bool>
    ) -> Result<Array<N>, ArrayError>;
}
Expand description

ArrayTrait - Array Create functions

Required Methods§

source

fn diag(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

Extract a diagonal or construct a diagonal array

Arguments
  • k - chosen diagonal. optional, defaults to 0
Examples
use arr_rs::prelude::*;

let expected: Array<i32> = array!([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]).unwrap();
let arr: Array<i32> = Array::diag(&array![1, 2, 3, 4].unwrap(), None).unwrap();
assert_eq!(expected, arr);

let expected: Array<i32> = array!([1, 2, 3, 4]).unwrap();
let arr: Array<i32> = Array::diag(&array!([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]).unwrap(), None).unwrap();
assert_eq!(expected, arr);

let expected: Array<i32> = array!([0, 0, 0]).unwrap();
let arr: Array<i32> = Array::diag(&array!([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]).unwrap(), Some(1)).unwrap();
assert_eq!(expected, arr);
source

fn diagflat(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

Construct a diagonal array for flattened input

Arguments
  • data - input array
  • k - chosen diagonal. optional, defaults to 0
Examples
use arr_rs::prelude::*;

let expected: Array<i32> = array!([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]).unwrap();
let arr: Array<i32> = Array::diagflat(&array![1, 2, 3, 4].unwrap(), None).unwrap();
assert_eq!(expected, arr);

let expected: Array<i32> = array!([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]).unwrap();
let arr: Array<i32> = Array::diagflat(&array!([[1, 2], [3, 4]]).unwrap(), None).unwrap();
assert_eq!(expected, arr);
source

fn tril(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

Return a copy of an array with elements above the k-th diagonal zeroed. For arrays with ndim exceeding 2, tril will apply to the final two axes.

Arguments
  • k - chosen diagonal. optional, defaults to 0
Examples
use arr_rs::prelude::*;

let arr: Array<i32> = array_arange!(1, 8).reshape(vec![2, 4]).unwrap();
let expected: Array<i32> = array!([[1, 0, 0, 0], [5, 6, 0, 0]]).unwrap();
assert_eq!(expected, arr.tril(None).unwrap());

let arr: Array<i32> = array_arange!(1, 8).reshape(vec![2, 2, 2]).unwrap();
let expected: Array<i32> = array!([[[1, 0], [3, 4]], [[5, 0], [7, 8]]]).unwrap();
assert_eq!(expected, arr.tril(None).unwrap());
source

fn triu(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

Return a copy of an array with elements below the k-th diagonal zeroed. For arrays with ndim exceeding 2, triu will apply to the final two axes.

Arguments
  • k - chosen diagonal. optional, defaults to 0
Examples
use arr_rs::prelude::*;

let arr: Array<i32> = array_arange!(1, 8).reshape(vec![2, 4]).unwrap();
let expected: Array<i32> = array!([[1, 2, 3, 4], [0, 6, 7, 8]]).unwrap();
assert_eq!(expected, arr.triu(None).unwrap());

let arr: Array<i32> = array_arange!(1, 8).reshape(vec![2, 2, 2]).unwrap();
let expected: Array<i32> = array!([[[1, 2], [0, 4]], [[5, 6], [0, 8]]]).unwrap();
assert_eq!(expected, arr.triu(None).unwrap());
source

fn vander( &self, n: Option<usize>, increasing: Option<bool> ) -> Result<Array<N>, ArrayError>

Generate a Vandermonde matrix

Arguments
  • n - number of columns in the output. optional, by default square array is returned
  • increasing - order of the powers of the columns. optional, defaults to false if true, the powers increase from left to right, if false, they are reversed.
Examples
use arr_rs::prelude::*;

let arr: Array<i32> = array!([1, 2, 3, 4]).unwrap();
let expected: Array<i32> = array!([[1, 1, 1, 1], [8, 4, 2, 1], [27, 9, 3, 1], [64, 16, 4, 1]]).unwrap();
assert_eq!(expected, arr.vander(None, Some(false)).unwrap());

let arr: Array<i32> = array!([1, 2, 3, 4]).unwrap();
let expected: Array<i32> = array!([[1, 1, 1, 1], [1, 2, 4, 8], [1, 3, 9, 27], [1, 4, 16, 64]]).unwrap();
assert_eq!(expected, arr.vander(None, Some(true)).unwrap());

Implementations on Foreign Types§

source§

impl<N: Numeric> ArrayCreateFrom<N> for Result<Array<N>, ArrayError>

source§

fn diag(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

source§

fn diagflat(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

source§

fn tril(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

source§

fn triu(&self, k: Option<isize>) -> Result<Array<N>, ArrayError>

source§

fn vander( &self, n: Option<usize>, increasing: Option<bool> ) -> Result<Array<N>, ArrayError>

Implementors§