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>
impl<'object> Indexer<'object>
Sourcepub fn new() -> Self
👎Deprecated since 3.7.0: Use Indexer::default() instead
pub fn new() -> Self
Create a new Indexer object and set the dimension specific index objects later
Sourcepub fn set_index<'s, T>(
&'s mut self,
idx: &'object T,
dim: u32,
is_batch: Option<bool>,
)where
T: Indexable + 'object,
pub fn set_index<'s, T>(
&'s mut self,
idx: &'object T,
dim: u32,
is_batch: Option<bool>,
)where
T: Indexable + 'object,
Sourcepub unsafe fn get(&self) -> af_index_t
pub unsafe fn get(&self) -> af_index_t
Get native(ArrayFire) resource handle
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more