[Numpy-discussion] recarray2 re-visited

Francesc Alted falted at openlc.org
Mon Jan 20 11:02:02 EST 2003


Hi,

As I needed a byteswap() method for recarray, after a bit of hacking I've
made one myself. This is based on my own version of recarray to take
advantage of the _fields cache so as to both speed-up and simplify the new
code.

Basically, the new method takes a recarray, checking which columns are
numarray arrays and invoking their byteswap() method if needed. Easy, but
effective. Moreover, a _byteswap() and togglebyteorder() are provided to be
compatible with existing methods in NumArray objects.

As a plus, the recarray __str__ has been modified in order to allow a
printing having in mind the byteorder of the recarray, and improving the
speed of printing by a factor of 30, that can be handy in some situations.

Do with it whatever you want,

-- 
Francesc Alted
-------------- next part --------------
A non-text attachment was scrubbed...
Name: recarray2.py
Type: text/x-python
Size: 21435 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20030120/b7a180d9/attachment.py>
-------------- next part --------------
recarray shape in test ==> (10000,)
Assignment in recarray original
-------------------------------
Assign time: 1.24  Rows/s: 8064

Assignment in recarray modified
-------------------------------
Assign time: 0.16  Rows/s: 62499  Speed-up: 7.75

Selection in recarray original
------------------------------
This record pass the cut ==> 0.0 (row 0 )
This record pass the cut ==> 1.0 (row 1 )
This record pass the cut ==> 4.0 (row 2 )
Select time: 1.53  Rows/s: 6535

Selection in recarray modified
------------------------------
This record pass the cut ==> 0.0 (row 0 )
This record pass the cut ==> 1.0 (row 1 )
This record pass the cut ==> 4.0 (row 2 )
Select time: 0.15  Rows/s: 66666  Speed-up: 10.2

Printing in recarray original
------------------------------
Print time: 18.11  Rows/s: 552

Printing in recarray modified
------------------------------
Print time: 0.63  Rows/s: 15872  Speed-up: 28.746

-------------- next part --------------
A non-text attachment was scrubbed...
Name: recarray2-test.py
Type: text/x-python
Size: 2946 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20030120/b7a180d9/attachment-0001.py>


More information about the NumPy-Discussion mailing list