diff --git a/Project.toml b/Project.toml index cddcafcb..7017acb4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AxisIndices" uuid = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11" authors = ["Tokazama "] -version = "0.4.2" +version = "0.4.3" [deps] ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" diff --git a/docs/src/observations.md b/docs/src/observations.md index a80e704b..36e8c113 100644 --- a/docs/src/observations.md +++ b/docs/src/observations.md @@ -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 diff --git a/src/Interface/names.jl b/src/Interface/names.jl index d6912f05..d31af304 100644 --- a/src/Interface/names.jl +++ b/src/Interface/names.jl @@ -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) @@ -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)) diff --git a/test/runtests.jl b/test/runtests.jl index 49e44e5b..a8b967c8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")