[pythran] Re: access multiple dimensions in cpp

  • From: Jochen S <cycomanic@xxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Sat, 16 Jan 2021 17:37:55 +0100

I was looking for a solution using pythran's ndarray (working on a patch
for pythran so don't think I can use xtensor), but I think your solution
might give me enough of an idea how to do this.  Thanks!

On Sat, Jan 16, 2021 at 1:08 PM Neal Becker <ndbecker2@xxxxxxxxx> wrote:

funny you should mention that, I have code that does exactly what you're
asking for.  In my ND-histogram class, I have a resize option.  This will
copy the small hypercube into a new one.

    auto cube = xt::xdynamic_slice_vector();
    for (int i = 0; i < buckets.dimension(); ++i) {
      int minindex = nint(mins[i]/deltas[i]) - nint(_mins[i]/deltas[i]);
      cube.push_back(xt::range(minindex, minindex + buckets.shape()[i]));
    }
    xt::dynamic_view(newhistogram.buckets, cube) = buckets;

On Sat, Jan 16, 2021 at 5:16 AM Jochen S <cycomanic@xxxxxxxxx> wrote:

How do I access multiple dimensions of an ndarray in cpp, in particular
if I don't know the number of dimensions? I guess I have to use
continguous_slice somehow? What I'm trying to do is to copy a
(N-n)x(M-m)x(K-k) array into a NxM,K array (however I might have more than
3 dimensions). So in python I would do something like: out[:n,:m,:k] = in,
is there some whay I could achieve the same in cpp in pythran?



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

Other related posts: