N-dimensional sparse matrix implementation