Skip to content

Commit cedd2a3

Browse files
authored
speed up iszero (#494)
* speed up izero * just use to_mpoly directly in iszero * check to see if polynorm form is a Number, then check iszero * bump symutils version * (Number or MPoly) && iszero
1 parent a48df76 commit cedd2a3

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Requires = "1.0"
4747
SafeTestsets = "0.0.1"
4848
SpecialFunctions = "0.7, 0.8, 0.9, 0.10"
4949
StaticArrays = "0.10, 0.11, 0.12"
50-
SymbolicUtils = "0.4.1"
50+
SymbolicUtils = "0.4.3"
5151
TreeViews = "0.3"
5252
UnPack = "0.1, 1.0"
5353
Unitful = "1.1"

src/operations.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ Base.hash(o::Operation, salt::UInt) = hash(o.args, hash(o.op, salt))
5858

5959
# provide iszero for Operations to help sparse addition and multiplication
6060
# e.g., we want to tell the sparse library that iszero(zero(Operation) + zero(Operation)) == true
61-
Base.iszero(x::Operation) = (_x = simplify(x); _x isa Constant && iszero(_x.value))
61+
62+
function Base.iszero(x::Operation)
63+
_x = SymbolicUtils.to_mpoly(to_symbolic(x))[1]
64+
return (_x isa Number || _x isa SymbolicUtils.MPoly) && iszero(_x)
65+
end
6266

6367
Base.show(io::IO, O::Operation) = print(io, convert(Expr, O))
6468

0 commit comments

Comments
 (0)