Mercurial > hg > octave-terminal
changeset 8949:e31d47f2c9bb
fixes to row-reducing cummin/cummax
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 10 Mar 2009 13:18:53 +0100 |
parents | 3e161cae0bc6 |
children | d865363208d6 |
files | liboctave/ChangeLog liboctave/mx-inlines.cc src/DLD-FUNCTIONS/max.cc |
diffstat | 3 files changed, 34 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2009-03-10 Jaroslav Hajek <highegg@gmail.com> + + * mx-inlines.cc (OP_CUMMINMAX_FCN2): r -> r0 where appropriate. + 2009-03-08 Jaroslav Hajek <highegg@gmail.com> * idx-vector.h (idx_vector::bloop): loop --> bloop.
--- a/liboctave/mx-inlines.cc +++ b/liboctave/mx-inlines.cc @@ -735,7 +735,7 @@ { \ if (xisnan (v[i])) \ { r[i] = r0[i]; nan = true; } \ - else if (xisnan (r[i]) || v[i] OP r[i]) \ + else if (xisnan (r0[i]) || v[i] OP r0[i]) \ r[i] = v[i]; \ } \ j++; v += m; r0 = r; r += m; \ @@ -743,7 +743,7 @@ while (j < n) \ { \ for (octave_idx_type i = 0; i < m; i++) \ - if (v[i] OP r[i]) \ + if (v[i] OP r0[i]) \ r[i] = v[i]; \ else \ r[i] = r0[i]; \ @@ -772,7 +772,7 @@ { \ if (xisnan (v[i])) \ { r[i] = r0[i]; ri[i] = r0i[i]; nan = true; } \ - else if (xisnan (r[i]) || v[i] OP r[i]) \ + else if (xisnan (r0[i]) || v[i] OP r0[i]) \ { r[i] = v[i]; ri[i] = j; }\ } \ j++; v += m; r0 = r; r += m; r0i = ri; ri += m; \ @@ -780,7 +780,7 @@ while (j < n) \ { \ for (octave_idx_type i = 0; i < m; i++) \ - if (v[i] OP r[i]) \ + if (v[i] OP r0[i]) \ { r[i] = v[i]; ri[i] = j; } \ else \ { r[i] = r0[i]; ri[i] = r0i[i]; } \
--- a/src/DLD-FUNCTIONS/max.cc +++ b/src/DLD-FUNCTIONS/max.cc @@ -862,6 +862,7 @@ break; \ } \ \ + int dim; \ dim_vector dv = arg1.dims (); \ if (error_state) \ { \ @@ -869,11 +870,23 @@ return retval; \ } \ \ - int dim = 0; \ - while ((dim < dv.length ()) && (dv (dim) <= 1)) \ - dim++; \ - if (dim == dv.length ()) \ - dim = 0; \ + if (nargin == 2) \ + { \ + dim = arg2.nint_value () - 1; \ + if (dim < 0 || dim >= dv.length ()) \ + { \ + error ("%s: invalid dimension", #FCN); \ + return retval; \ + } \ + } \ + else \ + { \ + dim = 0; \ + while ((dim < dv.length ()) && (dv (dim) <= 1)) \ + dim++; \ + if (dim == dv.length ()) \ + dim = 0; \ + } \ \ if (arg1.is_integer_type ()) \ { \ @@ -914,12 +927,12 @@ @noindent\n\ is equivalent to the following code:\n\ @example\n\ - colons(1:ndims (x)) = @{':'@};\n\ + w = iw = zeros (size (x));\n\ + idxw = idxx = repmat (@{':'@}, 1, ndims (x));\n\ for i = 1:size (x, dim)\n\ - idxw = idxx = colons;\n\ - idxw@{i@} = i; idxx@{i@} = 1:i;\n\ + idxw@{dim@} = i; idxx@{dim@} = 1:i;\n\ [w(idxw@{:@}), iw(idxw@{:@})] =\ - min(x(idxx@{:@}), dim);\n\ + min(x(idxx@{:@}), [], dim);\n\ endfor\n\ @end example\n\ \n\ @@ -945,12 +958,12 @@ @noindent\n\ is equivalent to the following code:\n\ @example\n\ - colons(1:ndims (x)) = @{':'@};\n\ + w = iw = zeros (size (x));\n\ + idxw = idxx = repmat (@{':'@}, 1, ndims (x));\n\ for i = 1:size (x, dim)\n\ - idxw = idxx = colons;\n\ - idxw@{i@} = i; idxx@{i@} = 1:i;\n\ + idxw@{dim@} = i; idxx@{dim@} = 1:i;\n\ [w(idxw@{:@}), iw(idxw@{:@})] =\ - max(x(idxx@{:@}), dim);\n\ + max(x(idxx@{:@}), [], dim);\n\ endfor\n\ @end example\n\ \n\