-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathruntests.jl
More file actions
2762 lines (2417 loc) · 99.2 KB
/
runtests.jl
File metadata and controls
2762 lines (2417 loc) · 99.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Adapt
using Aqua
using Base: Slice
using CatIndices: BidirectionalVector
using DelimitedFiles
using DistributedArrays
using Documenter
using EllipsisNotation
using FillArrays
using LinearAlgebra
using OffsetArrays
using OffsetArrays: IdentityUnitRange, no_offset_view, IIUR, Origin, IdOffsetRange
using StaticArrays
using Test
const SliceIntUR = Slice{<:AbstractUnitRange{<:Integer}}
DocMeta.setdocmeta!(OffsetArrays, :DocTestSetup, :(using OffsetArrays); recursive=true)
# https://github.com/JuliaLang/julia/pull/29440
if VERSION < v"1.1.0-DEV.389"
Base.:(:)(I::CartesianIndex{N}, J::CartesianIndex{N}) where N =
CartesianIndices(map((i,j) -> i:j, Tuple(I), Tuple(J)))
end
# Custom index types
struct ZeroBasedIndexing end
struct NewColon end
struct TupleOfRanges{N}
x ::NTuple{N, UnitRange{Int}}
end
include("customranges.jl")
function same_value(r1, r2)
length(r1) == length(r2) || return false
for (v1, v2) in zip(r1, r2)
v1 == v2 || return false
end
return true
end
@testset "Project meta quality checks" begin
# Not checking compat section for test-only dependencies
Aqua.test_all(OffsetArrays; project_extras=true, deps_compat=true, stale_deps=true, project_toml_formatting=true)
if VERSION >= v"1.2"
doctest(OffsetArrays, manual = false)
end
end
@testset "IdOffsetRange" begin
function check_indexed_by(r, rindx)
for i in rindx
r[i]
end
@test_throws BoundsError r[minimum(rindx)-1]
@test_throws BoundsError r[maximum(rindx)+1]
return nothing
end
ro = OffsetArrays.IdOffsetRange(Base.OneTo(3))
rs = OffsetArrays.IdOffsetRange(3:5, -2)
@test typeof(ro) !== typeof(rs)
@test same_value(ro, 1:3)
check_indexed_by(ro, 1:3)
@test same_value(rs, 1:3)
check_indexed_by(rs, -1:1)
@test firstindex(ro) == 1
@test lastindex(ro) == 3
@test firstindex(rs) == -1
@test lastindex(rs) == 1
@test @inferred(typeof(ro)(ro)) === ro
@test @inferred(OffsetArrays.IdOffsetRange{Int}(ro)) === ro
@test @inferred(OffsetArrays.IdOffsetRange{Int16}(ro)) === OffsetArrays.IdOffsetRange(Base.OneTo(Int16(3)))
@test @inferred(OffsetArrays.IdOffsetRange(ro)) === ro
@test parent(ro) === ro.parent
@test parent(rs) === rs.parent
# construction/coercion preserves the values, altering the axes if needed
r2 = @inferred(typeof(rs)(ro))
@test typeof(r2) === typeof(rs)
@test same_value(ro, 1:3)
check_indexed_by(ro, 1:3)
r2 = @inferred(typeof(ro)(rs))
@test typeof(r2) === typeof(ro)
@test same_value(r2, 1:3)
check_indexed_by(r2, 1:3)
# check the example in the comments
r = OffsetArrays.IdOffsetRange{Int,UnitRange{Int}}(3:4)
@test same_value(r, 3:4)
check_indexed_by(r, 1:2)
r = OffsetArrays.IdOffsetRange{Int,Base.OneTo{Int}}(3:4)
@test same_value(r, 3:4)
check_indexed_by(r, 3:4)
r = OffsetArrays.IdOffsetRange{Int,Base.OneTo{Int}}(3:4, -2)
@test same_value(r, 1:2)
check_indexed_by(r, 1:2)
r = OffsetArrays.IdOffsetRange{Int32, Base.OneTo{Int32}}(Base.OneTo(Int64(2)), 3)
@test same_value(r, 4:5)
check_indexed_by(r, 4:5)
r = IdOffsetRange{Int, UnitRange{Int}}(IdOffsetRange(3:5, 2), 2)
@test typeof(r) == IdOffsetRange{Int, UnitRange{Int}}
@test same_value(r, 7:9)
check_indexed_by(r, 5:7)
r = IdOffsetRange{Int, Base.OneTo{Int}}(IdOffsetRange(Base.OneTo(3), 1), 1)
@test typeof(r) == IdOffsetRange{Int,Base.OneTo{Int}}
@test same_value(r, 3:5)
check_indexed_by(r, 3:5)
rp = Base.OneTo(3)
r = IdOffsetRange(rp)
r2 = IdOffsetRange{Int,typeof(r)}(r, 1)
@test same_value(r2, 2:4)
check_indexed_by(r2, 2:4)
r2 = IdOffsetRange{Int32,IdOffsetRange{Int32,Base.OneTo{Int32}}}(r, 1)
@test typeof(r2) == IdOffsetRange{Int32,IdOffsetRange{Int32,Base.OneTo{Int32}}}
@test same_value(r2, 2:4)
check_indexed_by(r2, 2:4)
# eltype coercion through the AbstractUnitRange constructor
ro = OffsetArrays.IdOffsetRange(Base.OneTo(3))
@test @inferred(AbstractUnitRange{Int}(ro)) === ro
rb = IdOffsetRange(Base.OneTo(big(3)))
@test @inferred(AbstractUnitRange{Int}(rb)) === IdOffsetRange(Base.OneTo(3))
# Constructor that's round-trippable with `show`
rrt = IdOffsetRange(values=7:9, indices=-1:1)
@test same_value(rrt, 7:9)
check_indexed_by(rrt, -1:1)
@test_throws ArgumentError IdOffsetRange(values=7:9, indices=-1:2)
@test_throws ArgumentError IdOffsetRange(values=7:9, indices=-1:0)
@test_throws TypeError IdOffsetRange(values=7:9, indices=-1)
@test_throws UndefKeywordError IdOffsetRange(values=7:9)
@test_throws UndefKeywordError IdOffsetRange(indices=-1:1)
@test_throws MethodError IdOffsetRange(7:9, indices=-1:1)
@test_throws MethodError IdOffsetRange(-1:1, values=7:9)
p = IdOffsetRange(1:3, 2)
q = IdOffsetRange(values = p .- 2, indices = p)
@test same_value(q, 1:3)
check_indexed_by(q, p)
@testset for indices in Any[Base.OneTo(3), IdentityUnitRange(Base.OneTo(3))]
p = IdOffsetRange(values = IdOffsetRange(1:3, 2), indices = indices)
@test same_value(p, 3:5)
check_indexed_by(p, 1:3)
q = IdOffsetRange(values = Base.OneTo(3), indices = indices)
@test same_value(q, 1:3)
@test q isa IdOffsetRange{Int, Base.OneTo{Int}}
end
# conversion preserves both the values and the axes, throwing an error if this is not possible
@test @inferred(oftype(ro, ro)) === ro
@test @inferred(convert(OffsetArrays.IdOffsetRange{Int}, ro)) === ro
@test @inferred(convert(OffsetArrays.IdOffsetRange{Int}, rs)) === rs
@test @inferred(convert(OffsetArrays.IdOffsetRange{Int16}, ro)) === OffsetArrays.IdOffsetRange(Base.OneTo(Int16(3)))
r2 = @inferred(oftype(rs, ro))
@test typeof(r2) === typeof(rs)
@test same_value(r2, 1:3)
check_indexed_by(r2, 1:3)
# These two broken tests can be fixed by uncommenting the `convert` definitions
# in axes.jl, but unfortunately Julia may not quite be ready for this. (E.g. `reinterpretarray.jl`)
@test_broken try oftype(ro, rs); false catch err true end # replace with line below
# @test_throws ArgumentError oftype(ro, rs)
@test @inferred(oftype(ro, Base.OneTo(2))) === OffsetArrays.IdOffsetRange(Base.OneTo(2))
@test @inferred(oftype(ro, 1:2)) === OffsetArrays.IdOffsetRange(Base.OneTo(2))
@test_broken try oftype(ro, 3:4); false catch err true end
# @test_throws ArgumentError oftype(ro, 3:4)
# broadcasting behavior with scalars (issue #104)
r3 = (1 .+ OffsetArrays.IdOffsetRange(3:5, -1) .+ 1) .- 1
@test r3 isa OffsetArrays.IdOffsetRange
@test same_value(r3, 3:5)
check_indexed_by(r3, axes(r3,1))
r = OffsetArrays.IdOffsetRange(3:5, -1)
rc = copyto!(similar(r), r)
n = big(typemax(Int))
@test @inferred(broadcast(+, r, n)) == @inferred(broadcast(+, n, r)) == rc .+ n
@test @inferred(broadcast(-, r, n)) == rc .- n
@test @inferred(broadcast(big, r)) == big.(rc)
for n in Any[2, big(typemax(Int))]
@test @inferred(broadcast(+, r, n)) == @inferred(broadcast(+, n, r)) == rc .+ n
end
@testset "Idempotent indexing" begin
@testset "Indexing into an IdOffsetRange" begin
r = OffsetArrays.IdOffsetRange(3:5, -1)
# Indexing with IdentityUnitRange
s = IdentityUnitRange(0:2)
@test axes(r[s]) == axes(s)
for i in eachindex(s)
@test r[s[i]] == r[s][i]
end
# Indexing with IdOffsetRange
s = OffsetArrays.IdOffsetRange(-4:-2, 4)
@test axes(r[s]) == axes(s)
for i in eachindex(s)
@test r[s[i]] == r[s][i]
end
# Indexing with UnitRange
s = 0:2
@test axes(r[s]) == axes(s)
for i in eachindex(s)
@test r[s[i]] == r[s][i]
end
end
@testset "Indexing using an IdOffsetRange" begin
r = OffsetArrays.IdOffsetRange(3:5, -1)
# Indexing into an IdentityUnitRange
s = IdentityUnitRange(-1:5)
@test axes(s[r]) == axes(r)
for i in eachindex(r)
@test s[r[i]] == s[r][i]
end
# Indexing into an UnitRange
s = -3:6
@test axes(s[r]) == axes(r)
for i in eachindex(r)
@test s[r[i]] == s[r][i]
end
end
end
# Test reduced index
rred = Base.reduced_index(r)
@test typeof(rred) == typeof(r)
@test length(rred) == 1
@test first(rred) == first(r)
@testset "reduced_indices" begin
a = reshape(1:24, 2, 3, 4)
sa = OffsetArray(a, (2, 3, 4));
@testset for dim in 1:ndims(sa)
sasum = sum(sa, dims = dim)
@test parent(sasum) == sum(a, dims = dim)
find = firstindex(sa, dim)
@test axes(sasum, dim) == find:find
end
end
@testset "conversion to AbstractUnitRange" begin
r = IdOffsetRange(1:2)
@test AbstractUnitRange{Int}(r) === r
r2 = IdOffsetRange(big(1):big(2))
@test AbstractUnitRange{Int}(r2) === r
@test AbstractUnitRange{BigInt}(r2) === r2
if v"1.5" < VERSION
@test OrdinalRange{Int,Int}(r2) === r
@test OrdinalRange{BigInt,BigInt}(r2) === r2
end
end
@testset "Bool IdOffsetRange (issue #223)" begin
for b1 in [false, true], b2 in [false, true]
r = IdOffsetRange(b1:b2)
@test first(r) === b1
@test last(r) === b2
end
@test_throws ArgumentError IdOffsetRange(true:true, true)
@test_throws ArgumentError IdOffsetRange{Bool,UnitRange{Bool}}(true:true, true)
@test_throws ArgumentError IdOffsetRange{Bool,IdOffsetRange{Bool,UnitRange{Bool}}}(IdOffsetRange(true:true), true)
end
@testset "Logical indexing" begin
@testset "indexing with a single bool" begin
r = IdOffsetRange(1:2)
@test_throws ArgumentError r[true]
@test_throws ArgumentError r[false]
end
@testset "indexing wtih a Bool UnitRange" begin
r = IdOffsetRange(1:0)
@test r[true:false] == 1:0
@test r[true:false] == collect(r)[true:false]
@test_throws BoundsError r[true:true]
@test_throws BoundsError r[false:false]
@test_throws BoundsError r[false:true]
r = IdOffsetRange(1:1)
@test r[true:true] == 1:1
@test r[true:true] == collect(r)[true:true]
@test r[false:false] == 1:0
@test r[false:false] == collect(r)[false:false]
@test_throws BoundsError r[true:false]
@test_throws BoundsError r[false:true]
r = IdOffsetRange(1:2)
@test r[false:true] == 2:2
@test r[false:true] == collect(r)[false:true]
@test_throws BoundsError r[true:true]
@test_throws BoundsError r[true:false]
@test_throws BoundsError r[false:false]
end
@testset "indexing with a Bool IdOffsetRange" begin
# bounds-checking requires the axes of the indices to match that of the array
function testlogicalindexing(r, r2)
r3 = r[r2];
@test no_offset_view(r3) == collect(r)[collect(r2)]
end
r = IdOffsetRange(10:9)
r2 = IdOffsetRange(true:false)
testlogicalindexing(r, r2)
r = IdOffsetRange(10:10)
r2 = IdOffsetRange(false:false)
testlogicalindexing(r, r2)
r2 = IdOffsetRange(true:true)
testlogicalindexing(r, r2)
r = IdOffsetRange(10:10, 1)
r2 = IdOffsetRange(false:false, 1) # effectively true:true with indices 2:2
testlogicalindexing(r, r2)
r = IdOffsetRange(10:11)
r2 = IdOffsetRange(false:true)
testlogicalindexing(r, r2)
end
@testset "indexing wtih a Bool StepRange" begin
r = IdOffsetRange(1:0)
@test r[true:true:false] == 1:1:0
@test_throws BoundsError r[true:true:true]
@test_throws BoundsError r[false:true:false]
@test_throws BoundsError r[false:true:true]
r = IdOffsetRange(1:1)
@test r[true:true:true] == 1:1:1
@test r[true:true:true] == collect(r)[true:true:true]
@test axes(r[true:true:true], 1) == 1:1
@test r[false:true:false] == 1:1:0
@test r[false:true:false] == collect(r)[false:true:false]
# StepRange{Bool,Int}
s = StepRange(true, 1, true)
@test r[s] == 1:1:1
@test r[s] == collect(r)[s]
s = StepRange(true, 2, true)
@test r[s] == 1:1:1
@test r[s] == collect(r)[s]
s = StepRange(false, 1, false)
@test r[s] == 1:1:0
@test r[s] == collect(r)[s]
s = StepRange(false, 2, false)
@test r[s] == 1:1:0
@test r[s] == collect(r)[s]
@test_throws BoundsError r[true:true:false]
@test_throws BoundsError r[false:true:true]
r = IdOffsetRange(1:2)
@test r[false:true:true] == 2:1:2
@test r[false:true:true] == collect(r)[false:true:true]
# StepRange{Bool,Int}
s = StepRange(false, 1, true)
@test r[s] == 2:1:2
@test r[s] == collect(r)[s]
@test_throws BoundsError r[true:true:true]
@test_throws BoundsError r[true:true:false]
@test_throws BoundsError r[false:true:false]
end
end
@testset "iteration" begin
# parent has Base.OneTo axes
A = ones(4:10)
ax = axes(A, 1)
ind, st = iterate(ax)
@test A[ind] == A[4]
ind, st = iterate(ax, st)
@test A[ind] == A[5]
# parent doesn't have Base.OneTo axes
B = @view A[:]
C = OffsetArray(B, 0)
ax = axes(C, 1)
ind, st = iterate(ax)
@test C[ind] == C[4]
ind, st = iterate(ax, st)
@test C[ind] == C[5]
end
end
# used in testing the constructor
struct WeirdInteger{T} <: Integer
x :: T
end
# assume that it doesn't behave as expected
Base.Int(a::WeirdInteger) = a
@testset "Constructors" begin
@testset "Single-entry arrays in dims 0:5" begin
for n = 0:5
for z in (OffsetArray(ones(Int,ntuple(d->1,n)), ntuple(x->x-1,n)),
fill!(OffsetArray{Float64}(undef, ntuple(x->x:x, n)), 1),
fill!(OffsetArray{Float64}(undef, ntuple(x->x:x, n)...), 1),
fill!(OffsetArray{Float64,n}(undef, ntuple(x->x:x, n)), 1),
fill!(OffsetArray{Float64,n}(undef, ntuple(x->x:x, n)...), 1))
@test length(LinearIndices(z)) == 1
@test axes(z) == ntuple(x->x:x, n)
@test z[1] == 1
end
end
a0 = reshape([3])
a = OffsetArray(a0)
@test axes(a) == ()
@test ndims(a) == 0
@test a[] == 3
@test a === OffsetArray(a, ())
@test_throws ArgumentError OffsetArray(a, 0)
@test_throws ArgumentError OffsetArray(a0, 0)
end
@testset "OffsetVector" begin
# initialization
one_based_axes = Any[
(Base.OneTo(4), ),
(1:4, ),
(big(1):big(4), ),
(CartesianIndex(1):CartesianIndex(4), ),
(IdentityUnitRange(1:4), ),
(IdOffsetRange(1:4),),
(IdOffsetRange(3:6, -2),)
]
offset_axes = Any[
(-1:2, ),
(big(-1):big(2), ),
(CartesianIndex(-1):CartesianIndex(2), ),
(IdentityUnitRange(-1:2), ),
(IdOffsetRange(-1:2),),
(IdOffsetRange(3:6, -4),)
]
offsets = size.(one_based_axes[1], 1)
offsets_big = map(big, offsets)
for inds in Any[offsets, offsets_big, one_based_axes...]
# test indices API
a = OffsetVector{Float64}(undef, inds)
@test eltype(a) === Float64
@test axes(a) === axes(OffsetVector{Float64}(undef, inds...)) === axes(OffsetArray{Float64, 1}(undef, inds)) === axes(OffsetArray{Float64}(undef, inds))
@test axes(a) === (IdOffsetRange(Base.OneTo(4), 0), )
@test a.offsets === (0, )
@test axes(a.parent) == (Base.OneTo(4), )
a = OffsetVector{Nothing}(nothing, inds)
@test eltype(a) === Nothing
@test axes(a) === axes(OffsetVector{Nothing}(nothing, inds...)) === axes(OffsetArray{Nothing, 1}(nothing, inds))
@test axes(a) === (IdOffsetRange(Base.OneTo(4), 0), )
a = OffsetVector{Missing}(missing, inds)
@test eltype(a) === Missing
@test axes(a) === axes(OffsetVector{Missing}(missing, inds...)) === axes(OffsetArray{Missing, 1}(missing, inds))
@test axes(a) === (IdOffsetRange(Base.OneTo(4), 0), )
end
# nested OffsetVectors
for inds in Any[offsets, offsets_big]
a = OffsetVector{Float64}(undef, inds)
b = OffsetVector(a, inds); b2 = OffsetVector(a, inds...);
@test eltype(b) === eltype(b2) === Float64
@test axes(b, 1) === axes(b2, 1) === IdOffsetRange(Base.OneTo(4), 4)
end
# offset indexing
for inds in offset_axes
# test offsets
a = OffsetVector{Float64}(undef, inds)
ax = (IdOffsetRange(Base.OneTo(4), -2), )
@test a.offsets === (-2, )
@test axes(a.parent) == (Base.OneTo(4), )
@test axes(a) === ax
a = OffsetVector{Nothing}(nothing, inds)
@test axes(a) === ax
a = OffsetVector{Missing}(missing, inds)
@test axes(a) === ax
for (T, t) in Any[(Nothing, nothing), (Missing, missing)]
a = OffsetVector{Union{T, Vector{Int}}}(undef, inds)
@test !isassigned(a, -1)
@test eltype(a) === Union{T, Vector{Int}}
@test axes(a) === ax
a = OffsetVector{Union{T, Vector{Int}}}(t, inds)
@test a[-1] === t
end
end
@test_throws Union{ArgumentError, ErrorException} OffsetVector{Float64}(undef, -2) # only positive number works
# convenient constructors
a = rand(4)
for inds in offset_axes
oa1 = OffsetVector(a, inds...)
oa2 = OffsetVector(a, inds)
oa3 = OffsetArray(a, inds...)
oa4 = OffsetArray(a, inds)
@test oa1 === oa2 === oa3 === oa4
@test axes(oa1) === (IdOffsetRange(Base.OneTo(4), -2), )
@test parent(oa1) === a
@test oa1.offsets === (-2, )
end
oa = OffsetArray(a, :)
@test oa === OffsetArray(a, (:, )) === OffsetArray(a, axes(a)) === OffsetVector(a, :) === OffsetVector(a, axes(a))
@test oa == a
@test axes(oa) == axes(a)
@test axes(oa) !== axes(a)
# nested offset array
a = rand(4)
oa = OffsetArray(a, -1)
for inds in Any[.-oa.offsets, one_based_axes...]
ooa = OffsetArray(oa, inds)
@test typeof(parent(ooa)) <: Vector
@test ooa === OffsetArray(oa, inds...) === OffsetVector(oa, inds) === OffsetVector(oa, inds...)
@test ooa == a
@test axes(ooa) == axes(a)
@test axes(ooa) !== axes(a)
end
# overflow bounds check
v = rand(5)
@test axes(OffsetVector(v, typemax(Int)-length(v))) == (IdOffsetRange(axes(v)[1], typemax(Int)-length(v)), )
@test_throws OverflowError OffsetVector(v, typemax(Int)-length(v)+1)
ao = OffsetArray(v, typemin(Int))
ao2 = OffsetArray{Float64, 1, typeof(ao)}(ao, (-1, ))
@test axes(ao2, 1) == typemin(Int) .+ (0:length(v)-1)
ao2 = OffsetArray(ao, (-1,))
@test axes(ao2, 1) == typemin(Int) .+ (0:length(v)-1)
@test_throws OverflowError OffsetArray{Float64, 1, typeof(ao)}(ao, (-2, )) # inner Constructor
@test_throws OverflowError OffsetArray(ao, (-2, )) # convinient constructor accumulate offsets
@test_throws OverflowError OffsetVector(1:0, typemax(Int))
@test_throws OverflowError OffsetVector(OffsetVector(1:0, 0), typemax(Int))
@test_throws OverflowError OffsetArray(zeros(Int, typemax(Int):typemax(Int)), 2)
@test_throws OverflowError OffsetArray(v, OffsetArrays.Origin(typemax(Int)))
b = OffsetArray(OffsetArray(big(1):2, 1), typemax(Int)-1)
@test axes(b, 1) == big(typemax(Int)) .+ (1:2)
@testset "OffsetRange" begin
for r in Any[1:100, big(1):big(2)]
a = OffsetVector(r, 4)
@test first(r) in a
@test !(last(r) + 1 in a)
end
@testset "BigInt axes" begin
r = OffsetArray(1:big(2)^65, 4000)
@test eltype(r) === BigInt
@test axes(r, 1) == (big(1):big(2)^65) .+ 4000
end
end
# disallow OffsetVector(::Array{<:Any, N}, offsets) where N != 1
@test_throws ArgumentError OffsetVector(zeros(2,2), (2, 2))
@test_throws ArgumentError OffsetVector(zeros(2,2), 2, 2)
@test_throws ArgumentError OffsetVector(zeros(2,2), (1:2, 1:2))
@test_throws ArgumentError OffsetVector(zeros(2,2), 1:2, 1:2)
@test_throws ArgumentError OffsetVector(zeros(), ())
@test_throws ArgumentError OffsetVector(zeros())
@test_throws ArgumentError OffsetVector(zeros(2,2), ())
@test_throws ArgumentError OffsetVector(zeros(2,2))
@test_throws ArgumentError OffsetVector(zeros(2,2), 2)
@test_throws ArgumentError OffsetVector(zeros(2,2), (2,))
@test_throws ArgumentError OffsetVector(zeros(2:3,2:3), 2, 3)
@test_throws ArgumentError OffsetVector(zeros(2:3,2:3), (2, 4))
@test_throws ArgumentError OffsetVector(zeros(2:3,2:3), ())
@test_throws ArgumentError OffsetVector(zeros(2:3,2:3))
# eltype of an OffsetArray should match that of the parent (issue #162)
@test_throws TypeError OffsetVector{Float64,Vector{ComplexF64}}
# ndim of an OffsetArray should match that of the parent
@test_throws TypeError OffsetVector{Float64,Matrix{Float64}}
end
@testset "OffsetMatrix" begin
# initialization
one_based_axes = Any[
(Base.OneTo(4), Base.OneTo(3)),
(1:4, 1:3),
(big(1):big(4), big(1):big(3)),
(CartesianIndex(1, 1):CartesianIndex(4, 3), ),
(CartesianIndex(1):CartesianIndex(4), CartesianIndex(1):CartesianIndex(3)),
(CartesianIndex(1):CartesianIndex(4), 1:3),
(IdentityUnitRange(1:4), IdentityUnitRange(1:3)),
(IdOffsetRange(1:4), IdOffsetRange(1:3)),
(IdOffsetRange(3:6, -2), IdOffsetRange(3:5, -2)),
(IdOffsetRange(3:6, -2), IdentityUnitRange(1:3)),
(IdOffsetRange(3:6, -2), 1:3),
]
offset_axes = Any[
(-1:2, 0:2),
(big(-1):big(2), big(0):big(2)),
(CartesianIndex(-1, 0):CartesianIndex(2, 2), ),
(-1:2, CartesianIndex(0):CartesianIndex(2)),
(CartesianIndex(-1):CartesianIndex(2), CartesianIndex(0):CartesianIndex(2)),
(CartesianIndex(-1):CartesianIndex(2), 0:2),
(IdentityUnitRange(-1:2), 0:2),
(IdOffsetRange(-1:2), IdOffsetRange(0:2)),
(IdOffsetRange(3:6, -4), IdOffsetRange(2:4, -2)),
(IdOffsetRange(3:6, -4), IdentityUnitRange(0:2)),
(IdOffsetRange(-1:2), 0:2),
]
offsets = size.(one_based_axes[1], 1)
offsets_big = map(big, offsets)
for inds in Any[offsets, offsets_big, one_based_axes...]
# test API
a = OffsetMatrix{Float64}(undef, inds)
ax = (IdOffsetRange(Base.OneTo(4), 0), IdOffsetRange(Base.OneTo(3), 0))
@test eltype(a) === Float64
@test axes(a) === axes(OffsetMatrix{Float64}(undef, inds...)) === axes(OffsetArray{Float64, 2}(undef, inds)) === axes(OffsetArray{Float64, 2}(undef, inds...)) === axes(OffsetArray{Float64}(undef, inds))
@test axes(a) === ax
@test a.offsets === (0, 0)
@test axes(a.parent) == (Base.OneTo(4), Base.OneTo(3))
a = OffsetMatrix{Nothing}(nothing, inds)
@test eltype(a) === Nothing
@test axes(a) === axes(OffsetMatrix{Nothing}(nothing, inds...)) === axes(OffsetArray{Nothing, 2}(nothing, inds)) === axes(OffsetArray{Nothing, 2}(nothing, inds...))
@test axes(a) === ax
a = OffsetMatrix{Missing}(missing, inds)
@test eltype(a) === Missing
@test axes(a) === axes(OffsetMatrix{Missing}(missing, inds...)) === axes(OffsetArray{Missing, 2}(missing, inds)) === axes(OffsetArray{Missing, 2}(missing, inds...))
@test axes(a) === ax
end
@test_throws Union{ArgumentError, ErrorException} OffsetMatrix{Float64}(undef, 2, -2) # only positive numbers works
# nested OffsetMatrices
for inds in Any[offsets, offsets_big]
a = OffsetMatrix{Float64}(undef, inds)
b = OffsetMatrix(a, inds); b2 = OffsetMatrix(a, inds...);
@test eltype(b) === eltype(b2) === Float64
@test axes(b, 1) === axes(b2, 1) === IdOffsetRange(Base.OneTo(4), 4)
@test axes(b, 2) === axes(b2, 2) === IdOffsetRange(Base.OneTo(3), 3)
end
for inds in offset_axes
# test offsets
a = OffsetMatrix{Float64}(undef, inds)
ax = (IdOffsetRange(Base.OneTo(4), -2), IdOffsetRange(Base.OneTo(3), -1))
@test a.offsets === (-2, -1)
@test axes(a.parent) == (Base.OneTo(4), Base.OneTo(3))
@test axes(a) === ax
a = OffsetMatrix{Nothing}(nothing, inds)
@test axes(a) === ax
a = OffsetMatrix{Missing}(missing, inds)
@test axes(a) === ax
for (T, t) in Any[(Nothing, nothing), (Missing, missing)]
a = OffsetMatrix{Union{T, Vector{Int}}}(undef, inds)
@test !isassigned(a, -1, 0)
@test eltype(a) === Union{T, Vector{Int}}
@test axes(a) === ax
a = OffsetMatrix{Union{T, Vector{Int}}}(t, inds)
@test a[-1, 0] === t
end
end
# convenient constructors
a = rand(4, 3)
for inds in offset_axes
ax = (IdOffsetRange(Base.OneTo(4), -2), IdOffsetRange(Base.OneTo(3), -1))
oa1 = OffsetMatrix(a, inds...)
oa2 = OffsetMatrix(a, inds)
oa3 = OffsetArray(a, inds...)
oa4 = OffsetArray(a, inds)
@test oa1 === oa2 === oa3 === oa4
@test axes(oa1) === ax
@test parent(oa1) === a
@test oa1.offsets === (-2, -1)
end
oa = OffsetArray(a, :, axes(a, 2))
@test oa === OffsetArray(a, (axes(oa, 1), :)) === OffsetArray(a, axes(a)) === OffsetMatrix(a, (axes(oa, 1), :)) === OffsetMatrix(a, axes(a))
@test oa == a
@test axes(oa) == axes(a)
@test axes(oa) !== axes(a)
oa = OffsetMatrix(a, :, 2:4)
@test oa === OffsetMatrix(a, axes(a, 1), 2:4) === OffsetMatrix(a, (axes(oa, 1), 2:4))
# nested offset array
a = rand(4, 3)
oa = OffsetArray(a, -1, -2)
for inds in Any[.-oa.offsets, one_based_axes...]
ooa = OffsetArray(oa, inds)
@test ooa === OffsetArray(oa, inds...) === OffsetMatrix(oa, inds) === OffsetMatrix(oa, inds...)
@test typeof(parent(ooa)) <: Matrix
@test ooa == a
@test axes(ooa) == axes(a)
@test axes(ooa) !== axes(a)
end
# overflow bounds check
a = rand(4, 3)
@test axes(OffsetMatrix(a, typemax(Int)-size(a, 1), 0)) == (IdOffsetRange(axes(a)[1], typemax(Int)-size(a, 1)), axes(a, 2))
@test_throws OverflowError OffsetMatrix(a, typemax(Int)-size(a,1)+1, 0)
@test_throws OverflowError OffsetMatrix(a, 0, typemax(Int)-size(a, 2)+1)
# disallow OffsetMatrix(::Array{<:Any, N}, offsets) where N != 2
@test_throws ArgumentError OffsetMatrix(zeros(2), (2,))
@test_throws ArgumentError OffsetMatrix(zeros(2), 2)
@test_throws ArgumentError OffsetMatrix(zeros(2), (1:2,))
@test_throws ArgumentError OffsetMatrix(zeros(2), 1:2)
@test_throws ArgumentError OffsetMatrix(zeros(), ())
@test_throws ArgumentError OffsetMatrix(zeros())
@test_throws ArgumentError OffsetMatrix(zeros(2), ())
@test_throws ArgumentError OffsetMatrix(zeros(2))
@test_throws ArgumentError OffsetMatrix(zeros(2), (1, 2))
@test_throws ArgumentError OffsetMatrix(zeros(2), 1, 2)
@test_throws ArgumentError OffsetMatrix(zeros(2:3), (2,))
@test_throws ArgumentError OffsetMatrix(zeros(2:3), 2)
@test_throws ArgumentError OffsetMatrix(zeros(2:3, 1:2, 1:2), (2,0,0))
@test_throws ArgumentError OffsetMatrix(zeros(2:3, 1:2, 1:2), 2,0,0)
@test_throws ArgumentError OffsetMatrix(zeros(2:3, 1:2, 1:2), ())
@test_throws ArgumentError OffsetMatrix(zeros(2:3, 1:2, 1:2))
# eltype of an OffsetArray should match that of the parent (issue #162)
@test_throws TypeError OffsetMatrix{Float64,Matrix{ComplexF64}}
# ndim of an OffsetArray should match that of the parent
@test_throws TypeError OffsetMatrix{Float64,Vector{Float64}}
end
# no need to duplicate the 2D case here,
# only add some special test cases
@testset "OffsetArray" begin
a = rand(2, 2, 2)
oa = OffsetArray(a, 0:1, 3:4, 2:3)
@test OffsetArray(a, CartesianIndices(axes(oa))) == oa
@test axes(OffsetArray(a, :, CartesianIndices((3:4, 2:3)))) == (1:2, 3:4, 2:3)
@test axes(OffsetArray(a, 10:11, CartesianIndices((3:4, 2:3)) )) == (10:11, 3:4, 2:3)
@test axes(OffsetArray(a, CartesianIndices((3:4, 2:3)), :)) == (3:4, 2:3, 1:2)
@test axes(OffsetArray(a, CartesianIndices((3:4, 2:3)), 10:11)) == (3:4, 2:3, 10:11)
@test axes(OffsetArray(a, :, :, CartesianIndices((3:4,)) )) == (1:2, 1:2, 3:4)
@test axes(OffsetArray(a, 10:11, :, CartesianIndices((3:4,)) )) == (10:11, 1:2, 3:4)
@test axes(OffsetArray(a, 10:11, 2:3, CartesianIndices((3:4,)) )) == (10:11, 2:3, 3:4)
# ignore empty CartesianIndices
@test OffsetArray(a, CartesianIndices(()), 0:1, :, 2:3) == OffsetArray(a, 0:1, :, 2:3)
@test OffsetArray(a, 0:1, CartesianIndices(()), :, 2:3) == OffsetArray(a, 0:1, :, 2:3)
@test OffsetArray(a, 0:1, :, CartesianIndices(()), 2:3) == OffsetArray(a, 0:1, :, 2:3)
@test OffsetArray(a, 0:1, :, 2:3, CartesianIndices(())) == OffsetArray(a, 0:1, :, 2:3)
# nested OffsetArrays
for offsets in [(1,1,1), big.((1,1,1))]
ob = OffsetArray(oa, offsets); ob2 = OffsetArray(oa, offsets...);
@test eltype(ob) === eltype(ob2) === Float64
@test axes(ob, 1) === axes(ob2, 1) === IdOffsetRange(Base.OneTo(2), 0)
@test axes(ob, 2) === axes(ob2, 2) === IdOffsetRange(Base.OneTo(2), 3)
@test axes(ob, 3) === axes(ob2, 3) === IdOffsetRange(Base.OneTo(2), 2)
end
indices = (-1:1, -7:7, -1:2, -5:5, -1:1, -3:3, -2:2, -1:1)
y = OffsetArray{Float64}(undef, indices...);
@test axes(y) === axes(OffsetArray{Float64}(undef, indices))
@test axes(y) === axes(OffsetArray{Float64, length(indices)}(undef, indices...))
@test axes(y) == (-1:1, -7:7, -1:2, -5:5, -1:1, -3:3, -2:2, -1:1)
@test eltype(y) === Float64
@test_throws ArgumentError OffsetArray{Float64, 2}(undef, indices)
@test_throws ArgumentError OffsetArray(y, indices[1:2])
@test ndims(OffsetArray(zeros(), ())) == 0
@test Base.axes1(OffsetArray(zeros(), ())) === OffsetArrays.IdOffsetRange(Base.OneTo(1))
@testset "convenience constructors" begin
ax = (2:3, 4:5)
for f in (zeros, ones)
a = f(Float64, ax)
@test axes(a) == ax
@test eltype(a) == Float64
end
for f in (trues, falses)
a = f(ax)
@test axes(a) == ax
@test eltype(a) == Bool
end
end
# eltype of an OffsetArray should match that of the parent (issue #162)
@test_throws TypeError OffsetArray{Float64,2,Matrix{ComplexF64}}
# ndim of an OffsetArray should match that of the parent
@test_throws TypeError OffsetArray{Float64,3,Matrix{Float64}}
# should throw a TypeError if the offsets can not be converted to Ints
@test_throws TypeError OffsetVector{Int,Vector{Int}}(zeros(Int,2), (WeirdInteger(1),))
end
@testset "custom range types" begin
@testset "EllipsisNotation" begin
@testset "Vector" begin
v = rand(5)
@test axes(OffsetArray(v, ..)) == axes(v)
@test OffsetArray(v, ..) == OffsetArray(v, :)
@test axes(OffsetVector(v, ..)) == axes(v)
@test OffsetVector(v, ..) == OffsetVector(v, :)
@test axes(OffsetArray(v, .., 2:6)) == (2:6, )
@test OffsetArray(v, .., 2:6) == OffsetArray(v, 2:6)
@test axes(OffsetVector(v, .., 2:6)) == (2:6, )
@test OffsetVector(v, .., 2:6) == OffsetVector(v, 2:6)
end
@testset "Matrix" begin
m = rand(2, 2)
@test axes(OffsetArray(m, ..)) == axes(m)
@test OffsetArray(m, ..) == OffsetArray(m, :, :)
@test axes(OffsetMatrix(m, ..)) == axes(m)
@test OffsetMatrix(m, ..) == OffsetMatrix(m, :, :)
@test axes(OffsetArray(m, .., 2:3)) == (axes(m, 1), 2:3)
@test OffsetArray(m, .., 2:3) == OffsetArray(m, :, 2:3)
@test axes(OffsetMatrix(m, .., 2:3)) == (axes(m, 1), 2:3)
@test OffsetMatrix(m, .., 2:3) == OffsetMatrix(m, :, 2:3)
@test axes(OffsetArray(m, .., 2:3, 3:4)) == (2:3, 3:4)
@test OffsetArray(m, .., 2:3, 3:4) == OffsetArray(m, 2:3, 3:4)
@test axes(OffsetMatrix(m, .., 2:3, 3:4)) == (2:3, 3:4)
@test OffsetMatrix(m, .., 2:3, 3:4) == OffsetMatrix(m, 2:3, 3:4)
end
@testset "3D Array" begin
a = rand(2, 2, 2)
@test axes(OffsetArray(a, ..)) == axes(a)
@test OffsetArray(a, ..) == OffsetArray(a, :, :, :)
@test axes(OffsetArray(a, .., 2:3)) == (axes(a)[1:2]..., 2:3)
@test OffsetArray(a, .., 2:3) == OffsetArray(a, :, :, 2:3)
@test axes(OffsetArray(a, .., 2:3, 3:4)) == (axes(a, 1), 2:3, 3:4)
@test OffsetArray(a, .., 2:3, 3:4) == OffsetArray(a, :, 2:3, 3:4)
@test axes(OffsetArray(a, 2:3, .., 3:4)) == (2:3, axes(a, 2), 3:4)
@test OffsetArray(a, 2:3, .., 3:4) == OffsetArray(a, 2:3, :, 3:4)
@test axes(OffsetArray(a, .., 4:5, 2:3, 3:4)) == (4:5, 2:3, 3:4)
@test OffsetArray(a, .., 4:5, 2:3, 3:4) == OffsetArray(a, 4:5, 2:3, 3:4)
end
end
@testset "ZeroBasedIndexing" begin
Base.to_indices(A, inds, ::Tuple{ZeroBasedIndexing}) = map(x -> 0:length(x) - 1, inds)
a = zeros(3,3)
oa = OffsetArray(a, ZeroBasedIndexing())
@test axes(oa) == (0:2, 0:2)
end
@testset "TupleOfRanges" begin
Base.to_indices(A, inds, t::Tuple{TupleOfRanges{N}}) where {N} = t
OffsetArrays.AxisConversionStyle(::Type{TupleOfRanges{N}}) where {N} =
OffsetArrays.TupleOfRanges()
Base.convert(::Type{Tuple{Vararg{AbstractUnitRange{Int}}}}, t::TupleOfRanges) = t.x
a = zeros(3,3)
inds = TupleOfRanges((3:5, 2:4))
oa = OffsetArray(a, inds)
@test axes(oa) == inds.x
end
@testset "NewColon" begin
Base.to_indices(A, inds, t::Tuple{NewColon,Vararg{Any}}) =
(_uncolon(inds, t), to_indices(A, Base.tail(inds), Base.tail(t))...)
_uncolon(inds::Tuple{}, I::Tuple{NewColon, Vararg{Any}}) = OneTo(1)
_uncolon(inds::Tuple, I::Tuple{NewColon, Vararg{Any}}) = inds[1]
a = zeros(3, 3)
oa = OffsetArray(a, (NewColon(), 2:4))
@test axes(oa) == (axes(a,1), 2:4)
end
end
@testset "Offset range construction" begin
r = -2:5
for AT in Any[OffsetArray, OffsetVector]
y = AT(r, r)
@test axes(y) == (r,)
@test step(y) == step(r)
y = AT(r, (r,))
@test axes(y) == (r,)
y = AT(r, CartesianIndices((r, )))
@test axes(y) == (r, )
end
end
@testset "size/length" begin
for p in Any[SA[1,2,3,4], 1:4, [1:4;]]
for A in Any[OffsetArray(p, 4),
OffsetArray(reshape(p, 2, 2), 3, 4),
OffsetArray(reshape(p, 2, 1, 2), 3, 0, 4),
OffsetArray(reshape(p, Val(1)), 2)]
@test size(A) == size(parent(A))
@test length(A) == length(parent(A))
end
end
end
@testset "convert" begin
m = zeros(1,1)
mo = @inferred (x -> convert(OffsetArray{Float64,2,Matrix{Float64}}, x[1]))(Any[m])
@test mo == m
end
end
@testset "Axes supplied to constructor correspond to final result" begin
# Ref https://github.com/JuliaArrays/OffsetArrays.jl/pull/65#issuecomment-457181268
B = BidirectionalVector([1, 2, 3], -2)
A = OffsetArray(B, -1:1)
@test axes(A) == (IdentityUnitRange(-1:1),)
end
@testset "unwrap" begin
for A in [ones(2, 2), ones(2:3, 2:3), ZeroBasedRange(1:4)]
p, f = OffsetArrays.unwrap(A)
@test f(map(y -> y^2, p)) == A.^2
end
end
@testset "Traits" begin
A0 = [1 3; 2 4]
A = OffsetArray(A0, (-1,2)) # IndexLinear
S = OffsetArray(view(A0, 1:2, 1:2), (-1,2)) # IndexCartesian
@test axes(A) === axes(S)
@test axes(A) == axes(S) == (0:1, 3:4)
@test axes(A, 1) === OffsetArrays.IdOffsetRange(Base.OneTo(2), -1)
@test size(A) == size(A0)
@test size(A, 1) == size(A0, 1)
@test length(A) == length(A0)
@test A == OffsetArray(A0, 0:1, 3:4)
@test_throws DimensionMismatch OffsetArray(A0, 0:2, 3:4)
@test_throws DimensionMismatch OffsetArray(A0, 0:1, 2:4)
@test eachindex(IndexLinear(), A) == eachindex(IndexLinear(), parent(A))
@test eachindex(IndexCartesian(), A) == CartesianIndices(A) == CartesianIndices(axes(A))
@test eachindex(S) == eachindex(IndexCartesian(), S) == CartesianIndices(S)
@test eachindex(IndexLinear(), S) == eachindex(IndexLinear(), A0)
A = ones(5:6)
@test eachindex(IndexLinear(), A) === axes(A, 1)
A = OffsetArray(big(1):big(2), 1)
B = OffsetArray(1:2, 1)
@test CartesianIndices(A) == CartesianIndices(B)
@test LinearIndices(A) == LinearIndices(B)
@test eachindex(A) == eachindex(B)
end
@testset "Scalar indexing" begin
A0 = [1 3; 2 4]
A = OffsetArray(A0, (-1,2))
S = OffsetArray(view(A0, 1:2, 1:2), (-1,2))
@test @inferred(A[0,3]) == @inferred(A[0,3,1]) == @inferred(A[1]) == @inferred(S[0,3]) == @inferred(S[0,3,1]) == @inferred(S[1]) == 1
@test A[1,3] == A[1,3,1] == A[2] == S[1,3] == S[1,3,1] == S[2] == 2
@test A[0,4] == A[0,4,1] == A[3] == S[0,4] == S[0,4,1] == S[3] == 3
@test A[1,4] == A[1,4,1] == A[4] == S[1,4] == S[1,4,1] == S[4] == 4
@test @inbounds(A[0,3]) == @inbounds(A[0,3,1]) == @inbounds(A[1]) == @inbounds(S[0,3]) == @inbounds(S[0,3,1]) == @inbounds(S[1]) == 1
@test @inbounds(A[1,3]) == @inbounds(A[1,3,1]) == @inbounds(A[2]) == @inbounds(S[1,3]) == @inbounds(S[1,3,1]) == @inbounds(S[2]) == 2
@test @inbounds(A[0,4]) == @inbounds(A[0,4,1]) == @inbounds(A[3]) == @inbounds(S[0,4]) == @inbounds(S[0,4,1]) == @inbounds(S[3]) == 3
@test @inbounds(A[1,4]) == @inbounds(A[1,4,1]) == @inbounds(A[4]) == @inbounds(S[1,4]) == @inbounds(S[1,4,1]) == @inbounds(S[4]) == 4
@test_throws BoundsError(A, (1,1)) A[1,1]
@test_throws BoundsError(A, (1,1)) A[1,1] = 4
@test_throws BoundsError(S, (1,1)) S[1,1]
@test_throws BoundsError(S, (1,1)) S[1,1] = 4
@test_throws BoundsError(A, (0,3,2)) A[0,3,2]
@test_throws BoundsError(A, (0,3,2)) A[0,3,2] = 4
@test_throws BoundsError(A, (0,3,0)) A[0,3,0]
@test_throws BoundsError(A, (0,3,0)) A[0,3,0] = 4
Ac = copy(A)
Ac[0,3] = 10
@test Ac[0,3] == 10
Ac[0,3,1] = 11
@test Ac[0,3] == 11
@inbounds Ac[0,3,1] = 12
@test Ac[0,3] == 12