Skip to content
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

Significantly improve performance #40

Merged
merged 29 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
60748f7
Optimize igraph_edge usage
ragibson Jul 12, 2020
2c0e8ac
Avoid recomputation of igraph_is_directed
ragibson Jul 12, 2020
be4a473
Eliminate extraneous igraph_vector_init/destroy
ragibson Jul 12, 2020
a395dcd
Compute strength directly to avoid weight vector copies
ragibson Jul 12, 2020
65ee723
Compute some ALL NEIGH COMMS sets directly
ragibson Jul 12, 2020
c84b8ee
Reimplement collapse_graph() to avoid map iteration
ragibson Jul 12, 2020
d743ac8
Reimplement renumber_communities() to avoid recomputing community wei…
ragibson Jul 12, 2020
7ddb678
Add some fast paths for undirected graphs
ragibson Jul 12, 2020
042bc2f
Avoid repeated resizing of _cached_neighs_comms
ragibson Jul 12, 2020
137d14d
Recommend inlining of weight_to/from_comm
ragibson Jul 12, 2020
8c08b3c
Avoid set iteration in move_nodes() and merge_nodes_constrained()
ragibson Jul 12, 2020
4488813
Fix rearrange_community_labels() to allow for nonconsecutive communit…
ragibson Jul 13, 2020
6375738
Support rearrange_community_labels() calls that result in empty commu…
ragibson Jul 13, 2020
12cf8c9
Remove ">>" to improve macOS clang support
ragibson Jul 13, 2020
fe9f84e
Add temporary printf debug statement to diagnose i686 oddity
ragibson Jul 14, 2020
2843e4b
Decrease amount of debug output, targeting fixed nodes test
ragibson Jul 14, 2020
0e7d393
Fix bookkeeping when rearranging labels creates empty communities
ragibson Jul 14, 2020
70aacab
Add additional fixed node Optimiser tests
ragibson Jul 16, 2020
ccbd73e
Add DEBUG checks to rearrange_community_labels()
ragibson Jul 16, 2020
04393cf
Add weight_to/from_comm fast path for undirected graphs
ragibson Jul 16, 2020
ad942fe
Replace edge() pointer out parameters with references
ragibson Aug 2, 2020
ff70ef4
Change edge() calls to use C++ references
ragibson Aug 2, 2020
55849af
Move temporary igraph vector initialization to Graph constructors
ragibson Aug 4, 2020
1695025
Add documentation for relabel_communities
ragibson Aug 11, 2020
97f8362
Rename comm_ids_by_decreasing_size to rank_order_communities
ragibson Aug 11, 2020
761d75c
Move comm_added and comm initializations to be together
ragibson Aug 11, 2020
cb11cc6
Compute degrees directly rather than use igraph_degree
ragibson Aug 13, 2020
c2e6ea4
CI: Correction for new signing keys of msys2. See msys.org/news (2020…
vtraag Aug 20, 2020
a0a433f
Merge branch 'fix/CI-msys' into ragibson/master
vtraag Aug 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ before_build:
- git submodule update --init --recursive

install:
- bash -lc "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
- bash -lc "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig"
- bash -lc "pacman-key --verify msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig"
- bash -lc "pacman -U --noconfirm msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
- bash -lc "pacman --needed --noconfirm -Sy pacman-mirrors"
- bash -lc "pacman --noconfirm -Sy"
- bash -lc "pacman --noconfirm -S zstd"
Expand Down
19 changes: 11 additions & 8 deletions include/GraphHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class Graph
vector<size_t> const& get_neighbours(size_t v, igraph_neimode_t mode);
size_t get_random_neighbour(size_t v, igraph_neimode_t mode, igraph_rng_t* rng);

pair<size_t, size_t> get_endpoints(size_t e);

inline size_t get_random_node(igraph_rng_t* rng)
{
return get_random_int(0, this->vcount() - 1, rng);
Expand All @@ -113,7 +111,7 @@ class Graph
inline size_t ecount() { return igraph_ecount(this->_graph); };
inline double total_weight() { return this->_total_weight; };
inline size_t total_size() { return this->_total_size; };
inline int is_directed() { return igraph_is_directed(this->_graph); };
inline int is_directed() { return this->_is_directed; };
inline double density() { return this->_density; };
inline int correct_self_loops() { return this->_correct_self_loops; };
inline int is_weighted() { return this->_is_weighted; };
Expand All @@ -128,12 +126,15 @@ class Graph
return this->_edge_weights[e];
};

inline void edge(size_t eid, size_t &from, size_t &to) {
from = IGRAPH_FROM(this->get_igraph(), eid);
to = IGRAPH_TO(this->get_igraph(), eid);
}

inline vector<size_t> edge(size_t e)
{
igraph_integer_t v1, v2;
igraph_edge(this->_graph, e, &v1, &v2);
vector<size_t> edge(2);
edge[0] = v1; edge[1] = v2;
this->edge(e, edge[0], edge[1]);
return edge;
}

Expand All @@ -147,7 +148,7 @@ class Graph

inline size_t degree(size_t v, igraph_neimode_t mode)
{
if (mode == IGRAPH_IN)
if (mode == IGRAPH_IN || !this->is_directed())
return this->_degree_in[v];
else if (mode == IGRAPH_OUT)
return this->_degree_out[v];
Expand All @@ -159,7 +160,7 @@ class Graph

inline double strength(size_t v, igraph_neimode_t mode)
{
if (mode == IGRAPH_IN)
if (mode == IGRAPH_IN || !this->is_directed())
return this->_strength_in[v];
else if (mode == IGRAPH_OUT)
return this->_strength_out[v];
Expand All @@ -173,6 +174,7 @@ class Graph

private:
igraph_t* _graph;
igraph_vector_t _temp_igraph_vector;

// Utility variables to easily access the strength of each node
vector<double> _strength_in;
Expand All @@ -199,6 +201,7 @@ class Graph
double _total_weight;
size_t _total_size;
int _is_weighted;
bool _is_directed;

int _correct_self_loops;
double _density;
Expand Down
37 changes: 33 additions & 4 deletions include/MutableVertexPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ class MutableVertexPartition
inline Graph* get_graph() { return this->graph; };

void renumber_communities();
vector<size_t> renumber_communities(map<size_t, size_t> const& original_fixed_membership);
void renumber_communities(map<size_t, size_t> const& original_fixed_membership);
void renumber_communities(vector<size_t> const& new_membership);
void set_membership(vector<size_t> const& new_membership);
vector<size_t> static renumber_communities(vector<MutableVertexPartition*> partitions);
void relabel_communities(vector<size_t> const& new_comm_id);
vector<size_t> static rank_order_communities(vector<MutableVertexPartition*> partitions);
size_t get_empty_community();
size_t add_empty_community();
void from_coarse_partition(vector<size_t> const& coarse_partition_membership);
Expand All @@ -97,8 +98,36 @@ class MutableVertexPartition
inline double total_weight_in_all_comms() { return this->_total_weight_in_all_comms; };
inline size_t total_possible_edges_in_all_comms() { return this->_total_possible_edges_in_all_comms; };

double weight_to_comm(size_t v, size_t comm);
double weight_from_comm(size_t v, size_t comm);
inline double weight_to_comm(size_t v, size_t comm)
{
if (this->_current_node_cache_community_to != v)
{
this->cache_neigh_communities(v, IGRAPH_OUT);
this->_current_node_cache_community_to = v;
}

if (comm < this->_cached_weight_to_community.size())
return this->_cached_weight_to_community[comm];
else
return 0.0;
}

inline double weight_from_comm(size_t v, size_t comm)
{
if (!this->graph->is_directed())
return weight_to_comm(v, comm);

if (this->_current_node_cache_community_from != v)
{
this->cache_neigh_communities(v, IGRAPH_IN);
this->_current_node_cache_community_from = v;
}

if (comm < this->_cached_weight_from_community.size())
return this->_cached_weight_from_community[comm];
else
return 0.0;
}

vector<size_t> const& get_neigh_comms(size_t v, igraph_neimode_t);
set<size_t> get_neigh_comms(size_t v, igraph_neimode_t mode, vector<size_t> const& constrained_membership);
Expand Down
Loading