PEP 3118 AVVERTENZA Quando si utilizza l'array Ctypes come Array Numpy
Domanda
Ricevo il seguente messaggio di avviso quando provo a usare un array Ctypes come array numpy:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes, numpy
>>> TenByteBuffer = ctypes.c_ubyte * 10
>>> a = TenByteBuffer()
>>> b = numpy.ctypeslib.as_array(a)
C:\Python27\lib\site-packages\numpy\ctypeslib.py:402: RuntimeWarning: Item size
computed from the PEP 3118 buffer format string does not match the actual item s
ize.
return array(obj, copy=False)
>>> b
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=uint8)
Tuttavia, il codice sembra funzionare. È una cattiva idea ignorare questo avvertimento?
Contesto: chiamo una C DLL che produce dati in tempo reale. Devo passare la DLL una serie di buffer per contenere i dati. Mentre aspettavo che il prossimo buffer si riempia, mi piacerebbe elaborare il buffer più recente con Numpy e salvare il risultato. Sto generando i buffer con codice come sopra e le cose sembrano funzionare, ma non voglio spazzare un problema importante sotto il tappeto.
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow