@@ -207,22 +207,22 @@ end
207
207
@testset " Range Interface" begin
208
208
@testset " Range Constructors" begin
209
209
@test @inferred (StaticInt (1 ): StaticInt (10 )) == 1 : 10
210
- @test @inferred (StaticInt (1 ): StaticInt (2 ): StaticInt (10 )) == 1 : 2 : 10
210
+ @test @inferred (StaticInt (1 ): StaticInt (2 ): StaticInt (10 )) == 1 : 2 : 10
211
211
@test @inferred (1 : StaticInt (2 ): StaticInt (10 )) == 1 : 2 : 10
212
212
@test @inferred (StaticInt (1 ): StaticInt (2 ): 10 ) == 1 : 2 : 10
213
- @test @inferred (StaticInt (1 ): 2 : StaticInt (10 )) == 1 : 2 : 10
213
+ @test @inferred (StaticInt (1 ): 2 : StaticInt (10 )) == 1 : 2 : 10
214
214
@test @inferred (1 : 2 : StaticInt (10 )) == 1 : 2 : 10
215
215
@test @inferred (1 : StaticInt (2 ): 10 ) == 1 : 2 : 10
216
- @test @inferred (StaticInt (1 ): 2 : 10 ) == 1 : 2 : 10
217
- @test @inferred (StaticInt (1 ): UInt (10 )) === StaticInt (1 ): 10
216
+ @test @inferred (StaticInt (1 ): 2 : 10 ) == 1 : 2 : 10
217
+ @test @inferred (StaticInt (1 ): UInt (10 )) === StaticInt (1 ): 10
218
218
@test @inferred (UInt (1 ): StaticInt (1 ): StaticInt (10 )) === 1 : StaticInt (10 )
219
219
@test @inferred (ArrayInterface. OptionallyStaticUnitRange {Int,Int} (1 : 10 )) == 1 : 10
220
220
@test @inferred (ArrayInterface. OptionallyStaticUnitRange (1 : 10 )) == 1 : 10
221
221
222
222
@inferred (ArrayInterface. OptionallyStaticUnitRange (1 : 10 ))
223
223
224
- @test @inferred (ArrayInterface. OptionallyStaticStepRange (StaticInt (1 ), 1 , UInt (10 ))) == StaticInt (1 ): 1 : 10
225
- @test @inferred (ArrayInterface. OptionallyStaticStepRange (UInt (1 ), 1 , StaticInt (10 ))) == StaticInt (1 ): 1 : 10
224
+ @test @inferred (ArrayInterface. OptionallyStaticStepRange (StaticInt (1 ), 1 , UInt (10 ))) == StaticInt (1 ): 1 : 10
225
+ @test @inferred (ArrayInterface. OptionallyStaticStepRange (UInt (1 ), 1 , StaticInt (10 ))) == StaticInt (1 ): 1 : 10
226
226
@test @inferred (ArrayInterface. OptionallyStaticStepRange (1 : 10 )) == 1 : 1 : 10
227
227
228
228
@test_throws ArgumentError ArrayInterface. OptionallyStaticUnitRange (1 : 2 : 10 )
@@ -331,7 +331,6 @@ using OffsetArrays
331
331
@test @inferred (ArrayInterface. defines_strides (D1))
332
332
@test ! @inferred (ArrayInterface. defines_strides (view (A, :, [1 ,2 ],1 )))
333
333
@test @inferred (ArrayInterface. defines_strides (DenseWrapper{Int,2 ,Matrix{Int}}))
334
-
335
334
@test @inferred (device (A)) === ArrayInterface. CPUPointer ()
336
335
@test @inferred (device (B)) === ArrayInterface. CPUIndex ()
337
336
@test @inferred (device (- 1 : 19 )) === ArrayInterface. CPUIndex ()
@@ -372,7 +371,7 @@ using OffsetArrays
372
371
@test @inferred (contiguous_axis (PermutedDimsArray (DummyZeros (3 ,4 ), (2 , 1 )))) === nothing
373
372
@test @inferred (contiguous_axis (view (DummyZeros (3 ,4 ), 1 , :))) === nothing
374
373
@test @inferred (contiguous_axis (view (DummyZeros (3 ,4 ), 1 , :)' )) === nothing
375
-
374
+
376
375
@test @inferred (ArrayInterface. contiguous_axis_indicator (@SArray (zeros (2 ,2 ,2 )))) == (true ,false ,false )
377
376
@test @inferred (ArrayInterface. contiguous_axis_indicator (A)) == (true ,false ,false )
378
377
@test @inferred (ArrayInterface. contiguous_axis_indicator (B)) == (true ,false ,false )
@@ -424,7 +423,7 @@ using OffsetArrays
424
423
@test @inferred (stride_rank (PermutedDimsArray (DummyZeros (3 ,4 ), (2 , 1 )))) === nothing
425
424
@test @inferred (stride_rank (view (DummyZeros (3 ,4 ), 1 , :))) === nothing
426
425
427
-
426
+
428
427
#=
429
428
@btime ArrayInterface.is_column_major($(PermutedDimsArray(A,(3,1,2))))
430
429
0.047 ns (0 allocations: 0 bytes)
@@ -494,11 +493,11 @@ using OffsetArrays
494
493
@test @inferred (ArrayInterface. defines_strides (C1))
495
494
@test @inferred (ArrayInterface. defines_strides (C2))
496
495
@test @inferred (ArrayInterface. defines_strides (C3))
497
-
496
+
498
497
@test @inferred (device (C1)) === ArrayInterface. CPUPointer ()
499
498
@test @inferred (device (C2)) === ArrayInterface. CPUPointer ()
500
499
@test @inferred (device (C3)) === ArrayInterface. CPUPointer ()
501
-
500
+
502
501
@test @inferred (contiguous_batch_size (C1)) === ArrayInterface. StaticInt (0 )
503
502
@test @inferred (contiguous_batch_size (C2)) === ArrayInterface. StaticInt (0 )
504
503
@test @inferred (contiguous_batch_size (C3)) === ArrayInterface. StaticInt (0 )
@@ -510,7 +509,7 @@ using OffsetArrays
510
509
@test @inferred (contiguous_axis (C1)) === StaticInt (1 )
511
510
@test @inferred (contiguous_axis (C2)) === StaticInt (0 )
512
511
@test @inferred (contiguous_axis (C3)) === StaticInt (2 )
513
-
512
+
514
513
@test @inferred (ArrayInterface. contiguous_axis_indicator (C1)) == (true ,false ,false ,false )
515
514
@test @inferred (ArrayInterface. contiguous_axis_indicator (C2)) == (false ,false )
516
515
@test @inferred (ArrayInterface. contiguous_axis_indicator (C3)) == (false ,true )
535
534
R = StaticInt (1 ): StaticInt (2 );
536
535
Rnr = reinterpret (Int32, R);
537
536
Ar = reinterpret (Float32, A);
537
+ A2 = zeros (4 , 3 , 5 )
538
+ A2r = reinterpret (ComplexF64, A2)
538
539
539
540
sv5 = @SVector (zeros (5 )); v5 = Vector {Float64} (undef, 5 );
540
541
@test @inferred (ArrayInterface. size (sv5)) === (StaticInt (5 ),)
546
547
@test @inferred (ArrayInterface. size (R)) === (StaticInt (2 ),)
547
548
@test @inferred (ArrayInterface. size (Rnr)) === (StaticInt (4 ),)
548
549
@test @inferred (ArrayInterface. known_length (Rnr)) === 4
550
+ @test @inferred (ArrayInterface. size (A2)) === (4 ,3 ,5 )
551
+ @test @inferred (ArrayInterface. size (A2r)) === (2 ,3 ,5 )
549
552
550
553
@test @inferred (ArrayInterface. size (S)) === (StaticInt (2 ), StaticInt (3 ), StaticInt (4 ))
551
554
@test @inferred (ArrayInterface. size (Sp)) === (2 , 2 , StaticInt (3 ))
577
580
@test @inferred (ArrayInterface. known_size (Ar)) === (nothing ,nothing , nothing ,)
578
581
@test @inferred (ArrayInterface. known_size (Ar, static (1 ))) === nothing
579
582
@test @inferred (ArrayInterface. known_size (Ar, static (4 ))) === 1
583
+ @test @inferred (ArrayInterface. known_size (A2)) === (nothing , nothing , nothing )
584
+ @test @inferred (ArrayInterface. known_size (A2r)) === (nothing , nothing , nothing )
580
585
581
586
@test @inferred (ArrayInterface. known_size (S)) === (2 , 3 , 4 )
582
587
@test @inferred (ArrayInterface. known_size (Wrapper (S))) === (2 , 3 , 4 )
596
601
@test @inferred (ArrayInterface. strides (A)) == strides (A)
597
602
@test @inferred (ArrayInterface. strides (Ap)) == strides (Ap)
598
603
@test @inferred (ArrayInterface. strides (Ar)) === (StaticInt {1} (), 6 , 24 )
604
+ @test @inferred (ArrayInterface. strides (A2)) === (StaticInt (1 ), 4 , 12 )
605
+ @test @inferred (ArrayInterface. strides (A2r)) === (StaticInt (1 ), 2 , 6 )
599
606
600
607
@test @inferred (ArrayInterface. strides (S)) === (StaticInt (1 ), StaticInt (2 ), StaticInt (6 ))
601
608
@test @inferred (ArrayInterface. strides (Sp)) === (StaticInt (6 ), StaticInt (1 ), StaticInt (2 ))
618
625
@test @inferred (ArrayInterface. known_strides (Ap)) === (1 , nothing )
619
626
@test @inferred (ArrayInterface. known_strides (Ar)) === (1 , nothing , nothing )
620
627
@test @inferred (ArrayInterface. known_strides (reshape (view (zeros (100 ), 1 : 60 ), (3 ,4 ,5 )))) === (1 , nothing , nothing )
628
+ @test @inferred (ArrayInterface. known_strides (A2)) === (1 , nothing , nothing )
629
+ @test @inferred (ArrayInterface. known_strides (A2r)) === (1 , nothing , nothing )
621
630
622
631
@test @inferred (ArrayInterface. known_strides (S)) === (1 , 2 , 6 )
623
632
@test @inferred (ArrayInterface. known_strides (Sp)) === (6 , 1 , 2 )
635
644
@test @inferred (ArrayInterface. offsets (A)) === (StaticInt (1 ), StaticInt (1 ), StaticInt (1 ))
636
645
@test @inferred (ArrayInterface. offsets (Ap)) === (StaticInt (1 ), StaticInt (1 ))
637
646
@test @inferred (ArrayInterface. offsets (Ar)) === (StaticInt (1 ), StaticInt (1 ), StaticInt (1 ))
647
+ @test @inferred (ArrayInterface. offsets (A2)) === (StaticInt (1 ), StaticInt (1 ), StaticInt (1 ))
648
+ @test @inferred (ArrayInterface. offsets (A2r)) === (StaticInt (1 ), StaticInt (1 ), StaticInt (1 ))
638
649
639
650
@test @inferred (ArrayInterface. offsets (S)) === (StaticInt (1 ), StaticInt (1 ), StaticInt (1 ))
640
651
@test @inferred (ArrayInterface. offsets (Sp)) === (StaticInt (1 ), StaticInt (1 ), StaticInt (1 ))
649
660
@test @inferred (ArrayInterface. known_offsets (Ar)) === (1 , 1 , 1 )
650
661
@test @inferred (ArrayInterface. known_offsets (Ar, static (1 ))) === 1
651
662
@test @inferred (ArrayInterface. known_offsets (Ar, static (4 ))) === 1
663
+ @test @inferred (ArrayInterface. known_offsets (A2)) === (1 , 1 , 1 )
664
+ @test @inferred (ArrayInterface. known_offsets (A2r)) === (1 , 1 , 1 )
652
665
653
666
@test @inferred (ArrayInterface. known_offsets (S)) === (1 , 1 , 1 )
654
667
@test @inferred (ArrayInterface. known_offsets (Sp)) === (1 , 1 , 1 )
675
688
colormat = reinterpret (reshape, Float64, colors)
676
689
@test @inferred (ArrayInterface. strides (colormat)) === (StaticInt (1 ), StaticInt (3 ))
677
690
@test @inferred (ArrayInterface. dense_dims (colormat)) === (True (),True ())
678
- @test @inferred (ArrayInterface. dense_dims (view (colormat,:,4 ))) === (True (),)
691
+ @test @inferred (ArrayInterface. dense_dims (view (colormat,:,4 ))) === (True (),)
679
692
@test @inferred (ArrayInterface. dense_dims (view (colormat,:,4 : 7 ))) === (True (),True ())
680
693
@test @inferred (ArrayInterface. dense_dims (view (colormat,2 : 3 ,:))) === (True (),False ())
681
694
702
715
@test @inferred (ArrayInterface. strides (Ac2r)) === (StaticInt (1 ), StaticInt (2 ), 10 )
703
716
Ac2r_static = reinterpret (reshape, Float64, view (@MMatrix (rand (ComplexF64, 5 , 7 )), 2 : 4 , 3 : 6 ));
704
717
@test @inferred (ArrayInterface. strides (Ac2r_static)) === (StaticInt (1 ), StaticInt (2 ), StaticInt (10 ))
705
-
718
+
706
719
Ac2t = reinterpret (reshape, Tuple{Float64,Float64}, view (rand (ComplexF64, 5 , 7 ), 2 : 4 , 3 : 6 ));
707
720
@test @inferred (ArrayInterface. strides (Ac2t)) === (StaticInt (1 ), 5 )
708
721
Ac2t_static = reinterpret (reshape, Tuple{Float64,Float64}, view (@MMatrix (rand (ComplexF64, 5 , 7 )), 2 : 4 , 3 : 6 ));
711
724
end
712
725
end
713
726
727
+ @testset " Reshaped views" begin
728
+ u_base = randn (10 , 10 )
729
+ u_view = view (u_base, 3 , :)
730
+ u_reshaped_view1 = reshape (u_view, 1 , :)
731
+ u_reshaped_view2 = reshape (u_view, 2 , :)
732
+
733
+ @test @inferred (ArrayInterface. defines_strides (u_base))
734
+ @test @inferred (ArrayInterface. defines_strides (u_view))
735
+ @test @inferred (ArrayInterface. defines_strides (u_reshaped_view1))
736
+ @test @inferred (ArrayInterface. defines_strides (u_reshaped_view2))
737
+
738
+ # See https://github.com/JuliaArrays/ArrayInterface.jl/issues/160
739
+ @test @inferred (ArrayInterface. strides (u_base)) == (StaticInt (1 ), 10 )
740
+ @test @inferred (ArrayInterface. strides (u_view)) == (10 ,)
741
+ @test @inferred (ArrayInterface. strides (u_reshaped_view1)) == (10 , 10 )
742
+ @test @inferred (ArrayInterface. strides (u_reshaped_view2)) == (10 , 20 )
743
+
744
+ # See https://github.com/JuliaArrays/ArrayInterface.jl/issues/157
745
+ @test @inferred (ArrayInterface. dense_dims (u_base)) == (True (), True ())
746
+ @test @inferred (ArrayInterface. dense_dims (u_view)) == (False (),)
747
+ @test @inferred (ArrayInterface. dense_dims (u_reshaped_view1)) == (False (), False ())
748
+ @test @inferred (ArrayInterface. dense_dims (u_reshaped_view2)) == (False (), False ())
749
+ end
750
+
751
+ @testset " Reinterpreted reshaped views" begin
752
+ u_base = randn (1 , 4 , 4 , 5 )
753
+ u_vectors = reshape (reinterpret (SVector{1 , eltype (u_base)}, u_base),
754
+ Base. tail (size (u_base))... )
755
+ u_view = view (u_vectors, 2 , :, 3 )
756
+ u_view_reinterpreted = reinterpret (eltype (u_base), u_view)
757
+ u_view_reshaped = reshape (u_view_reinterpreted, 1 , length (u_view))
758
+
759
+ # See https://github.com/JuliaArrays/ArrayInterface.jl/issues/163
760
+ @test @inferred (ArrayInterface. strides (u_base)) == (StaticInt (1 ), 1 , 4 , 16 )
761
+ @test @inferred (ArrayInterface. strides (u_vectors)) == (StaticInt (1 ), 4 , 16 )
762
+ @test @inferred (ArrayInterface. strides (u_view)) == (4 ,)
763
+ if VERSION ≥ v " 1.6.0-DEV.1581"
764
+ @test @inferred (ArrayInterface. strides (u_view_reinterpreted)) == (4 ,)
765
+ @test @inferred (ArrayInterface. strides (u_view_reshaped)) == (4 , 4 )
766
+ else
767
+ @test_broken @inferred (ArrayInterface. strides (u_view_reinterpreted)) == (4 ,)
768
+ @test_broken @inferred (ArrayInterface. strides (u_view_reshaped)) == (4 , 4 )
769
+ end
770
+ end
771
+
714
772
@test ArrayInterface. can_avx (ArrayInterface. can_avx) == false
715
773
716
774
@testset " can_change_size" begin
842
900
@test @inferred (is_lazy_conjugate (d)) == false
843
901
e = permutedims (d)
844
902
@test @inferred (is_lazy_conjugate (e)) == false
845
-
903
+
846
904
@test @inferred (is_lazy_conjugate ([1 ,2 ,3 ]' )) == false # We don't care about conj on `<:Real`
847
905
end
0 commit comments