Skip to content

How to do a[a>0]-=1 in rust version? #347

Answered by 9prady9
3togo asked this question in Q&A
Discussion options

You must be logged in to vote

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

Comment options

You must be logged in to vote
3 replies
@3togo
Comment options

@9prady9
Comment options

@9prady9
Comment options

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