Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfilter with multiple conditions #509

Closed
alfaromartino opened this issue Sep 22, 2023 · 2 comments
Closed

vfilter with multiple conditions #509

alfaromartino opened this issue Sep 22, 2023 · 2 comments

Comments

@alfaromartino
Copy link

It seems that vfilter, vmap, etc can't handle multiple conditions?

x       = rand(10)
cond(a) = ((a > 0.25) && (a < 0.75))

vfilter(cond,x) # ERROR: TypeError: non-boolean (VectorizationBase.Mask{4, UInt8}) used in boolean context
filter(cond,x)  # this works

vmap(cond,x)    # ERROR: TypeError: non-boolean (VectorizationBase.Mask{4, UInt8}) used in boolean context
map(cond,x)     # this works

Thanks

@chriselrod
Copy link
Member

Use & and | rather than && and ||.

@chriselrod
Copy link
Member

Let me know if you have any further issues.
Unfortunately, supporting && and || is not possible without compiler magic.
LoopModels, the eventual successor to LoopVectorization.jl, will support those.

But LoopVectorization.jl is implemented largely using multiple dispatch, and it is not possible to overload && and || as these are syntax, not functions.

As a word of caution, note that & and | don't have the same precedence as && and ||, so you'll have to be sure and add parenthesis whenever using them, like you did in your example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants