pub trait ArrayCreateNumeric<N: Numeric>{
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 rand(shape: Vec<usize>) -> Result<Self, ArrayError>
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
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)));
§Errors
may returns ArrayError
Sourcefn identity(dim: usize) -> Result<Self, ArrayError>
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
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>
Creates new array of fill_value
like other array
§Arguments
other
- array defining the shape of new onefill_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
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));
§Errors
may returns ArrayError
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);
§Errors
may returns ArrayError
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));
§Errors
may returns ArrayError
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);
§Errors
may returns ArrayError
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}"));
§Errors
may returns ArrayError
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}"));
§Errors
may returns ArrayError
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());
§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.