[PYTHON MATRIX-SIG] Re: Version 2.0

Hinsen Konrad hinsenk@ere.umontreal.ca
Wed, 13 Dec 1995 14:04:10 -0500


   This is true.  You have to import omath somehow, or matrices do not have  
   any numeric behavior (notice that if you use import Matrix, or from Matrix  
   import *. this gets done for you).  Here are the reasons...

If omath is essential to the module "matrix", then this module should
do the import. All it takes is
   PyImport_ImportModule("omath");
somewhere in the module initialization.

   > b. Matrix(1,2,3) produces a Matrix_l, or at least that is what it
   >     claims it is. Should be a Matrix_i?

   This will be seen as a BIG issue, and I'll write more about it later (I've  
   a few other demands on my time right now).

   It should either be Matrix_b (a matrix of bytes, because 1,2, and 3 can all  
   be stored in a single byte) or it should be Matrix_l (a matrix of longs  
   because a python integer technically holds a C long).

I'd vote for "long" ("IntegerMatrix"). The idea is that the existence
of all the types that Python normally doesn't have should be hidden
as far as possible; those who need the smaller types to save memory
should be the only ones who have to know about it.

This guarantees that code like
   x = Matrix(a,b)
   x[0] = c
will always work correctly as long as a, b, and c are of the same
Python type. If the "smallest possible" rule were used, then
this would show an unexpected behaviour if a=1, b=2 and c=10000.

   > c. I preferred the [1.,2.,3.] rather than the Matrix_d(...). A lot. A
   > whole lot. Provide a query function for those who really want to know
   > the flavor of matrix.

I agree!

   Anybody who has good ideas about how to print a matrix can go in and modify  
   this python function to get whatever print behavior they like.  If you come  
   up with a good print function, send it to me, and I'll include the best one  
   in the next release.

The first contest in this SIG! ;-)
But before everyone starts coding essentially the same stuff,
let's first discuss what the output format should look like and
then search a volunteer to do the implementation.

The two esential problems to be solved are:
1) How to print arrays of rank > 2.
2) How to deal with large arrays that don't fit on the screen.

Personally I have a certain bias towards the APL output format,
which is based on the following principles:
- all elements of an array are printed using the same format,
  to make them line up nicely
- there is no border decoration whatsoever, just elements
  separated by spaces
- one-dimensional arays are printed in a line, two-dimensional
  arrays as a sequence of lines, N-dimensional arrays as
  sequences of (N-1)-dimensional arrays separated by
  (N-2) blank lines
- lines longer than the terminal width (an adjustable parameter)
  are wrapped to the following line with an indentation of
  six characters
This format is space-saving and very readable. The only
problem is that there is no visible difference between
a scalar and a higher-dimensional array with exactly
one element, but this has not turned out to be a problem
in practice.

   And here I decided to respond to your message in order to stay out of the  
   naming issue.  I like both approaches, and I'm waiting to see what things  
   look like after the dust has settled.

My suggestion for constructors:

  Array(sequence, typecode=None)
   transforms the sequence into an array of the given
   typecode; if the typecode is None, it determines
   the type by itself. Typecodes can be letters or
   type objects (as returned by type()).

  IntegerArray(sequence)
   transforms the given sequence into an array of
   integers.

  ShortIntegerArray(sequence)
   transforms the given sequence into an array of
   C-integers.

and so on for the other specific types. Output of repr() should be
IntegerArray() etc., output of str() should be the "pretty" format to
be discussed separately.

-------------------------------------------------------------------------------
Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)
-------------------------------------------------------------------------------

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

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