Open PrometheusPi opened 4 years ago
Furthermore, the value is not yet added to the output array. (Currently it is set to zero.)
Unfortunately we can't use that implementation. The sort_array is a local array and it's size has to be a simple constant expression (doc). In that case negative indexing is not purposeful. Pls review my suggestion: https://github.com/ComputationalRadiationPhysics/stencil_filter_on_GPU/commit/4633214ae2de4b2f82acd2a6f317f8e27bd8e2a0
I think your current implementation does not run into this error. You could close this issue, it you want.
The current median implementation:
will not produce the correct result. As an example, please have a look at this code:
For an odd length array - the result is the center value, but your method selects to different array values:
For an even length array, you should compute the mean between the two array values around the center - but you select the larger value twice:
The misconception might arris from the fact that regular counting is c-like, but rrevese indexing starts with 1.
This can be precented by changing the negative indexed array value to
...[-half-1]
.This produces the correct result for both odd and even sized arrays.