Blitz logo

Blitz Support :

From: Todd Veldhuizen (tveldhui_at_[hidden])
Date: 2003-07-21 07:58:46


Oh! I get it now. Maybe you can use this method, from
blitz/array/slicing.cc:

/*
 * After calling slice(int rank, Range r), the array refers only to the
 * Range r of the original array.
 * e.g. Array<int,1> x(100);
 * x.slice(firstRank, Range(25,50));
 * x = 0; // Sets elements 25..50 of the original array to 0
 */
template<class P_numtype, int N_rank>
void Array<P_numtype, N_rank>::slice(int rank, Range r);

It's no so convenient that it changes the array view you call the slice()
method on.. If you want a version that behaves better, this should work:

template<class T, int N>
Array<T,N> slice(Array<T,N>& A, int rank, Range r)
{
  Array<T,N> x(A);
  x.slice(rank,r);
  return x;
}

Hope that helps, sorry for the confusion.

Cheers,
Todd

-- 
Todd Veldhuizen  /  tveldhui_at_[hidden]  /  Indiana University Computer Science
On Sun, 20 Jul 2003, Alex Fore wrote:
> I think what he is trying to say, correct me if I am wrong, is that he would like a way to di this without having to specify all of the range arguments. i.e if we had a rank 3 array, and you wanted to pull out a subarray containing all elements of the array where the firstDimension's index was 5. with slicing one would need to:
>
> Array<T,3> big_array(10,10,10);
>
> Array<T,2> subarray;
> subarray = big_array(5,Range::all(),Range::all());
>
> when it would be nice to have a way to do this by just specifying that you want all elements which are indexed by j in the i'th dimension.
>
> int i = 0; int j = 5;
>
> subarray = big_array.sub(i,j);
>
> But the rank of tensor is a template argument so I dunno if this can be done in a rank - independant way.
> -Alex
>
> On Sun, 20 Jul 2003 13:22:44 -0400
> "Dalal, Navneet" <navneet.dalal_at_[hidden]> wrote:
>
> > Thanks Todd,
> >
> > but as I want to write meta programmes, so this way of specifying slicing
> > will be different for different dimensions.
> > I am looking for dimension independent function or operator.
> >
> > thanks
> > navneet
> >
> > > -----Original Message-----
> > > From: Todd Veldhuizen [mailto:tveldhui_at_[hidden]]
> > > Sent: Sunday, July 20, 2003 1:14 PM
> > > To: Support list for Blitz++
> > > Subject: Re: [Blitz-support] Sub arrays in blitz meta programming
> > >
> > >
> > > Hi Navneet,
> > >
> > > Try simply
> > >
> > >    Array<double,1> b = a(5, Range::all());
> > >
> > > See the slicing section of the manual for more detail:
> > > http://www.oonumerics.org/blitz/manual/blitz02.html#index00087
> > >
> > > Cheers,
> > > Todd
> > > --
> > > Todd Veldhuizen  /  tveldhui_at_[hidden]  /  Indiana University
> > > Computer Science
> > >
> > > On Thu, 17 Jul 2003, Dalal, Navneet wrote:
> > >
> > > > Hi,
> > > >
> > > > I am writing bilinear interpolation code using blitz
> > > arrays. I would like to
> > > > write this code for general N-d arrays using meta programming.
> > > >
> > > > However, I am stuck with one problem: how can I get a sub
> > > array along one
> > > > particular dimension for a blitz array ?
> > > >
> > > > What I need is something like this:
> > > >
> > > > Array<double, 2> a (10, 10);
> > > > // init a
> > > >
> > > > int index = 5;
> > > > int firstDimension = 0;
> > > >
> > > > Array<double,1> b = a.subarray(firstDimension, index);
> > > >
> > > > // now b points to a(5, range::all)
> > > >
> > > >
> > > >
> > > > Is there a function or operator already overloaded for this purpose?
> > > >
> > > > thanks
> > > > navneet
> > > > _______________________________________________
> > > > Blitz-support mailing list
> > > > Blitz-support_at_[hidden]
> > > > http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
> > > >
> > > _______________________________________________
> > > Blitz-support mailing list
> > > Blitz-support_at_[hidden]
> > > http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
> > >
> > _______________________________________________
> > Blitz-support mailing list
> > Blitz-support_at_[hidden]
> > http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
> >
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>