From c456d0d00c73c449804f2ac1efb01cfd5ce74ab4 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:01:15 -0400 Subject: [PATCH 01/19] Update setup.py using skbuild.setup() --- setup.py | 75 +++++++++++--------------------------------------------- 1 file changed, 14 insertions(+), 61 deletions(-) diff --git a/setup.py b/setup.py index 7a01142..02a485f 100644 --- a/setup.py +++ b/setup.py @@ -1,65 +1,18 @@ -from __future__ import print_function -import os.path -import sys -import setuptools -from numpy.distutils.core import setup - - -try: - import numpy -except ImportError: - print('numpy is required during installation') - sys.exit(1) - - +from skbuild import setup DISTNAME = 'soft-dtw' DESCRIPTION = "Python implementation of soft-DTW" -LONG_DESCRIPTION = open('README.rst').read() -MAINTAINER = 'Mathieu Blondel' -MAINTAINER_EMAIL = '' -URL = 'https://github.com/mblondel/soft-dtw/' +MAINTAINER = 'Mathieu Blondel,Cesar Rodas' +MAINTAINER_EMAIL = 'cesar_rodas@outlook.com' LICENSE = 'Simplified BSD' -DOWNLOAD_URL = 'https://github.com/mblondel/soft-dtw/' +PACKAGES=['sdtw'] VERSION = '0.1.dev0' - - -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - - config = Configuration(None, parent_package, top_path) - - config.add_subpackage('sdtw') - - return config - - -if __name__ == '__main__': - old_path = os.getcwd() - local_path = os.path.dirname(os.path.abspath(sys.argv[0])) - - os.chdir(local_path) - sys.path.insert(0, local_path) - - setup(configuration=configuration, - name=DISTNAME, - maintainer=MAINTAINER, - include_package_data=True, - maintainer_email=MAINTAINER_EMAIL, - description=DESCRIPTION, - license=LICENSE, - url=URL, - version=VERSION, - download_url=DOWNLOAD_URL, - long_description=LONG_DESCRIPTION, - zip_safe=False, # the package can run out of an .egg file - classifiers=[ - 'Intended Audience :: Science/Research', - 'Intended Audience :: Developers', 'License :: OSI Approved', - 'Programming Language :: C', 'Programming Language :: Python', - 'Topic :: Software Development', - 'Topic :: Scientific/Engineering', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', 'Operating System :: Unix', - 'Operating System :: MacOS' - ] - ) +setup( + configuration=configuration, + name=DISTNAME, + version=VERSION, + description=DESCRIPTION, + author=MANTAINER, + license=LICENSE, + packages=PACKAGES, + python_requires=">=3.7", + ) From e32083ccbe5d2c62bf59c9528d6f02416926370e Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:01:43 -0400 Subject: [PATCH 02/19] Create CMakeLists.txt --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1 @@ + From b403e3b489e23dd7616b161c1dff54f3a9e76c3f Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:18:05 -0400 Subject: [PATCH 03/19] Update CMakeLists.txt --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b13789..bdd4455 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1 +1,9 @@ +cmake_minimum_required(VERSION 3.18...3.22) +project(sdtw) + +find_package(PythonExtensions REQUIRED) + +add_library(sdtw MODULE sdtw/fast_soft_sdtw.pyx) +python_extension_module(sdtw) +install(TARGETS sdtw LIBRARY DESTINATION sdtw-lib) From e092494952c7c67fc939b0e0847311ff64a06e05 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:25:55 -0400 Subject: [PATCH 04/19] Update CMakeLists.txt --- CMakeLists.txt | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdd4455..b90c33e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,37 @@ -cmake_minimum_required(VERSION 3.18...3.22) +cmake_minimum_required(VERSION 3.0) project(sdtw) -find_package(PythonExtensions REQUIRED) +# Find Python and its libraries +find_package(Python3 COMPONENTS Interpreter Development) +find_package(Python3 REQUIRED) -add_library(sdtw MODULE sdtw/fast_soft_sdtw.pyx) -python_extension_module(sdtw) -install(TARGETS sdtw LIBRARY DESTINATION sdtw-lib) +# Find Cython +find_program(CYTHON_EXECUTABLE cython) +if(NOT CYTHON_EXECUTABLE) + message(FATAL_ERROR "Cython not found. Please install it.") +endif() + +# Add Cython source file +set(CYTHON_SOURCES sdtw/soft_dtw_fast.pyx) + +# Compile Cython source file to C++/C +set_source_files_properties(${CYTHON_SOURCES} PROPERTIES CYTHON_IS_CXX TRUE) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/soft_dtw_fast.cpp + COMMAND ${CYTHON_EXECUTABLE} --cplus -3 ${CMAKE_CURRENT_SOURCE_DIR}/sdtw/soft_dtw_fast.pyx -o ${CMAKE_CURRENT_BINARY_DIR}/soft_dtw_fast.cpp + DEPENDS ${CYTHON_SOURCES} +) + +# Add the compiled C++/C file to the project +set(CYTHON_CPP_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/soft_dtw_fast.cpp) + +# Include directories +include_directories(${Python3_INCLUDE_DIRS}) + +# Add the executable/library +add_library(my_module SHARED ${CYTHON_CPP_SOURCES}) +target_link_libraries(my_module ${Python3_LIBRARIES}) + +# Install target +install(TARGETS sdtw DESTINATION sdtw-lib) From 16280509d22eee30dc266f2a31de81c7e4c565db Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:26:19 -0400 Subject: [PATCH 05/19] Update CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b90c33e..6ca7f22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,8 @@ set(CYTHON_CPP_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/soft_dtw_fast.cpp) include_directories(${Python3_INCLUDE_DIRS}) # Add the executable/library -add_library(my_module SHARED ${CYTHON_CPP_SOURCES}) -target_link_libraries(my_module ${Python3_LIBRARIES}) +add_library(sdtw SHARED ${CYTHON_CPP_SOURCES}) +target_link_libraries(sdtw ${Python3_LIBRARIES}) # Install target install(TARGETS sdtw DESTINATION sdtw-lib) From 87916b0821b8379e73c910f143d9b5e2f396f4ad Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:27:39 -0400 Subject: [PATCH 06/19] Create pyproject.toml --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1 @@ + From 75677ec9f11ba551dc85976f344107f679222b17 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:29:11 -0400 Subject: [PATCH 07/19] Update pyproject.toml --- pyproject.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8b13789..1d4c476 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1 +1,7 @@ - +[build-system] +requires = [ + "setuptools>=42", + "scikit-build>=0.13", + "cmake>=3.18", +] +build-backend = "setuptools.build_meta" From 04e55b91052b1f28fa42fa367de3d91e16fbdb56 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:29:30 -0400 Subject: [PATCH 08/19] Update CMakeLists.txt --- CMakeLists.txt | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ca7f22..e359abb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,37 +1,8 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.15...3.26) project(sdtw) -# Find Python and its libraries -find_package(Python3 COMPONENTS Interpreter Development) -find_package(Python3 REQUIRED) +find_package(PythonExtensions REQUIRED) +find_package(Cython REQUIRED) -# Find Cython -find_program(CYTHON_EXECUTABLE cython) -if(NOT CYTHON_EXECUTABLE) - message(FATAL_ERROR "Cython not found. Please install it.") -endif() - -# Add Cython source file -set(CYTHON_SOURCES sdtw/soft_dtw_fast.pyx) - -# Compile Cython source file to C++/C -set_source_files_properties(${CYTHON_SOURCES} PROPERTIES CYTHON_IS_CXX TRUE) -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/soft_dtw_fast.cpp - COMMAND ${CYTHON_EXECUTABLE} --cplus -3 ${CMAKE_CURRENT_SOURCE_DIR}/sdtw/soft_dtw_fast.pyx -o ${CMAKE_CURRENT_BINARY_DIR}/soft_dtw_fast.cpp - DEPENDS ${CYTHON_SOURCES} -) - -# Add the compiled C++/C file to the project -set(CYTHON_CPP_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/soft_dtw_fast.cpp) - -# Include directories -include_directories(${Python3_INCLUDE_DIRS}) - -# Add the executable/library -add_library(sdtw SHARED ${CYTHON_CPP_SOURCES}) -target_link_libraries(sdtw ${Python3_LIBRARIES}) - -# Install target -install(TARGETS sdtw DESTINATION sdtw-lib) +add_subdirectory(sdtw) From b6f859f19efcbea8e939b8821f0b03a907462cda Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:30:42 -0400 Subject: [PATCH 09/19] Create CMakeLists.txt --- sdtw/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 sdtw/CMakeLists.txt diff --git a/sdtw/CMakeLists.txt b/sdtw/CMakeLists.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/sdtw/CMakeLists.txt @@ -0,0 +1 @@ + From 6604e5567e725041779d4727234d711d16dcda4f Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:33:08 -0400 Subject: [PATCH 10/19] Update CMakeLists.txt --- sdtw/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdtw/CMakeLists.txt b/sdtw/CMakeLists.txt index 8b13789..7e5d58c 100644 --- a/sdtw/CMakeLists.txt +++ b/sdtw/CMakeLists.txt @@ -1 +1,7 @@ + +add_cython_target(soft_dtw_fast CXX) +add_library(soft_dtw_fast MODULE ${soft_dtw_fast}) +python_extension_module(soft_dtw_fast) + +install(TARGETS soft_dtw_fast LIBRARY DESTINATION soft-dtw) From 9163aea4e49df4c22666ca43d630d7856b9c298d Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:43:02 -0400 Subject: [PATCH 11/19] Delete sdtw/setup.py --- sdtw/setup.py | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 sdtw/setup.py diff --git a/sdtw/setup.py b/sdtw/setup.py deleted file mode 100644 index c718096..0000000 --- a/sdtw/setup.py +++ /dev/null @@ -1,21 +0,0 @@ -import os.path - -import numpy - - -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - - config = Configuration('sdtw', parent_package, top_path) - - config.add_extension('soft_dtw_fast', sources=['soft_dtw_fast.c'], - include_dirs=[numpy.get_include()]) - - config.add_subpackage('tests') - - return config - - -if __name__ == '__main__': - from numpy.distutils.core import setup - setup(**configuration(top_path='').todict()) From c1b9a89eb180a1bd56d3f01d6820be47bbf71022 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:13:42 -0400 Subject: [PATCH 12/19] Update setup.py --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 02a485f..572b981 100644 --- a/setup.py +++ b/setup.py @@ -6,13 +6,14 @@ LICENSE = 'Simplified BSD' PACKAGES=['sdtw'] VERSION = '0.1.dev0' +CMAKE_INSTALL_DIR='sdtw' setup( - configuration=configuration, name=DISTNAME, version=VERSION, description=DESCRIPTION, - author=MANTAINER, + author=MAINTAINER, license=LICENSE, packages=PACKAGES, python_requires=">=3.7", + cmake_install_dir=CMAKE_INSTALL_DIR, ) From 9525973c15b7820ca6d754ca6862ff19e151ab77 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:14:06 -0400 Subject: [PATCH 13/19] Numpy support --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e359abb..3ae456b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,4 +5,12 @@ project(sdtw) find_package(PythonExtensions REQUIRED) find_package(Cython REQUIRED) +# Add NumPy include directory +execute_process( + COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy as np; print(np.get_include())" + OUTPUT_VARIABLE NUMPY_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) +include_directories(${NUMPY_INCLUDE_DIR}) + add_subdirectory(sdtw) From 5a831a1485e3f59968861ecd8b146731f7eb1eba Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:14:29 -0400 Subject: [PATCH 14/19] fix module name --- sdtw/CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sdtw/CMakeLists.txt b/sdtw/CMakeLists.txt index 7e5d58c..0c60e0e 100644 --- a/sdtw/CMakeLists.txt +++ b/sdtw/CMakeLists.txt @@ -1,7 +1,5 @@ - - -add_cython_target(soft_dtw_fast CXX) +add_cython_target(soft_dtw_fast soft_dtw_fast.pyx) add_library(soft_dtw_fast MODULE ${soft_dtw_fast}) python_extension_module(soft_dtw_fast) -install(TARGETS soft_dtw_fast LIBRARY DESTINATION soft-dtw) +install(TARGETS soft_dtw_fast LIBRARY DESTINATION sdtw) From 457b4f28bb498092d4cc29ac627dec62e45f9300 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:14:50 -0400 Subject: [PATCH 15/19] Numpy and ninja support --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 1d4c476..227ed0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,5 +3,8 @@ requires = [ "setuptools>=42", "scikit-build>=0.13", "cmake>=3.18", + "ninja", + "cython", + "numpy", ] build-backend = "setuptools.build_meta" From 57f842fad5e98311e163c5d02cbf67e1e2e4897e Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:19:31 -0400 Subject: [PATCH 16/19] Update install steps --- README.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.rst b/README.rst index b5a6a0e..e4f4802 100644 --- a/README.rst +++ b/README.rst @@ -84,9 +84,7 @@ or, if `git` is unavailable, `download as a ZIP from GitHub Date: Wed, 19 Jun 2024 13:22:40 -0400 Subject: [PATCH 17/19] Added: # cython: language_level=3str --- sdtw/soft_dtw_fast.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdtw/soft_dtw_fast.pyx b/sdtw/soft_dtw_fast.pyx index 854f2c4..27ced87 100644 --- a/sdtw/soft_dtw_fast.pyx +++ b/sdtw/soft_dtw_fast.pyx @@ -5,7 +5,7 @@ # cython: cdivision=True # cython: boundscheck=False # cython: wraparound=False - +# cython: language_level=3str import numpy as np cimport numpy as np np.import_array() From dd1cb8ea85782fc83484a01436ee1aae8edb8101 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:33:26 -0400 Subject: [PATCH 18/19] change DISTNAME to 'softdtw' --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 572b981..f8c6292 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ from skbuild import setup -DISTNAME = 'soft-dtw' +DISTNAME = 'softdtw' DESCRIPTION = "Python implementation of soft-DTW" MAINTAINER = 'Mathieu Blondel,Cesar Rodas' MAINTAINER_EMAIL = 'cesar_rodas@outlook.com' From bf41e476109f6d699cb8d78e3fc2825bf10b6767 Mon Sep 17 00:00:00 2001 From: Cesar Rodas <65242055+Care99@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:52:41 -0400 Subject: [PATCH 19/19] cmake_args=["-DCMAKE_BUILD_TYPE=Release"], --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index f8c6292..991c57f 100644 --- a/setup.py +++ b/setup.py @@ -16,4 +16,5 @@ packages=PACKAGES, python_requires=">=3.7", cmake_install_dir=CMAKE_INSTALL_DIR, + cmake_args=["-DCMAKE_BUILD_TYPE=Release"], # Adjust as needed )