Skip to content

Commit b594172

Browse files
authored
Add doctest: eachslice (#36386)
* add doctests for eachslice * update doctest eachslice
1 parent 8db9495 commit b594172

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

base/abstractarraymath.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,28 @@ See also [`eachrow`](@ref), [`eachcol`](@ref), and [`selectdim`](@ref).
514514
515515
!!! compat "Julia 1.1"
516516
This function requires at least Julia 1.1.
517+
518+
# Example
519+
520+
```jldoctest
521+
julia> M = [1 2 3; 4 5 6; 7 8 9]
522+
3×3 Array{Int64,2}:
523+
1 2 3
524+
4 5 6
525+
7 8 9
526+
527+
julia> first(eachslice(M, dims=1))
528+
3-element view(::Array{Int64,2}, 1, :) with eltype Int64:
529+
1
530+
2
531+
3
532+
533+
julia> collect(eachslice(M, dims=2))
534+
3-element Array{SubArray{Int64,1,Array{Int64,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true},1}:
535+
[1, 4, 7]
536+
[2, 5, 8]
537+
[3, 6, 9]
538+
```
517539
"""
518540
@inline function eachslice(A::AbstractArray; dims)
519541
length(dims) == 1 || throw(ArgumentError("only single dimensions are supported"))

0 commit comments

Comments
 (0)