By using CUDA Thrust’s inclusive scan with a max operator, I’m able to fill missing values with the previous non-missing value (i.e. last non-missing value to the left).
But how to fill using next non-missing value (to the right)? Thus, for example, using 0 as my missing value marker:
Input: [0 1 0 0 4 0 6 0]
Fill missing from left: [0 1 1 1 4 4 6 6]
Fill missing from right: [0 1 4 4 4 6 6 6] <- want
(Note if the last element is missing then revert to filling final 0s from left.)
I’ve tried a inclusive scan in reverse, which yields [0 6 6 6 6 6 6 6] for max, not as desired.
Many thanks.
The reason
max()works on ascending values when scanning from left to right is that the current maximum value will always be higher than your0missing element, so it becomes the correct value for filling in the missing elements even though it has a “memory” coming all the way from the beginning.If you simply scan from right to left,
max()no longer works, because you then have a descending range.So, it seems like you need to use
rbegin()andrend()to scan from right to left and, in addition, use MAX_INT as your place-holder andmin()as your operator.Then, you need to fudge things for your special cases on the left and right.