The following is the simple function for the test.
function vec_prod(n)
output = 0;
vec = collect(1:n)
mat = Array{Float64}(undef, n, n)
mat .= vec .* vec'
matt1 = mat .* mat
matt2 = mat * mat
output = dot(matt1, matt2)
return output
end
@btime vec_prod(50)
14.800 ΞΌs (7 allocations: 59.31 KiB)
1.1343603629882813e17
If I change mat = Array{Int64}(undef, n, n),
59.800 ΞΌs (10 allocations: 90.06 KiB)
113436036298828125
From my investigation, I figured out that the speed bottleneck for the case of {Int64} was matt2 = mat * mat. If I remove this matrix multiplication part, like switching that part with matt2 = matt1,
{Float64}
4.571 ΞΌs (5 allocations: 39.70 KiB)
4.312110892222225e15
{Int64}
3.786 ΞΌs (5 allocations: 39.70 KiB)
4312110892222225
The case of {Int64} is faster.
Iβve tested with pre-defining matt2 and/or using mul! of LinearAlgebra. The results were the same.
Why is the matrix multiplication with integer matrices much slower than with float ones? It looks like this is some kind of bug.