3 ms·
Coming from R, I have to ask... Why am I seeing 'for' and 'while' loops? Why isn't this code vectorized? It looks like both implementations suck.
by crasta 13y ago
Coming from R, I have to ask... Why am I seeing 'for' and 'while' loops? Why isn't this code vectorized? It looks like both implementations suck.
- 3JPLW 13y agoYeah, it's a big change in mindset for Julia. Basically, the reason MATLAB/Numpy/R folks harp so much about vectorizing code is because their interpreters are slow, and within a vectorized function they can punt to some C/C++/Cython implementation. But Julia loops compile down to almost ideal assembly; they are remarkably fast. In fact, verbose loops acting in-place almost always beat the vectorized alternatives because they don't need to allocate space for the result. The wonderful thing about Julia is that you can code it vectorized first, and if that's not fast enough (or if it uses too much memory), you can easily rewrite it in the same language.
- CatMtKing 13y agoAye, first thing I learned about R was that their for loops suck. On the bright side, it taught me how to use apply.
- shabadoop 13y agoThat, and the fact that Julia has pretty good CUDA modules, makes it seem like Julia is perfectly suited for work with Neural Networks.
- crasta 13y agoYou can't parallelize a for-loop the way you can apply a function on every member of a vector. If code can be vectorized in Julia, that is what I'm interested in seeing. These samples are obviously not intended for distributed compute. Thousands of CUDA cores sit idle waiting for this synchronous for-loop to finish.
- maxerickson 13y agoCython has a construct for parallelizing for loops. http://docs.cython.org/src/userguide/parallelism.html http://docs.cython.org/src/userguide/parallelism.html I wouldn't want to claim an informed opinion about whether it is a good style or not, but a block with no side effects isn't that far off from a function with no side effects.
- crasta 13y ago@maxerickson I can't reply to you so I'll reply next to you. That looks very interesting. I will have to look into it. Thanks