-
How to do a[a>0]-=1 in rust version? |
Beta Was this translation helpful? Give feedback.
Answered by
9prady9
Sep 11, 2022
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.
3 replies
Answer selected by
3togo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One way would be the following:
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.