Boost logo

Boost Users :

From: Martin Magnusson (martin.magnusson_at_[hidden])
Date: 2004-11-17 10:24:02


I'm having problems creating a slice of a multi_array in a
dimension-independent manner. Could someone please help?

The code posted here gives me the error
no match for 'operator[]' in 'rn2t[indices]'

Some explanations to the code snippet below:
My class is templated over an unsigned int Dim.
rn2t is a tensor of rank Dim+2 with real-valued elements.
bin_index is of dimension Dim+1, and contains integer indices into a tensor.
I want my_slice to be the one-dimensional vector pointed to by bin_index.

////////////////////////////////////////////////////////////
// Convenience typedefs for multi-rank arrays:
typedef typename boost::multi_array<double, Dim+2> Real_N2_Tensor;
typedef boost::array<typename Real_N2_Tensor::index, Dim+2>
   Real_N2_Tensor_Index;

typedef typename boost::multi_array<Positive, Dim+1> Positive_N1_Tensor;
typedef boost::array<typename Positive_N1_Tensor::index, Dim+1>
   Positive_N1_Tensor_Index;

////////////////////////////////////////////////////////////
template<int Dim>
void My_Class<Dim>::calc( Positive_N1_Tensor_Index bin_index, bool add )
{
   Real_N2_Tensor rn2t;
   // populate rn2t...

   // snip...

   typedef typename Real_N2_Tensor::index_range Range;
   typename Real_N2_Tensor::index_gen indices;
   // Is the following lines the correct way to populate 'indices'?
   indices[bin_index[0]];
   for (int a = 0; a < Dim; ++a)
     indices[bin_index[a+1]];
   indices[Range()];
   typename Real_N2_Tensor::array_view<1>::type my_slice =
        rn2t[indices]; ///// ERROR HERE

   // snip...
}
////////////////////////////////////////////////////////////

/ martin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net