def _nearest_real_complex_idx(fro, to, which):
 assert (which in ('real', 'complex'))
 order = np.argsort(np.abs((fro - to)))
 mask = np.isreal(fro[order])
 if (which == 'complex'):
  mask = (~ mask)
 return order[np.where(mask)[0][0]]

def _nearest_real_complex_idx ( fro , to , which ) : assert ( which in ( 'real' , 'complex' ) ) order = np . argsort ( np . abs ( ( fro - to ) ) ) mask = np . isreal ( fro [ order ] ) if ( which == 'complex' ) : mask = ( ~ mask ) return order [ np . where ( mask ) [ 0 ] [ 0 ] ]
get the next closest real or complex element based on distance .