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 Real_N2_Tensor;
typedef boost::array
Real_N2_Tensor_Index;
typedef typename boost::multi_array Positive_N1_Tensor;
typedef boost::array
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