Skip to content

Instantly share code, notes, and snippets.

View Malarkey73's full-sized avatar

Stephen Henderson Malarkey73

View GitHub Profile
# vectorised function from Julia blog
function vectorised(x,y)
r = exp(-abs(x-y))
return r
end
# recommended devectorised function
function devectorised(x,y)
r = similar(x)
for i = 1:length(x)
@Malarkey73
Malarkey73 / R Vectorisation
Created December 23, 2013 13:37
R Vectorisation
# vectorised function
vectorised <- function(x, y)
{
r = exp(-abs(x-y))
return(r)
}
#devectorised function
devectorised <- function(x,y)
{
@Malarkey73
Malarkey73 / R and Julia Vectorisation
Last active January 1, 2016 05:09
A slightly different comparison of R and Julia vectorisation closer to what most R people mean when they say "vectorised". The code example is plucked from the Julia blog discussion on code optimisation. Surprisingly for this use case Julia devectorised (~=0.18 secs) is just a little better than Julia vectorised (~= 0.25 secs), which is a little…
This is sort of a reply to this post:
http://www.johnmyleswhite.com/notebook/2013/12/22/the-relationship-between-vectorized-and-devectorized-code/
which arises from a a discussion of this
http://julialang.org/blog/2013/09/fast-numeric/
So....