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

Support if #21

Open
tshort opened this issue Oct 8, 2013 · 7 comments
Open

Support if #21

tshort opened this issue Oct 8, 2013 · 7 comments

Comments

@tshort
Copy link
Contributor

tshort commented Oct 8, 2013

It would be nice to support the following along with other uses of if:

a = [1:10]
b = rand(10)
@devec c = a .< 4 ? b : -b
@tshort
Copy link
Contributor Author

tshort commented Oct 8, 2013

Just found blend (like R's ifelse).

@nalimilan
Copy link

blend is useful, but it would also be interesting to have a vectorized switch-like function that would allow testing more conditions if the first one fails. More generally, the possibility to construct complex if... else blocks would really be nice to solve JuliaData/DataFrames.jl#369.

@lindahua
Copy link
Owner

lindahua commented Oct 8, 2013

One of the design goal here is the compatibility with the Julia base, that is, even omitting the @devec macro, the expression should still work as expected (but possibly slower).

For example, when you write @devec r = a + b .* c, and when you remove @devec, r = a + b. * c still works. In this way, people can first ensure the correctness of the implementation and then add @devec to accelerate part of the codes.

But this is not the case for c = a .< 4 ? b : -b -- this expression is not a valid one in itself in Julia.

What about we introduce a new function blend, and allow writing c = blend(c .< 4, b, -b) and prepending it with @devec.

@lindahua
Copy link
Owner

lindahua commented Oct 8, 2013

Oh, I forgot I already included blend in the package.

@nalimilan
Copy link

How about having a .? operator that would work like blend, for similarity with vectorized operations like .*?

Regarding if... else vectorized blocks, this would indeed be incompatible with base Julia. Maybe we should find a way to make them work in base first, and only then try to devectorize them?

@lindahua
Copy link
Owner

lindahua commented Oct 8, 2013

Unfortunately, .? is not a valid symbol / expression in Julia. Julia will raise error when you write :(a .? b : c) -- this means that this can not pass the basic syntax check even before the macro works on it.

@lindahua
Copy link
Owner

lindahua commented Oct 8, 2013

But we can try to propose to allow .? in Julia first.

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

3 participants