[PYTHON MATRIX-SIG] Attributes vs. methods

James Hugunin jjh@Goldilocks.LCS.MIT.EDU
Fri, 19 Jan 96 14:53:55 EST

Your last line made me realize that there is essentially a bug in the
current implementation of the matrix class (I just wasn't thinking
clearly) and this might be coloring the analysis.

> So, my conclusion is that if x.shape in the matrix class is an
> attribute, and we don't want any user to do x.shape=something, we should
> call it _shape, and supply an x.shape() for normal access.

For types written in C (as the array type is) access times between
attributes and function calls are really indistinguishable, so the
issue is whether to use x.shape() to return the current shape and
x.reshape(new_shape) to set a new one, or to use x.shape and
x.shape=new_shape instead (or maybe both).  The fact that you can't do
x.shape=new_shape in the current implementation is more an accident
than a matter of design.  It would be very easy to make this work
properly (using the set_attribute facilities of python).

Here's what I propose (after thinking about things one more time):

a.typecode, a.itemsize, a.contiguous should all become methods,
because setting these values makes no sense.

a.shape, a.real, and a.imaginary should be implemented as pseudo-data in
a self-consistent manner.  This means that I'll fix the code so that
a.shape = new_shape will work properly.

Does this sound reasonable?


MATRIX-SIG  - SIG on Matrix Math for Python

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