# Interoperability between Python and C by calling igraph\_community\_walktrap function

**URL:** <https://igraph.discourse.group/t/interoperability-between-python-and-c-by-calling-igraph-community-walktrap-function/1581>\
**Category:** Usage\
**Tags:** C, Python\
**Created:** [9 June 2023 06:40 UTC](https://igraph.discourse.group/t/interoperability-between-python-and-c-by-calling-igraph-community-walktrap-function/1581 "2023-06-09T06:40:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![123AB](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/123ab/32/957_2.png) [@123AB](https://igraph.discourse.group/u/123AB)\
**Post date:** [9 June 2023 06:40 UTC](https://igraph.discourse.group/t/interoperability-between-python-and-c-by-calling-igraph-community-walktrap-function/1581/1 "2023-06-09T06:40:27Z")

</div>

I have a question about the CPython implementation by using igraph, the idea is that I want to use python to call our C/igraph igraph\_community\_walktrap function, the process is like following:

> python data → C++ → C → python data

The reason behind this is that we are using python to develop a walktrap algorithm application, but we found that the memory usage is quite high when we call python ig.Graph.community\_walktrap function:

> ig.Graph.community\_walktrap(face\_graph, weights=“sim”, steps=4).as\_clustering()

so we want to pass our python igraph graph data to C++, and calling the C/igraph library function to process our data, then return the data from C++ to python. Does anyone know is this possible by using our igraph package?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [9 June 2023 09:34 UTC](https://igraph.discourse.group/t/interoperability-between-python-and-c-by-calling-igraph-community-walktrap-function/1581/2 "2023-06-09T09:34:03Z")

</div>

If I understand your question, you are saying that the Python function `Graph.community_walktrap()` takes too much memory, therefore you are looking to call the C function `igraph_community_walktrap()`.

However, `Graph.community_walktrap()` is just a wrapper to `igraph_community_walktrap()`, so unless there is a memory issue with the `VertexDendrogram` object, there shouldn’t be a significant difference.

---

<div class="post-metadata">

**Author:** ![123AB](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/123ab/32/957_2.png) [@123AB](https://igraph.discourse.group/u/123AB)\
**Post date:** [9 June 2023 10:08 UTC](https://igraph.discourse.group/t/interoperability-between-python-and-c-by-calling-igraph-community-walktrap-function/1581/3 "2023-06-09T10:08:36Z")

</div>

Ok, I got it. Thank you for your reply. But I really want to reduce the memory usage. The Graph.community\_walktrap cost too much memory, and honestly this is the most memory-cosume part in my project. Do you have any good idea about how to reduce the memory cost? Thank you.

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [9 June 2023 10:43 UTC](https://igraph.discourse.group/t/interoperability-between-python-and-c-by-calling-igraph-community-walktrap-function/1581/4 "2023-06-09T10:43:05Z")

</div>

I went through the code in the C core of igraph in `src/community/walktrap` and it seems like memory allocations are proportional to the number of nodes and edges in the graph, so unless you are working with super large graphs the memory usage should not be too high. How large is your graph?

---

<div class="post-metadata">

**Author:** ![123AB](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/123ab/32/957_2.png) [@123AB](https://igraph.discourse.group/u/123AB)\
**Post date:** [9 June 2023 16:27 UTC](https://igraph.discourse.group/t/interoperability-between-python-and-c-by-calling-igraph-community-walktrap-function/1581/5 "2023-06-09T16:27:45Z")

</div>

My graph contains 100,000 images, so it’s a 100,000 \* 100,000 size matrix, and I took the upper triangular matrix as the input adjacency matrix to generate the graph. So the graph is quite large.
