Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax allocation tests on nightly #314

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions test/big.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# one at http://mozilla.org/MPL/2.0/.

function allocation_test(
op,
T,
short,
short_to,
n;
op::F1,
::Type{T},
short::F2,
short_to::F3,
n::Integer;
a = T(2),
b = T(3),
c = T(4),
)
) where {T,F1,F2,F3}
@test MA.promote_operation(op, T, T) == T
alloc_test(() -> MA.promote_operation(op, T, T), 0)
if op != div && op != -
Expand Down Expand Up @@ -45,9 +45,15 @@ end
@testset "$T" for T in [BigInt, BigFloat, Rational{BigInt}]
MA.Test.int_test(T)
@testset "Allocation" begin
allocation_test(+, T, MA.add!!, MA.add_to!!, T <: Rational ? 168 : 0)
allocation_test(-, T, MA.sub!!, MA.sub_to!!, T <: Rational ? 168 : 0)
allocation_test(*, T, MA.mul!!, MA.mul_to!!, T <: Rational ? 240 : 0)
a, b = T(2), T(3)
a + b, a - b, a * b # compilation
# Test that the MA methods have fewer allocated than the Base method
n = T <: Rational ? (@allocated a + b) - 1 : 0
allocation_test(+, T, MA.add!!, MA.add_to!!, n)
n = T <: Rational ? (@allocated a - b) - 1 : 0
allocation_test(-, T, MA.sub!!, MA.sub_to!!, n)
n = T <: Rational ? (@allocated a * b) - 1 : 0
allocation_test(*, T, MA.mul!!, MA.mul_to!!, n)
add_sub_mul_test(MA.add_mul, T)
add_sub_mul_test(MA.sub_mul, T)
if T <: Rational # https://github.com/jump-dev/MutableArithmetics.jl/issues/167
Expand All @@ -56,7 +62,7 @@ end
T,
MA.add!!,
MA.add_to!!,
168,
(@allocated a + b) - 1,
a = T(1 // 2),
b = T(3 // 2),
c = T(5 // 2),
Expand All @@ -66,7 +72,7 @@ end
T,
MA.sub!!,
MA.sub_to!!,
168,
(@allocated a - b) - 1,
a = T(1 // 2),
b = T(3 // 2),
c = T(5 // 2),
Expand Down
4 changes: 2 additions & 2 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ end
@test x == 4
@test y == 5
# FIXME This should not allocate but I couldn't figure out where these
# 240 come from.
alloc_test(() -> MA.broadcast!!(+, a, b), 30 * sizeof(Int))
# allocations come from.
alloc_test_le(() -> MA.broadcast!!(+, a, b), 336)
alloc_test(() -> MA.broadcast!!(+, a, c), 0)
end

Expand Down
4 changes: 2 additions & 2 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ include("dummy.jl")
# Half size on 32-bit.
const BIGINT_ALLOC = Sys.WORD_SIZE == 64 ? 48 : 24

function alloc_test(f, n)
function alloc_test(f::F, n) where {F}
f() # compile
@test n == @allocated f()
end

function alloc_test_le(f, n)
function alloc_test_le(f::F, n) where {F}
f() # compile
@test n >= @allocated f()
end
Loading