Skip to content

add some method for utils#761

Closed
lambda7xx wants to merge 1 commit intorepo-refactorfrom
repo-refactor-lambda3
Closed

add some method for utils#761
lambda7xx wants to merge 1 commit intorepo-refactorfrom
repo-refactor-lambda3

Conversation

@lambda7xx
Copy link
Copy Markdown
Contributor

add some method for utils

@lambda7xx lambda7xx requested a review from lockshaw June 9, 2023 08:50
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete the README?

std::unordered_map<Node, std::unordered_set<Node>>
get_predecessors(DiGraphView const &, std::unordered_set<Node> const &);

// return the set of nodes without incoming edges
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to doxygen syntax

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a separate commit -- pull in changes from the commit linked in #758

DiGraphView() = delete;

operator GraphView() const;
operator GraphView() const {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move implementations to .cc files to avoid unnecessary compilations


namespace FlexFlow {

/**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted?

GraphView(std::shared_ptr<IGraphView const>);
GraphView(std::shared_ptr<IGraphView const> ptr) : ptr(ptr) {}

private:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you could review your PRs before requesting reviews (such as with git add -p) just to avoid small fixes like this making it in to the review (if you're already doing this, no problem--we all miss things sometimes 🙂)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why are we making this public? I don't see a reason why this shouldn't be private.


struct IGraph : IGraphView {
IGraph(IGraph const &) = delete;
IGraph() = default;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

InputMultiDiEdge(std::pair<std::size_t, std::size_t> const &,
Node const &,
std::size_t const &);
InputMultiDiEdge(std::pair<std::size_t, std::size_t> const &uid,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementations in .cc files


namespace FlexFlow {

struct UndirectedEdge : public use_visitable_cmp<UndirectedEdge> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer the explicit public--if you have an reason to prefer the other though I'd be happy to be convinced the other way


private:
UndirectedGraphView(std::shared_ptr<IUndirectedGraphView const>);
UndirectedGraphView(std::shared_ptr<IUndirectedGraphView const> ptr)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being made public?

UndirectedGraph &operator=(UndirectedGraph);

operator UndirectedGraphView() const;
operator UndirectedGraphView() const {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template <>
struct hash<::FlexFlow::JoinNodeKey> {
std::size_t operator()(::FlexFlow::JoinNodeKey const &) const;
std::size_t operator()(::FlexFlow::JoinNodeKey const &key) const {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead convert JoinNodeKey to being visitable and use MAKE_VISIT_HASHABLE

maybe_owned_ref() = delete;
maybe_owned_ref(T *);
maybe_owned_ref(std::shared_ptr<T>);
maybe_owned_ref(T *ptr) : _ptr(std::shared_ptr<T>(ptr)){};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the pointer should not be owned: change to _ptr(ptr)

}

std::unordered_set<Node> get_nodes(GraphView const &g) {
return g.unsafe()->query_nodes({});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return g.unsafe()->query_nodes({});
return g.query_nodes({});

Also, get_nodes(IGraphView const &) should be removed--algorithms should now function on Graphs, not IGraphs

}

std::unordered_set<Node> get_sinks(MultiDiGraphView const &g) {
std::unordered_set<Node> dsts;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change to use filter from containers.h? Would shorten this quite a bit I think

return std::unique_ptr<IDiGraphView>(new ViewMultiDiGraphAsDiGraph{multidi});
}

// DiGraphView unsafe_view_as_digraph(MultiDiGraphView const &) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

assert(lhs.srcs.has_value() && lhs.dsts.has_value() && rhs.srcs.has_value() &&
rhs.dsts.has_value());

tl::optional<std::unordered_set<Node>> srcs_t1 =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tl::optional<std::unordered_set<Node>> srcs_t1 =
optional<std::unordered_set<Node>> srcs_t1 =


DirectedEdgeQuery query_intersection(DirectedEdgeQuery const &lhs,
DirectedEdgeQuery const &rhs) {
assert(lhs.srcs.has_value() && lhs.dsts.has_value() && rhs.srcs.has_value() &&
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl::optional<std::unordered_set<Node>> dsts =
intersection(*lhs.dsts, *rhs.dsts);

// TODO, how to set srcIdxs, dstIdxs
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not merge this change until this TODO has been resolved


MultiDiGraph::operator MultiDiGraphView() const {
std::shared_ptr<IMultiDiGraph const> sharedPtr = ptr.get_shared_ptr();
return MultiDiGraphView(sharedPtr);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return MultiDiGraphView(sharedPtr);
return MultiDiGraphView(this->ptr.get_shared_ptr());

@@ -18,9 +18,16 @@ struct SplitASTNode;
using SplitAST = mpark::variant<SplitASTNode, Node>;

struct SplitASTNode {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move implementation to .cc file (also make SplitASTNode visitable)

JoinNodeKey::JoinNodeKey(Node const &node, LRDirection direction)
: node(node), direction(direction) {}

bool JoinNodeKey::operator==(JoinNodeKey const &jnk) const {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make JoinNodeKey visitable and use the automatic == generation

CHECK_BEFORE(3, 4);
CHECK_BEFORE(4, 5);
}
// #include "doctest.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why comment out all of the tests?

Copy link
Copy Markdown
Collaborator

@lockshaw lockshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See individual comments

@lambda7xx lambda7xx closed this Jun 21, 2023
@lambda7xx lambda7xx deleted the repo-refactor-lambda3 branch July 6, 2023 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants