Struct arrayfire::Indexer [] [src]

pub struct Indexer<'object> { /* fields omitted */ }

Struct to manage an array of resources of type af_indexer_t(ArrayFire C struct)

# Examples

Given below are examples illustrating correct and incorrect usage of Indexer struct.

Correct Usage

use arrayfire::{Array, Dim4, randu, index_gen, Indexer};

 // Always be aware of the fact that, the `Seq` or `Array` objects
 // that we intend to use for indexing via `Indexer` have to outlive
 // the `Indexer` object created in this context.

 let dims    = Dim4::new(&[1, 3, 1, 1]);
 let indices = [1u8, 0, 1];
 let idx     = Array::new(&indices, dims);
 let values  = [2.0f32, 5.0, 6.0];
 let arr     = Array::new(&values, dims);

 let mut idxr = Indexer::new();

 // `idx` is created much before idxr, thus will
 // stay in scope at least as long as idxr
 idxr.set_index(&idx, 0, None);

 index_gen(&arr, idxr);

Incorrect Usage

// Say, you create an Array on the fly and try
 // to call set_index, it will throw the given below
 // error or something similar to that
 idxr.set_index(&Array::new(&[1, 0, 1], dims), 0, None);
 error: borrowed value does not live long enough
   --> <anon>:16:55
   |
16 | idxr.set_index(&Array::new(&[1, 0, 1], dims), 0, None);
   |                 ----------------------------          ^ temporary value dropped here while still borrowed
   |                 |
   |                 temporary value created here
...
19 | }
   | - temporary value needs to live until here
   |
   = note: consider using a `let` binding to increase its lifetime

Methods

impl<'object> Indexer<'object>
[src]

Create a new Indexer object and set the dimension specific index objects later

Set either Array or Seq to index an Array along idx dimension

Get number of indexing objects set

Get native(ArrayFire) resource handle

Trait Implementations

impl<'object> Drop for Indexer<'object>
[src]

A method called when the value goes out of scope. Read more