Closed pkofod closed 9 years ago
Before I get to your issue, please wrap julia macro mentions in backticks in order to not ping GitHub users, i.e. @devec
, instead of directly writing it.
As far as your issue goes, it looks like you have tried to pre-allocate the result vector phat
, but the way you have used it re-binds the output of your computation to a new vector, as opposed to updating the values in phat
.
Re-writing things inside functions to avoid referencing variables at global scope gives something like:
function test1()
vector = rand(8000)
phat = zeros(8000)
@time for i = 1:1000
phat[:] = 1./(1+exp(-vector))
end
end
function test2()
vector = rand(8000)
phat = zeros(8000)
@time for i = 1:1000
@devec phat[:] = 1./(1+exp(-vector))
end
end
Note the assignment to phat[:]
which updates the contents of phat
rather than re-binding it. Written like this, you should see that test2
is faster than test1
.
Oh, I thought phat =
updated it if it existed already! I have a lot of my code to edit then. I know it is not your job to be my help()
, but is this mentioned in the documentation? Searching for [:] is kinda difficult.
Thanks!
I was sure that this must be mentioned in the docs, but after searching for a few minutes, I cannot find a direct reference.
I would note that the README in this repo does mention this issue in the section on "Simple References".
I am calculating
where
vector
is a vector of some dimension (say 8000). Ex:Gives me that devec is an order of magnitude slower, and allocates five times as much memory. On v0.4.
Am I using @devec incorrectly? That is, for the wrong purpose, doing it in a stupid way etc.
Edit: A straight loop gives the same time as vanilla Julia, but obviously way less memory allocation. I would have expected @devec to do exactly this.