From dfc00c23c28b0125ff9c2907f6e348e05edbe47e Mon Sep 17 00:00:00 2001 From: Rafael M Mudafort Date: Sat, 18 Mar 2023 16:33:27 -0500 Subject: [PATCH] Remove redundant array slice operations --- floris/simulation/flow_field.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/floris/simulation/flow_field.py b/floris/simulation/flow_field.py index aae7e028d..2e6011a12 100644 --- a/floris/simulation/flow_field.py +++ b/floris/simulation/flow_field.py @@ -183,10 +183,7 @@ def calculate_speed_ups(self, het_map, x, y, z=None): # Calculate the 3-dimensional speed ups; reshape is needed as the generator # adds an extra dimension speed_ups = np.reshape( - [ - het_map[0][i](x[i:i+1,:,:,:,:], y[i:i+1,:,:,:,:], z[i:i+1,:,:,:,:]) - for i in range(len(het_map[0])) - ], + [het_map[0][i](x[i:i+1], y[i:i+1], z[i:i+1]) for i in range( len(het_map[0]))], np.shape(x) ) @@ -195,10 +192,7 @@ def calculate_speed_ups(self, het_map, x, y, z=None): if np.isnan(speed_ups).any(): idx_nan = np.where(np.isnan(speed_ups)) speed_ups_out_of_region = np.reshape( - [ - het_map[1][i](x[i:i+1,:,:,:,:], y[i:i+1,:,:,:,:], z[i:i+1,:,:,:,:]) - for i in range(len(het_map[1])) - ], + [het_map[1][i](x[i:i+1], y[i:i+1], z[i:i+1]) for i in range(len(het_map[1]))], np.shape(x) ) @@ -208,10 +202,7 @@ def calculate_speed_ups(self, het_map, x, y, z=None): # Calculate the 2-dimensional speed ups; reshape is needed as the generator # adds an extra dimension speed_ups = np.reshape( - [ - het_map[0][i](x[i:i+1,:,:,:,:], y[i:i+1,:,:,:,:]) - for i in range(len(het_map[0])) - ], + [het_map[0][i](x[i:i+1], y[i:i+1]) for i in range(len(het_map[0]))], np.shape(x) ) @@ -220,10 +211,7 @@ def calculate_speed_ups(self, het_map, x, y, z=None): if np.isnan(speed_ups).any(): idx_nan = np.where(np.isnan(speed_ups)) speed_ups_out_of_region = np.reshape( - [ - het_map[1][i](x[i:i+1,:,:,:,:], y[i:i+1,:,:,:,:]) - for i in range(len(het_map[1])) - ], + [het_map[1][i](x[i:i+1], y[i:i+1]) for i in range(len(het_map[1]))], np.shape(x) )