Mercurial > octave
changeset 29975:06bf5aca68bb
Improve performance of sort along dimensions > 1 (bug #60928).
* Array.cc (sort (dim, mode), sort (&sidx, dim, mode)):
Replace calculation of offset using while loop with division and multiplication
of integers.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 16 Aug 2021 11:45:40 -0700 |
parents | 65c609504036 |
children | c44c72cc68a0 |
files | liboctave/array/Array.cc |
diffstat | 1 files changed, 4 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/array/Array.cc Mon Aug 16 19:16:58 2021 +0200 +++ b/liboctave/array/Array.cc Mon Aug 16 11:45:40 2021 -0700 @@ -1830,15 +1830,8 @@ for (octave_idx_type j = 0; j < iter; j++) { octave_idx_type offset = j; - octave_idx_type offset2 = 0; - - while (offset >= stride) - { - offset -= stride; - offset2++; - } - - offset += offset2 * stride * ns; + octave_idx_type n_strides = j / stride; + offset += n_strides * stride * (ns - 1); // gather and partition out NaNs. // FIXME: impact on integer types noticeable? @@ -1964,15 +1957,8 @@ for (octave_idx_type j = 0; j < iter; j++) { octave_idx_type offset = j; - octave_idx_type offset2 = 0; - - while (offset >= stride) - { - offset -= stride; - offset2++; - } - - offset += offset2 * stride * ns; + octave_idx_type n_strides = j / stride; + offset += n_strides * stride * (ns - 1); // gather and partition out NaNs. // FIXME: impact on integer types noticeable?