Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/StarWarsArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ Base.setindex!(A::StarWarsArray, v, i::Int) =
Base.setindex!(A::StarWarsArray{T,N}, v, i::Vararg{Int,N}) where {T,N} =
setindex!(parent(A), v, index.(i, size(parent(A)), order(A))...)

# Axes
Base.axes(A::StarWarsArray{T,N,P,OriginalOrder}) where {T,N,P} =
# StarWarsArrays.axes
axes(A::StarWarsArray{T,N,P,OriginalOrder}) where {T,N,P} =
map(i->index.(i, length(A), order(A)), machete_view_index.(size(A)))

Base.axes(A::StarWarsArray{T,N,P,MacheteOrder}) where {T,N,P} =
axes(A::StarWarsArray{T,N,P,MacheteOrder}) where {T,N,P} =
map(i->index.(i .+ 1, length(A), MacheteOrder), machete_view_index.(size(A)))

# StarWarsArrays.eachindex
eachindex(A::StarWarsArray{<: Any,1}) = first(axes(A))
eachindex(A::StarWarsArray) = vec(LinearIndices(size(A))[axes(A)...])

# Iteration
function iterate_revindex(i::Int, ::Type{OriginalOrder})
if 1 <= i <= 3
Expand Down
18 changes: 12 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import StarWarsArrays: StarWarsError, order
" 4\n 5\n 6\n 1\n 2\n 3\n 7\n 8\n 9"
v[4] = -42
@test v[4] == -42
@test axes(v) == ([4, 5, 6, 1, 2, 3, 7, 8, 9],)
@test eachindex(v) == [4, 5, 6, 1, 2, 3, 7, 8, 9]
@test StarWarsArrays.axes(v) == ([4, 5, 6, 1, 2, 3, 7, 8, 9],)
@test StarWarsArrays.eachindex(v) == [4, 5, 6, 1, 2, 3, 7, 8, 9]
@test axes(v) === (Base.OneTo(length(v)),)
@test eachindex(v) === Base.OneTo(length(v))
@test length(v) == 9
@test size(v) == (9,)
for (idx, x) in enumerate(v)
Expand All @@ -39,7 +41,8 @@ import StarWarsArrays: StarWarsError, order
@test m[4] == -42
m[1] = 0
@test m[1,4] == 0
@test axes(m) == ([4, 5, 6, 1, 2, 3, 7, 8, 9], [4, 5, 6, 1, 2, 3, 7, 8, 9])
@test StarWarsArrays.axes(m) == ([4, 5, 6, 1, 2, 3, 7, 8, 9], [4, 5, 6, 1, 2, 3, 7, 8, 9])
@test axes(m) == (Base.OneTo(size(m,1)), Base.OneTo(size(m,2)))
@test length(m) == 81
@test size(m) == (9, 9)
for (idx, x) in enumerate(m)
Expand All @@ -64,8 +67,10 @@ end
" 3\n 4\n 1\n 2\n 5\n 6\n 7\n 8"
v[4] = -42
@test v[4] == -42
@test axes(v) == ([3, 4, 1, 2, 5, 6, 7, 8],)
@test eachindex(v) == [3, 4, 1, 2, 5, 6, 7, 8]
@test StarWarsArrays.axes(v) == ([3, 4, 1, 2, 5, 6, 7, 8],)
@test StarWarsArrays.eachindex(v) == [3, 4, 1, 2, 5, 6, 7, 8]
@test axes(v) == (Base.OneTo(length(v)),)
@test eachindex(v) == Base.OneTo(length(v))
@test length(v) == 8
@test size(v) == (8,)
for (idx, x) in enumerate(v)
Expand All @@ -91,7 +96,8 @@ end
@test m[4] == -42
m[2] = 0
@test m[2,4] == 0
@test axes(m) == ([3, 4, 1, 2, 5, 6, 7, 8], [3, 4, 1, 2, 5, 6, 7, 8])
@test StarWarsArrays.axes(m) == ([3, 4, 1, 2, 5, 6, 7, 8], [3, 4, 1, 2, 5, 6, 7, 8])
@test axes(m) == (Base.OneTo(size(m,1)), Base.OneTo(size(m,2)))
@test length(m) == 64
@test size(m) == (8, 8)
for (idx, x) in enumerate(m)
Expand Down