-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Propagation of literals and constants into functions #24011
Comments
One related issue is that if you write a function that internally calls a function with lots of arguments and some infer like this, you'd want to pass splatted |
I am posting this as a simple example: function lyapunov(ds::ContinuousDynamicalSystem, T::Real = 10000.0,
return_convergence::Val{B} = Val{false}; kwargs...) where {B}
# code code code
λts, ts = lyapunov(integ1, integ2, T; kwargs...) # this function does all computations (and is type-stable)
# this simply decides the return values:
if B
return λts, ts
else
return λts[end]
end
end Chris instructed me to do this like it is, so that the function is still type-stable but also can return different things based on user input. |
Maybe the less magical way to handle this would be a way to designate in a function that the values for a specific argument should turn into a value-type, and have the literal/constant automatically turn into the value type. That way passing the value-type works, passing the literal/constant works, and passing a variable would incur a dynamic dispatch (but you'd use this in the case where it's very rare for that option to not be hardcoded). |
Dup of #5560 |
Very low hanging fruit here is to specialize on default values. |
It seems like in a lot of cases one wants to set a bunch of options. The options are usually set by constants from the user, and they can easily affect type-stability. A simple example is
qrfact
. In these cases the current standard is to have the API beqrfact(A,Val{true})
. But it seems like if you haveqrfact(A,true)
, Julia could in theory propagate the literal here. If the second argument is a constant in a function, then that could also happen at compilation time.But you might not always want that because that could be too coarse of a compilation setup, so instead it might be nice to have an opt-in for that:
or something like that to tell it to compile literals separately. Then APIs like
qrfact(A,true)
would allow optional arguments to change in a type-unstable way but keep type-stability when users are hardcoding the argument choice. When keyword dispatch is thing, it would be nice to allow this with keyword arguments as well.The text was updated successfully, but these errors were encountered: