Skip to content

Indexing an array using another array containing negative integers indexes wrong elements #2577

@ShadyBoukhary

Description

@ShadyBoukhary

In the following code, indexing array a with a(-1) and with another array that contains a -1 do not produce the same result. When indexing with a -1, the last element of the array is returned as expected. However, if the same array is indexed with another array containing a -1 the first element of the array is indexed.

Expected behavior

a(-1) should be equivalent to a(d)

Current behavior

a(d) indexes from the beginning of the array rather than the end as a(-1)

#include <arrayfire.h>

using namespace af;

int main() {
  info();

  array a = af::randu(5, 5, f32);
  int hc[] = {-1};
  array d(1, hc);
  af_print(a);
  af_print(a(-1));
  af_print(a(d));
}

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions