[PEP draft 2] Adding new math operators

Konrad Hinsen hinsen at cnrs-orleans.fr
Wed Aug 9 10:05:27 EDT 2000


Gregory Lielens <gregory.lielens at fft.be> writes:

> As I understand it, Huaiyu is saying that within a particular package
> (lets choose Matpy, oriented toward matrix behavior), the all operations
> must return matrix type (or array type, within NumPy), regardless of the
> type of the operands. The type of operands will only be used to indicate

In OO systems, it is perfectly normal that the type of a result should
depend on the type of the operands. And I wouldn't think of A.E as
being a modifier of A, but rather as another object type which happens
to contain the same data (and therefore I'd prefer to call it A.array
or something similar).

Maybe what I am proposing is then something sufficiently different from 
Huaiyu's proposal. So let me state it in my own words. There is

1) a class/type "array", which behaves like the current NumPy arrays
2) a class/type "matrix", which behaves like the current MatPy matrices

Operations between arrays work elementwise and return arrays. Operations
between matrices work as matrix operations and return matrices. Mixed
operations should probably raise an exception, but that remains to
be discussed.

Every matrix object has an attribute "array" whose value is an array
containing equivalent data. Every 1D and 2D array has an attribute
"matrix" whose value is a matrix object containing equivalent data
(of course the data part would be shared, not copied).

This scheme should work find as long as conversions between matrices
and arrays occur infrequently. This is certainly the case in all of my
own applications, which typically construct an array using elementwise
operations and at some point convert it to a matrix that is used in
matrix operations.

So the question is: for which real-life cases would this approach become
too cumbersome to be useful?
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------



More information about the Python-list mailing list