[Numpy-discussion] Bizarre errors with byteswapping, complex256, PPC

Charles R Harris charlesr.harris@gmail....
Wed Jun 20 17:05:05 CDT 2012


On Wed, Jun 20, 2012 at 4:00 PM, Matthew Brett <matthew.brett@gmail.com>wrote:

> Hi,
>
> On Wed, Jun 20, 2012 at 1:56 PM, Travis Oliphant <travis@continuum.io>
> wrote:
> > This looks like a problem with comparisons of floating point numbers
> rather than a byteswapping problem per-say.   Try to use an almost equal
> comparison instead.
>
> Is that right - that the byteswapped versions might not be strictly
> equal to identical numbers but not byteswapped?
>
> But I should maybe have been clearer - they also subtract wrongly:
>
> <script>
> import numpy as np
>
> arr = np.arange(10, dtype=np.complex256)
> bs_arr = arr.byteswap().newbyteorder('S')
> print arr
> print bs_arr
> print arr - bs_arr
> print arr - bs_arr
> print arr - bs_arr
> </script>
>
> (np-devel)[mb312@joshlegacy ~/tmp]$ python funny_bs.py
> [ 0.0+0.0j  1.0+0.0j  2.0+0.0j  3.0+0.0j  4.0+0.0j  5.0+0.0j  6.0+0.0j
>  7.0+0.0j  8.0+0.0j  9.0+0.0j]
> [ 0.0+0.0j  1.0+0.0j  2.0+0.0j  3.0+0.0j  4.0+0.0j  5.0+0.0j  6.0+0.0j
>  7.0+0.0j  8.0+0.0j  9.0+0.0j]
> [ 0.0+0.0j  1.0+0.0j  2.0+0.0j  3.0+0.0j  4.0+0.0j  5.0+0.0j  6.0+0.0j
>  7.0+0.0j  8.0+0.0j  9.0+0.0j]
> [ 0.0+0.0j  1.0+0.0j  2.0+0.0j  3.0+0.0j  4.0+0.0j  5.0+0.0j  6.0+0.0j
>  7.0+0.0j  8.0+0.0j  9.0+0.0j]
> [ 0.0+0.0j  1.0+0.0j  2.0+0.0j  3.0+0.0j  4.0+0.0j  5.0+0.0j  6.0+0.0j
>  7.0+0.0j  8.0+0.0j  9.0+0.0j]
>
> (wrong)
>
> (np-devel)[mb312@joshlegacy ~/tmp]$ python funny_bs.py
> [ 0.0+0.0j  1.0+0.0j  2.0+0.0j  3.0+0.0j  4.0+0.0j  5.0+0.0j  6.0+0.0j
>  7.0+0.0j  8.0+0.0j  9.0+0.0j]
> [ 0.0+0.0j  1.0+0.0j  2.0+0.0j  3.0+0.0j  4.0+0.0j  5.0+0.0j  6.0+0.0j
>  7.0+0.0j  8.0+0.0j  9.0+0.0j]
> [ 0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j
>  0.0+0.0j  0.0+0.0j  0.0+0.0j]
> [ 0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j
>  0.0+0.0j  0.0+0.0j  0.0+0.0j]
> [ 0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j  0.0+0.0j
>  0.0+0.0j  0.0+0.0j  0.0+0.0j]
>
> (right)
>
> See you,
>
>
Long doubles on PPC consist of two doubles, so I expect you need to swap
both doubles instead of 16 bytes. Strictly speaking, numpy doesn't support
non ieee floats.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120620/23e11da4/attachment-0001.html 


More information about the NumPy-Discussion mailing list