Added support for sparse matrix