From octave-maintainers-request at bevo dot che dot wisc dot edu Fri Sep 8 07:50:34 2000 Subject: Re: [PATCH] Add min/max tests. (4/4) From: Paul Kienzle To: "John W. Eaton" Cc: ejr at EECS dot Berkeley dot EDU, octave-maintainers@bevo.che.wisc.edu Date: Fri, 8 Sep 2000 13:51:07 +0100 On Thu, Sep 07, 2000 at 08:53:42PM -0500, John W. Eaton wrote: > On 8-Sep-2000, Paul Kienzle wrote: > > | To make it completely proper is a bit more work. You must protect the > | do_fortran_indexing state. > > For the (relatively common) case where a single matrix index is the > result of a call to find(), it seems like it would make more sense to > return a special `indexing object' that could be used on a matrix of > the same shape as the one passed to find() without having to worry > about do_fortran_indexing. Would that make sense, or do you think it > would also be too restrictive? > > jwe > > Actually, in this case I should have coded it without the find() as: z = x; idx = abs(x) > abs(y); z(idx) = y(idx); which gives the same result 2-3 times faster (at least with 2.1.31). Since this will work in almost all cases, it doesn't make sense to create a data type just for the return from find. Compatibility with matlab is more compelling, but you get that just by setting do_fortran_indexing = 1. Note that you still need do_fortran_indexing == 1 to handle the nargin==1 case: [z, zi] = min(abs(x)); [nr, nc] = size(x); if (nr == 1 || nc == 1) z(zi) = x(zi); else dfi = do_fortran_indexing; unwind_protect do_fortran_indexing = 1; z = x(zi + [0:nc-1]*nr); unwind_protect_cleanup do_fortran_indexing = dfi; end_unwind_protect endif A counter question: why would you ever want do_fortran_index == 0? - Paul