[PYTHON MATRIX-SIG] Release 0.20 of matrix object is available

James Hugunin jjh@mama-bear.lcs.mit.edu
Fri, 1 Dec 95 18:39:41 -0500


I can't completely believe I finally finished this latest release.  I'm  
heading off for the python workshop on Monday, and I wanted to get this out  
before I left.

The whole package can be found at the same site as before, (if you don't  
know the site you need to send me mail saying that you agree to test and  
review the object and I'll give you the site).

The NEWS for this release follows.  The two major incompatible changes at  
the very beginning are why this release took so long (that and the fact that  
I have a few other demands on my time).  Please let me know what you think  
of these changes!

I finally feel good about the feature set and performance of the object.   
If nobody has any major complaints (or REALLY good suggestions like Yorick  
pseudo and rubber indices, curse them) then I don't expect the basic  
structure of the object to change much in the future.

As before, don't hesitate to send me your gripes, your bugs, and your  
praise (if ever merited).  However, I'll be gone for most of next week at  
the python workshop, so I might be slow in replying.

-Jim

**********
Release 0.20 of the matrix object

Major incompatible changes (I expect that these might elict some  
interesting discussion):

1) Matrix indexing now returns by reference to the original data, not by  
value.  As a side effect of this change, arbitrary sequences are not allowed  
in multidimensional indices, but only single indices, slices, RubberIndex  
and None.

Note: there is a new method, take, which will allow you to index a matrix  
with an arbitrary sequence as before.

This change was motivated both by the possible speed increases (about 40%  
for some code) and more importantly by issues of clarity of expression.  I  
couldn't come up with any other way to make the following hold:

m[0][1] is an efficient way to index a multi-dimensional array.
m[0,1] == m[0][1]
m[0,] == m[0]


2) No more ranks of operators, instead Yorick style pseudo indices are  
used.  As a side effect of this, outer product is now a convenience function  
rather than a method on ofuncs.

For functions of unbounded rank (currently the only kind of function  
supported by my omathmodule) Yorick pseudo indices support a superset of  
what was possible to express using ranks and outer products.  There is no  
fundamental reason not to have both pseudo indices and ranks, I just think  
that it's conceptually cleaner not to mix the two up.

Here's a fun thing you can do with pseudo indices that is a lot uglier with  
ranks and outer products:

    x=mrange(-1, 1, 2.0/m)[All,None]
    y=mrange(-1, 1, 2.0/n)
    r=sqrt(x**2+y**2)
    z=exp(-r**2)*cos(2*pi*r)

This is modified from a piece of Tom Schwaller's code for producing a 2d  
surface plot.  Notice that this is much more efficient than generating x and  
y as full 2d matrices.


Major improvements:

1) This new release is about 40% faster than 0.11 (on a benchmark code I  
was given by the folks at LBL).

2) No longer need to say a[[1,2,3]] for multidimensional indexing, now  
a[1,2,3] works just fine (thanks Konrad!)

3) Type coercion is performed more or less according to the same rules that  
python uses.  So I can add a matrix of ints to one of floats, and I wind up  
with a matrix of floats at the end.

4) Finally there's a matrixMultiply method for matrices that behaves  
reasonably for all combinations of matrix, vector, and scalar arguments.



Minor improvements:

1) pickling of matrices works (and uses a binary format with endianness  
labeled for both efficiency and portability).

2) The omath module supports trig functions as object methods (if m has  
method sin, then I can take sin(m) and get the sine of m.  This also works  
on matrices of objects.  omathmodule can be used now a a replacement for  
cmathmodule and mathmodule.

3) transpose now does the appropriate arbitrary permutation of dimensions.

4) More matrix methods, and better implementations of existing ones.



Notes

1) The code hasn't actually grown to more than double it's previous size.   
This is just the effect of including all of Konrad's patches to the python  
Grammar as complete files rather than diffs.  Hopefully, this will be able  
to be cleanly seperated from the matrix object, but I just don't have the  
time to deal with that right now.


Things I plan to fix ASAP

1) Integrate Chris Chase's grammar patches to replace Slice(None,None,2) with ::2.

2) Make matrixMultiply work on matrices larger than 2d (this requires a  
notion of rank).

3) Fix the memory leaks

4) Make some real documentation (I already have doc strings for all the  
matrix methods, I'm hoping to steal some code to convert this to "real"  
documentation at the workshop).


=================
MATRIX-SIG  - SIG on Matrix Math for Python

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