Skip to content

Commit 073a4df

Browse files
committed
upgrade OffsetArrays to v1.1.3
v1.2.0 introduces an ambiguity and thus not used.
1 parent dceceaa commit 073a4df

File tree

4 files changed

+320
-115
lines changed

4 files changed

+320
-115
lines changed

test/arrayops.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,8 +1428,8 @@ end
14281428

14291429
# non-1-indexed array
14301430
oa = OffsetArray(Vector(1:10), -5)
1431-
filter!(x -> x > 5, oa)
1432-
@test oa == OffsetArray(Vector(6:10), -5)
1431+
oa = oa[oa.>5] # deleteat! is not supported for OffsetArrays
1432+
@test oa == Vector(6:10)
14331433

14341434
# empty non-1-indexed array
14351435
eoa = OffsetArray([], -5)

test/offsetarray.jl

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ using Random
77
using LinearAlgebra
88
using Statistics
99

10-
const OAs_name = join(fullname(OffsetArrays), ".")
11-
1210
if !isdefined(@__MODULE__, :T24Linear)
1311
include("testhelpers/arrayindexingtypes.jl")
1412
end
@@ -18,15 +16,15 @@ let
1816
v0 = rand(4)
1917
v = OffsetArray(v0, (-3,))
2018
h = OffsetArray([-1,1,-2,2,0], (-3,))
21-
@test axes(v) == (-2:1,)
19+
@test axes(v) === (OffsetArrays.IdOffsetRange(Base.OneTo(4), -3),)
2220
@test size(v) == (4,)
2321
@test size(v, 1) == 4
2422
@test_throws DimensionMismatch Array(v)
2523

2624
A0 = [1 3; 2 4]
2725
A = OffsetArray(A0, (-1,2)) # IndexLinear
2826
S = OffsetArray(view(A0, 1:2, 1:2), (-1,2)) # IndexCartesian
29-
@test axes(A) == axes(S) == (0:1, 3:4)
27+
@test axes(A) === axes(S) === (OffsetArrays.IdOffsetRange(Base.OneTo(2), -1), OffsetArrays.IdOffsetRange(Base.OneTo(2), 2))
3028
@test size(A) == (2,2)
3129
@test size(A, 1) == 2
3230

@@ -133,13 +131,13 @@ S = view(A, :, 3)
133131
@test S[0] == 1
134132
@test S[1] == 2
135133
@test_throws BoundsError S[2]
136-
@test axes(S) === (Base.IdentityUnitRange(0:1),)
134+
@test axes(S) === (Base.IdentityUnitRange(OffsetArrays.IdOffsetRange(Base.OneTo(2), -1)),)
137135
S = view(A, 0, :)
138136
@test S == OffsetArray([1,3], (A.offsets[2],))
139137
@test S[3] == 1
140138
@test S[4] == 3
141139
@test_throws BoundsError S[1]
142-
@test axes(S) === (Base.IdentityUnitRange(3:4),)
140+
@test axes(S) === (Base.IdentityUnitRange(OffsetArrays.IdOffsetRange(Base.OneTo(2), 2)),)
143141
S = view(A, 0:0, 4)
144142
@test S == [3]
145143
@test S[1] == 3
@@ -158,17 +156,17 @@ S = view(A, :, :)
158156
@test S[0,4] == S[3] == 3
159157
@test S[1,4] == S[4] == 4
160158
@test_throws BoundsError S[1,1]
161-
@test axes(S) === Base.IdentityUnitRange.((0:1, 3:4))
159+
@test axes(S) === Base.IdentityUnitRange.((OffsetArrays.IdOffsetRange(Base.OneTo(2), -1), OffsetArrays.IdOffsetRange(Base.OneTo(2), 2)))
162160
# https://github.com/JuliaArrays/OffsetArrays.jl/issues/27
163161
g = OffsetArray(Vector(-2:3), (-3,))
164162
gv = view(g, -1:2)
165163
@test axes(gv, 1) === Base.OneTo(4)
166164
@test collect(gv) == -1:2
167165
gv = view(g, OffsetArray(-1:2, (-2,)))
168-
@test axes(gv, 1) === Base.IdentityUnitRange(-1:2)
166+
@test axes(gv, 1) === OffsetArrays.IdOffsetRange(Base.OneTo(4), -2)
169167
@test collect(gv) == -1:2
170168
gv = view(g, OffsetArray(-1:2, (-1,)))
171-
@test axes(gv, 1) === Base.IdentityUnitRange(0:3)
169+
@test axes(gv, 1) === OffsetArrays.IdOffsetRange(Base.OneTo(4), -1)
172170
@test collect(gv) == -1:2
173171

174172
# iteration
@@ -199,7 +197,7 @@ str = String(take!(io))
199197
show(io, parent(v))
200198
@test str == String(take!(io))
201199
smry = summary(v)
202-
@test occursin("OffsetArray{Float64, 1", smry)
200+
@test occursin("OffsetArray(::Vector{Float64", smry)
203201
@test occursin("with indices -1:1", smry)
204202
function cmp_showf(printfunc, io, A; options = ())
205203
ioc = IOContext(io, :limit => true, :compact => true, options...)
@@ -216,11 +214,11 @@ cmp_showf(Base.print_matrix, io, OffsetArray(rand(10^3,10^3), (10,-9))) # neithe
216214
cmp_showf(Base.print_matrix, io, OffsetArray(reshape(range(-0.212121212121, stop=2/11, length=3*29), 3, 29), (-2, -15)); options=(:displaysize=>(53,210),))
217215
cmp_showf(show, io, OffsetArray(collect(1:100), (100,))) # issue #31641
218216

219-
targets1 = ["0-dimensional $OAs_name.OffsetArray{Float64, 0, Array{Float64, 0}}:\n1.0",
220-
"1-element $OAs_name.OffsetArray{Float64, 1, Vector{Float64}} with indices 2:2:\n 1.0",
221-
"1×1 $OAs_name.OffsetArray{Float64, 2, Matrix{Float64}} with indices 2:2×3:3:\n 1.0",
222-
"1×1×1 $OAs_name.OffsetArray{Float64, 3, Array{Float64, 3}} with indices 2:2×3:3×4:4:\n[:, :, 4] =\n 1.0",
223-
"1×1×1×1 $OAs_name.OffsetArray{Float64, 4, Array{Float64, 4}} with indices 2:2×3:3×4:4×5:5:\n[:, :, 4, 5] =\n 1.0"]
217+
targets1 = ["0-dimensional OffsetArray(::Array{Float64, 0}) with eltype Float64:\n1.0",
218+
"1-element OffsetArray(::Vector{Float64}, 2:2) with eltype Float64 with indices 2:2:\n 1.0",
219+
"1×1 OffsetArray(::Matrix{Float64}, 2:2, 3:3) with eltype Float64 with indices 2:2×3:3:\n 1.0",
220+
"1×1×1 OffsetArray(::Array{Float64, 3}, 2:2, 3:3, 4:4) with eltype Float64 with indices 2:2×3:3×4:4:\n[:, :, 4] =\n 1.0",
221+
"1×1×1×1 OffsetArray(::Array{Float64, 4}, 2:2, 3:3, 4:4, 5:5) with eltype Float64 with indices 2:2×3:3×4:4×5:5:\n[:, :, 4, 5] =\n 1.0"]
224222
targets2 = ["(fill(1.0), fill(1.0))",
225223
"([1.0], [1.0])",
226224
"([1.0], [1.0])",
@@ -235,7 +233,7 @@ targets2 = ["(fill(1.0), fill(1.0))",
235233
end
236234
P = OffsetArray(rand(8,8), (1,1))
237235
PV = view(P, 2:3, :)
238-
@test endswith(summary(PV), "with indices Base.OneTo(2)×2:9")
236+
@test endswith(summary(PV), "with indices Base.OneTo(2)×OffsetArrays.IdOffsetRange(2:9)")
239237

240238
# Similar
241239
B = similar(A, Float32)
@@ -247,26 +245,26 @@ B = similar(A, (3,4))
247245
@test axes(B) === (Base.OneTo(3), Base.OneTo(4))
248246
B = similar(A, (-3:3,1:4))
249247
@test isa(B, OffsetArray{Int,2})
250-
@test axes(B) === Base.IdentityUnitRange.((-3:3, 1:4))
248+
@test axes(B) === (OffsetArrays.IdOffsetRange(Base.OneTo(7), -4), OffsetArrays.IdOffsetRange(Base.OneTo(4)))
251249
B = similar(parent(A), (-3:3,1:4))
252250
@test isa(B, OffsetArray{Int,2})
253-
@test axes(B) === Base.IdentityUnitRange.((-3:3, 1:4))
251+
@test axes(B) === (OffsetArrays.IdOffsetRange(Base.OneTo(7), -4), OffsetArrays.IdOffsetRange(Base.OneTo(4)))
254252

255253
# Indexing with OffsetArray indices
256254
i1 = OffsetArray([2,1], (-5,))
257255
i1 = OffsetArray([2,1], -5)
258256
b = A0[i1, 1]
259-
@test axes(b) === (Base.IdentityUnitRange(-4:-3),)
257+
@test axes(b) === (OffsetArrays.IdOffsetRange(Base.OneTo(2), -5),)
260258
@test b[-4] == 2
261259
@test b[-3] == 1
262260
b = A0[1,i1]
263-
@test axes(b) === (Base.IdentityUnitRange(-4:-3),)
261+
@test axes(b) === (OffsetArrays.IdOffsetRange(Base.OneTo(2), -5),)
264262
@test b[-4] == 3
265263
@test b[-3] == 1
266264
v = view(A0, i1, 1)
267-
@test axes(v) === (Base.IdentityUnitRange(-4:-3),)
265+
@test axes(v) === (OffsetArrays.IdOffsetRange(Base.OneTo(2), -5),)
268266
v = view(A0, 1:1, i1)
269-
@test axes(v) === (Base.OneTo(1), Base.IdentityUnitRange(-4:-3))
267+
@test axes(v) === (Base.OneTo(1), OffsetArrays.IdOffsetRange(Base.OneTo(2), -5))
270268

271269
# copyto! and fill!
272270
a = OffsetArray{Int}(undef, (-3:-1,))
@@ -395,7 +393,7 @@ v2 = copy(v)
395393
v = OffsetArray(v0, (-3,))
396394
@test lastindex(v) == 1
397395
@test v v
398-
@test axes(v') === (Base.OneTo(1),Base.IdentityUnitRange(-2:1))
396+
@test axes(v') === (Base.OneTo(1), OffsetArrays.IdOffsetRange(Base.OneTo(4), -3))
399397
@test parent(v) == collect(v)
400398
rv = reverse(v)
401399
@test axes(rv) == axes(v)
@@ -411,7 +409,7 @@ A = OffsetArray(rand(4,4), (-3,5))
411409
@test lastindex(A, 1) == 1
412410
@test lastindex(A, 2) == 9
413411
@test A A
414-
@test axes(A') === Base.IdentityUnitRange.((6:9, -2:1))
412+
@test axes(A') === (OffsetArrays.IdOffsetRange(Base.OneTo(4), 5), OffsetArrays.IdOffsetRange(Base.OneTo(4), -3))
415413
@test parent(copy(A')) == copy(parent(A)')
416414
@test collect(A) == parent(A)
417415
@test maximum(A) == maximum(parent(A))

test/reinterpretarray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ let a = [0.1 0.2; 0.3 0.4], at = reshape([(i,i+1) for i = 1:2:8], 2, 2)
165165
@test r[1,2] === reinterpret(Int64, v[1,2])
166166
@test r[0,3] === reinterpret(Int64, v[0,3])
167167
@test r[1,3] === reinterpret(Int64, v[1,3])
168-
@test_throws ArgumentError("cannot reinterpret a `Float64` array to `UInt32` when the first axis is Base.IdentityUnitRange(0:1). Try reshaping first.") reinterpret(UInt32, v)
168+
@test_throws ArgumentError("cannot reinterpret a `Float64` array to `UInt32` when the first axis is OffsetArrays.IdOffsetRange(0:1). Try reshaping first.") reinterpret(UInt32, v)
169169
v = OffsetArray(a, (0, 1))
170170
r = reinterpret(UInt32, v)
171171
axsv = axes(v)
@@ -184,7 +184,7 @@ let a = [0.1 0.2; 0.3 0.4], at = reshape([(i,i+1) for i = 1:2:8], 2, 2)
184184
offsetvt = (-2, 4)
185185
vt = OffsetArray(at, offsetvt)
186186
istr = string(Int)
187-
@test_throws ArgumentError("cannot reinterpret a `Tuple{$istr, $istr}` array to `$istr` when the first axis is Base.IdentityUnitRange(-1:0). Try reshaping first.") reinterpret(Int, vt)
187+
@test_throws ArgumentError("cannot reinterpret a `Tuple{Int64, Int64}` array to `Int64` when the first axis is OffsetArrays.IdOffsetRange(-1:0). Try reshaping first.") reinterpret(Int, vt)
188188
vt = reshape(vt, 1:1, axes(vt)...)
189189
r = reinterpret(Int, vt)
190190
@test r == OffsetArray(reshape(1:8, 2, 2, 2), (0, offsetvt...))

0 commit comments

Comments
 (0)