just how 'discontiguous' can a numpy array become?
For example say we have an original array a=np.random.random((512, 512, 3)) and we take a slice of that array b=a[:100, :100, :] now, b is discontiguous, but all if its memory is owned by a. Will there ever be a situation where a discontiguous array owns its own data? Or more generally, will discontiguous data alway have a contiguous parent? As far as i understand the numpy strided model, that could only be supported if len(strides) = ndim+1, I dont think numpy supports that. Don't get me wrong, I'm not making a feature request, just making sure I fully understand the array model so I can avoid trampling on memory. Cheers! Chris
On Sat, Oct 31, 2009 at 9:22 PM, Chris Colbert
Will there ever be a situation where a discontiguous array owns its own data? Or more generally, will discontiguous data alway have a contiguous parent?
Yes to Q1 and No to Q2. Discontiguous arrays are very easy to create: for example, if you say np.empty((10, 50), order="F"), you have a discontiguous array. I use this quite often when I need to interoperate with C or Fortran libraries - interoperation with other libraries/formats is another common source of discontiguous arrays, compared to memory views. David
Thanks for the response david.
Lemme rephrase the question a little bit.
It terms of actually memory space, will a numpy array ever point to a
chunk of memory that is not a continually running series of memory
addresses and also not a child of a continuous block of addresses.
Graphically can this every occur in hardware memory:
|--- a portion of array A ---|--- python object foo ---|--- The rest
of array A ----|
The reason I ask is because I am passing numpy arrays into another
library which uses a strided memory model, but not FULLY strided, and
I need to figure out
what checks I need to put in place to ensure that it doesnt trample on
memory. In the best case senario, it would just trample on the parent
array, in the worst case senario it would segfault.
Cheers,
Chris
On Sat, Oct 31, 2009 at 1:32 PM, David Cournapeau
On Sat, Oct 31, 2009 at 9:22 PM, Chris Colbert
wrote: Will there ever be a situation where a discontiguous array owns its own data? Or more generally, will discontiguous data alway have a contiguous parent?
Yes to Q1 and No to Q2.
Discontiguous arrays are very easy to create: for example, if you say np.empty((10, 50), order="F"), you have a discontiguous array. I use this quite often when I need to interoperate with C or Fortran libraries - interoperation with other libraries/formats is another common source of discontiguous arrays, compared to memory views.
David _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Sat, Oct 31, 2009 at 9:45 PM, Chris Colbert
Graphically can this every occur in hardware memory:
|--- a portion of array A ---|--- python object foo ---|--- The rest of array A ----|
No, this can never happen in the current numpy memory model, the allocated block has to be contiguous, and you can get to any item of the array from the data pointer (address of the first item) by N * item_size. That's a fundamental feature to enable fast access (you only need to jump once). David
Great!
Thanks for the help David!
On Sat, Oct 31, 2009 at 1:58 PM, David Cournapeau
On Sat, Oct 31, 2009 at 9:45 PM, Chris Colbert
wrote: Graphically can this every occur in hardware memory:
|--- a portion of array A ---|--- python object foo ---|--- The rest of array A ----|
No, this can never happen in the current numpy memory model, the allocated block has to be contiguous, and you can get to any item of the array from the data pointer (address of the first item) by N * item_size. That's a fundamental feature to enable fast access (you only need to jump once).
David _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Chris Colbert
-
David Cournapeau