Check if accumulation is required
@@ -189,6 +189,13 @@ class coo_matrix(sparse_data._data_matrix):
''',
'sum_duplicates_diff'
)(src_row, src_col, size=self.row.size)
+
+ if diff[1:].all():
+ # All elements have different indices.
+ data = src_data
+ row = src_row
+ col = src_col
+ else:
index = cupy.cumsum(diff, dtype='i')
size = int(index[-1]) + 1
data = cupy.zeros(size, dtype=self.data.dtype)
