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

inline native Julia scalars encountered in f.(args...) AST #18202

Closed
wants to merge 1 commit into from

Conversation

stevengj
Copy link
Member

As an optimization, the "dot call" fusion does "inlining" of literal scalars, so that e.g. f.(x,3) turns into broadcast(x -> f(x,3), x) rather than broadcast(f, x, 3). This PR expands the range of scalars that are inlined to include Julia Number objects in the AST (and could do the same for String and some other types once #16966 is fixed … since it is just an optimization, it is okay if we aren't exhaustive).

(As was observed in #18176, the parser actually ends up converting things like floating-point literals into Julia objects in the AST, so without this optimization they aren't inlined.)

@stevengj stevengj added the broadcast Applying a function over a collection label Aug 23, 2016
@@ -288,6 +288,8 @@ let identity = error, x = [1,2,3]
x .= 1 # make sure it goes to broadcast!(Base.identity, ...), not identity
@test x == [1,1,1]
end
# See issue #18176:
@test ((a,b,c) -> a+b+c).(1.0:2, 3, 4) == ((a,b,c) -> a+b+c).(1.0:2, 3.0, 4.0) == [8,9]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is also tested in #18200, instead of this, a test of the resulting expression after parsing would be more useful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could check the result of expand.

@JeffBezanson
Copy link
Sponsor Member

👍 to this, but I think it would be simpler to add an flisp-callable predicate to test whether a julia_value is a Number instead of adding a new type.

@stevengj
Copy link
Member Author

@JeffBezanson, I don't think it would be shorter, but you're right that it may be cleaner. I'm working on an alternative PR.

@stevengj
Copy link
Member Author

stevengj commented Aug 23, 2016

Closing in favor of #18205, which adds a new julia-scalar? predicate in flisp. As I suspected, this actually requires more code, but is conceptually cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broadcast Applying a function over a collection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants