sparse support and bugfix

Fixed basic support for sparse matrices and fixed a bug for non-square
matrices.