[Matrix-SIG] Numpy in Viper

Konrad Hinsen hinsen@cnrs-orleans.fr
Wed, 27 Oct 1999 17:35:05 +0200


> 	Functional operations, such as 'map' and 'reduce'
> do not use indexing; that is, they represent loops, but
> the loops are not written explicitly. Therefore, the 'indexing'
> scheme must be embodied in the data structure they are applied to.

Not necessarily; in J, you would add a modifier to the map operation
to give it some specific rank. On the other hand, it often makes sense
to attach this information to the data, because it rarely changes in
the course of some computation.

> 	Not quite: things that reinterpret the shape are also 'operations'.
> In fact, the key to the design is that things like:
> 
> 	map undim array # 'undim' removes a dimension
> 
> can be interpreter two ways:
> 
> 	(map undim) array
> 
> and
> 
> 	map (undim array)
> 
> That the 'map' and 'undim' operations commute with array like this
> is the essential point: (map undim) is a new operation, and
> (undim array) is a new data structure.

OK, then the (map undim) interpretation is the J way of doing it. In
NumPy, you can only modify the array shape. For mapping a
two-dimensional object, you have to reshape the array, rolling the
mapped dimensions into one, then apply map(), and then reshape again.
A more general map() could be implemented without breaking any
compatibility, but I don't see an easy way to provide a general
mechanism for deriving structural operations.


> > approach would have been better. So I'd like to ask the same
> > question about FISh: where does the difference matter?
> 
> 	Polymorphism. In 'classic' functional programming
> languages, 'map' is type polymorphic in the sense that in

Fine, but the question was about a *practical* application, not
one of principle or elegance (which doesn't mean I don't care,
but it's good idea to keep in mind that programing languages
are made to solve real-life problems).

> 	What does this mean? It means you can write a program which
> works on matrices of ANY rank: that is, a rank polymorphic program.
> Just as you can write programs for 2D matrices of any dimensions.
> This CANNOT be done using indexing, because each extra rank requires
> another loop written in the program.

Still you can write rank polymorphic code in NumPy, using the approach
I mentioned above. I even did it. I wish it were easier, sure, but
being possible is already quite good, compared to (shudder) Fortran
programming...

Konrad.
-- 
-------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------