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 @@ -378,6 +378,19 @@ assert(tensor->getElements().size() == values.size()); return tensor; } + /// Variant for when the permutation is known to be the identity/iota. + SparseTensorCOO *toCOO() { + uint64_t rank = getRank(); + // The new coordinate scheme's sizes array. + std::vector permsz(rank); + for (uint64_t r = 0; r < rank; r++) + permsz[rev[r]] = sizes[r]; + SparseTensorCOO *tensor = new SparseTensorCOO(permsz, values.size()); + // Populate the coordinate scheme. + toCOO(*tensor, rev, 0, 0); + assert(tensor->getElements().size() == values.size()); + return tensor; + } /// Factory method. Constructs a sparse tensor storage scheme with the given /// dimensions, permutation, and per-dimension dense/sparse annotations, @@ -1108,9 +1121,7 @@ SparseTensorStorage *sparseTensor = static_cast *>(tensor); uint64_t rank = sparseTensor->getRank(); - std::vector perm(rank); - std::iota(perm.begin(), perm.end(), 0); - SparseTensorCOO *coo = sparseTensor->toCOO(perm.data()); + SparseTensorCOO *coo = sparseTensor->toCOO(); const std::vector> &elements = coo->getElements(); uint64_t nse = elements.size();