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

Cannot create NumPy long double arrays with mingw #3136

Open
david-cortes opened this issue Sep 7, 2019 · 2 comments

Comments

@david-cortes
Copy link

commented Sep 7, 2019

Following code will produce an error when compiled with mingw32 from anaconda in windows:

cyfile.pyx

import numpy as np
cimport numpy as np
import ctypes

def get_arr():
    cdef np.ndarray[long double, ndim=1] outp = np.zeros(10, dtype=ctypes.c_longdouble)
    return outp

setup.py:

try:
	from setuptools import setup
except:
	from distutils.core import setup
import numpy as np
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    name  = "cyext",
    packages = ["cyext"],
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("cyext", sources=["cyfile.pyx"], include_dirs=[np.get_include()])]
    )
>>> import cyext
>>> cyext.get_arr()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cyfile.pyx", line 6, in cyext.get_arr
    cdef np.ndarray[long double, ndim=1] outp = np.zeros(10, dtype=ctypes.c_longdouble)
ValueError: Buffer dtype mismatch, expected 'long double' but got 'double'
@scoder

This comment has been minimized.

Copy link
Contributor

commented Sep 7, 2019

@david-cortes

This comment has been minimized.

Copy link
Author

commented Sep 8, 2019

You should probably use the correct NumPy dtype, not anything from ctypes.

Still throws the same error:

import numpy as np
cimport numpy as np
import ctypes

def get_arr():
	cdef np.ndarray[long double, ndim = 1] outp = np.zeros(10, dtype = np.longdouble)
	return outp
import cyext
cyext.get_arr()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cyfile.pyx", line 6, in cyext.get_arr
    cdef np.ndarray[long double, ndim = 1] outp = np.zeros(10, dtype = np.longdouble)
ValueError: Item size of buffer (8 bytes) does not match size of 'long double' (16 bytes)

(Same result from np.longdouble_t in the cdef side)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.