How would you transpose a binary matrix?

前端 未结 7 986
-上瘾入骨i
-上瘾入骨i 2020-12-16 02:13

I have binary matrices in C++ that I repesent with a vector of 8-bit values.

For example, the following matrix:

1 0 1 0 1 0 1
0 1 1 0 0 1 1
0 0 0 1 1         


        
7条回答
  •  感情败类
    2020-12-16 03:06

    I have added a new awnser instead of editing my original one to make this more visible (no comment rights unfortunatly).

    In your own awnser you add an additional requirement not present in the first one: It has to work on ARM Cortex-M

    I did come up with an alternative solution for ARM in my original awnser but omitted it as it was not part of the question and seemed off topic (mostly because of the C++ tag).

    ARM Specific solution Cortex-M:

    Some or most Cortex-M 3/4 have a bit banding region which can be used for exactly what you need, it expands bits into 32-bit fields, this region can be used to perform atomic bit operations.

    If you put your array in a bitbanded region it will have an 'exploded' mirror in the bitband region where you can just use move operations on the bits itself. If you make a loop the compiler will surely be able to unroll and optimize to just move operations.

    If you really want to, you can even setup a DMA controller to process an entire batch of transpose operations with a bit of effort and offload it entirely from the cpu :)

    Perhaps this might still help you.

提交回复
热议问题