added fromGenerator constructor for sparse matrices