-
Notifications
You must be signed in to change notification settings - Fork 154
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
Preserve metadata on getindex
operation when scalarizing
#1010
base: master
Are you sure you want to change the base?
Preserve metadata on getindex
operation when scalarizing
#1010
Conversation
if isnothing(metadata(arr)) | ||
scalarized | ||
else | ||
metadata(scalarized, metadata(arr)) |
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.
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.
It should not be the same... And I think this should not be added... I would say this is a usecase where tagged-data like API becomes useful. You should be able to define something like:
@metadata getindex(::MetadataType, idx) = compute_output_metadata_here
And it should be handled for every key which registers in this way.
I'd be interested in adding this general feature, but I'm looking for more substantial examples where this is super useful.
Until then, I think you should just try to propagate the metadata outside of the package's behavior (by walking the tree once constructed). The method in this PR seems not correct to me.
The present behavior seems surprising to me. Is the correct resolution to document that scalarize does not preserve metadata or to create an issue to record this and come back to it when a more complete solution can be designed? |
I don't think the approach is generally wrong, it's just that |
The new thing that happens here is not the indexing, this was an indexing operation coming in and is still one on return (possibly even exactly the same one if there were no array operations in the variable or indexing arguments). The new thing is that |
What if you just add to the metadata the index? |
In the test case I have the index is just an integer. What is the right thing to wrap that in so I can attach metadata? |
@shashi have a preference? |
We already do something like this for Line 6 in 43f93d0
So if you just do And this function Line 21 in 43f93d0
|
In general, it would be nice to have something that makes sense for all purposes and is extensible. I'm also ok with attaching the index to the metadata, you could just create a new type called |
No description provided.