-
Notifications
You must be signed in to change notification settings - Fork 152
Fix method amguity in Scalar(::StaticArray) #774
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
Closed
Closed
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
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 guess
Scalar(Scalar(0)) == Scalar(0)
does not hold with this? As we already haveScalar(fill(0)) == Scalar(0) == Scalar((0,))
, maybe it should?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.
Hm, I hadn't considered that. It that does conflict a bit with the precendent already set, but I find that precedent kinda suspicious. It seems like it makes it very hard to make nested scalar objects. i.e. it makes things like this really hard:
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'd expect
Scalar(Scalar(0)) == Scalar(0)
sinceThe behavior of
Array{<:Any,0}
is expected given this recommendation in the manual:Stretching this recommendation a bit, in general, given
I expect
if
Container
is "narrow enough" (it obviously won't work ifContainer = Any
).To use
Scalar
forRef
, I think we need a factorythat ensures the wrapping behavior. This is compatible with how
tuple
andTuple
work.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.
Yeah exactly - in Julia we end up tending to need factories like
tuple
,collect
, etc to create collections rather than using the constructor (here we have aTuple
constructor to “bootstrap” but we could equally have created an explicit tuple->static array generic function, and otherwise we do attempt to follow the patterns in Base with the constructors).(I note that generally we see the same need for extra functions with anything that “wraps” or “contains” one or more objects, like
adjoint
vsAdjoint
.)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 it's actually kind of (half?) opposite for
adjoint
vsAdjoint
. The contractorAdjoint
always wraps the object while the factoryadjoint
doesn't behave this way. But yeah, it seems that it's unavoidable to have two entry points.)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.
This is the interesting part. The output of the generic interface
adjoint
does a better job of behaving as if it were always wrapped in anotherAdjoint
than the constructorAjdoint
would using the copy semantics that seems common toAbstractArray
constructors (your point above aboutScalar(Scalar(x)) == Scalar(x)
might as well be the same asAdjoint(Adjoint(x)) == Adjoint(x)
). It's just thatadjoint
can get away with removing anAdjoint
wrapper because of special properties ofAdjoint
- but IMO even without that theadjoint
function would likely still be necessary.