Skip to content

Commit beecd45

Browse files
authored
Remove version check (#731)
* Remove VERSION checks in source files * Remove version checks in tests * Add drop clarification to eachslice docstring for DimArray
1 parent d133571 commit beecd45

File tree

10 files changed

+141
-185
lines changed

10 files changed

+141
-185
lines changed

benchmarks/benchmarks.jl

+10-11
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,16 @@ a = rand(5, 4, 3);
8080
da = DimArray(a, (Y((1u"m", 5u"m")), X(1:4), Ti(1:3)))
8181
dimz = dims(da)
8282

83-
if VERSION > v"1.1-"
84-
suite["eachslice"] = BenchmarkGroup()
85-
suite["eachslice"]["array_intdim"] = @benchmarkable (()->eachslice($a; dims = 2))();
86-
suite["eachslice"]["dimarray_intdim"] = @benchmarkable (()->eachslice($da; dims = 2))();
87-
suite["eachslice"]["dimarray_dim"] = @benchmarkable (()->eachslice($da; dims = Y()))();
88-
suite["eachslice_to_vector"] = BenchmarkGroup()
89-
suite["eachslice_to_vector"]["array_intdim"] = @benchmarkable [slice for slice in eachslice($a; dims = 2)];
90-
suite["eachslice_to_vector"]["dimarray_intdim"] = @benchmarkable [slice for slice in eachslice($da; dims = 2)];
91-
suite["eachslice_to_vector"]["dimarray_dim"] = @benchmarkable [slice for slice in eachslice($da; dims = X())];
92-
# @test [slice for slice in eachslice(da; dims=1)] == [slice for slice in eachslice(da; dims=Y)]
93-
end
83+
suite["eachslice"] = BenchmarkGroup()
84+
suite["eachslice"]["array_intdim"] = @benchmarkable (()->eachslice($a; dims = 2))();
85+
suite["eachslice"]["dimarray_intdim"] = @benchmarkable (()->eachslice($da; dims = 2))();
86+
suite["eachslice"]["dimarray_dim"] = @benchmarkable (()->eachslice($da; dims = Y()))();
87+
suite["eachslice_to_vector"] = BenchmarkGroup()
88+
suite["eachslice_to_vector"]["array_intdim"] = @benchmarkable [slice for slice in eachslice($a; dims = 2)];
89+
suite["eachslice_to_vector"]["dimarray_intdim"] = @benchmarkable [slice for slice in eachslice($da; dims = 2)];
90+
suite["eachslice_to_vector"]["dimarray_dim"] = @benchmarkable [slice for slice in eachslice($da; dims = X())];
91+
# @test [slice for slice in eachslice(da; dims=1)] == [slice for slice in eachslice(da; dims=Y)]
92+
9493

9594

9695
suite["mean"] = BenchmarkGroup()

src/Dimensions/dimunitrange.jl

-13
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,13 @@ for f in [:length, :isempty, :first, :last]
2525
@eval @inline Base.$f(r::DimUnitRange) = Base.$f(parent(r))
2626
end
2727
@inline Base.axes(r::DimUnitRange) = (r,)
28-
if VERSION < v"1.8.2"
29-
# On recent Julia versions, these don't need to be defined, and defining them may
30-
# increase validations, see https://github.com/JuliaArrays/OffsetArrays.jl/pull/311
31-
Base.axes1(r::DimUnitRange) = r
32-
for f in [:firstindex, :lastindex]
33-
@eval @inline Base.$f(r::DimUnitRange) = $f(parent(r))
34-
end
35-
end
3628
@inline Base.iterate(r::DimUnitRange, i...) = iterate(parent(r), i...)
3729
@inline Base.getindex(r::DimUnitRange, i::Integer) = getindex(parent(r), i)
3830

3931
# Conversions to an AbstractUnitRange{Int} (and to an OrdinalRange{Int,Int} on Julia v"1.6") are necessary
4032
# to evaluate CartesianIndices for BigInt ranges, as their axes are also BigInt ranges
4133
Base.AbstractUnitRange{T}(r::DimUnitRange) where {T<:Integer} = DimUnitRange{T}(r)
4234

43-
# https://github.com/JuliaLang/julia/pull/40038
44-
if v"1.6" <= VERSION < v"1.9.0-DEV.642"
45-
Base.OrdinalRange{T,T}(r::DimUnitRange) where {T<:Integer} = DimUnitRange{T}(r)
46-
end
47-
4835
@inline function Base.checkindex(::Type{Bool}, r::DimUnitRange, i::Real)
4936
return Base.checkindex(Bool, parent(r), i)
5037
end

src/array/array.jl

+23-24
Original file line numberDiff line numberDiff line change
@@ -287,31 +287,30 @@ for (d, s) in ((:AbstractDimArray, :AbstractDimArray),
287287
end
288288
end
289289
# Ambiguity
290-
@static if VERSION >= v"1.9.0"
291-
Base.copyto!(dst::AbstractDimArray{T,2}, src::SparseArrays.CHOLMOD.Dense{T}) where T<:Union{Float64,ComplexF64} =
292-
(copyto!(parent(dst), src); dst)
293-
Base.copyto!(dst::AbstractDimArray{T}, src::SparseArrays.CHOLMOD.Dense{T}) where T<:Union{Float64,ComplexF64} =
294-
(copyto!(parent(dst), src); dst)
295-
Base.copyto!(dst::DimensionalData.AbstractDimArray, src::SparseArrays.CHOLMOD.Dense) =
296-
(copyto!(parent(dst), src); dst)
297-
Base.copyto!(dst::SparseArrays.AbstractCompressedVector, src::AbstractDimArray{T, 1} where T) =
298-
(copyto!(dst, parent(src)); dst)
299-
Base.copyto!(dst::AbstractDimArray{T,2} where T, src::SparseArrays.AbstractSparseMatrixCSC) =
300-
(copyto!(parent(dst), src); dst)
301-
Base.copyto!(dst::AbstractDimArray{T,2} where T, src::LinearAlgebra.AbstractQ) =
302-
(copyto!(parent(dst), src); dst)
303-
function Base.copyto!(
304-
dst::AbstractDimArray{<:Any,2},
305-
dst_i::CartesianIndices{2, R} where R<:Tuple{OrdinalRange{Int64, Int64}, OrdinalRange{Int64, Int64}},
306-
src::SparseArrays.AbstractSparseMatrixCSC{<:Any},
307-
src_i::CartesianIndices{2, R} where R<:Tuple{OrdinalRange{Int64, Int64}, OrdinalRange{Int64, Int64}}
308-
)
309-
copyto!(parent(dst), dst_i, src, src_i)
310-
return dst
311-
end
312-
Base.copy!(dst::SparseArrays.AbstractCompressedVector{T}, src::AbstractDimArray{T, 1}) where T =
313-
(copy!(dst, parent(src)); dst)
290+
Base.copyto!(dst::AbstractDimArray{T,2}, src::SparseArrays.CHOLMOD.Dense{T}) where T<:Union{Float64,ComplexF64} =
291+
(copyto!(parent(dst), src); dst)
292+
Base.copyto!(dst::AbstractDimArray{T}, src::SparseArrays.CHOLMOD.Dense{T}) where T<:Union{Float64,ComplexF64} =
293+
(copyto!(parent(dst), src); dst)
294+
Base.copyto!(dst::DimensionalData.AbstractDimArray, src::SparseArrays.CHOLMOD.Dense) =
295+
(copyto!(parent(dst), src); dst)
296+
Base.copyto!(dst::SparseArrays.AbstractCompressedVector, src::AbstractDimArray{T, 1} where T) =
297+
(copyto!(dst, parent(src)); dst)
298+
Base.copyto!(dst::AbstractDimArray{T,2} where T, src::SparseArrays.AbstractSparseMatrixCSC) =
299+
(copyto!(parent(dst), src); dst)
300+
Base.copyto!(dst::AbstractDimArray{T,2} where T, src::LinearAlgebra.AbstractQ) =
301+
(copyto!(parent(dst), src); dst)
302+
function Base.copyto!(
303+
dst::AbstractDimArray{<:Any,2},
304+
dst_i::CartesianIndices{2, R} where R<:Tuple{OrdinalRange{Int64, Int64}, OrdinalRange{Int64, Int64}},
305+
src::SparseArrays.AbstractSparseMatrixCSC{<:Any},
306+
src_i::CartesianIndices{2, R} where R<:Tuple{OrdinalRange{Int64, Int64}, OrdinalRange{Int64, Int64}}
307+
)
308+
copyto!(parent(dst), dst_i, src, src_i)
309+
return dst
314310
end
311+
Base.copy!(dst::SparseArrays.AbstractCompressedVector{T}, src::AbstractDimArray{T, 1}) where T =
312+
(copy!(dst, parent(src)); dst)
313+
315314
Base.copy!(dst::SparseArrays.SparseVector, src::AbstractDimArray{T,1}) where T =
316315
(copy!(dst, parent(src)); dst)
317316
Base.copyto!(dst::PermutedDimsArray, src::AbstractDimArray) =

src/array/methods.jl

+35-44
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ function Base._mapreduce_dim(f, op, nt, A::AbstractDimArray, dims::Colon)
6767
rebuild(A, Base._mapreduce_dim(f, op, nt, parent(A), dimnum(A, dims)), reducedims(A, dims))
6868
end
6969

70-
@static if VERSION >= v"1.6"
71-
function Base._mapreduce_dim(f, op, nt::Base._InitialValue, A::AbstractDimArray, dims)
72-
rebuild(A, Base._mapreduce_dim(f, op, nt, parent(A), dimnum(A, dims)), reducedims(A, dims))
73-
end
74-
function Base._mapreduce_dim(f, op, nt::Base._InitialValue, A::AbstractDimArray, dims::Colon)
75-
Base._mapreduce_dim(f, op, nt, parent(A), dims)
76-
end
70+
function Base._mapreduce_dim(f, op, nt::Base._InitialValue, A::AbstractDimArray, dims)
71+
rebuild(A, Base._mapreduce_dim(f, op, nt, parent(A), dimnum(A, dims)), reducedims(A, dims))
72+
end
73+
function Base._mapreduce_dim(f, op, nt::Base._InitialValue, A::AbstractDimArray, dims::Colon)
74+
Base._mapreduce_dim(f, op, nt, parent(A), dims)
7775
end
7876

77+
7978
# TODO: Unfortunately Base/accumulate.jl kw methods all force dims to be Integer.
8079
# accumulate wont work unless that is relaxed, or we copy half of the file here.
8180
# Base._accumulate!(op, B, A, dims::AllDims, init::Union{Nothing, Some}) =
@@ -120,51 +119,43 @@ end
120119
return rebuild(A, newdata, newdims)
121120
end
122121

123-
@static if VERSION < v"1.9-alpha1"
124-
"""
125-
Base.eachslice(A::AbstractDimArray; dims)
122+
"""
123+
Base.eachslice(A::AbstractDimArray; dims,drop=true)
126124
127-
Create a generator that iterates over dimensions `dims` of `A`, returning arrays that
128-
select all the data from the other dimensions in `A` using views.
125+
Create a generator that iterates over dimensions `dims` of `A`, returning arrays that
126+
select all the data from the other dimensions in `A` using views.
129127
130-
The generator has `size` and `axes` equivalent to those of the provided `dims`.
131-
"""
132-
function Base.eachslice(A::AbstractDimArray; dims)
133-
dimtuple = _astuple(dims)
134-
if !(dimtuple == ())
135-
all(hasdim(A, dimtuple...)) || throw(DimensionMismatch("A doesn't have all dimensions $dims"))
136-
end
137-
_eachslice(A, dimtuple)
128+
The generator has `size` and `axes` equivalent to those of the provided `dims` if `drop=true`.
129+
Otherwise it will have the same dimensionality as the underlying array with inner dimensions having size 1.
130+
"""
131+
@inline function Base.eachslice(A::AbstractDimArray; dims, drop=true)
132+
dimtuple = _astuple(dims)
133+
if !(dimtuple == ())
134+
all(hasdim(A, dimtuple...)) || throw(DimensionMismatch("A doesn't have all dimensions $dims"))
138135
end
139-
else
140-
@inline function Base.eachslice(A::AbstractDimArray; dims, drop=true)
141-
dimtuple = _astuple(dims)
142-
if !(dimtuple == ())
143-
all(hasdim(A, dimtuple...)) || throw(DimensionMismatch("A doesn't have all dimensions $dims"))
136+
_eachslice(A, dimtuple, drop)
137+
end
138+
Base.@constprop :aggressive function _eachslice(A::AbstractDimArray{T,N}, dims, drop) where {T,N}
139+
slicedims = Dimensions.dims(A, dims)
140+
Adims = Dimensions.dims(A)
141+
if drop
142+
ax = map(dim -> axes(A, dim), slicedims)
143+
slicemap = map(Adims) do dim
144+
hasdim(slicedims, dim) ? dimnum(slicedims, dim) : (:)
144145
end
145-
_eachslice(A, dimtuple, drop)
146-
end
147-
Base.@constprop :aggressive function _eachslice(A::AbstractDimArray{T,N}, dims, drop) where {T,N}
148-
slicedims = Dimensions.dims(A, dims)
149-
Adims = Dimensions.dims(A)
150-
if drop
151-
ax = map(dim -> axes(A, dim), slicedims)
152-
slicemap = map(Adims) do dim
153-
hasdim(slicedims, dim) ? dimnum(slicedims, dim) : (:)
154-
end
155-
return Slices(A, slicemap, ax)
156-
else
157-
ax = map(Adims) do dim
158-
hasdim(slicedims, dim) ? axes(A, dim) : axes(reducedims(dim, dim), 1)
159-
end
160-
slicemap = map(Adims) do dim
161-
hasdim(slicedims, dim) ? dimnum(A, dim) : (:)
162-
end
163-
return Slices(A, slicemap, ax)
146+
return Slices(A, slicemap, ax)
147+
else
148+
ax = map(Adims) do dim
149+
hasdim(slicedims, dim) ? axes(A, dim) : axes(reducedims(dim, dim), 1)
164150
end
151+
slicemap = map(Adims) do dim
152+
hasdim(slicedims, dim) ? dimnum(A, dim) : (:)
153+
end
154+
return Slices(A, slicemap, ax)
165155
end
166156
end
167157

158+
168159
# works for arrays and for stacks
169160
function _eachslice(x, dims::Tuple)
170161
slicedims = Dimensions.dims(x, dims)

src/stack/methods.jl

+10-17
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Base.copyto!(
4747
end
4848

4949
"""
50-
Base.eachslice(stack::AbstractDimStack; dims)
50+
Base.eachslice(stack::AbstractDimStack; dims, drop=true)
5151
5252
Create a generator that iterates over dimensions `dims` of `stack`, returning stacks that
5353
select all the data from the other dimensions in `stack` using views.
@@ -80,26 +80,19 @@ and 2 layers:
8080
:y Float64 dims: Y, Ti (3×5)
8181
```
8282
"""
83-
@static if VERSION < v"1.9-alpha1"
84-
function Base.eachslice(s::AbstractDimStack; dims)
85-
dimtuple = _astuple(basedims(dims))
86-
all(hasdim(s, dimtuple)) || throw(DimensionMismatch("s doesn't have all dimensions $dims"))
87-
_eachslice(s, dimtuple)
83+
function Base.eachslice(s::AbstractDimStack; dims, drop=true)
84+
dimtuple = _astuple(dims)
85+
if !(dimtuple == ())
86+
all(hasdim(s, dimtuple)) || throw(DimensionMismatch("A doesn't have all dimensions $dims"))
8887
end
89-
else
90-
function Base.eachslice(s::AbstractDimStack; dims, drop=true)
91-
dimtuple = _astuple(dims)
92-
if !(dimtuple == ())
93-
all(hasdim(s, dimtuple)) || throw(DimensionMismatch("A doesn't have all dimensions $dims"))
94-
end
95-
# Avoid getting DimUnitRange from `axes(s)`
96-
axisdims = map(DD.dims(s, dimtuple)) do d
97-
rebuild(d, axes(lookup(d), 1))
98-
end
99-
return DimSlices(s; dims=axisdims, drop)
88+
# Avoid getting DimUnitRange from `axes(s)`
89+
axisdims = map(DD.dims(s, dimtuple)) do d
90+
rebuild(d, axes(lookup(d), 1))
10091
end
92+
return DimSlices(s; dims=axisdims, drop)
10193
end
10294

95+
10396
"""
10497
Base.cat(stacks::AbstractDimStack...; [keys=keys(stacks[1])], dims)
10598

test/array.jl

+26-28
Original file line numberDiff line numberDiff line change
@@ -367,34 +367,32 @@ end
367367
@test convert(DimArray{eltype(da)}, da) === convert(DimArray, da) === da
368368
end
369369

370-
if VERSION > v"1.1-"
371-
@testset "copy!" begin
372-
dimz = dims(da2)
373-
A = zero(a2)
374-
sp = sprand(Int, 4, 0.5)
375-
db = DimArray(deepcopy(A), dimz)
376-
dc = DimArray(deepcopy(A), dimz)
377-
378-
@test copy!(A, da2) isa Matrix
379-
@test A == parent(da2)
380-
@test copy!(db, da2) isa DimMatrix
381-
@test parent(db) == parent(da2)
382-
@test copy!(dc, a2) isa DimMatrix
383-
@test parent(db) == a2
384-
# Sparse vector has its own method for ambiguity
385-
copy!(sp, da2[1, :])
386-
@test sp == parent(da2[1, :])
387-
388-
@testset "vector copy! (ambiguity fix)" begin
389-
v = zeros(3)
390-
dv = DimArray(zeros(3), X)
391-
@test copy!(v, DimArray([1.0, 2.0, 3.0], X)) isa Vector
392-
@test v == [1.0, 2.0, 3.0]
393-
@test copy!(dv, DimArray([9.9, 9.9, 9.9], X)) isa DimVector
394-
@test dv == [9.9, 9.9, 9.9]
395-
@test copy!(dv, [5.0, 5.0, 5.0]) isa DimVector
396-
@test dv == [5.0, 5.0, 5.0]
397-
end
370+
@testset "copy!" begin
371+
dimz = dims(da2)
372+
A = zero(a2)
373+
sp = sprand(Int, 4, 0.5)
374+
db = DimArray(deepcopy(A), dimz)
375+
dc = DimArray(deepcopy(A), dimz)
376+
377+
@test copy!(A, da2) isa Matrix
378+
@test A == parent(da2)
379+
@test copy!(db, da2) isa DimMatrix
380+
@test parent(db) == parent(da2)
381+
@test copy!(dc, a2) isa DimMatrix
382+
@test parent(db) == a2
383+
# Sparse vector has its own method for ambiguity
384+
copy!(sp, da2[1, :])
385+
@test sp == parent(da2[1, :])
386+
387+
@testset "vector copy! (ambiguity fix)" begin
388+
v = zeros(3)
389+
dv = DimArray(zeros(3), X)
390+
@test copy!(v, DimArray([1.0, 2.0, 3.0], X)) isa Vector
391+
@test v == [1.0, 2.0, 3.0]
392+
@test copy!(dv, DimArray([9.9, 9.9, 9.9], X)) isa DimVector
393+
@test dv == [9.9, 9.9, 9.9]
394+
@test copy!(dv, [5.0, 5.0, 5.0]) isa DimVector
395+
@test dv == [5.0, 5.0, 5.0]
398396
end
399397
end
400398

test/dimunitrange.jl

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ axdims = [
2222
@test axes(r) === (r,)
2323
@test axes(r, 1) === r
2424
@test Base.axes1(r) === r
25-
if VERSION < v"1.8.2"
26-
@test firstindex(r) == firstindex(ax)
27-
@test lastindex(r) == lastindex(ax)
28-
end
2925
@test iterate(r) === iterate(ax)
3026
@test iterate(r, iterate(r)[2]) === iterate(ax, iterate(r)[2])
3127
@test r[begin] == ax[begin]
@@ -38,9 +34,7 @@ axdims = [
3834
@test dims(bigr) === dim
3935
@test bigr == ax
4036
@test DimUnitRange{eltype(r)}(r) === r
41-
if VERSION >= v"1.6"
42-
@test Base.OrdinalRange{Int,Int}(r) == r
43-
end
37+
@test Base.OrdinalRange{Int,Int}(r) == r
4438
@test AbstractUnitRange{BigInt}(r) isa DimUnitRange{BigInt}
4539
@test parent(AbstractUnitRange{BigInt}(r)) == AbstractUnitRange{BigInt}(parent(r))
4640
@test dims(AbstractUnitRange{BigInt}(r)) === dim

test/indexing.jl

+6-7
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,12 @@ end
467467
@inferred setindex!(da2_set, 77, Dim{:row}(1), column=2)
468468

469469
# With a large type
470-
if VERSION >= v"1.5"
471-
da4 = DimArray(zeros(1, 2, 3, 4, 5, 6, 7, 8), (:a, :b, :c, :d, :d, :f, :g, :h))
472-
@inferred getindex(da2, a=1, b=2, c=3, d=4, e=5)
473-
# Type inference breaks with 6 arguments.
474-
# @inferred getindex(da2, a=1, b=2, c=3, d=4, e=5, f=6)
475-
# @code_warntype getindex(da2, a=1, b=2, c=3, d=4, e=5, f=6)
476-
end
470+
da4 = DimArray(zeros(1, 2, 3, 4, 5, 6, 7, 8), (:a, :b, :c, :d, :d, :f, :g, :h))
471+
@inferred getindex(da2, a=1, b=2, c=3, d=4, e=5)
472+
# Type inference breaks with 6 arguments.
473+
# @inferred getindex(da2, a=1, b=2, c=3, d=4, e=5, f=6)
474+
# @code_warntype getindex(da2, a=1, b=2, c=3, d=4, e=5, f=6)
475+
477476
end
478477

479478
@testset "trailing colon" begin

0 commit comments

Comments
 (0)