[PYTHON MATRIX-SIG] More on Less Copying

Konrad Hinsen hinsen@ibs.ibs.fr
Wed, 12 Mar 1997 11:41:32 +0100


> Yes and no. There is nothing wrong with the interface to pickle, but
> the current implementation has an additional copy implied by
> tostring().

Indeed, I hear it every time I save a big array ;-)

> The read() method could treat the data in the file as a byte-stream
> defining a sequence of equal-sized elements without gaps or blocking.
> It could map between the array and the sequence in the same way that
> you map between an array and its ravel(). That way your file does not
> need to know the layout of an array.

Sounds reasonable, assuming that we don't have to deal with files
that themselves have weird layouts. But I can't think of any right
away.

> The problem is the format of the elements. You could survive on most
> modern machines by assuming that the elements were either in native
> format or byte-swapped native format. You would have a problem

I could certainly live with that restriction.

> To my mind, the sticky interface issue is whether to have read() do
> the byteswapping or not. If it does it in C, we can avoid another
> copy. I'd suggest something along the lines of:
> 
>     a = Numeric.new(shape, typecode)
>     a.read(file, order=...)
>     a.read("file", order=...)

Agreed.

> Operators like += need not break the imutable types; they could act
> as a shorthand and might save looking up the same name twice.

In that case we wouldn't have to worry about them, since they would
be mapped to the standard __add__ etc. and would not denote in-place
modification.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________