
On 12/17/12 11:24, Larry Evans wrote:
On 12/17/12 09:50, gast128 wrote:
Dear all,
we use here the multi_array as a 2 dimensional matrix. Often we want to resize the row or column dependent on some GUI event. Code could be:
void Bla::ResizeRows(size_t nRows) { m_matrix.resize(boost::extents[nRows][m_matrix[0].size()]); }
However this uses the 0-index of row count (i.e. 'm_matrix[0].size()') to determine the size of the columns. Will this not crash if you have 0 rows? And if so is there a better alternative?
wkr. The test driver:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/sandbox/array_dyn/...
produces output:
********reshape demo*********** dir_op=0 shape={ 0, 3} my_data.size()=0 ai= } . shape={ 1, 3} ai= { { 0, 0, 0} } . shape={ 5, 3} ai= { { 0, 0, 0} , { 0, 0, 0} , { 0, 0, 0} , { 0, 0, 0} , { 0, 0, 0} } .
Compilation finished at Mon Dec 17 11:11:25
Which suggests it will work when 1st axis (the row axis) has 0 as it's size. Unfortunately, this is not Boost.MultiArray and it's probably a lot slower since the sizes of the dimensions are all runtime values. Also, the printout when the shape includes a 0, as in:
shape={ 0, 3}
does not have balanced curly brackets:
ai= }
I'm not sure how to handle that yet.
Addition of print_array<.>::visit_empty and corresponding change to array_host seems to solve the empty axis print problem: ********reshape demo*********** dir_op=0 shape={ 3, 0} my_data.size()=0 ai= { { } , { } , { } } . shape={ 3, 1} ai= { { 0} , { 1} , { 2} } . shape={ 3, 5} ai= { { 0, 3, 6, 9, 12} , { 1, 4, 7, 10, 13} , { 2, 5, 8, 11, 14} } . shape={ 0, 5} ai= { } . Compilation finished at Mon Dec 17 12:55:44 HTH. -regards, Larry