-
Notifications
You must be signed in to change notification settings - Fork 21
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
Automatically change parameter and return float types #222
base: main
Are you sure you want to change the base?
Conversation
That looks nice, two comments:
|
I don't follow this statement --- what do you mean? For situations with large numbers of parameters, you can put them in an Array (like Another possibility is to convert at runtime, eg with something like const parameter = 1.23
f(a::FT) = a + convert(FT, parameter) |
Sorry I missed this I've been a bit busy. I think that makes sense, there are a lot of instances here where On the sugar kelp model, I didn't do it because I was being lazy but I'll change them before I merge the PR. |
You can also make a note in the source code and then open an issue about improvements if it doesn't make sense to prioritize immediately |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also agree that this is nice and doesn't need to be perfect to be merged!
Maybe I'm misunderstanding the issue but with tons of parameters can't we loop over each property and convert it?
Something like this:
function Base.convert(::Type{SugarKelp{FT_new, TL}}, x::SugarKelp{FT_old, TL}) where {FT_new, FT_old, TL}
fields = NamedTuple{fieldnames(typeof(x))}(
field === :temperature_limit ? getfield(x, field) : convert(FT_new, getfield(x, field))
for field in fieldnames(typeof(x))
)
return SugarKelp{FT_new, TL}(; fields...)
end
Oh yes that's a good idea, I hadn't thought of that. Do you think we would then need to put in the
|
You want to throw an error if the float type is wrong |
This PR removes hard coded float types in function returns, and sets up most (not worth it to do the sugar kelp model because it has a billion parameters) model setup functions to automatically set the correct float type, or at least be able to set in a simple way, e.g.:
cc: @ali-ramadhan @glwagner
Closes #218