Skip to content

Commit

Permalink
Skip redundant test
Browse files Browse the repository at this point in the history
only test each dest style once.
  • Loading branch information
N5N3 committed Nov 7, 2022
1 parent 10e6442 commit 960e1c7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
[compat]
Adapt = "1, 2, 3"
DataAPI = "1"
StaticArraysCore = "1.3"
StaticArrays = "1.5.6"
GPUArraysCore = "0.1.2"
StaticArrays = "1.5.6"
StaticArraysCore = "1.3"
Tables = "1"
julia = "1.6"

Expand All @@ -23,10 +23,11 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"

[targets]
test = ["Test", "JLArrays", "StaticArrays", "OffsetArrays", "PooledArrays", "TypedTables", "WeakRefStrings", "Documenter"]
test = ["Test", "JLArrays", "StaticArrays", "OffsetArrays", "PooledArrays", "TypedTables", "WeakRefStrings", "Documenter", "Random"]
80 changes: 47 additions & 33 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using TypedTables: Table
using DataAPI: refarray, refvalue
using Adapt: adapt, Adapt
using JLArrays
using Random
using Test

using Documenter: doctest
Expand Down Expand Up @@ -1151,29 +1152,39 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
# used inside of broadcast but we also test it here explicitly
@test isa(@inferred(Base.dataids(s)), NTuple{N, UInt} where {N})

# Make sure we can handle style with similar defined
# And we can handle most conflicts
# `s1` and `s2` have similar defined, but `s3` does not
# `s2` conflicts with `s1` and `s3` and is weaker than `DefaultArrayStyle`
s1 = StructArray{ComplexF64}((MyArray1(rand(2)), MyArray1(rand(2))))
s2 = StructArray{ComplexF64}((MyArray2(rand(2)), MyArray2(rand(2))))
s3 = StructArray{ComplexF64}((MyArray3(rand(2)), MyArray3(rand(2))))
s4 = StructArray{ComplexF64}((rand(2), rand(2)))

function _test_similar(a, b, c)
try
d = StructArray{ComplexF64}((a.re .+ b.re .- c.re, a.im .+ b.im .- c.im))
@test typeof(a .+ b .- c) == typeof(d)
catch
@test_throws MethodError a .+ b .- c

@testset "style conflict check" begin
using StructArrays: StructArrayStyle
# Make sure we can handle style with similar defined
# And we can handle most conflicts
# `s1` and `s2` have similar defined, but `s3` does not
# `s2` conflicts with `s1` and `s3` and is weaker than `DefaultArrayStyle`
s1 = StructArray{ComplexF64}((MyArray1(rand(2)), MyArray1(rand(2))))
s2 = StructArray{ComplexF64}((MyArray2(rand(2)), MyArray2(rand(2))))
s3 = StructArray{ComplexF64}((MyArray3(rand(2)), MyArray3(rand(2))))
s4 = StructArray{ComplexF64}((rand(2), rand(2)))
test_set = Any[s1, s2, s3, s4]
tested_style = Any[]
dotaddadd((a, b, c),) = @. a + b + c
for is in Iterators.product(randperm(4), randperm(4), randperm(4))
as = map(i -> test_set[i], is)
ares = map(a->a.re, as)
aims = map(a->a.im, as)
style = Broadcast.combine_styles(ares...)
if !(style in tested_style)
push!(tested_style, style)
if style isa Broadcast.ArrayStyle{MyArray3}
@test_throws MethodError dotaddadd(as)
else
d = StructArray{ComplexF64}((dotaddadd(ares), dotaddadd(aims)))
@test @inferred(dotaddadd(as))::typeof(d) == d
end
end
end
@test length(tested_style) == 5
end
for s in (s1,s2,s3,s4), s′ in (s1,s2,s3,s4), s″ in (s1,s2,s3,s4)
_test_similar(s, s′, s″)
end

# test for dimensionality track
s = s1
s = StructArray{ComplexF64}((MyArray1(rand(2)), MyArray1(rand(2))))
@test Base.broadcasted(+, s, s) isa Broadcast.Broadcasted{<:Broadcast.AbstractArrayStyle{1}}
@test Base.broadcasted(+, s, 1:2) isa Broadcast.Broadcasted{<:Broadcast.AbstractArrayStyle{1}}
@test Base.broadcasted(+, s, reshape(1:2,1,2)) isa Broadcast.Broadcasted{<:Broadcast.AbstractArrayStyle{2}}
Expand All @@ -1197,22 +1208,25 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
@test (x -> x.x.x.a).(StructArray(x=StructArray(x=StructArray(a=1:3)))) == [1, 2, 3]

@testset "ambiguity check" begin
function _test(a, b, c)
if a isa StructArray || b isa StructArray || c isa StructArray
d = @inferred a .+ b .- c
@test d == collect(a) .+ collect(b) .- collect(c)
@test d isa StructArray
end
end
testset = Any[StructArray([1;2+im]),
test_set = Any[StructArray([1;2+im]),
1:2,
(1,2),
StructArray(@SArray [1 1+2im]),
(@SArray [1 2])
]
for aa in testset, bb in testset, cc in testset
_test(aa, bb, cc)
StructArray(@SArray [1;1+2im]),
(@SArray [1 2]),
1]
tested_style = StructArrayStyle[]
dotaddsub((a, b, c),) = @. a + b - c
for is in Iterators.product(randperm(6), randperm(6), randperm(6))
as = map(i -> test_set[i], is)
if any(a -> a isa StructArray, as)
style = Broadcast.combine_styles(as...)
if !(style in tested_style)
push!(tested_style, style)
@test @inferred(dotaddsub(as))::StructArray == dotaddsub(map(collect, as))
end
end
end
@test length(tested_style) == 4
end

@testset "StructStaticArray" begin
Expand Down

0 comments on commit 960e1c7

Please sign in to comment.