8000 ENH: random: Add the method `permuted` to Generator. by WarrenWeckesser · Pull Request #15121 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 14 commits into from
Sep 2, 2020
Merged
Changes from 1 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
Prev Previous commit
Next Next commit
Use PyMem_Malloc/_Free instead of malloc/free
  • Loading branch information
WarrenWeckesser committed Aug 13, 2020
commit 7fc1136633704db883ee9070e1868a3442bcffde
5 changes: 3 additions & 2 deletions numpy/random/_generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import warnings

from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
from cpython cimport (Py_INCREF, PyFloat_AsDouble)
from cpython.mem cimport PyMem_Malloc, PyMem_Free

cimport cython
import numpy as np
Expand Down Expand Up @@ -4275,7 +4276,7 @@ cdef class Generator:

it = np.PyArray_IterAllButAxis(out, &ax)

buf = malloc(itemsize)
buf = PyMem_Malloc(itemsize)
if buf == NULL:
raise MemoryError('memory allocation failed in permuted')

Expand All @@ -4285,7 +4286,7 @@ cdef class Generator:
<char *>np.PyArray_ITER_DATA(it), <char *>buf)
np.PyArray_ITER_NEXT(it)

free(buf)
PyMem_Free(buf)
return out

def shuffle(self, object x, axis=0):
Expand Down
0