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
/*
   Appellation: shapes <mod>
   Contrib: FL03 <jo3mccain@icloud.com>
*/
//! # Shapes
//!
//! This modules provides implements several useful primitives for working with
//! the shape of a [Tensor](crate::tensor::TensorBase).
pub use self::{axis::*, error::*, layout::Layout, rank::*, shape::Shape, stride::*};

pub(crate) mod axis;
pub(crate) mod error;
pub(crate) mod layout;
pub(crate) mod rank;
pub(crate) mod shape;
pub(crate) mod stride;

#[doc(hidden)]
pub mod dim;

pub trait IntoShape {
    fn into_shape(self) -> Shape;
}

impl<S> IntoShape for S
where
    S: Into<Shape>,
{
    fn into_shape(self) -> Shape {
        self.into()
    }
}

impl<'a> IntoShape for &'a Shape {
    fn into_shape(self) -> Shape {
        self.clone()
    }
}

pub(crate) mod prelude {
    pub use super::IntoShape;

    pub use super::axis::{Axis, IntoAxis};
    pub use super::error::{ShapeError, ShapeResult};
    pub use super::layout::Layout;
    pub use super::rank::{IntoRank, Rank};
    pub use super::shape::Shape;
    pub use super::stride::{IntoStride, Stride};
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_shape() {
        let mut shape = Shape::default();
        shape.extend([1, 1, 1]);
        assert_eq!(shape, Shape::new(vec![1, 1, 1]));
        assert_eq!(shape.size(), 1);
        assert_eq!(*shape.rank(), 3);
    }
}