Skip to content

Commit 95057d7

Browse files
committed
Merge branch 's/enable-bench'
2 parents 1c5eee2 + ec99cd0 commit 95057d7

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
File renamed without changes.

src/abstractalgebra.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,9 @@ function expand(expr, variable_type::Type=DynamicPolynomials.PolyVar{true})
173173
to_term(expr, to_mpoly(expr, variable_type)...)
174174
end
175175

176+
## Hack to fix https://github.com/JuliaAlgebra/MultivariatePolynomials.jl/issues/169
177+
178+
Base.promote_rule(::Type{S}, ::Type{T}) where {S<:Symbolic, T<:MP.AbstractPolynomialLike}= Any
179+
Base.promote_rule(::Type{T}, ::Type{S}) where {S<:Symbolic, T<:MP.AbstractPolynomialLike}= Any
180+
176181
Base.@deprecate polynormalize(x) expand(x)

src/rewriters.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ struct Empty end
4141

4242
(rw::Empty)(x) = nothing
4343

44+
instrument(x, f) = f(x)
45+
instrument(x::Empty, f) = x
46+
4447
struct IfElse{F, A, B}
4548
cond::F
4649
yes::A
4750
no::B
4851
end
4952

53+
instrument(x::IfElse, f) = IfElse(x.cond, instrument(x.yes, f), instrument(x.no, f))
54+
5055
function (rw::IfElse)(x)
5156
rw.cond(x) ? rw.yes(x) : rw.no(x)
5257
end
@@ -67,11 +72,14 @@ function (rw::Chain)(x)
6772
return x
6873
end
6974

75+
instrument(c::Chain, f) = Chain(map(x->instrument(x,f), c.rws))
7076

7177
struct RestartedChain{Cs}
7278
rws::Cs
7379
end
7480

81+
instrument(c::RestartedChain, f) = RestartedChain(map(x->instrument(x,f), c.rws))
82+
7583
function (rw::RestartedChain)(x)
7684
for f in rw.rws
7785
y = @timer cached_repr(f) f(x)
@@ -99,6 +107,8 @@ struct Fixpoint{C}
99107
rw::C
100108
end
101109

110+
instrument(x::Fixpoint, f) = Fixpoint(instrument(x.rw, f))
111+
102112
function (rw::Fixpoint)(x)
103113
f = rw.rw
104114
y = @timer cached_repr(f) f(x)
@@ -116,6 +126,13 @@ struct Walk{ord, C, F, threaded}
116126
similarterm::F
117127
end
118128

129+
function instrument(x::Walk{ord, C,F,threaded}, f) where {ord,C,F,threaded}
130+
irw = instrument(x.rw, f)
131+
Walk{ord, typeof(irw), typeof(x.similarterm), threaded}(irw,
132+
x.thread_cutoff,
133+
x.similarterm)
134+
end
135+
119136
using .Threads
120137

121138
function Postwalk(rw; threaded::Bool=false, thread_cutoff=100, similarterm=similarterm)
@@ -129,6 +146,8 @@ end
129146
struct PassThrough{C}
130147
rw::C
131148
end
149+
instrument(x::PassThrough, f) = PassThrough(instrument(x.rw, f))
150+
132151
(p::PassThrough)(x) = (y=p.rw(x); y === nothing ? x : y)
133152

134153
passthrough(x, default) = x === nothing ? default : x
@@ -170,5 +189,19 @@ function (p::Walk{ord, C, F, true})(x) where {ord, C, F}
170189
end
171190
end
172191

192+
function instrument_io(x)
193+
function io_instrumenter(r)
194+
function (args...)
195+
println("Rule: ", r)
196+
println("Input: ", args)
197+
res = r(args...)
198+
println("Output: ", res)
199+
res
200+
end
201+
end
202+
203+
instrument(x, io_instrumenter)
204+
end
205+
173206
end # end module
174207

0 commit comments

Comments
 (0)