CERN/TIGRE

File "tigre/utilities/cuda_interface/_Ax.pyx", line 91, in _Ax._Ax_ext TypeError: 'numpy.float32' object cannot be interpreted as an integer

tamish2 opened this issue ยท 38 comments

When running the d03_generateData.py or any of the demos I am getting a TypeError and I am unsure what the cause of this is

Actual Behavior

Traceback (most recent call last):
File "/home-local/usr/TIGRE/Python/demos/d03_generateData.py", line 39, in
projections = tigre.Ax(head, geo, angles)
File "/home-local/usr/.local/lib/python3.10/site-packages/pytigre-2.4.0-py3.10-linux-x86_64.egg/tigre/utilities/Ax.py", line 35, in Ax
return _Ax_ext(img, geox, geox.angles, projection_type, geox.mode, gpuids=gpuids)
File "tigre/utilities/cuda_interface/_Ax.pyx", line 91, in _Ax._Ax_ext
TypeError: 'numpy.float32' object cannot be interpreted as an integer
(base) :~/TIGRE/Python/demos$ python d03_generateData.py
Traceback (most recent call last):
File "/home-local/usr/TIGRE/Python/demos/d03_generateData.py", line 39, in
projections = tigre.Ax(head, geo, angles)
File "/home-local/usr/.local/lib/python3.10/site-packages/pytigre-2.4.0-py3.10-linux-x86_64.egg/tigre/utilities/Ax.py", line 35, in Ax
return _Ax_ext(img, geox, geox.angles, projection_type, geox.mode, gpuids=gpuids)
File "tigre/utilities/cuda_interface/_Ax.pyx", line 91, in _Ax._Ax_ext
TypeError: 'numpy.float32' object cannot be interpreted as an integer

Code to reproduce the problem (If applicable)

python d03_generateData.py

Specifications

  • MATLAB/python version: Python 3.10.9
  • OS: Ubuntu (Ubuntu 22.04.2)
  • CUDA version: 11.5

Hi @tamish2

Did you just dowload/compile TIGRE recently? Aparently Cython 3.0.0 just released and it may be messing with the code #472 #471

Yeah that resolved an earlier issue I had just like #472 but I am running into this even with the older Cython version

Hum, strange.... Can you tell me exactly which ctyhon version you are using, so I can compare with mine/test?

0.29.35

I am also encoutering exactly the same problem, have you found a solution? @tamish2

I am fairly confused. I have been trying older python and cython versions, from times when I knew it worked for a fact, and its still crashing. I wonder of there is any third library that is causing issues too here...

I can't build myself now.... If someone has a working conda env, can they please make a yml file to test? Smoething updated, and its screwing the code. This was working with packages from 6~ months ago, if someone has the patience to downgrade their build, that could be useful too, to pinpoint the issue.

I have also tried older python and cython versions for TIGRE 2.5, the result turns out to be still crashing. I notice that when I use TIGRE 2.4's instruciton, I will meet a nvcc:fatal error as follows:
nvcc fatal : Unsupported gpu architecture 'compute_86'
However, this does not occur when I use TIGRE 2.5 setup.py for installation. I am not sure whether it is related to this issue.

@JixiangChen-Jimmy no, thast unrelated, thats simply because of CUDA versions and so on.
The issue is somewhere else, in some dependency, not in the TIGRE versions. The codes erroring have not been changed in 2 years.

@tsadakane Do you maybe have a conda enviroment with a working TIGRE? I recently needed to resintall from scratch my PC and I lost my working versions of TIGRE enviroments. If you do, can you provide a yml file of the enviroment?

@AnderBiguri Thanks for your information. But I am wondering why using setup.py in TIGRE 2.5 encounters no error during the installation, as I notice that it also contains 'sm86' in the list of the setup.py.

@JixiangChen-Jimmy but those commands gets added/removed depending on the CUDA version in your computer, and there was a bug in 2.4 that its not there in 2.5

@AnderBiguri I see, thanks for your prompt response! Looking forward to locating the bug metioned before.

I think it might be an issue with numpy. I got it to work with 1.20.0. I was previously using 1.24.3.

I ceratinly have used newer ones, but that helps quite a lot, thanks!

@tamish2 Thanks for you solution! However, I still encounter problems by using numpy 1.20.0, here is the error information:
(DIF-Net) chenjx@6d39a5819b8d:~/code/TIGRE/Python/demos$ python d03_generateData.py
Traceback (most recent call last):
File "/public/home/chenjx/code/TIGRE/Python/demos/d03_generateData.py", line 23, in
import tigre
File "/public/home/chenjx/anaconda3/envs/DIF-Net/lib/python3.9/site-packages/pytigre-2.4.0-py3.9-linux-x86_64.egg/tigre/init.py", line 23, in
from .utilities.Ax import Ax
File "/public/home/chenjx/anaconda3/envs/DIF-Net/lib/python3.9/site-packages/pytigre-2.4.0-py3.9-linux-x86_64.egg/tigre/utilities/Ax.py", line 4, in
from _Ax import _Ax_ext
File "tigre/utilities/cuda_interface/_Ax.pyx", line 1, in init _Ax
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

Have you ever meet this during fixing this bug?

@JixiangChen-Jimmy you seem to not have recompiled for numpy 1.20

So I tested it with 1.24.3 numpy version again and that also seems to work. Can someone confirm?

@AnderBiguri Yeah, thanks. I solely uninstall new version numpy and install numpy==1.20.0. Can you indicate the procedure of recopile? Because I just tried to use 'pip uninstall pytigre' and use 'python setup.py install' and still get the same ValueError.

@JixiangChen-Jimmy remove the tigre/Python/build folder and then python setup.py install again

@tamish2 did you clean the old compiled versions (see above) and test again? Its possible its not recompiling the files for 1.24.3

@AnderBiguri It is strange that after recompiling, I get 'TypeError: 'numpy.float32' object cannot be interpreted as an integer' again. Can you resolve the bug via using numpy==1.20.0?

@JixiangChen-Jimmy are you saying that it works for you in 1.20 too?

@AnderBiguri No, changing into 1.20 does not solve this bug for me.

Yeah I don't think numpy is the issue; I can't figure put how I got it to work

@tamish2 Are you using conda or mamba? If so, can you share your environment yml file?

@AnderBiguri I have tried numpy==1.19.4 and scipy==1.9.1, which still fails to solve the bug after recompile.

@AnderBiguri Sorry but here are my version numbers

  • cython==0.29.35
  • numpy==1.23.5

Were you able to get it to work btw? I see that @JixiangChen-Jimmy is still having issues

@tamish2 no worries. If you are using conda though, if you can put here the entire yml that would make testing so much easier, as it could be something else that those two depend on.

ok I think it may be an issue with the python version as well. I tried python 3.9.16 and cython 0.29.35.

I tried python 3.9.16 and cython 0.29.35, this modification does not resolve the issue for me.

Sorry I am quite busy this days, I am trying to find a small timeslot to fix this ASAP.

I strongly suspect that any cython <3 should work, but its the python+numpy versions that are being the problem here. I'd suggest trying nympy <1.24 as 1.24 and 1.25 are very recent, I suspect changed to support cython 3.

@AnderBiguri @JixiangChen-Jimmy @tamish2 I had the same problem and spent a long time trying to debug with different package version combinations. I couldn't get the latest build to work. But checkout with commit 7cd10dd from last month works with numpy==1.23.1, Cython==0.29.35 and python 3.11.4. The latest numpy version works as well.

@AnderBiguri , I did some experiment with new environments using Python 3.11 and the HEAD (e6d24b0) revision of the master.

Exp. 1 cython 3

Setup

conda create -n dev311 python=3.11
conda activate dev311
conda install jupyter numpy matplotlib opencv pillow pandas scipy imageio cython pylint

versions

  • cython=3.0.0=py311h2bbff1b_0
  • numpy=1.25.2=py311hdab7c0b_0
  • numpy-base=1.25.2=py311hd01c5d8_0

build

Python setup.py develop --user > Build.log 2>&1

result

Compilation failure:

running develop
C:\opt\anaconda3\envs\dev311\Lib\site-packages\setuptools\command\develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
C:\opt\anaconda3\envs\dev311\Lib\site-packages\setuptools\_distutils\cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
running egg_info
creating pytigre.egg-info
writing pytigre.egg-info\PKG-INFO
writing dependency_links to pytigre.egg-info\dependency_links.txt
writing requirements to pytigre.egg-info\requires.txt
writing top-level names to pytigre.egg-info\top_level.txt
writing manifest file 'pytigre.egg-info\SOURCES.txt'
file tigre\py.py (for module tigre.py) not found
reading manifest file 'pytigre.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.ipynb' under directory 'tigre\demos'
warning: no files found matching '*.mat' under directory 'tigre\demos'
adding license file 'LICENSE'
writing manifest file 'pytigre.egg-info\SOURCES.txt'
running build_ext
C:\opt\anaconda3\envs\dev311\Lib\site-packages\Cython\Compiler\Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: F:\ws\20230812_tsTIGRE_dev11\Python\tigre\utilities\cuda_interface\_Ax.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
Compiling tigre/utilities/cuda_interface/_Ax.pyx because it changed.
[1/1] Cythonizing tigre/utilities/cuda_interface/_Ax.pyx
building '_Ax' extension
error: unknown file type '.pxd' (from 'tigre/utilities/cuda_interface/_gpuUtils.pxd')

Exp. 2 cython 0.29

Setup

conda create -n dev311_cython29 python=3.11
conda activate dev311_cython29
conda install jupyter numpy matplotlib opencv pillow pandas scipy imageio cython==0.29.36 pylint

, where cython 0.29.36 is the latest win-64 cython in https://anaconda.org/anaconda/cython/files as of today.

versions

  • cython=0.29.36=py311h2bbff1b_0
  • numpy=1.25.2=py311hdab7c0b_0
  • numpy-base=1.25.2=py311hd01c5d8_0

build

Python setup.py develop --user > Build.log 2>&1

result

Build OK (see below)
Run example.py successfully.

Note

At the top of the build log, there are some warnings:

running develop
C:\opt\anaconda3\envs\dev311\Lib\site-packages\setuptools\command\develop.py:40: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
C:\opt\anaconda3\envs\dev311\Lib\site-packages\setuptools\_distutils\cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
running egg_info
...

@tsadakane I see, so python setup.py --install got completely deprecated with cython 3.

So, with the cython 0.29 and python 3.11 it works for you? Can you run the code? I have python 3.10, and the combintaion of things not working are indeed different (as you can see above with the other users too).

I guess the best approach would be to move everything to the most updated stuff, and that would include going tor the newer suggested installation options suggested in the error I guess.

Unfortunately I am very busy, will pick this up in a months time, as I am going to ICIAM 2023 and then take some needed holidays.

@AnderBiguri ,

So, with the cython 0.29 and python 3.11 it works for you?

Yes, it does. I could run example.py successfully. I think @matthewyccheung could do it in almost the same environment for very recent revision (Jul 11, #473 (comment)).

Please note that the source that I used was the HEAD and all packages I install was only

conda install jupyter numpy matplotlib opencv pillow pandas scipy imageio cython==0.29.36 pylint

i.e., nothing is installed by pip.

Here is the yml file:

name: dev311_cython29
channels:
  - defaults
dependencies:
  - aiofiles=22.1.0=py311haa95532_0
  - aiosqlite=0.18.0=py311haa95532_0
  - anyio=3.5.0=py311haa95532_0
  - argon2-cffi=21.3.0=pyhd3eb1b0_0
  - argon2-cffi-bindings=21.2.0=py311h2bbff1b_0
  - astroid=2.14.2=py311haa95532_0
  - asttokens=2.0.5=pyhd3eb1b0_0
  - attrs=22.1.0=py311haa95532_0
  - babel=2.11.0=py311haa95532_0
  - backcall=0.2.0=pyhd3eb1b0_0
  - beautifulsoup4=4.12.2=py311haa95532_0
  - blas=1.0=mkl
  - bleach=4.1.0=pyhd3eb1b0_0
  - bottleneck=1.3.5=py311h5bb9823_0
  - brotli=1.0.9=h2bbff1b_7
  - brotli-bin=1.0.9=h2bbff1b_7
  - brotlipy=0.7.0=py311h2bbff1b_1002
  - bzip2=1.0.8=he774522_0
  - ca-certificates=2023.05.30=haa95532_0
  - certifi=2023.7.22=py311haa95532_0
  - cffi=1.15.1=py311h2bbff1b_3
  - charset-normalizer=2.0.4=pyhd3eb1b0_0
  - colorama=0.4.6=py311haa95532_0
  - comm=0.1.2=py311haa95532_0
  - contourpy=1.0.5=py311h59b6b97_0
  - cryptography=41.0.2=py311h31511bf_0
  - cycler=0.11.0=pyhd3eb1b0_0
  - cython=0.29.36=py311h2bbff1b_0
  - debugpy=1.6.7=py311hd77b12b_0
  - decorator=5.1.1=pyhd3eb1b0_0
  - defusedxml=0.7.1=pyhd3eb1b0_0
  - dill=0.3.6=py311haa95532_0
  - eigen=3.3.7=h59b6b97_1
  - entrypoints=0.4=py311haa95532_0
  - executing=0.8.3=pyhd3eb1b0_0
  - ffmpeg=4.2.2=he774522_0
  - fonttools=4.25.0=pyhd3eb1b0_0
  - freetype=2.12.1=ha860e81_0
  - giflib=5.2.1=h8cc25b3_3
  - glib=2.69.1=h5dc1a3c_2
  - gst-plugins-base=1.18.5=h9e645db_0
  - gstreamer=1.18.5=hd78058f_0
  - hdf5=1.12.1=h51c971a_3
  - icc_rt=2022.1.0=h6049295_2
  - icu=58.2=ha925a31_3
  - idna=3.4=py311haa95532_0
  - imageio=2.26.0=py311haa95532_0
  - intel-openmp=2023.1.0=h59b6b97_46319
  - ipykernel=6.25.0=py311h746a85d_0
  - ipython=8.12.2=py311haa95532_0
  - ipython_genutils=0.2.0=pyhd3eb1b0_1
  - ipywidgets=8.0.4=py311haa95532_0
  - isort=5.9.3=pyhd3eb1b0_0
  - jedi=0.18.1=py311haa95532_1
  - jinja2=3.1.2=py311haa95532_0
  - jpeg=9e=h2bbff1b_1
  - json5=0.9.6=pyhd3eb1b0_0
  - jsonschema=4.17.3=py311haa95532_0
  - jupyter=1.0.0=py311haa95532_8
  - jupyter_client=7.4.9=py311haa95532_0
  - jupyter_console=6.6.3=py311haa95532_0
  - jupyter_core=5.3.0=py311haa95532_0
  - jupyter_events=0.6.3=py311haa95532_0
  - jupyter_server=1.23.4=py311haa95532_0
  - jupyter_server_fileid=0.9.0=py311haa95532_0
  - jupyter_server_ydoc=0.8.0=py311haa95532_1
  - jupyter_ydoc=0.2.4=py311haa95532_0
  - jupyterlab=3.6.3=py311haa95532_0
  - jupyterlab_pygments=0.1.2=py_0
  - jupyterlab_server=2.22.0=py311haa95532_0
  - jupyterlab_widgets=3.0.5=py311haa95532_0
  - kiwisolver=1.4.4=py311hd77b12b_0
  - krb5=1.19.4=h5b6d351_0
  - lazy-object-proxy=1.6.0=py311h2bbff1b_0
  - lerc=3.0=hd77b12b_0
  - libbrotlicommon=1.0.9=h2bbff1b_7
  - libbrotlidec=1.0.9=h2bbff1b_7
  - libbrotlienc=1.0.9=h2bbff1b_7
  - libclang=14.0.6=default_hb5a9fac_1
  - libclang13=14.0.6=default_h8e68704_1
  - libdeflate=1.17=h2bbff1b_0
  - libffi=3.4.4=hd77b12b_0
  - libiconv=1.16=h2bbff1b_2
  - libogg=1.3.5=h2bbff1b_1
  - libpng=1.6.39=h8cc25b3_0
  - libprotobuf=3.20.3=h23ce68f_0
  - libsodium=1.0.18=h62dcd97_0
  - libtiff=4.5.0=h6c2663c_2
  - libvorbis=1.3.7=he774522_0
  - libwebp=1.2.4=hbc33d0d_1
  - libwebp-base=1.2.4=h2bbff1b_1
  - libxml2=2.10.3=h0ad7f3c_0
  - libxslt=1.1.37=h2bbff1b_0
  - lxml=4.9.2=py311h2bbff1b_0
  - lz4-c=1.9.4=h2bbff1b_0
  - markupsafe=2.1.1=py311h2bbff1b_0
  - matplotlib=3.7.1=py311haa95532_1
  - matplotlib-base=3.7.1=py311hf62ec03_1
  - matplotlib-inline=0.1.6=py311haa95532_0
  - mccabe=0.7.0=pyhd3eb1b0_0
  - mistune=0.8.4=py311h2bbff1b_1000
  - mkl=2023.1.0=h6b88ed4_46357
  - mkl-service=2.4.0=py311h2bbff1b_1
  - mkl_fft=1.3.6=py311hf62ec03_1
  - mkl_random=1.2.2=py311hf62ec03_1
  - munkres=1.1.4=py_0
  - nbclassic=0.5.5=py311haa95532_0
  - nbclient=0.5.13=py311haa95532_0
  - nbconvert=6.5.4=py311haa95532_0
  - nbformat=5.7.0=py311haa95532_0
  - nest-asyncio=1.5.6=py311haa95532_0
  - notebook=6.5.4=py311haa95532_1
  - notebook-shim=0.2.2=py311haa95532_0
  - numexpr=2.8.4=py311h1fcbade_1
  - numpy=1.25.2=py311hdab7c0b_0
  - numpy-base=1.25.2=py311hd01c5d8_0
  - opencv=4.6.0=py311h5d08a89_5
  - openssl=1.1.1v=h2bbff1b_0
  - packaging=23.0=py311haa95532_0
  - pandas=1.5.3=py311heda8569_0
  - pandocfilters=1.5.0=pyhd3eb1b0_0
  - parso=0.8.3=pyhd3eb1b0_0
  - pcre=8.45=hd77b12b_0
  - pickleshare=0.7.5=pyhd3eb1b0_1003
  - pillow=9.4.0=py311hd77b12b_0
  - pip=23.2.1=py311haa95532_0
  - platformdirs=2.5.2=py311haa95532_0
  - ply=3.11=py311haa95532_0
  - prometheus_client=0.14.1=py311haa95532_0
  - prompt-toolkit=3.0.36=py311haa95532_0
  - prompt_toolkit=3.0.36=hd3eb1b0_0
  - psutil=5.9.0=py311h2bbff1b_0
  - pure_eval=0.2.2=pyhd3eb1b0_0
  - pycparser=2.21=pyhd3eb1b0_0
  - pygments=2.15.1=py311haa95532_1
  - pylint=2.16.2=py311haa95532_0
  - pyopenssl=23.2.0=py311haa95532_0
  - pyparsing=3.0.9=py311haa95532_0
  - pyqt=5.15.7=py311hd77b12b_0
  - pyqt5-sip=12.11.0=py311hd77b12b_0
  - pyrsistent=0.18.0=py311h2bbff1b_0
  - pysocks=1.7.1=py311haa95532_0
  - python=3.11.4=h966fe2a_0
  - python-dateutil=2.8.2=pyhd3eb1b0_0
  - python-fastjsonschema=2.16.2=py311haa95532_0
  - python-json-logger=2.0.7=py311haa95532_0
  - pytz=2022.7=py311haa95532_0
  - pywin32=305=py311h2bbff1b_0
  - pywinpty=2.0.10=py311h5da7b33_0
  - pyyaml=6.0=py311h2bbff1b_1
  - pyzmq=23.2.0=py311hd77b12b_0
  - qt-main=5.15.2=he8e5bd7_8
  - qt-webengine=5.15.9=hb9a9bb5_5
  - qtconsole=5.4.2=py311haa95532_0
  - qtpy=2.2.0=py311haa95532_0
  - qtwebkit=5.212=h2bbfb41_5
  - requests=2.31.0=py311haa95532_0
  - rfc3339-validator=0.1.4=py311haa95532_0
  - rfc3986-validator=0.1.1=py311haa95532_0
  - scipy=1.11.1=py311hc1ccb85_0
  - send2trash=1.8.0=pyhd3eb1b0_1
  - setuptools=68.0.0=py311haa95532_0
  - sip=6.6.2=py311hd77b12b_0
  - six=1.16.0=pyhd3eb1b0_1
  - sniffio=1.2.0=py311haa95532_1
  - soupsieve=2.4=py311haa95532_0
  - sqlite=3.41.2=h2bbff1b_0
  - stack_data=0.2.0=pyhd3eb1b0_0
  - tbb=2021.8.0=h59b6b97_0
  - terminado=0.17.1=py311haa95532_0
  - tinycss2=1.2.1=py311haa95532_0
  - tk=8.6.12=h2bbff1b_0
  - toml=0.10.2=pyhd3eb1b0_0
  - tomlkit=0.11.1=py311haa95532_0
  - tornado=6.3.2=py311h2bbff1b_0
  - traitlets=5.7.1=py311haa95532_0
  - typing-extensions=4.7.1=py311haa95532_0
  - typing_extensions=4.7.1=py311haa95532_0
  - tzdata=2023c=h04d1e81_0
  - urllib3=1.26.16=py311haa95532_0
  - vc=14.2=h21ff451_1
  - vs2015_runtime=14.27.29016=h5e58377_2
  - wcwidth=0.2.5=pyhd3eb1b0_0
  - webencodings=0.5.1=py311haa95532_1
  - websocket-client=0.58.0=py311haa95532_4
  - wheel=0.38.4=py311haa95532_0
  - widgetsnbextension=4.0.5=py311haa95532_0
  - win_inet_pton=1.1.0=py311haa95532_0
  - winpty=0.4.3=4
  - wrapt=1.14.1=py311h2bbff1b_0
  - xz=5.4.2=h8cc25b3_0
  - y-py=0.5.9=py311hb6bf4ef_0
  - yaml=0.2.5=he774522_0
  - ypy-websocket=0.8.2=py311haa95532_0
  - zeromq=4.3.4=hd77b12b_0
  - zlib=1.2.13=h8cc25b3_0
  - zstd=1.5.5=hd43e919_0
prefix: C:\opt\anaconda3\envs\dev311_cython29

Tokyo might be hotter and wetter than you think. Take care and have a nice trip.

p.s. This was reported at #472 . I didn't realized it when I posted this comment. Sorry.

@AnderBiguri , I modified several files to modernize the setup, in the environment of Cython 3.0.0 under anaconda, and I could reproduce the entitled problem by running example.py

(dev311) F:\ws\20230815_tsTIGRE_ModernizeSetup2\Python>python example.py
0: NVIDIA GeForce GTX 1060 6GB
{'name': 'NVIDIA GeForce GTX 1060 6GB', 'devices': [0]}
Before cast_to_single, type of nDetector is <class 'numpy.int32'>     <<< My debug code
After  cast_to_single, type of nDetector is <class 'numpy.float32'>   <<< My debug code
type of geometry.nDetector[0] : <class 'numpy.float32'>               <<< My debug code
Traceback (most recent call last):
  File "F:\ws\20230815_tsTIGRE_ModernizeSetup2\Python\example.py", line 38, in <module>
    proj = tigre.Ax(head, geo, angles, gpuids=gpuids)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\ws\20230815_tsTIGRE_ModernizeSetup2\Python\tigre\utilities\Ax.py", line 37, in Ax
    return _Ax_ext(img, geox, geox.angles, projection_type, geox.mode, gpuids=gpuids)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "tigre\\utilities\\cuda_interface\\_Ax.pyx", line 92, in _Ax._Ax_ext
    shape[1] = <np.npy_intp> geometry.nDetector[0]
TypeError: 'numpy.float32' object cannot be interpreted as an integer

I could find that nDetector[0] is casted to np.float32 in cast_to_single function in Ax.py. The function casts the ALL attributes of the given geometry object to np.float32. It is also called in Atb.py, so _Atb_ext would also fail as nVoxel is numpy.float32.

There are several options:

  1. Modify cast_to_single so that it does not affect to the specified attributes.
    def cast_to_single(self):
    """
    Casts all number values in current instance to single prevision floating point types.
    :return: None
    """
    for attrib in self.__dict__:
    if getattr(self, attrib) is not None:
    try:
    setattr(self, attrib, np.float32(getattr(self, attrib)))

    =>
        list_attrib_skip = ["nDetector", "nVoxel", "n_proj"]
        for attrib in self.__dict__:
            if attrib in list_attrib_skip:
                continue
            if getattr(self, attrib) is not None:
  1. Modify _Ax_ext and _Atb_ext so that they cast nVoxel and nDetector to int when they are evaluated:
    shape[1] = <np.npy_intp> geometry.nDetector[0]
    shape[2] = <np.npy_intp> geometry.nDetector[1]

    =>
    shape[1] = <np.npy_intp> (<np.npy_long>(geometry.nDetector[0]))
    shape[2] = <np.npy_intp> (<np.npy_long>(geometry.nDetector[1]))

The 1st one seems simpler but I don't know why cast_to_single function had to affect ALL attributes. I guess the 2nd one is safer. What do you think?

@tsadakane I think we recently had a similar issue with numpy 1.24, it seems they have been changing how the ints are treated under the hood.
I would probably go for the second option, its a few values, and it makes the code much easier to read, I think, for long term support.

@tamish2 @JixiangChen-Jimmy Check the latests master branch, it seems that @tsadakane has fixed the issues! :)