Added a cdef definition for the second looping variable to make everything faster.