Skip to content

Commit

Permalink
[RUNTIME] Add clear() function in tvm::Map class (apache#7826)
Browse files Browse the repository at this point in the history
Co-authored-by: honghua.cao <honghua.cao@streamcomputing.com>
  • Loading branch information
2 people authored and Trevor Morris committed May 6, 2021
1 parent 3a49066 commit f7c382f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/tvm/runtime/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -2980,6 +2980,13 @@ class Map : public ObjectRef {
}
/*! \return whether array is empty */
bool empty() const { return size() == 0; }
/*! \brief Release reference to all the elements */
void clear() {
MapNode* n = GetMapNode();
if (n != nullptr) {
data_ = MapNode::Empty();
}
}
/*!
* \brief set the Map.
* \param key The index key.
Expand Down
10 changes: 10 additions & 0 deletions tests/cpp/container_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ TEST(Map, Mutate) {
ICHECK(it == dict2.end());
}

TEST(Map, Clear) {
using namespace tvm;
Var x("x");
auto z = max(x + 1 + 2, 100);
Map<PrimExpr, PrimExpr> dict{{x, z}, {z, 2}};
ICHECK(dict.size() == 2);
dict.clear();
ICHECK(dict.size() == 0);
}

TEST(Map, Iterator) {
using namespace tvm;
PrimExpr a = 1, b = 2;
Expand Down

0 comments on commit f7c382f

Please sign in to comment.