copy data to allow in-place edits
@@ -564,6 +564,12 @@ def cscsort(x):
def coosort(x):
+ """Sorts indices of COO-matrix in place
+
+ Args:
+ x (cupyx.scipy.sparse.coo_matrix): A sparse matrix to sort.
+
+ """
nnz = x.nnz
if nnz == 0:
return
@@ -574,16 +580,16 @@ def coosort(x):
handle, m, n, nnz, x.row.data.ptr, x.col.data.ptr)
buf = cupy.empty(buffer_size, 'b')
P = cupy.empty(nnz, 'i')
- data_sorted = cupy.empty_like(x.data)
+ # copy data to do safe in-place edits by gthr
+ data_orig = x.data.copy()
cusparse.createIdentityPermutation(handle, nnz, P.data.ptr)
cusparse.xcoosortByRow(
handle, m, n, nnz, x.row.data.ptr, x.col.data.ptr,
P.data.ptr, buf.data.ptr)
_call_cusparse(
'gthr', x.dtype,
- handle, nnz, x.data.data.ptr, data_sorted.data.ptr,
+ handle, nnz, data_orig.data.ptr, x.data.data.ptr,
P.data.ptr, cusparse.CUSPARSE_INDEX_BASE_ZERO)
- x.data = data_sorted
def coo2csr(x):
