[Numpy-discussion] byteswap() not doing anything !?

Francesc Alted falted at openlc.org
Thu Feb 20 10:54:07 EST 2003


A Dijous 20 Febrer 2003 15:36, Todd Miller va escriure:
>
> The current "plan" is that byteswap() and _byteswap() will both behave
> as _byteswap() does now;  i.e., they will be Numeric compatible synonyms.
>
> An explict (extra) call to togglebyteorder() will then produce the
> current behavior.  The meaning of _byteorder will be unchanged.
>
> Please let me know if you see any snags in the plan.

Well, I've been doing some tests, and I think I'll be able to produce a
version of my code that will be compatible with numarray 0.4 and future
versions (I'm just no using byteswap() at all).

However, I've detected a side effect on this change: copy() method is
broken now in CVS:

In [131]: a=numarray.array([1,2])

In [132]: a.togglebyteorder()

In [133]: b=a.copy()

In [134]: a
Out[134]: array([16777216, 33554432])

In [135]: b
Out[135]: array([1, 2])

In [136]: a._byteorder
Out[136]: 'big'

In [137]: b._byteorder
Out[137]: 'big'

so, you don't get a well-behaved copy of original array a in b

I think the next patch should cure it:

--- numarray.py Tue Feb 18 16:35:16 2003
+++ /usr/local/lib/python2.2/site-packages/numarray/numarray.py Thu Feb 20 
19:36:07 2003
@@ -609,6 +609,7 @@
         c._type = self._type
         if self.isbyteswapped():
             c.byteswap()
+           c.togglebyteorder()
         return c


-- 
Francesc Alted




More information about the NumPy-Discussion mailing list