# HG changeset patch # User Jaroslav Hajek # Date 1259477475 -3600 # Node ID cddd5c3d5f04014f0b927938b2ee6dc2f66cbdcc # Parent dd3fc8ba479692b7562d8b9509e4585ce2b8e244 fix & extend special-case optimizations for indexed assignment diff --git a/liboctave/Array.cc b/liboctave/Array.cc --- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -1180,12 +1180,12 @@ if (rhl == 1 || i.length (n) == rhl) { octave_idx_type nx = i.extent (n); + bool colon = i.is_colon_equiv (nx); // Try to resize first if necessary. if (nx != n) { // Optimize case A = []; A(1:n) = X with A empty. - if (rows () == 0 && columns () == 0 && ndims () == 2 - && i.is_colon_equiv (nx)) + if (dimensions.zero_by_zero () && colon) { if (rhl == 1) *this = Array (dim_vector (1, nx), rhs(0)); @@ -1198,7 +1198,7 @@ n = numel (); } - if (i.is_colon ()) + if (colon) { // A(:) = X makes a full fill or a shallow copy. if (rhl == 1) @@ -1249,12 +1249,13 @@ if (match) { + bool all_colons = (i.is_colon_equiv (rdv(0)) + && j.is_colon_equiv (rdv(1))); // Resize if requested. if (rdv != dv) { // Optimize case A = []; A(1:m, 1:n) = X - if (dv.all_zero () && i.is_colon_equiv (rdv(0)) - && j.is_colon_equiv (rdv(1))) + if (dv.zero_by_zero () && all_colons) { if (isfill) *this = Array (rdv, rhs(0)); @@ -1267,7 +1268,7 @@ dv = dimensions; } - if (i.is_colon () && j.is_colon ()) + if (all_colons) { // A(:,:) = X makes a full fill or a shallow copy if (isfill) @@ -1353,7 +1354,7 @@ int j = 0, rhdvl = rhdv.length (); for (int i = 0; i < ial; i++) { - all_colons = all_colons && ia(i).is_colon (); + all_colons = all_colons && ia(i).is_colon_equiv (rdv(i)); octave_idx_type l = ia(i).length (rdv(i)); if (l == 1) continue; match = match && j < rhdvl && l == rhdv(j++); @@ -1367,6 +1368,17 @@ // Resize first if necessary. if (rdv != dv) { + // Optimize case A = []; A(1:m, 1:n) = X + if (dv.zero_by_zero () && all_colons) + { + rdv.chop_trailing_singletons (); + if (isfill) + *this = Array (rdv, rhs(0)); + else + *this = Array (rhs, rdv); + return; + } + resize_fill (rdv, rfv); dv = dimensions; chop_trailing_singletons (); diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2009-11-28 Jaroslav Hajek + + * dim-vector.h (dim_vector::zero_by_zero): New method. + * idx-vector.h (idx_vector::idx_mask_rep::is_colon_equiv): Fix. + * Array.cc (Array::assign): Minor tweaks. Optimize + A = []; A(1:m,1:n,1:k) = X for all cases. Use a shallow copy + for all colon-equivalent indices. + 2009-11-27 Jaroslav Hajek * idx-vector.h (idx_vector::index_class): New member: class_mask. diff --git a/liboctave/dim-vector.h b/liboctave/dim-vector.h --- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -278,6 +278,11 @@ return retval; } + bool zero_by_zero (void) const + { + return length () == 2 && elem (0) == 0 && elem (1) == 0; + } + bool any_zero (void) const { bool retval = false; diff --git a/liboctave/idx-vector.h b/liboctave/idx-vector.h --- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -367,7 +367,7 @@ { return orig_dims; } bool is_colon_equiv (octave_idx_type n) const - { return count == n && ext == n; } + { return len == n && ext == n; } const bool *get_data (void) const { return data; }