The nested container resize_as() function misbehaves, in beta 4 and beta 5, Sandy Bridge or Core 2, Debug or Release modes in MSVC 10. Consider this code (pretty print code below):
dense dat = dense::parse("{1.,2.,3.,4.}");
nested idx = nested::parse("{{3},{2},{1,1},{0,0}}");
nested out = reshape_as(dat, idx);
...from which I expected this result, reading the docs:
out: {{4},{3},{2,2},{1,1}}
flat: 4 3 2 2 1 1
...instead the result is:
out: {{1},{2},{3,4},{0,0}}
flat:1 2 3 4
Apparently an improper nested container has been constructed with too little data, without throwing an exception, and operator(i,j)"reads" beyond the available data without complaint.If the data is changed to:
dense dat = dense::parse("{1.,2.,3.,4.,5.,6.,7.,8.}");
...the result is:
out: {{1},{2},{3,4},{5,6}}
flat:1 2 3 4 5 6 7 8
Another apparently improper nested container with too much data.
If reshape_as() merely operates like reshape_nested_lengths(), ~offsets(), and ~flags() there would be no excuse for the reference argument to be nested. It could be any nested type. While not explicitly documented, one suspects reshape_as() is the nested equivalent of the dense's gather() function ...especially since there is no other. In any case, reshape_as() does unexpected things.
- paul
Pretty printing code:
cout << "out: {";
_for(usize i = 0, i < idx.offsets().length(), ++i)
{
_if(c0) {
cout << "},"; } _end_if;
c0 = true;
cout << "{";
boolean c1 = false;
_for(usize j = 0, j < idx.segment(i).length(), ++j)
{
_if(c1) {
cout << ","; } _end_if;
c1 = true;
cout << value(out(i,j));
} _end_for;
} _end_for;
cout << "}}" << endl;
dense flat = out.flatten();
cout << "flat:";
const_range r = flat.read_only_range();
for (const_range::const_iterator i = r.begin(); i != r.end(); ++i)
cout << *i << " ";
cout << endl;



