diff --git a/src/mtables.jl b/src/mtables.jl index 4d76d69..20a6114 100644 --- a/src/mtables.jl +++ b/src/mtables.jl @@ -91,8 +91,13 @@ function MA.operate!( v::AbstractVector, w::AbstractVector, ) + l1 = issparse(v) ? nnz(v) : 2^8 + l2 = issparse(w) ? nnz(w) : 2^8 + l = l1 * l2 idcs = Vector{key_type(res)}() vals = Vector{eltype(res)}() + sizehint!(idcs, l) + sizehint!(vals, l) for (kv, a) in nonzero_pairs(v) for (kw, b) in nonzero_pairs(w) diff --git a/test/arithmetic.jl b/test/arithmetic.jl index f22fd7c..f804820 100644 --- a/test/arithmetic.jl +++ b/test/arithmetic.jl @@ -303,31 +303,35 @@ end @static if VERSION ≥ v"1.9" @test (@allocations Y * Y) > k^2 - 2 * k @test Y * Y isa AlgebraElement - @test (@allocations Y * Y) < 50 + @test (@allocations Y * Y) ≤ 26 else k1 = @allocated Y * Y @test Y * Y isa AlgebraElement Y * Y k2 = @allocated Y * Y - @test k2 / k1 < 0.2 + @test k2 / k1 < 0.5 end @test all(!iszero, SA.mstructure(fRG).table) @static if VERSION ≥ v"1.9" YY = deepcopy(Y) + # MA.operate_to!(YY, +, Y, YY) + # YY = deepcopy(Y) @test_broken @allocations(MA.operate_to!(YY, +, Y, YY)) == 0 @test_broken YY == Y + Y - YY = deepcopy(Y) + # MA.operate_to!(YY, +, YY, Y) + # YY = deepcopy(Y) @test_broken @allocations(MA.operate_to!(YY, +, YY, Y)) == 0 @test_broken YY == Y + Y - @test_broken @allocations(MA.operate_to!(YY, +, Y, deepcopy(Y))) == - 0 + # MA.operate_to!(YY, +, Y, Y) + @test_broken @allocations(MA.operate_to!(YY, +, Y, Y)) == 0 @test_broken YY == Y + Y - @test @allocations(MA.operate_to!(YY, *, Y, Y)) ≤ 40 + MA.operate_to!(YY, *, Y, Y) + @test @allocations(MA.operate_to!(YY, *, Y, Y)) ≤ 25 @test YY == Y * Y end end