Robert Jacques wrote:
That sounds sensible. However, extensive experience in Matlab has taught me that resorting to custom for-loop indicates you've failed to sufficiently think in arrays. :)

Indeed, most use cases are simple enough to be handled in array notation. I have worked with Matlab and Python and managed to come up with array notations in many non-trivial cases as well. However, once in a while, it just cannot be done. Typically, this happens when you have to handle non-linear terms or high order tensorial objects.

Of course, my examples were simple enough to permit alternative expressions, but I have encountered quite a number of cases where I could not avoid a loop in Python. I is hard to spontaneously construct something useful that I can describe in a few lines.

Imagine a charge density in one dimension:
        rho[r]
and then compute the coulomb energy
        sum(r1,r2)(rho[r1]*rho[r2]/(r1-r2))

Or an expression containing function calls

        sum(i,j)(f(i)*g(j)*A[i,j]))

Ultimately, 'sum' and other reduction would actually be just one use case. One could even use the same mechanism to construct arrays from expressions.

        auto A = array(a=0:10,b=0:20)(2*a + b%3)

(Disregard the exact syntax here...)

I will think further about this and try to come up with more specific use cases.

Greetings,
Norbert

Reply via email to