From 18cb198bef44b118bc736b1db122bd87621fdd22 Mon Sep 17 00:00:00 2001
From: "Olivier J.N. Bertrand" <olivier.bertrand@uni-bielefeld.de>
Date: Thu, 17 Jan 2019 17:21:59 +0100
Subject: [PATCH] Speed up velocity calculation The calculation skip null diff
 euler angles and thus skip many iteration in the loop

---
 navipy/trajectories/__init__.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/navipy/trajectories/__init__.py b/navipy/trajectories/__init__.py
index 8051f65..8f5f3c7 100644
--- a/navipy/trajectories/__init__.py
+++ b/navipy/trajectories/__init__.py
@@ -641,7 +641,13 @@ class Trajectory(pd.DataFrame):
                                 dtype=float)
         diffrow = self.diff()
         velocity.loc[:, ['dx', 'dy', 'dz']] = diffrow.loc[:, 'location'].values
-        for index_i, row in self.iterrows():
+        # Look for true zeros in order to save time
+        true_zeros = diffrow == 0
+        diffrow[true_zeros] = np.nan
+        velocity[true_zeros[self.rotation_mode]] = 0
+        # Loop only on non true zeros
+        for index_i in diffrow.loc[:, self.rotation_mode].dropna().index:
+            row = self.loc[index_i, :]
             if self.rotation_mode == 'quaternion':
                 raise NameError('Not implemented')
             else:
-- 
GitLab