Created
September 5, 2017 13:43
-
-
Save pkofod/025a108751efb8b0550be2a215ea6104 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pkg.add("BenchmarkTools") | |
using BenchmarkTools | |
function inplace_sq_mat(m::Array{Float64, 2}, n::Array{Float64, 2}) | |
s = size(m, 1) | |
t = s+1 | |
v = zeros(t) | |
@inbounds for i=1:s | |
for j=1:s | |
v[j] = m[j, i] | |
end | |
for k=1:s | |
v[t] = 0. | |
for l=1:s | |
v[t] += v[l]*n[k, l] | |
end | |
m[k, i] = v[t] | |
end | |
end | |
return m | |
end | |
function inplace_sq_mat_bounds(m::Array{Float64, 2}, n::Array{Float64, 2}) | |
s = size(m, 1) | |
t = s+1 | |
v = zeros(t) | |
for i=1:s | |
for j=1:s | |
v[j] = m[j, i] | |
end | |
for k=1:s | |
v[t] = 0. | |
for l=1:s | |
v[t] += v[l]*n[k, l] | |
end | |
m[k, i] = v[t] | |
end | |
end | |
return m | |
end | |
A = rand(100, 100) | |
B = rand(100, 100) | |
@benchmark inplace_sq_mat($A, $B) | |
@benchmark inplace_sq_mat_bounds($A, $B) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment