Function reverse_matrix_index_bits

Source
pub fn reverse_matrix_index_bits<'a, F, S>(mat: &mut DenseMatrix<F, S>)
where F: Clone + Send + Sync + 'a, S: DenseStorage<F> + BorrowMut<[F]>,
Expand description

Reverse the order of matrix rows based on the bit-reversal of their indices.

Given a matrix mat of height h = 2^k, this function rearranges its rows by reversing the binary representation of each row index. For example, if h = 8 (i.e., 3 bits):

Original Index  Binary   Reversed   Target Index
--------------  -------  ---------  -------------
     0          000      000        0
     1          001      100        4
     2          010      010        2
     3          011      110        6
     4          100      001        1
     5          101      101        5
     6          110      011        3
     7          111      111        7

The transformation is performed in-place.

§Panics

Panics if the height of the matrix is not a power of two.

§Arguments

  • mat: The matrix whose rows should be reordered.