I've heard that SubArray and other array operations are eventually due for a performance overhaul in the future. For the time being, I've had some fairly minor slowdowns in my code due to SubArray being slow. Here's an example:
A=rand(Float32,20000,20000);
B=sub(A,2:19999,2:19999);
@time scale!(A,0.2f0);
@time scale!(B,0.2f0);
resulting in
elapsed time: 0.245619038 seconds
elapsed time: 11.706939438 seconds
and so scale! is about 40-50 times slower on a similarly-sized SubArray than on an Array.
Is there a simple workaround I can use for scale! on SubArray's for the time being? Or should I just wait for improvements in the next release?
If there are no workarounds, it's not a big problem, I was just curious.
If you're up for it, it would not be particularly hard to radically improve the performance. scale! just needs an implementation that uses cartesian (multidimensional), rather than linear, indexing. For the moment, that does mean you have to use what might be unfamiliar syntax of Base.Cartesian.
The core code for scale! is here. You would want to make it look more similar to this implementation of copy!. The function body would literally change by two characters (adding s* to the RHS of that assignment).
Of course, if you're wanting to stick with Julia 0.3, your best bet is to use your own custom implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With