slaypni / fastdtw

A Python implementation of FastDTW
MIT License
777 stars 121 forks source link

To use the cython extension with windows ... #7

Closed gitoops closed 5 years ago

gitoops commented 7 years ago

I had to do the following modifications:

  1. Install the msvc for python https://www.microsoft.com/en-us/download/details.aspx?id=44266
  2. Adjust the setup.py a) to not use stdlibc++, b) to use cythonize (from Cython.Build import cythonize and in kwargs change ext_module to 'ext_modules': cythonize(extensions), c) import numpy and add include_dirs=[numpy.get_include()], in extensions:
    
    from setuptools import setup, find_packages, Extension
    from Cython.Build import cythonize
    import os.path
    import warnings
    import numpy

classifiers = [ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: MIT License', 'Topic :: Scientific/Engineering' ]

extensions = [Extension( 'fastdtw._fastdtw', [os.path.join('fastdtw', "_fastdtw.pyx")], language="c++", include_dirs=[numpy.get_include()],

if you want to debug from MSVC IDE uncomment the following

extra_compile_args=["-Zi", "/Od"],

extra_link_args=["-debug"],

libraries=["stdc++","stdc"]

)]

kwargs = { 'name': 'fastdtw', 'version': '0.3.0', 'author': 'Kazuaki Tanida', 'url': 'https://github.com/slaypni/fastdtw', 'description': 'Dynamic Time Warping (DTW) algorithm with an O(N) time and memory complexity.', 'license': 'MIT', 'keywords': ['dtw'], 'install_requires': ['numpy'], 'packages': find_packages(), 'ext_modules': cythonize(extensions), 'test_suite': 'tests', 'setup_requires': ['pytest-runner'], 'tests_require': ['pytest'], 'classifiers': classifiers }

try: setup(kwargs) except SystemExit: del kwargs['ext_modules'] warnings.warn('compilation failed. Installing pure python package') setup(kwargs)


3. Modify the cpx to use the INFINITY definition from numpy: 

from libc.math cimport INFINITY,pow, fabs

from libc.math cimport pow, fabs from numpy.math cimport INFINITY



Thank you for your great work!

Jan
slaypni commented 7 years ago

@gitoops Thank you for pointing it out!

I made PR #8 which might solve this problem by fixing some of what you mentioned. Could you see it to find if it works?

gitoops commented 7 years ago

I tried but unfortunately it doesen't compile out of the box´, falls back to install the pure python version.

Additionally I found with the version I compiled for Windows deviations depending on order of vectors: fastdtw(A,B) different to fastdtw(B,A). I would expect it should be the same. The pure python gives the correct solution independent of the order A,B or B,A. The test was with vectors of length 120, y values betwen 0 and 1000. Do you see the same issue with linux? Any idea what the problem causes?

Kind regards Jan

gitoops commented 7 years ago

Okay, increasing the radius improved the precision and the distance A->B becomes B->A.

shuffle2 commented 6 years ago

Current master is still broken on windows/cython. The reason is that stdc++ library does not exist. The module seems to compile and work fine if just removing this library reference. @slaypni please do that (I would, but don't know the "correct way" to do it within setup.py :) )

slaypni commented 6 years ago

@shuffle2 I am also not good at writing setup.py.😭PR is welcome!

Seanny123 commented 5 years ago

Seems to be fixed on Windows 10. I think you can close this issue.

slaypni commented 5 years ago

@Seanny123 Thx!

shuffle2 commented 4 years ago

Well, it's not fixed (how would it be with no changes?). I still had to remove stdc++ reference from setup.py