From 0238ae4daaa210290ed1ed07db244615579c934d Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Wed, 18 Sep 2019 10:03:30 +0100 Subject: BUG: Avoid ctypes in Generators Avoid unnecessary use of ctypes in Generators closes #14131 --- numpy/random/generator.pyx | 4 ++-- numpy/random/mtrand.pyx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/numpy/random/generator.pyx b/numpy/random/generator.pyx index a233810da..37ac57c06 100644 --- a/numpy/random/generator.pyx +++ b/numpy/random/generator.pyx @@ -3837,7 +3837,7 @@ cdef class Generator: # Fast, statically typed path: shuffle the underlying buffer. # Only for non-empty, 1d objects of class ndarray (subclasses such # as MaskedArrays may not support this approach). - x_ptr = x.ctypes.data + x_ptr = np.PyArray_DATA(x) stride = x.strides[0] itemsize = x.dtype.itemsize # As the array x could contain python objects we use a buffer @@ -3845,7 +3845,7 @@ cdef class Generator: # within the buffer and erroneously decrementing it's refcount # when the function exits. buf = np.empty(itemsize, dtype=np.int8) # GC'd at function exit - buf_ptr = buf.ctypes.data + buf_ptr = np.PyArray_DATA(buf) with self.lock: # We trick gcc into providing a specialized implementation for # the most common case, yielding a ~33% performance improvement. diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx index 468703e38..267a056e8 100644 --- a/numpy/random/mtrand.pyx +++ b/numpy/random/mtrand.pyx @@ -4070,7 +4070,7 @@ cdef class RandomState: # Fast, statically typed path: shuffle the underlying buffer. # Only for non-empty, 1d objects of class ndarray (subclasses such # as MaskedArrays may not support this approach). - x_ptr = x.ctypes.data + x_ptr = np.PyArray_DATA(x) stride = x.strides[0] itemsize = x.dtype.itemsize # As the array x could contain python objects we use a buffer @@ -4078,7 +4078,7 @@ cdef class RandomState: # within the buffer and erroneously decrementing it's refcount # when the function exits. buf = np.empty(itemsize, dtype=np.int8) # GC'd at function exit - buf_ptr = buf.ctypes.data + buf_ptr = np.PyArray_DATA(buf) with self.lock: # We trick gcc into providing a specialized implementation for # the most common case, yielding a ~33% performance improvement. -- cgit v1.2.1