There are several ways of referencing values. ArrayFire uses parenthesis for subscripted referencing instead of the traditional square bracket notation. Indexing is zero-based, i.e. the first element is at index zero (A(0)
). Indexing can be done with mixtures of:
See Indexing for the full listing.
array A = array(seq(1,9), 3, 3);
float b_host[] = {0,1,2,3,4,5,6,7,8,9};
array b(10, 1, b_host);
#define af_print(...)
Definition util.h:141
You can set values in an array:
array A = constant(0, 3, 3);
A(span) = 4;
A.row(0) = -1;
A(seq(3)) = 3.1415;
array B = constant(1, 4, 4,
s32);
B.row(0) = randu(1, 4,
f32);
@ s32
32-bit signed integral values
Definition defines.h:201
@ f32
32-bit floating point values
Definition defines.h:196
Use one array to reference into another.
float h_inds[] = {0, 4, 2, 1};
array inds(1, 4, h_inds);
array B = randu(1, 4);
array c = B(inds);
B(inds) = -1;
B(inds) = constant(0, 4);