Select Git revision
find_duplicates_test.py
matrix_transpose.py 641 B
class Matrix:
"""Interface of a matrix.
This class provides only the matrix size N and a method for swapping
two items. The actual storage of the matrix in memory is provided by
subclasses in testing code.
"""
def __init__(self, N):
self.N = N
def swap(self, i1, j1, i2, j2):
"""Swap elements (i1,j1) and (i2,j2)."""
# Overridden in subclasses
raise NotImplementedError
def transpose(self):
"""Transpose the matrix."""
# TODO: Implement more efficiently
for i in range(self.N):
for j in range(i):
self.swap(i, j, j, i)