kunaldahiya / pyxclib

Tools for multi-label classification problems.
MIT License
126 stars 36 forks source link

Fix compilation error with latest NumPy versions #39

Closed nasib-ullah closed 3 weeks ago

nasib-ullah commented 3 weeks ago

When trying to install pyxclib using pip with latest NumPy version, the following error occurs during compilation:

Error compiling Cython file:
...
cdef np.ndarray[np.int_t, ndim=1] rank = _np.empty(data.size, dtype='int')
^
xclib/utils/_sparse.pyx:197:23: Invalid type.

This error seems to be caused by the use of np.int_t, which is no longer supported in newer NumPy versions.

Environment details:

Proposed solution: Replace np.int_t with np.intp_t in the affected files, particularly in xclib/utils/_sparse.pyx. This should resolve the compilation issue while maintaining compatibility across different platforms.

Steps to reproduce:

  1. Set up a Python environment with NumPy 2.1.2
  2. Run pip install git+https://github.com/kunaldahiya/pyxclib
  3. Observe the compilation error

Please review the changes and let me know if any further modifications are needed.

kunaldahiya commented 3 weeks ago

Thanks for pointing this out. This looks the right way to go. However, there seems to be mismatch in precision - one the left side it is 32 bit precision (with np.int32_t) and 64 bit on the right side (with 'int'). We can possibly make the indices 64 bits on both sides?

nasib-ullah commented 3 weeks ago

You're absolutely right about the precision mismatch. I've updated the code to use np.int64_t and dtype=np.int64 to ensure that the indices are 64-bit integers on both sides. Thanks

kunaldahiya commented 3 weeks ago

Thanks! Merged.