indexing inside gfor

19 views
Skip to first unread message

Avinash Rangarajan

unread,
Jun 12, 2021, 3:30:44 AMJun 12
to ArrayFire Users
I am trying to subtract column 2 with column 1 inside a gfor loop.

auto col_len = a_input.dims(1);
auto row_len = a_input.dims(1);

af::array r(row_len, col_len - 1, c32);
gfor(af::seq k, col_len - 1)
{
r(af::span, k) = a_input(af::span, k + 1) - a_input(af::span, k);
}

Its not compiling in visual studio

The error "More than one operator + matches this operands
function af::operator +
function af::seq::operator +


uma...@gmail.com

unread,
Jun 16, 2021, 2:29:53 PMJun 16
to ArrayFire Users
That is a strange error. It should be able to resolve that symbol. I can look into it.

I think this is the same operation as diff. Take a look at that function. I think that will be faster than this approach.

Umar

Avinash Rangarajan

unread,
Jun 17, 2021, 8:13:40 AMJun 17
to ArrayFire Users
I could see only diff1 and diff2 functions. 

Further, inside a gfor for an  dimensional array, i like to perform compare operation, each element pointed by index of gfor, compare with set of elements in that array and if greater than threshold update with 1 else 0

#if 1
af::array t_range(af::array t_output, uint16_t t_cell, uint16_t t_cells, float th) {
af::array t_input = flat(t_output);
af::array t_output(t_input.dims(0));
auto row = t_input.dims(0);
auto total = (t_cells + t_cell);
af::timer start1 = af::timer::start();

gfor(af::seq k, total, row - (total + 1)) {
t_output(k) = t_input(k) - (th + (af::sum(t_input(af::seq(k.operator-(total).s.begin, k.operator-(t_cell + 1).s.begin))) +
af::sum(t_input(af::seq(k.operator+(t_cell + 1).s.begin, k.operator+(total).s.begin)))) / 2);
}

af::dim4 new_dims(7, 4);
t_output = af::moddims(t_output, new_dims);
printf("elapsed time: %g ms\n", af::timer::stop(start1) * 1000);
return t_output;
}
#endif
t_input(af::seq(k.operator-(total).s.begin - this portion of code is written to index k+1 bcoz direct indexing k+1 is giving error (operator overload error)

Regards
R Avinash
Reply all
Reply to author
Forward
0 new messages