-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use HPy to define the ndarray type #2
Changes from 14 commits
969e1e1
8e55aa7
acee27f
337504f
46a179c
f46629a
0371393
be76a4b
abe1d63
e6f5941
274de4e
945ce86
8acae98
aeebf2b
24c3c4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#define PY_SSIZE_T_CLEAN | ||
#include "Python.h" | ||
#include "structmember.h" | ||
#include "hpy.h" | ||
|
||
#define NPY_NO_DEPRECATED_API NPY_API_VERSION | ||
#define _UMATHMODULE | ||
|
@@ -4510,7 +4511,10 @@ intern_strings(void) | |
|
||
static struct PyModuleDef moduledef = { | ||
PyModuleDef_HEAD_INIT, | ||
"_multiarray_umath", | ||
/* XXX: Unclear if a dotted name is legit in .m_name, but universal | ||
* mode requires it. | ||
*/ | ||
"numpy.core._multiarray_umath", | ||
rlamy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NULL, | ||
-1, | ||
array_module_methods, | ||
|
@@ -4521,7 +4525,8 @@ static struct PyModuleDef moduledef = { | |
}; | ||
|
||
/* Initialization function for the module */ | ||
PyMODINIT_FUNC PyInit__multiarray_umath(void) { | ||
HPy_MODINIT(_multiarray_umath) | ||
static HPy init__multiarray_umath_impl(HPyContext ctx) { | ||
PyObject *m, *d, *s; | ||
PyObject *c_api; | ||
|
||
|
@@ -4588,13 +4593,14 @@ PyMODINIT_FUNC PyInit__multiarray_umath(void) { | |
goto err; | ||
} | ||
|
||
PyObject *array_type = PyType_FromSpec(&PyArray_Type_spec); | ||
if (array_type == NULL) { | ||
HPy h_array_type = HPyType_FromSpec(ctx, &PyArray_Type_spec, NULL); | ||
if (HPy_IsNull(h_array_type)) { | ||
goto err; | ||
} | ||
_PyArray_Type_p = (PyTypeObject*)array_type; | ||
_PyArray_Type_p = (PyTypeObject*)HPy_AsPyObject(ctx, h_array_type); | ||
PyArray_Type.tp_as_buffer = &array_as_buffer; | ||
PyArray_Type.tp_weaklistoffset = offsetof(PyArrayObject_fields, weakreflist); | ||
HPy_Close(ctx, h_array_type); | ||
|
||
if (setup_scalartypes(d) < 0) { | ||
goto err; | ||
|
@@ -4725,7 +4731,7 @@ PyMODINIT_FUNC PyInit__multiarray_umath(void) { | |
ADDCONST(MAY_SHARE_EXACT); | ||
#undef ADDCONST | ||
|
||
PyDict_SetItemString(d, "ndarray", array_type); | ||
PyDict_SetItemString(d, "ndarray", (PyObject*)&PyArray_Type); | ||
PyDict_SetItemString(d, "flatiter", (PyObject *)&PyArrayIter_Type); | ||
PyDict_SetItemString(d, "nditer", (PyObject *)&NpyIter_Type); | ||
PyDict_SetItemString(d, "broadcast", | ||
|
@@ -4767,12 +4773,12 @@ PyMODINIT_FUNC PyInit__multiarray_umath(void) { | |
if (initumath(m) != 0) { | ||
goto err; | ||
} | ||
return m; | ||
return HPy_FromPyObject(ctx, m); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, this is interesting. I always assumed that the first thing to do to port a module to HPy would be to convert It is worth adding a note to |
||
|
||
err: | ||
if (!PyErr_Occurred()) { | ||
PyErr_SetString(PyExc_RuntimeError, | ||
"cannot load multiarray module."); | ||
} | ||
return NULL; | ||
return HPy_NULL; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ requires = [ | |
"setuptools<49.2.0", | ||
"wheel<=0.35.1", | ||
"Cython>=0.29.21,<3.0", # Note: keep in sync with tools/cythonize.py | ||
"hpy.devel @ git+https://github.com/hpyproject/hpy.git@8e20b89116c2993188157c09a6070a64f8efbd82#egg=hpy.devel" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should start to tag/release "real" revisions |
||
] | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,6 +405,10 @@ def setup_package(): | |
cmdclass=cmdclass, | ||
python_requires='>=3.7', | ||
zip_safe=False, | ||
setup_requires=['hpy.devel'], | ||
# distuils doesn't load hpy.devel unless hpy_ext_modules is present | ||
# as a keyword | ||
hpy_ext_modules=[], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rlamy I'm not sure what the final fix should be yet, but in the mean time this small change made what was happening much more understandable. With it, |
||
entry_points={ | ||
'console_scripts': f2py_cmds | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ pip install --upgrade pip 'setuptools<49.2.0' wheel | |
# requirement using `grep cython test_requirements.txt` instead of simply | ||
# writing 'pip install setuptools wheel cython'. | ||
pip install `grep cython test_requirements.txt` | ||
pip install `grep hpy.devel test_requirements.txt` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed for a good reason, or simply because we haven't released There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I think that the comment about Cython applies to HPy as well: we probably want to ensure that we have a specific version of HPy and setup_requires may not be enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
not necessarily: Cython has a weird way of integrating with setuptools: you need to call
I think that |
||
|
||
if [ -n "$DOWNLOAD_OPENBLAS" ]; then | ||
pwd | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,8 @@ if [ -n "$PYTHON_OPTS" ]; then | |
fi | ||
|
||
# make some warnings fatal, mostly to match windows compilers | ||
werrors="-Werror=vla -Werror=nonnull -Werror=pointer-arith" | ||
# werrors="-Werror=vla -Werror=nonnull -Werror=pointer-arith" | ||
werrors="-Werror=nonnull -Werror=pointer-arith" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because ATM HPy uses Variable Length Arrays, so the build fails with "-Werror=vla" on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See discussion in hpyproject/hpy#125. |
||
werrors="$werrors -Werror=implicit-function-declaration" | ||
|
||
# build with c99 by default | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a note: looking at how it is easy to migrate an existing extension, I think that the invention of
.legacy_slots
is a Very Good Idea :)