This file contains 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
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.... |
This file contains 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
# vectorised function | |
vectorised <- function(x, y) | |
{ | |
r = exp(-abs(x-y)) | |
return(r) | |
} | |
#devectorised function | |
devectorised <- function(x,y) | |
{ |
This file contains 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
# 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) |