Skip to content

Instantly share code, notes, and snippets.

@pkofod
Created September 5, 2017 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkofod/025a108751efb8b0550be2a215ea6104 to your computer and use it in GitHub Desktop.
Save pkofod/025a108751efb8b0550be2a215ea6104 to your computer and use it in GitHub Desktop.
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