Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable reduce_indices over AbstractArrays #194

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 55 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This file is machine-generated - editing it directly is not advised
glennmoy marked this conversation as resolved.
Show resolved Hide resolved

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[EllipsisNotation]]
git-tree-sha1 = "65dad386e877850e6fce4fc77f60fe75a468ce9d"
uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
version = "0.4.0"

[[IntervalSets]]
deps = ["Dates", "EllipsisNotation", "Statistics"]
git-tree-sha1 = "2daa370870d2a4d198642277d050aa7d34a7cad2"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.5.0"

[[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.3.0"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[RangeArrays]]
git-tree-sha1 = "b9039e93773ddcfc828f12aadf7115b4b4d225f5"
uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d"
version = "0.3.2"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AxisArrays"
uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
version = "0.4.3"
version = "0.4.4"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
5 changes: 5 additions & 0 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ reduced_indices(axs::Tuple{Vararg{Axis,N}}, region::Dims) where {N} =
reduced_indices0(axs::Tuple{Vararg{Axis,N}}, region::Dims) where {N} =
map((ax,d)->d∈region ? reduced_axis0(ax) : ax, axs, ntuple(identity, N))

reduced_indices(axs::Tuple{Vararg{Axis}}, regions::AbstractArray) =
reduced_indices(axs, Tuple(regions))
reduced_indices0(axs::Tuple{Vararg{Axis}}, regions::AbstractArray) =
reduced_indices0(axs, Tuple(regions))

@inline reduced_indices(axs::Tuple{Vararg{Axis}}, region::Type{<:Axis}) =
_reduced_indices(reduced_axis, (), region, axs...)
@inline reduced_indices0(axs::Tuple{Vararg{Axis}}, region::Type{<:Axis}) =
Expand Down
2 changes: 2 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ for C in arrays
@test (op(C, dims=Axis{:y}())) == C1
@test (op(C, dims=Axis{:x}())) == C2
@test (op(C, dims=(Axis{:y}(),Axis{:x}()))) == C12
@test (op(C, dims=[Axis{:y}(),Axis{:x}()])) == C12
end
end

Expand Down Expand Up @@ -343,6 +344,7 @@ for op in functions # together, cover both reduced_indices and reduced_indices0
@test (op(C, dims=Axis{:y}())) == C1
@test (op(C, dims=Axis{:x}())) == C2
@test (op(C, dims=(Axis{:y}(),Axis{:x}()))) == C12
@test (op(C, dims=[Axis{:y}(),Axis{:x}()])) == C12
end

C = AxisArray(collect(reshape(1:15,3,5)), Axis{:y}([:a,:b,:c]), Axis{:x}(["a","b","c","d","e"]))
Expand Down