[pythran] Re: ndarray

  • From: Neal Becker <ndbecker2@xxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Fri, 29 Aug 2014 09:07:54 -0400

If an array is dense, indexing optimizations can be applied.  It is not
necessary to refer to the strides.

For example if we want to apply the ufunc 'sqr' to each element of an
array, if we know it is dense (contiguous, not strided), then we can in c++
use simple iteration:

for (; ...; ;):
  *out++ = sqr (*in++);

and avoid indexing calculations.

Also, for dense arrays, we can use simd.

But if the argument is not dense (contiguous), e.g., x[::2], then we do
need to take the strides into account, and IIRC simd can't be used.

My interest is communications and digital signal processing.


On Fri, Aug 29, 2014 at 8:57 AM, serge Guelton <sguelton@xxxxxxxxxxxxx>
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
> >
> > https://github.com/ndarray/ndarray
> >
> > which I have been making heavy use of for my python c++ needs.
> >
> > It seems not.
>
> Indeed
>
> >
> > https://github.com/ndarray/ndarray uses 3 template parameters
> >
> > <T,N,M>
> >
> > 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
> > accordingly?
>
> 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?
>
>


-- 
*Those who don't understand recursion are doomed to repeat it*

Other related posts: