From edcjones@erols.com Sun May 2 12:02:07 1999 From: edcjones@erols.com (Edward C. Jones) Date: Sun, 02 May 1999 07:02:07 -0400 Subject: [Matrix-SIG] Bug in "reduceat"? Message-ID: <372C30AF.259CD2E@erols.com> #! /usr/bin/python import Numeric # In NumPy, "reduceat" does not accept an "axis" parameter like "reduce" # does. Here are some simple examples for "reduceat". You may need to change # "#! /usr/bin/python" to where python is on your machine. a = Numeric.array([0, 1, 2, 10, 11, 12], 'i') ind = [0, 3] b = Numeric.add.reduceat(a, ind) print b # The following array might be an image that needs to be reduced in size or # a spreadsheet with blocks to be summed. a = Numeric.array([[ 0, 1, 2, 10, 11, 12], \ [ 3, 4, 5, 13, 14, 15], \ [ 6, 7, 8, 16, 17, 18], \ [20, 21, 22, 30, 31, 32], \ [23, 24, 25, 33, 34, 35], \ [26, 27, 28, 36, 37, 38]], 'i') print a b = Numeric.add.reduceat(a, [0, 3]) print b tb = Numeric.transpose(b) print tb c = Numeric.add.reduceat(tb, [0,3]) print c # The following fails: d = Numeric.add.reduceat(a, [0, 3], 1) From Oliphant.Travis@mayo.edu Tue May 4 15:22:42 1999 From: Oliphant.Travis@mayo.edu (Travis Oliphant) Date: Tue, 4 May 1999 09:22:42 -0500 (CDT) Subject: [Matrix-SIG] Multipack requires 1.5.2b2 or later Message-ID: The Multipack package I discussed a couple of days ago requires 1.5.2b2 or later to run. The reason is that it makes use of the "N" option to Py_BuildValue in the C/API of Python that was added at the 1.5.2b2 stage. I'm sorry if neglecting to mention this wasted your time. It is not hard to fix the code for other (previous) versions by replacing the N with an O. This will, however, create a memory leak in Python as the array objects returned will have a double reference count increase. (That's why I used "N" in the first place. I didn't know it was a "recently-added" feature.) I suspect people who will be using Multipack will be getting 1.5.2 anyway? If there is a real demand for functionality with 1.5.2b1 and before, it is not hard to change the code to make it work. Let me know. Travis From vanandel@ucar.edu Tue May 4 15:38:13 1999 From: vanandel@ucar.edu (Joe Van Andel) Date: Tue, 04 May 1999 08:38:13 -0600 Subject: [Matrix-SIG] Latest EGCS snapshot compiles CXX code Message-ID: <372F0655.9441C37C@ucar.edu> Good news: egcs-2.93.21 19990502 now compiles CXX code (on Solaris 2.6, and probably other targets). (No patching required). Using templates slows down the compiler noticably, but at least we can now use CXX to build C++ to Python interfaces. egcs is available from ftp://egcs.cygnus.com/pub/egcs/releases/index.html or its mirrors. And egcs is now "mainstream" - it will be the basis for the next "official" GNU gcc. -- Joe VanAndel Internet: vanandel@ucar.edu National Center for http://www.atd.ucar.edu/~vanandel/ Atmospheric Research From pearu@ioc.ee Fri May 7 16:22:07 1999 From: pearu@ioc.ee (Pearu Peterson) Date: Fri, 7 May 1999 18:22:07 +0300 (EETDST) Subject: [Matrix-SIG] Interactive shell In-Reply-To: <14116.62126.63884.351725@lisboa> Message-ID: On Tue, 27 Apr 1999 jhauser@ifm.uni-kiel.de wrote: > -special shell commands starting with a @ > @pwd @cd @who @whos @logon @logoff @clean > These commands don't need () Here follows an idea: I felt that these commands don't need '@' (and '!') either. So, below is my hack of prefilter function. As a result I can do: >>> ls -l >>> dir >>> dir shell >>> who etc def prefilter(self, line): sline=string.strip(line) i=string.find(sline,' ') if i<0: cline,aline=sline,'' else: cline,aline=sline[:i],sline[i+1:] if line and string.strip(line)[0] == '!': self.handle_shell_escape(line) return '' # Empty string is needed here! elif line and string.strip(line)[0] == '?': return self.handle_help(line) elif line and string.strip(line)[0] == '@': return self.handle_magic(line) elif line and sline in ['who','dir','pwd','whos','clear','logon','logoff']: # etc return self.handle_magic('@'+sline) elif line and cline in ['cd']: # etc return self.handle_magic('@'+cline+'('+aline+')') From jhauser@ifm.uni-kiel.de Sat May 8 22:41:17 1999 From: jhauser@ifm.uni-kiel.de (jhauser@ifm.uni-kiel.de) Date: Sat, 8 May 1999 23:41:17 +0200 (CEST) Subject: [Matrix-SIG] Interactive shell In-Reply-To: References: <14116.62126.63884.351725@lisboa> Message-ID: <14132.44402.464263.462459@lisboa> Thank's for the patch. I think this can be done, but I'm not sure, it should be. For example the cd command is now not clear who executes it, the underlying shell or the interpreter. The shell will probably be used by people who are just starting with Python and NumPy. I fear some confusion if they don't see the difference between valid python code and some special commands which the can't use in batch scripts. I followed your idea and have made the rest of the line after the @command available for the shell method. This leads to some more intiutive input like in @cd /home/joeuser. I have made a new version where the main enhancement is a starting help system. See the announcement on the list. but I will think about it a little bit more. __Janko Pearu Peterson writes: > > On Tue, 27 Apr 1999 jhauser@ifm.uni-kiel.de wrote: > > > -special shell commands starting with a @ > > @pwd @cd @who @whos @logon @logoff @clean > > These commands don't need () > > Here follows an idea: > I felt that these commands don't need '@' (and '!') either. So, below is > my hack of prefilter function. As a result I can do: > >>> ls -l > >>> dir > >>> dir shell > >>> who > etc > > def prefilter(self, line): > sline=string.strip(line) > i=string.find(sline,' ') > if i<0: cline,aline=sline,'' > else: cline,aline=sline[:i],sline[i+1:] > if line and string.strip(line)[0] == '!': > self.handle_shell_escape(line) > return '' # Empty string is needed here! > elif line and string.strip(line)[0] == '?': > return self.handle_help(line) > elif line and string.strip(line)[0] == '@': > return self.handle_magic(line) > elif line and sline in > ['who','dir','pwd','whos','clear','logon','logoff']: # etc > return self.handle_magic('@'+sline) > elif line and cline in ['cd']: # etc > return self.handle_magic('@'+cline+'('+aline+')') > > > > _______________________________________________ > Matrix-SIG maillist - Matrix-SIG@python.org > http://www.python.org/mailman/listinfo/matrix-sig From jhauser@ifm.uni-kiel.de Sat May 8 22:54:46 1999 From: jhauser@ifm.uni-kiel.de (jhauser@ifm.uni-kiel.de) Date: Sat, 8 May 1999 23:54:46 +0200 (CEST) Subject: [Matrix-SIG] ANNOUNCE: New version of ipp Message-ID: <14132.44951.602480.704767@lisboa> I have put a new version of ipp in my starship cabin at http://starship.python.net/crew/jhauser/miscellany.html I started to make a cleaner code, with some success but than added the help system, which is only weak integrated in the code. One can now ask for all the info from them library section of the python documentation. @apply or @mpz will give now complete help. This is only a test, if people like it this way. There is currently no mechanismen to integrate new HTML documents, but this can easily be added. The other approach is to build on top of ihelp of David Ascher, but info format is not very common in these days and not every one has it installed. The current system needs nothing besides standard python and the html-files locally installed. A hook for introspection is there, but I don't know what should be done with it :-) I have than included my own completer and keep my own track of the history lines. So one can now expand beginning with a point the last line starting with the same characters. After I had this build in I read the readline docu more carefully and learned that something similar is already available, by typing Ctrl-r. Na... Feedback is always welcome, there are lot's of things missing. (No consistent way to get help for the builtin shell methods, for example) __Janko From Oliphant.Travis@mayo.edu Sun May 9 06:55:48 1999 From: Oliphant.Travis@mayo.edu (Travis Oliphant) Date: Sun, 9 May 1999 00:55:48 -0500 (CDT) Subject: [Matrix-SIG] Interactive Shell In-Reply-To: <14118.7340.22749.295136@lisboa> Message-ID: This is looking really great, Janko. A couple of thoughts and a bug. 1) It would be nice if this were the Interactive environment in IDLE (or the start of another one in wxWindows...) 2) I really like what you are doing with going to the HTML files for help from the command line. I like the idea of not relying only on doc strings for interactive help. One thought I've been toying with is having a viewer defined that launches a PDF viewer for looking at documentation in PDF. This would be excellent for writing nicely typeset documentation to explain mathematical modules and uses for them. We really need to get away from doc-string-only interactive help. I haven't looked at ihelp which is probably along the lines of what I have in mind, but I'm not sure that texinfo is the way to go. Bug: When I type ?@cd (just checking.... :-) ) it gives a traceback, an error and then stops the interactive session. Good job Janko. This is should be in the Tools directory of the main distribution so all newcomers see it quickly. Travis From olafb@pvv.org Fri May 14 16:30:42 1999 From: olafb@pvv.org (Olaf Trygve Berglihn) Date: 14 May 1999 17:30:42 +0200 Subject: [Matrix-SIG] Has anyone made a responce surface toolkit for python? In-Reply-To: Michael Haggerty's message of "Wed, 18 Nov 1998 19:00:13 -0500" Message-ID: Before I even think of reinventing the wheel: is there available python code for handling design of experiments and multi dimensional regression analysis for both linear and polynomial models, or any model really? I would also be interesting in tools for discrimination of models. Olaf -- * Olaf Trygve Berglihn From lbda@earthlink.net Fri May 14 19:47:54 1999 From: lbda@earthlink.net (David & Laura Beth Holz) Date: Fri, 14 May 1999 14:47:54 -0400 Subject: [Matrix-SIG] Logical operations and fromfunction Message-ID: <000001be9e3a$46daf8c0$ecb51b26@golden> I just started using python and am intrigued by the fromfunction function method of filling arrays as opposed to using nested loops like in Fortran. However, I am having a problem and I just can't seem to follow the logic in the NumPy user's guide. The code I am trying to implement is as follows: def awk_fill(j): if j == 0: fnj = float(nj[j]) return fn1 + one else: fnj = float(nj[j]) return awk[j1] + fnj awk = fromfunction(awk_fill, (jm,)) where nj & awk is an 8 element vectors. I see on page 27 of the user's guide that NumPy doesn't allow this operation, but I don't understand the fix that the guide suggests at the bottom of the page. Has anyone run into this before and how did you get around it? Or should I just be using some next for loops. Thanks for the help. Dave Holz From pearu@ioc.ee Mon May 17 17:37:02 1999 From: pearu@ioc.ee (Pearu Peterson) Date: Mon, 17 May 1999 19:37:02 +0300 (EETDST) Subject: [Matrix-SIG] Running python from latex Message-ID: Hi! I wrote a LaTeX package runpython.sty. Using this one can run Python code from LaTeX, display the code and also the results in latex verbatim environment. So, it can be useful in writing documentation and examples for python codes. You can download runpython.sty and see examples in http://koer.ioc.ee/~pearu/python/ Below is an example LaTeX document. Best regards, Pearu \documentclass[12pt,a4paper]{article} \usepackage{runpython} \begin{document} Let us print out some members of Fibonacci series. Here is how you can find them in python. First we initialize \begin{python} a, b = 0, 1 \end{python} and then iterate \begin{python} while b < 10: print b, a, b = b, a+b \end{python} Here are the results: \runpython Another example (also taken from Python Tutorial): \begin{python} def f(x): return x % 2 != 0 and x % 3 != 0 print filter(f, range(2, 25)) \end{python} Here is the result \runpython \end{document} From da@ski.org Mon May 17 23:05:12 1999 From: da@ski.org (David Ascher) Date: Mon, 17 May 1999 15:05:12 -0700 (Pacific Daylight Time) Subject: [Matrix-SIG] Running python from latex In-Reply-To: Message-ID: On Mon, 17 May 1999, Pearu Peterson wrote: > I wrote a LaTeX package runpython.sty. Using this one can run Python code > from LaTeX, display the code and also the results in latex verbatim > environment. So, it can be useful in writing documentation > and examples for python codes. FYI, did you follow the discussion in the DOC-sig a few months back? See http://www.python.org/pipermail/doc-sig/1999-March/000650.html and http://www.python.org/pipermail/doc-sig/1999-March/000651.html --david ascher From pearu@ioc.ee Tue May 18 14:22:53 1999 From: pearu@ioc.ee (Pearu Peterson) Date: Tue, 18 May 1999 16:22:53 +0300 (EETDST) Subject: [Matrix-SIG] Running python from latex In-Reply-To: Message-ID: On Mon, 17 May 1999, David Ascher wrote: > On Mon, 17 May 1999, Pearu Peterson wrote: > > > I wrote a LaTeX package runpython.sty. Using this one can run Python code > > from LaTeX, display the code and also the results in latex verbatim > > environment. So, it can be useful in writing documentation > > and examples for python codes. > > FYI, did you follow the discussion in the DOC-sig a few months back? No. > http://www.python.org/pipermail/doc-sig/1999-March/000650.html > http://www.python.org/pipermail/doc-sig/1999-March/000651.html Now I have, thanks for the references! LaTeXPy.py seems to be a nice job (LaTeXPy however did not work on the first run for me: 'from PyLaTeX.LaTeXPy import main' gave an error). Now that we have two things doing similar things, allow me to point out some good points in runpython.sty: First, it is small. Nevertless, it does (approximately) the same job as LaTeXPy.py (I have not fully compared the possibilities of both approaches). Second, you don't have to call python on a latex document. The final dvi document is obtained by running only 'latex --shell-escape' (which then calls python when needed and the results of the python call are included "dynamically"). This seems to be more natural (but it is a matter of taste). Pearu From Oliphant.Travis@mayo.edu Tue May 18 21:38:45 1999 From: Oliphant.Travis@mayo.edu (Travis Oliphant) Date: Tue, 18 May 1999 15:38:45 -0500 (CDT) Subject: [Matrix-SIG] Adding a Sparse matrix object Message-ID: I had the necessity of iteratively inverting a large linear system with the conjugate gradient method and wanted to use Python, but there is only rudimentary sparse matrix support. (I couldn't find anything to solve my problem (without extra coding in C)). So I had to use MATLAB, which has a rather nice sparse matrix implementation. Is there an interest in developing a sparse matrix object with appropriate methods and functions defined to complement the array object? I suppose to be symmetric it should be a sparse array object... I'm interested in generating some discussion on this topic if there are any takers. Thanks, Travis Oliphant From turner@blueskystudios.com Tue May 18 22:44:04 1999 From: turner@blueskystudios.com (John Turner) Date: Tue, 18 May 1999 17:44:04 -0400 (EDT) Subject: [Matrix-SIG] Adding a Sparse matrix object In-Reply-To: References: Message-ID: <14145.57124.655026.14188@oneida.blueskyprod.com> >>>>> "TO" == Travis Oliphant writes: TO> I had the necessity of iteratively inverting a large linear system TO> with the conjugate gradient method and wanted to use Python, but TO> there is only rudimentary sparse matrix support. (I couldn't find TO> anything to solve my problem (without extra coding in C)). So I TO> had to use MATLAB, which has a rather nice sparse matrix TO> implementation. TO> TO> Is there an interest in developing a sparse matrix object with TO> appropriate methods and functions defined to complement the array TO> object? I suppose to be symmetric it should be a sparse array TO> object... I'm interested in generating some discussion on this TO> topic if there are any takers. I've been thinking of doing just this for a while as a "first significant Python project", since it's something I know a little about. I've written a series of packages to solve linear systems by preconditioned Krylov subspace methods (CG, GMRES, TFQMR, etc.) that progressed from horrible Fortran 77 to fully object-based modern Fortran (F90/F95). I've fooled around a little with C++ implementations, but not to as great an extent as with Fortran. There are many design decisions to be made when developing such a package, such as how to support the plethora of sparse storage formats. Some more "researchy" packages simply support a single storage scheme and provide routines to translate from a wide variety of formats into that one, but of course that can have serious memory and performance penalties. And note that most of the solvers themselves are pretty easy to implement; the difficult part is the preconditioning, which is almost always necessary for "real" problems. Anyway, there's lots we could talk about... I'm not sure if it should be done here or offline or in a separate list or what. But I'd like to be involved in such an effort. -- John A. Turner, Ph.D. Senior Research Associate Blue Sky Studios http://www.blueskystudios.com/ One South Road, Harrison, NY 10528 http://www.lanl.gov/home/turner/ Phone: 914-381-8400 http://john.turner.org/ Info on Blue Sky's fully computer-generated, Oscar-winning short film: http://bunny.blueskystudios.com/ From da@ski.org Tue May 18 22:53:16 1999 From: da@ski.org (David Ascher) Date: Tue, 18 May 1999 14:53:16 -0700 (Pacific Daylight Time) Subject: [Matrix-SIG] Adding a Sparse matrix object In-Reply-To: <14145.57124.655026.14188@oneida.blueskyprod.com> Message-ID: On Tue, 18 May 1999, John Turner wrote: > >>>>> "TO" == Travis Oliphant writes: > TO> Is there an interest in developing a sparse matrix object with > TO> appropriate methods and functions defined to complement the array > TO> object? I suppose to be symmetric it should be a sparse array > TO> object... I'm interested in generating some discussion on this > TO> topic if there are any takers. > > I've been thinking of doing just this for a while as a "first > significant Python project", since it's something I know a little I can't help, knowing very little about sparse matrices, but I can guarantee that many folks would be very interested in such a datatype w/ adjunct solvers/etc. It's a very common question re: NumPy. I can give general advice on writing object types, etc. BTW, I'd suggest looking into ExtensionClasses, as they provide very useful mechanisms for subclassing in both C and Python. Information available at: http://www.digicool.com/releases/ExtensionClass/ --david From roitblat@hawaii.edu Tue May 18 23:43:35 1999 From: roitblat@hawaii.edu (Herbert L. Roitblat) Date: Tue, 18 May 1999 12:43:35 -1000 Subject: [Matrix-SIG] Adding a Sparse matrix object In-Reply-To: Message-ID: I would very much like to see a sparse matrix implementation. I also used the facilities of matlab to do get the eigenvectors for a rather large matrix. I am not in a position to code such a system, but I would very much like to see it. Included with the matlab distribution is a white paper on implementing sparse matrices. Thanks very much for considering such an enterprise. HLR On Tue, 18 May 1999, Travis Oliphant wrote: > > I had the necessity of iteratively inverting a large linear system with > the conjugate gradient method and wanted to use Python, but there is only > rudimentary sparse matrix support. (I couldn't find anything to solve my > problem (without extra coding in C)). So I had to use MATLAB, which has a > rather nice sparse matrix implementation. > > Is there an interest in developing a sparse matrix object with appropriate > methods and functions defined to complement the array object? I > suppose to be symmetric it should be a sparse array object... I'm > interested in generating some discussion on this topic if there are any > takers. > > Thanks, > > Travis Oliphant > > > _______________________________________________ > Matrix-SIG maillist - Matrix-SIG@python.org > http://www.python.org/mailman/listinfo/matrix-sig > Herbert Roitblat, Ph.D. Professor of Psychology roitblat@hawaii.edu University of Hawaii (808) 956-6727 (808) 956-4700 fax 2430 Campus Road, Honolulu, HI 96822 USA From robin@jessikat.demon.co.uk Wed May 19 01:35:46 1999 From: robin@jessikat.demon.co.uk (Robin Becker) Date: Wed, 19 May 1999 01:35:46 +0100 Subject: [Matrix-SIG] Adding a Sparse matrix object In-Reply-To: References: Message-ID: In article , Travis Oliphant writes > >I had the necessity of iteratively inverting a large linear system with >the conjugate gradient method and wanted to use Python, but there is only >rudimentary sparse matrix support. (I couldn't find anything to solve my >problem (without extra coding in C)). So I had to use MATLAB, which has a >rather nice sparse matrix implementation. > >Is there an interest in developing a sparse matrix object with appropriate >methods and functions defined to complement the array object? I >suppose to be symmetric it should be a sparse array object... I'm >interested in generating some discussion on this topic if there are any >takers. > >Thanks, > >Travis Oliphant > > >_______________________________________________ >Matrix-SIG maillist - Matrix-SIG@python.org >http://www.python.org/mailman/listinfo/matrix-sig I think more than one sparse matrix format would be useful. The direct sparse solvers have more than one format (banded, symmetric etc). Iterative methods add to this. -- Robin Becker From hinsen@cnrs-orleans.fr Wed May 19 13:59:46 1999 From: hinsen@cnrs-orleans.fr (Konrad Hinsen) Date: Wed, 19 May 1999 14:59:46 +0200 Subject: [Matrix-SIG] Adding a Sparse matrix object In-Reply-To: (message from Travis Oliphant on Tue, 18 May 1999 15:38:45 -0500 (CDT)) References: Message-ID: <199905191259.OAA21998@chinon.cnrs-orleans.fr> > Is there an interest in developing a sparse matrix object with appropriate > methods and functions defined to complement the array object? I Definitely. The big problems seems to me to decide about the data storage layout; there are simply too many different kinds of sparse matrices. How does MATLAB solve this problem? -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From roitblat@hawaii.edu Wed May 19 18:11:45 1999 From: roitblat@hawaii.edu (Herbert L. Roitblat) Date: Wed, 19 May 1999 07:11:45 -1000 Subject: [Matrix-SIG] Adding a Sparse matrix object Message-ID: <002101bea21a$ad835f70$bef07fce@0gl1u.pixi.com> Matlab has a white paper on sparse matrices in the help\pdf_doc\otherdocs directory called simax.ps. This paper is part of the matlab 5.2 distribution and may be included in other versions. HLR -----Original Message----- From: Konrad Hinsen To: Oliphant.Travis@mayo.edu Cc: matrix-sig@python.org Date: Wednesday, May 19, 1999 4:49 AM Subject: Re: [Matrix-SIG] Adding a Sparse matrix object >> Is there an interest in developing a sparse matrix object with appropriate >> methods and functions defined to complement the array object? I > >Definitely. The big problems seems to me to decide about the >data storage layout; there are simply too many different kinds of sparse >matrices. How does MATLAB solve this problem? >-- >--------------------------------------------------------------------------- ---- >Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr >Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69 >Rue Charles Sadron | Fax: +33-2.38.63.15.17 >45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ >France | Nederlands/Francais >--------------------------------------------------------------------------- ---- > >_______________________________________________ >Matrix-SIG maillist - Matrix-SIG@python.org >http://www.python.org/mailman/listinfo/matrix-sig > From Oliphant.Travis@mayo.edu Wed May 19 18:16:25 1999 From: Oliphant.Travis@mayo.edu (Travis Oliphant) Date: Wed, 19 May 1999 12:16:25 -0500 (CDT) Subject: [Matrix-SIG] Sparse objects Message-ID: It looks like there is enough interest to get something done and it sounds like there is enough experience in the user base to do a decent job of implementation. My first post hinted at the idea of general sparse arrays but I wonder if that is a bit too ambitious at this point, especially considering that I haven't heard of any uses for such beasts. I'm sure one could come up with some uses but the useability/cost ratio seems to me a bit too low at this point. So, we should probably concentrate on just getting a useful sparse matrix object defined. On second thought it may be useful to define an object with a sparsity structure in 2-D and a full structure in the other dimensions --- ah, but wait if we define a good 2-D sparse object then we could but those as elements in NumPy arrays... Storage problem: I looked some at how MATLAB stores sparse matrices. I have not seen any comment on this so I'm not sure but looking at the sizes of some sparse matrices it looks like they use a compressed row or a compressed colum storage format. This is pretty transparent to the user, however, as you mainly interact with the matrix using index notation. The important thing that matlab does is define the standard mathematical operations on sparse matrices so that they happen quickly, so that all of the iterative algorithms can be coded in MATLAB's language. I rather like the idea of having multiple storage formats with a flag in the object indicating which storage format is in use. This would allow better interfacing with existing code. I think it would be useful to have the data itself stored in a NumPy array so that ufuncs could be easily applied. This would add only minimal overhead to the entire structure. -------------------------------------------------- Travis Oliphant 200 First St SW Rochester MN 55905 Ultrasound Research Lab (507) 286-5293 Mayo Graduate School Oliphant.Travis@mayo.edu From ffjhl@uaf.edu Wed May 19 20:39:19 1999 From: ffjhl@uaf.edu (Jonah Lee) Date: Wed, 19 May 1999 11:39:19 -0800 (AKDT) Subject: [Matrix-SIG] Sparse objects In-Reply-To: Message-ID: On Wed, 19 May 1999, Travis Oliphant wrote: > > It looks like there is enough interest to get something done and it sounds > like there is enough experience in the user base to do a decent job of > implementation. I agree. > I rather like the idea of having multiple storage formats with a flag in > the object indicating which storage format is in use. This would allow > better interfacing with existing code. Yes. I currently have some code using Numpy does just that. The formats of interest to me would be: 1. banded, 2. skyline, 3. compressed column. And each with a symmetric and non-symmetric version. Preconditioners would be important as well. Regards, Jonah From hjansen@math.tudelft.nl Thu May 20 06:22:52 1999 From: hjansen@math.tudelft.nl (Henk Jansen) Date: Thu, 20 May 1999 07:22:52 +0200 Subject: [Matrix-SIG] Sparse objects Message-ID: <99052007283003.00636@duti7m> In the "old" Fortran days, I did some work using Yousef Saad's SPARSEKIT (2) sparse matrix (source) library. He was supporting most (appr. 10) of the formats most commonly used. They were all pretty well described in the documentation. It may pay off having a look at it. (I think it's available on Netlib). It may even well be possible to rewrite (or translate, f2c?) his code in C, write a NumPy wrapper around it, and go (provided permissions allow this to do). Regards, Henk. -- -Henk Jansen - hjansen@math.tudelft.nl - phone/fax +31(0)15-278-7295/7209- Dept. of Mathematics and Computer Science - Delft University of Technology --------- http://ta.twi.tudelft.nl/WAGM/people/H.Jansen.html ------------- From turner@blueskystudios.com Thu May 20 15:22:28 1999 From: turner@blueskystudios.com (John Turner) Date: Thu, 20 May 1999 10:22:28 -0400 (EDT) Subject: [Matrix-SIG] Sparse objects In-Reply-To: <99052007283003.00636@duti7m> References: <99052007283003.00636@duti7m> Message-ID: <14148.6820.336785.257@oneida.blueskyprod.com> >>>>> "HJ" == Henk Jansen writes: HJ> In the "old" Fortran days, I did some work using Yousef Saad's HJ> SPARSEKIT (2) sparse matrix (source) library. He was supporting HJ> most (appr. 10) of the formats most commonly used. They were all HJ> pretty well described in the documentation. It may pay off having HJ> a look at it. (I think it's available on Netlib). But if I recall correctly, SPARSEKIT was one of the "researchy" pkgs I alluded to in my previous msg that really only supported one format internally (compressed sparse row, CSR, if I remember correctly), and accomodated other formats by providing routines to convert to and from CSR. Fine for investigating algorithm performance, developing solvers and preconditioners, etc, but not for "production". -- John A. Turner, Ph.D. Senior Research Associate Blue Sky Studios http://www.blueskystudios.com/ One South Road, Harrison, NY 10528 http://www.lanl.gov/home/turner/ Phone: 914-381-8400 http://john.turner.org/ Info on Blue Sky's fully computer-generated, Oscar-nominated short film: http://bunny.blueskystudios.com/ You've never seen computer-generated images like this... From Oliphant.Travis@mayo.edu Thu May 20 21:52:33 1999 From: Oliphant.Travis@mayo.edu (Travis Oliphant) Date: Thu, 20 May 1999 15:52:33 -0500 (CDT) Subject: [Matrix-SIG] Sparse objects In-Reply-To: <00ac01bea27e$8d1fc0c0$f4160218@plstn1.sfba.home.com> Message-ID: An anonymous reader asks this valid question? > Why not wrap the Yale Sparse Matrix package or something from netlib and be > done with it? This is a good suggestion and has already been done to some degree with Neil Schemenauer's sparsemodule which defines a sparse matrix object in wrapping a sparse LU solver available on netlib. As I was looking at it the structure is highly dependent on that used by the wrapped-library and so it is not directly useful for an iterative solver. I didn't want to just repeat this and have another only-useful-here implementation. Matlab has a sparse matrix object that is integrated quite nicely in the language along with some routines which allow for easy construction of sparse matrices so that any iterative algorithm can be rapidly implemented in the MATLAB language. I don't think it would be that difficult to replicate MATLAB's functionality. I posted here before just doing it because I know this is a popular subject and other's would have some good ideas. Plus, this gives someone else the "chance" to get intimate with Python's and Numeric Python's guts by writing C-code which interacts with it. In this case, it seems like we could define a UserArray that acts like a Sparse Matrix. We would likely want some of the operations coded in C but this may be the way to go, rather than defining a new type in C. Does anybody see any obvious problems with this? I'm under the impression that the Yale Sparse Matrix package is only available if you own an IMSL license. Can anybody verify that? Travis From neelk@alum.mit.edu Fri May 21 03:18:54 1999 From: neelk@alum.mit.edu (Neel Krishnaswami) Date: Thu, 20 May 1999 21:18:54 -0500 (EST) Subject: [Matrix-SIG] Small patch to UserArray.py in LLNLDistribution11 Message-ID: <14148.49225.82418.232827@brick.cswv.com> Hi, I just downloaded and built the Numeric package in LLNL Distribution 11. I found a small problem in the UserArray.py module though -- it wasn't working correctly because of inconsistent indentation in the UserArray.__init__() method. (The indentation incorrectly defined all the methods *inside* __init__()'s scope.) Here's a small diff demonstrating the fix. --- UserArray.py~ Thu May 20 20:49:44 1999 +++ UserArray.py Thu May 20 21:03:33 1999 @@ -2,11 +2,11 @@ import string class UserArray: - def __init__(self, data, typecode = None): - self.array = array(data, typecode) - self.shape = self.array.shape - self._typecode = self.array.typecode() - self.name = string.split(str(self.__class__))[0] + def __init__(self, data, typecode = None): + self.array = array(data, typecode) + self.shape = self.array.shape + self._typecode = self.array.typecode() + self.name = string.split(str(self.__class__))[0] def __repr__(self): return self.name+repr(self.array)[len("array"):] -- Neel Krishnaswami neelk@alum.mit.edu From jhsh@iafrica.com Fri May 21 07:52:21 1999 From: jhsh@iafrica.com (Jannie Hofmeyr) Date: Fri, 21 May 1999 08:52:21 +0200 Subject: [Matrix-SIG] Small patch to UserArray.py in LLNLDistribution11 References: <14148.49225.82418.232827@brick.cswv.com> Message-ID: <374502A5.5937C08D@iafrica.com> Neel Krishnaswami wrote: > I just downloaded and built the Numeric package in LLNL Distribution > 11. I found a small problem in the UserArray.py module though -- it > wasn't working correctly because of inconsistent indentation in the > UserArray.__init__() method. (The indentation incorrectly defined all > the methods *inside* __init__()'s scope.) The problem is that the def __init__ is indented with spaces while the rest of the class is indented with tabs. Jannie From hjansen@math.tudelft.nl Fri May 21 07:18:12 1999 From: hjansen@math.tudelft.nl (Henk Jansen) Date: Fri, 21 May 1999 08:18:12 +0200 Subject: [Matrix-SIG] Re: Matrix-SIG digest, Vol 1 #215 - 4 msgs References: <199905210500.BAA02863@python.org> Message-ID: <99052108233207.00636@duti7m> On Fri, 21 May 1999, you wrote: > Message: 2 > From: turner@blueskystudios.com (John Turner) > Date: Thu, 20 May 1999 10:22:28 -0400 (EDT) > To: matrix-sig@python.org > Subject: Re: [Matrix-SIG] Sparse objects > > >>>>> "HJ" == Henk Jansen writes: > > HJ> In the "old" Fortran days, I did some work using Yousef Saad's > HJ> SPARSEKIT (2) sparse matrix (source) library. He was supporting > HJ> most (appr. 10) of the formats most commonly used. They were all > HJ> pretty well described in the documentation. It may pay off having > HJ> a look at it. (I think it's available on Netlib). > > But if I recall correctly, SPARSEKIT was one of the "researchy" pkgs I > alluded to in my previous msg that really only supported one format > internally (compressed sparse row, CSR, if I remember correctly), and > accomodated other formats by providing routines to convert to and from > CSR. Yes, you're right, they only supported CSR and conversion routines to and from it. I never realized (or, can't see) that "production" code would require full (solver) support for all formats. Sparse objects by their nature are lean and quickly convert into other (sparse) objects. Is that penalty too high? > > Fine for investigating algorithm performance, developing solvers and > preconditioners, etc, but not for "production". Henk. -Henk Jansen - hjansen@math.tudelft.nl - phone/fax +31(0)15-278-7295/7209- --Dept. of Mathematics and Computer Science - Delft University of Technology- ---------- http://ta.twi.tudelft.nl/users/hjansen/H.Jansen.html ------------ From turner@blueskystudios.com Fri May 21 17:11:31 1999 From: turner@blueskystudios.com (John Turner) Date: Fri, 21 May 1999 12:11:31 -0400 (EDT) Subject: [Matrix-SIG] Sparse objects In-Reply-To: <99052108233207.00636@duti7m> References: <199905210500.BAA02863@python.org> <99052108233207.00636@duti7m> Message-ID: <14149.34227.582298.919912@oneida.blueskyprod.com> >>>>> "HJ" == Henk Jansen writes: >> But if I recall correctly, SPARSEKIT was one of the "researchy" >> pkgs I alluded to in my previous msg that really only supported one >> format internally (compressed sparse row, CSR, if I remember >> correctly), and accomodated other formats by providing routines to >> convert to and from CSR. HJ> Yes, you're right, they only supported CSR and conversion routines HJ> to and from it. I never realized (or, can't see) that "production" HJ> code would require full (solver) support for all formats. Sparse HJ> objects by their nature are lean and quickly convert into other HJ> (sparse) objects. Is that penalty too high? Memory is often a limiting factor in large, "real", 3-D simulations (hundreds of thousands or millions of cells in an implicit flow calculation, for example). But maybe that's an inherently inappropriate problem space for Python/NumPy. I don't know... Also "full support for all formats" really means a design such that the solvers don't care about the storage format but instead just implement the algorithm on "matrices" and "vectors", with those things knowing how to do the appropriate operations. As yet another twist, in many cases the actual coefficient is never even constructed explicitly, either because it is too difficult or the problem is too large. In this case the solver needs a routine to call to obtain the get the result of, e.g., multiplying some vector by the coefficient. This sort of "matrix-free" implementation is extremely common. My Fortran 90 package does all this in a nice object-based way, and as I've mentioned before represents the last in a series of evolutionary implementations of sparse iterative solver libraries that I've done over a number of years. I'm sort of slow, so I had to do lots of bad implementations along the way, but I think now I at least understand a lot of the issues. I'd love to collaborate with someone who knows Python/NumPy better than I do on the development of some sparse solver capability. I know I'd learn a lot in the process, and maybe the community would gain a useful tool as well. -- John A. Turner, Ph.D. Senior Research Associate Blue Sky Studios http://www.blueskystudios.com/ One South Road, Harrison, NY 10528 http://www.lanl.gov/home/turner/ Phone: (914) 381-8400 http://john.turner.org/ From HYoon@exchange.ml.com Tue May 25 19:55:36 1999 From: HYoon@exchange.ml.com (Yoon, Hoon (CICG - NY Program Trading)) Date: Tue, 25 May 1999 14:55:36 -0400 Subject: [Matrix-SIG] NumPy and XEmacs Crashes on Error on NT Message-ID: from Numeric import * from LinearAlgebra import * matrixmultiply(array([[1,0],[0,1]], 'f'),array([[2],[1]], 'f')) matrixmultiply(array([[1,0],[0,1]], 'f'),array([2],[1], 'f')) # crash! Hi, For some reason, while using NTEmacs beta [version 21.0; Aug 1998] by Charles W. I am getting crashes on many call errors as above and python mode gets killed. Is there a newer version of NTEmacs that does not crash? It just brings up exception as expected on python console or pythonwin: Traceback (innermost last): File "", line 0, in ? TypeError: illegal argument type for built-in operation Thanks, ************************************************************** S. Hoon Yoon (Quant) Merrill Lynch Equity Trading yelled@yahoo.com hoon@bigfoot.com(w) "Miracle is always only few standard deviations away, but so is catastrophe." * Expressed opinions are often my own, but NOT my employer's. "I feel like a fugitive from the law of averages." Mauldin ************************************************************** > -----Original Message----- > From: Jannie Hofmeyr > Sent: Friday, May 21, 1999 2:52 AM > To: neelk@alum.mit.edu > Cc: matrix-sig@python.org > Subject: Re: [Matrix-SIG] Small patch to UserArray.py in > LLNLDistribution11 > > Neel Krishnaswami wrote: > > > I just downloaded and built the Numeric package in LLNL Distribution > > 11. I found a small problem in the UserArray.py module though -- it > > wasn't working correctly because of inconsistent indentation in the > > UserArray.__init__() method. (The indentation incorrectly defined all > > the methods *inside* __init__()'s scope.) > > The problem is that the def __init__ is indented with spaces while the > rest of the class is indented with tabs. > > Jannie > > > > _______________________________________________ > Matrix-SIG maillist - Matrix-SIG@python.org > http://www.python.org/mailman/listinfo/matrix-sig From HYoon@exchange.ml.com Tue May 25 20:30:52 1999 From: HYoon@exchange.ml.com (Yoon, Hoon (CICG - NY Program Trading)) Date: Tue, 25 May 1999 15:30:52 -0400 Subject: [Matrix-SIG] Fibonnaci Message-ID: Hi, Iam trying to do Fibonnaci numbers. Obviously I am trying to raise the base matrix x to some power p, but I don't know how to do it in one step. I would like to call something like x^34. x = array([[ 1., 1.], [ 1., 0.]],'f') >>> x*x array([[ 1., 1.], [ 1., 0.]],'f') >>> matrixmultiply(x,x) array([[ 2., 1.], [ 1., 1.]],'f') >>> matrixmultiply(x,matrixmultiply(x,x)) array([[ 3., 2.], [ 2., 1.]],'f') >>> matrixmultiply(x,matrixmultiply(x,matrixmultiply(x,x))) array([[ 5., 3.], [ 3., 2.]],'f') >>> power(x, 3) array([[ 1., 1.], [ 1., 0.]]) >>> power.outer(x,3) array([[ 1., 1.], [ 1., 0.]]) Thanks much, P.S: Does anyone have Markov Chains in NumPy? ************************************************************** S. Hoon Yoon (Quant) Merrill Lynch Equity Trading yelled@yahoo.com hoon@bigfoot.com(w) "Miracle is always only few standard deviations away, but so is catastrophe." * Expressed opinions are often my own, but NOT my employer's. "I feel like a fugitive from the law of averages." Mauldin ************************************************************** From cgw@fnal.gov Tue May 25 20:53:01 1999 From: cgw@fnal.gov (Charles G Waldman) Date: Tue, 25 May 1999 14:53:01 -0500 (CDT) Subject: [Matrix-SIG] Fibonnaci In-Reply-To: References: Message-ID: <14154.65437.197793.475692@buffalo.fnal.gov> Yoon, Hoon (CICG - NY Program Trading) writes: > Hi, > > Iam trying to do Fibonnaci numbers. Obviously I am trying to raise the > base matrix x to some power p, but I don't know how to do it in one step. I > would like to call something like x^34. The problem is that the default __mul__ and __pow__ methods on arrays multiply the arrays elementwise, rather than as a matrix multiply. You could define an object with __mul__ and __pow__ methods (and their "r" versions) to behave as "proper" matrices. However, you shouldn't have to do this because Numeric provides a "Matrix" class which does exactly this. I was about to send you an example of its use, when I made the unpleasant discovery that it's broken in the current distribution: buffalo:numeric$python Matrix.py Traceback (innermost last): File "Matrix.py", line 27, in ? print m*m File "Matrix.py", line 12, in __mul__ return self._rc(matrixmultiply(self.array, asarray(other))) AttributeError: _rc buffalo:numeric$ buffalo:numeric\$ python UserArray.py ['_typecode', 'array', 'name', 'shape'] () (100, 100) Traceback (innermost last): File "UserArray.py", line 95, in ? ua_small=ua[:3,:5] AttributeError: __getitem__ I guess nobody's really been doing much with UserArray :-( I'll see if I can cook up a quick patch for this.... From cgw@fnal.gov Tue May 25 21:05:04 1999 From: cgw@fnal.gov (Charles G Waldman) Date: Tue, 25 May 1999 15:05:04 -0500 (CDT) Subject: [Matrix-SIG] Fix for UserArray.py Message-ID: <14155.624.855795.577139@buffalo.fnal.gov> Looks like in Distribution 11, the indentation in UserArray.py got botched up. Maybe the critics are right, and Python should have explicit block delimiters!! <**duck**> --- UserArray.py 1999/05/25 19:58:20 1.1 +++ UserArray.py 1999/05/25 19:59:33 @@ -8,96 +8,96 @@ self._typecode = self.array.typecode() self.name = string.split(str(self.__class__))[0] - def __repr__(self): - return self.name+repr(self.array)[len("array"):] + def __repr__(self): + return self.name+repr(self.array)[len("array"):] - def __array__(self,t=None): - if t: return asarray(self.array,t) - return asarray(self.array) + def __array__(self,t=None): + if t: return asarray(self.array,t) + return asarray(self.array) - def __float__(self): - return float(asarray(self.array)) + def __float__(self): + return float(asarray(self.array)) - # Array as sequence - def __len__(self): return len(self.array) + # Array as sequence + def __len__(self): return len(self.array) - def __getitem__(self, index): - return self._rc(self.array[index]) + def __getitem__(self, index): + return self._rc(self.array[index]) - def __getslice__(self, i, j): - return self._rc(self.array[i:j]) + def __getslice__(self, i, j): + return self._rc(self.array[i:j]) - def __setitem__(self, index, value): self.array[index] = asarray(value,self._typecode) - def __setslice__(self, i, j, value): self.array[i:j] = asarray(value,self._typecode) + def __setitem__(self, index, value): self.array[index] = asarray(value,self._typecode) + def __setslice__(self, i, j, value): self.array[i:j] = asarray(value,self._typecode) - def __del__(self): - for att in dir(self): - delattr(self,att) - #del(self) + def __del__(self): + for att in dir(self): + delattr(self,att) + #del(self) - def __abs__(self): return self._rc(absolute(self.array)) - def __neg__(self): return self._rc(-self.array) + def __abs__(self): return self._rc(absolute(self.array)) + def __neg__(self): return self._rc(-self.array) - def __add__(self, other): - return self._rc(self.array+asarray(other)) - __radd__ = __add__ + def __add__(self, other): + return self._rc(self.array+asarray(other)) + __radd__ = __add__ - def __sub__(self, other): - return self._rc(self.array-asarray(other)) - def __rsub__(self, other): - return self._rc(asarray(other)-self.array) + def __sub__(self, other): + return self._rc(self.array-asarray(other)) + def __rsub__(self, other): + return self._rc(asarray(other)-self.array) - def __mul__(self, other): - return self._rc(multiply(self.array,asarray(other))) - __rmul__ = __mul__ + def __mul__(self, other): + return self._rc(multiply(self.array,asarray(other))) + __rmul__ = __mul__ - def __div__(self, other): - return self._rc(divide(self.array,asarray(other))) - def __rdiv__(self, other): - return self._rc(divide(asarray(other),self.array)) + def __div__(self, other): + return self._rc(divide(self.array,asarray(other))) + def __rdiv__(self, other): + return self._rc(divide(asarray(other),self.array)) - def __pow__(self,other): - return self._rc(power(self.array,asarray(other))) - def __rpow__(self,other): - return self._rc(power(asarray(other),self.array)) + def __pow__(self,other): + return self._rc(power(self.array,asarray(other))) + def __rpow__(self,other): + return self._rc(power(asarray(other),self.array)) - def __sqrt__(self): - return self._rc(sqrt(self.array)) + def __sqrt__(self): + return self._rc(sqrt(self.array)) - def tostring(self): return self.array.tostring() + def tostring(self): return self.array.tostring() - def byteswapped(self): return self._rc(self.array.byteswapped()) - def astype(self, typecode): return self._rc(self.array.asType(typecode)) + def byteswapped(self): return self._rc(self.array.byteswapped()) + def astype(self, typecode): return self._rc(self.array.asType(typecode)) - def typecode(self): return self.array._typecode - def itemsize(self): return self.array.itemsize() - def iscontiguous(self): return self.array.iscontiguous() - - def _rc(self, a): - if len(shape(a)) == 0: return a - else: return self.__class__(a) + def typecode(self): return self.array._typecode + def itemsize(self): return self.array.itemsize() + def iscontiguous(self): return self.array.iscontiguous() + + def _rc(self, a): + if len(shape(a)) == 0: return a + else: return self.__class__(a) ############################################################# # Test of class UserArray ############################################################# if __name__ == '__main__': - import Numeric + import Numeric - temp=reshape(arange(10000),(100,100)) + temp=reshape(arange(10000),(100,100)) - ua=UserArray(temp) - # new object created begin test - print dir(ua) - print shape(ua),ua.shape # I have changed Numeric.py - - ua_small=ua[:3,:5] - print ua_small - ua_small[0,0]=10 # this did not change ua[0,0], wich is not normal behavior - print ua_small[0,0],ua[0,0] - print sin(ua_small)/3.*6.+sqrt(ua_small**2) - print less(ua_small,103),type(less(ua_small,103)) - print type(ua_small*reshape(arange(15),shape(ua_small))) - print reshape(ua_small,(5,3)) - print transpose(ua_small) + ua=UserArray(temp) + # new object created begin test + print dir(ua) + print shape(ua),ua.shape # I have changed Numeric.py + + ua_small=ua[:3,:5] + print ua_small + ua_small[0,0]=10 # this did not change ua[0,0], wich is not normal behavior + print ua_small[0,0],ua[0,0] + print sin(ua_small)/3.*6.+sqrt(ua_small**2) + print less(ua_small,103),type(less(ua_small,103)) + print type(ua_small*reshape(arange(15),shape(ua_small))) + print reshape(ua_small,(5,3)) + print transpose(ua_small) From HYoon@exchange.ml.com Tue May 25 21:29:46 1999 From: HYoon@exchange.ml.com (Yoon, Hoon (CICG - NY Program Trading)) Date: Tue, 25 May 1999 16:29:46 -0400 Subject: [Matrix-SIG] Fix for UserArray.py Message-ID: Charles, >>> x = Matrix.Matrix(M, 'f') >>> x = Matrix.Matrix(M, 'f') >>> x >>> x*x Traceback (innermost last): File "", line 0, in ? File "C:\Python\LLNLDistribution\NUMERICAL\LIB\Matrix.py", line 12, in __mul__ return self._rc(matrixmultiply(self.array, asarray(other))) AttributeError: _rc >>> x >>> dir(x) ['_typecode', 'array', 'name', 'shape'] >>> x.array array([[ 0.94999999, 0.03 ], [ 0.05 , 0.97000003]],'f') May be the Matrix is broken as well??? While we are at it, let's go for variable typing as well. ; ) BTW: Do you have new NTXEmacs compiled? Last one is really NumPy unfriendly as you can see from my earlier e-mail. I cannot live without XEmacs on Py. Thank you for everything, ************************************************************** S. Hoon Yoon (Quant) Merrill Lynch Equity Trading yelled@yahoo.com hoon@bigfoot.com(w) "Miracle is always only few standard deviations away, but so is catastrophe." * Expressed opinions are often my own, but NOT my employer's. "I feel like a fugitive from the law of averages." Mauldin ************************************************************** > -----Original Message----- > From: Charles G Waldman > Sent: Tuesday, May 25, 1999 4:05 PM > To: matrix-sig@python.org > Cc: support@icf.llnl.gov > Subject: [Matrix-SIG] Fix for UserArray.py > > > Looks like in Distribution 11, the indentation in UserArray.py got > botched up. Maybe the critics are right, and Python should have explicit > block delimiters!! <**duck**> > > --- UserArray.py 1999/05/25 19:58:20 1.1 > +++ UserArray.py 1999/05/25 19:59:33 > @@ -8,96 +8,96 @@ > self._typecode = self.array.typecode() > self.name = string.split(str(self.__class__))[0] > > - def __repr__(self): > - return self.name+repr(self.array)[len("array"):] > + def __repr__(self): > + return self.name+repr(self.array)[len("array"):] > > - def __array__(self,t=None): > - if t: return asarray(self.array,t) > - return asarray(self.array) > + def __array__(self,t=None): > + if t: return asarray(self.array,t) > + return asarray(self.array) > > - def __float__(self): > - return float(asarray(self.array)) > + def __float__(self): > + return float(asarray(self.array)) > > - # Array as sequence > - def __len__(self): return len(self.array) > + # Array as sequence > + def __len__(self): return len(self.array) > > - def __getitem__(self, index): > - return self._rc(self.array[index]) > + def __getitem__(self, index): > + return self._rc(self.array[index]) > > - def __getslice__(self, i, j): > - return self._rc(self.array[i:j]) > + def __getslice__(self, i, j): > + return self._rc(self.array[i:j]) > > > - def __setitem__(self, index, value): self.array[index] = > asarray(value,self._typecode) > - def __setslice__(self, i, j, value): self.array[i:j] = > asarray(value,self._typecode) > + def __setitem__(self, index, value): self.array[index] = > asarray(value,self._typecode) > + def __setslice__(self, i, j, value): self.array[i:j] = > asarray(value,self._typecode) > > - def __del__(self): > - for att in dir(self): > - delattr(self,att) > - #del(self) > + def __del__(self): > + for att in dir(self): > + delattr(self,att) > + #del(self) > > - def __abs__(self): return self._rc(absolute(self.array)) > - def __neg__(self): return self._rc(-self.array) > + def __abs__(self): return self._rc(absolute(self.array)) > + def __neg__(self): return self._rc(-self.array) > > - def __add__(self, other): > - return self._rc(self.array+asarray(other)) > - __radd__ = __add__ > + def __add__(self, other): > + return self._rc(self.array+asarray(other)) > + __radd__ = __add__ > > - def __sub__(self, other): > - return self._rc(self.array-asarray(other)) > - def __rsub__(self, other): > - return self._rc(asarray(other)-self.array) > + def __sub__(self, other): > + return self._rc(self.array-asarray(other)) > + def __rsub__(self, other): > + return self._rc(asarray(other)-self.array) > > - def __mul__(self, other): > - return self._rc(multiply(self.array,asarray(other))) > - __rmul__ = __mul__ > + def __mul__(self, other): > + return self._rc(multiply(self.array,asarray(other))) > + __rmul__ = __mul__ > > - def __div__(self, other): > - return self._rc(divide(self.array,asarray(other))) > - def __rdiv__(self, other): > - return self._rc(divide(asarray(other),self.array)) > + def __div__(self, other): > + return self._rc(divide(self.array,asarray(other))) > + def __rdiv__(self, other): > + return self._rc(divide(asarray(other),self.array)) > > - def __pow__(self,other): > - return self._rc(power(self.array,asarray(other))) > - def __rpow__(self,other): > - return self._rc(power(asarray(other),self.array)) > + def __pow__(self,other): > + return self._rc(power(self.array,asarray(other))) > + def __rpow__(self,other): > + return self._rc(power(asarray(other),self.array)) > > - def __sqrt__(self): > - return self._rc(sqrt(self.array)) > + def __sqrt__(self): > + return self._rc(sqrt(self.array)) > > - def tostring(self): return self.array.tostring() > + def tostring(self): return self.array.tostring() > > - def byteswapped(self): return self._rc(self.array.byteswapped()) > - def astype(self, typecode): return > self._rc(self.array.asType(typecode)) > + def byteswapped(self): return self._rc(self.array.byteswapped()) > + def astype(self, typecode): return > self._rc(self.array.asType(typecode)) > > - def typecode(self): return self.array._typecode > - def itemsize(self): return self.array.itemsize() > - def iscontiguous(self): return self.array.iscontiguous() > - > - def _rc(self, a): > - if len(shape(a)) == 0: return a > - else: return self.__class__(a) > + def typecode(self): return self.array._typecode > + def itemsize(self): return self.array.itemsize() > + def iscontiguous(self): return self.array.iscontiguous() > + > + def _rc(self, a): > + if len(shape(a)) == 0: return a > + else: return self.__class__(a) > > > ############################################################# > # Test of class UserArray > ############################################################# > if __name__ == '__main__': > - import Numeric > + import Numeric > > - temp=reshape(arange(10000),(100,100)) > + temp=reshape(arange(10000),(100,100)) > > - ua=UserArray(temp) > - # new object created begin test > - print dir(ua) > - print shape(ua),ua.shape # I have changed Numeric.py > - > - ua_small=ua[:3,:5] > - print ua_small > - ua_small[0,0]=10 # this did not change ua[0,0], wich is not normal > behavior > - print ua_small[0,0],ua[0,0] > - print sin(ua_small)/3.*6.+sqrt(ua_small**2) > - print less(ua_small,103),type(less(ua_small,103)) > - print type(ua_small*reshape(arange(15),shape(ua_small))) > - print reshape(ua_small,(5,3)) > - print transpose(ua_small) > + ua=UserArray(temp) > + # new object created begin test > + print dir(ua) > + print shape(ua),ua.shape # I have changed Numeric.py > + > + ua_small=ua[:3,:5] > + print ua_small > + ua_small[0,0]=10 # this did not change ua[0,0], wich is not normal > behavior > + print ua_small[0,0],ua[0,0] > + print sin(ua_small)/3.*6.+sqrt(ua_small**2) > + print less(ua_small,103),type(less(ua_small,103)) > + print type(ua_small*reshape(arange(15),shape(ua_small))) > + print reshape(ua_small,(5,3)) > + print transpose(ua_small) > > _______________________________________________ > Matrix-SIG maillist - Matrix-SIG@python.org > http://www.python.org/mailman/listinfo/matrix-sig From cgw@fnal.gov Tue May 25 21:59:16 1999 From: cgw@fnal.gov (Charles G Waldman) Date: Tue, 25 May 1999 15:59:16 -0500 (CDT) Subject: [Matrix-SIG] More patches for UserArray and Numeric Message-ID: <14155.3876.3486.446012@buffalo.fnal.gov> --P/w5pKn1kt Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit Below are two more patches against LLNLDistribution11. The first one, for UserArray.py is to be applied on top of the indentation-fixing patch I recently posted. This patch fixes some problems with the typecode method, and allows one to assign directly to the "shape" attribute, as one can do for Numeric arrays. The second patch, for Matrix.py, fixes a few errors. First is that the __init__ for the base class UserArray is not called. Additionally, I now allow square matrices to be raised to positive or negative integer or long integer powers. Of course if the power is negative and the matrix is non-invertible, an exception is raised. Patch #2 for UserArray: --P/w5pKn1kt Content-Type: application/octet-stream Content-Description: Patch #2 for UserArray Content-Disposition: attachment; filename="Upatch2.py" Content-Transfer-Encoding: base64 LS0tIFVzZXJBcnJheS5weQkxOTk5LzA1LzI1IDIwOjQ0OjQwCTEuMgorKysgVXNlckFycmF5 LnB5CTE5OTkvMDUvMjUgMjA6NDY6MDUKQEAgLTcwLDEzICs3MCwxOSBAQAogICAgIGRlZiBi eXRlc3dhcHBlZChzZWxmKTogcmV0dXJuIHNlbGYuX3JjKHNlbGYuYXJyYXkuYnl0ZXN3YXBw ZWQoKSkKICAgICBkZWYgYXN0eXBlKHNlbGYsIHR5cGVjb2RlKTogcmV0dXJuIHNlbGYuX3Jj KHNlbGYuYXJyYXkuYXNUeXBlKHR5cGVjb2RlKSkKICAgIAotICAgIGRlZiB0eXBlY29kZShz ZWxmKTogcmV0dXJuIHNlbGYuYXJyYXkuX3R5cGVjb2RlCisgICAgZGVmIHR5cGVjb2RlKHNl bGYpOiByZXR1cm4gc2VsZi5hcnJheS50eXBlY29kZSgpCiAgICAgZGVmIGl0ZW1zaXplKHNl bGYpOiByZXR1cm4gc2VsZi5hcnJheS5pdGVtc2l6ZSgpCiAgICAgZGVmIGlzY29udGlndW91 cyhzZWxmKTogcmV0dXJuIHNlbGYuYXJyYXkuaXNjb250aWd1b3VzKCkKIAogICAgIGRlZiBf cmMoc2VsZiwgYSk6CiAgICAgICAgCWlmIGxlbihzaGFwZShhKSkgPT0gMDogcmV0dXJuIGEK ICAgICAgICAJZWxzZTogcmV0dXJuIHNlbGYuX19jbGFzc19fKGEpCisKKyAgICBkZWYgX19z ZXRhdHRyX18oc2VsZixhdHRyLHZhbHVlKToKKyAgICAgICAgaWYgYXR0cj09J3NoYXBlJzoK KyAgICAgICAgICAgIHNlbGYuYXJyYXkuc2hhcGU9dmFsdWUKKyAgICAgICAgZWxzZToKKyAg ICAgICAgICAgIHNlbGYuX19kaWN0X19bYXR0cl09dmFsdWUKIAogCiAjIyMjIyMjIyMjIyMj IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjCg== --P/w5pKn1kt Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit Patch for Matrix.py, implementing M**n: --P/w5pKn1kt Content-Type: application/octet-stream Content-Description: Patch for Matrix.py Content-Disposition: attachment; filename="mpatch" Content-Transfer-Encoding: base64 LS0tIE1hdHJpeC5weQlUaHUgQXByICAxIDE4OjE0OjQ1IDE5OTkKKysrIC4uLy4uLy4uL0xM TkxEaXN0cmlidXRpb24xMWEvTnVtZXJpY2FsL0xpYi9NYXRyaXgucHkJVHVlIE1heSAyNSAx NTo1NDo0NyAxOTk5CkBAIC02LDggKzYsMTIgQEAKIAogZnJvbSBVc2VyQXJyYXkgaW1wb3J0 IFVzZXJBcnJheSwgYXNhcnJheQogZnJvbSBOdW1lcmljIGltcG9ydCBtYXRyaXhtdWx0aXBs eQorZnJvbSBMaW5lYXJBbGdlYnJhIGltcG9ydCBpbnZlcnNlCiAKIGNsYXNzIE1hdHJpeChV c2VyQXJyYXkpOgorICAgIGRlZiBfX2luaXRfXyhzZWxmLCBkYXRhLCB0eXBlY29kZT1Ob25l KToKKyAgICAgICAgVXNlckFycmF5Ll9faW5pdF9fKHNlbGYsZGF0YSx0eXBlY29kZSkKKyAg ICAgICAgCiAgICAgZGVmIF9fbXVsX18oc2VsZiwgb3RoZXIpOgogCXJldHVybiBzZWxmLl9y YyhtYXRyaXhtdWx0aXBseShzZWxmLmFycmF5LCBhc2FycmF5KG90aGVyKSkpCiAKQEAgLTE1 LDcgKzE5LDIyIEBACiAJcmV0dXJuIHNlbGYuX3JjKG1hdHJpeG11bHRpcGx5KGFzYXJyYXko b3RoZXIpLCBzZWxmLmFycmF5KSkKIAogICAgIGRlZiBfX3Bvd19fKHNlbGYsIG90aGVyKToK LQlyYWlzZSBUeXBlRXJyb3IsICJ4Kip5IG5vdCBpbXBsZW1lbnRlZCBmb3IgbWF0cmljZXMg eCIKKyAgICAgICAgc2hhcGUgPSBzZWxmLmFycmF5LnNoYXBlCisgICAgICAgIGlmIGxlbihz aGFwZSkhPTIgb3Igc2hhcGVbMF0hPXNoYXBlWzFdOgorICAgICAgICAgICAgcmFpc2UgIlR5 cGUgZXJyb3I6IG1hdHJpeCBpcyBub3Qgc3F1YXJlIgorICAgICAgICBpZiB0eXBlKG90aGVy KSBpbiAodHlwZSgxKSwgdHlwZSgxTCkpOgorICAgICAgICAgICAgaWYgb3RoZXI9PTA6Cisg ICAgICAgICAgICAgICAgcmV0dXJuIE1hdHJpeChpZGVudGl0eShzaGFwZVswXSkpCisgICAg ICAgICAgICBpZiBvdGhlcjwwOgorICAgICAgICAgICAgICAgIHJlc3VsdD1pbnZlcnNlKHNl bGYuYXJyYXkpCisgICAgICAgICAgICBlbHNlOgorICAgICAgICAgICAgICAgIHJlc3VsdD1z ZWxmCisgICAgICAgICAgICB3aGlsZShvdGhlcj4xKToKKyAgICAgICAgICAgICAgICByZXN1 bHQ9cmVzdWx0KnNlbGYKKyAgICAgICAgICAgICAgICBvdGhlcj1vdGhlci0xCisgICAgICAg ICAgICByZXR1cm4gcmVzdWx0CisgICAgICAgIGVsc2U6CisgICAgICAgICAgICByYWlzZSBU eXBlRXJyb3IsICJleHBvbmVudCBtdXN0IGJlIGFuIGludGVnZXIiCiAKICAgICBkZWYgX19y cG93X18oc2VsZiwgb3RoZXIpOgogCXJhaXNlIFR5cGVFcnJvciwgIngqKnkgbm90IGltcGxl bWVudGVkIGZvciBtYXRyaWNlcyB5Igo= --P/w5pKn1kt-- From cgw@fnal.gov Wed May 26 17:53:04 1999 From: cgw@fnal.gov (Charles G Waldman) Date: Wed, 26 May 1999 11:53:04 -0500 (CDT) Subject: [Matrix-SIG] Patch for multiarraymodule.c In-Reply-To: References: <14156.7134.243463.190579@buffalo.fnal.gov> Message-ID: <14156.9968.742307.21846@buffalo.fnal.gov> The symptom: Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> from Matrix import * >>> m = Matrix([1,1],[1,0]) Segmentation fault (core dumped) The cure: --- multiarraymodule.c 1999/05/26 16:43:37 1.1 +++ multiarraymodule.c 1999/05/26 16:50:59 @@ -864,6 +864,11 @@ if (tpo == Py_None) { type = PyArray_NOTYPE; } else { + if (!PyString_Check(tpo)){ + PyErr_SetString(PyExc_TypeError, + "typecode must be a character"); + return NULL; + } tp = PyString_AsString(tpo); if (tp[0] == 0) type = PyArray_NOTYPE; else type = tp[0]; From ryszard@moldyn.com Thu May 27 18:31:51 1999 From: ryszard@moldyn.com (Ryszard Czerminski) Date: Thu, 27 May 1999 13:31:51 -0400 (EDT) Subject: [Matrix-SIG] CCL:DX goes open source (fwd) Message-ID: It might be of interest to this group... ------------------------------------------------- The long awaited announcement is now public. Source code will officially be released in two days. http://www.ibm.com/dx As a founding member of the OpenDX.org, I'm happy to answer any questions that aren't answered on the website(s). Cheers, Chris Pelkie Scientific Visualization Producer Cornell Theory Center 618 Rhodes Hall Cornell University Ithaca, NY 14853-3801 chrisp@tc.cornell.edu -= This is automatically added to each message by mailing script =- CHEMISTRY@ccl.net -- To Everybody | CHEMISTRY-REQUEST@ccl.net -- To Admins MAILSERV@ccl.net -- HELP CHEMISTRY or HELP SEARCH CHEMISTRY-SEARCH@ccl.net -- archive search | Gopher: gopher.ccl.net 70 Ftp: ftp.ccl.net | WWW: http://www.ccl.net/chemistry/ | Jan: jkl@osc.edu From Oliphant.Travis@mayo.edu Sun May 30 07:06:48 1999 From: Oliphant.Travis@mayo.edu (Travis Oliphant) Date: Sun, 30 May 1999 01:06:48 -0500 (CDT) Subject: [Matrix-SIG] Sparse matrices Message-ID: After reading many of the informative posts here and thinking a little bit more about the problem of sparse matrices (as least as it applies to me), I've come up with the following solution skeleton and am requesting feedback. I'm going to have a little time this next week and would like to make some progress on improving the sparse matrix support in Python. The basic idea is to define a sparse matrix class in Python which uses NumPy arrays to store the data and index information. The storage format will be variable and indicated by an attribute. Most of the manipulations and basic math operations will be handled by C or Fortran code (right now I'm looking quite favorably at SPARSEKIT2 by Yousef Saad) which is called by the sparse matrix class methods (via a C-module, of course). In addition to this class there will be a collection of iterative and direct solvers that take as arguments sparse matrix objects. These could be written in Python or just wrapped up versions of solvers available in Fortran on the net (like in SPARSEKIT2). SPARSEKIT2 also has a wide selection of conversion routines which could be used. The problem I see with SPARSEKIT2 is that it is defined only for double precision types and I need a complex sparse matrix. It may be possible, however, to compile the key components of SPARSEKIT2 for complex numbers fairly straightforwardly (search-and-replace, comments?) That's a plan of attack as I (perhaps naively) see it. Any comments would be appreciated and encouraged, as I know there are people on this list with a lot more experience in this area than I have. Thanks, Travis Oliphant From hjansen@math.tudelft.nl Mon May 31 09:01:37 1999 From: hjansen@math.tudelft.nl (Henk Jansen) Date: Mon, 31 May 1999 10:01:37 +0200 Subject: [Matrix-SIG] Re: Matrix-SIG digest, Vol 1 #220 - 1 msg References: <199905310500.BAA17078@python.org> Message-ID: <9905311006050A.00636@duti7m> On Mon, 31 May 1999, you wrote: > > From: Travis Oliphant > > Most of the manipulations and basic math operations will be handled by C > or Fortran code (right now I'm looking quite favorably at SPARSEKIT2 by > Yousef Saad) which is called by the sparse matrix class methods (via a > C-module, of course). I seem to rememeber that c.a. 5 years ago when I used the Fortran version of SPARSEKIT2, it was only available for non-commercial use. I guess this may have changed in the meantime so that it will fit into Python's *all-free" philosophy. Henk. -- -Henk Jansen - hjansen@math.tudelft.nl - phone/fax +31(0)15-278-7295/7209- Dept. of Mathematics and Computer Science - Delft University of Technology --------- http://ta.twi.tudelft.nl/users/hjansen/H.Jansen.html ----------- From hjansen@math.tudelft.nl Mon May 31 09:17:21 1999 From: hjansen@math.tudelft.nl (Henk Jansen) Date: Mon, 31 May 1999 10:17:21 +0200 Subject: [Matrix-SIG] egcs compiles CXX??? Message-ID: <9905311028080B.00636@duti7m> Joe van Andel sent the following posing on Tue, 04 May1999: > Good news: > > egcs-2.93.21 19990502 now compiles CXX code (on Solaris 2.6, and > probably other targets). (No patching required). > > Using templates slows down the compiler noticably, but at least we can > now use CXX to build C++ to Python interfaces. I downloaded the newer egcs-2.95 19990524 but haven't been quite as successful with the CXX code from the LLNLDistribution11. Actually, I ran into the same template-related compiling problems as before. (Joe's success was booked on Solaris and I'm using Linux, RedHat 5.2 but I can't see this difference will matter.) Help appreciated, thanks, Henk. -- -Ir. Henk Jansen - hjansen@math.tudelft.nl - phone/fax +31(0)15-278-7295/7209- Dept. of Mathematics and Computer Science - Delft University of Technology --------- http://ta.twi.tudelft.nl/users/hjansen/H.Jansen.html ----------- From avv@quasar.ipa.nw.ru Mon May 31 21:14:37 1999 From: avv@quasar.ipa.nw.ru (Alexander V. Voinov) Date: Mon, 31 May 1999 13:14:37 -0700 Subject: [Matrix-SIG] NumPy C API and RedHat 6.0 Message-ID: <3752EDAD.CCBC2D1E@quasar.ipa.nw.ru> Dear Colleagues, I fail to recompile my Python extension modules, which involve NumPy C API, under RedHat 6.0. There is a segmentation fault on the first call to PyArray_ContiguousFromObject, PyArray_FromDims, etc. It was all ok with RH 5.2. The shared modules are in their places. I used first Oliver Andrich rpms, but finally recompiled Numeric from the sources. Same result. What may be the cause? Thank you in advance Alexander From HYoon@exchange.ml.com Mon May 31 23:32:57 1999 From: HYoon@exchange.ml.com (Yoon, Hoon (CICG - NY Program Trading)) Date: Mon, 31 May 1999 18:32:57 -0400 Subject: [Matrix-SIG] egcs compiles CXX??? Message-ID: Hi, Has there been anyone able to use CXX code using egcs with NT? I have some code in Fortran and C that I need VC++ is not so good with F77 on NT side. Are there docs for CXX and numpy combined? I found Travis' docs and CXX from LLNL, but no CXX and Numpy (although David A. had one page on his pdf file). BTW: LLNL distribution 11 for NT is not available. Thanks in Adv, ************************************************************** S. Hoon Yoon (Quant) Merrill Lynch Equity Trading yelled@yahoo.com hoon@bigfoot.com(w) "Miracle is always only few standard deviations away, but so is catastrophe." * Expressed opinions are often my own, but NOT my employer's. "I feel like a fugitive from the law of averages." Mauldin ************************************************************** > -----Original Message----- > From: Henk Jansen > Sent: Monday, May 31, 1999 4:17 AM > To: matrix-sig@python.org > Subject: [Matrix-SIG] egcs compiles CXX??? > > Joe van Andel sent the following posing on Tue, 04 May1999: > > > Good news: > > > > egcs-2.93.21 19990502 now compiles CXX code (on Solaris 2.6, and > > probably other targets). (No patching required). > > > > Using templates slows down the compiler noticably, but at least we can > > now use CXX to build C++ to Python interfaces. > > I downloaded the newer egcs-2.95 19990524 but haven't been quite as > successful > with the CXX code from the LLNLDistribution11. Actually, I ran into the > same > template-related compiling problems as before. (Joe's success was booked > on > Solaris and I'm using Linux, RedHat 5.2 but I can't see this difference > will > matter.) > > Help appreciated, thanks, > > Henk. > > -- > -Ir. Henk Jansen - hjansen@math.tudelft.nl - phone/fax > +31(0)15-278-7295/7209- > Dept. of Mathematics and Computer Science - Delft University of > Technology > --------- http://ta.twi.tudelft.nl/users/hjansen/H.Jansen.html > ----------- > > > _______________________________________________ > Matrix-SIG maillist - Matrix-SIG@python.org > http://www.python.org/mailman/listinfo/matrix-sig