[PYTHON MATRIX-SIG] Calling all extensions...

Doug Heisterkamp drh@cse.unl.edu
Mon, 4 Nov 1996 14:03:37 -0600 (CST)


> 
> 
> Your general approach seems interesting. We should work much more in
> that direction.
> 
> Btw, has anybody written a general module to dynamicaly load numericl
> procedures
> after declaring their argument types. There is a module in the python
> distribution,
> but it's very rudimentary.

I assume you mean dlmodule.  I have not look at that module before -- I'd
assume it was Sun specific.  Is it portable and is there documentation
for it?

> 
> I do not remeber the exact form in Scilab, but in Python it should work
> like:
> 
> C-Function: double func(int n, double* a, int r, double s)
> 
> f=dynload(func, 'd', 'i', 'D', 'i', 'd') (or f=funcload('diDid') , or
> f=funcload('d', 'iDid'))
> res = f(10, arange(10), 3, 5.3)
> 

I think something like this is possible.  I would prefer separating the
return type from the parameter types and making the return type optional
with a default of returning None.  I would also like an optional argument
for the library which holds the function.  The default libraries list 
could be kept in the dynamic load module.  

> Some months ago I also saw a Tcl-extenion for compiling simple
> C-Cyntax like expressions (just Tcl strings) to C-Functions on the fly..
> 
<snip>
> 
> This is a dirty, not so Python-like solution, but is there a better one
> for scientific computations. For heavy computations you need compiled
> functions, which you can
> generate on the fly, evaluating a interpreted function 10000 time for a
> computation
> is to slow. Any comments on that.

Generating compiled functions on the fly can be done right now if you 
have a set interface.  Doing it portably could be difficult.  But it
can be done by (1) writing the text to a file, (2) executing a makefile
that (a) compiles the text file, (b) places it into a library, (c) relinks
the dynamically loaded module that holds the interface function with
the library, (d) copy the module to python's sharedmodule directory, 
(3) reload the module.

If we can get a dynload module working then the restriction on having
a set interface is gone, and also the restriction of using only a 
certain number of functions at one time is gone (the interface module
has a static number of function interfaces).

As to interpreted functions being to slow for heavy computations, I think
it will depend on the problem.  But in general, I think it will be true.
I'm hopeful that if the function is using the array operations then
it will run in a reasonable amount of time.  Even if it does not, there
is always late friday afternoons.  Where letting the machine run over the
weekend is much better than staying into the evening and writing the
C functions.


> 
> What about sparse matrices. I remeber we had a discussion on that a very
> long time ago.
> I propose taking the sparsepack library and melting it with NumPy.

Which sparse matrix library do you use?  I don't need to use sparse
matrices at the moment, but I would be willing to help someone else
in setting up the interface with NumPy.

Doug Heisterkamp
drh@cse.unl.edu



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

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