From viennet@ura1507.univ-paris13.fr  Sun Jun  2 14:08:52 1996
From: viennet@ura1507.univ-paris13.fr (Emmanuel Viennet)
Date: Sun, 2 Jun 1996 14:08:52 +0100
Subject: [PYTHON MATRIX-SIG] Gist and GNU readline
In-Reply-To: <9605281646.AA29432@icf.llnl.gov>
References: <9605281646.AA29432@icf.llnl.gov>
Message-ID: <199606021308.OAA05452@univ-paris13.fr>


 Hi,

GIST seems to be a cool plotting package.
For those like me who can't live without the line editing facilities
from GNU readline, here is a useful patch. I did not make extensive
tests, but it seems to work.

Apply the following diff to the file gistCmodule.c
from  ftp-icf.llnl.gov:/pub/python/busby/pygist-1.0.tgz
Then configure python with readline enabled and recompile.

13a14,22
> #ifdef WITH_READLINE
> #  error Sorry: The Gist module cannot presently co-exist with Readline.
> #endif
> 
> /* (Actually, Gist probably *can* co-exist with readline, by using the
>  * trick of replacing read() with a gist_read(), but I haven't had a chance
>  * to review the readline source yet.)
>  */
> 
82,87d90
< /* GNU readline callback (E.viennet) */ 
< #ifdef WITH_READLINE
< static int readline_event_hook(void);
< extern  int (*rl_event_hook)(); /* from readline.h */
< #endif
< 
409d411
< #ifndef WITH_READLINE
420,422d421
< #else /* GNU READLINE */
<   rl_event_hook = readline_event_hook;
< #endif
521d519
< #ifndef WITH_READLINE
524d521
< #endif
1429,1436d1425
< 
< #ifdef WITH_READLINE
< static int readline_event_hook(void) {
<   do YGDispatch ();
<   while (!yPendingIn);
<   return 1;
< }
< #endif

-- 
Emmanuel Viennet: <viennet@ura1507.univ-paris13.fr>
LIPN - Institut Galilee - Universite Paris-Nord       
93430 Villetaneuse -  France

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

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

From jjh@goldilocks.lcs.mit.edu  Sun Jun  2 22:13:03 1996
From: jjh@goldilocks.lcs.mit.edu (James Hugunin)
Date: Sun, 2 Jun 1996 17:13:03 -0400
Subject: [PYTHON MATRIX-SIG] Numerical exception handling
Message-ID: <199606022113.RAA00600@ling-ling.zoo>


Interestingly enough, I'd received private mail about this bug hours
before this was posted to the list.

   From: Brien Barton <barton@simsg1.mdc.com>

   My apologies if this has already been covered.  The following is a
   demonstration of an error that is not handled gracefully when using array
   objects:

       >>> b=array([1,2,3])
       >>> b.x=10
       Fatal Python error: print_error called but no exception
       Abort (core dumped)

This will be fixed in the next release (which should be coming out
shortly after the python workshop).

-Jim

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

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

From hinsenk@ere.umontreal.ca  Tue Jun 11 21:38:03 1996
From: hinsenk@ere.umontreal.ca (Konrad HINSEN)
Date: Tue, 11 Jun 1996 16:38:03 -0400
Subject: [PYTHON MATRIX-SIG] Vacation and move
Message-ID: <199606112038.QAA18825@cyclone.ERE.UMontreal.CA>

This weekend I will leave Montreal for an extended vacation (all
across the country to the West coast, then down to California, and
finally to Texas), after which I will move to France, where I will be
working for the next two years. I will stay on the SIG (hoping not to
be inundated by large messages) and check my e-mail whenever I find an
opportunity, but don't expect quick reactions from me during that
time. I hope that you will all be working hard, and that I will find a
much improved array module with lots of interesting applications when
I return to work...

My research project in France will require lots of Python programming.
Essentially I will write a molecular modelling toolkit in Python,
using C modules where necessary for speed. Although this toolkit will
be specialized to my personal needs, I'll try to keep it as general as
possible, and if I can find interested collaborators, it might
eventually become a general-purpose tool, which would certainly be the
most modern one in existence (which is not much of an achievement in
view of the "state of the art" in this field). I expect to produce
many general-purpose numerical modules as a side product, which I will
of course make available and announce to the public.

Finally, I'd like to announce my latest Python package, which is a
Gaussian random number generator using Paul Dubois' URNG module.
Anyone who wants a copy please write to me.

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

From jlv@zorglub.univ-lyon1.fr  Fri Jun 14 06:33:15 1996
From: jlv@zorglub.univ-lyon1.fr (Jean-Louis Villecroze)
Date: Fri, 14 Jun 1996 08:33:15 +0300
Subject: [PYTHON MATRIX-SIG] Create and fill an array from Numeric module in C function ??
Message-ID: <31C0F99B.23AC23D5@zorglub.univ-lyon1.fr>

Hello,

I'm currently working in the integration of a library in Python, and i
would like to create and fill a Numeric array from my Data but directly
in a C function, which be used in Python ...

How make that's ... 

Tanks for any support ....

Jean-Louis

--

Jean-Louis Villecroze
                                                C.R.A.L.
Tel (33) 78.86.83.81                            Observatoire de Lyon
Fax (33) 78.86.83.86                            9, Avenue Charles Andre
                                                69561 St Genis-Laval
Cedex
E-mail: jlv@zorglub.univ-lyon1.fr               France
URL: http://www-obs.univ-lyon1.fr/~jlv/jl.html

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

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

From Emmanuel.Viennet@laforia.ibp.fr  Fri Jun 14 17:15:57 1996
From: Emmanuel.Viennet@laforia.ibp.fr (VIENNET Emmanuel 48.06.27.97 Equipe Gallinari)
Date: Fri, 14 Jun 1996 18:15:57 +0200
Subject: [PYTHON MATRIX-SIG] Create and fill an array from Numeric module in C function ??
In-Reply-To: <31C0F99B.23AC23D5@zorglub.univ-lyon1.fr>
References: <31C0F99B.23AC23D5@zorglub.univ-lyon1.fr>
Message-ID: <199606141615.SAA00386@lpia2.ibp.fr>


Jean-Louis Villecroze writes:
> Hello,
> 
> I'm currently working in the integration of a library in Python, and i
> would like to create and fill a Numeric array from my Data but directly
> in a C function, which be used in Python ...
> 

Quite easy :-)
write a python-C glue function:

- to create a new array and return it:
    int dims[ nbdims ] = { ... };

    arr = (PyArrayObject *)PyArray_FromDims( nbdims, dims, PyArray_FLOAT );
                                                                    
    use the memory pointed by arr->data

    When you're done, return a python object:
     return (PyObject *)arr;

For more infos, look at Include/arrayobject.h, where you will find
usefull comments. 
Have fun
Emmanuel

-- 
Emmanuel Viennet: <viennet@ura1507.univ-paris13.fr>
LIPN - Institut Galilee - Universite Paris-Nord       
93430 Villetaneuse -  France

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

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

From da@maigret.cog.brown.edu  Wed Jun 19 18:09:34 1996
From: da@maigret.cog.brown.edu (David Ascher)
Date: Wed, 19 Jun 1996 13:09:34 -0400 (EDT)
Subject: [PYTHON MATRIX-SIG] FFT's
Message-ID: <199606191709.NAA11503@maigret>

I never got time to test it, so I'm letting people give it a go
as is -- my module to interface to fftpack is up on my website

    http://maigret.cog.brown.edu/Python/Extensions/FFT/

This is based on the fftpack.c which is part of TELA.

I suspect my translation of TELA's fft.ct frontend into my FFT.py is
buggy, since I don't really read TELA code.  I'm especially suspicious
of the real FFT's, but the complex ones seem to work ok.  

Anyway, if anyone gives this a try, let me know when you find bugs.  

--david

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

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

From fonseca@acse.shef.ac.uk  Wed Jun 19 19:38:40 1996
From: fonseca@acse.shef.ac.uk (carlos fonseca)
Date: Wed, 19 Jun 1996 19:38:40 +0100
Subject: [PYTHON MATRIX-SIG] Matrix multiplication
Message-ID: <199606191838.TAA00611@serin.acse>

Hello,

I may have missed any previous discussion on the implementation of
matrix multiplication in Numerical Python. Anyway, I understand that
the current implementation of .matrixMultiply() requires arrays to be
2-dimensional (has this changed?).

While trying to port some matlab code to Numerical Python and make it
more general (eliminate for loops, add functionality, etc), I realised
that it would be nice to be able to:

1) treat (e.g.) the last 2 dimensions of an array as matrices, i.e.,
  having arrays of matrices. For example,

  A[m-by-n-by-p] * B[p-by-q] = A[m-by-n-by-p] * B[1-p-by-q]
                             = C[m-by-n-by-q]

  In this case, each of the m n-by-p matrices in A is multiplied by B.
  Another example would be

  A[m-by-n-by-p] * D[m-p-by-q] = E[m-by-n-by-q]

  Now, each of the m n-by-p matrices in A is multiplied by the corresponding
  p-by-q matrix in B

2) be able to do the sort of thing Yorick does where, for example,
  A[n-by-m-by-p] * B[p-by-q-by-r] = C[n-by-m-by-q-by-r]

  This looks more like (2-dimensional) matrix mutiplication.

A simple way of achieving both would be to define a .dot(B,n) method
such that A.dot(B,n) would compute the dot product of the rows of A by
the corresponding rows of B (or any other dimension n, for that
matter), reducing the number of dimensions by one like add.reduce does
for a single array. The arrays should be conformable as for addition
and multiplication.

Essentially, A.dot(B,n) = add.reduce(A*B,n), but memory for the
intermediate result A*B would not need to be allocated (a saving when
casting of dimensions occurs, as in the example below).

For two-dimensional arrays, A.matrixMultiply(B) could be written
something like A[...,NewAxis].dot(B,-2).  The automatic casting of the
dimension introduced into A to match that of B would produce the
desired results. Note that add.reduce(A[...,NewAxis]*B) would imply
storing a 3-dimensional array. This would generalize well for any
number of dimensions, I believe. 

For example, case 1) above could be written

C = A[...,NewAxis].dot(B,-2)
E = A[...,NewAxis].dot(D[...,NewAxis,:,:],-2)

and case 2) could be written

A[...,NewAxis,NewAxis].dot(B,-3)

How do others feel about this issue?

Carlos Fonseca

P.S.: Why doesn't A[RubberIndex,NewAxis,NewAxis] work? 

	>>> a
	 0  1  2  3  4
	 5  6  7  8  9
	10 11 12 13 14
	>>> a[RubberIndex,NewAxis]
	Traceback (innermost last):
	  File "<stdin>", line 1, in ?
	ArrayError: each subindex must be either a slice, an integer,
	RubberIndex, or None
        ^^^^^^^^^^^ !??

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

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

From fonseca@acse.shef.ac.uk  Wed Jun 19 19:38:40 1996
From: fonseca@acse.shef.ac.uk (carlos fonseca)
Date: Wed, 19 Jun 1996 19:38:40 +0100
Subject: [PYTHON MATRIX-SIG] Matrix multiplication
Message-ID: <199606191838.TAA00611@serin.acse>

Hello,

I may have missed any previous discussion on the implementation of
matrix multiplication in Numerical Python. Anyway, I understand that
the current implementation of .matrixMultiply() requires arrays to be
2-dimensional (has this changed?).

While trying to port some matlab code to Numerical Python and make it
more general (eliminate for loops, add functionality, etc), I realised
that it would be nice to be able to:

1) treat (e.g.) the last 2 dimensions of an array as matrices, i.e.,
  having arrays of matrices. For example,

  A[m-by-n-by-p] * B[p-by-q] = A[m-by-n-by-p] * B[1-p-by-q]
                             = C[m-by-n-by-q]

  In this case, each of the m n-by-p matrices in A is multiplied by B.
  Another example would be

  A[m-by-n-by-p] * D[m-p-by-q] = E[m-by-n-by-q]

  Now, each of the m n-by-p matrices in A is multiplied by the corresponding
  p-by-q matrix in B

2) be able to do the sort of thing Yorick does where, for example,
  A[n-by-m-by-p] * B[p-by-q-by-r] = C[n-by-m-by-q-by-r]

  This looks more like (2-dimensional) matrix mutiplication.

A simple way of achieving both would be to define a .dot(B,n) method
such that A.dot(B,n) would compute the dot product of the rows of A by
the corresponding rows of B (or any other dimension n, for that
matter), reducing the number of dimensions by one like add.reduce does
for a single array. The arrays should be conformable as for addition
and multiplication.

Essentially, A.dot(B,n) = add.reduce(A*B,n), but memory for the
intermediate result A*B would not need to be allocated (a saving when
casting of dimensions occurs, as in the example below).

For two-dimensional arrays, A.matrixMultiply(B) could be written
something like A[...,NewAxis].dot(B,-2).  The automatic casting of the
dimension introduced into A to match that of B would produce the
desired results. Note that add.reduce(A[...,NewAxis]*B) would imply
storing a 3-dimensional array. This would generalize well for any
number of dimensions, I believe. 

For example, case 1) above could be written

C = A[...,NewAxis].dot(B,-2)
E = A[...,NewAxis].dot(D[...,NewAxis,:,:],-2)

and case 2) could be written

A[...,NewAxis,NewAxis].dot(B,-3)

How do others feel about this issue?

Carlos Fonseca

P.S.: Why doesn't A[RubberIndex,NewAxis,NewAxis] work? 

	>>> a
	 0  1  2  3  4
	 5  6  7  8  9
	10 11 12 13 14
	>>> a[RubberIndex,NewAxis]
	Traceback (innermost last):
	  File "<stdin>", line 1, in ?
	ArrayError: each subindex must be either a slice, an integer,
	RubberIndex, or None
        ^^^^^^^^^^^ !??

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

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

From fonseca@acse.shef.ac.uk  Wed Jun 19 19:42:40 1996
From: fonseca@acse.shef.ac.uk (carlos fonseca)
Date: Wed, 19 Jun 1996 19:42:40 +0100
Subject: [PYTHON MATRIX-SIG] a.choose() segfaults
Message-ID: <199606191842.TAA00617@serin.acse>

Apologies if this bug is already known:

>>> a=arange(10)
>>> a
0 1 2 3 4 5 6 7 8 9
>>> a.choose
<built-in method choose of array object at d00e8>
>>> a.choose()
Segmentation Fault (core dumped)

This happens both under Linux-i386, and under Solaris 2 on a Sun.

Carlos

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

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

From tschwal@artinet.de  Thu Jun 20 18:55:34 1996
From: tschwal@artinet.de (Tom Schwaller)
Date: Thu, 20 Jun 1996 19:55:34 +0200 (MET DST)
Subject: [PYTHON MATRIX-SIG] ezmodule this week! (long message)
In-Reply-To: <199606191709.NAA11503@maigret>
Message-ID: <Pine.LNX.3.91.960620193659.31286D-100000@samba.artinet.de>


Hi all,
I am just finishing a new Python module
ezmodule
which is a new GUI-Library with
an incorporated 3D-Api (very similar to OpenGL).
It only works on X-windows, but a nice thing about it is,
that you have all what you need in one very
compact module. The Tk C-API should be available this
year, which will finally blow out the Tcl Stuff
in the Tk-Module, the Netscape plugin for Tk is 
also out soon, so why another toolkit?
Well, look at it. It's fast, easy to use
and very easy to install (compared to a
Tkinter, OpenGL (Mesa), Tk/OpenGL widget installation)

-rwxrwxr-x   1 et  users  640870 Jun 20 16:33 ezmodule.so

For a toolkit which allows you to programm in 3D (eg.
with numerical Python, drawing surfaces with Gouraud shading)
building GUI's (including notebooks, drawing of ppm's),
that's really not bad. Setting callbacks and configuring
widgets is dead easy. Here's a simple example:


#!/usr/local/bin/python

from EZ import *
import sys
  
def shellCB(widget, bitmap, color):
   global p2
   widget.Configure(BITMAP_FILE=bitmap)
   p2.Configure(FOREGROUND=color)

def main():
   global p2
   Initialize(1)
   SetApplicationName('Test1')
   
   f = Frame(label='NoteBook');
   n = f.NoteBook() 
   
   p1 = n.NoteBookPage(label='RadioButtons')
   p1.Configure(FOREGROUND="Blue", BACKGROUND="White")
   p1.im = p1.Label()
   p1.im.Configure(IMAGE='logo.ppm')
   p1.f = p1.Frame('Classification')
   p1.f.Configure(STACKING = VERTICAL, SIDE=LEFT, FOREGROUND="Red")  
   p1.f.l1 = p1.f.RadioButton(label='VeryCcool', value=0)
   p1.f.l2 = p1.f.RadioButton(label='Cool', value=1)
   p1.f.l3 = p1.f.RadioButton(label='Ok', value=2)
   p1.f.l3 = p1.f.RadioButton(label='Bad', value=3)
   p1.f.l4 = p1.f.RadioButton(label='Very Bad', value=4)
   
   p2 = n.NoteBookPage(label='Pixmaps') 
   p2.Configure(FOREGROUND="Red", BACKGROUND="#007f6f")
   p2.f = p2.Frame('Shells')
   p2.f.Configure(BITMAP_FILE='xterm.xpm')
   p2.f.Configure(STACKING = VERTICAL, SIDE=LEFT)
   i=0; 
   colors=['Red', 'Green', 'Blue', 'Yellow', 'Cyan', 'Magenta']
   for s in ['axp', 'blank', 'dec', 'sgi', 'sol', 'sun']: 
      b = p2.f.RadioButton(label='xterm-'+s, gid=1, value=i)
      b.SetCallBack(shellCB, p2.f, 'xterm-'+s+'.xpm', colors[i])
      i = i+1
       
   p3 = n.NoteBookPage(label='Text')  
   p3.t = p3.TextWidget()
   p3.t.LoadAnnotatedFile('text.txt')
  
   p4 = n.NoteBookPage(label='Misc')  
   p4.f = p4.Frame()
   p4.f.Configure(BITMAP_FILE='xterm-sun.xpm')
   p4.b1 = p4.MenuButton(label='Menu')
   p4.b2 = p4.Button(label='Quit')
   p4.b2.SetCallBack(sys.exit)
   #p4.s = p4.Slider()
 
   f.Display()
   f.MainLoop()
   
main()



Check

http://www.artinet.de/python/notebook.jpeg

to see how it looks like.

At http://www.artinet.de/python/EZWGL.tgz
you can get EZGL from
Maorong Zou
Department of Mathematics
The University of Texas at Austin
Austin, TX 78712
mzou@ma.utexas.edu

to have a first impression. I lost the annoucment.
Somewehere in comp.os.linux.apps last week

I used SWIG plus some handcoding for the callback and
widget configuration mechanism. Fortunately I 
did not have to change the source code for it.
I had to llok quite a bit to find a solution,
but it wirks now. :-)

Last but not least, here's the REDME.
If you are interested, please tell me,
so I'm even more motivated to work on it...



____________________________________________________________

Python ez-Module: Version 0.1 (20 June 1996) 
by Tom Schwaller (German Linux Magazine, tschwal@artinet.de)
Tested and developped on Linux 1.2.13 (ELF) with gcc 2.7.0
Available at http://www.artinet.de/python/ez.html

-----------------------------------------------------------------

This is my first version of the ez-Module, which interfaces the
C-library EZWGL, done by

Maorong Zou
Department of Mathematics
The University of Texas at Austin
Austin, TX 78712
mzou@ma.utexas.edu

This high-level library incorporates a GUI widget set for
the X-Window System (No cross platform tool, sorry!) and
Graphics commands, which resemble OpenGL a lot (except the
names and (in the actual version) missing texture mapping). 
When I read the announcment I thought first, well another
GUI library but when I saw the first GUI/3D applications
with it on my screen, I immediately decided to write
a Python module (had some time :-), being quite busy for
the German Linux Magazine).

It wrapps nearly 280 C-Functions, so it seemed ideal for
testing SWIG (Simplified Wrapper and Interface Generator),
done by

David M. Beazley 
Department of Computer Science 
University of Utah 
Salt Lake City, Utah 84112 
beazley@cs.utah.edu 

even though SWIG does not generate that kind of code I use
to write myself wrapping libraries. But you can get results
very fast, which is cool!

Not everything is quite polished at the moment, but it seems to
works. A challenge in writing the module things was
the Python translation of the Widget Configuration 

   p1 = n.NoteBookPage(label='RadioButtons')
   p1.Configure(FOREGROUND="Blue", BACKGROUND="White")
   
which uses variable argument lists in the C-API. Also
the callback mechnism was not straightforward, but look
at the result to understand how it works:

   def callback0():
      print 'No Argument!'
 
   def callback1(widget):
      print 'One Argument:', widget
       
   def callback2(widget, color):
      print 'Two Arguments:', widget, color
      
   a.SetCallBack(callback0)
   b.SetCallBack(callback1, w)
   c.SetCallBack(callback2, w, color)
   

Just use the same number of arguments as in the function
definition when registering the callback with SetCallBack. 
I found that solution very appealing, when coding it.

Another problem was, that the header file ez.h is not ANSI
at the moment, so I had to write the declarations myself 
for use with SWIG. As in the OpenGL module (Version 0.4 by 
James Hugunin, David Ascher and myself to follow soon I hope) 
I would have liked to use the matrix module, but I decided not 
to at the moment, so everybody interested in this module can 
give it a try. One will have to rewrite some of the 3d Graphics 
functions in the ez-module for easier use. At the moment just 
look at the OpenGL examples in the SWIG Distribtion to see how
they work.


Installation:

This should be fairly easy. First compile the EZ library libEZ.a
(You can do a shared library if you want) and make shure
your compiler finds it while linking. Then add the following
line to your Python Setup file (eg. after *noconfig*)

ez ezmodule.c -DALLOW_NULL -DEZ_MAIN -lEZ -lX11 -lXext

Install EZ.py somewhere in your PYTHONPATH. That's all.
Now you are ready for GUI and 3D Programming.

Testing:
Change to the examples subdirectory and try test.py
to see if it works (It really should!). You can also
take a look at notebook.jpeg in the same directory to
compare.

More examples (GUI/3D) to follow.... 

I have not tested everything at the moment (there are also 
some small bugs in EZWGL itself, remeber it's a Beta Version), 
so I hope to get some feedback. In my eyes ezmodule is very 
well suited for medium sized Scientific applications (e.g take 
a look at the isosurf example in the EZGL examples subdirectory,
which is taken from the Mesa distribution and rewritten
in EZGL and you will see what I mean). Displaying shaded
surfaces a la Matlab, Mathematica or Maple should be straightforward.
Any volunteers? In conjunction with Numerical Python this module 
gives you a small and easy to use library for writing visualisation 
tools (Installing Python with Tkinter, OpenGL and some 
Tk/OpenGL widget is not that easy as it should be).


Have fun. Enhacments, comments and contributions welcome.
Please send them to tschwal@artinet.de to incorporate them
in the next release.

Thanks to all in the Python Community.
Special thanks to Maorong Zou, for contributung EZWGL.




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

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

From tbyang@icf.llnl.gov  Fri Jun 21 22:34:00 1996
From: tbyang@icf.llnl.gov (Tser-Yuan (Brian) Yang)
Date: Fri, 21 Jun 1996 14:34:00 -0700 (PDT)
Subject: [PYTHON MATRIX-SIG] may be a bug
Message-ID: <Pine.SUN.3.92.960621143000.22311A-100000@icf.llnl.gov>

The following may have been posted or even corrected. If so, I apologize
for sending junk mail.

>>> from Numeric import *
>>> a=array((1,2))
>>> import sys
>>> sys.getrefcount(a)
2
>>> a
1 2
>>> sys.getrefcount(a)
5
>>> b=1
>>> sys.getrefcount(a)
4

Something is holding extra references

				Brian Yang


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

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

From tbyang@icf.llnl.gov  Sat Jun 22 00:04:27 1996
From: tbyang@icf.llnl.gov (Tser-Yuan (Brian) Yang)
Date: Fri, 21 Jun 1996 16:04:27 -0700 (PDT)
Subject: [PYTHON MATRIX-SIG] Re: may be a bug
Message-ID: <Pine.SUN.3.92.960621155955.23986A-100000@icf.llnl.gov>

Brian Yang wrote:

> The following may have been posted or even corrected. If so, I apologize
> for sending junk mail.

> >>> from Numeric import *
> >>> a=array((1,2))
> >>> import sys
> >>> sys.getrefcount(a)
> 2
> >>> a
> 1 2
> >>> sys.getrefcount(a)
> 5
> >>> b=1
> >>> sys.getrefcount(a)
> 4

First, I should correct myself:

sys.getrefcount(a) should still be 5 after b=1, since assignment does not
return a value.

Some experiment showed that the extra reference counts are held by
something in ArrayPrinter.py, because I commented out the following line
in numeric.py:

#from ArrayPrinter import arrayToString
#set_print_function(arrayToString)

and it hehaves like the following


>>> from Numeric import *
>>> a=array((1,3))
>>> a
array([1,3], 'l')
>>> import sys
>>> sys.getrefcount(a)
3
>>> 1
1
>>> sys.getrefcount(a)
2

				Brian Yang


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

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

From hinsenk@ere.umontreal.ca  Mon Jun 24 18:23:40 1996
From: hinsenk@ere.umontreal.ca (Konrad HINSEN)
Date: Mon, 24 Jun 1996 13:23:40 -0400
Subject: [PYTHON MATRIX-SIG] Matrix multiplication
In-Reply-To: <199606191838.TAA00611@serin.acse> (fonseca@acse.shef.ac.uk)
Message-ID: <199606241723.NAA05534@cyclone.ERE.UMontreal.CA>

> I may have missed any previous discussion on the implementation of
> matrix multiplication in Numerical Python. Anyway, I understand that
> the current implementation of .matrixMultiply() requires arrays to be
> 2-dimensional (has this changed?).

True. As a temporary solution, I can offer a (slow) Python function
that is more general:

def dot(a1, a2):
    r1 = len(a1.shape)-1
    r2 = len(a2.shape)-1
    axes = [r1] + range(r1)
    a1 = a1.transpose(axes).copy()
    f = a1.reshape
    a1 = apply(f, a1.shape + r2*(1,))
    a2 = a2.copy()
    f = a2.reshape
    a2 = apply(f, a2.shape[0:1] + r1*(1,) + a2.shape[1:])
    return Numeric.add.reduce(a1*a2)

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

From hinsenk@ere.umontreal.ca  Mon Jun 24 18:26:19 1996
From: hinsenk@ere.umontreal.ca (Konrad HINSEN)
Date: Mon, 24 Jun 1996 13:26:19 -0400
Subject: [PYTHON MATRIX-SIG] Re: may be a bug
In-Reply-To: <Pine.SUN.3.92.960621155955.23986A-100000@icf.llnl.gov> (tbyang@icf.llnl.gov)
Message-ID: <199606241726.NAA05614@cyclone.ERE.UMontreal.CA>

> Some experiment showed that the extra reference counts are held by
> something in ArrayPrinter.py, because I commented out the following line
> in numeric.py:

I can't see how the array printer could keep references, since it
doesn't assign anything to a global variable.

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

From pas@lems.brown.edu  Mon Jun 24 19:52:32 1996
From: pas@lems.brown.edu (Perry A. Stoll)
Date: Mon, 24 Jun 1996 14:52:32 -0400 (EDT)
Subject: [PYTHON MATRIX-SIG] Re: may be a bug
In-Reply-To: <Pine.SUN.3.92.960621155955.23986A-100000@icf.llnl.gov>
Message-ID: <Pine.SUN.3.91.960624143835.306A-100000@lems61>


I know of one thing that can hold references. In the interpreter, you can
reference the last value returned by using an underscore.
 
For example:
 
>>> x = 1
>>> x
1
>>> z = _
>>> z
1
 
So that should account for the drop in refcount from 5 to 4 in your 
example and probably why you found the problem in ArrayPrinter.py. 

I haven't read the documentation too recently, but I don't recall seeing 
this - is this documented? How did I find it? just lucky.
 
-Perry
 <pas@lems.brown.edu>
 

On Fri, 21 Jun 1996, Tser-Yuan (Brian) Yang wrote:

> Brian Yang wrote:
> 
> > The following may have been posted or even corrected. If so, I apologize
> > for sending junk mail.
> 
> > >>> from Numeric import *
> > >>> a=array((1,2))
> > >>> import sys
> > >>> sys.getrefcount(a)
> > 2
> > >>> a
> > 1 2
> > >>> sys.getrefcount(a)
> > 5
> > >>> b=1
> > >>> sys.getrefcount(a)
> > 4
> 
> Some experiment showed that the extra reference counts are held by
> something in ArrayPrinter.py, because I commented out the following line
> in numeric.py:
> 


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

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

From guido@CNRI.Reston.Va.US  Wed Jun 26 17:01:45 1996
From: guido@CNRI.Reston.Va.US (Guido van Rossum)
Date: Wed, 26 Jun 1996 12:01:45 -0400
Subject: [PYTHON MATRIX-SIG] Re: may be a bug
In-Reply-To: Your message of "Mon, 24 Jun 1996 14:52:32 EDT."
 <Pine.SUN.3.91.960624143835.306A-100000@lems61>
References: <Pine.SUN.3.91.960624143835.306A-100000@lems61>
Message-ID: <199606261601.MAA27949@monty>

> I know of one thing that can hold references. In the interpreter, you can
> reference the last value returned by using an underscore.
[...]
> I haven't read the documentation too recently, but I don't recall seeing 
> this - is this documented? How did I find it? just lucky.

Probably the only place is the section "Recent Additions" in the
tutorial, e.g. http://www.python.org/doc/tut/node64.html

--Guido van Rossum (home page: http://www.python.org/~guido/)

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

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

From tbyang@icf.llnl.gov  Fri Jun 28 22:06:08 1996
From: tbyang@icf.llnl.gov (Tser-Yuan (Brian) Yang)
Date: Fri, 28 Jun 1996 14:06:08 -0700 (PDT)
Subject: [PYTHON MATRIX-SIG] Re: may be a bug
In-Reply-To: <Pine.SUN.3.91.960624143835.306A-100000@lems61>
Message-ID: <Pine.SUN.3.92.960628140415.6070A-100000@icf.llnl.gov>

I finally figure out what is holding the two extra reference counts in the
following block of script.

>>> from Numeric import *
>>> a=array((1,2))
>>> import sys
>>> sys.getrefcount(a)
2
>>> print a
1 2
>>> sys.getrefcount(a)
4


One is the variable 'data' in arrayToString (in ArrayPrinter.py), and the
other is the exception handler. After I added 'del data' before the
return of arrayToString, and commented out some statements in arrayToString:

    if max_line_width is None:
#	try:
#	    max_line_width = sys.output_line_width
#	except AttributeError:
	    max_line_width = 77
    if precision is None:
#	try:
#	    precision = sys.float_output_precision
#	except AttributeError:
	    precision = 8
    if suppress_small is None:
#	try:
#	    suppress_small = sys.float_output_suppress_small
#	except AttributeError:
	    suppress_small = 0

The same block of script gives:

>>> from Numeric import *
>>> a=array((1,2))
>>> import sys
>>> print a
1 2
>>> sys.getrefcount(a)
2

I agree this is probably a feature rather than a bug, since these reference
counts will be released after printing another array. Just to point this out
in case some of you may be interested.
						Brian Yang


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

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