diff --git a/NEWS.md b/NEWS.md index 4ea4b13021399..4c08456ddcccf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,6 +34,7 @@ New library functions * `splitpath(p::String)` function, which is the opposite of `joinpath(parts...)`: it splits a filepath into its components ([#28156]). * `isnothing(::Any)` function, to check whether something is a `Nothing`, returns a `Bool` ([#29679]). * `getpid(::Process)` method ([#24064]). + * `eachrow`, `eachcol` and `eachslice` functions provide efficient iterators over slices of arrays ([#29749]). Standard library changes ------------------------ diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 5b04fa310e740..eb435b786a831 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -413,7 +413,11 @@ end Create a generator that iterates over the first dimension of vector or matrix `A`, returning the rows as views. + See also [`eachcol`](@ref) and [`eachslice`](@ref). + +!!! compat "Julia 1.1" + This function requires at least Julia 1.1. """ eachrow(A::AbstractVecOrMat) = (view(A, i, :) for i in axes(A, 1)) @@ -423,7 +427,11 @@ eachrow(A::AbstractVecOrMat) = (view(A, i, :) for i in axes(A, 1)) Create a generator that iterates over the second dimension of matrix `A`, returning the columns as views. + See also [`eachrow`](@ref) and [`eachslice`](@ref). + +!!! compat "Julia 1.1" + This function requires at least Julia 1.1. """ eachcol(A::AbstractVecOrMat) = (view(A, :, i) for i in axes(A, 2)) @@ -435,7 +443,11 @@ the data from the other dimensions in `A`. Only a single dimension in `dims` is currently supported. Equivalent to `(view(A,:,:,...,i,:,: ...)) for i in axes(A, dims))`, where `i` is in position `dims`. + See also [`eachrow`](@ref), [`eachcol`](@ref), and [`selectdim`](@ref). + +!!! compat "Julia 1.1" + This function requires at least Julia 1.1. """ @inline function eachslice(A::AbstractArray; dims) length(dims) == 1 || throw(ArgumentError("only single dimensions are supported"))