Skip to content

Commit

Permalink
format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda7xx committed Jul 17, 2023
1 parent cd7fef3 commit 66f72db
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
11 changes: 4 additions & 7 deletions lib/utils/include/utils/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ std::unordered_map<K, V> filter_keys(std::unordered_map<K, V> const &m,
return result;
}

template <typename K, typename V, typename F> std::unordered_map<K, V> filter_keys(bidict<K, V> const & m, F const & f) {
template <typename K, typename V, typename F>
std::unordered_map<K, V> filter_keys(bidict<K, V> const &m, F const &f) {
std::unordered_map<K, V> result;
for (auto const &kv : m) {
if (f(kv.first)) {
Expand All @@ -182,8 +183,8 @@ template <typename K, typename V, typename F> std::unordered_map<K, V> filter_ke
return result;
}


template <typename K, typename V, typename F> std::unordered_map<K, V> filter_values(bidict<K, V> const & m, F const & f) {
template <typename K, typename V, typename F>
std::unordered_map<K, V> filter_values(bidict<K, V> const &m, F const &f) {
std::unordered_map<K, V> result;
for (auto const &kv : m) {
if (f(kv.second)) {
Expand All @@ -193,7 +194,6 @@ template <typename K, typename V, typename F> std::unordered_map<K, V> filter_va
return result;
}


template <typename K,
typename V,
typename F,
Expand Down Expand Up @@ -231,9 +231,6 @@ std::unordered_map<K, V> filter_values(std::unordered_map<K, V> const &m,
return result;
}




template <typename C>
std::vector<typename C::key_type> keys(C const &c) {
std::vector<typename C::key_type> result;
Expand Down
29 changes: 14 additions & 15 deletions lib/utils/include/utils/graph/query_set.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_QUERY_SET_H
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_QUERY_SET_H

#include "utils/bidict.h"
#include "utils/containers.h"
#include "utils/exception.h"
#include "utils/optional.h"
#include "utils/bidict.h"
#include <unordered_set>

namespace FlexFlow {

template <typename T>
struct query_set {
query_set() = delete;
query_set(T const & query) : query({query}) {
std::cout<<"1"<<std::endl;
query_set(T const &query) : query({query}) {
std::cout << "1" << std::endl;
}
query_set(std::unordered_set<T> const &query) : query(query) {}

query_set(optional<std::unordered_set<T>> const & query): query(query) {}
query_set(optional<std::unordered_set<T>> const &query) : query(query) {}

friend bool operator==(query_set const &lhs, query_set const &rhs) {
return lhs.value == rhs.value;
Expand Down Expand Up @@ -71,37 +71,36 @@ template <typename C,
typename K = typename C::key_type,
typename V = typename C::mapped_type>
std::unordered_map<K, V> query_keys(query_set<K> const &q, C const &m) {
std::cout<<"3"<<std::endl;
std::cout << "3" << std::endl;
std::unordered_set<K> q_set = allowed_values(q);

auto filter_lambda = [&q_set](const K& key) {
auto filter_lambda = [&q_set](K const &key) {
return q_set.find(key) != q_set.end();
};

return filter_keys(m, filter_lambda);
}//TODO
} // TODO

template <typename K,
typename V>
std::unordered_map<K,V> query_keys(query_set<V> const &q, bidict<K, V> const &m) {
template <typename K, typename V>
std::unordered_map<K, V> query_keys(query_set<V> const &q,
bidict<K, V> const &m) {
std::unordered_set<V> q_set = allowed_values(q);

auto filter_lambda = [&q_set](const V& value) {
auto filter_lambda = [&q_set](V const &value) {
return q_set.find(value) != q_set.end();
};

return filter_values(m, filter_lambda);
return filter_values(m, filter_lambda);
}


template <typename C,
typename K = typename C::key_type,
typename V = typename C::mapped_type>
std::unordered_map<K, V> query_values(query_set<V> const &q, C const &m) {
std::cout<<"4"<<std::endl;
std::cout << "4" << std::endl;
std::unordered_set<V> q_set = allowed_values(q);

auto filter_lambda = [&q_set](const V& value) {
auto filter_lambda = [&q_set](V const &value) {
return q_set.find(value) != q_set.end();
};

Expand Down
6 changes: 4 additions & 2 deletions lib/utils/src/graph/adjacency_multidigraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ void AdjacencyMultiDiGraph::remove_edge(MultiDiEdge const &e) {
std::unordered_set<MultiDiEdge>
AdjacencyMultiDiGraph::query_edges(MultiDiEdgeQuery const &q) const {
std::unordered_set<MultiDiEdge> result;
for (auto const &src_kv : query_keys(q.srcs, this->adjacency)) { //query_keys(q.srcs, this->adjacency) return map<node, map<node, map<nodeport, set<nodeport>>>>
for (auto const &src_kv : query_keys(q.srcs, this->adjacency)) {
for (auto const &dst_kv : query_keys(q.dsts, src_kv.second)) {
for (auto const &srcIdx_kv : query_keys(q.srcIdxs, dst_kv.second)) {
for (auto const &dstIdx : apply_query(q.dstIdxs, srcIdx_kv.second)) {
std::cout<<"add edge "<<src_kv.first.value()<<" "<<dst_kv.first.value()<<" "<<srcIdx_kv.first.value()<<" "<<dstIdx.value()<<std::endl;
std::cout << "add edge " << src_kv.first.value() << " "
<< dst_kv.first.value() << " " << srcIdx_kv.first.value()
<< " " << dstIdx.value() << std::endl;
result.insert({src_kv.first, dst_kv.first, srcIdx_kv.first, dstIdx});
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/src/graph/views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::unordered_set<MultiDiEdge> ViewOpenMultiDiGraphAsMultiDiGraph::query_edges(
// }

// return result;
std::cout<<"5"<<std::endl;
std::cout << "5" << std::endl;
NOT_IMPLEMENTED();
}

Expand Down Expand Up @@ -147,7 +147,7 @@ JoinedNodeView::JoinedNodeView(GraphView const &lhs, GraphView const &rhs) {

std::unordered_set<Node>
JoinedNodeView::query_nodes(NodeQuery const &query) const {
return unique(values(query_keys(query.nodes, this->mapping)));//query_keys(query.nodes, this->mapping)->std::unordered_map<x, Node>
return unique(values(query_keys(query.nodes, this->mapping)));
}

std::pair<std::unordered_set<Node>, std::unordered_set<Node>>
Expand Down

0 comments on commit 66f72db

Please sign in to comment.