[PYTHON MATRIX-SIG] Some thoughts on default axes.

tim@lassi.ece.uiuc.edu tim@lassi.ece.uiuc.edu
Wed, 21 Aug 1996 23:23:43 -0500


I have an idea about default axes. I'm not entirely satisfied with it,
but its been bugging me for a week or so, so I figured I'd let it bug
you'all instead.

To the best of my recollection, the arguments about default axes go
like this (apologies in advance for any misrepresentation of someone's
posistion):

Jim Hugunin:
	Remembering what are the default axes is too comlicated. We
	should pick a single default axes and stick with it. (With
	perhaps 1 or 2 exceptions for some weird functions).

Konrad Hinsen:
	It's absurd to make people type axis=? for a whole class of
	functions that normally use an axis other than the
	default. The array functions divide naturally into two
	classes, those that normally use axis=0 and those that use the
	last possible axis (-1 for vector ops, -2 for 2d matrix ops,
	etc.). Therefore, it should be possible to figure out with a
	minimum of effort what the natural axis is.

I agree with both these posistions! It would be annoying to have to
type axis=0 (or conversely axis=-1) all over the place if there's a
single default axis. On the other hand, I'm not sure the difference
between structural and non-strucural matrix ops is clear for all
cases. Particularly for people new to NumPy. And, some people may have
different ideas about what is the natural axis for a particular
operation (Carlos said something about this, I think?).

A problem I see with both posistions, particuarly Jim's, is that there
will be a temptation to redefine the functions when the desired
default axis  with the default, e.g (as Jim posted),

def fft(f):
	fft(f, axis=-1)

Which leads to a problem with code readability for people who don't
use your conventions.

Some sort of naming convention could provide a way out of this
box. That is, indicate by the name of the function what the default
axis is, e.g.,

fft(f)  <=> fft(f,axis=0)
fft_(f) <=> fft(f,axis=-1)     # _ <=> farther away <=> -1 (or -2...)
	
A complete set of both functions could be provided, or just guidelines
on how people are to name their own should they need the other axis.

Pros: 
	1) No need to type axis=? for what should be the default case.
	2) Obvious at a glance what the default axis is.
	3) Removes incentive to create private versions of functions.

Cons:
	1) Aesthetics?
	2) Requires a certain amount of function renaming.
	3) Doesn't help with dot (**).
	4) ....

Opinions?



________________________________________________________________


(**) Another naming convention that is too ugly too live, but would
take care of dot, is:
dot00(f,g) = dot(f,g,axis=(0,0))
dot01(f,g) = dot(f,g,axis=(0,-1))
fft1(f) = fft(f,axis=-1)
etc.


-- 
	-tim

+--------------------------------------------------------------------+
| Tim Hochberg               Ultrahigh Speed Digital Electronics Lab |
| tim@lassi.ece.uiuc.edu              University of Illinois         |
| http://dogbert.ece.uiuc.edu/~tim         (217) 333-6014            |
+--------------------------------------------------------------------+

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

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