-
Notifications
You must be signed in to change notification settings - Fork 42
Implement indexing by value with atvalue #52
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 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
36ff77a
Implement indexing by value with atvalue
ajkeller34 3267a55
Tighten up Idx, add docs for atvalue, add tests
ajkeller34 0242ee4
Address review comments
ajkeller34 6e99a30
Add options for tolerance
ajkeller34 9ba355f
Add ability to throw a BoundsError with value index
ajkeller34 94671bf
Mark a test as broken for Julia 0.5.2 only.
ajkeller34 5073684
Minor docs tweaks, bump Unitful version in test/REQUIRE, small change…
ajkeller34 c769962
Fix typo in a test due to character encodings
ajkeller34 53a5f88
Fix typo in README
ajkeller34 dba7370
Fix Julia 0.5 complaint
ajkeller34 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,3 +165,38 @@ A = AxisArray(rand(2,2), :x, :y) | |
| acc = zeros(Int, 4, 1, 2) | ||
| Base.mapreducedim!(x->x>5, +, acc, A3) | ||
| @test acc == reshape([1 3; 2 3; 2 3; 2 3], 4, 1, 2) | ||
|
|
||
| # Indexing by value using `atvalue` | ||
| A = AxisArray([1 2; 3 4], Axis{:x}([1.0,4.0]), Axis{:y}([2.0,6.1])) | ||
| @test @inferred(A[atvalue(1.0)]) == @inferred(A[atvalue(1.0), :]) == [1,2] | ||
| # `atvalue` doesn't require same type: | ||
| @test @inferred(A[atvalue(1)]) == @inferred(A[atvalue(1), :]) ==[1,2] | ||
| @test A[atvalue(4.0)] == A[atvalue(4.0),:] == [3,4] | ||
| @test A[atvalue(4)] == A[atvalue(4),:] == [3,4] | ||
| @test_throws BoundsError A[atvalue(5.0)] | ||
| @test @inferred(A[atvalue(1.0), atvalue(2.0)]) == 1 | ||
| @test @inferred(A[:, atvalue(2.0)]) == [1,3] | ||
| @test @inferred(A[Axis{:x}(atvalue(4.0))]) == [3,4] | ||
| @test @inferred(A[Axis{:y}(atvalue(6.1))]) == [2,4] | ||
| @test @inferred(A[Axis{:x}(atvalue(4.00000001))]) == [3,4] | ||
| @test @inferred(A[Axis{:x}(atvalue(2.0, atol=5))]) == [1,2] | ||
| @test_throws BoundsError A[Axis{:x}(atvalue(4.00000001, rtol=0))] | ||
|
|
||
| # Indexing by value into an OffsetArray | ||
| A = AxisArray(OffsetArrays.OffsetArray([1 2; 3 4], 0:1, 1:2), | ||
| Axis{:x}([1.0,4.0]), Axis{:y}([2.0,6.1])) | ||
| @test_broken @inferred(A[atvalue(4.0)]) == [3,4] | ||
| @test @inferred(A[:, atvalue(2.0)]) == OffsetArrays.OffsetArray([1,3], 0:1) | ||
| @test_throws BoundsError A[atvalue(5.0)] | ||
|
|
||
| # Indexing by value directly is forbidden for indexes that are Real | ||
| @test_throws ArgumentError A[4.0] | ||
| @test_throws ArgumentError A[BigFloat(1.0)] | ||
| @test_throws ArgumentError A[1.0f0] | ||
| if VERSION == v"0.5.2" | ||
| # Cannot compose @test_broken with @test_throws (Julia #21098) | ||
| # A[:,6.1] incorrectly throws a BoundsError instead of an ArgumentError on Julia 0.5.2 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would show up as a package regression if I make an 0.5.3, so I'd like to figure out what caused this and whether it was something that should not have been backported |
||
| @test_broken A[:,6.1] | ||
| else | ||
| @test_throws ArgumentError A[:,6.1] | ||
| end | ||
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.
did anyone bisect this?
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 didn't bisect it, but I'm quite certain that it was JuliaLang/julia#19730. We used to check bounds with
<before converting indices. Now we convert indices first. This is expected.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.
huh? how, this is a problem only on 0.5.2 apparently?