Travis,
Perhaps you can add this rationale to the PEP? It seems helpful and
might stave off future confusion.
--Guido
On Jan 23, 2008 8:17 AM, Travis Oliphant
Thomas Heller wrote:
Hi Travis,
The pep contains this sample:
""" Nested array ::
struct { int ival; double data[16*4]; } """i:ival: (16,4)d:data: """ """
I think it is wrong and must be changed to the following; is this correct?
""" Nested array ::
struct { int ival; double data[16][4]; } """i:ival: (16,4)d:data: """ """
I responded off list to this email and wanted to summarize my response for others to peruse.
Basically, the answer is that the struct syntax proposed for multi-dimensional arrays is not intended to mimic how the C-compiler handles statically defined C-arrays (i.e. the pointer-to-pointers style of multi-dimensional arrays). It is intended to handle the contiguous-block-of-data style of multi-dimensional arrays that NumPy uses.
I wanted to avoid 2-d static arrays in the examples because it gets confusing and AFAIK the layout of the memory for a double data[16][4] is the same as data[16*4]. The only difference is how the C-compiler translates data[4][3] and data[4].
The intent of the struct syntax is to handle describing memory. The point is not to replicate how the C-compiler deals with statically defined N-D arrays. Thus, even though the struct syntax allows *communicating* the intent of a contiguous block of memory inside a structure as an N-d array, the fundamental memory block is the equivalent of a 1-d array in C.
So, I think the example is correct (and intentional).
-Travis O.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (home page: http://www.python.org/~guido/)