[PYTHON MATRIX-SIG] Ranks of operators
James Hugunin
jjh@mama-bear.lcs.mit.edu
Tue, 31 Oct 95 12:53:43 -0500
Yesterday I announced an alpha version of my C-based matrix object, and I
already have gotten significant feedback on it from a number of folks on the
list. One topic was brought up by Konrad Hinsen that I think merits
discussion by the full list. This is the issue of ranks of functions, and
generalizations of functions to outer, inner, reduce, etc. And yes, I know
that we've been over this before.
Here's what I'm pretty sure of:
1) We need an object that can hold a basic mathematical function in a form
that it can be efficiently (nearly as fast as hand-coded C) applied to a
matrix of raw basic types (ints and floats).
2) Many of these are binary functions (add, subtract, etc.). These
functions should be able to be applied as outer products, reductions and
accumulations also efficiently (inner products as well, but these involve
two binary functions, so I'll leave them out for now).
3) The basic notion of rank in J is a sound one. A n-dimensional matrix is
well viewed as a k-dimensional frame of (n-k)-dimensional cells. Thus a
"matrix" can be a 2d cell, or a 1d frame of 1d cells (vector of vectors) or
a 2d array of 0d numbers.
My new plan is the following. I want to throw this out to the list to see
if there are any significant complaints about this approach before I spend a
couple of days modifying my code to match this spec.
add is a python object of type ofunc. This means that the add object knows
how to add matrices together efficiently.
add(a,b) <--> a+b
Every basic object of type ofunc has the members "reduce", "outer",
"accumulate", ("inner"?). These members are themselves ofuncs, however,
they don't have the members given above.
[This is in contrast to these being methods of the ofunc object, my initial
implementation.]
ie. add.reduce is an ofunc where reduce(add, m) <-> add.reduce(m) (except
that the second form is a couple orders of magnitude faster).
Note: add.reduce.reduce is an error
Every object of type ofunc can have its rank specified using [] notation.
[This is in contrast to using a keyword specifier for rank during the call.]
ie. add.reduce[1] is an ofunc with rank 1.
Note: add.reduce[1][0] is an ofunc with rank 0
Negative ranks are allowed (as in J). These are similar to negative
indices in slices, and specify an offset from the rank of there argument.
ie. add[-1]([1,2,3],[[1,2],[4,5]]) <--> add[(0,1)]([1,2,3],[[1,2],[4,5]])
I'm open to suggestions as to how the rank of inner product should be treated.
Well, that's it for now. Let me know if this makes sense, or seems like a
bad idea.
-Jim
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================