Skip to content

Commit 1ff2e45

Browse files
committed
order: Add enum Order
1 parent 702de70 commit 1ff2e45

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub use crate::dimension::IxDynImpl;
145145
pub use crate::dimension::NdIndex;
146146
pub use crate::error::{ErrorKind, ShapeError};
147147
pub use crate::indexes::{indices, indices_of};
148+
pub use crate::order::Order;
148149
pub use crate::slice::{
149150
MultiSliceArg, NewAxis, Slice, SliceArg, SliceInfo, SliceInfoElem, SliceNextDim,
150151
};
@@ -202,6 +203,7 @@ mod linspace;
202203
mod logspace;
203204
mod math_cell;
204205
mod numeric_util;
206+
mod order;
205207
mod partial;
206208
mod shape_builder;
207209
#[macro_use]

src/order.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
/// Array order
3+
///
4+
/// Order refers to indexing order, or how a linear sequence is translated
5+
/// into a two-dimensional or multi-dimensional array.
6+
///
7+
/// - `RowMajor` means that the index along the row is the most rapidly changing
8+
/// - `ColumnMajor` means that the index along the column is the most rapidly changing
9+
///
10+
/// Given a sequence like: 1, 2, 3, 4, 5, 6
11+
///
12+
/// If it is laid it out in a 2 x 3 matrix using row major ordering, it results in:
13+
///
14+
/// ```text
15+
/// 1 2 3
16+
/// 4 5 6
17+
/// ```
18+
///
19+
/// If it is laid using column major ordering, it results in:
20+
///
21+
/// ```text
22+
/// 1 3 5
23+
/// 2 4 6
24+
/// ```
25+
///
26+
/// It can be seen as filling in "rows first" or "columns first".
27+
///
28+
/// `Order` can be used both to refer to logical ordering as well as memory ordering or memory
29+
/// layout. The orderings have common short names, also seen in other environments, where
30+
/// row major is called "C" order (after the C programming language) and column major is called "F"
31+
/// or "Fortran" order.
32+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
33+
#[non_exhaustive]
34+
pub enum Order {
35+
/// Row major or "C" order
36+
RowMajor,
37+
/// Column major or "F" order
38+
ColumnMajor,
39+
}
40+
41+
impl Order {
42+
/// "C" is an alias for row major ordering
43+
pub const C: Order = Order::RowMajor;
44+
45+
/// "F" (for Fortran) is an alias for column major ordering
46+
pub const F: Order = Order::ColumnMajor;
47+
}

0 commit comments

Comments
 (0)