concision_core/traits/arr/
reshape.rs

1/*
2    Appellation: reshape <module> [traits::arr]
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use nd::prelude::*;
6use nd::{RawData, RawDataClone};
7
8pub trait Unsqueeze {
9    type Output;
10
11    fn unsqueeze(self, axis: usize) -> Self::Output;
12}
13
14/*
15 ************* Implementations *************
16*/
17
18impl<A, S, D> Unsqueeze for ArrayBase<S, D>
19where
20    D: Dimension,
21    S: RawData<Elem = A>,
22{
23    type Output = ArrayBase<S, D::Larger>;
24
25    fn unsqueeze(self, axis: usize) -> Self::Output {
26        self.insert_axis(Axis(axis))
27    }
28}
29
30impl<'a, A, S, D> Unsqueeze for &'a ArrayBase<S, D>
31where
32    D: Dimension,
33    S: RawDataClone<Elem = A>,
34{
35    type Output = ArrayBase<S, D::Larger>;
36
37    fn unsqueeze(self, axis: usize) -> Self::Output {
38        self.clone().insert_axis(Axis(axis))
39    }
40}