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

Replace for loops by functional approach #26

Closed
blegat opened this issue Dec 15, 2019 · 4 comments
Closed

Replace for loops by functional approach #26

blegat opened this issue Dec 15, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@blegat
Copy link
Member

blegat commented Dec 15, 2019

Using for loops for generators may create type instabilities, see https://discourse.julialang.org/t/multiplying-by-a-variable-in-a-constraint-causing-type-instability-in-code-warntype/32239 and forces us to create local scopes with let in the macro.
We could switch to a functional approach similarly to jump-dev/JuMP.jl#2070

Moreover, we currently we rewrite sum(... for i in ... but we don't rewrite sum(i -> ..., ...).

@odow odow added the enhancement New feature or request label Jan 14, 2021
@odow
Copy link
Member

odow commented Feb 7, 2022

There doesn't seem to be much appetite for this. I haven't seen any issues relating to it since 2019. Can we close?

@odow
Copy link
Member

odow commented Nov 15, 2022

The new rewrite #170 adds support for sum(generator; init), but it doesn't add support for the two-argument sum(f, x). I think automatically rewriting that gets a little risky, because we don't know that:

sum(f, x; init) === sum(f(x) for a in x; init = init)

(It might depend on the types, although it'd be pretty poor form to change the semantics of sum like that.)

I also don't see how we would use functions instead of the loop, because in the functional case we wouldn't be able to rewrite in-place?

@odow
Copy link
Member

odow commented Nov 17, 2022

Closing this as won't-fix. The loops are okay.

@odow odow closed this as completed Nov 17, 2022
@blegat
Copy link
Member Author

blegat commented Nov 21, 2022

I also don't see how we would use functions instead of the loop, because in the functional case we wouldn't be able to rewrite in-place?

I don't see why but the functional approach might allocate because of closure so it might be best to stay with for-loops until closures are faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants