Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid type error compiling cluster.pyx with Cython #15

Open
cloudbroken opened this issue Sep 7, 2024 · 1 comment
Open

Invalid type error compiling cluster.pyx with Cython #15

cloudbroken opened this issue Sep 7, 2024 · 1 comment

Comments

@cloudbroken
Copy link

Thank you for making this interesting tool.
I tried installing it with Cython, but was getting type errors compiling cluster.pyx.
Let me disclaim that I am a python novice, and may therefore be making some kind of obvious mistake.

Error compiling Cython file:
------------------------------------------------------------
...

            delta_LL[i, j] = delta
            delta_LL[j, i] = delta

    # array of cluster label
    cdef np.ndarray[np.int_t, ndim = 1] clusters = np.arange(clst.N_boxes)
                       ^
------------------------------------------------------------

cellstates/cluster.pyx:365:23: Invalid type.
Error compiling Cython file:
------------------------------------------------------------
...
    cells are optimally placed.
    """

    cdef:
        int cell, c_best, move_count = 0
        np.ndarray[np.int_t, ndim = 1] cell_iter
                      ^
------------------------------------------------------------

cellstates/cluster.pyx:430:22: Invalid type.
Error compiling Cython file:
------------------------------------------------------------
...
            if np.any(mask):
                l = l[mask]
                d = d[mask, :]

        self.LAMBDA = <np.ndarray[np.float_t, ndim = 1]> l
        self.data = <np.ndarray[np.int_t, ndim = 2]?> d
                                   ^
------------------------------------------------------------

cellstates/cluster.pyx:539:35: Invalid type.

The compilation problem was resolved by explicitly declaring the array type as np.int64_t as follows:

Line 365: cdef np.ndarray[np.int64_t, ndim=1] clusters = np.arange(clst.N_boxes, dtype=np.int64)
Line 430: np.ndarray[np.int64_t, ndim = 1] cell_iter
LIne 539: self.data = <np.ndarray[np.int64_t, ndim = 2]?> d

Environment

_libgcc_mutex             0.1                        main
_openmp_mutex             5.1                       1_gnu
bzip2                     1.0.8                h5eee18b_6
ca-certificates           2024.7.2             h06a4308_0
cellstates                0.1                      pypi_0    pypi
contourpy                 1.3.0                    pypi_0    pypi
cycler                    0.12.1                   pypi_0    pypi
cython                    3.0.11                   pypi_0    pypi
expat                     2.6.3                h6a678d5_0
fonttools                 4.53.1                   pypi_0    pypi
kiwisolver                1.4.7                    pypi_0    pypi
ld_impl_linux-64          2.38                 h1181459_1
libffi                    3.4.4                h6a678d5_1
libgcc-ng                 11.2.0               h1234567_1
libgomp                   11.2.0               h1234567_1
libstdcxx-ng              11.2.0               h1234567_1
libuuid                   1.41.5               h5eee18b_0
matplotlib                3.9.2                    pypi_0    pypi
ncurses                   6.4                  h6a678d5_0
numpy                     2.1.1                    pypi_0    pypi
openssl                   3.0.15               h5eee18b_0
packaging                 24.1                     pypi_0    pypi
pandas                    2.2.2                    pypi_0    pypi
pillow                    10.4.0                   pypi_0    pypi
pip                       24.2                     pypi_0    pypi
pyparsing                 3.1.4                    pypi_0    pypi
python                    3.12.4               h5148396_1
python-dateutil           2.9.0.post0              pypi_0    pypi
pytz                      2024.1                   pypi_0    pypi
readline                  8.2                  h5eee18b_0
scipy                     1.14.1                   pypi_0    pypi
setuptools                72.1.0                   pypi_0    pypi
six                       1.16.0                   pypi_0    pypi
sqlite                    3.45.3               h5eee18b_0
tk                        8.6.14               h39e8969_0
tzdata                    2024.1                   pypi_0    pypi
wheel                     0.43.0                   pypi_0    pypi
xz                        5.4.6                h5eee18b_1
zlib                      1.2.13               h5eee18b_1```
@Biomiha
Copy link

Biomiha commented Sep 10, 2024

This also worked for me. Much appreciated, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants