Mercurial > hg > octave-terminal
changeset 8563:3a3421a9f0bb
optimize resizable indexing with scalars
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 22 Jan 2009 13:26:04 +0100 |
parents | a6edd5c23cb5 |
children | b0f803b5ce41 |
files | liboctave/Array.cc liboctave/ChangeLog |
diffstat | 2 files changed, 26 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -1119,7 +1119,12 @@ { octave_idx_type n = numel (), nx = i.extent (n); if (n != nx) - tmp.resize_fill (nx, rfv); + { + if (i.is_scalar ()) + return Array<T> (1, rfv); + else + tmp.resize_fill (nx, rfv); + } if (tmp.numel () != nx) return Array<T> (); @@ -1140,7 +1145,12 @@ octave_idx_type r = dv(0), c = dv(1); octave_idx_type rx = i.extent (r), cx = j.extent (c); if (r != rx || c != cx) - tmp.resize_fill (rx, cx, rfv); + { + if (i.is_scalar () && j.is_scalar ()) + return Array<T> (1, rfv); + else + tmp.resize_fill (rx, cx, rfv); + } if (tmp.rows () != rx || tmp.columns () != cx) return Array<T> (); @@ -1162,7 +1172,15 @@ dim_vector dvx; dvx.resize (ial); for (int i = 0; i < ial; i++) dvx(i) = ia(i).extent (dv (i)); if (! (dvx == dv)) - tmp.resize_fill (dvx, rfv); + { + bool all_scalars = true; + for (int i = 0; i < ial; i++) + all_scalars = all_scalars && ia(i).is_scalar (); + if (all_scalars) + return Array<T> (1, rfv); + else + tmp.resize_fill (dvx, rfv); + } if (tmp.dimensions != dvx) return Array<T> ();
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2009-01-22 Jaroslav Hajek <highegg@gmail.com> + + * Array.cc (Array<T>::index (..., bool resize_ok)): + Optimize the all-scalar-indices cases. + 2009-01-22 Jaroslav Hajek <highegg@gmail.com> * dbleQR.h: Optionally declare warn_qrupdate_once.