Skip to content

Commit a216ce8

Browse files
Merge pull request #12 from ilias-karimalis/main
Scikit-Learn compatible rewrite
2 parents 5ce5035 + afa39bd commit a216ce8

File tree

159 files changed

+10980
-54337
lines changed

Some content is hidden

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

159 files changed

+10980
-54337
lines changed

.github/workflows/main.yml

+73-234
Large diffs are not rendered by default.

.gitignore

+157-33
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,163 @@
1-
# Python Ignores
2-
notebooks/.ipynb_checkpoints/*
3-
*.pyc
4-
*.pyo
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
55

6-
# Build Objects
7-
*.o
8-
*.tmp
6+
# C extensions
7+
*.so
98

10-
gosdt_test
11-
12-
# Autobuild Ignores
9+
# Distribution / packaging
10+
wheelhouse/
11+
.Python
12+
pyproject-build/
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
share/python-wheels/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
1329
MANIFEST
14-
Makefile
15-
config.log
16-
config.status
17-
autom4te.cache/*
18-
aclocal.m4
19-
m4
20-
libtool
21-
.deps
22-
gosdt_test
23-
bin
24-
.scon*
25-
.DS_Store
2630

27-
## Xcode User settings
28-
xcuserdata/
31+
# PyInstaller
32+
# Usually these files are written by a python script from a template
33+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
34+
*.manifest
35+
*.spec
36+
37+
# Installer logs
38+
pip-log.txt
39+
pip-delete-this-directory.txt
40+
41+
# Unit test / coverage reports
42+
htmlcov/
43+
.tox/
44+
.nox/
45+
.coverage
46+
.coverage.*
47+
.cache
48+
nosetests.xml
49+
coverage.xml
50+
*.cover
51+
*.py,cover
52+
.hypothesis/
53+
.pytest_cache/
54+
cover/
55+
56+
# Translations
57+
*.mo
58+
*.pot
59+
60+
# Django stuff:
61+
*.log
62+
local_settings.py
63+
db.sqlite3
64+
db.sqlite3-journal
65+
66+
# Flask stuff:
67+
instance/
68+
.webassets-cache
69+
70+
# Scrapy stuff:
71+
.scrapy
72+
73+
# Sphinx documentation
74+
docs/_build/
75+
76+
# PyBuilder
77+
.pybuilder/
78+
target/
79+
80+
# Jupyter Notebook
81+
.ipynb_checkpoints
82+
83+
# IPython
84+
profile_default/
85+
ipython_config.py
86+
87+
# pyenv
88+
# For a library or package, you might want to ignore these files since the code is
89+
# intended to run in multiple environments; otherwise, check them in:
90+
# .python-version
91+
92+
# pipenv
93+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
95+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
96+
# install all needed dependencies.
97+
#Pipfile.lock
98+
99+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
100+
__pypackages__/
29101

30-
.idea/
102+
# Celery stuff
103+
celerybeat-schedule
104+
celerybeat.pid
105+
106+
# SageMath parsed files
107+
*.sage.py
108+
109+
# Environments
110+
.env
111+
.venv
112+
env/
113+
venv/
114+
ENV/
115+
env.bak/
116+
venv.bak/
117+
118+
# Spyder project settings
119+
.spyderproject
120+
.spyproject
121+
122+
# Rope project settings
123+
.ropeproject
124+
125+
# mkdocs documentation
126+
/site
127+
128+
# mypy
129+
.mypy_cache/
130+
.dmypy.json
131+
dmypy.json
132+
133+
# Pyre type checker
134+
.pyre/
135+
136+
# pytype static type analyzer
137+
.pytype/
138+
139+
# Cython debug symbols
140+
cython_debug/
141+
142+
# setuptools_scm
143+
src/*/_version.py
144+
145+
146+
# ruff
147+
.ruff_cache/
148+
149+
# OS specific stuff
31150
.DS_Store
32-
._DS_Store
33-
__private/
34-
cmake*/
35-
_skbuild/
36-
dist/
37-
wheelhouse/
38-
*.egg-info/
39-
/gosdt.xcodeproj/xcuserdata/
151+
.DS_Store?
152+
._*
153+
.Spotlight-V100
154+
.Trashes
155+
ehthumbs.db
156+
Thumbs.db
157+
158+
# Common editor files
159+
*~
160+
*.swp
161+
162+
# Cmake files
163+
compile_commands.json

CMakeLists.txt

+55-90
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,73 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.15...3.27)
2+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
23

3-
# Project `Name` and `Language`
4-
project(GOSDT)
4+
set(CMAKE_CXX_STANDARD 20)
55

6-
# Set the language standard to `c++11`
7-
set(CMAKE_CXX_STANDARD 11)
6+
set(TARGET "_libgosdt")
7+
set(CLI_TARGET "gosdt_cli")
88

9-
# Set the compiler flags
10-
if (MSVC)
11-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
12-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /DDEBUG")
13-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
9+
message(STATUS "PATH environment variable: $ENV{PATH}")
10+
message(STATUS "LD_LIBRARY_PATH environment variable: $ENV{LD_LIBRARY_PATH}")
1411

15-
# `#define NOMINMAX` prevents expansion of min and max macros on Windows,
16-
# otherwise `std::numeric_limits<T>::max()/min()` leads to MSVC compiler errors.
17-
# Reference: https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax
18-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /w /DNOMINMAX")
19-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DDEBUG")
20-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
21-
else()
22-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
23-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -DDEBUG")
24-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
12+
# Python Target
13+
if (SKBUILD)
14+
# Find the module development requirements (requires FindPython from 3.17 or
15+
# scikit-build-core's built-in backport)
16+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
17+
find_package(pybind11 CONFIG REQUIRED)
2518

26-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
27-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -DDEBUG")
28-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
29-
endif()
19+
# Python Target
20+
file(GLOB_RECURSE SOURCE_FILES src/libgosdt/src/*.cpp src/libgosdt.cpp)
21+
python_add_library(${TARGET} MODULE ${SOURCE_FILES} WITH_SOABI)
22+
target_link_libraries(${TARGET} PRIVATE pybind11::module)
23+
target_include_directories(${TARGET} PUBLIC src/libgosdt/include/)
24+
install(TARGETS ${TARGET} DESTINATION ${SKBUILD_PROJECT_NAME})
3025

31-
#
32-
# MARK: - Targets
33-
#
26+
# In the case where wer're running on Windows with packages installed via vcpkg, we include
27+
# the vcpkg.cmake file to find the packages.
28+
if (WIN32)
29+
include($ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake)
30+
endif()
3431

35-
# Target Definition
36-
set(TARGET_CLI "gosdt")
37-
set(TARGET_TESTS "gosdt_tests")
38-
set(TARGET_PYTHON "libgosdt")
39-
40-
# Target: GOSDT CLI
41-
file(GLOB_RECURSE SOURCE_FILES_CLI src/*.cpp)
42-
list(REMOVE_ITEM SOURCE_FILES_CLI "${CMAKE_SOURCE_DIR}/src/python_extension.cpp")
43-
add_executable(${TARGET_CLI} ${SOURCE_FILES_CLI})
44-
target_include_directories(${TARGET_CLI} PUBLIC ${CMAKE_SOURCE_DIR}/include)
32+
endif()
4533

46-
# Target: GOSDT Tests
47-
file(GLOB_RECURSE SOURCE_FILES_TESTS src/*.cpp)
48-
list(REMOVE_ITEM SOURCE_FILES_TESTS "${CMAKE_SOURCE_DIR}/src/python_extension.cpp")
49-
list(REMOVE_ITEM SOURCE_FILES_TESTS "${CMAKE_SOURCE_DIR}/src/main.cpp")
50-
list(INSERT SOURCE_FILES_TESTS 0 "${CMAKE_SOURCE_DIR}/test/test.cpp")
51-
add_executable(${TARGET_TESTS} ${SOURCE_FILES_TESTS})
52-
target_include_directories(${TARGET_TESTS} PUBLIC ${CMAKE_SOURCE_DIR}/include)
34+
# CLI Target
35+
file(GLOB_RECURSE SOURCE_FILES src/libgosdt/src/*.cpp src/cli.cpp)
36+
add_executable(${CLI_TARGET} ${SOURCE_FILES})
37+
target_include_directories(${CLI_TARGET} PUBLIC src/libgosdt/include/)
5338

5439
#
55-
# MARK: - Dependencies
40+
# Link all needed dependencies to this project:
5641
#
42+
find_package(PkgConfig REQUIRED)
43+
include(FetchContent)
5744

58-
# Dependencies: Intel TBB
45+
# TBB:
5946
find_package(TBB REQUIRED)
60-
target_link_libraries(${TARGET_CLI} PRIVATE TBB::tbb)
61-
target_link_libraries(${TARGET_CLI} PRIVATE TBB::tbbmalloc)
62-
target_link_libraries(${TARGET_TESTS} PRIVATE TBB::tbb)
63-
target_link_libraries(${TARGET_TESTS} PRIVATE TBB::tbbmalloc)
47+
if (SKBUILD)
48+
target_link_libraries(${TARGET} PRIVATE TBB::tbb)
49+
target_link_libraries(${TARGET} PRIVATE TBB::tbbmalloc)
50+
endif()
51+
target_link_libraries(${CLI_TARGET} PRIVATE TBB::tbb TBB::tbbmalloc)
6452

65-
# Dependencies: GMP
66-
find_package(PkgConfig REQUIRED)
53+
# GMP:
6754
pkg_check_modules(GMP REQUIRED IMPORTED_TARGET gmp)
68-
target_link_libraries(${TARGET_CLI} PRIVATE PkgConfig::GMP)
69-
target_include_directories(${TARGET_CLI} PRIVATE ${GMP_INCLUDE_DIRS})
70-
target_link_libraries(${TARGET_TESTS} PRIVATE PkgConfig::GMP)
71-
target_include_directories(${TARGET_TESTS} PRIVATE ${GMP_INCLUDE_DIRS})
72-
73-
# Dependencies: Threads (pthread on macOS and Ubuntu, win32 thread on Windows)
74-
# This is needed because the CentOS docker provided by manylinux reports linker errors
75-
set(THREADS_PREFER_PTHREAD_FLAG ON)
76-
find_package(Threads REQUIRED)
77-
target_link_libraries(${TARGET_CLI} PRIVATE Threads::Threads)
78-
target_link_libraries(${TARGET_TESTS} PRIVATE Threads::Threads)
55+
if (SKBUILD)
56+
target_link_libraries(${TARGET} PRIVATE PkgConfig::GMP)
57+
target_include_directories(${TARGET} PRIVATE ${GMP_INCLUDE_DIRS})
58+
endif()
59+
target_link_libraries(${CLI_TARGET} PRIVATE PkgConfig::GMP)
60+
target_include_directories(${CLI_TARGET} PRIVATE ${GMP_INCLUDE_DIRS})
7961

80-
# Target: GOSDT Python Module
62+
# nlohmann::json:
63+
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
64+
FetchContent_MakeAvailable(json)
8165
if (SKBUILD)
82-
message(STATUS "GOSDT is built using scikit-build. Will build the Python module.")
83-
# Find the Python 3 development environment
84-
if (NOT DEFINED Python3_INCLUDE_DIR)
85-
message(FATAL_ERROR "The CMake variable Python3_INCLUDE_DIR should have been defined by scikit-build.")
86-
endif()
87-
# Create the list of source files needed to build the Python extension
88-
file(GLOB_RECURSE SOURCE_FILES_PY src/*.cpp)
89-
list(REMOVE_ITEM SOURCE_FILES_PY "${CMAKE_SOURCE_DIR}/src/main.cpp")
90-
# Define the CMake target for the Python extension
91-
add_library(${TARGET_PYTHON} MODULE ${SOURCE_FILES_PY})
92-
target_include_directories(${TARGET_PYTHON} PRIVATE ${CMAKE_SOURCE_DIR}/include ${Python3_INCLUDE_DIR} ${GMP_INCLUDE_DIRS})
93-
target_link_libraries(${TARGET_PYTHON} TBB::tbb TBB::tbbmalloc PkgConfig::GMP Threads::Threads)
94-
# Set up the Python extension
95-
find_package(PythonExtensions REQUIRED)
96-
## Use the suffix `.abi3.so` or `.pyd` so that Python 3 on other platforms can find the dylib and import it properly
97-
message(STATUS "The current Python extension suffix is \"${PYTHON_EXTENSION_MODULE_SUFFIX}\".")
98-
if (WIN32)
99-
set(PYTHON_EXTENSION_MODULE_SUFFIX ".pyd")
100-
else()
101-
set(PYTHON_EXTENSION_MODULE_SUFFIX ".abi3.so")
102-
endif()
103-
message(STATUS "The new Python extension suffix is \"${PYTHON_EXTENSION_MODULE_SUFFIX}\".")
104-
## Define the Python extension module target
105-
python_extension_module(${TARGET_PYTHON})
106-
# Install `libgosdt` to the root directory of the Python extension package
107-
install(TARGETS ${TARGET_PYTHON} LIBRARY DESTINATION .)
66+
target_link_libraries(${TARGET} PRIVATE nlohmann_json::nlohmann_json)
10867
endif()
68+
target_link_libraries(${CLI_TARGET} PRIVATE nlohmann_json::nlohmann_json)
69+
70+
# Generate compile_commands.json for vscode
71+
set(CMAKE_EXPORT_COMPILE_COMMANDS
72+
ON
73+
CACHE INTERNAL "")

LICENSE

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2021, 2022 Chudi Zhong, Hayden McTavish, Jimmy Lin, Margo Seltzer,
4-
Cynthia Rudin, The University of British Columbia, Duke University
3+
Copyright (c) 2021, 2022, 2024, Chudi Zhong, Hayden McTavish, Jimmy Lin, Ilias Karimalis,
4+
Margo Seltzer, Cynthia Rudin, The University of British Columbia, Duke University
55
All rights reserved.
66

77
Redistribution and use in source and binary forms, with or without
88
modification, are permitted provided that the following conditions are met:
99

10-
1. Redistributions of source code must retain the above copyright notice, this
11-
list of conditions and the following disclaimer.
10+
* Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
1212

13-
2. Redistributions in binary form must reproduce the above copyright notice,
14-
this list of conditions and the following disclaimer in the documentation
15-
and/or other materials provided with the distribution.
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
1616

17-
3. Neither the name of the copyright holder nor the names of its
18-
contributors may be used to endorse or promote products derived from
19-
this software without specific prior written permission.
17+
* Neither the name of the copyright holder nor the names of its
18+
contributors may be used to endorse or promote products derived from
19+
this software without specific prior written permission.
2020

2121
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2222
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

0 commit comments

Comments
 (0)