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

994 Views Asked by At

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:

  • I have a fairly big set of rotations (around 2'000'000).
  • I would like to speed up the accessing time for my data as much as possible.
  • I am not concerned with memory usage so I am willing to trade space for speed.
  • I don't intend to apply my rotations to anything. This is purely for storage use.
  • I will have to access my rotations both as quaternions (.as_quat()) and as euler angles (.as_euler())
  • I will have to split my data into smaller chunk at some point (And I am aware that if I use a single Rotation object I might have to re-create on per chunk in order to split my data correctly)

What I am looking for:

  • The method that has the fastest access time
  • The method that is closer to good practice and coding convention in python

Thanks in advance.

1

There are 1 best solutions below

1
On BEST ANSWER

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:

  • If you're just looking to use the object for storage then the single object is probably more efficient. (However that would apply very specific cases since you could also compute the resulting rotation and store a single quaternion or rotation object)

  • If you're looking to manipulate your data in any way then the list of object seems more indicated for that. The only real draw back is memory use how ever if you manipulate the data you would also have to unpack the single object at some point, leading to a similar problem, if not worse due to data duplication.

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