Skip to content

Commit

Permalink
Merge pull request #48 from ArnoStrouwen/master
Browse files Browse the repository at this point in the history
add formatting toml
  • Loading branch information
ChrisRackauckas committed Oct 26, 2022
2 parents 41071e9 + 8b21392 commit 7b0d873
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 80 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
@@ -0,0 +1 @@
style = "sciml"
20 changes: 8 additions & 12 deletions docs/make.jl
Expand Up @@ -2,17 +2,13 @@ using Documenter, EllipsisNotation

include("pages.jl")

makedocs(
sitename = "EllipsisNotation.jl",
authors = "Chris Rackauckas",
modules = [EllipsisNotation],
clean = true,
doctest = false,
format = Documenter.HTML(
assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/EllipsisNotation/stable/",
),
pages = pages,
)
makedocs(sitename = "EllipsisNotation.jl",
authors = "Chris Rackauckas",
modules = [EllipsisNotation],
clean = true,
doctest = false,
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/EllipsisNotation/stable/"),
pages = pages)

deploydocs(repo = "github.com/SciML/EllipsisNotation.jl.git"; push_preview = true)
14 changes: 7 additions & 7 deletions src/EllipsisNotation.jl
Expand Up @@ -50,24 +50,24 @@ true
"""
const .. = Ellipsis()

@inline function to_indices(
A,
inds::NTuple{M,Any},
I::Tuple{Ellipsis,Vararg{Any,N}},
) where {M,N}
@inline function to_indices(A,
inds::NTuple{M, Any},
I::Tuple{Ellipsis, Vararg{Any, N}}) where {M, N}
# Align the remaining indices to the tail of the `inds`
colons = ntuple(n -> Colon(), M - _ndims_index(I) + 1)
to_indices(A, inds, (colons..., tail(I)...))
end

@inline _ndims_index(inds::Tuple{}) = ArrayInterface.static(0)
@inline _ndims_index(inds::Tuple) =
@inline function _ndims_index(inds::Tuple)
ArrayInterface.ndims_index(inds[1]) + _ndims_index(tail(inds))
end

ArrayInterface.is_splat_index(::Type{Ellipsis}) = ArrayInterface.static(true)
ArrayInterface.ndims_index(::Type{Ellipsis}) = ArrayInterface.static(1)
ArrayInterface.to_index(x, ::Ellipsis) =
function ArrayInterface.to_index(x, ::Ellipsis)
ntuple(i -> ArrayInterface.indices(x, i), Val(ndims(x)))
end

export ..

Expand Down
91 changes: 34 additions & 57 deletions test/basic.jl
Expand Up @@ -3,54 +3,36 @@

A = Array{Int}(undef, 2, 4, 2)

A[.., 1] = [
2 1 4 5
2 2 3 6
]

A[.., 2] = [
3 2 6 5
3 2 6 6
]

@test A[:, :, 1] == [
2 1 4 5
2 2 3 6
]

@test A[:, :, 2] == [
3 2 6 5
3 2 6 6
]

@test A[:, .., 1] == [
2 1 4 5
2 2 3 6
]

@test A[:, .., 1] == [
2 1 4 5
2 2 3 6
]

A[1, ..] = reshape(
[
3 4
5 6
4 5
6 7
],
1,
4,
2,
)

B = [
3 4
5 6
4 5
6 7
]
A[.., 1] = [2 1 4 5
2 2 3 6]

A[.., 2] = [3 2 6 5
3 2 6 6]

@test A[:, :, 1] == [2 1 4 5
2 2 3 6]

@test A[:, :, 2] == [3 2 6 5
3 2 6 6]

@test A[:, .., 1] == [2 1 4 5
2 2 3 6]

@test A[:, .., 1] == [2 1 4 5
2 2 3 6]

A[1, ..] = reshape([3 4
5 6
4 5
6 7],
1,
4,
2)

B = [3 4
5 6
4 5
6 7]

@test B == reshape(A[1, ..], 4, 2) == reshape(view(A, 1, ..), 4, 2)

Expand Down Expand Up @@ -92,18 +74,15 @@ C[1, 1] += 1
@test ArrayInterface.getindex(A, :, :, 1) == [2 1 4 5; 2 2 3 6]
@test ArrayInterface.getindex(A, :, :, 2) == [3 2 6 5; 3 2 6 6]


@test ArrayInterface.getindex(A, :, .., 1) == [2 1 4 5; 2 2 3 6]
@test ArrayInterface.getindex(A, :, .., 2) == [3 2 6 5; 3 2 6 6]

ArrayInterface.setindex!(A, reshape([3 4; 5 6; 4 5; 6 7], 1, 4, 2), 1, ..)

B = [
3 4
5 6
4 5
6 7
]
B = [3 4
5 6
4 5
6 7]

@test B ==
reshape(ArrayInterface.getindex(A, 1, ..), 4, 2) ==
Expand All @@ -123,6 +102,4 @@ C[1, 1] += 1
@test B == C
C[1, 1] += 1
@test B != C

end

2 changes: 1 addition & 1 deletion test/cartesian.jl
Expand Up @@ -6,5 +6,5 @@

@test A[.., 1:1, 2:2, 1:3] == A[.., CartesianIndices((1:1, 2:2, 1:3))]
@test A[1:1, .., 2:2, 1:3] == A[1:1, .., CartesianIndices((2:2, 1:3))]
@test A[1:2, 2, .., 1:3] == A[CartesianIndices((1:2,)), 2, .., CartesianIndices((1:3),)]
@test A[1:2, 2, .., 1:3] == A[CartesianIndices((1:2,)), 2, .., CartesianIndices((1:3))]
end
6 changes: 3 additions & 3 deletions test/more_generic.jl
@@ -1,7 +1,7 @@
B = Array{Int}(undef, 2, 3, 4, 5, 6)

n = 0
for i5 = 1:6, i4 = 1:5, i3 = 1:4
for i5 in 1:6, i4 in 1:5, i3 in 1:4
global n += 1
B[.., i3, i4, i5] .= n
end
Expand All @@ -26,7 +26,7 @@ end
C = Array{Int}(undef, 2, 3, 4, 5, 6)

n = 0
for i3 = 1:4, i2 = 1:3, i1 = 1:2
for i3 in 1:4, i2 in 1:3, i1 in 1:2
global n += 1
C[i1, i2, i3, ..] .= n
end
Expand All @@ -50,4 +50,4 @@ end

D = ones(Int, 1, 2, 3, 4)
D[1, .., 2] .= 2
@test D == [i1 == 1 && i4 == 2 ? 2 : 1 for i1 = 1:1, i2 = 1:2, i3 = 1:3, i4 = 1:4]
@test D == [i1 == 1 && i4 == 2 ? 2 : 1 for i1 in 1:1, i2 in 1:2, i3 in 1:3, i4 in 1:4]

0 comments on commit 7b0d873

Please sign in to comment.