Clone this wiki locally

SIMD array operations

This proposal is about adding SIMD behaviour/elementwise behaviour to the arrays proposed in CEP 517, in arithmetic operators and function calls.

Noone stands ready to implement this at the moment, it mainly serves as a potential future development direction in order to discuss the merits of CEP 517. Discussing minute details in this proposal should therefore probably wait.

What will this make possible that is currently not possible?

The idea is to turn a longer expression into a single pass over the data. In many situations this can reduce memory bus traffic over the common Python approach (which is to evaluate each subexpression one by one into temporary buffers).

There seems to be only two possible ways of achieving this at compile-time. One is building it into the language (proposed here). The other would be using the powerful metaprogramming capabilities of C++ and wrap a C++ library. However to get the nice interopability with Python, such a C++ library would need to be pretty much custom-written for use by Cython.

For function calls like sqrt above, functions must have arguments typed as the base-type of the array. If they take object this is interpreted as the entire array coerced to an object, not element-wise behaviour.

Side-effects in functions calls do (of course) happen once for each element in the array -- this is just part of the convention

Broadcasting

The NumPy broadcasting rules will apply. This deals with how situations is handled for array with different sizes. The basic idea is that arrays with lower dimensionality gets added 1-length dimensions, and dimensions of length 1 can be repeated. See e.g.: