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

Remove call to eval in simplify #111

Open
sglyon opened this issue Jun 12, 2017 · 1 comment
Open

Remove call to eval in simplify #111

sglyon opened this issue Jun 12, 2017 · 1 comment

Comments

@sglyon
Copy link
Member

sglyon commented Jun 12, 2017

I have some code where I want to use Calculus.jl to differentiate symbolic expressions inside a @generated function. This currently does not work because after differentiating Calculus.jl calls simplify, which in turn often ends up calling eval. As of right now @generated functions are not allowed to call eval.

I'm opening this issue to see if those who know the internals here better think it would be possible/feasible to remove the call to eval inside simplify?

ref: EconForge/Dolang.jl#31 (comment)

@JanisErdmanis
Copy link

I had exactly the same issue today. Looking in the symbolic.jl I saw that it was only used for doing arithmetics. Thus replaced eval with a following code

    if all(isnumber, ex.args[2:end]) && length(ex.args) > 1
        ### Doing numerical stuff!!!
        ################ A Patch Here #################
        op = ex.args[1]
        nums = ex.args[2:end]
        if op==:+
            return +(nums...)
        elseif op==:-
            return -(nums...)
        elseif op==:/
            return /(nums...)
        elseif op==:*
            return *(nums...)
        else
            error("Operation $op not implemented")
        end

        ############# Replaces ######################
        #return eval(current_module(), ex)
        #############################################
    end

which seems to work fine ;)

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

No branches or pull requests

2 participants