[pythran] Re: ndarray

  • From: Pierrick Brunet <pierrick.brunet@xxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Fri, 29 Aug 2014 22:26:12 +0200

On 29/08/2014 14:57, serge Guelton wrote:
On Fri, Aug 29, 2014 at 08:38:11AM -0400, Neal Becker wrote:
I noticed pythran using ndarray c++ class, and wondered if it was similar to


which I have been making heavy use of for my python c++ needs.

It seems not.

https://github.com/ndarray/ndarray uses 3 template parameters


where T is type
N is #dim
M is #contiguous dimensions

which allows optimization based on contiguity. Â Would pythran be able to
optimize based on contiguousness? Â For example:

#export sum(int[])
def sum (x):

would pythran be able to detect whether the argument is contiguous and dispatch
I am not sure of what you mean by contiguous dimensions.

In Pythran an ndarray always wraps a flat pointer. When taking slices,
it does not create an intermediate array, but a view that stores the
slices/strides and so on.

I am unsure my answer is clear...

BTW, what's your background / what are you using Pythran for?

Just for information. On your example:

#export sum(int[])
def sum (x):

We will *assum* that x is contiguous.

If you use : sum(a[::2]), you will have an incorrect output.
It can be fix if you need this kind of use.

Otherwise as serge said, simd and even some parallelism is added by the Pythran 
compiler for dense array and even for stride arrays.

Other related posts: