Skip to content

Commit

Permalink
improved clogged pipe detection and circumvention
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Apr 15, 2018
1 parent f83ea98 commit acb5659
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ function ReduceCheck(output) # check for REDUCE errors
contains(output,"***** ")|contains(output,"+++ ") && throw(ReduceError(output))
end

function PipeClogged(tf::Bool,c::Int,info::String)
warn("Reduce pipe clogged by $info, $(tf ? "success" : "failure") after $c tries")
end

clear(rs::PSL) = (write(rs.input,";\n"); readavailable(rs.output))
clears = (()->(c=true; return (tf=c)->(ctf && (c=tf); return c)))()

Expand Down Expand Up @@ -171,9 +175,11 @@ function Load()
!contains(dirname(@__FILE__),"appveyor") &&
println(split(String(banner),'\n')[rcsl ? 1 : end-3])
ColCheck(false)
else
ReduceCheck(banner)
rcsl = contains(banner," CSL ")
println(split(String(banner),'\n')[rcsl ? 1 : end-3])
end
ReduceCheck(banner)
rcsl = contains(banner," CSL ")
load_package(:rlfi)
offs |> RExpr |> rcall
show(DevNull,"text/latex",R"int(sinh(e**i*z),z)")
Expand Down
15 changes: 14 additions & 1 deletion src/calculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ end
//(a::T,expr::ExprSymbol;be=0) where T <: AbstractFloat = //(RExpr(a),RExpr(expr);be=be) |> parse
function //(a::T,b::T;be=0) where T <: AbstractFloat
isnan(a) | isnan(b) | (isinf(a) & isinf(b)) && return NaN
return //(RExpr(a),RExpr(b);be=be) |> parse |> eval
out = //(RExpr(a),RExpr(b);be=be) |> parse |> eval
if out == nothing
c = 1
f = SubFail()
h = SubHold()
while out == nothing && c < f
sleep(sqrt(c)*h)
out = //(RExpr(a),RExpr(b);be=be) |> parse |> eval
c += 1
end
PipeClogged(out nothing, c, "rational division")
out == nothing && throw(ReduceError("If generated code relies on many floating point divisions, try setting `Reduce.Rational(false)` and use `Reduce.Reset()`, since rational division is the default."))
end
return out
end

export ∑, ∏
Expand Down
4 changes: 2 additions & 2 deletions src/rexpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ ColCheck = ( () -> begin
w = _subst(sym == :r ? symrjl : symjlr, a[s])
c += 1
end
warn("Reduce pipe clogged, $(w "" ? "success" : "failure") after $c tries")
PipeClogged(w "", c, "substitution")
end
w "" && (a[s] = w)
w "" ? (a[s] = w) : info("If this is a recurring problem, try with `Reduce.SubCall(false)`.")
end
if sym == :r
a[s] == "inf" && (a[s] = "Inf")
Expand Down

0 comments on commit acb5659

Please sign in to comment.