/rust/registry/src/index.crates.io-1949cf8c6b5b557f/ndarray-0.16.1/src/split_at.rs
Line | Count | Source |
1 | | use crate::imp_prelude::*; |
2 | | |
3 | | /// Arrays and similar that can be split along an axis |
4 | | pub(crate) trait SplitAt |
5 | | { |
6 | | fn split_at(self, axis: Axis, index: usize) -> (Self, Self) |
7 | | where Self: Sized; |
8 | | } |
9 | | |
10 | | pub(crate) trait SplitPreference: SplitAt |
11 | | { |
12 | | #[allow(dead_code)] // used only when Rayon support is enabled |
13 | | fn can_split(&self) -> bool; |
14 | | fn split_preference(&self) -> (Axis, usize); |
15 | 0 | fn split(self) -> (Self, Self) |
16 | 0 | where Self: Sized |
17 | | { |
18 | 0 | let (axis, index) = self.split_preference(); |
19 | 0 | self.split_at(axis, index) |
20 | 0 | } |
21 | | } |
22 | | |
23 | | impl<D> SplitAt for D |
24 | | where D: Dimension |
25 | | { |
26 | 0 | fn split_at(self, axis: Axis, index: Ix) -> (Self, Self) |
27 | | { |
28 | 0 | let mut d1 = self; |
29 | 0 | let mut d2 = d1.clone(); |
30 | 0 | let i = axis.index(); |
31 | 0 | let len = d1[i]; |
32 | 0 | d1[i] = index; |
33 | 0 | d2[i] = len - index; |
34 | 0 | (d1, d2) |
35 | 0 | } |
36 | | } |
37 | | |
38 | | impl<'a, A, D> SplitAt for ArrayViewMut<'a, A, D> |
39 | | where D: Dimension |
40 | | { |
41 | 0 | fn split_at(self, axis: Axis, index: usize) -> (Self, Self) |
42 | | { |
43 | 0 | self.split_at(axis, index) |
44 | 0 | } |
45 | | } |
46 | | |
47 | | impl<A, D> SplitAt for RawArrayViewMut<A, D> |
48 | | where D: Dimension |
49 | | { |
50 | 0 | fn split_at(self, axis: Axis, index: usize) -> (Self, Self) |
51 | | { |
52 | 0 | self.split_at(axis, index) |
53 | 0 | } |
54 | | } |