Skip to content

Commit

Permalink
Added window iterator for named dimensions method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokazama committed Jun 18, 2020
1 parent 0331647 commit 5e733ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AxisIndices"
uuid = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11"
authors = ["Tokazama <zchristensen7@gmail.com>"]
version = "0.4.2"
version = "0.4.3"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/observations.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ julia> data[observations = :subject_1]
```

But there are a number of convenient methods for accessing observation data with this module.
...but there are a number of convenient methods for accessing observation data with this module.
```jldoctest observation_docs
julia> using AxisIndices.ObservationDims
Expand Down
9 changes: 9 additions & 0 deletions src/Interface/names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ macro defdim(name, condition)
Returns the axis corresponding to the $name dimension.
"""

name_axis_itr = """
$name_axis(x, size[; first_pad=nothing, last_pad=nothing, stride=nothing, dilation=nothing])
Returns an `AxisIterator` along the $name axis.
"""

name_indices = Symbol(name, :_indices)
name_indices_doc = """
$name_indices(x)
Expand Down Expand Up @@ -170,6 +176,9 @@ macro defdim(name, condition)
@doc $name_axis_doc
@inline $name_axis(x) = axes(x, $name_dim(x))

@doc $name_axis_itr
@inline $name_axis(x, sz; kwargs...) = AxisIterator(axes(x, $name_dim(x)), sz; kwargs...)

@doc $name_keys_doc
@inline $name_keys(x) = keys($name_axis(x))

Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ end
itr, state = iterate(obs_iter, state)
@test itr == [5, 6]
@test isnothing(iterate(obs_iter, state))

A = NamedAxisArray(reshape(1:40, 2, 20), x = 2:3, observations = 1:20)
@test collect(obs_axis(A, 2)) == [1:2, 3:4, 5:6, 7:8, 9:10, 11:12, 13:14, 15:16, 17:18,19:20]
end

include("table_tests.jl")
Expand Down

2 comments on commit 5e733ee

@Tokazama
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

@defdim has a window iterator method now too

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/16557

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.3 -m "<description of version>" 5e733eec690b03499b47ba17ef7003d8ac2ee191
git push origin v0.4.3

Please sign in to comment.