
Hello, I'm trying to track down a segv when I do the B[:] operation on an array, "B", a that I've built in as a view on external data. During the process I ran into the following code (Numeric-21.0): /* {%c++%} */ extern int PyArray_Free(PyObject *op, char *ptr) { PyArrayObject *ap = (PyArrayObject *)op; int i, n; if (ap->nd > 2) return -1; if (ap->nd == 3) { n = ap->dimensions[0]; for (i=0; i<n; i++) { free(((char **)ptr)[i]); } } if (ap->nd >= 2) { free(ptr); } Py_DECREF(ap); return 0; } /* {%c++%} */ The multiple, incompatible tests of ap->nd are the problem. -chris

clee@spiralis.merseine.nu writes:
Hello, I'm trying to track down a segv when I do the B[:] operation on an array, "B", a that I've built in as a view on external data. During... [snip]
To clarify my own somewhat non-sensical post: When I started composing my message, I was trying to figure out a bug in my own code that caused a crash while doing slice_array. I've since fixed that bug. However, in the process of figuring out what I was doing wrong I was browsing the Numeric source code. While examining PyArray_Free(..) in arrayobject.c, I saw that returns -1 whenever the number of dimensions is greater than 2, yet it has code that tests for when the number of dimensions equals 3. So utimately, my post is just an alert, that I think there might be some code that needs to be cleaned up. Thanks, lacking-caffeine-ly yours -chris

Hi, Can anyone explain the following? Python 2.1.1, Numpy version='20.2.0' Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help
from RandomArray import * normal(3., 1., (5,)) array([ 2.19091588, 2.44682837, 2.51790264, 4.26374364, 4.56880629])
Python 2.2, Numpy version='20.3' Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help
from RandomArray import * normal(3., 1., (5,)) array([-3.78572679, -3.63714516, -3.01228334, -4.80211985, -2.57420304])
Why am I getting negative values with Python 2.2? This happens consistently. Any help would be appreciated. Thanks, Ray _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com

On Thu, 4 Apr 2002, Ray Drew wrote:
Python 2.2, Numpy version='20.3'
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help
from RandomArray import * normal(3., 1., (5,)) array([-3.78572679, -3.63714516, -3.01228334, -4.80211985, -2.57420304])
Why am I getting negative values with Python 2.2? This happens consistently. Any help would be appreciated.
This is a bug in Numpy 20.3 and should be fixed in Numpy 21.0. Pearu

clee@spiralis.merseine.nu wrote:
clee@spiralis.merseine.nu writes:
Hello, I'm trying to track down a segv when I do the B[:] operation on an array, "B", a that I've built in as a view on external data. During... [snip]
To clarify my own somewhat non-sensical post: When I started composing my message, I was trying to figure out a bug in my own code that caused a crash while doing slice_array. I've since fixed that bug. However, in the process of figuring out what I was doing wrong I was browsing the Numeric source code. While examining PyArray_Free(..) in arrayobject.c, I saw that returns -1 whenever the number of dimensions is greater than 2, yet it has code that tests for when the number of dimensions equals 3.
So utimately, my post is just an alert, that I think there might be some code that needs to be cleaned up.
Thanks, lacking-caffeine-ly yours -chris
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Looking at the code to PyArray_Free, I agree with Chris. Called to free a 2D array, I think that PyArray_Free leaks all of the row storage because ap->nd == 2, not 3: * {%c++%} */ extern int PyArray_Free(PyObject *op, char *ptr) { PyArrayObject *ap = (PyArrayObject *)op; int i, n; if (ap->nd > 2) return -1; if (ap->nd == 3) { n = ap->dimensions[0]; for (i=0; i<n; i++) { free(((char **)ptr)[i]); } } if (ap->nd >= 2) { free(ptr); } Py_DECREF(ap); return 0; } /* {%c++%} */ Other opinions? Todd -- Todd Miller jmiller@stsci.edu STSCI / SSG (410) 338 4576

Looking at the code to PyArray_Free, I agree with Chris. Called to free a 2D array, I think that PyArray_Free leaks all of the row storage because ap->nd == 2, not 3:
* {%c++%} */ extern int PyArray_Free(PyObject *op, char *ptr) { PyArrayObject *ap = (PyArrayObject *)op; int i, n;
if (ap->nd > 2) return -1; if (ap->nd == 3) { n = ap->dimensions[0]; for (i=0; i<n; i++) { free(((char **)ptr)[i]); } } if (ap->nd >= 2) { free(ptr); } Py_DECREF(ap); return 0; } /* {%c++%} */
This has been broken since the beginning. I believe the documentation says as much. I've never used it because I always think of 2-D arrays as a block of data not as rows of pointers. It should be fixed, but no one's ever been interested enough to do it. -Travis Oliphant
participants (5)
-
clee@spiralis.merseine.nu
-
Pearu Peterson
-
Ray Drew
-
Todd Miller
-
Travis Oliphant