Mercurial > hg > octave-jordi
diff src/DLD-FUNCTIONS/find.cc @ 4826:a7b1e6122d0c
[project @ 2004-03-09 19:57:29 by jwe]
author | jwe |
---|---|
date | Tue, 09 Mar 2004 19:57:29 +0000 |
parents | e1c2d8ca8bc0 |
children | c891dd97b837 |
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/find.cc +++ b/src/DLD-FUNCTIONS/find.cc @@ -51,46 +51,58 @@ count++; } - if (count == 0) - return retval; + // If the original argument was a row vector, force a row vector of + // the overall indices to be returned. - ColumnVector idx (count); - - ColumnVector i_idx (count); - ColumnVector j_idx (count); + int result_nr = count; + int result_nc = 1; - T val (dim_vector (count, 1)); - - count = 0; + if (nda.ndims () == 2 && nda.rows () == 1) + { + result_nr = 1; + result_nc = count; + } - int nr = nda.rows (); + Matrix idx (result_nr, result_nc); - int i = 0; - int j = 0; + Matrix i_idx (result_nr, result_nc); + Matrix j_idx (result_nr, result_nc); - for (int k = 0; k < nel; k++) + T val (dim_vector (result_nr, result_nc)); + + if (count > 0) { - OCTAVE_QUIT; + count = 0; + + int nr = nda.rows (); - if (nda(k) != 0.0) + int i = 0; + int j = 0; + + for (int k = 0; k < nel; k++) { - idx(count) = k + 1; + OCTAVE_QUIT; - i_idx(count) = i + 1; - j_idx(count) = j + 1; - - val(count) = nda(k); + if (nda(k) != 0.0) + { + idx(count) = k + 1; - count++; - } + i_idx(count) = i + 1; + j_idx(count) = j + 1; - i++; + val(count) = nda(k); + + count++; + } - if (i == nr) - { - i = 0; + i++; - j++; + if (i == nr) + { + i = 0; + + j++; + } } } @@ -98,15 +110,7 @@ { case 0: case 1: - { - // If the original argument was a row vector, force a row vector of - // the overall indices to be returned. - - if (nda.ndims () == 2 && nda.rows () == 1) - retval(0) = idx.transpose (); - else - retval(0) = idx; - } + retval(0) = idx; break; case 3: