So I've been working on this really bad python code I wrote a while ago and as an easy way to optimize it, I tried to use PyPy instead of python 2.7 but while trying to run it, PyPy gives me a list index out of range error whereas python runs the code just fine.
The offending bit of code is attached below -
for front_no in xrange(1, self.no_of_fronts + 1):
temp = []
for member in self.population_members:
if member.front == front_no:
temp.append(member)
if(len(temp) == 1):
temp[0].crowding_distance = float('inf')
else:
for member in temp:
member.crowding_distance = 0
for y in xrange(0, p.number_of_objectives):
temp.sort(key=lambda x: x.objective_function_values[y])
temp[0].crowding_distance = float("inf")
temp[len(temp) - 1].crowding_distance = float("inf")
if temp[0].gene == temp[-1].gene:
for i in xrange(1, len(temp) - 1):
temp[i].crowding_distance = 0
temp[0].crowding_distance = float("inf")
is what's causing the problem specifically, but there's no reason for temp to be empty at that point.