Hi Ron,

This helped a great deal.  I have one follow on question:

Suppose this type of setup was within a function, is it possible to make OneDView the return value of this function?  In other words, I would like to:

array_type::const_array_view <1>::type OneDView;
OneDView = multi_array[myindices];
return OneDView;

In every dimensional case, could I construct my OneDView and save it to a variable so I have don't have to do the setup every time?  The reason I ask is I have this piece of code in a tight loop and it does take a bit of time.  Maybe there is an easier way to do it?  Alternatively, I suppose I could copy the contents of the slice to another vector or array?.   Is there an easy C++/Boost way to do this?

When I compile the code above, I get a compiler error saying operator= is private as least that's what I think it is saying!

Joey

On Jun 18, 2008, at 11:51 AM, Ronald Garcia wrote:

Hi Joey,

I have looked at your self-contained example, so I get the gist of what you're trying to do.  Rather than assigning to the array view, you can assign to an indices object and build the view after the fact.  Here's how to do the 2-dimensional case that you had commented out:

                     //This doesn't work, but I would love a generic version of this:
                     
                     array_type::index_gen::gen_type<1,2>::type myindices;
                     if (desired_slice [0] == -1)
                       myindices = indices [range ()][desired_slice [1]];
                         else
                     if (desired_slice [1] == -1)
                       myindices = indices [desired_slice [0]][range ()];

                     array_type::const_array_view <1>::type OneDView
                       = multi_array[myindices];

                     ret_val = (OneDView [whichPosition]);

HTH,
ron



On Jun 14, 2008, at 10:32 AM, Joey Mukherjee wrote:


I am trying to use boost::multi_array and want to create a view where I am 
lowering the number of dimensions, but I wish the dimension to be reduced 
to be decided at runtime. 

I have a vector of integers and this vector size is the same as the number 
of dimensions.  If the vector [1] value is -1, then the first dimension 
will have all values (i.e. range ()), otherwise it will be a number 
indicating what slice to use. 


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users