Skip to main content

ionian_core/tensor/
shape.rs

1#[derive(Debug, Clone, PartialEq, Eq)]
2pub struct Shape {
3    dims: Vec<usize>,
4}
5
6impl Shape {
7    pub fn new(dims: Vec<usize>) -> Self {
8        Shape { dims }
9    }
10
11    pub fn dims(&self) -> &[usize] {
12        &self.dims
13    }
14
15    pub fn num_elements(&self) -> usize {
16        self.dims.iter().product()
17    }
18
19    pub fn rank(&self) -> usize {
20        self.dims.len()
21    }
22}
23
24impl From<Vec<usize>> for Shape {
25    fn from(dims: Vec<usize>) -> Self {
26        Shape::new(dims)
27    }
28}