Trait arr_rs::numeric::operations::create::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§
sourcefn eye(n: usize, m: Option<usize>, k: Option<usize>) -> Result<Self, ArrayError>
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 rowsm
- number of columns. optional, defaulted to nk
- 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)));
sourcefn identity(dim: usize) -> Result<Self, ArrayError>
fn identity(dim: usize) -> Result<Self, ArrayError>
sourcefn zeros_like(other: &Self) -> Result<Self, ArrayError>
fn zeros_like(other: &Self) -> Result<Self, ArrayError>
sourcefn ones_like(other: &Self) -> Result<Self, ArrayError>
fn ones_like(other: &Self) -> Result<Self, ArrayError>
sourcefn full_like(other: &Self, fill_value: N) -> Result<Self, ArrayError>
fn full_like(other: &Self, fill_value: N) -> Result<Self, ArrayError>
sourcefn arange(start: N, stop: N, step: Option<N>) -> Result<Self, ArrayError>
fn arange(start: N, stop: N, step: Option<N>) -> Result<Self, ArrayError>
sourcefn linspace(
start: N,
stop: N,
num: Option<usize>,
endpoint: Option<bool>
) -> Result<Self, ArrayError>
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 intervalstop
- end of intervalnum
- number of samples to generate. optional, defaults to 50endpoint
- determines ifstop
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));
sourcefn linspace_a(
start: &Self,
stop: &Self,
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>
Creates new array of numbers evenly spaced over a specified interval
Arguments
start
- start of intervalstop
- end of intervalnum
- number of samples to generate. optional, defaults to 50endpoint
- determines ifstop
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);
sourcefn logspace(
start: N,
stop: N,
num: Option<usize>,
endpoint: Option<bool>,
base: Option<usize>
) -> Result<Self, ArrayError>
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 intervalstop
- end of intervalnum
- number of samples to generate. optional, defaults to 50endpoint
- determines ifstop
should be included in returned data. optional, defaults to truebase
- 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));
sourcefn logspace_a(
start: &Self,
stop: &Self,
num: Option<usize>,
endpoint: Option<bool>,
base: Option<&Array<usize>>
) -> Result<Self, ArrayError>
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 intervalstop
- end of intervalnum
- number of samples to generate. optional, defaults to 50endpoint
- determines ifstop
should be included in returned data. optional, defaults to truebase
- 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);
sourcefn geomspace(
start: N,
stop: N,
num: Option<usize>,
endpoint: Option<bool>
) -> Result<Self, ArrayError>
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 intervalstop
- end of intervalnum
- number of samples to generate. optional, defaults to 50endpoint
- determines ifstop
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}"));
sourcefn geomspace_a(
start: &Self,
stop: &Self,
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>
Creates new array of numbers evenly spaced on a log scale (a geometric progression) over a specified interval
Arguments
start
- start of intervalstop
- end of intervalnum
- number of samples to generate. optional, defaults to 50endpoint
- determines ifstop
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}"));
sourcefn tri(n: usize, m: Option<usize>, k: Option<isize>) -> Result<Self, ArrayError>
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 rowsm
- number of columns. optional, defaults ton
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());