Skip to content

Commit

Permalink
Check function identity
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Jul 26, 2023
1 parent 88e2e13 commit 382a88f
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/code.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Code

using StaticArrays, LabelledArrays, SparseArrays, LinearAlgebra, NaNMath
using StaticArrays, LabelledArrays, SparseArrays, LinearAlgebra, NaNMath, SpecialFunctions

export toexpr, Assignment, (), Let, Func, DestructuredArgs, LiteralExpr,
SetArray, MakeArray, MakeSparseArray, MakeTuple, AtIndex,
Expand Down Expand Up @@ -97,22 +97,23 @@ Base.convert(::Type{Assignment}, p::Pair) = Assignment(pair[1], pair[2])
toexpr(a::Assignment, st) = :($(toexpr(a.lhs, st)) = $(toexpr(a.rhs, st)))

const NaNMathFuns = (
:sin,
:cos,
:tan,
:asin,
:acos,
:acosh,
:atanh,
:log,
:log2,
:log10,
:lgamma,
:log1p,
:sqrt,
sin,
cos,
tan,
asin,
acos,
acosh,
atanh,
log,
log2,
log10,
lgamma,
log1p,
sqrt,
)
function function_to_expr(op, O, st)
(op isa Function && (name = nameof(op)) in NaNMathFuns) || return nothing
op in NaNMathFuns || return nothing
name = nameof(op)
fun = GlobalRef(NaNMath, name)
args = map(Base.Fix2(toexpr, st), arguments(O))
expr = Expr(:call, fun)
Expand Down

0 comments on commit 382a88f

Please sign in to comment.