[PYTHON MATRIX-SIG] [firstname.lastname@example.org: Some subtlety in
reaching items of a matrix]
Fri, 10 Nov 95 12:08:37 -0500
> For a rank-3 matrix `c', there are some subtle difference between
> C and c[(0,1)]. The following example illustrates this:
First, I agree completely, this is terrible. Nevertheless, here's my
Returning a matrix by-copy is always the best thing to do conceptually (I
guess I've played with too many functional languages). I find it a lot
easier to think about my matrix code if I don't have to worry about
references to objects.
On the other hand, if you want to allow python indexing of the style
a[i][j] to function with any sort of reasonable efficiency, then you need to
have a[i] return by reference.
I'm perfectly willing to be convinced to change over to always returning
matrices by reference (with the understanding that the code will have many
more bugs, and the understanding that if a = Matrix(1,2,3) then a will
return not a python float, but a 0d matrix with the same sort of reference
style semantics) or to always returning arrays by copy with the
understanding that a[i][j] will potentially be an incredibly inefficient way
of accessing an array element.
I'm not happy with my chosen compromise. I just can't come up with a
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: email@example.com
administrivia to: firstname.lastname@example.org