/rust/registry/src/index.crates.io-1949cf8c6b5b557f/ndarray-0.17.2/src/dimension/axis.rs
Line | Count | Source |
1 | | // Copyright 2016 bluss and ndarray developers. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
4 | | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
5 | | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
6 | | // option. This file may not be copied, modified, or distributed |
7 | | // except according to those terms. |
8 | | |
9 | | /// An axis index. |
10 | | /// |
11 | | /// An axis one of an array’s “dimensions”; an *n*-dimensional array has *n* |
12 | | /// axes. Axis *0* is the array’s outermost axis and *n*-1 is the innermost. |
13 | | /// |
14 | | /// All array axis arguments use this type to make the code easier to write |
15 | | /// correctly and easier to understand. |
16 | | /// |
17 | | /// For example: in a method like `index_axis(axis, index)` the code becomes |
18 | | /// self-explanatory when it's called like `.index_axis(Axis(1), i)`; it's |
19 | | /// evident which integer is the axis number and which is the index. |
20 | | /// |
21 | | /// Note: This type does **not** implement From/Into usize and similar trait |
22 | | /// based conversions, because we want to preserve code readability and quality. |
23 | | /// |
24 | | /// `Axis(1)` in itself is a very clear code style and the style that should be |
25 | | /// avoided is code like `1.into()`. |
26 | | #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
27 | | pub struct Axis(pub usize); |
28 | | |
29 | | impl Axis |
30 | | { |
31 | | /// Return the index of the axis. |
32 | | #[inline(always)] |
33 | 0 | pub fn index(self) -> usize |
34 | | { |
35 | 0 | self.0 |
36 | 0 | } |
37 | | } |