Unverified Commit 4323986b authored by yxy235's avatar yxy235 Committed by GitHub
Browse files

[GraphBolt] Get feature keys of FeatureStore. (#6920)


Co-authored-by: default avatarUbuntu <ubuntu@ip-172-31-0-133.us-west-2.compute.internal>
parent 0742b85b
......@@ -171,3 +171,14 @@ class FeatureStore:
updated.
"""
raise NotImplementedError
def keys(self):
"""Get the keys of the features.
Returns
-------
List[tuple]
The keys of the features. The tuples are in `(domain, type_name,
feat_name)` format.
"""
raise NotImplementedError
......@@ -136,3 +136,14 @@ class BasicFeatureStore(FeatureStore):
def __len__(self):
"""Return the number of features."""
return len(self._features)
def keys(self):
"""Get the keys of the features.
Returns
-------
List[tuple]
The keys of the features. The tuples are in `(domain, type_name,
feat_name)` format.
"""
return list(self._features.keys())
......@@ -43,6 +43,9 @@ def test_basic_feature_store_homo():
assert feature_store.metadata("node", None, "a") == metadata
assert feature_store.metadata("node", None, "b") == {}
# Test get keys of the features.
assert feature_store.keys() == [("node", None, "a"), ("node", None, "b")]
def test_basic_feature_store_hetero():
a = torch.tensor([[1, 2, 4], [2, 5, 3]])
......@@ -81,6 +84,12 @@ def test_basic_feature_store_hetero():
assert feature_store.metadata("node", "author", "a") == metadata
assert feature_store.metadata("edge", "paper:cites", "b") == {}
# Test get keys of the features.
assert feature_store.keys() == [
("node", "author", "a"),
("edge", "paper:cites", "b"),
]
def test_basic_feature_store_errors():
a = torch.tensor([3, 2, 1])
......
......@@ -239,6 +239,12 @@ def test_torch_based_feature_store(in_memory):
"edge", "paper:cites:paper", "b"
) == torch.Size([2, 2])
# Test get the keys of the features.
assert feature_store.keys() == [
("node", "paper", "a"),
("edge", "paper:cites:paper", "b"),
]
# For windows, the file is locked by the numpy.load. We need to delete
# it before closing the temporary directory.
a = b = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment