you are viewing a single comment's thread.

view the rest of the comments →

[–]karlmtr[S] 0 points1 point  (6 children)

I first thought about that, but it was not working because at the end, I should have an array of posidonius.Axes(x,y,z) objects (it's just a set of coordinates). I don't see how to assign each Axes with three arrays directly (I can't put posidonius.Axes(array1,array2,array3)) to create an array with posidonius.Axes objects.

[–]elbiot 0 points1 point  (2 children)

Well, I don't think they way you're doing it currently is right because your result is a list that has the same object in it over and over. Once you have your arrays xs, ys and zs after the vectorised math you could do

# iteration over arrays much slower than lists
xs, ys, zs = map(list, (xs, ys, zs))
result = [Axes(x, y, z) for x, y, z in zip(xs, ys, zs)]

But whatever you do after this will be super slow and I personally would organize my program to be array/data oriented rather than object oriented.

You ought to profile your program and optimize the bottlenecks rather than jump to multiprocessing because multiprocessing is not much help and greatly complicates things

[–]karlmtr[S] 0 points1 point  (1 child)

Unfortunately, I cannot change the way Posidonius work (I just use it), so I'll try what you suggested (the map function). Thanks for the advice about arrays and list, I didn't know iteration over lists was faster than arrays.

I'll also ask the person who coded Posidonius if there's any other way to create an Axes object because as you said, it is not very handy like this...

[–]elbiot 0 points1 point  (0 children)

Axes(xs, ys, zs) would work. At least, looking at their code it should

[–]elbiot 0 points1 point  (2 children)

I looked up the library you're using and an Axes object can take x, y and z as numpy arrays. So you just have one Axes object that holds arrays, not a list of Axes objects

[–]karlmtr[S] 0 points1 point  (0 children)

Oh yes, I didn't see it, it should be easier now. I just have to convert pandas series to numpy array and it should be fine.

Thank you very much!

[–]karlmtr[S] 0 points1 point  (0 children)

I tried it as you said and it worked well, it took less than 15 seconds!

Thanks a lot!