-
Couldn't load subscription status.
- Fork 58
-
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(>(&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);
}
Beta Was this translation helpful? Give feedback.
All reactions
@9prady9,
implementing af_clone_indexer in rust will definitely be a better alternative.
Replies: 2 comments 1 reply
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@9prady9,
implementing af_clone_indexer in rust will definitely be a better alternative.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.