Skip to content

Commit 1c15bbe

Browse files
authored
first attempt to have compatibility with EllipsisNotation.jl, cf. #39 (#41)
* first attempt to have compatibility with EllipsisNotation.jl, cf. #39 * revert 2184ee1 except new tests * restrict overwritten method of view to known index types * add tests for Cartesian indices * set version to v0.4.5
1 parent 1550dab commit 1c15bbe

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HybridArrays"
22
uuid = "1baab800-613f-4b0a-84e4-9cd3431bfbb9"
33
authors = ["Mateusz Baran <[email protected]>"]
4-
version = "0.4.4"
4+
version = "0.4.5"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -15,8 +15,9 @@ julia = "1"
1515

1616
[extras]
1717
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
18+
EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
1819
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1920
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2021

2122
[targets]
22-
test = ["Test", "Random", "ArrayInterface"]
23+
test = ["Test", "Random", "ArrayInterface", "EllipsisNotation"]

src/indexing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ end
298298

299299
@inline function Base.view(
300300
a::HybridArray{S},
301-
indices...,
301+
indices::Union{Int, AbstractArray, Colon}...,
302302
) where {S}
303303
inner_view = invoke(view, Tuple{AbstractArray, typeof(indices).parameters...}, a, indices...)
304304
return _view_hybrid(a, all_dynamic_fixed_val(S, indices...), inner_view, indices...)

test/nonstandard_indices.jl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
module TestEllipsisNotationCompat # use a module to avoid cluttering the global namespace
3+
4+
using EllipsisNotation
5+
using HybridArrays
6+
using Test
7+
8+
9+
@testset "Compatibility with EllipsisNotation" begin
10+
u_array = rand(2, 10)
11+
u_hybrid = HybridArray{Tuple{2, HybridArrays.Dynamic()}}(copy(u_array))
12+
@test u_hybrid u_array
13+
@test u_hybrid[1, ..] u_array[1, ..]
14+
@test u_hybrid[.., 1] u_array[.., 1]
15+
@test u_hybrid[..] u_array[..]
16+
17+
@test_broken typeof(u_hybrid[1, ..]) == typeof(u_hybrid[1, :])
18+
@test_broken typeof(u_hybrid[.., 1]) == typeof(u_hybrid[:, 1])
19+
@test typeof(u_hybrid[..]) == typeof(u_hybrid[:, :])
20+
21+
@inferred u_hybrid[1, ..]
22+
@inferred u_hybrid[.., 1]
23+
@inferred u_hybrid[..]
24+
25+
let new_values = rand(10)
26+
u_array[1, ..] .= new_values
27+
u_hybrid[1, ..] .= new_values
28+
@test u_hybrid u_array
29+
@test u_hybrid[1, ..] u_array[1, ..]
30+
@test u_hybrid[.., 1] u_array[.., 1]
31+
@test u_hybrid[..] u_array[..]
32+
end
33+
34+
let new_values = rand(2)
35+
u_array[.., 1] .= new_values
36+
u_hybrid[.., 1] .= new_values
37+
@test u_hybrid u_array
38+
@test u_hybrid[1, ..] u_array[1, ..]
39+
@test u_hybrid[.., 1] u_array[.., 1]
40+
@test u_hybrid[..] u_array[..]
41+
end
42+
43+
let new_values = rand(2, 10)
44+
u_array .= new_values
45+
u_hybrid .= new_values
46+
@test u_hybrid u_array
47+
@test u_hybrid[1, ..] u_array[1, ..]
48+
@test u_hybrid[.., 1] u_array[.., 1]
49+
@test u_hybrid[..] u_array[..]
50+
end
51+
end
52+
53+
54+
@testset "Compatibility with Cartesian indices" begin
55+
u_array = rand(2, 3, 4)
56+
u_hybrid = HybridArray{Tuple{2, 3, 4}}(copy(u_array))
57+
@test u_hybrid u_array
58+
@test u_hybrid[CartesianIndex(1, 2), :] u_array[CartesianIndex(1, 2), :]
59+
@test u_hybrid[:, CartesianIndex(1, 2)] u_array[:, CartesianIndex(1, 2)]
60+
61+
@test_broken typeof(u_hybrid[CartesianIndex(1, 2), :]) == typeof(u_hybrid[1, 2, :])
62+
@test_broken typeof(u_hybrid[:, CartesianIndex(1, 2)]) == typeof(u_hybrid[:, 1, 2])
63+
64+
@inferred u_hybrid[CartesianIndex(1, 2), :]
65+
@inferred u_hybrid[:, CartesianIndex(1, 2)]
66+
@inferred u_hybrid[CartesianIndex(1, 2, 3)]
67+
68+
let new_values = rand(4)
69+
u_array[CartesianIndex(1, 2), :] .= new_values
70+
u_hybrid[CartesianIndex(1, 2), :] .= new_values
71+
@test u_hybrid u_array
72+
@test u_hybrid[CartesianIndex(1, 2), :] u_array[CartesianIndex(1, 2), :]
73+
@test u_hybrid[:, CartesianIndex(1, 2)] u_array[:, CartesianIndex(1, 2)]
74+
end
75+
76+
let new_values = rand(2)
77+
u_array[:, CartesianIndex(1, 2)] .= new_values
78+
u_hybrid[:, CartesianIndex(1, 2)] .= new_values
79+
@test u_hybrid u_array
80+
@test u_hybrid[CartesianIndex(1, 2), :] u_array[CartesianIndex(1, 2), :]
81+
@test u_hybrid[:, CartesianIndex(1, 2)] u_array[:, CartesianIndex(1, 2)]
82+
end
83+
end
84+
85+
86+
end # module

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ include("arraymath.jl")
158158
include("broadcast.jl")
159159
include("linalg.jl")
160160
include("ssubarray.jl")
161+
include("nonstandard_indices.jl")
161162
if VERSION >= v"1.2"
162163
include("array_interface_compat.jl")
163164
end

0 commit comments

Comments
 (0)