pythonperformancescipyscipy-spatial

scipy.spatial.transform.Rotation Array of rotation vs Stack inside the same object


In a project I have to store a sequence of successive rotations of an object in python. I intend to store them using scipy.spatial.transform.Rotation objects.

I have noticed that two options are available.

  1. I store a multitude of Rotation object in an array, each Rotation object containing a single rotation of my sequence.

  2. I store every rotation in the same Rotation object, effectively stacking them in a single object.

I wondered what were the trade offs between the methods in terms of computational speed and data access speed. And ultimately which method should be preferred.

In my particular case:

What I am looking for:

Thanks in advance.


Solution

  • Alright so I'll throw in the first elements I have.

    For both you end up accessing an iterable and an object (just in a different order). Therefor there should not be any major difference in accessing speed.

    The list of R is easier to access and manipulate afterwards. Hence if you are suceptible of changing anything in your rotation sequence it is the easier way. There for using a single object requires some extra-code for manipulation and might be slower. However it really depends on what you do and I have no data to prove that it is significantly slower.

    The single object should take less memory space since there is only one instance, where as the list of object has nb_rotation times more. I already mentionned that this was not critical in my case it is not critical. Again I don't have any data to support this but I expect the difference to be significative since I have about 2'000'000 rotations.

    Regarding those facts I would make the decision as follow:

    In my case I will be using the list of object.