Skip to content

Commit add8f06

Browse files
authored
Merge pull request #68 from Tokazama/similar
Reduce similar ambiguities
2 parents 8f3ce1f + 9693bb7 commit add8f06

26 files changed

+495
-397
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
name: CI
22
on:
3-
pull_request:
4-
branches:
5-
- master
6-
push:
7-
branches:
8-
- master
9-
tags: '*'
3+
- push
4+
- pull_request
105
jobs:
116
test:
127
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
@@ -15,30 +10,55 @@ jobs:
1510
fail-fast: false
1611
matrix:
1712
version:
18-
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
13+
- '1'
1914
- 'nightly'
2015
os:
2116
- ubuntu-latest
17+
- macOS-latest
18+
- windows-latest
2219
arch:
2320
- x64
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: julia-actions/setup-julia@v1
24+
with:
25+
version: ${{ matrix.version }}
26+
arch: ${{ matrix.arch }}
27+
- uses: actions/cache@v1
28+
env:
29+
cache-name: cache-artifacts
30+
with:
31+
path: ~/.julia/artifacts
32+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
33+
restore-keys: |
34+
${{ runner.os }}-test-${{ env.cache-name }}-
35+
${{ runner.os }}-test-
36+
${{ runner.os }}-
37+
- uses: julia-actions/julia-buildpkg@v1
38+
- uses: julia-actions/julia-runtest@v1
39+
- uses: julia-actions/julia-processcoverage@v1
40+
- uses: codecov/codecov-action@v1
41+
with:
42+
file: lcov.info
2443
docs:
2544
name: Documentation
2645
runs-on: ubuntu-latest
2746
steps:
2847
- uses: actions/checkout@v2
2948
- uses: julia-actions/setup-julia@v1
3049
with:
31-
version: '1'
50+
version: '1.6'
3251
- run: |
33-
git config --global user.name name
34-
git config --global user.email email
35-
git config --global github.user username
52+
julia --project=docs -e '
53+
using Pkg
54+
Pkg.develop(PackageSpec(path=pwd()))
55+
Pkg.instantiate()'
3656
- run: |
3757
julia --project=docs -e '
38-
using Pkg;
39-
Pkg.develop(PackageSpec(path=pwd()));
40-
Pkg.instantiate();
41-
include("docs/make.jl");'
58+
using Documenter: doctest
59+
using AxisIndices
60+
doctest(AxisIndices)'
61+
- run: julia --project=docs docs/make.jl
4262
env:
4363
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
64+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AxisIndices"
22
uuid = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11"
33
authors = ["Tokazama <[email protected]>"]
4-
version = "0.7.1"
4+
version = "0.7.2"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ When using functions as indexing arguments, the axis corresponding to each argum
3939

4040
```julia
4141
julia> ax[:, >(2)]
42-
2×2 AxisArray(::Array{Int64,2}
42+
2×2 AxisArray(::Matrix{Int64}
4343
• axes:
4444
1 = 1:2
4545
2 = 1:2
@@ -65,7 +65,7 @@ julia> inds_before = firstindex(axis):(not_index - 1); # all of the indices bef
6565
julia> inds_after = (not_index + 1):lastindex(axis); # all of the indices after `not_index`
6666

6767
julia> x[:, vcat(inds_before, inds_after)]
68-
2×3 Array{Int64,2}:
68+
2×3 Matrix{Int64}:
6969
1 5 7
7070
2 6 8
7171

@@ -74,7 +74,7 @@ julia> x[:, vcat(inds_before, inds_after)]
7474
Using an `AxisArray`, this only requires one line of code
7575
```julia
7676
julia> ax[:, !=(2)]
77-
2×3 AxisArray(::Array{Int64,2}
77+
2×3 AxisArray(::Matrix{Int64}
7878
• axes:
7979
1 = 1:2
8080
2 = 1:3
@@ -89,7 +89,7 @@ We can using `ChainedFixes` to combine multiple functions.
8989
julia> using ChainedFixes
9090

9191
julia> ax[:, or(<(2), >(3))] # == ax[:, [1, 4]]
92-
2×2 AxisArray(::Array{Int64,2}
92+
2×2 AxisArray(::Matrix{Int64}
9393
• axes:
9494
1 = 1:2
9595
2 = 1:2
@@ -99,7 +99,7 @@ julia> ax[:, or(<(2), >(3))] # == ax[:, [1, 4]]
9999
2 2 8
100100

101101
julia> ax[:, and(>(1), <(4))]
102-
2×2 AxisArray(::Array{Int64,2}
102+
2×2 AxisArray(::Matrix{Int64}
103103
• axes:
104104
1 = 1:2
105105
2 = 1:2
@@ -136,7 +136,7 @@ julia> ax = AxisArray(x, nothing, (.1:.1:.4)s)
136136
We can still use functions to access these elements
137137
```julia
138138
julia> ax[:, <(0.3s)]
139-
2×2 AxisArray(::Array{Int64,2}
139+
2×2 AxisArray(::Matrix{Int64}
140140
• axes:
141141
1 = 1:2
142142
2 = (0.1:0.1:0.2) s
@@ -155,7 +155,7 @@ julia> ax[1, 0.1s]
155155
...or as intervals.
156156
```julia
157157
julia> ax[:, 0.1s..0.3s]
158-
2×3 AxisArray(::Array{Int64,2}
158+
2×3 AxisArray(::Matrix{Int64}
159159
• axes:
160160
1 = 1:2
161161
2 = (0.1:0.1:0.3) s
@@ -182,7 +182,7 @@ julia> ax = AxisArray(x, 2:3, 2:5)
182182
3 2 4 6 8
183183

184184
julia> ax[:,2]
185-
2-element AxisArray(::Array{Int64,1}
185+
2-element AxisArray(::Vector{Int64}
186186
• axes:
187187
1 = 2:3
188188
)
@@ -259,7 +259,7 @@ julia> ArrayInterface.known_length(typeof(ax)) # size is known at compile time
259259
julia> ax[1:2, 1:2] .= x[1:2, 1:2]; # underlying type is mutable `Array`, so we can assign new values
260260

261261
julia> ax
262-
2×2 AxisArray(::Array{Int64,2}
262+
2×2 AxisArray(::Matrix{Int64}
263263
• axes:
264264
1 = 1:2
265265
2 = 1:2
@@ -274,7 +274,7 @@ julia> ax
274274

275275
If each element along a particular axis corresponds to a field of a type then we can encode that information in the axis.
276276
```julia
277-
julia> ax = AxisArray(reshape(1:4, 2, 2), StructAxis{Complex{Float64}}(), [:a, :b])
277+
julia> ax = AxisArray(reshape(1:4, 2, 2), StructAxis{ComplexF64}(), [:a, :b])
278278
2×2 AxisArray(reshape(::UnitRange{Int64}, 2, 2)
279279
• axes:
280280
1 = [:re, :im]
@@ -289,7 +289,7 @@ julia> ax = AxisArray(reshape(1:4, 2, 2), StructAxis{Complex{Float64}}(), [:a, :
289289
We can then create a lazy mapping of that type across views of the array.
290290
```julia
291291
julia> axview = struct_view(ax)
292-
2-element AxisArray(mappedarray(Complex{Float64}, view(reshape(::UnitRange{Int64}, 2, 2), 1, :), view(reshape(::UnitRange{Int64}, 2, 2), 2, :))
292+
2-element AxisArray(mappedarray(ComplexF64, view(reshape(::UnitRange{Int64}, 2, 2), 1, :), view(reshape(::UnitRange{Int64}, 2, 2), 2, :))
293293
• axes:
294294
1 = [:a, :b]
295295
)
@@ -313,7 +313,7 @@ julia> mx = attach_metadata(AxisArray(x))
313313
• axes:
314314
1 = 1:2
315315
2 = 1:4
316-
), ::Dict{Symbol,Any}
316+
), ::Dict{Symbol, Any}
317317
• metadata:
318318
)
319319
1 2 3 4
@@ -345,7 +345,7 @@ We can also pad axes in various ways.
345345
julia> x = [:a, :b, :c, :d];
346346

347347
julia> AxisArray(x, circular_pad(first_pad=2, last_pad=2))
348-
8-element AxisArray(::Array{Symbol,1}
348+
8-element AxisArray(::Vector{Symbol}
349349
• axes:
350350
1 = -1:6
351351
)
@@ -360,7 +360,7 @@ julia> AxisArray(x, circular_pad(first_pad=2, last_pad=2))
360360
6 :b
361361

362362
julia> AxisArray(x, replicate_pad(first_pad=2, last_pad=2))
363-
8-element AxisArray(::Array{Symbol,1}
363+
8-element AxisArray(::Vector{Symbol}
364364
• axes:
365365
1 = -1:6
366366
)
@@ -375,7 +375,7 @@ julia> AxisArray(x, replicate_pad(first_pad=2, last_pad=2))
375375
6 :d
376376

377377
julia> AxisArray(x, symmetric_pad(first_pad=2, last_pad=2))
378-
8-element AxisArray(::Array{Symbol,1}
378+
8-element AxisArray(::Vector{Symbol}
379379
• axes:
380380
1 = -1:6
381381
)
@@ -390,7 +390,7 @@ julia> AxisArray(x, symmetric_pad(first_pad=2, last_pad=2))
390390
6 :b
391391

392392
julia> AxisArray(x, reflect_pad(first_pad=2, last_pad=2))
393-
8-element AxisArray(::Array{Symbol,1}
393+
8-element AxisArray(::Vector{Symbol}
394394
• axes:
395395
1 = -1:6
396396
)

docs/src/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ julia> x[:one] == y["one"] == z[Second(1)]
129129
true
130130
131131
julia> x[[:one, :two]]
132-
2-element AxisArray(::Array{Int64,1}
132+
2-element AxisArray(::Vector{Int64}
133133
• axes:
134134
1 = [:one, :two]
135135
)
@@ -190,7 +190,7 @@ Axis((1.5:0.5:2.0) s => SimpleAxis(2:3))
190190
However, we can't ensure that the resulting range will have a step of one in other cases so only the indices are returned.
191191
```jldoctest indexing_examples
192192
julia> time1[1:2:3]
193-
2-element AxisArray(::StepRange{Int64,Int64}
193+
2-element AxisArray(::StepRange{Int64, Int64}
194194
• axes:
195195
1 = (1.5:1.0:2.5) s
196196
)
@@ -199,9 +199,9 @@ julia> time1[1:2:3]
199199
2.5 s 3
200200
201201
julia> time1[[1, 2, 3]]
202-
3-element AxisArray(::Array{Int64,1}
202+
3-element AxisArray(::Vector{Int64}
203203
• axes:
204-
1 = Unitful.Quantity{Float64,𝐓,Unitful.FreeUnits{(s,),𝐓,nothing}}[1.5 s, 2.0 s, 2.5 s]
204+
1 = Unitful.Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}[1.5 s, 2.0 s, 2.5 s]
205205
)
206206
1
207207
1.5 s 1
@@ -294,7 +294,7 @@ julia> using AxisIndices
294294
julia> A_base = [1 2; 3 4];
295295
296296
julia> A_axis = AxisArray(A_base, ["a", "b"], [:one, :two])
297-
2×2 AxisArray(::Array{Int64,2}
297+
2×2 AxisArray(::Matrix{Int64}
298298
• axes:
299299
1 = ["a", "b"]
300300
2 = [:one, :two]
@@ -319,7 +319,7 @@ julia> A_axis = AxisArray{Int}(undef, ["a", "b"], [:one, :two]);
319319
julia> A_axis[:,:] = A_base;
320320
321321
julia> A_axis
322-
2×2 AxisArray(::Array{Int64,2}
322+
2×2 AxisArray(::Matrix{Int64}
323323
• axes:
324324
1 = ["a", "b"]
325325
2 = [:one, :two]
@@ -335,11 +335,11 @@ We can also attach metadata to an array.
335335
julia> using Metadata
336336
337337
julia> attach_metadata(AxisArray(A_base, (["a", "b"], [:one, :two])), (m1 = 1, m2 = 2))
338-
2×2 attach_metadata(AxisArray(::Array{Int64,2}
338+
2×2 attach_metadata(AxisArray(::Matrix{Int64}
339339
• axes:
340340
1 = ["a", "b"]
341341
2 = [:one, :two]
342-
), ::NamedTuple{(:m1, :m2),Tuple{Int64,Int64}}
342+
), ::NamedTuple{(:m1, :m2), Tuple{Int64, Int64}}
343343
• metadata:
344344
m1 = 1
345345
m2 = 2
@@ -349,11 +349,11 @@ julia> attach_metadata(AxisArray(A_base, (["a", "b"], [:one, :two])), (m1 = 1, m
349349
"b" 3 4
350350
351351
julia> attach_metadata(NamedAxisArray{(:xdim, :ydim)}(A_base, ["a", "b"], [:one, :two]), (m1 = 1, m2 = 2))
352-
2×2 NamedDimsArray(attach_metadata(AxisArray(::Array{Int64,2}
352+
2×2 NamedDimsArray(attach_metadata(AxisArray(::Matrix{Int64}
353353
• axes:
354354
xdim = ["a", "b"]
355355
ydim = [:one, :two]
356-
), ::NamedTuple{(:m1, :m2),Tuple{Int64,Int64}}
356+
), ::NamedTuple{(:m1, :m2), Tuple{Int64, Int64}}
357357
• metadata:
358358
m1 = 1
359359
m2 = 2
@@ -372,7 +372,7 @@ offset by 4 and the last indices are centered.
372372

373373
```jldoctest indexing_examples
374374
julia> AxisArray(ones(3,3), offset(4), center)
375-
3×3 AxisArray(::Array{Float64,2}
375+
3×3 AxisArray(::Matrix{Float64}
376376
• axes:
377377
1 = 5:7
378378
2 = -1:1

src/AxisIndices.jl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ export
7070

7171
const ArrayInitializer = Union{UndefInitializer, Missing, Nothing}
7272

73-
# Val wraps the number of axes to retain
74-
naxes(A::AbstractArray, v::Val) = naxes(axes(A), v)
75-
naxes(axs::Tuple, v::Val{N}) where {N} = _naxes(axs, N)
76-
@inline function _naxes(axs::Tuple, i::Int)
77-
if i === 0
78-
return ()
79-
else
80-
return (first(axs), _naxes(tail(axs), i - 1)...)
81-
end
82-
end
83-
84-
@inline function _naxes(axs::Tuple{}, i::Int)
85-
if i === 0
86-
return ()
87-
else
88-
return (SimpleAxis(1), _naxes((), i - 1)...)
89-
end
90-
end
91-
9273
include("errors.jl")
9374
include("abstract_axis.jl")
9475
include("axis_array.jl")
@@ -137,15 +118,8 @@ include("centered_axis.jl")
137118
include("identity_axis.jl")
138119
include("padded_axis.jl")
139120
include("struct_axis.jl")
140-
141-
# TODO assign_indices tests
142-
function assign_indices(axis, inds)
143-
if can_change_size(axis) && !((known_length(inds) === nothing) || known_length(inds) === known_length(axis))
144-
return unsafe_reconstruct(axis, inds)
145-
else
146-
return axis
147-
end
148-
end
121+
include("similar.jl")
122+
include("utils.jl")
149123

150124
"""
151125
is_key([collection,] arg) -> Bool

src/abstract_axis.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ and [`IdentityAxis`](@ref) for more details and examples.
2020
"""
2121
abstract type AbstractOffsetAxis{I,Inds,F} <: AbstractAxis{I,Inds} end
2222

23-
2423
"""
2524
IndexAxis
2625
@@ -160,7 +159,7 @@ ArrayInterface.known_first(::Type{T}) where {T<:AbstractAxis} = known_first(pare
160159
Base.summary(io::IO, axis::AbstractAxis) = show(io, axis)
161160

162161
function reverse_keys(axis::AbstractAxis, newinds::AbstractUnitRange)
163-
return Axis(reverse(keys(axis)), newinds; checks=NoChecks)
162+
return initialize_axis(reverse(keys(axis)), compose_axis(newinds))
164163
end
165164

166165
###

0 commit comments

Comments
 (0)