question about conditional statements

I wrote a little code to flip the dimensions of a matrix. It compiled and ran but the values were not changed.
After playing around with it for a little bit, I found that using “if (b_idx<N && a_idx<N)” or “if (b_idx<N)” instead of “if (a_idx<N)” worked.

Can anybody explain why this would happen?

Code that didn’t work:

global void shiftDimOnDevice_float(float *a, float *b, int N, int width, int height)
{
int row = blockIdx.y * blockDim.y + threadIdx.y;
int col = blockIdx.x * blockDim.x + threadIdx.x;

int a_idx = rowwidth + col;
int b_idx = col
height+row;

if (a_idx<N) {
b[b_idx] = a[a_idx];
}
}

I am embarrassed to say I once wrote code to swap data in a 1D array was something like this
for ( int ii = 0; ii < N; ii++) { A[ii] = A[N-ii] }

unfortunantly that resulted in the following elements being changed
A[0] = A[N-1]

A[N-1] = A[0] // Eeek this returned the data to where it came from :wallbash:

Maybe something like that is happening in your code