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
//! Auxiliary routines ported from StridedViews.jl/src/auxiliary.jl
/// Compute the relative order of strides.
///
/// Returns a vector where `result[i]` is the rank of `strides[i]` among all non-zero strides.
/// Zero strides have order 1.
///
/// Returns an inline [`crate::AxisVec`]: the result does not allocate at rank
/// `<=` [`crate::INLINE_RANK`] and spills above it.
///
/// # Examples
///
/// ```
/// use strided_view::auxiliary::index_order;
///
/// let order = index_order(&[4, 1, 2]);
/// assert_eq!(order.as_slice(), &[3, 1, 2]);
/// ```
///
/// # Julia equivalent
/// ```julia
/// function indexorder(strides::NTuple{N,Int}) where {N}
/// return ntuple(Val(N)) do i
/// si = abs(strides[i])
/// si == 0 && return 1
/// k = 1
/// for s in strides
/// if s != 0 && abs(s) < si
/// k += 1
/// end
/// end
/// return k
/// end
/// end
/// ```