-
Couldn't load subscription status.
- Fork 58
-
How to do a[a>0]-=1 in rust version?
Beta Was this translation helpful? Give feedback.
All reactions
One way would be the following:
let non_negs = a > 0; let res = non_negs * (a - 1) + (1 - non_negs) * a;
Indexing functions like lookup and eval macro can also be used I think but I believe the above version is better in terms of performance because there is no random lookup involved and all reads/writes to GPU memory are coalesced.
Replies: 1 comment 3 replies
-
One way would be the following:
let non_negs = a > 0; let res = non_negs * (a - 1) + (1 - non_negs) * a;
Indexing functions like lookup and eval macro can also be used I think but I believe the above version is better in terms of performance because there is no random lookup involved and all reads/writes to GPU memory are coalesced.
Beta Was this translation helpful? Give feedback.
All reactions
-
I try to implement your suggested answer as follow:
let non_negs = gt(&a, &(0.0 as f32), false);
let a = &non_negs * (&a - 1.0 as f32) + (1 - &non_negs) * &a ;
However, I need to use "gt" instead of ">"
If I use ">", the compiler will complain that ">" cannot be applied to type '&arrayfire::Array<f32>' rustc(E0369)
let non_negs = &a > 0.0 as f32;
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, the operator isn't implemented for default move semantics of rust, it accepts only a reference object.
Is this let non_negs = &a > 0.0 as f32; snippet also not working ?
Beta Was this translation helpful? Give feedback.
All reactions
-
Never mind, my mistake - it has been a while I touched this section of rust wrapper. Rust doesn't have operator trait for comparison - not in the way arrayfire comparison results are reported. Hence that code doesn't work. Please use gt function.
Beta Was this translation helpful? Give feedback.