# Change a function without the actual evaluation ...?

**URL:** <https://discourse.julialang.org/t/change-a-function-without-the-actual-evaluation/60657>\
**Category:** Performance\
**Tags:** question, macros\
**Created:** [May 6, 2021, 2:37pm UTC](https://discourse.julialang.org/t/change-a-function-without-the-actual-evaluation/60657 "2021-05-06T14:37:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [May 6, 2021, 2:37pm UTC](https://discourse.julialang.org/t/change-a-function-without-the-actual-evaluation/60657/1 "2021-05-06T14:37:32Z")

</div>

Hi.

I’d like to know if there is a way to convert a function to a different form without the actual evaluation.

For example, I’m trying to make an API of [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl). However, I encountered a serious performance degradation. The following code is an example of my API.

```julia
function DifferentialEquations.ODEProblem(env::AbstractEnv, f, x0, tspan; kwargs...)
    warn_is_registered(env)
    _x0 = raw(env, x0)
    _f(_x, p, t) = raw(env, f(readable(env, _x), p, t))
    ODEProblem(_f, _x0, tspan; kwargs...)
end

```

In the above code, `x0` denotes NamedTuple-valued (i.e., readable) initial condition.  
`_x0` is a vector-valued (i.e., raw) initial condition.  
From this line, `_f(_x, p, t) = raw(env, f(readable(env, _x), p, t))`, you may notice that the argument `f` of the extended function `DifferentialEquations.ODEProblem(env::AbstractEnv, f, x0, tspan; kwargs...)` will receive a “readable” state (`x`) and provide a “readable” output of its derivative.  
For the compatibility with DifferentialEquations.jl, `_f`, which is the injected dynamical equations into `ODEProblem` provided by DifferentialEquations.jl, should provide a “raw” output, so the output of `f(readable(env, _x), p, t)` is wrapped by `raw`.

In this case, I realised that every call of `_f` would require two processings, `raw` and `readable`, which drastically degrade the performance. So, I wonder if there is a way of parsing the “readable” dynamical equations, `f`, to the “raw” dynamical equations, `_f`, at the beginning, not every time it is called.

---

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [May 7, 2021, 7:32am UTC](https://discourse.julialang.org/t/change-a-function-without-the-actual-evaluation/60657/2 "2021-05-07T07:32:37Z")

</div>

[LabelledArrays.jl](https://github.com/SciML/LabelledArrays.jl) resolves my issue. So I closed this conversation.
