Skip to content

Cannot index with booleans #34

@FilipeMaia

Description

@FilipeMaia
import arrayfire
a = arrayfire.randu(3)
b = arrayfire.constant(1,3,dtype=arrayfire.Dtype.b8)
a[b] = 1
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-4-64b55ef890aa> in <module>()
----> 1 a[b] = 1

/Users/filipe/Library/Python/2.7/lib/python/site-packages/arrayfire-3.0.0-py2.7.egg/arrayfire/array.pyc in __setitem__(self, key, val)
    908
    909         except RuntimeError as e:
--> 910             raise IndexError(str(e))
    911
    912     def to_ctype(self, row_major=False, return_shape=False):

IndexError: ('In function /Users/filipe/src/arrayfire/src/api/c/assign.cpp(272):\nInvalid argument at index 3\nExpected: (idxType!=b8 )\n', 202)

This works in C++, but not in C, that's why the error. I think it would be more user friendly if it worked also in C.

Here's the C++ example showing the issue in arrayfire:

#include <arrayfire.h>

int main(){
  af::array a = af::randu(3);
  af::array idx = af::constant(1,3,b8);
  af_print(a(idx));
  af_index_t c_idx;
  c_idx.idx.arr = idx.get();
  c_idx.isSeq = false;
  c_idx.isBatch = false;   
  af_array ret;
  af_err err = af_index_gen(&ret, a.get(), 1, &c_idx);
  char * str;
  dim_t strlen;
  af_get_last_error(&str, &strlen);
  printf("%s\n", str);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions