Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to copy Indexer? #353

Answered by 3togo
3togo asked this question in Q&A
Oct 6, 2022 · 2 comments · 1 reply
Discussion options

Below is a simple script to do a[a>5.] /= 100.

Because index_gen will consume idxrs, I need to create and set_index to another identical indexers: idxrs2.
Is there any way to copy/clone/borrow idxrs instead of repeatedly doing set_index to idxrs2?

use arrayfire::*;
fn main() {
 println!("Hello, world!");
 let mut a = range::<f64>(dim4!(10), 0);
 let b = locate(&gt(&a, &constant(5., dim4!(1)), true));
 let mut idxrs = Indexer::default();
 let mut idxrs2 = Indexer::default();
 idxrs.set_index(&b, 0, None);
 idxrs2.set_index(&b, 0, None); // set_index again here
 let c = index_gen(&a, idxrs);
 let d = &c / 100.;
 let e = assign_gen(&mut a, &idxrs2, &d);
 af_print!("a", a);
 af_print!("b", b);
 af_print!("c", c);
 af_print!("d", d);
 println!("e={:#?}", e);
}
You must be logged in to vote

@9prady9,
implementing af_clone_indexer in rust will definitely be a better alternative.

Replies: 2 comments 1 reply

Comment options

Indexer is generic in a way because it stores handles to af_index_t which can point to a simple sequence as well as a reference counted handle to af_array. I think the right way to provide Clone feature to this object would be to add af_clone_indexer to arrayfire's C API and use that to implement clone trait in rust.

If it is the same set of objects being used to create the Indexer, is there something that prevents you in putting that inside a function and call that repeatedly ?

Note that these are quite light weight objects and they shouldn't ideally cause performance issues if they are copies - other than incrementing the reference count of any af_array objects being stored via af_index_t - this could increase your memory foot print though.

You must be logged in to vote
0 replies
Comment options

@9prady9,
implementing af_clone_indexer in rust will definitely be a better alternative.

You must be logged in to vote
1 reply
Comment options

It needs a feature request on upstream and then only we can add it here. Can you please raise a request in arrayfire.

About my other suggestion,

If it is the same set of objects being used to create the Indexer, is there something that prevents you in putting that inside a function and call that repeatedly ?

Have you given that a try ? the alternative solution will take some time to be available in rust wrapper.

Answer selected by 3togo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /