@@ -563,8 +563,8 @@ def __get_neighbors_indices_strictlyadjacent(
563
563
)
564
564
# calculate the absolute difference between the parameter value indices
565
565
abs_index_difference = np .abs (self .params_values_indices - param_config_value_indices )
566
- # get the param config indices where the difference is one or less for each position
567
- matching_indices = ( np .max (abs_index_difference , axis = 1 ) <= 1 ). nonzero ( )[0 ]
566
+ # get the param config indices where the difference is one for at most one position and zero for the other positions
567
+ matching_indices = np .where (abs_index_difference . sum ( axis = 1 ) <= 1 )[0 ]
568
568
# as the selected param config does not differ anywhere, remove it from the matches
569
569
if param_config_index is not None :
570
570
matching_indices = np .setdiff1d (matching_indices , [param_config_index ], assume_unique = False )
@@ -581,26 +581,29 @@ def __get_neighbors_indices_adjacent(self, param_config_index: int = None, param
581
581
index_difference = self .params_values_indices - param_config_value_indices
582
582
# transpose to get the param indices difference per parameter instead of per param config
583
583
index_difference_transposed = index_difference .transpose ()
584
+ # find 'hamming' neighbors for which at most one position is different
585
+ hamming_mask = (index_difference != 0 ).sum (axis = 1 ) <= 1
584
586
# for each parameter get the closest upper and lower parameter (absolute index difference >= 1)
585
587
# np.PINF has been replaced by 1e12 here, as on some systems np.PINF becomes np.NINF
586
588
upper_bound = tuple (
587
589
np .min (
588
- index_difference_transposed [p ][( index_difference_transposed [ p ] > 0 ). nonzero ()] ,
590
+ index_difference_transposed [p ],
589
591
initial = 1e12 ,
592
+ where = hamming_mask ,
590
593
)
591
594
for p in range (self .num_params )
592
595
)
593
596
lower_bound = tuple (
594
597
np .max (
595
- index_difference_transposed [p ][( index_difference_transposed [ p ] < 0 ). nonzero ()] ,
598
+ index_difference_transposed [p ],
596
599
initial = - 1e12 ,
600
+ where = hamming_mask ,
597
601
)
598
602
for p in range (self .num_params )
599
603
)
600
604
# return the indices where each parameter is within bounds
601
- matching_indices = (
602
- np .logical_and (index_difference <= upper_bound , index_difference >= lower_bound ).all (axis = 1 ).nonzero ()[0 ]
603
- )
605
+ within_bounds = np .logical_and (index_difference <= upper_bound , index_difference >= lower_bound ).all (axis = 1 )
606
+ matching_indices = (hamming_mask & within_bounds ).nonzero ()[0 ]
604
607
# as the selected param config does not differ anywhere, remove it from the matches
605
608
if param_config_index is not None :
606
609
matching_indices = np .setdiff1d (matching_indices , [param_config_index ], assume_unique = False )
0 commit comments