Mercurial > hg > octave-lyh
changeset 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 | 6980b0f35df9 |
children | bb5ecda3b975 f947d2922feb |
files | liboctave/Array.cc liboctave/dim-vector.cc liboctave/dim-vector.h src/ov-struct.cc |
diffstat | 4 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -1164,16 +1164,21 @@ Array<T>::assign (const idx_vector& i, const idx_vector& j, const Array<T>& rhs, const T& rfv) { + bool initial_dims_all_zero = dimensions.all_zero (); + // Get RHS extents, discarding singletons. dim_vector rhdv = rhs.dims (); + // Get LHS extents, allowing Fortran indexing in the second dim. dim_vector dv = dimensions.redim (2); + // Check for out-of-bounds and form resizing dimensions. dim_vector rdv; + // In the special when all dimensions are zero, colons are allowed // to inquire the shape of RHS. The rules are more obscure, so we // solve that elsewhere. - if (dv.all_zero ()) + if (initial_dims_all_zero) rdv = zero_dims_inquire (i, j, rhdv); else { @@ -1267,6 +1272,8 @@ assign (ia(0), ia(1), rhs, rfv); else if (ial > 0) { + bool initial_dims_all_zero = dimensions.all_zero (); + // Get RHS extents, discarding singletons. dim_vector rhdv = rhs.dims (); @@ -1279,7 +1286,7 @@ // In the special when all dimensions are zero, colons are // allowed to inquire the shape of RHS. The rules are more // obscure, so we solve that elsewhere. - if (dv.all_zero ()) + if (initial_dims_all_zero) rdv = zero_dims_inquire (ia, rhdv); else {
--- a/liboctave/dim-vector.cc +++ b/liboctave/dim-vector.cc @@ -272,16 +272,11 @@ { dim_vector retval = alloc (n); - int pad = 0; for (int i = 0; i < n_dims; i++) - { - retval.rep[i] = rep[i]; - if (rep[i] != 0) - pad = 1; - } + retval.rep[i] = rep[i]; for (int i = n_dims; i < n; i++) - retval.rep[i] = pad; + retval.rep[i] = 1; return retval; }
--- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -381,8 +381,7 @@ // Force certain dimensionality, preserving numel (). Missing // dimensions are set to 1, redundant are folded into the trailing // one. If n = 1, the result is 2d and the second dim is 1 - // (dim_vectors are always at least 2D). If the original dimensions - // were all zero, the padding value is zero. + // (dim_vectors are always at least 2D). dim_vector redim (int n) const;