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

Perf #3

Merged
merged 3 commits into from
Feb 12, 2020
Merged

Perf #3

merged 3 commits into from
Feb 12, 2020

Conversation

YingboMa
Copy link
Member

@YingboMa YingboMa commented Feb 12, 2020

julia> using SymbolicUtils

julia> @vars a b c;

julia> x = foldr(*, [rand([a, b, c]) for i in 1:1000]);

julia> r = rewriter(SymbolicUtils.PLUS_AND_SCALAR_MUL);

julia> r(x);

julia> @time r(x);
  1.664081 seconds (19.56 M allocations: 1.992 GiB, 6.34% gc time)

```julia
julia> using SymbolicUtils

julia> @vars a b c;

julia> x = foldr(*, [rand([a, b, c]) for i in 1:1000]);

julia> r = rewriter(SymbolicUtils.PLUS_AND_SCALAR_MUL);

julia> r(x);

julia> @time r(x);
  0.019116 seconds (250.73 k allocations: 23.153 MiB, 29.31% gc time)
```
@YingboMa YingboMa requested a review from shashi February 12, 2020 04:36
src/util.jl Outdated
end
@inline cdr(v) = isempty(v) ? empty(l) : LL(v, 2)

@inline take_n(ll::LL, n) = isempty(ll) || n == 0 ? empty(ll) : @view ll.v[ll.i:min(end, n+ll.i-1)]
Copy link
Member

Choose a reason for hiding this comment

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

maybe LL{<:AbstractVector}? it can be anything.

src/util.jl Outdated
@inline cdr(v) = isempty(v) ? empty(l) : LL(v, 2)

@inline take_n(ll::LL, n) = isempty(ll) || n == 0 ? empty(ll) : @view ll.v[ll.i:min(end, n+ll.i-1)]
@inline take_n(ll, n) = @view ll[1:min(end, n)]
Copy link
Member

Choose a reason for hiding this comment

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

This should probably fail if it can't take. The only place it is used shouldn't need it to fail silently.

Copy link
Member Author

@YingboMa YingboMa Feb 12, 2020

Choose a reason for hiding this comment

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

I think we actually need this.

Copy link
Member

Choose a reason for hiding this comment

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

I'm saying @view ll[1:min(end, n)] should be @view ll[1:n]

@@ -6,27 +6,27 @@ end
islist(::Any) = false
islist(l::Union{LL, Term, AbstractArray, Tuple}) = true

Base.empty(l::LL) = empty(l.v)
Copy link
Member

Choose a reason for hiding this comment

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

I didn't know about this function, so type stable, wow.

@YingboMa
Copy link
Member Author

Oh, don't merge this. It is wrong.

src/util.jl Outdated

@inline drop_n(ll::Term, n) = drop_n(arguments(ll), n)
@inline drop_n(ll::AbstractArray, n) = drop_n(LL(ll, 1), n)
@inline drop_n(ll::LL, n) = LL(ll.v, max(1, ll.i-n))
Copy link
Member

@shashi shashi Feb 12, 2020

Choose a reason for hiding this comment

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

I think it needs to handle ll.i-n=0, otherwise segment recognition is wrong.

src/util.jl Outdated

@inline drop_n(ll::Term, n) = drop_n(arguments(ll), n)
Copy link
Member

Choose a reason for hiding this comment

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

should be drop_n(arguments(ll), n-1)

f is considered car of a term :trollface:

Co-authored-by: "Shashi Gowda" <[email protected]>
Co-authored-by: "Yingbo Ma" <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants