From fe5f3f769a51430782aa83b07af10e8bf5f336c2 Mon Sep 17 00:00:00 2001
From: Andi Gerken <andi.gerken@gmail.com>
Date: Wed, 23 Feb 2022 14:10:46 +0100
Subject: [PATCH] Optimized very slow validation routine.

---
 src/robofish/io/validation.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/robofish/io/validation.py b/src/robofish/io/validation.py
index 502e0bb..5d1cb7c 100644
--- a/src/robofish/io/validation.py
+++ b/src/robofish/io/validation.py
@@ -304,7 +304,8 @@ def validate_positions_range(world_size, positions, e_name):
     # positions which are just a bit over the world edge are fine
     error_allowance = 1.01
 
-    positions = np.array([p for p in positions if not any(np.isnan(p))])
+    # Remove rows where there is any nan
+    positions = np.array(positions)[~np.isnan(positions).any(axis=1)]
 
     allowed_x = [
         -1 * world_size[0] * error_allowance / 2,
@@ -334,7 +335,9 @@ def validate_positions_range(world_size, positions, e_name):
 
 
 def validate_orientations_length(orientations, e_name):
-    orientations = np.array([o for o in orientations if not any(np.isnan(o))])
+
+    # Remove rows where there is any nan
+    orientations = np.array(orientations)[~np.isnan(orientations).any(axis=1)]
 
     ori_lengths = np.linalg.norm(orientations, axis=1)
 
-- 
GitLab