-
Notifications
You must be signed in to change notification settings - Fork 9
Add AMS Homogeneous and Heterogenous Graph data structures. #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24952fa
Add support for int32_t and int64_t.
YohannDudouit 806d2c8
Fix typo/bug in AMSEOS.
YohannDudouit fbe9fa1
Apply suggestions from code review
YohannDudouit 9e548a0
Add AMS Homogeneous and Heterogenous Graph data structures.
YohannDudouit eb65263
Update CI user for LLNL tests (#189)
lpottier e1357a0
Add support for int32_t and int64_t (#187)
YohannDudouit 51b47ca
Add AMS Homogeneous and Heterogenous Graph data structures.
YohannDudouit 0a7be4c
Merge branch 'yohann/graph-support' of https://github.com/llnl/AMS in…
YohannDudouit 8498102
clang-format.
YohannDudouit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| #include "AMSGraph.hpp" | ||
|
|
||
| #include <stdexcept> | ||
|
|
||
| namespace ams | ||
| { | ||
| namespace | ||
| { | ||
|
|
||
| static std::size_t hashCombine(std::size_t seed, std::size_t value) noexcept | ||
| { | ||
| seed ^= value + 0x9e3779b9u + (seed << 6) + (seed >> 2); | ||
| return seed; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| EdgeType::EdgeType(std::string src_, std::string rel_, std::string dst_) | ||
| : src(std::move(src_)), rel(std::move(rel_)), dst(std::move(dst_)) | ||
| { | ||
| } | ||
|
|
||
| bool EdgeType::operator==(const EdgeType& other) const noexcept | ||
| { | ||
| return src == other.src && rel == other.rel && dst == other.dst; | ||
| } | ||
|
|
||
| std::size_t EdgeTypeHash::operator()(const EdgeType& e) const noexcept | ||
| { | ||
| std::size_t seed = std::hash<std::string>{}(e.src); | ||
| seed = hashCombine(seed, std::hash<std::string>{}(e.rel)); | ||
| seed = hashCombine(seed, std::hash<std::string>{}(e.dst)); | ||
| return seed; | ||
| } | ||
|
|
||
| std::string edgeTypeToString(const EdgeType& e) | ||
| { | ||
| return e.src + "__" + e.rel + "__" + e.dst; | ||
| } | ||
|
|
||
| ams::EdgeType edgeTypeFromString(const std::string& key) | ||
| { | ||
| const std::string delim = "__"; | ||
|
|
||
| auto p1 = key.find(delim); | ||
| if (p1 == std::string::npos) { | ||
| throw std::runtime_error("edgeTypeFromString: missing first delimiter"); | ||
| } | ||
|
|
||
| auto p2 = key.find(delim, p1 + delim.size()); | ||
| if (p2 == std::string::npos) { | ||
| throw std::runtime_error("edgeTypeFromString: missing second delimiter"); | ||
| } | ||
|
|
||
| if (key.find(delim, p2 + delim.size()) != std::string::npos) { | ||
| throw std::runtime_error("edgeTypeFromString: too many delimiters"); | ||
| } | ||
|
|
||
| std::string src = key.substr(0, p1); | ||
| std::string rel = key.substr(p1 + delim.size(), p2 - (p1 + delim.size())); | ||
| std::string dst = key.substr(p2 + delim.size()); | ||
|
|
||
| if (src.empty() || rel.empty() || dst.empty()) { | ||
| throw std::runtime_error("edgeTypeFromString: empty src/rel/dst component"); | ||
| } | ||
|
|
||
| return ams::EdgeType{std::move(src), std::move(rel), std::move(dst)}; | ||
| } | ||
|
|
||
| bool containsTensor(const AMSTensorMap& store, const std::string& name) | ||
| { | ||
| return store.find(name) != store.end(); | ||
| } | ||
|
|
||
| AMSTensor* findTensor(AMSTensorMap& store, const std::string& name) noexcept | ||
| { | ||
| auto it = store.find(name); | ||
| if (it == store.end()) { | ||
| return nullptr; | ||
| } | ||
| return &it->second; | ||
| } | ||
|
|
||
| const AMSTensor* findTensor(const AMSTensorMap& store, | ||
| const std::string& name) noexcept | ||
| { | ||
| auto it = store.find(name); | ||
| if (it == store.end()) { | ||
| return nullptr; | ||
| } | ||
| return &it->second; | ||
| } | ||
|
|
||
| void insertTensor(AMSTensorMap& store, std::string name, AMSTensor&& tensor) | ||
| { | ||
| auto [it, inserted] = store.emplace(std::move(name), std::move(tensor)); | ||
| if (!inserted) { | ||
| throw std::runtime_error("insertTensor: tensor name already exists"); | ||
| } | ||
| } | ||
|
|
||
| void insertOrAssignTensor(AMSTensorMap& store, | ||
| std::string name, | ||
| AMSTensor&& tensor) | ||
| { | ||
| auto it = store.find(name); | ||
| if (it == store.end()) { | ||
| store.emplace(std::move(name), std::move(tensor)); | ||
| } else { | ||
| it->second = std::move(tensor); | ||
| } | ||
| } | ||
|
|
||
| bool AMSHeterogeneousGraph::containsNodeStore(const std::string& name) const | ||
| { | ||
| return node_stores.find(name) != node_stores.end(); | ||
| } | ||
|
|
||
| bool AMSHeterogeneousGraph::containsEdgeStore(const EdgeType& edge_type) const | ||
| { | ||
| return edge_stores.find(edge_type) != edge_stores.end(); | ||
| } | ||
|
|
||
| AMSTensorMap& AMSHeterogeneousGraph::getOrCreateNodeStore(std::string name) | ||
| { | ||
| auto [it, inserted] = | ||
| node_stores.try_emplace(std::move(name), AMSTensorMap{}); | ||
| (void)inserted; | ||
| return it->second; | ||
| } | ||
|
|
||
| AMSTensorMap& AMSHeterogeneousGraph::getOrCreateEdgeStore(EdgeType edge_type) | ||
| { | ||
| auto [it, inserted] = | ||
| edge_stores.try_emplace(std::move(edge_type), AMSTensorMap{}); | ||
| (void)inserted; | ||
| return it->second; | ||
| } | ||
|
|
||
| AMSTensorMap* AMSHeterogeneousGraph::findNodeStore( | ||
| const std::string& name) noexcept | ||
| { | ||
| auto it = node_stores.find(name); | ||
| if (it == node_stores.end()) { | ||
| return nullptr; | ||
| } | ||
| return &it->second; | ||
| } | ||
|
|
||
| const AMSTensorMap* AMSHeterogeneousGraph::findNodeStore( | ||
| const std::string& name) const noexcept | ||
| { | ||
| auto it = node_stores.find(name); | ||
| if (it == node_stores.end()) { | ||
| return nullptr; | ||
| } | ||
| return &it->second; | ||
| } | ||
|
|
||
| AMSTensorMap* AMSHeterogeneousGraph::findEdgeStore( | ||
| const EdgeType& edge_type) noexcept | ||
| { | ||
| auto it = edge_stores.find(edge_type); | ||
| if (it == edge_stores.end()) { | ||
| return nullptr; | ||
| } | ||
| return &it->second; | ||
| } | ||
|
|
||
| const AMSTensorMap* AMSHeterogeneousGraph::findEdgeStore( | ||
| const EdgeType& edge_type) const noexcept | ||
| { | ||
| auto it = edge_stores.find(edge_type); | ||
| if (it == edge_stores.end()) { | ||
| return nullptr; | ||
| } | ||
| return &it->second; | ||
| } | ||
|
|
||
| } // namespace ams | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the goal of that function / magic number? Can't we use a classic hashing function?