Hi All,

I have got somthing that puzzles me about the definition and use of operator [].

Suppose I have a 1D array A={a,b,c,d}

And I wish to genrate a 2D array of the form B={b,a,d,c}

Then I would gusess that I should create a 2D indices array, where each index consists of a single value:


Such that


But the documentation says:

dense< T, 2 >operator[] (const dense< array< usize, 2 >, 2 > &indices) const
Returns a dense container R of the same size as indices, such that R[i] == (*this)[indices[i]].
Meaning the that regradless of the dimention of the original array (in our case D=1) one needs to use a 2D indices array which consists of 2 elements (array< usize, 2 >) instead of a single one.

It would be great if some one could clarify this...



2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


Your confusion comes from a misunderstanding that the calling object of operator[] and the returned object can have different number of dimensions. In particular, you cannot produce a 2D dense out of a 1D dense using operator[].

This class template member function:

dense operator[] (const dense, 2>& indices) const

only applies when *this is a 2D dense.

ArBB provides "reshape" and "reshape_as" utility functions that allow you to create a 2D or 3D dense object out of a 1D dense. You should use them to solve your problem. Please check their descriptions here.

Leave a Comment

Please sign in to add a comment. Not a member? Join today