Fix a bug transpose_dense()

The function was implemented incorrectly if the number of rows and columns is
different. A test for this was added that fails.

The assert statement was fixed as well as the loop, now the added test passes.

Fixes #304.