Skip to content

Commit

Permalink
Merge pull request #1067 from bernlu/feature/dynalgorithm-bindings-py…
Browse files Browse the repository at this point in the history
…thon

Add DynAlgorithm bindings to python
  • Loading branch information
fabratu committed Jun 8, 2023
2 parents 4350ea6 + 6d0b6c7 commit c7b04c5
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 323 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ if(NETWORKIT_PYTHON)
endif()

foreach (EXT base centrality clique coarsening community components correlation
distance dynamics embedding engineering flow generators globals graph graphio
distance dynamics dynbase embedding engineering flow generators globals graph graphio
graphtools helpers independentset linkprediction matching
randomization reachability scd simulation sparsification stats
structures traversal viz)
Expand Down
1 change: 0 additions & 1 deletion docs/python_api/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ networkit.base
.. automodule:: networkit.base
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/python_api/dynbase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
networkit.dynbase
=======================

.. automodule:: networkit.dynbase
:members:
:undoc-members:
:inherited-members:
1 change: 1 addition & 0 deletions docs/python_api/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Modules
distance
dynamic
dynamics
dynbase
embedding
engineering
flow
Expand Down
5 changes: 3 additions & 2 deletions include/networkit/centrality/DynBetweennessOneNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef NETWORKIT_CENTRALITY_DYN_BETWEENNESS_ONE_NODE_HPP_
#define NETWORKIT_CENTRALITY_DYN_BETWEENNESS_ONE_NODE_HPP_

#include <networkit/base/Algorithm.hpp>
#include <networkit/base/DynAlgorithm.hpp>
#include <networkit/dynamics/GraphEvent.hpp>

Expand All @@ -17,7 +18,7 @@ namespace NetworKit {
* @ingroup graph
* Dynamic betweenness of a single node.
*/
class DynBetweennessOneNode : public DynAlgorithm {
class DynBetweennessOneNode : public Algorithm, public DynAlgorithm {

public:
/**
Expand All @@ -29,7 +30,7 @@ class DynBetweennessOneNode : public DynAlgorithm {
DynBetweennessOneNode(Graph &G, node x);

/** initialize distances and Pred by repeatedly running the Dijkstra2 algorithm */
void run();
void run() override;

/**
* Updates the betweenness centrality of x after an edge insertions on the graph.
Expand Down
12 changes: 3 additions & 9 deletions networkit/base.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ cdef extern from "<networkit/base/Algorithm.hpp>" namespace "NetworKit":
void run() nogil except +
bool_t hasFinished() except +

cdef class Algorithm:
cdef class _CythonParentClass:
cdef _Algorithm *_this

# This creates a cyclic import and is currently unused
#from .dynamics cimport _GraphEvent, GraphEvent

#cdef extern from "<networkit/base/DynAlgorithm.hpp>":
#
# cdef cppclass _DynAlgorithm "NetworKit::DynAlgorithm":
# void update(_GraphEvent) except +
# void updateBatch(vector[_GraphEvent]) except +
cdef class Algorithm(_CythonParentClass):
pass
20 changes: 19 additions & 1 deletion networkit/base.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# distutils: language=c++

cdef class Algorithm:

cdef class _CythonParentClass:
""" Abstract base class for Cython
The purpose of this class is to provide a single combined base cdef class for all classes that we use in this project.
Cython cannot handle multiple inheritance without this single common base class.
"""
def __init__(self, *args, **namedargs):
if type(self) == _CythonParentClass:
raise RuntimeError("Error, you may not use _CythonParentClass directly, use a sub-class instead")

def __cinit__(self, *args, **namedargs):
self._this = NULL

def __dealloc__(self):
if self._this != NULL:
del self._this
self._this = NULL

cdef class Algorithm(_CythonParentClass):
""" Abstract base class for algorithms """
def __init__(self, *args, **namedargs):
if type(self) == Algorithm:
Expand Down
Loading

0 comments on commit c7b04c5

Please sign in to comment.