Skip to content

Commit

Permalink
NEWS and compat annotation for each(row|col|slice) #29749 (#30245)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman authored and fredrikekre committed Dec 4, 2018
1 parent 7a5042a commit 7920a2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------
Expand Down
12 changes: 12 additions & 0 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))

Expand All @@ -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"))
Expand Down

0 comments on commit 7920a2a

Please sign in to comment.