Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

API,MAINT: Reorganize array-wrap calling and introducereturn_scalar#25409

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
seberg merged 18 commits intonumpy:mainfromseberg:clean-wrapping
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
18 commits
Select commitHold shift + click to select a range
0ba20d7
API: Reorganize `__array_wrap__` and add `return_scalar=False`
sebergNov 10, 2023
e6fdbdc
BUG: Fix niche bug in rounding.
sebergDec 17, 2023
b9fb29e
MAINT: Adjust __array_wrap__ in code and tests (also deprecation test)
sebergDec 17, 2023
3c51b0f
MAINT: Use/move the simplest C-wrapping also
sebergDec 17, 2023
ad0e168
DOC: Update doc and add release note
sebergDec 17, 2023
09ba729
STY: Make linter happy in old tests
sebergDec 17, 2023
2ef4302
MAINT: Silence GCC warning (value cannot really be used uninitialized)
sebergDec 17, 2023
411e2db
MAINT: Small style fixes
sebergDec 18, 2023
4846b1d
BUG: Fix reference leak in ufunc array-wrapping
sebergDec 18, 2023
a2cee02
BUG: Fix leak for result arrays in all ufunc calls
sebergDec 19, 2023
3caf819
Ensure we try passing context and address related smaller review comm…
sebergJan 17, 2024
5d2c04c
Merge branch 'main' into clean-wrapping
sebergJan 17, 2024
181a376
Ensure we don't try `context=None` and expand code comment
sebergJan 17, 2024
8621eee
Rely on return_scalar always being right (and style nit)
sebergJan 17, 2024
3122538
Remove outdated comments as per review
sebergJan 17, 2024
497c535
Let's just undo force-wrap for now for reductions (its a change...)
sebergJan 17, 2024
f50ff16
ENH: Chain the original error when the deprecationwarning is raised
sebergJan 19, 2024
606f5c3
BUG,MAINT: Address Martens review comments
sebergJan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
MAINT: Use/move the simplest C-wrapping also
  • Loading branch information
@seberg
seberg committedDec 17, 2023
commit3c51b0f804601ba54ad0a73d6cc6145644a5eca0
5 changes: 4 additions & 1 deletionnumpy/_core/src/multiarray/arrayobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,7 @@ maintainer email: oliphant.travis@ieee.org

#include "number.h"
#include "usertypes.h"
#include "arraywrap.h"
#include "arraytypes.h"
#include "scalartypes.h"
#include "arrayobject.h"
Expand DownExpand Up@@ -988,7 +989,9 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
* already have deferred. So use `self` for wrapping. If users
* need more, they need to override `==` and `!=`.
*/
Py_SETREF(res, PyArray_SubclassWrap(self, res));
PyObject *wrapped = npy_apply_wrap_simple(self, res);
Py_DECREF(res);
return wrapped;
}
return (PyObject *)res;
}
Expand Down
24 changes: 21 additions & 3 deletionsnumpy/_core/src/multiarray/arraywrap.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,9 +118,9 @@ _get_wrap_prepare_args(NpyUFuncContext *context) {
* Apply the array wrapping to a result array.
*
* @param obj The object (should be an array) to wrap.
* @param original_out NULL/None (both valid) orthe originalobjectpassed
*in via `out=` (expected to be an array).
*If given, its wrapping method is always preferred.
* @param original_out NULL/None (both valid) oranobjectwho's wrapping
*method is always used/preferred. The naming comes because for an
*`out=` argument we always trigger its own wrapping method.
* @param wrap The array wrap function to call
* @param wrap_type The type belonging to the wrap function, when it matches
* wrapping may be short-cut.
Expand DownExpand Up@@ -256,3 +256,21 @@ npy_apply_wrap(
Py_XDECREF(new_wrap);
return res;
}


/*
* Calls arr_of_subclass.__array_wrap__(towrap), in order to make 'towrap'
* have the same ndarray subclass as 'arr_of_subclass'.
* `towrap` should be a base-class ndarray.
*/
NPY_NO_EXPORT PyObject *
npy_apply_wrap_simple(PyArrayObject *arr_of_subclass, PyArrayObject *towrap)
{
/*
* Same as apply-wrap, but when there is only a single other array we
* can `original_out` and not worry about passing a useful wrap.
*/
return npy_apply_wrap(
(PyObject *)towrap, (PyObject *)arr_of_subclass, Py_None, NULL,
NULL, NPY_FALSE, NPY_TRUE);
}
6 changes: 6 additions & 0 deletionsnumpy/_core/src/multiarray/arraywrap.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,9 +16,15 @@ npy_apply_wrap(
PyObject *wrap, PyObject *wrap_type,
NpyUFuncContext *context, npy_bool return_scalar, npy_bool force_wrap);


NPY_NO_EXPORT PyObject *
npy_apply_wrap_simple(PyArrayObject *arr_of_subclass, PyArrayObject *towrap);


NPY_NO_EXPORT int
npy_find_array_wrap(
int nin, PyObject *const *inputs,
PyObject **out_wrap, PyObject **out_wrap_type);


#endif /* NUMPY_CORE_SRC_MULTIARRAY_ARRAYWRAP_H_ */
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing end of line

23 changes: 0 additions & 23 deletionsnumpy/_core/src/multiarray/ctors.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4073,26 +4073,3 @@ _array_fill_strides(npy_intp *strides, npy_intp const *dims, int nd, size_t item
}
return;
}

/*
* Calls arr_of_subclass.__array_wrap__(towrap), in order to make 'towrap'
* have the same ndarray subclass as 'arr_of_subclass'.
*/
NPY_NO_EXPORT PyArrayObject *
PyArray_SubclassWrap(PyArrayObject *arr_of_subclass, PyArrayObject *towrap)
{
PyObject *wrapped = PyObject_CallMethodObjArgs((PyObject *)arr_of_subclass,
npy_ma_str_array_wrap, (PyObject *)towrap, NULL);
if (wrapped == NULL) {
return NULL;
}
if (!PyArray_Check(wrapped)) {
PyErr_SetString(PyExc_RuntimeError,
"ndarray subclass __array_wrap__ method returned an "
"object which was not an instance of an ndarray subclass");
Py_DECREF(wrapped);
return NULL;
}

return (PyArrayObject *)wrapped;
}
7 changes: 0 additions & 7 deletionsnumpy/_core/src/multiarray/ctors.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,13 +124,6 @@ copy_and_swap(void *dst, void *src, int itemsize, npy_intp numitems,
NPY_NO_EXPORT void
byte_swap_vector(void *p, npy_intp n, int size);

/*
* Calls arr_of_subclass.__array_wrap__(towrap), in order to make 'towrap'
* have the same ndarray subclass as 'arr_of_subclass'.
*/
NPY_NO_EXPORT PyArrayObject *
PyArray_SubclassWrap(PyArrayObject *arr_of_subclass, PyArrayObject *towrap);

NPY_NO_EXPORT PyObject *
PyArray_Zeros_int(int nd, npy_intp const *dims, PyArray_Descr *descr,
PyArray_DTypeMeta *dtype, int is_f_order);
Expand Down
9 changes: 5 additions & 4 deletionsnumpy/_core/src/multiarray/shape.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@

#include "npy_pycompat.h"

#include "arraywrap.h"
#include "ctors.h"

#include "shape.h"
Expand DownExpand Up@@ -567,9 +568,9 @@ PyArray_Squeeze(PyArrayObject *self)
* __array_wrap__ method
*/
if (Py_TYPE(self) != &PyArray_Type) {
PyArrayObject *tmp =PyArray_SubclassWrap(self, ret);
PyObject *wrapped =npy_apply_wrap_simple(self, ret);
Py_DECREF(ret);
ret = tmp;
return wrapped;
}

return (PyObject *)ret;
Expand DownExpand Up@@ -623,9 +624,9 @@ PyArray_SqueezeSelected(PyArrayObject *self, npy_bool *axis_flags)
* __array_wrap__ method
*/
if (Py_TYPE(self) != &PyArray_Type) {
PyArrayObject *tmp =PyArray_SubclassWrap(self, ret);
PyObject *wrapped =npy_apply_wrap_simple(self, ret);
Py_DECREF(ret);
ret = tmp;
return wrapped;
}

return (PyObject *)ret;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp