[−][src]Struct arrayfire::Indexer
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
ⓘ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
Methods
impl<'object> Indexer<'object>
[src]
pub fn new() -> Self
[src]
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,
[src]
&'s mut self,
idx: &'object T,
dim: u32,
is_batch: Option<bool>
) where
T: Indexable + 'object,
pub fn len(&self) -> usize
[src]
Get number of indexing objects set
pub fn get(&self) -> i64
[src]
Get native(ArrayFire) resource handle
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,