-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move back to templated FullBinaryTree
- Loading branch information
Showing
78 changed files
with
792 additions
and
462 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,32 @@ | ||
#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_FMT_MONOSTATE_H | ||
#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_FMT_MONOSTATE_H | ||
|
||
#include <variant> | ||
#include <fmt/format.h> | ||
|
||
namespace fmt { | ||
|
||
template <typename Char> | ||
struct formatter< | ||
::std::monostate, | ||
Char, | ||
std::enable_if_t<!detail::has_format_as<::std::monostate>::value>> | ||
: formatter<::std::string> { | ||
template <typename FormatContext> | ||
auto format(::std::monostate const &, FormatContext &ctx) | ||
-> decltype(ctx.out()) { | ||
std::string result = "<monostate>"; | ||
|
||
return formatter<std::string>::format(result, ctx); | ||
} | ||
}; | ||
|
||
} // namespace fmt | ||
|
||
namespace FlexFlow { | ||
|
||
std::ostream &operator<<(std::ostream &, std::monostate const &); | ||
|
||
} // namespace FlexFlow | ||
|
||
#endif |
This file contains 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 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,47 @@ | ||
#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_FULL_BINARY_TREE_FMT_H | ||
#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_FULL_BINARY_TREE_FMT_H | ||
|
||
#include "utils/full_binary_tree/full_binary_tree.h" | ||
#include "utils/full_binary_tree/get_left_child.h" | ||
#include "utils/full_binary_tree/get_right_child.h" | ||
#include "utils/full_binary_tree/visit.h" | ||
#include "utils/overload.h" | ||
#include <fmt/format.h> | ||
|
||
namespace FlexFlow { | ||
|
||
template <typename ParentLabel, typename LeafLabel> | ||
std::string format_as(FullBinaryTreeParentNode<ParentLabel, LeafLabel> const &t) { | ||
return fmt::format("<{} ({} {})>", | ||
t.label, | ||
get_left_child(t), | ||
get_right_child(t)); | ||
} | ||
|
||
template <typename ParentLabel, typename LeafLabel> | ||
std::string format_as(FullBinaryTree<ParentLabel, LeafLabel> const &t) { | ||
auto visitor = FullBinaryTreeVisitor<std::string, ParentLabel, LeafLabel>{ | ||
[](FullBinaryTreeParentNode<ParentLabel, LeafLabel> const &parent) { | ||
return fmt::to_string(parent); | ||
}, | ||
[](LeafLabel const &leaf) { | ||
return fmt::format("{}", leaf); | ||
}, | ||
}; | ||
|
||
return visit(t, visitor); | ||
} | ||
|
||
template <typename ParentLabel, typename LeafLabel> | ||
std::ostream &operator<<(std::ostream &s, FullBinaryTreeParentNode<ParentLabel, LeafLabel> const &t) { | ||
return (s << fmt::to_string(t)); | ||
} | ||
|
||
template <typename ParentLabel, typename LeafLabel> | ||
std::ostream &operator<<(std::ostream &s, FullBinaryTree<ParentLabel, LeafLabel> const &t) { | ||
return (s << fmt::to_string(t)); | ||
} | ||
|
||
} // namespace FlexFlow | ||
|
||
#endif |
102 changes: 102 additions & 0 deletions
102
lib/utils/include/utils/full_binary_tree/full_binary_tree.h
This file contains 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,102 @@ | ||
#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_FULL_BINARY_TREE_FULL_BINARY_TREE_H | ||
#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_FULL_BINARY_TREE_FULL_BINARY_TREE_H | ||
|
||
#include <memory> | ||
#include <variant> | ||
#include <tuple> | ||
|
||
namespace FlexFlow { | ||
|
||
template <typename ParentLabel, typename LeafLabel> | ||
struct FullBinaryTree; | ||
|
||
template <typename ParentLabel, typename LeafLabel> | ||
struct FullBinaryTreeParentNode { | ||
explicit FullBinaryTreeParentNode( | ||
ParentLabel const &label, | ||
FullBinaryTree<ParentLabel, LeafLabel> const &lhs, | ||
FullBinaryTree<ParentLabel, LeafLabel> const &rhs) | ||
: label(label), | ||
left_child_ptr( | ||
std::make_shared<FullBinaryTree<ParentLabel, LeafLabel>>(lhs)), | ||
right_child_ptr( | ||
std::make_shared<FullBinaryTree<ParentLabel, LeafLabel>>(rhs)) | ||
{ } | ||
|
||
FullBinaryTreeParentNode(FullBinaryTreeParentNode const &) = default; | ||
|
||
bool operator==(FullBinaryTreeParentNode const &other) const { | ||
if (this->tie_ptr() == other.tie_ptr()) { | ||
return true; | ||
} | ||
|
||
return this->tie() == other.tie(); | ||
} | ||
|
||
bool operator!=(FullBinaryTreeParentNode const &other) const { | ||
if (this->tie_ptr() == other.tie_ptr()) { | ||
return false; | ||
} | ||
|
||
return this->tie() != other.tie(); | ||
} | ||
|
||
bool operator<(FullBinaryTreeParentNode const &other) const { | ||
return this->tie() < other.tie(); | ||
} | ||
public: | ||
ParentLabel label; | ||
std::shared_ptr<FullBinaryTree<ParentLabel, LeafLabel>> left_child_ptr; | ||
std::shared_ptr<FullBinaryTree<ParentLabel, LeafLabel>> right_child_ptr; | ||
private: | ||
std::tuple<ParentLabel const &, | ||
std::shared_ptr<FullBinaryTree<ParentLabel, LeafLabel>> const &, | ||
std::shared_ptr<FullBinaryTree<ParentLabel, LeafLabel>> const &> | ||
tie_ptr() const { | ||
return std::tie(this->label, this->left_child_ptr, this->right_child_ptr); | ||
} | ||
|
||
std::tuple<ParentLabel const &, | ||
FullBinaryTree<ParentLabel, LeafLabel> const &, | ||
FullBinaryTree<ParentLabel, LeafLabel> const &> | ||
tie() const { | ||
return std::tie(this->label, *this->left_child_ptr, *this->right_child_ptr); | ||
} | ||
|
||
friend std::hash<FullBinaryTreeParentNode>; | ||
}; | ||
|
||
template <typename ParentLabel, typename LeafLabel> | ||
struct FullBinaryTree { | ||
public: | ||
FullBinaryTree() = delete; | ||
explicit FullBinaryTree(FullBinaryTreeParentNode<ParentLabel, LeafLabel> const &t) | ||
: root{t} {} | ||
|
||
explicit FullBinaryTree(LeafLabel const &t) | ||
: root{t} {} | ||
|
||
bool operator==(FullBinaryTree const &other) const { | ||
return this->tie() == other.tie(); | ||
} | ||
|
||
bool operator!=(FullBinaryTree const &other) const { | ||
return this->tie() != other.tie(); | ||
} | ||
|
||
bool operator<(FullBinaryTree const &other) const { | ||
return this->tie() < other.tie(); | ||
} | ||
public: | ||
std::variant<FullBinaryTreeParentNode<ParentLabel, LeafLabel>, LeafLabel> root; | ||
private: | ||
std::tuple<decltype(root) const &> tie() const { | ||
return std::tie(this->root); | ||
} | ||
|
||
friend std::hash<FullBinaryTree>; | ||
}; | ||
|
||
} // namespace FlexFlow | ||
|
||
#endif |
20 changes: 0 additions & 20 deletions
20
lib/utils/include/utils/full_binary_tree/full_binary_tree.struct.toml
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
lib/utils/include/utils/full_binary_tree/full_binary_tree_parent_node.struct.toml
This file was deleted.
Oops, something went wrong.
This file contains 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 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
Oops, something went wrong.