Skip to content
11 changes: 6 additions & 5 deletions test/big.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ 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)
MAX_ALLOC = T <: Rational ? 280 : 0
allocation_test(+, T, MA.add!!, MA.add_to!!, MAX_ALLOC)
allocation_test(-, T, MA.sub!!, MA.sub_to!!, MAX_ALLOC)
allocation_test(*, T, MA.mul!!, MA.mul_to!!, MAX_ALLOC)
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 +57,7 @@ end
T,
MA.add!!,
MA.add_to!!,
168,
MAX_ALLOC,
a = T(1 // 2),
b = T(3 // 2),
c = T(5 // 2),
Expand All @@ -66,7 +67,7 @@ end
T,
MA.sub!!,
MA.sub_to!!,
168,
MAX_ALLOC,
a = T(1 // 2),
b = T(3 // 2),
c = T(5 // 2),
Expand Down
5 changes: 3 additions & 2 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ 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.
n = (VERSION >= v"1.11" ? 42 : 30) * sizeof(Int)
alloc_test(() -> MA.broadcast!!(+, a, b), n)
alloc_test(() -> MA.broadcast!!(+, a, c), 0)
end

Expand Down
1 change: 1 addition & 0 deletions test/dummy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Base.copy(x::DummyBigInt) = x
MA.mutable_copy(x::DummyBigInt) = DummyBigInt(MA.mutable_copy(x.data))
LinearAlgebra.symmetric_type(::Type{DummyBigInt}) = DummyBigInt
LinearAlgebra.symmetric(x::DummyBigInt, ::Symbol) = x
LinearAlgebra.issymmetric(::DummyBigInt) = true
LinearAlgebra.hermitian_type(::Type{DummyBigInt}) = DummyBigInt
LinearAlgebra.hermitian(x::DummyBigInt, ::Symbol) = x
LinearAlgebra.dot(x::DummyBigInt, y::DummyBigInt) = x * y
Expand Down
12 changes: 4 additions & 8 deletions test/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,13 @@ end
alloc_test(() -> MA.mutability(y, MA.add_mul, y, A, x), 0)
end

# 40 bytes to create the buffer
# 8 bytes in the double for loop. FIXME: figure out why
# Half size on 32-bit.
n = Sys.WORD_SIZE == 64 ? 48 : 24
alloc_test(() -> MA.add_mul!!(y, A, x), n)
alloc_test(() -> MA.add_mul!!(y, A, x), BIGINT_ALLOC)
alloc_test(
() -> MA.operate_fallback!!(MA.IsMutable(), MA.add_mul, y, A, x),
n,
BIGINT_ALLOC,
)
alloc_test(() -> MA.operate!!(MA.add_mul, y, A, x), n)
alloc_test(() -> MA.operate!(MA.add_mul, y, A, x), n)
alloc_test(() -> MA.operate!!(MA.add_mul, y, A, x), BIGINT_ALLOC)
alloc_test(() -> MA.operate!(MA.add_mul, y, A, x), BIGINT_ALLOC)
# Apparently, all allocations were on creating the buffer since this is allocation free:
buffer = MA.buffer_for(MA.add_mul, typeof(y), typeof(A), typeof(x))
alloc_test(() -> MA.buffered_operate!(buffer, MA.add_mul, y, A, x), 0)
Expand Down
11 changes: 8 additions & 3 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

include("dummy.jl")

# Allocating size for allocating a `BigInt`.
# Half size on 32-bit.
const BIGINT_ALLOC = Sys.WORD_SIZE == 64 ? 48 : 24
# Allocating size for allocating a `BigInt`. Half size on 32-bit.
const BIGINT_ALLOC = @static if VERSION >= v"1.12"
Sys.WORD_SIZE == 64 ? 72 : 36
elseif VERSION >= v"1.11"
Sys.WORD_SIZE == 64 ? 56 : 28
else
Sys.WORD_SIZE == 64 ? 48 : 24
end

function alloc_test(f, n)
f() # compile
Expand Down
Loading