@@ -1583,11 +1583,11 @@ end
1583
1583
@test length (rr) == length (r)
1584
1584
end
1585
1585
1586
- struct FakeZeroDimArray <: AbstractArray{Int, 0} end
1587
- Base. strides (:: FakeZeroDimArray ) = ()
1588
- Base. size (:: FakeZeroDimArray ) = ()
1586
+ module IRUtils
1587
+ include (normpath (@__DIR__ , " ./compiler/irutils.jl" ))
1588
+ end
1589
+
1589
1590
@testset " strides for ReshapedArray" begin
1590
- # Type-based contiguous check is tested in test/compiler/inline.jl
1591
1591
function check_strides (A:: AbstractArray )
1592
1592
# Make sure stride(A, i) is equivalent with strides(A)[i] (if 1 <= i <= ndims(A))
1593
1593
dims = ntuple (identity, ndims (A))
@@ -1598,6 +1598,10 @@ Base.size(::FakeZeroDimArray) = ()
1598
1598
end
1599
1599
return true
1600
1600
end
1601
+ # Type-based contiguous Check
1602
+ a = vec (reinterpret (reshape,Int16,reshape (view (reinterpret (Int32,randn (10 )),2 : 11 ),5 ,:)))
1603
+ f (a) = only (strides (a));
1604
+ @test IRUtils. fully_eliminated (f, Base. typesof (a)) && f (a) == 1
1601
1605
# General contiguous check
1602
1606
a = view (rand (10 ,10 ), 1 : 10 , 1 : 10 )
1603
1607
@test check_strides (vec (a))
@@ -1629,6 +1633,9 @@ Base.size(::FakeZeroDimArray) = ()
1629
1633
@test_throws " Input is not strided." strides (reshape (a,3 ,5 ,3 ,2 ))
1630
1634
@test_throws " Input is not strided." strides (reshape (a,5 ,3 ,3 ,2 ))
1631
1635
# Zero dimensional parent
1636
+ struct FakeZeroDimArray <: AbstractArray{Int, 0} end
1637
+ Base. strides (:: FakeZeroDimArray ) = ()
1638
+ Base. size (:: FakeZeroDimArray ) = ()
1632
1639
a = reshape (FakeZeroDimArray (),1 ,1 ,1 )
1633
1640
@test @inferred (strides (a)) == (1 , 1 , 1 )
1634
1641
# Dense parent (but not StridedArray)
@@ -1660,3 +1667,21 @@ end
1660
1667
@test (@inferred A[i,i,i]) === A[1 ]
1661
1668
@test (@inferred to_indices ([], (1 , CIdx (1 , 1 ), 1 , CIdx (1 , 1 ), 1 , CIdx (1 , 1 ), 1 ))) == ntuple (Returns (1 ), 10 )
1662
1669
end
1670
+
1671
+ @testset " type-based offset axes check" begin
1672
+ a = randn (ComplexF64, 10 )
1673
+ ta = reinterpret (Float64, a)
1674
+ tb = reinterpret (Float64, view (a, 1 : 2 : 10 ))
1675
+ tc = reinterpret (Float64, reshape (view (a, 1 : 3 : 10 ), 2 , 2 , 1 ))
1676
+ # Issue #44040
1677
+ @test IRUtils. fully_eliminated (Base. require_one_based_indexing, Base. typesof (ta,tc))
1678
+ @test IRUtils. fully_eliminated (Base. require_one_based_indexing, Base. typesof (tc,tc))
1679
+ @test IRUtils. fully_eliminated (Base. require_one_based_indexing, Base. typesof (ta,tc,tb))
1680
+ # Ranges && CartesianIndices
1681
+ @test IRUtils. fully_eliminated (Base. require_one_based_indexing, Base. typesof (1 : 10 ,Base. OneTo (10 ),1.0 : 2.0 ,LinRange (1.0 ,2.0 ,2 ),1 : 2 : 10 ,CartesianIndices ((1 : 2 : 10 ,1 : 2 : 10 ))))
1682
+ # Remind us to call `any` in `Base.has_offset_axes` once our compiler is ready.
1683
+ @inline _has_offset_axes (A) = @inline any (x-> Int (first (x)):: Int != 1 , axes (A))
1684
+ @inline _has_offset_axes (As... ) = @inline any (_has_offset_axes, As)
1685
+ a, b = zeros (2 ,2 ,2 ), zeros (2 ,2 )
1686
+ @test_broken IRUtils. fully_eliminated (_has_offset_axes, Base. typesof (a,a,b,b))
1687
+ end
0 commit comments