diff --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp --- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp +++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp @@ -269,6 +269,8 @@ pointers[r].push_back(0); // Then assign contents from coordinate scheme tensor if provided. if (tensor) { + // We sort the tensor here, to ensure the preconditions for `fromCOO`. + tensor->sort(); const std::vector> &elements = tensor->getElements(); uint64_t nnz = elements.size(); values.reserve(nnz); @@ -386,7 +388,6 @@ assert(tensor->getRank() == rank); for (uint64_t r = 0; r < rank; r++) assert(sizes[r] == 0 || tensor->getSizes()[perm[r]] == sizes[r]); - tensor->sort(); // sort lexicographically n = new SparseTensorStorage(tensor->getSizes(), perm, sparsity, tensor); delete tensor;