Fix segfault with sparse matrix constructor