Re: [pypy-dev] Shift and typed array
Alright, thanks again! On Mon, Apr 4, 2016 at 3:58 PM, Maciej Fijalkowskiwrote: > 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**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, 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 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 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: >>> >>> 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 Fijalkowski >>> wrote: 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" :-) Cheers, fijal On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen wrote: > 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: > > a[0] = (2**63 << 1) & (2**64 - 1) > > My question is, when I know that the result will be stored in > `array.array` anyway, how to prevent the promotion to long integers? > What is the most performat way to perform such calculations? Is PyPy > able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? > > I mean, in C I wouldn't have to worry about it as everything above the > 63rd bit will be simply cut off. I would like to help PyPy to generate > the best possible code, does anyone have some suggestions please? > > Thanks! > ___ > pypy-dev mailing list > pypy-dev@python.org > https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
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 Larsenwrote: > 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 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 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 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: > > 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 Fijalkowski > wrote: >> 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" :-) >> >> Cheers, >> fijal >> >> On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen >> wrote: >>> 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: >>> >>> a[0] = (2**63 << 1) & (2**64 - 1) >>> >>> My question is, when I know that the result will be stored in >>> `array.array` anyway, how to prevent the promotion to long integers? >>> What is the most performat way to perform such calculations? Is PyPy >>> able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? >>> >>> I mean, in C I wouldn't have to worry about it as everything above the >>> 63rd bit will be simply cut off. I would like to help PyPy to generate >>> the best possible code, does anyone have some suggestions please? >>> >>> Thanks! >>> ___ >>> pypy-dev mailing list >>> pypy-dev@python.org >>> https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
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 Fijalkowskiwrote: > 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 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 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: 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 Fijalkowski wrote: > 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" :-) > > Cheers, > fijal > > On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen wrote: >> 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: >> >> a[0] = (2**63 << 1) & (2**64 - 1) >> >> My question is, when I know that the result will be stored in >> `array.array` anyway, how to prevent the promotion to long integers? >> What is the most performat way to perform such calculations? Is PyPy >> able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? >> >> I mean, in C I wouldn't have to worry about it as everything above the >> 63rd bit will be simply cut off. I would like to help PyPy to generate >> the best possible code, does anyone have some suggestions please? >> >> Thanks! >> ___ >> pypy-dev mailing list >> pypy-dev@python.org >> https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
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 Larsenwrote: > 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 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: >>> >>> 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 Fijalkowski wrote: 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" :-) Cheers, fijal On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen wrote: > 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: > > a[0] = (2**63 << 1) & (2**64 - 1) > > My question is, when I know that the result will be stored in > `array.array` anyway, how to prevent the promotion to long integers? > What is the most performat way to perform such calculations? Is PyPy > able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? > > I mean, in C I wouldn't have to worry about it as everything above the > 63rd bit will be simply cut off. I would like to help PyPy to generate > the best possible code, does anyone have some suggestions please? > > Thanks! > ___ > pypy-dev mailing list > pypy-dev@python.org > https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
but if you dont actually overflow, the cost is really low btw On Mon, Apr 4, 2016 at 3:49 PM, Maciej Fijalkowskiwrote: > 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 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 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: 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 Fijalkowski wrote: > 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" :-) > > Cheers, > fijal > > On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen wrote: >> 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: >> >> a[0] = (2**63 << 1) & (2**64 - 1) >> >> My question is, when I know that the result will be stored in >> `array.array` anyway, how to prevent the promotion to long integers? >> What is the most performat way to perform such calculations? Is PyPy >> able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? >> >> I mean, in C I wouldn't have to worry about it as everything above the >> 63rd bit will be simply cut off. I would like to help PyPy to generate >> the best possible code, does anyone have some suggestions please? >> >> Thanks! >> ___ >> pypy-dev mailing list >> pypy-dev@python.org >> https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
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 Fijalkowskiwrote: > 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: >> >> 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 Fijalkowski wrote: >>> 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" :-) >>> >>> Cheers, >>> fijal >>> >>> On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen wrote: 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: a[0] = (2**63 << 1) & (2**64 - 1) My question is, when I know that the result will be stored in `array.array` anyway, how to prevent the promotion to long integers? What is the most performat way to perform such calculations? Is PyPy able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? I mean, in C I wouldn't have to worry about it as everything above the 63rd bit will be simply cut off. I would like to help PyPy to generate the best possible code, does anyone have some suggestions please? Thanks! ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
so numpy64 will give you wrap-around arithmetics. What else are you looking for? :-) On Mon, Apr 4, 2016 at 3:38 PM, Tuom Larsenwrote: > 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 Fijalkowski wrote: >> 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" :-) >> >> Cheers, >> fijal >> >> On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen wrote: >>> 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: >>> >>> a[0] = (2**63 << 1) & (2**64 - 1) >>> >>> My question is, when I know that the result will be stored in >>> `array.array` anyway, how to prevent the promotion to long integers? >>> What is the most performat way to perform such calculations? Is PyPy >>> able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? >>> >>> I mean, in C I wouldn't have to worry about it as everything above the >>> 63rd bit will be simply cut off. I would like to help PyPy to generate >>> the best possible code, does anyone have some suggestions please? >>> >>> Thanks! >>> ___ >>> pypy-dev mailing list >>> pypy-dev@python.org >>> https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
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 Fijalkowskiwrote: > 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" :-) > > Cheers, > fijal > > On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen wrote: >> 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: >> >> a[0] = (2**63 << 1) & (2**64 - 1) >> >> My question is, when I know that the result will be stored in >> `array.array` anyway, how to prevent the promotion to long integers? >> What is the most performat way to perform such calculations? Is PyPy >> able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? >> >> I mean, in C I wouldn't have to worry about it as everything above the >> 63rd bit will be simply cut off. I would like to help PyPy to generate >> the best possible code, does anyone have some suggestions please? >> >> Thanks! >> ___ >> pypy-dev mailing list >> pypy-dev@python.org >> https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Shift and typed array
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" :-) Cheers, fijal On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsenwrote: > 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: > > a[0] = (2**63 << 1) & (2**64 - 1) > > My question is, when I know that the result will be stored in > `array.array` anyway, how to prevent the promotion to long integers? > What is the most performat way to perform such calculations? Is PyPy > able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? > > I mean, in C I wouldn't have to worry about it as everything above the > 63rd bit will be simply cut off. I would like to help PyPy to generate > the best possible code, does anyone have some suggestions please? > > Thanks! > ___ > pypy-dev mailing list > pypy-dev@python.org > https://mail.python.org/mailman/listinfo/pypy-dev ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
[pypy-dev] Shift and typed array
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: a[0] = (2**63 << 1) & (2**64 - 1) My question is, when I know that the result will be stored in `array.array` anyway, how to prevent the promotion to long integers? What is the most performat way to perform such calculations? Is PyPy able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode? I mean, in C I wouldn't have to worry about it as everything above the 63rd bit will be simply cut off. I would like to help PyPy to generate the best possible code, does anyone have some suggestions please? Thanks! ___ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev