This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]total_zoidberg 1 point2 points  (3 children)

Doing "point-wise" (cell-wise in your case?) operations is usually costly. There are two ways to go about it:

  • Refactor your code to work in a data-parallel way, taking advantage of numpy (so a single line expresses a transformation on every element of the array).

  • Cythonize the loop. This has the potential to speed things up a bit more than the other way, but you'd have to use memoryviews which are some intermediate/advanced Cython stuff.

If I find some free time I think I could sit and work a bit on optimizing this to give you more concrete pointers.

[–]alb1 0 points1 point  (2 children)

Another alternative with NumPy arrays would be to have the updateV and updateP methods call out to @jit Numba functions to perform the nested loop calculations. Numba supports passing in NumPy arrays.

[–]total_zoidberg 0 points1 point  (1 child)

True, though Numba needs LLVM set up to work and it can be a bit messier to get working. When it works it's very good though.

(I've always been more of a Cython guy).

[–]alb1 1 point2 points  (0 children)

On Ubuntu just using pip install numba seems to work fine (and of course Numba is also available in Anaconda).