comparison liboctave/Array.cc @ 14624:edf9ca8a92a8 stable

when redimensioning, always pad dim_vector objects with 1 (bug #33216) * dim-vector.cc (dim_vector::redim): Always pad with 1. * dim-vector.h (dim_vector::redim): Update comment. * Array.cc (Array<T>::assign): Query dimensions for all zeros before redimensioning. * ov-struct.cc: New test.
author John W. Eaton <jwe@octave.org>
date Fri, 11 May 2012 12:33:13 -0400
parents 3d4bea9accd7
children bb5ecda3b975
comparison
equal deleted inserted replaced
14597:6980b0f35df9 14624:edf9ca8a92a8
1162 template <class T> 1162 template <class T>
1163 void 1163 void
1164 Array<T>::assign (const idx_vector& i, const idx_vector& j, 1164 Array<T>::assign (const idx_vector& i, const idx_vector& j,
1165 const Array<T>& rhs, const T& rfv) 1165 const Array<T>& rhs, const T& rfv)
1166 { 1166 {
1167 bool initial_dims_all_zero = dimensions.all_zero ();
1168
1167 // Get RHS extents, discarding singletons. 1169 // Get RHS extents, discarding singletons.
1168 dim_vector rhdv = rhs.dims (); 1170 dim_vector rhdv = rhs.dims ();
1171
1169 // Get LHS extents, allowing Fortran indexing in the second dim. 1172 // Get LHS extents, allowing Fortran indexing in the second dim.
1170 dim_vector dv = dimensions.redim (2); 1173 dim_vector dv = dimensions.redim (2);
1174
1171 // Check for out-of-bounds and form resizing dimensions. 1175 // Check for out-of-bounds and form resizing dimensions.
1172 dim_vector rdv; 1176 dim_vector rdv;
1177
1173 // In the special when all dimensions are zero, colons are allowed 1178 // In the special when all dimensions are zero, colons are allowed
1174 // to inquire the shape of RHS. The rules are more obscure, so we 1179 // to inquire the shape of RHS. The rules are more obscure, so we
1175 // solve that elsewhere. 1180 // solve that elsewhere.
1176 if (dv.all_zero ()) 1181 if (initial_dims_all_zero)
1177 rdv = zero_dims_inquire (i, j, rhdv); 1182 rdv = zero_dims_inquire (i, j, rhdv);
1178 else 1183 else
1179 { 1184 {
1180 rdv(0) = i.extent (dv(0)); 1185 rdv(0) = i.extent (dv(0));
1181 rdv(1) = j.extent (dv(1)); 1186 rdv(1) = j.extent (dv(1));
1265 assign (ia(0), rhs, rfv); 1270 assign (ia(0), rhs, rfv);
1266 else if (ial == 2) 1271 else if (ial == 2)
1267 assign (ia(0), ia(1), rhs, rfv); 1272 assign (ia(0), ia(1), rhs, rfv);
1268 else if (ial > 0) 1273 else if (ial > 0)
1269 { 1274 {
1275 bool initial_dims_all_zero = dimensions.all_zero ();
1276
1270 // Get RHS extents, discarding singletons. 1277 // Get RHS extents, discarding singletons.
1271 dim_vector rhdv = rhs.dims (); 1278 dim_vector rhdv = rhs.dims ();
1272 1279
1273 // Get LHS extents, allowing Fortran indexing in the second dim. 1280 // Get LHS extents, allowing Fortran indexing in the second dim.
1274 dim_vector dv = dimensions.redim (ial); 1281 dim_vector dv = dimensions.redim (ial);
1277 dim_vector rdv; 1284 dim_vector rdv;
1278 1285
1279 // In the special when all dimensions are zero, colons are 1286 // In the special when all dimensions are zero, colons are
1280 // allowed to inquire the shape of RHS. The rules are more 1287 // allowed to inquire the shape of RHS. The rules are more
1281 // obscure, so we solve that elsewhere. 1288 // obscure, so we solve that elsewhere.
1282 if (dv.all_zero ()) 1289 if (initial_dims_all_zero)
1283 rdv = zero_dims_inquire (ia, rhdv); 1290 rdv = zero_dims_inquire (ia, rhdv);
1284 else 1291 else
1285 { 1292 {
1286 rdv = dim_vector::alloc (ial); 1293 rdv = dim_vector::alloc (ial);
1287 for (int i = 0; i < ial; i++) 1294 for (int i = 0; i < ial; i++)