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: Introducecopy argument fornp.asarray [Array API]#25168

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
ngoldbaum merged 5 commits intonumpy:mainfrommtsokol:asarray-copy-arg
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
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
NextNext commit
API: Introduce copy argument for np.asarray
  • Loading branch information
@mtsokol
mtsokol committedFeb 29, 2024
commit906010e173a7fc5859b610a1864f0443824cc84e
3 changes: 0 additions & 3 deletionsdoc/source/reference/array_api.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -494,9 +494,6 @@ Creation functions differences
* - Feature
- Type
- Notes
* - ``copy`` keyword argument to ``asarray``
- **Compatible**
-

Elementwise functions differences
---------------------------------
Expand Down
7 changes: 7 additions & 0 deletionsnumpy/_core/_add_newdocs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -939,6 +939,13 @@
For Array-API interoperability only, so must be ``"cpu"`` if passed.

.. versionadded:: 2.0.0
copy : bool, optional
If true, then the object is copied. If false then the object is
copied only if needed, i.e. if ``__array__`` returns a copy, if obj
is a nested sequence, or if a copy is needed to satisfy any of
the other requirements (``dtype``, ``order``, etc.).
For ``np._CopyMode.NEVER`` it raises a ``ValueError`` if a copy
cannot be avoided. Default: false.
${ARRAY_FUNCTION_LIKE}

.. versionadded:: 1.20.0
Expand Down
4 changes: 2 additions & 2 deletionsnumpy/_core/src/multiarray/conversion_utils.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -227,7 +227,7 @@ PyArray_OptionalIntpConverter(PyObject *obj, PyArray_Dims *seq)
}

NPY_NO_EXPORT int
PyArray_CopyConverter(PyObject *obj,_PyArray_CopyMode *copymode) {
PyArray_CopyConverter(PyObject *obj,NPY_COPYMODE *copymode) {
if (obj == Py_None) {
PyErr_SetString(PyExc_ValueError,
"NoneType copy mode not allowed.");
Expand DownExpand Up@@ -258,7 +258,7 @@ PyArray_CopyConverter(PyObject *obj, _PyArray_CopyMode *copymode) {
int_copymode = (int)bool_copymode;
}

*copymode = (_PyArray_CopyMode)int_copymode;
*copymode = (NPY_COPYMODE)int_copymode;
return NPY_SUCCEED;
}

Expand Down
4 changes: 2 additions & 2 deletionsnumpy/_core/src/multiarray/conversion_utils.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,10 +16,10 @@ typedef enum {
NPY_COPY_IF_NEEDED = 0,
NPY_COPY_ALWAYS = 1,
NPY_COPY_NEVER = 2,
}_PyArray_CopyMode;
}NPY_COPYMODE;

NPY_NO_EXPORT int
PyArray_CopyConverter(PyObject *obj,_PyArray_CopyMode *copyflag);
PyArray_CopyConverter(PyObject *obj,NPY_COPYMODE *copyflag);

NPY_NO_EXPORT int
PyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf);
Expand Down
2 changes: 1 addition & 1 deletionnumpy/_core/src/multiarray/methods.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -782,7 +782,7 @@ array_astype(PyArrayObject *self,
npy_dtype_info dt_info = {NULL, NULL};
NPY_CASTING casting = NPY_UNSAFE_CASTING;
NPY_ORDER order = NPY_KEEPORDER;
_PyArray_CopyMode forcecopy = 1;
NPY_COPYMODE forcecopy = 1;
int subok = 1;

NPY_PREPARE_ARGPARSER;
Expand Down
8 changes: 5 additions & 3 deletionsnumpy/_core/src/multiarray/multiarraymodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1554,7 +1554,7 @@ _prepend_ones(PyArrayObject *arr, int nd, int ndmin, NPY_ORDER order)
static inline PyObject *
_array_fromobject_generic(
PyObject *op, PyArray_Descr *in_descr, PyArray_DTypeMeta *in_DType,
_PyArray_CopyMode copy, NPY_ORDER order, npy_bool subok, int ndmin)
NPY_COPYMODE copy, NPY_ORDER order, npy_bool subok, int ndmin)
{
PyArrayObject *oparr = NULL, *ret = NULL;
PyArray_Descr *oldtype = NULL;
Expand DownExpand Up@@ -1703,7 +1703,7 @@ array_array(PyObject *NPY_UNUSED(ignored),
{
PyObject *op;
npy_bool subok = NPY_FALSE;
_PyArray_CopyMode copy = NPY_COPY_ALWAYS;
NPY_COPYMODE copy = NPY_COPY_ALWAYS;
int ndmin = 0;
npy_dtype_info dt_info = {NULL, NULL};
NPY_ORDER order = NPY_KEEPORDER;
Expand DownExpand Up@@ -1751,6 +1751,7 @@ array_asarray(PyObject *NPY_UNUSED(ignored),
PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
{
PyObject *op;
NPY_COPYMODE copy = NPY_COPY_IF_NEEDED;
npy_dtype_info dt_info = {NULL, NULL};
NPY_ORDER order = NPY_KEEPORDER;
NPY_DEVICE device = NPY_DEVICE_CPU;
Expand All@@ -1763,6 +1764,7 @@ array_asarray(PyObject *NPY_UNUSED(ignored),
"|dtype", &PyArray_DTypeOrDescrConverterOptional, &dt_info,
"|order", &PyArray_OrderConverter, &order,
"$device", &PyArray_DeviceConverterOptional, &device,
"$copy", &PyArray_CopyConverter, &copy,
"$like", NULL, &like,
NULL, NULL, NULL) < 0) {
Py_XDECREF(dt_info.descr);
Expand All@@ -1784,7 +1786,7 @@ array_asarray(PyObject *NPY_UNUSED(ignored),
}

PyObject *res = _array_fromobject_generic(
op, dt_info.descr, dt_info.dtype,NPY_FALSE, order, NPY_FALSE, 0);
op, dt_info.descr, dt_info.dtype,copy, order, NPY_FALSE, 0);
Py_XDECREF(dt_info.descr);
Py_XDECREF(dt_info.dtype);
return res;
Expand Down
11 changes: 0 additions & 11 deletionstools/ci/array-api-skips.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
# copy not implemented
array_api_tests/test_creation_functions.py::test_asarray_arrays

# 'unique_inverse' output array is 1-D for 0-D input
array_api_tests/test_set_functions.py::test_unique_all
array_api_tests/test_set_functions.py::test_unique_inverse
Expand DownExpand Up@@ -28,11 +25,6 @@ array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]

# asarray() got an unexpected keyword argument 'copy'
array_api_tests/test_array_object.py::test_setitem
# array_api_tests/test_array_object.py::test_setitem_masking
array_api_tests/test_creation_functions.py::test_asarray_scalars

# fft test suite is buggy as of 83f0bcdc
array_api_tests/test_fft.py

Expand All@@ -54,8 +46,5 @@ array_api_tests/test_signatures.py::test_func_signature[reshape]
array_api_tests/test_signatures.py::test_func_signature[argsort]
array_api_tests/test_signatures.py::test_func_signature[sort]

# asarray() got an unexpected keyword argument 'copy'
array_api_tests/test_special_cases.py::test_iop

# assertionError: out.dtype=float32, but should be float64 [sum(float32)]
array_api_tests/test_statistical_functions.py::test_sum

[8]ページ先頭

©2009-2025 Movatter.jp