-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: random: Add the method permuted
to Generator.
#15121
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
Changes from 1 commit
a84cdf0
081298c
7fc1136
bc49d4b
3dbcbae
50c7611
023114f
91d208a
95eff00
677f862
f5d6f0b
f016d3a
ebed0e8
785e239
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -30,6 +30,14 @@ from ._common cimport (POISSON_LAM_MAX, CONS_POSITIVE, CONS_NONE, | |||||
validate_output_shape | ||||||
) | ||||||
|
||||||
cdef extern from "numpy/arrayobject.h": | ||||||
#int PyArray_SetWritebackIfCopyBase(np.ndarray, np.ndarray) | ||||||
int PyArray_ResolveWritebackIfCopy(np.ndarray) | ||||||
object PyArray_FromArray(object, object, int) | ||||||
|
||||||
enum: | ||||||
NPY_ARRAY_WRITEBACKIFCOPY | ||||||
|
||||||
np.import_array() | ||||||
|
||||||
cdef int64_t _safe_sum_nonneg_int64(size_t num_colors, int64_t *colors): | ||||||
|
@@ -4184,7 +4192,7 @@ cdef class Generator: | |||||
|
||||||
Parameters | ||||||
---------- | ||||||
x : array_like | ||||||
x : array_like, at least one-dimensional | ||||||
Array to be shuffled. | ||||||
axis : int, optional | ||||||
WarrenWeckesser marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Slices of `x` in this axis are shuffled. Each slice | ||||||
|
@@ -4255,6 +4263,9 @@ cdef class Generator: | |||||
cdef np.npy_intp axlen, axstride, itemsize | ||||||
cdef void *buf | ||||||
cdef np.flatiter it | ||||||
cdef np.ndarray to_shuffle | ||||||
cdef int status | ||||||
cdef int flags | ||||||
|
||||||
x = np.asarray(x) | ||||||
WarrenWeckesser marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
@@ -4268,7 +4279,25 @@ cdef class Generator: | |||||
out[...] = x | ||||||
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. IIRC this uses force-casting, maybe we should use |
||||||
|
||||||
if axis is None: | ||||||
self.shuffle(out.flat) | ||||||
if x.ndim > 1: | ||||||
if not (np.PyArray_FLAGS(out) & (np.NPY_ARRAY_C_CONTIGUOUS | | ||||||
np.NPY_ARRAY_F_CONTIGUOUS)): | ||||||
flags = (np.NPY_ARRAY_C_CONTIGUOUS | | ||||||
NPY_ARRAY_WRITEBACKIFCOPY) | ||||||
to_shuffle = PyArray_FromArray(out, <object>NULL, flags) | ||||||
self.shuffle(to_shuffle.ravel(order='K')) | ||||||
# Because we only execute this block if out is not | ||||||
# contiguous, we know this call will always result in a | ||||||
# copy of to_shuffle back to out. I.e. status will be 1. | ||||||
status = PyArray_ResolveWritebackIfCopy(to_shuffle) | ||||||
assert status == 1 | ||||||
else: | ||||||
# out is n-d with n > 1, but is either C- or F-contiguous, | ||||||
# so we know out.ravel(order='A') is a view. | ||||||
self.shuffle(out.ravel(order='A')) | ||||||
else: | ||||||
# out is 1-d | ||||||
self.shuffle(out) | ||||||
return out | ||||||
WarrenWeckesser marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
ax = normalize_axis_index(axis, np.ndim(out)) | |||||
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.
Suggested change
|
||||||
|
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.