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

Rewriting broadcasted functions doesn't work #113

Open
jenkspt opened this issue Apr 1, 2022 · 1 comment
Open

Rewriting broadcasted functions doesn't work #113

jenkspt opened this issue Apr 1, 2022 · 1 comment

Comments

@jenkspt
Copy link

jenkspt commented Apr 1, 2022

The following works as expected

julia> r = @rule a b log(a / b) --> log(a) - log(b)
julia> r(:(log(x / y)))
:(log(x) - log(y))

However I'm interested in matching broadcasted functions in expressions, but the following doesn't work:

julia> r = @rule a b log.(a./b) --> log.(a) - log.(b)
julia> r(:(log.(x./y)))
(nothing)

broadcasting binary operators does work

julia> r = @rule a b a .+ b --> b .+ a
julia> r(:(x .+ y))
:(y .+ x)

using the broadcast function doesn't work

julia> r = @rule a b broadcast(+, a, b) --> broadcast(+, b, a)
julia> r(:(broadcast(+, x, y)))
(nothing)

I briefly looked into TermInterface.jl, and am wondering if the fact that exprhead returns :. for some expressions and :call for others is the culprit.

julia> exprhead(:(a .+ b))
:call
julia> exprhead(:(log.(a)))
:.
@0x0f0f0f
Copy link
Member

0x0f0f0f commented Apr 5, 2022

Yes, may be the culprit. Need to debug.

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