Exemplo n.º 1
0
 def setUp(self):
     self.m = Matrix(5)
     # Pull the matrix out of the docstring for the class. I'm lazy.
     rows = [x.strip() for x in self.__doc__.split('\n')]
     rows = [x for x in rows if x[0] == '|']
     rows = [[float(x) for x in y.strip('|').split()] for y in rows]
     for i in xrange(len(rows)):
         self.m.set_row(i, rows[i])
Exemplo n.º 2
0
 def __init__(self, a_link_matrix, unreachable_distance=None):
     self._matrix = Matrix(len(a_link_matrix))
     if unreachable_distance is None:
         unreachable_distance = len(a_link_matrix)
     self._unreachable = unreachable_distance
     logging.log(ULTRADEBUG, "Getting C versions of the matrices.")
     transposed = a_link_matrix.transpose()
     transposed_c = transposed.as_binary_c_matrix()
     c_link_matrix = a_link_matrix.as_binary_c_matrix()
     to_fill_in = self._matrix.as_binary_c_matrix()
     logging.log(ULTRADEBUG, "Going into C to perform the search.")
     DISTLIB.fill_distance_matrix(byref(to_fill_in), byref(c_link_matrix),
                                  byref(transposed_c), len(a_link_matrix),
                                  self._unreachable)
     logging.log(ULTRADEBUG, "Back from C. Filling the matrix in.")
     self._matrix.fill_from_c_matrix(to_fill_in)
     self._converted_distance = None