[PYTHON MATRIX-SIG] a few thoughts

Hinsen Konrad hinsenk@ere.umontreal.ca
Thu, 19 Oct 1995 18:05:37 -0400


   1. Usage of the matrix operators is perhaps 1% or less of the usage of
   the element-wise numbers. This is because when two-dimensional

That raises the question of what kinds of applications were typically
involved. I can think of several that would make heavy use of
arrays as operators (e.g. all kinds of quantum mechanics). Maybe
they were just underrepresented among your users.

   fast that can talk to C or Fortran. I timed this class doing x+x where
   x was 100,000 elements long, and it was about 1000 times slower than
   a simple C extension to Python and even ten times slower than doing a for 
   loop in Python (but boy, I learned a lot about Python from it!).

I agree that speed is a real problem. In fact, I openly admit that I
keep a "stripped-down" version that does only one-dimensional lists
for the many cases where I need long one-dimensional arrays. But this
is purely an implementation problem, not a problem in principle.
Much of the efficiency problems probably comes from the decision
to use nested lists as an internal representation, and this decision
was mostly based on laziness; it let me use simple recursive
functions to handle higher-rank arrays.

   But of course having all the numbers be secretly complex is completely 
   crazy from an efficiency point of view, not to mention storage.

When I made this suggestion, I referred to modern implementations of
APL (including J), which in fact have many internal representations
for numbers, for efficiency reasons. A typical APL implementation
has
1) Bits
2) small integers (i.e. bytes)
3) long integers (4 bytes)
4) real numbers
5) complex numbers
But to the user all this looks like a single number type, since all
conversions happen automatically. The price to pay is not in efficiency
(internal APL operations tend to outperform Fortran), but in a
rather complex implementation, which has to decide the optimal
data type based on various criteria. For example, the high cost
of unpacking bit arrays means that they will be used only for
very large objects and/or when memory runs down.

The advantage of this is that numbers behave like you would expect
from mathematics, e.g. 1/3 equals 1./3., not 0. This prevents many
errors. There are actually more user-friendly features like this in
APL, e.g. non-zero comparison tolerance.

Actually, my dream language would also handle symbolic operations
in the style of Mathematica or Maple...

   b. Yes, I implemented an extension language in Fortran. It was 1984 and
   it was the only language available on a Cray. The computer center manager
   said that I didn't need C, you can do everything in Fortran.

Isn't it great to have someone who always knows your real needs? ;-)

-------------------------------------------------------------------------------
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
=================