Discussion: new operators for numerical computation

Huaiyu Zhu hzhu at localhost.localdomain
Fri Jul 21 15:05:08 EDT 2000


On 21 Jul 2000 12:08:23 +0200, Konrad Hinsen <hinsen at cnrs-orleans.fr> wrote:
>
>The cleanest concept (in my opinion) is the one implemented in J,
>where an array has (conceptually) a "data rank" and a "value rank",
>the sum of the two being the rank, i.e. the number of indices. For
>example, an array of rank 3 could be interpreted as a list of matrices
>(data rank 1, value rank 2), as a matrix of vectors (data rank 2,
>value rank 1), or as a 3-d array of scalars (data rank 3, value rank
>0). In J the data and value ranks are not properties of the arrays,
>but of the operators, whose value rank can be modified. In the early
>days of NumPy development, I proposed this model for NumPy as well,
>but there was no majority for it. And I agree that there are not so
>many practical cases where this mechanism is necessary. However,
>it nicely illustrates how one would extend vector and matrix operations
>to higher-dimensional data.

This looks like a good idea.  The question is whether we need to put this
into the infix operators or as class methods.

For example.  I have a current piece of code like this (which animates the
performance of a learning algorithm against two parameters)

for i: for j: A[i,j,:] = vector
for k: matrix = A[:,:,k]; gplot.mesh(matrix); sleep(0.1)

Now this does not contain infix operators, but even if it did, the operators
don't need to know they are operating on part of a larger piece of data.

Another example concerns the inner and outer products.  Suppose we define a
class of tensor-with-indices, we could do innerproduct like

a = b.index((2,3)) * c.index((2,4))     # a_ilmnp = b_ijkl c_mjnkp

and outerproduct like

a = b.index(()) * c.index(())           # a_ijklmnpqr = b_ijkl c_mnpqr

Is this similar to what you proposed? It looks to me this is can be handled
by the existing Python mechanism of method overloading.

Huaiyu



More information about the Python-list mailing list