-
Notifications
You must be signed in to change notification settings - Fork 15
Make inverse(::VectorTransfrom, x)
return a vector of floats
#133
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think that this catches too much. I would simply condition on
dimension(t) == 0
, I don't think thatUnion{}
can happen outside that. Something likeThere 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.
In your suggestion you seem to condition on
Union{}
as well?I was actually considering checking only
dimsnion(t) == 0
as for my use case it shouldn't matter. I went with checking only whetherinverse_eltype(t, y) === Union{}
since I was worried that branching on the value ofdimension(t)
could introduce a type instability.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.
Yes, that makes sense.
But now that I think about it, it is kind of funny to make
eltype(inverse(t, y)) != inverse_eltype(t, y)
. I think it would be best to fix it ininverse_eltype
, the following way:Introduce a function, eg
narrow_inverse_eltype
, basically renameinverse_eltype
to that, in the state before this PR. Document that types should extent it.In
inverse_eltype
, just check forUnion{}
and replace withFloat64
.Now that I look at the code, the eltype determination is a bit flaky in a lot of places:
We should probably rethink it as a whole for all kinds of corner cases. Suggestions welcome.
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.
Initially I wanted to change
inverse_eltype
. But making it concrete seemed wrong - similar to the scalar transforms (such asinverse_eltype(::Constant) = Union{}
), per se aninverse_eltype
seems completely correct: It avoids prematurely introducing e.g.Float64
in a "non-leaf" transform (ie before applying all compositions or combinations). IMO the element type is only relevant when the output array is actually instantiated, and changes (such as changing to floating point number types or turningUnion{}
toFloat64
) should only be performed at this final stage - as done in this PR.I think this example is quite special as it is caused by the same bug as #73: The element type of the output (
inverse_eltype
) is in this case computed based on the first element of inputx
. Whereas actually for non-concrete element types, I thinkinverse_eltype
take into account the full inputx
, e.g. by promoting theinverse_eltype
s for each element (can't be inferred in this case) or returning an abstract type such asAny
.By construction of this failing example, it is actually fixed by this PR since
Int
would be changed toFloat64
when constructing theVector
. With this PR,