Trait ArrayCreateNumeric

Source
pub trait ArrayCreateNumeric<N: Numeric>
where Self: Sized + Clone,
{
Show 17 methods // Required methods fn rand(shape: Vec<usize>) -> Result<Self, ArrayError>; fn eye( n: usize, m: Option<usize>, k: Option<usize>, ) -> Result<Self, ArrayError>; fn identity(dim: usize) -> Result<Self, ArrayError>; fn zeros(shape: Vec<usize>) -> Result<Self, ArrayError>; fn zeros_like(other: &Self) -> Result<Self, ArrayError>; fn ones(shape: Vec<usize>) -> Result<Self, ArrayError>; fn ones_like(other: &Self) -> Result<Self, ArrayError>; fn full(shape: Vec<usize>, fill_value: N) -> Result<Self, ArrayError>; fn full_like(other: &Self, fill_value: N) -> Result<Self, ArrayError>; fn arange(start: N, stop: N, step: Option<N>) -> Result<Self, ArrayError>; fn linspace( start: N, stop: N, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>; fn linspace_a( start: &Self, stop: &Self, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>; fn logspace( start: N, stop: N, num: Option<usize>, endpoint: Option<bool>, base: Option<usize>, ) -> Result<Self, ArrayError>; fn logspace_a( start: &Self, stop: &Self, num: Option<usize>, endpoint: Option<bool>, base: Option<&Array<usize>>, ) -> Result<Self, ArrayError>; fn geomspace( start: N, stop: N, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>; fn geomspace_a( start: &Self, stop: &Self, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>; fn tri( n: usize, m: Option<usize>, k: Option<isize>, ) -> Result<Self, ArrayError>;
}
Expand description

ArrayTrait - Array Create functions

Required Methods§

Source

fn rand(shape: Vec<usize>) -> Result<Self, ArrayError>

Creates new array with random elements from (0 ..= 1) range

§Arguments
  • shape - vector representing array elements
§Examples
use arr_rs::prelude::*;

assert_eq!(4, Array::<f64>::rand(vec![4]).len().unwrap());
assert_eq!(64, Array::<f64>::rand(vec![4, 4, 4]).len().unwrap());
§Errors

may returns ArrayError

Source

fn eye(n: usize, m: Option<usize>, k: Option<usize>) -> Result<Self, ArrayError>

Creates new 2d array with ones on the diagonal and zeros elsewhere

§Arguments
  • n - number of rows
  • m - number of columns. optional, defaulted to n
  • k - index of diagonal. optional, defaulted to 0
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(i32, [[1, 0, 0], [0, 1, 0]]), Array::<i32>::eye(2, Some(3), Some(0)));
assert_eq!(array!(i32, [[0, 1, 0], [0, 0, 1]]), Array::<i32>::eye(2, Some(3), Some(1)));
§Errors

may returns ArrayError

Source

fn identity(dim: usize) -> Result<Self, ArrayError>

Creates new identity 2d array

§Arguments
  • n - numbers of rows and columns of resulting array
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(i32, [[1, 0], [0, 1]]), Array::<i32>::identity(2));
assert_eq!(array!(i32, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]), Array::<i32>::identity(3));
§Errors

may returns ArrayError

Source

fn zeros(shape: Vec<usize>) -> Result<Self, ArrayError>

Creates new array of zeros

§Arguments
  • shape - vector representing array elements
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [0, 0, 0, 0]), Array::<f64>::zeros(vec![4]));
§Errors

may returns ArrayError

Source

fn zeros_like(other: &Self) -> Result<Self, ArrayError>

Creates new array of zeros like other array

§Arguments
  • other - array defining the shape of new one
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [0, 0, 0, 0]), Array::<f64>::zeros_like(&array!(f64, [1, 2, 3, 4]).unwrap()));
§Errors

may returns ArrayError

Source

fn ones(shape: Vec<usize>) -> Result<Self, ArrayError>

Creates new array of ones

§Arguments
  • shape - vector representing array shape
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [1, 1, 1, 1]), Array::<f64>::ones(vec![4]));
§Errors

may returns ArrayError

Source

fn ones_like(other: &Self) -> Result<Self, ArrayError>

Creates new array of ones like other array

§Arguments
  • other - array defining the shape of new one
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [1, 1, 1, 1]), Array::<f64>::ones_like(&array!(f64, [1, 2, 3, 4]).unwrap()));
§Errors

may returns ArrayError

Source

fn full(shape: Vec<usize>, fill_value: N) -> Result<Self, ArrayError>

Creates new array of fill_value

§Arguments
  • shape - vector representing array shape
  • fill_value - value to fill the array with
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [2, 2, 2, 2]), Array::<f64>::full(vec![4], 2.));
§Errors

may returns ArrayError

Source

fn full_like(other: &Self, fill_value: N) -> Result<Self, ArrayError>

Creates new array of fill_value like other array

§Arguments
  • other - array defining the shape of new one
  • fill_value - value to fill the array with
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [2, 2, 2, 2]), Array::<f64>::full_like(&array!(f64, [1, 2, 3, 4]).unwrap(), 2.));
§Errors

may returns ArrayError

Source

fn arange(start: N, stop: N, step: Option<N>) -> Result<Self, ArrayError>

Creates new array from range

§Arguments
  • start - start of interval
  • stop - end of interval
  • step - spacing between values. optional, defaults to 1
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [0., 1., 2., 3., 4.]), Array::arange(0., 4., None));
§Errors

may returns ArrayError

Source

fn linspace( start: N, stop: N, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>

Creates new array of numbers evenly spaced over a specified interval

§Arguments
  • start - start of interval
  • stop - end of interval
  • num - number of samples to generate. optional, defaults to 50
  • endpoint - determines if stop should be included in returned data. optional, defaults to true
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [0., 2.5, 5.]), Array::<f64>::linspace(0., 5., Some(3), None));
§Errors

may returns ArrayError

Source

fn linspace_a( start: &Self, stop: &Self, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>

Creates new array of numbers evenly spaced over a specified interval

§Arguments
  • start - start of interval
  • stop - end of interval
  • num - number of samples to generate. optional, defaults to 50
  • endpoint - determines if stop should be included in returned data. optional, defaults to true
§Examples
use arr_rs::prelude::*;

let arr = Array::linspace_a(&array!(f64, [0., 2.]).unwrap(), &array!(f64, [4., 6.]).unwrap(), Some(3), None).unwrap();
assert_eq!(array!(f64, [[0., 2.], [2., 4.], [4., 6.]]).unwrap(), arr);
let arr = Array::linspace_a(&array!(f64, [[0., 2.], [2., 4.]]).unwrap(), &array!(f64, [[4., 6.], [6., 8.]]).unwrap(), Some(3), None).unwrap();
assert_eq!(array!(f64, [[[0., 2.], [2., 4.]], [[2., 4.], [4., 6.]], [[4., 6.], [6., 8.]]]).unwrap(), arr);
§Errors

may returns ArrayError

Source

fn logspace( start: N, stop: N, num: Option<usize>, endpoint: Option<bool>, base: Option<usize>, ) -> Result<Self, ArrayError>

Creates new array of numbers evenly spaced on a log scale over a specified interval

§Arguments
  • start - start of interval
  • stop - end of interval
  • num - number of samples to generate. optional, defaults to 50
  • endpoint - determines if stop should be included in returned data. optional, defaults to true
  • base - the base of the log space. optional, defaults to 10
§Examples
use arr_rs::prelude::*;

assert_eq!(array!(f64, [1., 316.22776601683796, 100000.]), Array::<f64>::logspace(0., 5., Some(3), None, None));
§Errors

may returns ArrayError

Source

fn logspace_a( start: &Self, stop: &Self, num: Option<usize>, endpoint: Option<bool>, base: Option<&Array<usize>>, ) -> Result<Self, ArrayError>

Creates new array of numbers evenly spaced on a log scale over a specified interval

§Arguments
  • start - start of interval
  • stop - end of interval
  • num - number of samples to generate. optional, defaults to 50
  • endpoint - determines if stop should be included in returned data. optional, defaults to true
  • base - the base of the log space. optional, defaults to 10
§Examples
use arr_rs::prelude::*;

let arr = Array::logspace_a(&array!(f64, [0., 2.]).unwrap(), &array!(f64, [4., 6.]).unwrap(), Some(3), None, None).unwrap();
assert_eq!(array!(f64, [[1., 100.], [100., 10000.], [10000., 1000000.]]).unwrap(), arr);
let arr = Array::logspace_a(&array!(f64, [[0., 2.], [2., 4.]]).unwrap(), &array!(f64, [[4., 6.], [6., 8.]]).unwrap(), Some(3), None, None).unwrap();
assert_eq!(array!(f64, [[[1., 100.], [100., 10000.]], [[100., 10000.], [10000., 1000000.]], [[10000., 1000000.], [1000000., 100000000.]]]).unwrap(), arr);
§Errors

may returns ArrayError

Source

fn geomspace( start: N, stop: N, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>

Creates new array of numbers evenly spaced on a log scale (a geometric progression) over a specified interval

§Arguments
  • start - start of interval
  • stop - end of interval
  • num - number of samples to generate. optional, defaults to 50
  • endpoint - determines if stop should be included in returned data. optional, defaults to true
§Examples
use arr_rs::prelude::*;

let expected = array!(f64, [1., 10., 100., 1000.]).unwrap();
let arr = Array::geomspace(1., 1000., Some(4), None).unwrap();
assert_eq!(format!("{expected:.4}"), format!("{arr:.4}"));
§Errors

may returns ArrayError

Source

fn geomspace_a( start: &Self, stop: &Self, num: Option<usize>, endpoint: Option<bool>, ) -> Result<Self, ArrayError>

Creates new array of numbers evenly spaced on a log scale (a geometric progression) over a specified interval

§Arguments
  • start - start of interval
  • stop - end of interval
  • num - number of samples to generate. optional, defaults to 50
  • endpoint - determines if stop should be included in returned data. optional, defaults to true
§Examples
use arr_rs::prelude::*;

let expected = array!(f64, [[1., 10.], [10., 100.], [100., 1000.], [1000., 10000.]]).unwrap();
let arr = Array::geomspace_a(&array!(f64, [1., 10.]).unwrap(), &array!(f64, [1000., 10000.]).unwrap(), Some(4), None).unwrap();
assert_eq!(format!("{expected:.4}"), format!("{arr:.4}"));
let expected = array!(f64, [[[1., 10.], [10., 100.]], [[10., 100.], [100., 1000.]], [[100., 1000.], [1000., 10000.]]]).unwrap();
let arr = Array::geomspace_a(&array!(f64, [[1., 10.], [10., 100.]]).unwrap(), &array!(f64, [[100., 1000.], [1000., 10000.]]).unwrap(), Some(3), None).unwrap();
assert_eq!(format!("{expected:.4}"), format!("{arr:.4}"));
§Errors

may returns ArrayError

Source

fn tri(n: usize, m: Option<usize>, k: Option<isize>) -> Result<Self, ArrayError>

Construct an array with ones at and below the given diagonal and zeros elsewhere

§Arguments
  • n - number of rows
  • m - number of columns. optional, defaults to n
  • k - chosen diagonal. optional, defaults to 0
§Examples
use arr_rs::prelude::*;

let expected = array!(i32, [[1, 0], [1, 1]]).unwrap();
assert_eq!(expected, Array::<i32>::tri(2, Some(2), None).unwrap());

let expected = array!(i32, [[1, 0, 0], [1, 1, 0], [1, 1, 1]]).unwrap();
assert_eq!(expected, Array::<i32>::tri(3, Some(3), None).unwrap());
§Errors

may returns ArrayError

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§