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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use array::Array;


/// Creates new array of given shape filled with given value
///
/// # Arguments
///
/// * `value` - value to fill array with
/// * `shape` - shape of new array
///
/// # Examples
///
/// ```
///  use numas::array::Array;
///  use numas::shape::Shape;
///
///  let array = numas::factory::fill::full::<i32>(3, vec![2, 2]);
///  let data = array.collect();
///
///  assert_eq!(data, vec![3; 4]);
/// ```
pub fn full<T: Copy>(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
///
/// # Examples
///
/// ```
///  use numas::array::Array;
///  use numas::shape::Shape;
///
///  let array = numas::factory::fill::zeros::<f64>(vec![2, 2]);
///  let data = array.collect();
///
///  assert_eq!(data, vec![0.0 as f64; 4]);
/// ```
#[inline]
pub fn zeros<T: Copy + 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
///
/// # Examples
///
/// ```
///  use numas::array::Array;
///  use numas::shape::Shape;
///
///  let array = numas::factory::fill::zeroes::<f64>(vec![2, 2]);
///  let data = array.collect();
///
///  assert_eq!(data, vec![0.0 as f64; 4]);
/// ```
#[inline]
pub fn zeroes<T: Copy + 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
///
/// # Examples
///
/// ```
///  use numas::array::Array;
///  use numas::shape::Shape;
///
///  let array = numas::factory::fill::ones::<i32>(vec![2, 2]);
///  let data = array.collect();
///
///  assert_eq!(data, vec![1 as i32; 4]);
/// ```
#[inline]
pub fn ones<T: Copy + From<u8>>(shape: Vec<i32>) -> Array<T> {
    return full::<T>(T::from(1), shape);
}