-
-
Notifications
You must be signed in to change notification settings - Fork 47
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 output dimension type parameter and add output_dim
to API
#396
base: master
Are you sure you want to change the base?
Conversation
@ChrisRackauckas isn't this another argument in favor of the I guess this feature has some use somewhere otherwise it wouldn't have been added |
IMO it's just generally bad and not useful: It can't be inferred and doesn't tell you anything about the structure of And the type inference problem implies that generally you pay runtime dispatch penalties in a function if you construct the interpolation and use it for computations.
Downstream packages could still use the same runtime logic for deriving the output dimension (could even be made available as part of the API) if they want that information, without breaking type inference for every user of DataInterpolations. |
I had added it as a feature request (#328) but if it breaks inference, I guess its not worth it. |
It's used https://github.com/adrhill/SparseConnectivityTracer.jl/blob/622cfb729832d127f2d0f9f94110391b4d439b6b/ext/SparseConnectivityTracerDataInterpolationsExt.jl#L54 and https://github.com/adrhill/SparseConnectivityTracer.jl/blob/622cfb729832d127f2d0f9f94110391b4d439b6b/ext/SparseConnectivityTracerDataInterpolationsExt.jl#L64 but these cases do not need a static type information but can just extract the dimension (IMO still questionable how useful in general given the different types of |
Why is it not inferable? This seems trivial to infer? |
No, it can only be inferred from static arrays. It queries |
Wait it's not a dimension size computable from |
No, it's not. It refers to the actual size of the output/input data. |
Oh, that can't be type information. Wait why would DI even want or need that? That seems silly. |
🤷 |
From the original issue by @adrhill:
So it might be useful to use |
I thought this as well. At least that was my intention in opening #328 – Having the interpolations mirror array types. I have no problem with a revert/fix of whatever |
Let's fix it to |
So, you'd want output_dims(::AbstractVector) = 0 # each value is a scalar
output_dims(::AbstractVector{<:AbstractArray{<:Any,N}}) where {N} = N # each value is an array but values are not stacked
output_dims(::AbstractArray{<:Any,N}) where {N} = N - 1 # each value is an array but multiple values are stacked Note that you still wouldn't be able to draw any conclusion about the structure of the output based on N. |
output_dim
to API
The PR removes the type parameter. I tested with my downstream package and tests finally pass again with this change.
The reason is that
u
u::Vector{<:Vector}
where each element is of length 3 or e.g. au::Matrix
with 3 rowsOn the master branch:
This PR:
Edit: I added an exported
output_dim
function as discussed in #396 (comment). This could be used by SparseConnectivityTracer if desired/useful which currently seems to be the only downstream user of the type parameter but only makes us of it in a non-static way.