-
Notifications
You must be signed in to change notification settings - Fork 9
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
Added support for broadcasted piping .|>. #16
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5be6d16
Added support for element-wise piping .|>.
racinmat c5e08ce
renamed elementwise to broadcast, bumped minor version
racinmat 130e774
working piping for .|>, but I don't know how shouldI write tests
racinmat b31fc6a
using comparisons without linenums
racinmat 07aea9d
tests are passing
racinmat 9e0152b
testing also for Julia 1.4
racinmat b7f93c2
better errors during tests
racinmat c148523
testing is independent on names of temporary variables
racinmat e9595b3
Updated badges
racinmat ca0aef0
fixed tests
racinmat f781005
Update test/runtests.jl
racinmat 1d8a318
split rewriting into separate functions based on broadcast
racinmat 5d14bc4
Merge remote-tracking branch 'origin/master'
racinmat a59c92a
calling correct functions
racinmat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ julia: | |
- 1.0 | ||
- 1.2 | ||
- 1.3 | ||
- 1.4 | ||
- nightly | ||
notifications: | ||
email: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,45 +5,62 @@ export @pipe | |
|
||
const PLACEHOLDER = :_ | ||
|
||
function rewrite(ff::Expr,target) | ||
function replace(arg::Any) | ||
arg #Normally do nothing | ||
function replace(arg::Any, target) | ||
arg #Normally do nothing | ||
end | ||
|
||
function replace(arg::Symbol, target) | ||
if arg==PLACEHOLDER | ||
target | ||
else | ||
arg | ||
end | ||
function replace(arg::Symbol) | ||
if arg==PLACEHOLDER | ||
target | ||
else | ||
arg | ||
end | ||
|
||
function replace(arg::Expr, target) | ||
rep = copy(arg) | ||
rep.args = map(x->replace(x, target), rep.args) | ||
rep | ||
end | ||
|
||
function rewrite(ff::Expr, target, broadcast=false) | ||
if broadcast | ||
temp_var = gensym() | ||
rep_args = map(x->replace(x, temp_var), ff.args) | ||
if ff.args != rep_args | ||
#_ subsitution | ||
ff.args = rep_args | ||
return :($temp_var->$ff) | ||
end | ||
else | ||
rep_args = map(x->replace(x, target), ff.args) | ||
if ff.args != rep_args | ||
#_ subsitution | ||
ff.args = rep_args | ||
return ff | ||
end | ||
end | ||
function replace(arg::Expr) | ||
rep = copy(arg) | ||
rep.args = map(replace,rep.args) | ||
rep | ||
end | ||
|
||
rep_args = map(replace,ff.args) | ||
if ff.args != rep_args | ||
#_ subsitution | ||
ff.args=rep_args | ||
return ff | ||
end | ||
#No subsitution was done (no _ found) | ||
#Apply to a function that is being returned by ff, | ||
#(ff could be a function call or something more complex) | ||
rewrite_apply(ff,target) | ||
rewrite_apply(ff,target,broadcast) | ||
end | ||
|
||
|
||
function rewrite_apply(ff, target) | ||
:($ff($target)) #function application | ||
function rewrite_apply(ff, target, broadcast=false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we break this into two functions? |
||
if broadcast | ||
temp_var = gensym() | ||
:($temp_var->$ff($temp_var)) | ||
else | ||
:($ff($target)) #function application | ||
end | ||
end | ||
|
||
function rewrite(ff::Symbol, target) | ||
function rewrite(ff::Symbol, target, broadcast=false) | ||
if ff==PLACEHOLDER | ||
target | ||
else | ||
rewrite_apply(ff,target) | ||
rewrite_apply(ff,target,broadcast) | ||
end | ||
end | ||
|
||
|
@@ -55,6 +72,11 @@ function funnel(ee::Expr) | |
if (ee.args[1]==:|>) | ||
target = funnel(ee.args[2]) #Recurse | ||
rewrite(ee.args[3],target) | ||
elseif (ee.args[1]==:.|>) | ||
target = funnel(ee.args[2]) #Recurse | ||
rewritten = rewrite(ee.args[3],target,true) | ||
ee.args[3] = rewritten | ||
ee | ||
else | ||
#Not in a piping situtation | ||
ee #make no change | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we break this into two functions?
rewrite
andrewrite_broadcasted