def wrap_neg_index(index, dim):
 if ((index is not None) and (index < 0)):
  index %= dim
 return index

def wrap_neg_index ( index , dim ) : if ( ( index is not None ) and ( index < 0 ) ) : index %= dim return index
converts a negative index into a positive index .