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

Convert most of np.zeros to HPy #12

Open
wants to merge 1 commit into
base: hpy
Choose a base branch
from

Conversation

steve-s
Copy link

@steve-s steve-s commented Feb 10, 2022

No description provided.

@steve-s steve-s requested a review from rlamy February 10, 2022 10:27
Copy link
Member

@rlamy rlamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. I would prefer the implementation to be complete before merging though. How hard would it be to support like?

char const *message)
{
HPyContext *ctx = npy_get_context();
return hpy_string_converter_helper(ctx, HPy_FromPyObject(ctx, object), out, str_func, name, message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HPy_FromPyObject(ctx, object) handle needs to be closed

@@ -2988,32 +2988,48 @@ PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags)
NPY_NO_EXPORT PyObject *
PyArray_Zeros(int nd, npy_intp const *dims, PyArray_Descr *type, int is_f_order)
{
PyArrayObject *ret;
HPyContext *ctx = npy_get_context();
HPy_AsPyObject(ctx, HPyArray_Zeros(ctx, nd, dims, type, is_f_order));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this handle needs to be closed

ret = (PyArrayObject *)PyArray_NewFromDescr_int(
&PyArray_Type, type,
ret = HPyArray_NewFromDescr_int(
ctx, HPy_FromPyObject(ctx, (PyObject *)&PyArray_Type), type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle leak

return deferred;
if (!HPy_IsNull(h_typecode)) {
// HPY TODO: needs PyArray_Descr porting
PyObject* py_typecode = HPy_AsPyObject(ctx, h_typecode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h_typecode should be closed here, I think

}
}
if (HPyArray_OrderConverter(ctx, h_order, &order) != NPY_SUCCEED) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h_order needs to be closed

goto fail;
}

if (!HPy_IsNull(h_like)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h_like needs to be closed

@@ -354,6 +354,9 @@
'PyDataMem_SetHandler': (304,),
'PyDataMem_GetHandler': (305,),
# End 1.21 API

# HPy API:
'HPyArray_Zeros': (307,),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't add HPy functions to the API, but rather, eventually, have a separate function table for the HPy API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed. I want to play with this a bit to move forward quicker: we'd like to prototype integration with Matplotlib port too. However, new table will be the way to go longer term.

PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
HPyDef_METH(array_zeros, "zeros", array_zeros_impl, HPyFunc_KEYWORDS)
static HPy
array_zeros_impl(HPyContext *ctx, HPy NPY_UNUSED(ignored), HPy *args, HPy_ssize_t nargs, HPy kw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we should probably have const HPy *args in the signature, to match CPython...

{
HPy_ssize_t nd;
npy_intp i;
HPy op, err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is unused

@steve-s
Copy link
Author

steve-s commented Feb 11, 2022

Looks good overall. I would prefer the implementation to be complete before merging though. How hard would it be to support like?

Yes, I'll take a look. I am also trying to port PyArray_Descr, because that also prevents us from executing np.zeros fully in HPy I think. Thanks for the review. I'll update the PR to contain only essential changes to be merged to hpy and keep e.g. the API changes in a separate branch. There is also one new API that I had to add to HPy, which I'll need to upstream.

fangerer added a commit that referenced this pull request Jul 7, 2022
Merge in ~STEPAN.SINDELAR_ORACLE.COM/numpy-hpy from fa/hpy_global to labs-hpy-port

* commit '4f2d3de9229a9c7d2ae6a978cda04ab2262209a8':
  Use HPyGlobal for global type vars
@WilliamGazeley
Copy link

This PR seems to have been quiet for a while. Are there any updates on the numpy hpy project?

@fangerer
Copy link

Hi @WilliamGazeley,

yes, there are updates. In fact, we are actively working on that. It's just that this PR was basically just the initial effort. In order to see our full work, checkout branches graal-team/hpy and graal-team/hpy-0.0.5.

Branch graal-team/hpy requires an HPy branch that is based on the last HPy release 0.0.4. Since we migrated a lot of the needed features to HPy, branch graal-team/hpy-0.0.5 uses an HPy branch that is based on HPy's current master.

We also updated the README.md in those branches and described how to run an example.

I encourage you and everyone else to try it out and I'm happy to help in case of problems.

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

Successfully merging this pull request may close these issues.

4 participants