Looks like A_mul_B! should work for you to avoid memory allocation.

 — John

On Mar 8, 2014, at 3:38 PM, Spencer Russell <[email protected]> wrote:

> I'm learning a little numerical ODE stuff, so I whipped up an implementation 
> of the Euler algorithm.
> 
> It accepts systems of 1st-order equations, and the code was clean and I was 
> happy, and all was right in the world. Then I noticed that for small step 
> sizes it was allocating a very large amount of memory. It seems that the 
> allocation is happening in the matrix math, because when I wrote out the 
> matrix multiplication explicitly I got about a 30x speedup and huge reduction 
> in memory allocation (50MB instead of 2GB).
> 
> This feels like a bit of a nuclear option, and makes what was really nice 
> general code into something much uglier. Is there a better solution?
> 
> https://gist.github.com/ssfrr/4f5ecfaf462bb5b487db
> 
> -s

Reply via email to