8000 ENH: Add shape to *_like() array creation by pentschev · Pull Request #13046 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add shape to *_like() array creation #13046

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

Merged
merged 24 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f885c08
ENH: Added shape argument to *_like() array creation functions
pentschev Feb 26, 2019
5ad61b6
ENH: C backend adjustments for shape argument on *_like()
pentschev Feb 26, 2019
fd3e270
TST: Added test for shape argument in *_like() functions
pentschev Feb 26, 2019
b7202a7
ENH: Added PyArray_NewLikeArrayWithShape()
pentschev Feb 26, 2019
013cbce
BUG: Fix for PyArray_NewLikeArrayWithShape strides and ndim == 0
pentschev Feb 27, 2019
807f512
REL: Updates for C-API, version 1.17.x
pentschev Feb 27, 2019
95bbfd0
Revert "REL: Updates for C-API, version 1.17.x"
pentschev Mar 13, 2019
43b9828
Revert exposing PyArray_NewLikeArrayWithShape on C-API
pentschev Mar 13, 2019
fa7fd75
DOC: fix versionadded for *_like() shape argument
pentschev Mar 13, 2019
d57e6d3
STY: add missing spaces in array initializers
pentschev Mar 13, 2019
f1b3e91
ENH: empty_like raises ValueError
pentschev Mar 16, 2019
d24ac10
TST: test for exception of *_like() functions
pentschev Mar 16, 2019 8000
ec26417
DOC: release note for shape argument in *_like() functions
pentschev Mar 16, 2019
40e7e9e
DOC: fix *_like() documentation on raises
pentschev Mar 17, 2019
928952d
BUG: *_like() raises for non-C/F-layout arrays
pentschev Mar 17, 2019
e394356
TST: change *_like() shapes to prevent NPY_RELAXED_STRIDE_DEBUG=1 fai…
pentschev Mar 17, 2019
d938fb9
Move empty_like() exception to C implementation
pentschev Mar 19, 2019
99a55e0
Merge branch 'master' into add-shape-to-like-array-creation
pentschev Mar 28, 2019
c087801
Update *_like() ValueError documentation
pentschev Apr 4, 2019
db7614b
Merge remote-tracking branch 'upstream/master' into add-shape-to-like…
pentschev Apr 5, 2019
669ea71
Rearrange stride computation for *_like() if new shape and order='K'
pentschev Apr 10, 2019
f53afbe
Change handling of order= for *_like()
pentschev Apr 19, 2019
c3ac08e
Merge branch 'master' into add-shape-to-like-array-creation
pentschev Apr 19, 2019
695b836
Fix *_like() tests
pentschev Apr 19, 2019
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
Prev Previous commit
Next Next commit
Rearrange stride computation for *_like() if new shape and order='K'
  • Loading branch information
pentschev committed Apr 10, 2019
commit 669ea71a1750fc8eb6911353e48ac34f8df1d664
5 changes: 1 addition & 4 deletions numpy/core/multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ def empty_like(prototype, dtype=None, order=None, subok=None, shape=None):
Raises
------
ValueError
If `order` is 'K' and any of the following is true

- ``len(shape) != a.ndim``,
- `a` is neither C nor F contiguous.
If `order` is 'K' and ``len(shape) != a.ndim``.

See Also
--------
Expand Down
16 changes: 3 additions & 13 deletions numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ def zeros_like(a, dtype=None, order='K', subok=True, shape=None):
Raises
------
ValueError
If `order` is 'K' and any of the following is true

- ``len(shape) != a.ndim``,
- `a` is neither C nor F contiguous.

If `order` is 'K' and ``len(shape) != a.ndim``.

See Also
--------
Expand Down Expand Up @@ -273,10 +269,7 @@ def ones_like(a, dtype=None, order='K', subok=True, shape=None):
Raises
------
ValueError
If `order` is 'K' and any of the following is true

- ``len(shape) != a.ndim``,
- `a` is neither C nor F contiguous.
If `order` is 'K' and ``len(shape) != a.ndim``.

See Also
--------
Expand Down Expand Up @@ -395,10 +388,7 @@ def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None):
Raises
------
ValueError
If `order` is 'K' and any of the following is true

- ``len(shape) != a.ndim``,
- `a` is neither C nor F contiguous.
If `order` is 'K' and ``len(shape) != a.ndim``.

See Also
--------
Expand Down
7 changes: 3 additions & 4 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,10 +1214,9 @@ PyArray_NewLikeArrayWithShape(PyArrayObject *prototype, NPY_ORDER order,
dims = PyArray_DIMS(prototype);
new_shape = 0;
}
else if (order == NPY_KEEPORDER && (ndim != PyArray_NDIM(prototype) ||
!(PyArray_IS_C_CONTIGUOUS(prototype) || PyArray_IS_F_CONTIGUOUS(prototype)))) {
else if (order == NPY_KEEPORDER && (ndim != PyArray_NDIM(prototype))) {
PyErr_SetString(PyExc_ValueError,
"mismatching ndim or non-C/F-layout arrays can not keep order");
"mismatching ndim arrays can not keep order");
return ret;
}

Expand Down Expand Up @@ -1248,7 +1247,7 @@ PyArray_NewLikeArrayWithShape(PyArrayObject *prototype, NPY_ORDER order,
}

/* If it's not KEEPORDER, or there is a shape change, this is simple */
if (order != NPY_KEEPORDER || new_shape) {
if (order != NPY_KEEPORDER || (new_shape && ndim != PyArray_NDIM(prototype))) {
ret = PyArray_NewFromDescr(subok ? Py_TYPE(prototype) : &PyArray_Type,
dtype,
ndim,
Expand Down
3 changes: 1 addition & 2 deletions numpy/core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2239,8 +2239,7 @@ def check_like_function(self, like_function, value, fill_value=False):
assert_(sz.flags.f_contiguous)
self.compare_array_value(sz, value, fill_value)

if (d.ndim != len(s) or
not (d.flags.c_contiguous or d.flags.f_contiguous)):
if (d.ndim != len(s)):
assert_raises(ValueError, like_function, d, dtype=dtype,
shape=s, order='K', **fill_kwarg)
Copy link
Member
@eric-wieser eric-wieser Mar 17, 2019

Choose a reason for hiding this comment

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

Needs an else: assert_equal(np.argsort(like_function(...).strides), np.argsort(d.strides))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just added this condition. Note we have also to check for non-C/F-layouts while raising an exception.

else:
Expand Down
0