1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use array::Array;
use shape::Shape;


/// Creates new array of given shape filled with given value
///
/// # Arguments
///
/// * `value` - value to fill array with
/// * `shape` - shape of new array
pub fn full<T: Clone>(value: T, shape: Vec<i32>) -> Array<T> {
    let len: i32 = shape.iter().product();
    return Array::new(vec![value; len as usize], shape);
}

/// Creates new array of given shape filled with zeros
///
/// # Arguments
///
/// * `shape` - shape of new array
#[inline]
pub fn zeros<T: Clone + From<u8>>(shape: Vec<i32>) -> Array<T> {
    return full::<T>(T::from(0), shape);
}

/// Creates new array of given shape filled with zeros
///
/// # Arguments
///
/// * `shape` - shape of new array
#[inline]
pub fn zeroes<T: Clone + From<u8>>(shape: Vec<i32>) -> Array<T> {
    return zeros::<T>(shape);
}

/// Creates new array of given shape filled with ones
///
/// # Arguments
///
/// * `shape` - shape of new array
#[inline]
pub fn ones<T: Clone + From<u8>>(shape: Vec<i32>) -> Array<T> {
    return full::<T>(T::from(1), shape);
}