I have a very big array with dimensions (nr,nc) row and cols. I iterate over this array to calculate the function "fun" from a constant entry of this array (px,py). The calculation for this function is only relevant in a constant area (distance d) around this point. So my goal is to speed up the code and only calculate in this circle around the point (px,py).
int i;
int j;
for(i=0; i<nr; i++){
for(j=0; j<nc; j++){
*(arr_stg+i*nc+j) = fun(i,j,px,py);
}
}
I also have a function to calculate a boolean "mask" (I don't know if that's the right word for this). I calculate it with the euclidean distance around a sample point. So for a given distance, i.e. 4 I calculate this kind of mask-array:
0 0 0 0 1 0 0 0 0
0 0 0 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 0 0
0 0 0 1 1 1 0 0 0
0 0 0 0 1 0 0 0 0
The exact form (if it's a zero or a one) is not relevant here, should be working for any kind of this nxn-"masks".
My question is, how do I have to change the two for loops to iterate only over this mask around the given point in a way that I get a faster code then just calculate it for all i,j's of the big array and don't use the ones with a distance greater than the given one.
if(mask[i][j]) *(arr_stg+i*nc+j) = fun(i,j,px,py);arr_stgdefinition ?nc?px?py?iterate only over this mask- in what way or does it doesn't matter which point is the first?