Skip to content

Commit 9b340c9

Browse files
committed
Some test move.
1 parent 1cb5f9d commit 9b340c9

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

test/abstractarray.jl

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,11 +1583,11 @@ end
15831583
@test length(rr) == length(r)
15841584
end
15851585

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+
15891590
@testset "strides for ReshapedArray" begin
1590-
# Type-based contiguous check is tested in test/compiler/inline.jl
15911591
function check_strides(A::AbstractArray)
15921592
# Make sure stride(A, i) is equivalent with strides(A)[i] (if 1 <= i <= ndims(A))
15931593
dims = ntuple(identity, ndims(A))
@@ -1598,6 +1598,10 @@ Base.size(::FakeZeroDimArray) = ()
15981598
end
15991599
return true
16001600
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
16011605
# General contiguous check
16021606
a = view(rand(10,10), 1:10, 1:10)
16031607
@test check_strides(vec(a))
@@ -1629,6 +1633,9 @@ Base.size(::FakeZeroDimArray) = ()
16291633
@test_throws "Input is not strided." strides(reshape(a,3,5,3,2))
16301634
@test_throws "Input is not strided." strides(reshape(a,5,3,3,2))
16311635
# Zero dimensional parent
1636+
struct FakeZeroDimArray <: AbstractArray{Int, 0} end
1637+
Base.strides(::FakeZeroDimArray) = ()
1638+
Base.size(::FakeZeroDimArray) = ()
16321639
a = reshape(FakeZeroDimArray(),1,1,1)
16331640
@test @inferred(strides(a)) == (1, 1, 1)
16341641
# Dense parent (but not StridedArray)
@@ -1660,3 +1667,21 @@ end
16601667
@test (@inferred A[i,i,i]) === A[1]
16611668
@test (@inferred to_indices([], (1, CIdx(1, 1), 1, CIdx(1, 1), 1, CIdx(1, 1), 1))) == ntuple(Returns(1), 10)
16621669
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

test/compiler/inline.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,13 +995,6 @@ end
995995
@invoke conditional_escape!(false::Any, x::Any)
996996
end
997997

998-
@testset "strides for ReshapedArray (PR#44027)" begin
999-
# Type-based contiguous check
1000-
a = vec(reinterpret(reshape,Int16,reshape(view(reinterpret(Int32,randn(10)),2:11),5,:)))
1001-
f(a) = only(strides(a));
1002-
@test fully_eliminated(f, Tuple{typeof(a)}) && f(a) == 1
1003-
end
1004-
1005998
@testset "elimination of `get_binding_type`" begin
1006999
m = Module()
10071000
@eval m begin

0 commit comments

Comments
 (0)