Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread eryk sun
On Sun, Sep 18, 2016 at 3:55 AM, Chris Angelico  wrote:
> On Sun, Sep 18, 2016 at 1:16 PM, Lawrence D’Oliveiro
>  wrote:
>> On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote:
>>> However, I see that MicroPython [1] has been ported to 16-bit
>>> PIC microcontrollers. An int should be 16-bit in that case.
>>>
>>> [1]: https://github.com/micropython/micropython
>>
>> From the readme: “MicroPython implements the entire Python 3.4 syntax...”
>>
>> Darn. I don’t know whether to applaud or grit my teeth...
>
> What do you mean? It's not perfectly up-to-date with respect to
> CPython, but most alternate implementations lag a bit.
>
> However, it doesn't appear to have an 'itemsize' on its array.
>
 a=array.array("l", (0,))
 dir(a)
> ['append', 'extend']
>
> Not sure what that means about its sizes.

MicroPython's array and struct modules use a common mp_binary_get_size function:

https://github.com/micropython/micropython/blob/v1.8.4/py/binary.c#L37

The array module uses native ("@") sizes, so the size of "i" and "I"
is sizeof(int).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Chris Angelico
On Sun, Sep 18, 2016 at 1:16 PM, Lawrence D’Oliveiro
 wrote:
> On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote:
>> However, I see that MicroPython [1] has been ported to 16-bit
>> PIC microcontrollers. An int should be 16-bit in that case.
>>
>> [1]: https://github.com/micropython/micropython
>
> From the readme: “MicroPython implements the entire Python 3.4 syntax...”
>
> Darn. I don’t know whether to applaud or grit my teeth...

What do you mean? It's not perfectly up-to-date with respect to
CPython, but most alternate implementations lag a bit.

However, it doesn't appear to have an 'itemsize' on its array.

>>> a=array.array("l", (0,))
>>> dir(a)
['append', 'extend']

Not sure what that means about its sizes.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Lawrence D’Oliveiro
On Sunday, September 18, 2016 at 2:34:46 PM UTC+12, eryk sun wrote:
> However, I see that MicroPython [1] has been ported to 16-bit
> PIC microcontrollers. An int should be 16-bit in that case.
> 
> [1]: https://github.com/micropython/micropython

From the readme: “MicroPython implements the entire Python 3.4 syntax...”

Darn. I don’t know whether to applaud or grit my teeth...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread eryk sun
On Sun, Sep 18, 2016 at 12:17 AM, Lawrence D’Oliveiro
 wrote:
>
> why does the documentation suggest that “i” and “I” could have an item size 
> of 2?

SHRT_MAX <= INT_MAX <= LONG_MAX <= LLONG_MAX. short int and int  ("h"
and "i") are at least 16-bit. long int ("l") is at least 32-bit. long
long int ("q") is at least 64-bit.

AFAIK, however, an int is 32-bit on all platforms supported by
CPython. However, I see that MicroPython [1] has been ported to 16-bit
PIC microcontrollers. An int should be 16-bit in that case.

[1]: https://github.com/micropython/micropython
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Lawrence D’Oliveiro
On Saturday, September 17, 2016 at 3:47:15 PM UTC+12, I wrote:
> >>> a = array.array("I", (0,))
> >>> a.itemsize
> 4
> >>> a = array.array("L", (0,))
> >>> a.itemsize
> 8

Let me rephrase the question. It seems clear 
 that “l” and “L” are not be 
relied on. As far as I can tell, on all current Python implementations, “i” and 
“I” have item sizes of 4, while “q” and “Q” have item sizes of 8.

Can anybody offer any counterexamples? If not, why does the documentation 
suggest that “i” and “I” could have an item size of 2?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Lawrence D’Oliveiro
On Saturday, September 17, 2016 at 11:54:10 PM UTC+12, Christian Heimes wrote:
>
> ... on Windows (32 and 64bit), a long is always 32bit and an array with
> datatype "L" has itemsize 4.

Ah, I forgot the LLP64 nonsense...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: array.itemsize: Documentation Versus Reality

2016-09-17 Thread Christian Heimes
On 2016-09-17 05:47, Lawrence D’Oliveiro wrote:
> >>> a = array.array("I", (0,))
> >>> a.itemsize
> 4
> >>> a = array.array("L", (0,))
> >>> a.itemsize
> 8
> 
> According to , the “minimum 
> size” should be 2 and 4 respectively. It further says:
> 
> The actual representation of values is determined by the machine
> architecture (strictly speaking, by the C implementation).
> The actual size can be accessed through the itemsize attribute.
> 
> Are there any C compilers still in common use where the values will not be 4 
> and 8, as above?

Yes, on Windows (32 and 64bit), a long is always 32bit and an array with
datatype "L" has itemsize 4.

Christian


-- 
https://mail.python.org/mailman/listinfo/python-list


array.itemsize: Documentation Versus Reality

2016-09-16 Thread Lawrence D’Oliveiro
>>> a = array.array("I", (0,))
>>> a.itemsize
4
>>> a = array.array("L", (0,))
>>> a.itemsize
8

According to , the “minimum size” 
should be 2 and 4 respectively. It further says:

The actual representation of values is determined by the machine
architecture (strictly speaking, by the C implementation).
The actual size can be accessed through the itemsize attribute.

Are there any C compilers still in common use where the values will not be 4 
and 8, as above?
-- 
https://mail.python.org/mailman/listinfo/python-list