-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[DOC] Fix small typo in subarray docs #23298
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 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 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 |
---|---|---|
|
@@ -36,14 +36,37 @@ cartesian, rather than linear, indexing. | |
|
||
Consider making 2d slices of a 3d array: | ||
|
||
```julia | ||
S1 = view(A, :, 5, 2:6) | ||
S2 = view(A, 5, :, 2:6) | ||
```@meta | ||
DocTestSetup = :(srand(1234)) | ||
``` | ||
```jldoctest subarray | ||
julia> A = rand(6, 6, 6); | ||
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. Does the matrix really have to be so big? |
||
|
||
julia> S1 = view(A, :, 5, 2:6) | ||
6×5 SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Int64,UnitRange{Int64}},false}: | ||
0.643704 0.386568 0.146333 0.34124 0.344757 | ||
0.401421 0.330579 0.647078 0.52376 0.929902 | ||
0.525057 0.748041 0.998546 0.661835 0.520697 | ||
0.61201 0.265595 0.495394 0.833012 0.613 | ||
0.432577 0.291069 0.654293 0.498856 0.144613 | ||
0.082207 0.612628 0.834909 0.937867 0.465207 | ||
|
||
julia> S2 = view(A, 5, :, 2:6) | ||
6×5 SubArray{Float64,2,Array{Float64,3},Tuple{Int64,Base.Slice{Base.OneTo{Int64}},UnitRange{Int64}},true}: | ||
0.0462887 0.775194 0.727763 0.603624 0.481834 | ||
0.147329 0.60808 0.80743 0.140473 0.324266 | ||
0.260715 0.110096 0.883704 0.682579 0.778229 | ||
0.753508 0.838042 0.500725 0.494824 0.369212 | ||
0.432577 0.291069 0.654293 0.498856 0.144613 | ||
0.204728 0.192634 0.689977 0.677079 0.274452 | ||
``` | ||
```@meta | ||
DocTestSetup = nothing | ||
``` | ||
|
||
`view` drops "singleton" dimensions (ones that are specified by an `Int`), so both `S1` and `S2` | ||
are two-dimensional `SubArray`s. Consequently, the natural way to index these is with `S1[i,j]`. | ||
To extract the value from the parent array `A`, the natural approach is to replace `S1[i,j]` | ||
To extract the value from the parent array `A`, the natural approach is to replace `S1[i,j]` | ||
with `A[i,5,(2:6)[j]]` and `S2[i,j]` with `A[5,i,(2:6)[j]]`. | ||
|
||
The key feature of the design of SubArrays is that this index replacement can be performed without | ||
|
@@ -71,13 +94,13 @@ a `Tuple` of the types of the indices for each dimension. The final one, `L`, is | |
as a convenience for dispatch; it's a boolean that represents whether the index types support | ||
fast linear indexing. More on that later. | ||
|
||
If in our example above `A` is a `Array{Float64, 3}`, our `S1` case above would be a `SubArray{Int64,2,Array{Int64,3},Tuple{Colon,Int64,UnitRange{Int64}},false}`. | ||
If in our example above `A` is a `Array{Float64, 3}`, our `S1` case above would be a `SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},Int64,UnitRange{Int64}},false}`. | ||
Note in particular the tuple parameter, which stores the types of the indices used to create | ||
`S1`. Likewise, | ||
|
||
```julia-repl | ||
```jldoctest subarray | ||
julia> S1.indexes | ||
(Colon(),5,2:6) | ||
(Base.Slice(Base.OneTo(6)), 5, 2:6) | ||
``` | ||
|
||
Storing these values allows index replacement, and having the types encoded as parameters allows | ||
|
@@ -138,7 +161,7 @@ For `SubArray` types, the availability of efficient linear indexing is based pur | |
of the indices, and does not depend on values like the size of the parent array. You can ask whether | ||
a given set of indices supports fast linear indexing with the internal `Base.viewindexing` function: | ||
|
||
```julia-repl | ||
```jldoctest subarray | ||
julia> Base.viewindexing(S1.indexes) | ||
IndexCartesian() | ||
|
||
|
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.
In line 175, should
jldoctest
->jldoctest subarray
like here? (I couldn't figure out what this really does from the Documenter.jl docs)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, because we don't use anything (eg. variables, functions etc) from these blocks in that block below, see https://juliadocs.github.io/Documenter.jl/latest/man/doctests/#Preserving-definitions-between-blocks-1 :)
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.
thanks, @fredrikekre