Edited gen_sparse to be more flexible with high dimensions