From 2083317d25213ba3f0229430e64d37ba6c580944 Mon Sep 17 00:00:00 2001 From: Gautam Mishra Date: Mon, 22 Jun 2020 13:58:15 +0530 Subject: [PATCH 1/2] add doctests for eachslice --- base/abstractarraymath.jl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 32bd3c2d20c4f..3844e780a2ec2 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -491,6 +491,28 @@ See also [`eachrow`](@ref), [`eachcol`](@ref), and [`selectdim`](@ref). !!! compat "Julia 1.1" This function requires at least Julia 1.1. + +# Example + +```jldoctest +julia> M = [1 2 3; 4 5 6; 7 8 9] +3×3 Array{Int64,2}: + 1 2 3 + 4 5 6 + 7 8 9 + +julia> first(eachslice(M, dims=1)) +3-element view(::Array{Int64,2}, 1, :) with eltype Int64: + 1 + 2 + 3 + +julia> first(eachslice(M, dims=2)) +3-element view(::Array{Int64,2}, :, 1) with eltype Int64: + 1 + 4 + 7 +``` """ @inline function eachslice(A::AbstractArray; dims) length(dims) == 1 || throw(ArgumentError("only single dimensions are supported")) From 9247c0ddf65e01b1b06f8e7e26a3c7deec923951 Mon Sep 17 00:00:00 2001 From: Gautam Mishra Date: Mon, 22 Jun 2020 14:02:32 +0530 Subject: [PATCH 2/2] update doctest eachslice --- base/abstractarraymath.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 3844e780a2ec2..1f26f8ca2ecd7 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -507,11 +507,11 @@ julia> first(eachslice(M, dims=1)) 2 3 -julia> first(eachslice(M, dims=2)) -3-element view(::Array{Int64,2}, :, 1) with eltype Int64: - 1 - 4 - 7 +julia> collect(eachslice(M, dims=2)) +3-element Array{SubArray{Int64,1,Array{Int64,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true},1}: + [1, 4, 7] + [2, 5, 8] + [3, 6, 9] ``` """ @inline function eachslice(A::AbstractArray; dims)