A high-performance general-purpose compute library

Lookup values of an array based on sequences and/or arrays. More...

Functions

AFAPI void copy (array &dst, const array &src, const index &idx0, const index &idx1=span, const index &idx2=span, const index &idx3=span)
 Copy the values of an input array based on index. More...
 
AFAPI af_err af_index (af_array *out, const af_array in, const unsigned ndims, const af_seq *const index)
 Lookup the values of input array based on sequences. More...
 
AFAPI af_err af_index_gen (af_array *out, const af_array in, const dim_t ndims, const af_index_t *indices)
 Indexing an array using af_seq, or af_array. More...
 
AFAPI af_err af_create_indexers (af_index_t **indexers)
 Create an quadruple of af_index_t array. More...
 
AFAPI af_err af_set_array_indexer (af_index_t *indexer, const af_array idx, const dim_t dim)
 set dim to given indexer af_array idx More...
 
AFAPI af_err af_set_seq_indexer (af_index_t *indexer, const af_seq *idx, const dim_t dim, const bool is_batch)
 set dim to given indexer af_array idx More...
 
AFAPI af_err af_set_seq_param_indexer (af_index_t *indexer, const double begin, const double end, const double step, const dim_t dim, const bool is_batch)
 set dim to given indexer af_array idx More...
 
AFAPI af_err af_release_indexers (af_index_t *indexers)
 Release's the memory resource used by the quadruple af_index_t array. More...
 

Detailed Description

Lookup values of an array based on sequences and/or arrays.


Function Documentation

◆ af_create_indexers()

AFAPI af_err af_create_indexers ( af_index_t **  indexers)

Create an quadruple of af_index_t array.

af_index_t *indexers = 0;
af_err err = af_create_indexers(&indexers); // Memory is allocated on heap by the callee
// by default all the indexers span all the elements along
// the given dimension
// Create array
unsigned ndims = 2;
dim_t dim[] = {10, 10};
af_randu(&a, ndims, dim, f32);
// Create index array
af_array idx;
unsigned n = 1;
dim_t d[] = {5};
af_range(&idx, n, d, 0, s32);
// create array indexer
err = af_set_array_indexer(indexers, idx, 1);
// index with indexers
af_array out;
err = af_index_gen(&out, a, 2, indexers); // number of indexers should be two since
// we have set only second af_index_t
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
af_seq zeroIndices = af_make_seq(0.0, 9.0, 2.0);
err = af_set_seq_indexer(indexers, &zeroIndices, 0, false);
err = af_index_gen(&out, a, 2, indexers);
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
return 0;
@ s32
32-bit signed integral values
Definition: defines.h:216
@ f32
32-bit floating point values
Definition: defines.h:211
long long dim_t
Definition: defines.h:56
af_err
Definition: defines.h:71
@ AF_SUCCESS
The function returned successfully.
Definition: defines.h:75
void * af_array
Definition: defines.h:240
AFAPI af_err af_release_array(af_array arr)
Reduce the reference count of the af_array.
AFAPI af_err af_range(af_array *out, const unsigned ndims, const dim_t *const dims, const int seq_dim, const af_dtype type)
C Interface to generate an array with [0, n-1] values along the seq_dim dimension and tiled across ot...
AFAPI af_err af_index_gen(af_array *out, const af_array in, const dim_t ndims, const af_index_t *indices)
Indexing an array using af_seq, or af_array.
AFAPI af_err af_create_indexers(af_index_t **indexers)
Create an quadruple of af_index_t array.
AFAPI af_err af_release_indexers(af_index_t *indexers)
Release's the memory resource used by the quadruple af_index_t array.
AFAPI af_err af_set_array_indexer(af_index_t *indexer, const af_array idx, const dim_t dim)
set dim to given indexer af_array idx
AFAPI af_err af_set_seq_indexer(af_index_t *indexer, const af_seq *idx, const dim_t dim, const bool is_batch)
set dim to given indexer af_array idx
AFAPI af_err af_print_array(af_array arr)
AFAPI af_err af_randu(af_array *out, const unsigned ndims, const dim_t *const dims, const af_dtype type)
AFAPI af_seq af_make_seq(double begin, double end, double step)
Create a new af_seq object.
Struct used to index an af_array.
Definition: index.h:22
C-style struct to creating sequences for indexing.
Definition: seq.h:20
Parameters
[out]indexerspointer to location where quadruple af_index_t array is created
Returns
af_err error code

◆ af_index()

AFAPI af_err af_index ( af_array out,
const af_array  in,
const unsigned  ndims,
const af_seq *const  index 
)

Lookup the values of input array based on sequences.

Parameters
[out]outoutput array containing values indexed by the sequences
[in]inis the input array
[in]ndimsis the number of sequences provided
[in]indexis an array of sequences

◆ af_index_gen()

AFAPI af_err af_index_gen ( af_array out,
const af_array  in,
const dim_t  ndims,
const af_index_t indices 
)

Indexing an array using af_seq, or af_array.

Generalized indexing function that accepts either af_array or af_seq along a dimension to index the input array and create the corresponding output array

Parameters
[out]outoutput array containing values at indexed by the sequences
[in]inis the input array
[in]ndimsis the number of af_index_t provided
[in]indicesis an array of af_index_t objects

◆ af_release_indexers()

AFAPI af_err af_release_indexers ( af_index_t indexers)

Release's the memory resource used by the quadruple af_index_t array.

af_index_t *indexers = 0;
af_err err = af_create_indexers(&indexers); // Memory is allocated on heap by the callee
// by default all the indexers span all the elements along
// the given dimension
// Create array
unsigned ndims = 2;
dim_t dim[] = {10, 10};
af_randu(&a, ndims, dim, f32);
// Create index array
af_array idx;
unsigned n = 1;
dim_t d[] = {5};
af_range(&idx, n, d, 0, s32);
// create array indexer
err = af_set_array_indexer(indexers, idx, 1);
// index with indexers
af_array out;
err = af_index_gen(&out, a, 2, indexers); // number of indexers should be two since
// we have set only second af_index_t
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
af_seq zeroIndices = af_make_seq(0.0, 9.0, 2.0);
err = af_set_seq_indexer(indexers, &zeroIndices, 0, false);
err = af_index_gen(&out, a, 2, indexers);
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
return 0;
Parameters
[in]indexersis pointer to location where quadruple af_index_t array is created

◆ af_set_array_indexer()

AFAPI af_err af_set_array_indexer ( af_index_t indexer,
const af_array  idx,
const dim_t  dim 
)

set dim to given indexer af_array idx

af_index_t *indexers = 0;
af_err err = af_create_indexers(&indexers); // Memory is allocated on heap by the callee
// by default all the indexers span all the elements along
// the given dimension
// Create array
unsigned ndims = 2;
dim_t dim[] = {10, 10};
af_randu(&a, ndims, dim, f32);
// Create index array
af_array idx;
unsigned n = 1;
dim_t d[] = {5};
af_range(&idx, n, d, 0, s32);
// create array indexer
err = af_set_array_indexer(indexers, idx, 1);
// index with indexers
af_array out;
err = af_index_gen(&out, a, 2, indexers); // number of indexers should be two since
// we have set only second af_index_t
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
af_seq zeroIndices = af_make_seq(0.0, 9.0, 2.0);
err = af_set_seq_indexer(indexers, &zeroIndices, 0, false);
err = af_index_gen(&out, a, 2, indexers);
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
return 0;
Parameters
[in]indexerpointer to location where quadruple af_index_t array was created
[in]idxis the af_array indexer for given dimension dim
[in]dimis the dimension to be indexed
Returns
af_err error code

◆ af_set_seq_indexer()

AFAPI af_err af_set_seq_indexer ( af_index_t indexer,
const af_seq idx,
const dim_t  dim,
const bool  is_batch 
)

set dim to given indexer af_array idx

This function is similar to af_set_array_indexer in terms of functionality except that this version accepts object of type af_seq instead of af_array.

af_index_t *indexers = 0;
af_err err = af_create_indexers(&indexers); // Memory is allocated on heap by the callee
// by default all the indexers span all the elements along
// the given dimension
// Create array
unsigned ndims = 2;
dim_t dim[] = {10, 10};
af_randu(&a, ndims, dim, f32);
// Create index array
af_array idx;
unsigned n = 1;
dim_t d[] = {5};
af_range(&idx, n, d, 0, s32);
// create array indexer
err = af_set_array_indexer(indexers, idx, 1);
// index with indexers
af_array out;
err = af_index_gen(&out, a, 2, indexers); // number of indexers should be two since
// we have set only second af_index_t
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
af_seq zeroIndices = af_make_seq(0.0, 9.0, 2.0);
err = af_set_seq_indexer(indexers, &zeroIndices, 0, false);
err = af_index_gen(&out, a, 2, indexers);
if (err != AF_SUCCESS) {
printf("Failed in af_index_gen: %d\n", err);
return 1;
}
return 0;
Parameters
[in]indexerpointer to location where quadruple af_index_t array was created
[in]idxis the af_seq indexer for given dimension dim
[in]dimis the dimension to be indexed
[in]is_batchindicates if the sequence based indexing is inside a batch operation

◆ af_set_seq_param_indexer()

AFAPI af_err af_set_seq_param_indexer ( af_index_t indexer,
const double  begin,
const double  end,
const double  step,
const dim_t  dim,
const bool  is_batch 
)

set dim to given indexer af_array idx

This function is alternative to af_set_seq_indexer where instead of passing in an already prepared af_seq object, you pass the arguments necessary for creating an af_seq directly.

Parameters
[in]indexerpointer to location where quadruple af_index_t array was created
[in]beginis the beginning index of along dimension dim
[in]endis the beginning index of along dimension dim
[in]stepsize along dimension dim
[in]dimis the dimension to be indexed
[in]is_batchindicates if the sequence based indexing is inside a batch operation
Returns
af_err error code

◆ copy()

AFAPI void copy ( array dst,
const array src,
const index idx0,
const index idx1 = span,
const index idx2 = span,
const index idx3 = span 
)

Copy the values of an input array based on index.

Parameters
[out]dstThe destination array
[in]srcThe source array
[in]idx0The first index
[in]idx1The second index (defaults to af::span)
[in]idx2The third index (defaults to af::span)
[in]idx3The fourth index (defaults to af::span)