From: wren romano <2998727+wrengr@users.noreply.github.com> Date: Tue, 22 Mar 2022 00:39:15 +0000 (-0700) Subject: [mlir][sparse] Moving lexOrder from SparseTensorCOO to Element X-Git-Tag: upstream/15.0.7~12710 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=110295ebb76150887a5a83733d7ddcf8506da9ad;p=platform%2Fupstream%2Fllvm.git [mlir][sparse] Moving lexOrder from SparseTensorCOO to Element This is the more logical place for the function to live. If/when we factor out a separate class for just the `Coordinates` themselves, then the definition should be moved to `Coordinates::lexOrder` (and `Element::lexOrder` would become a thin wrapper delegating to that function). This is (tangentially) work towards fixing: https://github.com/llvm/llvm-project/issues/51652 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D122057 --- diff --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp index b307104..ab145fb 100644 --- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp +++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp @@ -82,6 +82,17 @@ struct Element { Element(const std::vector &ind, V val) : indices(ind), value(val){}; std::vector indices; V value; + /// Returns true if indices of e1 < indices of e2. + static bool lexOrder(const Element &e1, const Element &e2) { + uint64_t rank = e1.indices.size(); + assert(rank == e2.indices.size()); + for (uint64_t r = 0; r < rank; r++) { + if (e1.indices[r] == e2.indices[r]) + continue; + return e1.indices[r] < e2.indices[r]; + } + return false; + } }; /// A memory-resident sparse tensor in coordinate scheme (collection of @@ -111,7 +122,7 @@ public: assert(!iteratorLocked && "Attempt to sort() after startIterator()"); // TODO: we may want to cache an `isSorted` bit, to avoid // unnecessary/redundant sorting. - std::sort(elements.begin(), elements.end(), lexOrder); + std::sort(elements.begin(), elements.end(), Element::lexOrder); } /// Returns rank. uint64_t getRank() const { return sizes.size(); } @@ -149,17 +160,6 @@ public: } private: - /// Returns true if indices of e1 < indices of e2. - static bool lexOrder(const Element &e1, const Element &e2) { - uint64_t rank = e1.indices.size(); - assert(rank == e2.indices.size()); - for (uint64_t r = 0; r < rank; r++) { - if (e1.indices[r] == e2.indices[r]) - continue; - return e1.indices[r] < e2.indices[r]; - } - return false; - } const std::vector sizes; // per-dimension sizes std::vector> elements; bool iteratorLocked;