-
Notifications
You must be signed in to change notification settings - Fork 56
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
RFC: storing intermediate values #152
Comments
Why can't you just use a closure or something and store it yourself? |
|
I don't know how to get the type inferred correctly. Eg using Roots
function find_zero_ext(f, g, bracket)
local val
x = find_zero(x -> (val = g(x); f(val)), bracket)
(x, val)
end results in julia> @code_warntype find_zero_ext(x -> x^3, cbrt, (-1, 1))
Body::Tuple{Float64,Any}
1 ─ %1 = %new(Core.Box)::Core.Box
│ %2 = %new(getfield(Main, Symbol("##9#10")){getfield(Main, Symbol("##15#16")),typeof(cbrt)}, f, g, %1)::getfield(Main, Symbol("##9#10")){getfield(Main, Symbol("##15#16")),typeof(cbrt)}
│ %3 = Roots.find_zero::typeof(find_zero)
│ %4 = invoke Roots.:(#find_zero#8)($(QuoteNode(Roots.NullTracks()))::Roots.NullTracks, false::Bool, $(QuoteNode(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}()))::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, %3::Function, %2::Function, _4::Tuple{Int64,Int64}, $(QuoteNode(Bisection()))::Bisection)::Float64
│ %5 = (Core.isdefined)(%1, :contents)::Bool
└── goto #3 if not %5
2 ─ goto #4
3 ─ $(Expr(:throw_undef_if_not, :val, false))
4 ┄ %9 = (Core.getfield)(%1, :contents)::Any
│ %10 = (Core.tuple)(%4, %9)::Tuple{Float64,Any}
└── return %10 |
That's the old "boxes in closures"-issue. Can be worked around with something like:
|
Assume I don't know the result type of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes I solve nonlinear systems of the form
where
g(x)
is a large, costly, and ultimately interesting object, so one would call it on the root, but that is a bit wasteful. It would be nice to have an interface that returns it. I am thinking of something likewhere
by
would beg
, and aNamedTuple
is returned. But this of course would be breaking, so a new name would perhaps be better.The text was updated successfully, but these errors were encountered: