[][src]Struct arrayfire::Indexer

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

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

Sharing Across Threads

While sharing an Indexer object with other threads, just move it across threads. At the moment, one cannot share borrowed references across threads.


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::default();

// `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

This example is not tested
// 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


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

pub fn new() -> Self[src]

👎 Deprecated since 3.7.0:

Use Indexer::default() instead

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

pub fn set_index<'s, T>(
    &'s mut self,
    idx: &'object T,
    dim: u32,
    is_batch: Option<bool>
) where
    T: Indexable + 'object, 

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

pub fn len(&self) -> usize[src]

Get number of indexing objects set

pub fn is_empty(&self) -> bool[src]

Check if any indexing objects are set

pub unsafe fn get(&self) -> af_index_t[src]

Get native(ArrayFire) resource handle

Trait Implementations

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

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

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

Auto Trait Implementations

impl<'object> RefUnwindSafe for Indexer<'object>

impl<'object> !Sync for Indexer<'object>

impl<'object> Unpin for Indexer<'object>

impl<'object> UnwindSafe for Indexer<'object>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.