I`m currently struggling to write efficient function which will follow simple rules.
Lets assume matrix (it always came sorted descending).
| 7 4 3 2 | # sums up to 16
| 3 2 1 0 | # sums up to 6
I want to clip values to certain number (let it be 5), but "rest" from clipping should propagate into columns to the right (these columns should be also clipped and so on). So having this in head, the result matrix should look like:
| 5 5 4 2 | # still sums up to 16, but values "moves" to the right
| 3 2 1 0 | # no value extends 5 do nothing happens
Algorithm isn't hard in terms in writing it with one loop (saving clipped values to buffer, distribute it in next column, and so on), which works well, but as I said, it would be ideal to make this using vectorization (and dismiss using any loop). I tried some cumsum + clip + diff solution, but nothing really works. Right now I`m stuck.
Thank you for any help.