-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Adding one
for structured matrices that preserves type
#29777
Merged
stevengj
merged 8 commits into
JuliaLang:master
from
mcognetta:add_one_structured_matrix
Feb 6, 2019
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
38713b6
added one for structured types. not very elegant
mcognetta e507488
fix diagonal fill
mcognetta 392c194
adding tests and making the container types stay the same (except for…
mcognetta 3d86c23
removing small enough to put into separate PR
mcognetta 58b5b31
fixing the case of types with dimension and adding tests
mcognetta 2928f39
fixing merge conflict after merge from master
mcognetta 429620a
missed merge conflict in the test file
mcognetta 36921f8
fixing error in test
mcognetta 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 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 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.
similar(foo)
in all of these cases is wrong. It should besimilar(foo, typeof(one(T)))
The issue is that, if
T
is a dimensionful type,one
returns a dimensionless type.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.
You could also use
fill(one(T), size(foo))
, which might be simpler.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.
zero(A.dl)
etcetera is wrong for a related reason, becausezero
returns a dimensionful value. You should instead usefill(zero(one(T)), size(A.dl))
or similar.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.
No, this would always return
Vector
.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.
Would be good to test the dimensionful case … see the tests with
Furlongs
in thetest/triangular.jl
file.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.
@fredrikekre is correct about (not) using
fill(one(T), size(foo))
. This would not preserve the underlying container type (as an example: sparsevector).As for the dimensionless type, using similar should an abstractvector with the given eltype, which then promotes the result of
one
to the appropriate dimensionful type.For example:
Is this not the behavior that we want?
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.
one
should return a multiplicative identity, so it should be unitless, e.g.and thus,
should be true.
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.
Ah, I interpreted @stevengj 's comment the opposite way. I will update this and add some tests with types that have a dimension.
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.
Who cares? Why does the underlying container type matter? An array of ones is not sparse anyway.
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 way, it would be consistent with
zero
. Not that I think making it a vector is a bad idea though (especially considering the behavior ofzero
andone
for these matrices backed by ranges).