We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9deb383 commit 4a0dc78Copy full SHA for 4a0dc78
src/splitdims.jl
@@ -73,6 +73,7 @@ end
73
end
74
75
@generated function slice_inds(i::CartesianIndex, ::Val{dims}, ::Val{n}) where {dims, n}
76
+ @assert length(i) == length(dims)
77
out = []
78
for j in 1:n
79
k = findfirst(==(j), dims)
@@ -96,7 +97,7 @@ Base.parent(a::SplitDimsArray) = a.parent
96
97
axes(a::SplitDimsArray{T, N, Dims}) where {T, N, Dims} = getindices(axes(parent(a)), Dims)
98
size(a::SplitDimsArray{T, N, Dims}) where {T, N, Dims} = getindices(size(parent(a)), Dims)
99
Base.IndexStyle(::SplitDimsArray) = Base.IndexCartesian()
-@propagate_inbounds function Base.getindex(a::SplitDimsArray{T, N, Dims}, i::Int...) where {T, N, Dims}
100
+@propagate_inbounds function Base.getindex(a::SplitDimsArray{T, N, Dims}, i::Vararg{Int, N}) where {T, N, Dims}
101
return view(parent(a), slice_inds(CartesianIndex(i), Val(Dims), Val(ndims(parent(a))))...)
102
103
test/splitdims.jl
@@ -34,12 +34,21 @@ end
34
@test splitdimsview([1 2; 3 4], (1, 2)) == tmp
35
tmp[1,2][] = 3; tmp[2,1][] = 2
36
@test splitdimsview([1 2; 3 4], (2, 1)) == tmp
37
+ # indexing
38
+ @test splitdimsview([1 2; 3 4], (1, 2))[2, 1] == fill(3)
39
+ @test splitdimsview([1 2; 3 4], (1, 2))[2] == fill(3)
40
+ @test splitdimsview([1 2; 3 4], (1, 2))[CartesianIndex(2)] == fill(3)
41
42
# Vector
43
@test splitdimsview([1,2,3]) == [fill(1, ()), fill(2, ()), fill(3, ())]
44
@test splitdimsview([1,2,3], (1,)) == [fill(1, ()), fill(2, ()), fill(3, ())]
45
@test splitdimsview([1,2,3], ()) == fill([1,2,3], ())
46
47
+ @test splitdimsview([1,2,3], (1,))[2] == fill(2)
48
+ @test splitdimsview([1,2,3], (1,))[CartesianIndex(2)] == fill(2)
49
50
# Array{0}
51
@test splitdimsview(fill(1, ())) == fill(fill(1, ()), ())
52
53
+ @test splitdimsview(fill(1, ()))[] == fill(1)
54
0 commit comments