Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active September 25, 2018 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/d1103c4c37643272daf8deb940e2b5b2 to your computer and use it in GitHub Desktop.
Save chelseatroy/d1103c4c37643272daf8deb940e2b5b2 to your computer and use it in GitHub Desktop.
toarray implementation in _cs_matrix
class _cs_matrix(_data_matrix, _minmax_mixin, IndexMixin):
...
def toarray(self, order=None, out=None):
if out is None and order is None:
order = self._swap('cf')[0]
out = self._process_toarray_args(order, out)
if not (out.flags.c_contiguous or out.flags.f_contiguous):
raise ValueError('Output array must be C or F contiguous')
# align ideal order with output array order
if out.flags.c_contiguous:
x = self.tocsr()
y = out
else:
x = self.tocsc()
y = out.T
M, N = x._swap(x.shape)
_sparsetools.csr_todense(M, N, x.indptr, x.indices, x.data, y)
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment