Skip to content

Commit 3383860

Browse files
committed
[feat] add GCluster in python.
1 parent 109f57c commit 3383860

File tree

14 files changed

+206
-118
lines changed

14 files changed

+206
-118
lines changed

python/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

22
cmake_minimum_required(VERSION 3.8)
3-
project(pyCGraph)
3+
project(PyCGraph)
44

55
set(CMAKE_CXX_STANDARD 11)
66
set(CMAKE_CXX_STANDARD_REQUIRED True)
77

88
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared -pthread -fPIC")
99

10-
find_package(PythonLibs REQUIRED)
1110
find_package(pybind11 CONFIG REQUIRED)
1211

1312
include(../cmake/CGraph-env-include.cmake)
1413

15-
include_directories(pyCGraph PUBLIC
14+
include_directories(PyCGraph PUBLIC
1615
${pybind11_INCLUDE_DIRS}
17-
${PYTHON_INCLUDE_DIRS})
16+
)
1817

19-
pybind11_add_module(pyCGraph
18+
pybind11_add_module(PyCGraph
2019
$<TARGET_OBJECTS:CGraph>
21-
SHARED pyCGraph.cpp)
20+
SHARED PyCGraph.cpp
21+
)
2222

23-
target_link_libraries(pyCGraph PRIVATE
23+
target_link_libraries(PyCGraph PRIVATE
2424
pybind11::pybind11
25-
${PYTHON_LIBRARIES})
25+
)
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using namespace CGraph;
88
namespace py = pybind11;
99

10-
PYBIND11_MODULE(pyCGraph, m) {
10+
PYBIND11_MODULE(PyCGraph, m) {
1111
py::class_<CStatus>(m, "CStatus")
1212
.def(py::init<>())
1313
.def(py::init<int, const std::string&>())
@@ -20,46 +20,53 @@ PYBIND11_MODULE(pyCGraph, m) {
2020
.value("PARALLEL", GMultiConditionType::PARALLEL)
2121
.export_values();
2222

23-
py::class_<GPipelinePy, std::unique_ptr<GPipelinePy, py::nodelete> >(m, "GPipeline")
23+
py::class_<PyGPipeline, std::unique_ptr<PyGPipeline, py::nodelete> >(m, "GPipeline")
2424
.def(py::init<>())
25-
.def("init", &GPipelinePy::init)
26-
.def("run", &GPipelinePy::run, py::call_guard<py::gil_scoped_release>())
27-
.def("process", &GPipelinePy::process, py::call_guard<py::gil_scoped_release>(),
25+
.def("init", &PyGPipeline::init)
26+
.def("run", &PyGPipeline::run, py::call_guard<py::gil_scoped_release>())
27+
.def("process", &PyGPipeline::process, py::call_guard<py::gil_scoped_release>(),
2828
py::arg("runTimes") = 1)
29-
.def("destroy", &GPipelinePy::destroy)
30-
.def("registerGElement", &GPipelinePy::registerGElement,
29+
.def("destroy", &PyGPipeline::destroy)
30+
.def("registerGElement", &PyGPipeline::registerGElement,
3131
py::arg("element"),
3232
py::arg("depends") = GElementPtrSet{},
3333
py::arg("name") = CGRAPH_EMPTY,
3434
py::arg("loop") = CGRAPH_DEFAULT_LOOP_TIMES,
3535
"register a GElement with dependencies, name, and loop count.");
3636

37-
py::class_<GElement, GElementPyw, std::unique_ptr<GElement, py::nodelete> >(m, "GElement")
37+
py::class_<GElement, PywGElement, std::unique_ptr<GElement, py::nodelete> >(m, "GElement")
3838
.def(py::init<>())
3939
.def("getName", &GElement::getName)
4040
.def("setName", &GElement::setName)
4141
.def("addDependGElements", &GElement::addDependGElements,
4242
py::arg("elements"))
4343
.def("setLoop", &GElement::setLoop);
4444

45-
py::class_<GNode, GNodePyw, GElement, std::unique_ptr<GNode, py::nodelete> >(m, "GNode")
45+
py::class_<GNode, PywGNode, GElement, std::unique_ptr<GNode, py::nodelete> >(m, "GNode")
4646
.def(py::init<>());
4747

48-
py::class_<GRegionPy, GElement, std::unique_ptr<GRegionPy, py::nodelete> >(m, "GRegion")
48+
py::class_<PyGCluster, GElement, std::unique_ptr<PyGCluster, py::nodelete> >(m, "GCluster")
4949
.def(py::init<>())
50-
.def("addGElement", &GRegionPy::addGElement,
50+
.def("addGElement", &PyGCluster::addGElement,
5151
py::arg("element"));
5252

53-
py::class_<GConditionPyw, GElement, std::unique_ptr<GConditionPyw, py::nodelete> >(m, "GCondition")
53+
py::class_<PyGRegion, GElement, std::unique_ptr<PyGRegion, py::nodelete> >(m, "GRegion")
5454
.def(py::init<>())
55-
.def("addGElement", &GConditionPyw::addGElement,
55+
.def("addGElement", &PyGRegion::addGElement,
5656
py::arg("element"));
5757

58-
py::class_<GMultiConditionPy<CGraph::GMultiConditionType::SERIAL>, GElement>(m, "GSerialMultiCondition")
58+
py::class_<PywGCondition, GElement, std::unique_ptr<PywGCondition, py::nodelete> >(m, "GCondition")
5959
.def(py::init<>())
60-
.def("addGElement", &GMultiConditionPy<CGraph::GMultiConditionType::SERIAL>::addGElement);
60+
.def("addGElement", &PywGCondition::addGElement,
61+
py::arg("element"));
6162

62-
py::class_<GMultiConditionPy<CGraph::GMultiConditionType::PARALLEL>, GElement>(m, "GParallelMultiCondition")
63+
py::class_<PyGMultiCondition<CGraph::GMultiConditionType::SERIAL>, GElement>(m, "GSerialMultiCondition")
6364
.def(py::init<>())
64-
.def("addGElement", &GMultiConditionPy<CGraph::GMultiConditionType::PARALLEL>::addGElement);
65+
.def("addGElement", &PyGMultiCondition<CGraph::GMultiConditionType::SERIAL>::addGElement,
66+
py::arg("element"));
67+
68+
py::class_<PyGMultiCondition<CGraph::GMultiConditionType::PARALLEL>, GElement>(m, "GParallelMultiCondition")
69+
.def(py::init<>())
70+
.def("addGElement", &PyGMultiCondition<CGraph::GMultiConditionType::PARALLEL>::addGElement,
71+
py::arg("element"));
6572
}

python/wrapper/GConditionPyw.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

python/wrapper/GElementPyw.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

python/wrapper/GMultiConditionPy.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

python/wrapper/GRegionPy.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

python/wrapper/PyGCluster.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/***************************
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: PyGCluster.h
5+
@Time: 2025/1/30 21:52
6+
@Desc:
7+
***************************/
8+
9+
#ifndef CGRAPH_PYGCLUSTER_H
10+
#define CGRAPH_PYGCLUSTER_H
11+
12+
#include "CGraph.h"
13+
14+
class PyGCluster : public CGraph::GCluster {
15+
public:
16+
explicit PyGCluster() : CGraph::GCluster() {};
17+
~PyGCluster() override {};
18+
19+
CStatus addGElement(CGraph::GElementPtr element) {
20+
return addElement(element);
21+
}
22+
};
23+
24+
#endif //CGRAPH_PYGCLUSTER_H

python/wrapper/PyGMultiCondition.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/***************************
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: PyGMultiCondition.h
5+
@Time: 2025/1/30 21:40
6+
@Desc:
7+
***************************/
8+
9+
#ifndef CGRAPH_PYGMULTICONDITION_H
10+
#define CGRAPH_PYGMULTICONDITION_H
11+
12+
#include "CGraph.h"
13+
14+
template<CGraph::GMultiConditionType type>
15+
class PyGMultiCondition : public CGraph::GMultiCondition<type> {
16+
public:
17+
explicit PyGMultiCondition() : CGraph::GMultiCondition<type>() {};
18+
~PyGMultiCondition() override {};
19+
20+
CStatus addGElement(CGraph::GElementPtr element) {
21+
return CGraph::GMultiCondition<type>::addElement(element);
22+
}
23+
};
24+
25+
#endif //CGRAPH_PYGMULTICONDITION_H
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
#ifndef CGRAPH_GPIPELINE_PY_H
2-
#define CGRAPH_GPIPELINE_PY_H
1+
/***************************
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: PyGPipeline.h
5+
@Time: 2025/1/30 21:43
6+
@Desc:
7+
***************************/
8+
9+
#ifndef CGRAPH_PYGPIPELINE_H
10+
#define CGRAPH_PYGPIPELINE_H
311

412
#include "CGraph.h"
513

6-
class GPipelinePy : public CGraph::GPipeline {
14+
class PyGPipeline : public CGraph::GPipeline {
715
public:
8-
explicit GPipelinePy() : CGraph::GPipeline() {}
9-
~GPipelinePy() override {}
16+
explicit PyGPipeline() : CGraph::GPipeline() {}
17+
~PyGPipeline() override {}
1018

1119
CStatus registerGElement(CGraph::GElementPtr element,
1220
const CGraph::GElementPtrSet &depends = CGraph::GElementPtrSet{},
@@ -16,4 +24,4 @@ class GPipelinePy : public CGraph::GPipeline {
1624
}
1725
};
1826

19-
#endif // CGRAPH_GPIPELINE_PY_H
27+
#endif //CGRAPH_PYGPIPELINE_H

python/wrapper/PyGRegion.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/***************************
2+
@Author: Chunel
3+
@Contact: chunel@foxmail.com
4+
@File: PyGRegion.h
5+
@Time: 2025/1/30 21:44
6+
@Desc:
7+
***************************/
8+
9+
#ifndef CGRAPH_PYGREGION_H
10+
#define CGRAPH_PYGREGION_H
11+
12+
#include "CGraph.h"
13+
14+
class PyGRegion : public CGraph::GRegion {
15+
public:
16+
explicit PyGRegion() : CGraph::GRegion() {};
17+
~PyGRegion() override {};
18+
19+
CStatus addGElement(CGraph::GElementPtr element) {
20+
return addElement(element);
21+
}
22+
};
23+
24+
#endif //CGRAPH_PYGREGION_H

0 commit comments

Comments
 (0)