Skip to content

Commit c265991

Browse files
authored
Rename dsm to dsf and add Python support (#302)
* Init python binding * Change `dsm` to `dsf` * Auto-fetch for pybind11 * Typo * Missing files * Fix pylinting * Pylint * Pylint bastaaaa * Rename extension * Add nlanes to exportEdges functioN * Bugfix * Add functions to binding * Add debug msgs * Verbose log * Comments * Fix tests * Add agents tests * Add instructions
1 parent 4fab95e commit c265991

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1071
-459
lines changed

.github/workflows/cmake_install.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ jobs:
2727
working-directory: ${{github.workspace}}
2828
run: |
2929
touch test.cpp
30-
echo "#include <dsm/dsm.hpp>" >> test.cpp
30+
echo "#include <dsf/dsf.hpp>" >> test.cpp
3131
echo "int main() {}" >> test.cpp
32-
g++ test.cpp -std=c++20 && echo "Compiled successfully" || echo "Cannot include dsm"
32+
g++ test.cpp -std=c++20 && echo "Compiled successfully" || echo "Cannot include dsf"

.github/workflows/cmake_install_macos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
working-directory: ${{github.workspace}}
3535
run: |
3636
touch test.cpp
37-
echo "#include <dsm/dsm.hpp>" >> test.cpp
37+
echo "#include <dsf/dsf.hpp>" >> test.cpp
3838
echo "int main() {}" >> test.cpp
3939
g++ test.cpp -std=c++20 -I$(brew --prefix tbb)/include -L$(brew --prefix tbb)/lib -ltbb \
4040
&& echo "Compiled successfully" \
41-
|| (echo "Cannot include dsm" ; exit 1)
41+
|| (echo "Cannot include dsf" ; exit 1)

.github/workflows/cmake_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Run tests
3535
working-directory: ${{github.workspace}}/test
36-
run: ./dsm_tests.out
36+
run: ./dsf_tests.out
3737

3838
- name: create Report
3939
working-directory: ${{github.workspace}}/test

.github/workflows/cmake_test_macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727

2828
- name: Run tests
2929
working-directory: ${{github.workspace}}/test
30-
run: ./dsm_tests.out
30+
run: ./dsf_tests.out

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ images
3838
examples/debug
3939
examples/release
4040

41-
test/data/*dsm
41+
test/data/*dsf
4242

4343

4444
webapp/data/*
45+
*egg-info*

CMakeLists.txt

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
cmake_minimum_required(VERSION 3.16.0)
22

3-
project(dms VERSION 2.5.8 LANGUAGES CXX)
3+
# Read version from header file
4+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/dsf/dsf.hpp" DSF_HPP_CONTENT)
5+
string(REGEX MATCH "DSF_VERSION_MAJOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
6+
set(DSF_VERSION_MAJOR ${CMAKE_MATCH_1})
7+
string(REGEX MATCH "DSF_VERSION_MINOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
8+
set(DSF_VERSION_MINOR ${CMAKE_MATCH_1})
9+
string(REGEX MATCH "DSF_VERSION_PATCH = ([0-9]+)" _ ${DSF_HPP_CONTENT})
10+
set(DSF_VERSION_PATCH ${CMAKE_MATCH_1})
11+
12+
set(DSF_VERSION "${DSF_VERSION_MAJOR}.${DSF_VERSION_MINOR}.${DSF_VERSION_PATCH}")
13+
14+
project(dsf VERSION ${DSF_VERSION} LANGUAGES CXX)
415

516
# Set the C++ standard
617
set(CMAKE_CXX_STANDARD 20)
@@ -14,16 +25,16 @@ endif()
1425

1526
find_package(TBB REQUIRED CONFIG)
1627

17-
file(GLOB SOURCES "src/dsm/sources/*.cpp" "src/dsm/utility/*.cpp")
28+
file(GLOB SOURCES "src/dsf/sources/*.cpp" "src/dsf/utility/*.cpp")
1829

19-
add_library(dsm STATIC ${SOURCES})
20-
target_include_directories(dsm PUBLIC
30+
add_library(dsf STATIC ${SOURCES})
31+
target_include_directories(dsf PUBLIC
2132
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/headers>
2233
$<INSTALL_INTERFACE:include>
2334
)
24-
target_link_libraries(dsm PRIVATE TBB::tbb)
35+
target_link_libraries(dsf PRIVATE TBB::tbb)
2536

26-
install(TARGETS dsm
37+
install(TARGETS dsf
2738
EXPORT dsmConfig
2839
ARCHIVE DESTINATION lib
2940
LIBRARY DESTINATION lib
@@ -33,5 +44,40 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_PREFIX}
3344

3445
install(EXPORT dsmConfig
3546
FILE dsmConfig.cmake
36-
NAMESPACE dsm::
37-
DESTINATION lib/cmake/dsm)
47+
NAMESPACE dsf::
48+
DESTINATION lib/cmake/dsf)
49+
50+
# Optional Python bindings - only build if requested
51+
option(BUILD_PYTHON_BINDINGS "Build Python bindings" OFF)
52+
53+
if(BUILD_PYTHON_BINDINGS)
54+
include(FetchContent)
55+
56+
# Get pybind11
57+
FetchContent_Declare(pybind11
58+
GIT_REPOSITORY https://github.com/pybind/pybind11.git
59+
GIT_TAG v2.13.6
60+
)
61+
FetchContent_GetProperties(pybind11)
62+
if(NOT pybind11_POPULATED)
63+
FetchContent_MakeAvailable(pybind11)
64+
endif()
65+
66+
# Add the Python binding module
67+
add_library(dsf_python_module MODULE src/dsf/binding.cpp)
68+
69+
# Ensure the Python module name has no 'lib' prefix on Unix systems
70+
set_target_properties(dsf_python_module PROPERTIES
71+
PREFIX ""
72+
OUTPUT_NAME "dsf"
73+
)
74+
75+
# Link the pybind11 module with your static library and pybind11
76+
target_link_libraries(dsf_python_module PRIVATE dsf pybind11::module pybind11::headers)
77+
78+
# Set include directories (if binding.cpp needs headers from your project)
79+
target_include_directories(dsf_python_module PRIVATE
80+
${CMAKE_CURRENT_SOURCE_DIR}/src/headers
81+
)
82+
endif()
83+

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ WARN_LOGFILE =
943943
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
944944
# Note: If this tag is empty the current directory is searched.
945945

946-
INPUT = ./src/dsm/headers
946+
INPUT = ./src/dsf/headers
947947

948948
# This tag can be used to specify the character encoding of the source files
949949
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ cmake --build build
4848
cmake --install build
4949
```
5050

51+
## Installation via Pybind11
52+
If you want to use the library from Python, you can build the Python bindings using [pybind11](https://github.com/pybind/pybind11). Make sure you have Python and pybind11 installed:
53+
```shell
54+
pip install pybind11
55+
```
56+
57+
Then, the installation is automatic via `pip`:
58+
```shell
59+
pip install .
60+
```
61+
62+
After installation, you should be able to import the module in Python:
63+
```python
64+
import dsf
65+
```
66+
67+
If you encounter issues, ensure that the installation path is in your `PYTHONPATH` environment variable.
68+
5169
## Testing
5270
This project uses [Doctest](https://github.com/doctest/doctest) for testing.
5371

@@ -58,7 +76,7 @@ cmake -B build && make -C build
5876
```
5977
To run all the tests together use the command:
6078
```shell
61-
./dsm_tests.out
79+
./dsf_tests.out
6280
```
6381

6482
## Benchmarking

benchmark/Adj/BenchAdj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "SparseMatrix.hpp"
77
#include "Bench.hpp"
88

9-
using namespace dsm;
9+
using namespace dsf;
1010

1111
using Bench = sb::Bench<long long int>;
1212

benchmark/Adj/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O3")
1313
# Set the folder for the executable
1414
set(EXECUTABLE_OUTPUT_PATH ../../)
1515

16-
include_directories(../../src/dsm/headers)
17-
include_directories(../../src/dsm/utility/)
16+
include_directories(../../src/dsf/headers)
17+
include_directories(../../src/dsf/utility/)
1818

19-
file(GLOB SOURCES "../../src/dsm/sources/*.cpp" "../../src/dsm/utility/*.cpp")
19+
file(GLOB SOURCES "../../src/dsf/sources/*.cpp" "../../src/dsf/utility/*.cpp")
2020

2121
# Compile
2222
add_executable(bench_adj.out BenchAdj.cpp ${SOURCES})

0 commit comments

Comments
 (0)