From 6691b9e2ce6dba3ee0f0c641e52ac16be881fb7e Mon Sep 17 00:00:00 2001 From: lambda7xx Date: Sat, 15 Jul 2023 13:16:41 +0000 Subject: [PATCH] format --- lib/utils/include/utils/graph/multidiedge.h | 2 +- .../utils/graph/multidigraph_interfaces.h | 4 +- lib/utils/include/utils/graph/open_graphs.h | 2 +- lib/utils/include/utils/graph/query_set.h | 4 +- lib/utils/src/graph/adjacency_multidigraph.cc | 2 +- lib/utils/src/graph/digraph.cc | 15 ++++--- lib/utils/src/graph/multidigraph.cc | 24 ++++++----- lib/utils/src/graph/node.cc | 11 ++--- lib/utils/src/graph/views.cc | 2 +- .../test/src/test_adjacency_multidigraph.cc | 40 ++++++++++--------- lib/utils/test/src/test_algorithms.cc | 26 +++++++----- 11 files changed, 73 insertions(+), 59 deletions(-) diff --git a/lib/utils/include/utils/graph/multidiedge.h b/lib/utils/include/utils/graph/multidiedge.h index 508779a0fe..3d5d0332f3 100644 --- a/lib/utils/include/utils/graph/multidiedge.h +++ b/lib/utils/include/utils/graph/multidiedge.h @@ -26,7 +26,7 @@ struct MultiDiEdge { NodePort srcIdx, dstIdx; }; FF_VISITABLE_STRUCT(MultiDiEdge, src, dst, srcIdx, dstIdx); -std::ostream& operator<<(std::ostream& os, const MultiDiEdge& edge); +std::ostream &operator<<(std::ostream &os, MultiDiEdge const &edge); struct MultiDiInput { Node node; diff --git a/lib/utils/include/utils/graph/multidigraph_interfaces.h b/lib/utils/include/utils/graph/multidigraph_interfaces.h index 807d94a452..fbcf30d810 100644 --- a/lib/utils/include/utils/graph/multidigraph_interfaces.h +++ b/lib/utils/include/utils/graph/multidigraph_interfaces.h @@ -21,7 +21,7 @@ struct MultiDiEdgeQuery { MultiDiEdgeQuery with_src_idxs(query_set const &) const; MultiDiEdgeQuery with_dst_idxs(query_set const &) const; - MultiDiEdgeQuery with_dst_node(Node const &) const; + MultiDiEdgeQuery with_dst_node(Node const &) const; MultiDiEdgeQuery with_src_node(Node const &) const; MultiDiEdgeQuery with_src_idx(NodePort const &) const; MultiDiEdgeQuery with_dst_idx(NodePort const &) const; @@ -40,7 +40,7 @@ struct IMultiDiGraphView : public IGraphView { using EdgeQuery = MultiDiEdgeQuery; virtual std::unordered_set query_edges(EdgeQuery const &) const = 0; - virtual ~IMultiDiGraphView()=default; + virtual ~IMultiDiGraphView() = default; }; CHECK_RC_COPY_VIRTUAL_COMPLIANT(IMultiDiGraphView); diff --git a/lib/utils/include/utils/graph/open_graphs.h b/lib/utils/include/utils/graph/open_graphs.h index 219fa344e6..378287a821 100644 --- a/lib/utils/include/utils/graph/open_graphs.h +++ b/lib/utils/include/utils/graph/open_graphs.h @@ -72,7 +72,7 @@ struct OpenMultiDiGraph { } OpenMultiDiGraph(std::unique_ptr ptr); - + private: cow_ptr_t ptr; }; diff --git a/lib/utils/include/utils/graph/query_set.h b/lib/utils/include/utils/graph/query_set.h index c71903ca72..ee54f07446 100644 --- a/lib/utils/include/utils/graph/query_set.h +++ b/lib/utils/include/utils/graph/query_set.h @@ -14,8 +14,8 @@ struct query_set { query_set(T const &) { NOT_IMPLEMENTED(); } - query_set(std::unordered_set const & query): query(query) {} - + query_set(std::unordered_set const &query) : query(query) {} + query_set(optional> const &) { NOT_IMPLEMENTED(); } diff --git a/lib/utils/src/graph/adjacency_multidigraph.cc b/lib/utils/src/graph/adjacency_multidigraph.cc index b17a5d0742..ce9fd33d8d 100644 --- a/lib/utils/src/graph/adjacency_multidigraph.cc +++ b/lib/utils/src/graph/adjacency_multidigraph.cc @@ -6,7 +6,7 @@ namespace FlexFlow { Node AdjacencyMultiDiGraph::add_node() { Node node{this->next_node_idx}; adjacency[node]; - std::cout<<"add node "<next_node_idx++; return node; } diff --git a/lib/utils/src/graph/digraph.cc b/lib/utils/src/graph/digraph.cc index e67eca3ac0..6c33225755 100644 --- a/lib/utils/src/graph/digraph.cc +++ b/lib/utils/src/graph/digraph.cc @@ -75,17 +75,20 @@ DiGraphView unsafe_create(IDiGraphView const &graphView) { } DirectedEdgeQuery DirectedEdgeQuery::all() { - return {matchall(), - matchall()}; + return {matchall(), matchall()}; } -DirectedEdgeQuery query_intersection(DirectedEdgeQuery const &lhs, DirectedEdgeQuery const &rhs){ +DirectedEdgeQuery query_intersection(DirectedEdgeQuery const &lhs, + DirectedEdgeQuery const &rhs) { assert(lhs != tl::nullopt); assert(rhs != tl::nullopt); - assert (lhs.srcs.has_value() && lhs.dsts.has_value() && rhs.srcs.has_value() && rhs.dsts.has_value()); + assert(lhs.srcs.has_value() && lhs.dsts.has_value() && rhs.srcs.has_value() && + rhs.dsts.has_value()); - std::unordered_set srcs_t1 = intersection(allowed_values(lhs.srcs), allowed_values(rhs.srcs)); - std::unordered_set dsts_t1 = intersection(allowed_values(lhs.dsts), allowed_values(rhs.dsts)); + std::unordered_set srcs_t1 = + intersection(allowed_values(lhs.srcs), allowed_values(rhs.srcs)); + std::unordered_set dsts_t1 = + intersection(allowed_values(lhs.dsts), allowed_values(rhs.dsts)); DirectedEdgeQuery result = DirectedEdgeQuery::all(); result.srcs = srcs_t1; diff --git a/lib/utils/src/graph/multidigraph.cc b/lib/utils/src/graph/multidigraph.cc index 85a950d892..2ddcb22b60 100644 --- a/lib/utils/src/graph/multidigraph.cc +++ b/lib/utils/src/graph/multidigraph.cc @@ -40,15 +40,19 @@ MultiDiEdgeQuery } MultiDiEdgeQuery query_intersection(MultiDiEdgeQuery const &lhs, - MultiDiEdgeQuery const &rhs) { + MultiDiEdgeQuery const &rhs) { assert(lhs != tl::nullopt); assert(rhs != tl::nullopt); - std::unordered_set srcs_t1 = intersection(allowed_values(lhs.srcs), allowed_values(rhs.srcs)); - std::unordered_set dsts_t1 = intersection(allowed_values(lhs.dsts), allowed_values(rhs.dsts)); + std::unordered_set srcs_t1 = + intersection(allowed_values(lhs.srcs), allowed_values(rhs.srcs)); + std::unordered_set dsts_t1 = + intersection(allowed_values(lhs.dsts), allowed_values(rhs.dsts)); - std::unordered_set srcIdxs_t1 = intersection(allowed_values(lhs.srcIdxs), allowed_values(rhs.srcIdxs)); - std::unordered_set dstIdxs_t1 = intersection(allowed_values(lhs.dstIdxs), allowed_values(rhs.dstIdxs)); + std::unordered_set srcIdxs_t1 = + intersection(allowed_values(lhs.srcIdxs), allowed_values(rhs.srcIdxs)); + std::unordered_set dstIdxs_t1 = + intersection(allowed_values(lhs.dstIdxs), allowed_values(rhs.dstIdxs)); MultiDiEdgeQuery e = MultiDiEdgeQuery::all(); e.srcs = srcs_t1; @@ -61,19 +65,19 @@ MultiDiEdgeQuery query_intersection(MultiDiEdgeQuery const &lhs, MultiDiEdgeQuery MultiDiEdgeQuery::with_dst_node(Node const &n) const { return this->with_dst_nodes({n}); } -MultiDiEdgeQuery MultiDiEdgeQuery::with_src_idx(NodePort const & p) const { +MultiDiEdgeQuery MultiDiEdgeQuery::with_src_idx(NodePort const &p) const { return this->with_src_idxs({p}); } -MultiDiEdgeQuery MultiDiEdgeQuery::with_dst_idx(NodePort const & p) const { +MultiDiEdgeQuery MultiDiEdgeQuery::with_dst_idx(NodePort const &p) const { return this->with_dst_idxs({p}); } -MultiDiEdgeQuery MultiDiEdgeQuery::with_src_idxs( - query_set const &idxs) const { +MultiDiEdgeQuery + MultiDiEdgeQuery::with_src_idxs(query_set const &idxs) const { MultiDiEdgeQuery e{*this}; if (is_matchall(e.srcIdxs)) { - throw mk_runtime_error("Expected matchall previous value"); + throw mk_runtime_error("Expected matchall previous value"); } e.srcIdxs = idxs; return e; diff --git a/lib/utils/src/graph/node.cc b/lib/utils/src/graph/node.cc index 82ca92b7ca..da4249a24f 100644 --- a/lib/utils/src/graph/node.cc +++ b/lib/utils/src/graph/node.cc @@ -7,13 +7,14 @@ std::ostream &operator<<(std::ostream &os, Node const &node) { return os << fmt::format("Node({})", node.value()); } -NodeQuery NodeQuery::all() { - return {matchall()} ; - } +NodeQuery NodeQuery::all() { + return {matchall()}; +} -NodeQuery query_intersection(NodeQuery const & lhs, NodeQuery const & rhs) { +NodeQuery query_intersection(NodeQuery const &lhs, NodeQuery const &rhs) { assert(lhs != tl::nullopt && rhs != tl::nullopt); - std::unordered_set nodes = intersection(allowed_values(lhs.nodes), allowed_values(rhs.nodes)); + std::unordered_set nodes = + intersection(allowed_values(lhs.nodes), allowed_values(rhs.nodes)); NodeQuery intersection_result = NodeQuery::all(); intersection_result.nodes = nodes; return intersection_result; diff --git a/lib/utils/src/graph/views.cc b/lib/utils/src/graph/views.cc index 7f8dca7995..8c0da05971 100644 --- a/lib/utils/src/graph/views.cc +++ b/lib/utils/src/graph/views.cc @@ -42,7 +42,7 @@ std::unordered_set ViewOpenMultiDiGraphAsMultiDiGraph::query_nodes( std::unordered_set ViewOpenMultiDiGraphAsMultiDiGraph::query_edges( MultiDiEdgeQuery const &query) const { - + // OpenMultiDiEdgeQuery q{query}; // // q.standard_edge_query = query; // std::unordered_set edges = g.query_edges(q); diff --git a/lib/utils/test/src/test_adjacency_multidigraph.cc b/lib/utils/test/src/test_adjacency_multidigraph.cc index e375084183..16297a02db 100644 --- a/lib/utils/test/src/test_adjacency_multidigraph.cc +++ b/lib/utils/test/src/test_adjacency_multidigraph.cc @@ -21,13 +21,15 @@ TEST_CASE("AdjacencyMultiDiGraph:basic_test") { g.add_edge(e3); g.add_edge(e4); - CHECK(g.query_nodes(NodeQuery::all()) == std::unordered_set{n0, n1, n2}); - + CHECK(g.query_nodes(NodeQuery::all()) == + std::unordered_set{n0, n1, n2}); + std::unordered_set nodes = {n0, n2}; query_set q{nodes}; CHECK(g.query_nodes(NodeQuery(q)) == std::unordered_set{n0, n2}); - //CHECK(g.query_edges({}) == std::unordered_set{e1, e2, e3, e4}); + // CHECK(g.query_edges({}) == std::unordered_set{e1, e2, e3, + // e4}); CHECK(g.query_edges(MultiDiEdgeQuery::all().with_src_node(n1)) == std::unordered_set{}); @@ -37,22 +39,22 @@ TEST_CASE("AdjacencyMultiDiGraph:basic_test") { std::unordered_set{}); CHECK(g.query_edges(MultiDiEdgeQuery::all().with_dst_idx(p1)) == std::unordered_set{e1, e4}); -// CHECK(g.query_edges(MultiDiEdgeQuery::all().with_src_nodes({n1, n2})) == -// std::unordered_set{e3, e4}); -// CHECK(g.query_edges(MultiDiEdgeQuery::all().with_dst_nodes({n0, n2})) == -// std::unordered_set{e2, e3}); -// CHECK(g.query_edges(MultiDiEdgeQuery::all().with_src_idxs({p1, p2})) == -// std::unordered_set{e3, e4}); -// CHECK(g.query_edges(MultiDiEdgeQuery::all().with_dst_idxs({p0, p2})) == -// std::unordered_set{e2, e3}); -// CHECK(g.query_edges(MultiDiEdgeQuery::all() -// .with_src_node(n1) -// .with_dst_node(n2) -// .with_src_idx(p1) -// .with_dst_idx(p2)) == -// std::unordered_set{}); -// CHECK(g.query_edges(MultiDiEdgeQuery::all().with_dst_idx(p2)) == -// std::unordered_set{e2}); + // CHECK(g.query_edges(MultiDiEdgeQuery::all().with_src_nodes({n1, n2})) == + // std::unordered_set{e3, e4}); + // CHECK(g.query_edges(MultiDiEdgeQuery::all().with_dst_nodes({n0, n2})) == + // std::unordered_set{e2, e3}); + // CHECK(g.query_edges(MultiDiEdgeQuery::all().with_src_idxs({p1, p2})) == + // std::unordered_set{e3, e4}); + // CHECK(g.query_edges(MultiDiEdgeQuery::all().with_dst_idxs({p0, p2})) == + // std::unordered_set{e2, e3}); + // CHECK(g.query_edges(MultiDiEdgeQuery::all() + // .with_src_node(n1) + // .with_dst_node(n2) + // .with_src_idx(p1) + // .with_dst_idx(p2)) == + // std::unordered_set{}); + // CHECK(g.query_edges(MultiDiEdgeQuery::all().with_dst_idx(p2)) == + // std::unordered_set{e2}); } // TEST_CASE("AdjacencyMultiDiGraph:remove_node") { diff --git a/lib/utils/test/src/test_algorithms.cc b/lib/utils/test/src/test_algorithms.cc index 7f6c88d121..31b034c89a 100644 --- a/lib/utils/test/src/test_algorithms.cc +++ b/lib/utils/test/src/test_algorithms.cc @@ -28,13 +28,14 @@ // g.add_edge(e3); // CHECK(g.query_nodes({}) == std::unordered_set{n0, n1, n2, n3}); -// CHECK(g.query_edges({}) == std::unordered_set{e0, e1, e2, e3}); -// CHECK(get_incoming_edges(g, {n1, n3}) == +// CHECK(g.query_edges({}) == std::unordered_set{e0, e1, e2, +// e3}); CHECK(get_incoming_edges(g, {n1, n3}) == // std::unordered_set{e0, e2, e3}); // CHECK(get_incoming_edges(g, {n1}) == std::unordered_set{}); -// CHECK(get_outgoing_edges(g, {n2, n3}) == std::unordered_set{e3}); -// auto res = get_predecessors(g, {n1, n2, n3}); -// auto expected_result = std::unordered_map>{ +// CHECK(get_outgoing_edges(g, {n2, n3}) == +// std::unordered_set{e3}); auto res = get_predecessors(g, {n1, +// n2, n3}); auto expected_result = std::unordered_map>{ // {n1, {}}, // {n2, {n1}}, // {n3, {n0, n1, n2}}, @@ -60,11 +61,12 @@ // g.add_edge(e2); // g.add_edge(e3); -// CHECK(g.query_edges({}) == std::unordered_set{e0, e1, e2, e3}); -// CHECK(get_incoming_edges(g, {n2, n3}) == +// CHECK(g.query_edges({}) == std::unordered_set{e0, e1, e2, +// e3}); CHECK(get_incoming_edges(g, {n2, n3}) == // std::unordered_set{e0, e2, e3}); -// CHECK(get_outgoing_edges(g, {n2, n3}) == std::unordered_set{}); -// auto expected_result = std::unordered_map>{ +// CHECK(get_outgoing_edges(g, {n2, n3}) == +// std::unordered_set{}); auto expected_result = +// std::unordered_map>{ // {n1, {n0}}, // {n2, {n0, n1}}, // {n3, {n0}}, @@ -82,7 +84,8 @@ // g.add_edge({n[1], n[2]}); // g.add_edge({n[2], n[3]}); -// /* CHECK(get_incoming_edges(g, n[0]) == std::unordered_set{}); +// /* CHECK(get_incoming_edges(g, n[0]) == +// std::unordered_set{}); // */ // CHECK(get_sources(g) == std::unordered_set{n[0]}); // CHECK(get_unchecked_dfs_ordering(g, {n[0]}) == @@ -136,7 +139,8 @@ // auto CHECK_BEFORE = [&](int l, int r) { // CHECK(index_of(ordering, n[l]).has_value()); // CHECK(index_of(ordering, n[r]).has_value()); -// CHECK(index_of(ordering, n[l]).value() < index_of(ordering, n[r]).value()); +// CHECK(index_of(ordering, n[l]).value() < index_of(ordering, +// n[r]).value()); // }; // CHECK(ordering.size() == n.size());