Indexing issue

43 views
Skip to first unread message

Dhia Slama

unread,
Oct 23, 2021, 8:11:54 PM10/23/21
to ArrayFire Users
Hi, 

I have an issue converting loops in c++ code into vectorized arrayfire arrays : 
for (int k = 0; k < Max1-1; k++)
{
for (int j = 1; j < Max2- 1; j++)
{
for (int i = 1; i < Max3- 1; i++)
{
Tab[i][j][k+ 1] =  Tab  [i][j][k] + K1 * ( Tab  [i- 1][j][k] +  Tab  [i+ 1][j][k] - 4 *  Tab  [i][j][k] +  Tab  [i][j- 1][k] +  Tab[i][j+ 1][k]); 
}
}
}
Converting the code above to arrayfire : 
af::array  Tab_array  = af::constant(0, Max3, Max2, Max1, type::TYPE_AF<T>());
For (int k = 0; k < Max1-1; k++) 
{
Tab_array(span,span,k+1) =   Tab_array(span,span,k)   + K1 * (  Tab_array(????,span,k)   +   Tab_array(?????,span,k)   - 4 *   Tab_array(span,span,k)   +   Tab_array(span,??????,k)   +   Tab_array(span,?????,k)  ); 
}

So the issue here is that I am not able to define i-1 or i+1 using arrayfire. 
Using numpy + python : the solution can be like that : 
Tab_array[2:, 1:-1]  +  Tab_array[:-2, 1:-1]- 4* Tab_array[1:-1, 1:-1] .....

Any solutions for this type of indexing problem ? 

Thanks!
Dhia
Reply all
Reply to author
Forward
0 new messages