Skip to content

Commit 3c94155

Browse files
add comments from doc, to describe how the locig works
1 parent 12878c6 commit 3c94155

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

src/impl_methods.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,37 +2549,6 @@ where
25492549
/// **Panics** if any of the axes are out of bounds, if an axis is missing,
25502550
/// or if an axis is repeated more than once.
25512551
///
2552-
/// # About the Cycle Detection
2553-
///
2554-
/// The cycle detection is done using a bitmask to track visited positions.
2555-
///
2556-
/// For example, axes from \[0,1,2\] to \[2, 0, 1\]
2557-
/// For axis values \[1, 0, 2\]:
2558-
/// 1 << 1 // 0b0001 << 1 = 0b0010 (decimal 2)
2559-
/// 1 << 0 // 0b0001 << 0 = 0b0001 (decimal 1)
2560-
/// 1 << 2 // 0b0001 << 2 = 0b0100 (decimal 4)
2561-
///
2562-
/// Each axis gets its own unique bit position in the bitmask:
2563-
/// - Axis 0: bit 0 (rightmost)
2564-
/// - Axis 1: bit 1
2565-
/// - Axis 2: bit 2
2566-
///
2567-
/// The check `(visited & (1 << axis)) != 0` works as follows:
2568-
/// ```no_run
2569-
/// let mut visited = 0; // 0b0000
2570-
/// let axis = 1;
2571-
/// let new_axis = 0;
2572-
/// // Check axis 1
2573-
/// if (visited & (1 << axis)) != 0 { // 0b0000 & 0b0010 = 0b0000
2574-
/// // Not visited yet
2575-
/// }
2576-
/// // Mark axis 1 as visited
2577-
/// visited |= (1 << axis) | (1 << new_axis); // 0b0000 | 0b0010 | 0b0001 = 0b0011
2578-
/// if (visited & (1 << 1)) != 0 { // 0b0011 & 0b0010 = 0b0010
2579-
/// // Already visited!
2580-
/// }
2581-
/// ```
2582-
///
25832552
/// # Example
25842553
/// ```rust
25852554
/// use ndarray::{arr2, Array3};
@@ -2610,6 +2579,18 @@ where
26102579
let strides = self.layout.strides.slice_mut();
26112580
let axes = axes.slice();
26122581

2582+
// The cycle detection is done using a bitmask to track visited positions.
2583+
// For example, axes from [0,1,2] to [2, 0, 1]
2584+
// For axis values [1, 0, 2]:
2585+
// 1 << 1 // 0b0001 << 1 = 0b0010 (decimal 2)
2586+
// 1 << 0 // 0b0001 << 0 = 0b0001 (decimal 1)
2587+
// 1 << 2 // 0b0001 << 2 = 0b0100 (decimal 4)
2588+
//
2589+
// Each axis gets its own unique bit position in the bitmask:
2590+
// - Axis 0: bit 0 (rightmost)
2591+
// - Axis 1: bit 1
2592+
// - Axis 2: bit 2
2593+
//
26132594
let mut visited = 0usize;
26142595
for (new_axis, &axis) in axes.iter().enumerate() {
26152596
if (visited & (1 << axis)) != 0 {

0 commit comments

Comments
 (0)