[Python-Dev] Error in PEP3118?

Thomas Heller theller at ctypes.org
Wed Jan 23 20:03:55 CET 2008


Travis Oliphant schrieb:

[...]

> 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).

Sorry, I do not think so.  If you use a 2-d array in the example, you
must describe it correctly.  The difference between this pep and the old
buffer interface is that the pep allows to describe both how the compiler
sees the memory block plus the size and layout of the memory block, while
the old buffer interface only describes single-segment memory blocks.
And 'double data[16][4]' *is* a single memory block containing a 2-d array,
and *not* an array of pointers.

---

Here is another typo (?) in the pep; I think it should be changed:

Index: pep-3118.txt
===================================================================
--- pep-3118.txt	(revision 60037)
+++ pep-3118.txt	(working copy)
@@ -338,7 +338,7 @@
 
 ``len``
     the total bytes of memory the object uses.  This should be the
-    same as the product of the shape array multiplied by the number of
+    same as the length of the shape array multiplied by the number of
     bytes per item of memory.
 
 ``readonly``


After all, imo there's a lot to do to fully implement the pep for python 2.6.

Thomas



More information about the Python-Dev mailing list