Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Tuom Larsen
Alright, thanks again! On Mon, Apr 4, 2016 at 3:58 PM, Maciej Fijalkowski wrote: > you can write a if in_pypy wrapper that uses __pypy__.intops or > something, but for exactly the same code is hard to do better. We can > think about adding some optimizations that do that btw > > > On Mon, Apr 4,

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Maciej Fijalkowski
you can write a if in_pypy wrapper that uses __pypy__.intops or something, but for exactly the same code is hard to do better. We can think about adding some optimizations that do that btw On Mon, Apr 4, 2016 at 3:53 PM, Tuom Larsen wrote: > So other than numpy, do you think: > > a[0] = (2**

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Tuom Larsen
So other than numpy, do you think: a[0] = (2**63 << 1) & (2**64 - 1) is the best way I can do? On Mon, Apr 4, 2016 at 3:52 PM, Tuom Larsen wrote: > Yes, I just want to write code which is portable (as for example that > `& ...`) but still favors PyPy. > > On Mon, Apr 4, 2016 at 3:49 PM, Mac

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Tuom Larsen
Yes, I just want to write code which is portable (as for example that `& ...`) but still favors PyPy. On Mon, Apr 4, 2016 at 3:49 PM, Maciej Fijalkowski wrote: > right, so there is no way to get wrap-around arithmetics in cpython > without modifications > > On Mon, Apr 4, 2016 at 3:48 PM, Tuom La

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Maciej Fijalkowski
right, so there is no way to get wrap-around arithmetics in cpython without modifications On Mon, Apr 4, 2016 at 3:48 PM, Tuom Larsen wrote: > I would like to avoid numpy, if possible. Even if it might be bundled > with PyPy (is it?) I still would like the code to run in CPython with > no depende

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Maciej Fijalkowski
but if you dont actually overflow, the cost is really low btw On Mon, Apr 4, 2016 at 3:49 PM, Maciej Fijalkowski wrote: > right, so there is no way to get wrap-around arithmetics in cpython > without modifications > > On Mon, Apr 4, 2016 at 3:48 PM, Tuom Larsen wrote: >> I would like to avoid nu

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Tuom Larsen
I would like to avoid numpy, if possible. Even if it might be bundled with PyPy (is it?) I still would like the code to run in CPython with no dependencies. On Mon, Apr 4, 2016 at 3:45 PM, Maciej Fijalkowski wrote: > so numpy64 will give you wrap-around arithmetics. What else are you > looking fo

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Maciej Fijalkowski
so numpy64 will give you wrap-around arithmetics. What else are you looking for? :-) On Mon, Apr 4, 2016 at 3:38 PM, Tuom Larsen wrote: > You mean I should first store the result into numpy's `int64`, and > then to `array.array`? Like: > > x = int64(2**63 << 1) > a[0] = x > > Or: > >

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Tuom Larsen
You mean I should first store the result into numpy's `int64`, and then to `array.array`? Like: x = int64(2**63 << 1) a[0] = x Or: x = int64(2**63) x[0] = x << 1 What the "real types" goes, is this the only option? Thanks in any case! On Mon, Apr 4, 2016 at 3:32 PM, Maciej Fi

Re: [pypy-dev] Shift and typed array

2016-04-04 Thread Maciej Fijalkowski
one option would be to use integers from _numpypy module: from numpy import int64 after installing numpy. There are obscure ways to get it without installing numpy. Another avenue would be to use __pypy__.intop.int_mul etc. Feel free to complain "no, I want real types that I can work with" :-)

[pypy-dev] Shift and typed array

2016-04-04 Thread Tuom Larsen
Hello! Suppose I'm on 64-bit machine and there is an `a = arrar.array('L', [0])` (item size is 8 bytes). In Python, when an integer does not fit machine width it gets promoted to "long" integer of arbitrary size. So this will fail: a[0] = 2**63 << 1 To fix this, one could instead write: