0
For example, if I have a array like
condition=[
[0,0,1,0,0],
[1,1,0,0,0],
[0,0,1,0,0],
[0,0,0,1,0],
[0,0,0,0,1]
]
then I want to get idx_x=[2, 0, 1, 2, 3, 4], idx_y = [0, 1, 1, 2, 3, 4]
I wrote an kernel which works wrongly;
__global__ void nonzero_kernel(const float* input, float* output,
const int iH, const int iW) {
const size_t gidx = blockIdx.x * blockDim.x + threadIdx.x;
if ( gidx >= iH*iW ) return;
if (input[gidx]==1.0f){
output[gidx] = (gidx)%iW;//x
output[gidx+iH*iW] = (gidx)/iW;//y
}
else{
output[gidx] = -1;//x
output[gidx+iH*iW] = -1;//y
}
}
as it returns dummy values(-1) like ;
[[[-1. -1. 2. -1. -1.]
[ 0. 1. -1. -1. -1.]
[-1. -1. 2. -1. -1.]
[-1. -1. -1. 3. -1.]
[-1. -1. -1. -1. 4.]]
[[-1. -1. 0. -1. -1.]
[ 1. 1. -1. -1. -1.]
[-1. -1. 2. -1. -1.]
[-1. -1. -1. 3. -1.]
[-1. -1. -1. -1. 4.]]]