Struct Indexer

Source
pub struct Indexer<'object> { /* private fields */ }
Expand description

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.

§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::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

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

Implementations§

Source§

impl<'object> Indexer<'object>

Source

pub fn new() -> Self

👎Deprecated since 3.7.0: Use Indexer::default() instead

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

Source

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

Source

pub fn len(&self) -> usize

Get number of indexing objects set

Source

pub fn is_empty(&self) -> bool

Check if any indexing objects are set

Source

pub unsafe fn get(&self) -> af_index_t

Get native(ArrayFire) resource handle

Trait Implementations§

Source§

impl<'object> Default for Indexer<'object>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'object> Drop for Indexer<'object>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'object> Send for Indexer<'object>

Auto Trait Implementations§

§

impl<'object> Freeze for Indexer<'object>

§

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§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.