Mercurial > octave
annotate libinterp/corefcn/find.cc @ 21724:aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
* configure.ac, Doxyfile.in, make_int.cc, Backend.cc, BaseControl.cc,
ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc,
ContextMenu.cc, EditControl.cc, Figure.cc, FigureWindow.cc,
GLCanvas.cc, KeyMap.cc, ListBoxControl.cc, Logger.cc, Menu.cc,
MouseModeActionGroup.cc, Object.cc, ObjectFactory.cc,
ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc,
PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc,
SliderControl.cc, TextControl.cc, TextEdit.cc,
ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, __init_qt__.cc,
annotation-dialog.cc, gl-select.cc, module.mk, color-picker.cc,
dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc,
find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc,
liboctgui-build-info.in.cc, file-editor-tab.cc, file-editor.cc,
find-dialog.cc, marker.cc, marker.h, octave-qscintilla.cc,
octave-txt-lexer.cc, main-window.cc, octave-cmd.cc,
octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc,
octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc,
settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc,
thread-manager.cc, welcome-wizard.cc, workspace-model.cc,
workspace-view.cc, build-env.in.cc, Cell.cc, __contourc__.cc,
__dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc,
__lin_interpn__.cc, __luinc__.cc, __magick_read__.cc,
__pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc,
bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, colloc.cc,
comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
debug.cc, defaults.cc, defaults.in.h, defun.cc, det.cc, dirfns.cc,
display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc,
error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc,
file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, gammainc.cc,
gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc,
gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc,
help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-ir.h,
jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc,
load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc,
ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc,
ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc,
lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mex.h,
mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc,
oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-iostrm.cc,
oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc,
oct-stdstrm.h, oct-stream.cc, oct-strstrm.cc, oct-tex-lexer.in.ll,
oct-tex-parser.in.yy, octave-link.cc, ordschur.cc, pager.cc,
pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc,
pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc,
regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, siglist.c,
siglist.h, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc,
sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc,
time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc,
urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc,
xpow.cc, zfstream.cc, zfstream.h, __delaunayn__.cc, __eigs__.cc,
__fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc,
convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc,
liboctinterp-build-info.in.cc, mkbuiltins, mkops, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc,
ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc,
ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc,
ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc,
ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc,
ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc,
ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc,
ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ovl.cc, octave.cc, octave.h,
op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc,
op-bm-sbm.cc, op-cdm-cdm.cc, op-cdm-cm.cc, op-cdm-dm.cc,
op-cdm-m.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cdm.cc,
op-cm-cm.cc, op-cm-cs.cc, op-cm-dm.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc,
op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-cdm.cc, op-dm-cm.cc,
op-dm-dm.cc, op-dm-m.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-double-conv.cc,
op-fcdm-fcdm.cc, op-fcdm-fcm.cc, op-fcdm-fdm.cc, op-fcdm-fm.cc,
op-fcm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fdm.cc,
op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc,
op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fcdm.cc, op-fdm-fcm.cc,
op-fdm-fdm.cc, op-fdm-fm.cc, op-float-conv.cc, op-fm-fcdm.cc,
op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fdm.cc, op-fm-fm.cc, op-fm-fs.cc,
op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc,
op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc,
op-int-conv.cc, op-m-cdm.cc, op-m-cm.cc, op-m-cs.cc, op-m-dm.cc,
op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc,
op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc,
op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc,
op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc,
op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc,
op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc,
lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc,
pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc,
pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc,
pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc,
pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc,
pt-loop.h, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc,
pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-tc.cc,
version.cc, Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc,
Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc,
Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc,
CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc,
CRowVector.cc, CSparse.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc,
MArray-fC.cc, MArray-i.cc, MArray-s.cc, MSparse-C.cc, MSparse-d.cc,
MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc,
Sparse-d.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc,
chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc,
dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dim-vector.cc,
dim-vector.h, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc,
fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc,
int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc,
uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc,
uint8NDArray.cc, Faddeeva.cc, blaswrap.c, cquit.c, f77-extern.cc,
f77-fcn.c, f77-fcn.h, lo-error.c, lo-error.h, quit.cc, quit.h,
liboctave-build-info.in.cc, CollocWt.cc, DASPK.cc, DASRT.cc,
DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc,
chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc,
lo-mappers.cc, lo-specfun.cc, lu.cc, oct-convn.cc, oct-fftw.cc,
oct-norm.cc, oct-rand.cc, oct-spparms.cc, qr.cc, qrp.cc,
randmtzig.cc, randpoisson.cc, schur.cc, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc, mk-ops.awk,
mx-defs.h, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, oct-time.cc, oct-uname.cc, pathlen.h, syswait.h,
cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc,
kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c,
lo-cutils.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-utils.cc,
oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h,
oct-locbuf.cc, oct-mutex.cc, oct-rl-edit.c, oct-rl-edit.h,
oct-rl-hist.c, oct-rl-hist.h, oct-shlib.cc, oct-sort.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc,
statdefs.h, str-vec.cc, unwind-prot.cc, url-transfer.cc,
acinclude.m4, display-available.c, display-available.h, main-cli.cc,
main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-build-info.in.cc,
octave-config.in.cc, shared-fcns.h:
Use "#if ..." consistently instead of "#ifdef" and "#ifndef".
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 17 May 2016 12:09:30 -0400 |
parents | 40de9f8f23a6 |
children | b571fc85953f |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18849
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2928 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2928 | 25 #endif |
26 | |
4153 | 27 #include "quit.h" |
28 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
29 #include "defun.h" |
2928 | 30 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
31 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
32 #include "ovl.h" |
2928 | 33 |
6002 | 34 // Find at most N_TO_FIND nonzero elements in NDA. Search forward if |
35 // DIRECTION is 1, backward if it is -1. NARGOUT is the number of | |
36 // output arguments. If N_TO_FIND is -1, find all nonzero elements. | |
4678 | 37 |
38 template <typename T> | |
39 octave_value_list | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
40 find_nonzero_elem_idx (const Array<T>& nda, int nargout, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
41 octave_idx_type n_to_find, int direction) |
4678 | 42 { |
6002 | 43 octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ()); |
4678 | 44 |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
45 Array<octave_idx_type> idx; |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
46 if (n_to_find >= 0) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
47 idx = nda.find (n_to_find, direction == -1); |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
48 else |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
49 idx = nda.find (); |
5130 | 50 |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
51 // The maximum element is always at the end. |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
52 octave_idx_type iext = idx.is_empty () ? 0 : idx.xelem (idx.numel () - 1) + 1; |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
53 |
2928 | 54 switch (nargout) |
55 { | |
6254 | 56 default: |
2928 | 57 case 3: |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9544
diff
changeset
|
58 retval(2) = Array<T> (nda.index (idx_vector (idx))); |
2928 | 59 // Fall through! |
60 | |
61 case 2: | |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
62 { |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
63 Array<octave_idx_type> jdx (idx.dims ()); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20181
diff
changeset
|
64 octave_idx_type n = idx.numel (); |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
65 octave_idx_type nr = nda.rows (); |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
66 for (octave_idx_type i = 0; i < n; i++) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
67 { |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
68 jdx.xelem (i) = idx.xelem (i) / nr; |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
69 idx.xelem (i) %= nr; |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
70 } |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
71 iext = -1; |
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
72 retval(1) = idx_vector (jdx, -1); |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
73 } |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
74 // Fall through! |
2928 | 75 |
6254 | 76 case 1: |
77 case 0: | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
78 retval(0) = idx_vector (idx, iext); |
2928 | 79 break; |
80 } | |
81 | |
82 return retval; | |
83 } | |
84 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
85 template <typename T> |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
86 octave_value_list |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
87 find_nonzero_elem_idx (const Sparse<T>& v, int nargout, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
88 octave_idx_type n_to_find, int direction) |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
89 { |
20758
f819397c0bc1
Stop segfault when find() called with 6 outputs (bug #42424).
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
90 nargout = std::min (nargout, 5); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
91 octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ()); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
92 |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
93 octave_idx_type nr = v.rows (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
94 octave_idx_type nc = v.cols (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
95 octave_idx_type nz = v.nnz (); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
96 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
97 // Search in the default range. |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
98 octave_idx_type start_nc = -1; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
99 octave_idx_type end_nc = -1; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
100 octave_idx_type count; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
101 |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
102 // Search for the range to search |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
103 if (n_to_find < 0) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
104 { |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
105 start_nc = 0; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
106 end_nc = nc; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
107 n_to_find = nz; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
108 count = nz; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
109 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
110 else if (direction > 0) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
111 { |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
112 for (octave_idx_type j = 0; j < nc; j++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
113 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
114 OCTAVE_QUIT; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
115 if (v.cidx (j) == 0 && v.cidx (j+1) != 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
116 start_nc = j; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
117 if (v.cidx (j+1) >= n_to_find) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
118 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
119 end_nc = j + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
120 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
121 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
122 } |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
124 else |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 { |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 for (octave_idx_type j = nc; j > 0; j--) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
127 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
128 OCTAVE_QUIT; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
129 if (v.cidx (j) == nz && v.cidx (j-1) != nz) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
130 end_nc = j; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
131 if (nz - v.cidx (j-1) >= n_to_find) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
132 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
133 start_nc = j - 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
134 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
135 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
136 } |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
139 count = (n_to_find > v.cidx (end_nc) - v.cidx (start_nc) ? |
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
140 v.cidx (end_nc) - v.cidx (start_nc) : n_to_find); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
141 |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
142 octave_idx_type result_nr; |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
143 octave_idx_type result_nc; |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
144 |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
145 // Default case is to return a column vector, however, if the original |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
146 // argument was a row vector, then force return of a row vector. |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
147 if (nr == 1) |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
148 { |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 result_nr = 1; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 result_nc = count; |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
151 } |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
152 else |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
153 { |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
154 result_nr = count; |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
155 result_nc = 1; |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
156 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
157 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
158 Matrix idx (result_nr, result_nc); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
159 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
160 Matrix i_idx (result_nr, result_nc); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
161 Matrix j_idx (result_nr, result_nc); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
162 |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9544
diff
changeset
|
163 Array<T> val (dim_vector (result_nr, result_nc)); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
164 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
165 if (count > 0) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
166 { |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
167 // Search for elements to return. Only search the region where there |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
168 // are elements to be found using the count that we want to find. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
169 for (octave_idx_type j = start_nc, cx = 0; j < end_nc; j++) |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18676
diff
changeset
|
170 for (octave_idx_type i = v.cidx (j); i < v.cidx (j+1); i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
171 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
172 OCTAVE_QUIT; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
173 if (direction < 0 && i < nz - count) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
174 continue; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
175 i_idx(cx) = static_cast<double> (v.ridx (i) + 1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
176 j_idx(cx) = static_cast<double> (j + 1); |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
177 idx(cx) = j * nr + v.ridx (i) + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
178 val(cx) = v.data(i); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
179 cx++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
180 if (cx == count) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
181 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
182 } |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
183 } |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
184 else |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
185 { |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
186 // No items found. Fixup return dimensions for Matlab compatibility. |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
187 // The behavior to match is documented in Array.cc (Array<T>::find). |
18793
332450e56698
Fix compilation warning about use of '&' versus '&&' in find.cc.
Rik <rik@octave.org>
parents:
18779
diff
changeset
|
188 if ((nr == 0 && nc == 0) || (nr == 1 && nc == 1)) |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
189 { |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
190 idx.resize (0, 0); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
191 |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
192 i_idx.resize (0, 0); |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
193 j_idx.resize (0, 0); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
194 |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
195 val.resize (dim_vector (0, 0)); |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
196 } |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
197 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
198 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
199 switch (nargout) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
200 { |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
201 case 0: |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
202 case 1: |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
203 retval(0) = idx; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
204 break; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
205 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
206 case 5: |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
207 retval(4) = nc; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
208 // Fall through |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
209 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
210 case 4: |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
211 retval(3) = nr; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
212 // Fall through |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
213 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
214 case 3: |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
215 retval(2) = val; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
216 // Fall through! |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
217 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
218 case 2: |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
219 retval(1) = j_idx; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
220 retval(0) = i_idx; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
221 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
222 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
223 return retval; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
224 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
225 |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
226 octave_value_list |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
227 find_nonzero_elem_idx (const PermMatrix& v, int nargout, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
228 octave_idx_type n_to_find, int direction) |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
229 { |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
230 // There are far fewer special cases to handle for a PermMatrix. |
20758
f819397c0bc1
Stop segfault when find() called with 6 outputs (bug #42424).
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
231 nargout = std::min (nargout, 5); |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
232 octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ()); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
233 |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
234 octave_idx_type nr = v.rows (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
235 octave_idx_type nc = v.cols (); |
13219
cf5ebc0e47e4
fix warnings for unused but set variables and shadowed variables
John W. Eaton <jwe@octave.org>
parents:
12639
diff
changeset
|
236 octave_idx_type start_nc, count; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
237 |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
238 // Determine the range to search. |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
239 if (n_to_find < 0 || n_to_find >= nc) |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
240 { |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
241 start_nc = 0; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
242 count = nc; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
243 } |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
244 else if (direction > 0) |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
245 { |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
246 start_nc = 0; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
247 count = n_to_find; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
248 } |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
249 else |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
250 { |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
251 start_nc = nc - n_to_find; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
252 count = n_to_find; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
253 } |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
254 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
255 Matrix idx (count, 1); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
256 Matrix i_idx (count, 1); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
257 Matrix j_idx (count, 1); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
258 // Every value is 1. |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9544
diff
changeset
|
259 Array<double> val (dim_vector (count, 1), 1.0); |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
260 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
261 if (count > 0) |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
262 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
263 const Array<octave_idx_type>& p = v.col_perm_vec (); |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
264 for (octave_idx_type k = 0; k < count; k++) |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
265 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
266 OCTAVE_QUIT; |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
267 const octave_idx_type j = start_nc + k; |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
268 const octave_idx_type i = p(j); |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
269 i_idx(k) = static_cast<double> (1+i); |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
270 j_idx(k) = static_cast<double> (1+j); |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
271 idx(k) = j * nc + i + 1; |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
272 } |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
273 } |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
274 else |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
275 { |
18793
332450e56698
Fix compilation warning about use of '&' versus '&&' in find.cc.
Rik <rik@octave.org>
parents:
18779
diff
changeset
|
276 // FIXME: Is this case even possible? A scalar permutation matrix seems |
332450e56698
Fix compilation warning about use of '&' versus '&&' in find.cc.
Rik <rik@octave.org>
parents:
18779
diff
changeset
|
277 // to devolve to a scalar full matrix, at least from the Octave command |
332450e56698
Fix compilation warning about use of '&' versus '&&' in find.cc.
Rik <rik@octave.org>
parents:
18779
diff
changeset
|
278 // line. Perhaps this function could be called internally from C++ with |
332450e56698
Fix compilation warning about use of '&' versus '&&' in find.cc.
Rik <rik@octave.org>
parents:
18779
diff
changeset
|
279 // such a matrix. |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
280 // No items found. Fixup return dimensions for Matlab compatibility. |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
281 // The behavior to match is documented in Array.cc (Array<T>::find). |
18793
332450e56698
Fix compilation warning about use of '&' versus '&&' in find.cc.
Rik <rik@octave.org>
parents:
18779
diff
changeset
|
282 if ((nr == 0 && nc == 0) || (nr == 1 && nc == 1)) |
18779
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
283 { |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
284 idx.resize (0, 0); |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
285 |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
286 i_idx.resize (0, 0); |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
287 j_idx.resize (0, 0); |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
288 |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
289 val.resize (dim_vector (0, 0)); |
a5286fb173cd
Match Matlab return dimensions for find on empty sparse matrices (bug #42408).
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
290 } |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
291 } |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
292 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
293 switch (nargout) |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
294 { |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
295 case 0: |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
296 case 1: |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
297 retval(0) = idx; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
298 break; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
299 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
300 case 5: |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
301 retval(4) = nc; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
302 // Fall through |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
303 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
304 case 4: |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
305 retval(3) = nc; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
306 // Fall through |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
307 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
308 case 3: |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
309 retval(2) = val; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
310 // Fall through! |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
311 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
312 case 2: |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
313 retval(1) = j_idx; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
314 retval(0) = i_idx; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
315 } |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
316 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
317 return retval; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
318 } |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
319 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
320 DEFUN (find, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
321 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
322 @deftypefn {} {@var{idx} =} find (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
323 @deftypefnx {} {@var{idx} =} find (@var{x}, @var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
324 @deftypefnx {} {@var{idx} =} find (@var{x}, @var{n}, @var{direction})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
325 @deftypefnx {} {[i, j] =} find (@dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
326 @deftypefnx {} {[i, j, v] =} find (@dots{})\n\ |
6524 | 327 Return a vector of indices of nonzero elements of a matrix, as a row if\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
328 @var{x} is a row vector or as a column otherwise.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
329 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
330 To obtain a single index for each matrix element, Octave pretends that the\n\ |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
331 columns of a matrix form one long vector (like Fortran arrays are stored).\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
332 For example:\n\ |
3369 | 333 \n\ |
334 @example\n\ | |
335 @group\n\ | |
336 find (eye (2))\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
337 @result{} [ 1; 4 ]\n\ |
3369 | 338 @end group\n\ |
339 @end example\n\ | |
340 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
341 If two inputs are given, @var{n} indicates the maximum number of elements to\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
342 find from the beginning of the matrix or vector.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
343 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
344 If three inputs are given, @var{direction} should be one of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
345 @qcode{\"first\"} or @qcode{\"last\"}, requesting only the first or last\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
346 @var{n} indices, respectively. However, the indices are always returned in\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
347 ascending order.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
348 \n\ |
3369 | 349 If two outputs are requested, @code{find} returns the row and column\n\ |
10840 | 350 indices of nonzero elements of a matrix. For example:\n\ |
3369 | 351 \n\ |
352 @example\n\ | |
353 @group\n\ | |
354 [i, j] = find (2 * eye (2))\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
355 @result{} i = [ 1; 2 ]\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
356 @result{} j = [ 1; 2 ]\n\ |
3369 | 357 @end group\n\ |
358 @end example\n\ | |
359 \n\ | |
360 If three outputs are requested, @code{find} also returns a vector\n\ | |
10840 | 361 containing the nonzero values. For example:\n\ |
3369 | 362 \n\ |
363 @example\n\ | |
364 @group\n\ | |
365 [i, j, v] = find (3 * eye (2))\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
366 @result{} i = [ 1; 2 ]\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
367 @result{} j = [ 1; 2 ]\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
368 @result{} v = [ 3; 3 ]\n\ |
3369 | 369 @end group\n\ |
370 @end example\n\ | |
6002 | 371 \n\ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
372 Note that this function is particularly useful for sparse matrices, as\n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18794
diff
changeset
|
373 it extracts the nonzero elements as vectors, which can then be used to\n\ |
10840 | 374 create the original matrix. For example:\n\ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
375 \n\ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
376 @example\n\ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
377 @group\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
378 sz = size (a);\n\ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
379 [i, j, v] = find (a);\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
380 b = sparse (i, j, v, sz(1), sz(2));\n\ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
381 @end group\n\ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
382 @end example\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
383 @seealso{nonzeros}\n\ |
3369 | 384 @end deftypefn") |
2928 | 385 { |
386 int nargin = args.length (); | |
387 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
388 if (nargin < 1 || nargin > 3) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20773
diff
changeset
|
389 print_usage (); |
2928 | 390 |
6002 | 391 // Setup the default options. |
392 octave_idx_type n_to_find = -1; | |
393 if (nargin > 1) | |
394 { | |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20557
diff
changeset
|
395 double val = args(1).xscalar_value ("find: N must be an integer"); |
9310 | 396 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20557
diff
changeset
|
397 if (val < 0 || (! xisinf (val) && val != xround (val))) |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20557
diff
changeset
|
398 error ("find: N must be a non-negative integer"); |
10338
21dd58bd683c
fix unsafe conversion in find
Jaroslav Hajek <highegg@gmail.com>
parents:
10285
diff
changeset
|
399 else if (! xisinf (val)) |
9310 | 400 n_to_find = val; |
6002 | 401 } |
402 | |
403 // Direction to do the searching (1 == forward, -1 == reverse). | |
404 int direction = 1; | |
405 if (nargin > 2) | |
406 { | |
407 direction = 0; | |
408 | |
409 std::string s_arg = args(2).string_value (); | |
410 | |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
411 if (s_arg == "first") |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
412 direction = 1; |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
413 else if (s_arg == "last") |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
414 direction = -1; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
415 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
416 error ("find: DIRECTION must be \"first\" or \"last\""); |
6002 | 417 } |
418 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
419 octave_value_list retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
420 |
2928 | 421 octave_value arg = args(0); |
422 | |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
423 if (arg.is_bool_type ()) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
424 { |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
425 if (arg.is_sparse_type ()) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
426 { |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
427 SparseBoolMatrix v = arg.sparse_bool_matrix_value (); |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
428 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
429 retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
430 } |
9544
df0abc63c230
cache/use cached index vector on full find in logical masks
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
431 else if (nargout <= 1 && n_to_find == -1 && direction == 1) |
df0abc63c230
cache/use cached index vector on full find in logical masks
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
432 { |
df0abc63c230
cache/use cached index vector on full find in logical masks
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
433 // This case is equivalent to extracting indices from a logical |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
434 // matrix. Try to reuse the possibly cached index vector. |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
435 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20232
diff
changeset
|
436 // No need to catch index_exception, since arg is bool. |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
437 // Out-of-range errors have already set pos, and will be caught later. |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
438 retval(0) = arg.index_vector ().unmask (); |
9544
df0abc63c230
cache/use cached index vector on full find in logical masks
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
439 } |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
440 else |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
441 { |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
442 boolNDArray v = arg.bool_array_value (); |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
443 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
444 retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
445 } |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
446 } |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
447 else if (arg.is_integer_type ()) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
448 { |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
449 #define DO_INT_BRANCH(INTT) \ |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
450 else if (arg.is_ ## INTT ## _type ()) \ |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
451 { \ |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
452 INTT ## NDArray v = arg.INTT ## _array_value (); \ |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
453 \ |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
454 retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); \ |
9028
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
455 } |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
456 |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
457 if (false) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
458 ; |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
459 DO_INT_BRANCH (int8) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
460 DO_INT_BRANCH (int16) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
461 DO_INT_BRANCH (int32) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
462 DO_INT_BRANCH (int64) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
463 DO_INT_BRANCH (uint8) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
464 DO_INT_BRANCH (uint16) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
465 DO_INT_BRANCH (uint32) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
466 DO_INT_BRANCH (uint64) |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
467 else |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
468 panic_impossible (); |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
469 } |
e67dc11ed6e8
use Array<T>::find in find
Jaroslav Hajek <highegg@gmail.com>
parents:
9019
diff
changeset
|
470 else if (arg.is_sparse_type ()) |
2928 | 471 { |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
472 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
473 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
474 SparseMatrix v = arg.sparse_matrix_value (); |
2928 | 475 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
476 retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
477 } |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
478 else if (arg.is_complex_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
479 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
480 SparseComplexMatrix v = arg.sparse_complex_matrix_value (); |
5107 | 481 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
482 retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
483 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
484 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
485 err_wrong_type_arg ("find", arg); |
5107 | 486 } |
10550 | 487 else if (arg.is_perm_matrix ()) |
488 { | |
489 PermMatrix P = arg.perm_matrix_value (); | |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
490 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
491 retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction); |
10550 | 492 } |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
493 else if (arg.is_string ()) |
2928 | 494 { |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
495 charNDArray chnda = arg.char_array_value (); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
496 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
497 retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction); |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
498 } |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
499 else if (arg.is_single_type ()) |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
500 { |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
501 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
502 { |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
503 FloatNDArray nda = arg.float_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
504 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
505 retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction); |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
506 } |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
507 else if (arg.is_complex_type ()) |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
508 { |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
509 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
510 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
511 retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9894
diff
changeset
|
512 } |
2928 | 513 } |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
514 else if (arg.is_real_type ()) |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
515 { |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
516 NDArray nda = arg.array_value (); |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
517 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
518 retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction); |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
519 } |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
520 else if (arg.is_complex_type ()) |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
521 { |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
522 ComplexNDArray cnda = arg.complex_array_value (); |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
523 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
524 retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction); |
10826
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
525 } |
9e6aed3c6704
fix find for character arrays
John W. Eaton <jwe@octave.org>
parents:
10550
diff
changeset
|
526 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
527 err_wrong_type_arg ("find", arg); |
2928 | 528 |
529 return retval; | |
530 } | |
531 | |
532 /* | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
533 %!assert (find (char ([0, 97])), 2) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
534 %!assert (find ([1, 0, 1, 0, 1]), [1, 3, 5]) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
535 %!assert (find ([1; 0; 3; 0; 1]), [1; 3; 5]) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
536 %!assert (find ([0, 0, 2; 0, 3, 0; -1, 0, 0]), [3; 5; 7]) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
537 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
538 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
539 %! [i, j, v] = find ([0, 0, 2; 0, 3, 0; -1, 0, 0]); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
540 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
541 %! assert (i, [3; 2; 1]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
542 %! assert (j, [1; 2; 3]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
543 %! assert (v, [-1; 3; 2]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
544 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
545 %!assert (find (single ([1, 0, 1, 0, 1])), [1, 3, 5]) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
546 %!assert (find (single ([1; 0; 3; 0; 1])), [1; 3; 5]) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
547 %!assert (find (single ([0, 0, 2; 0, 3, 0; -1, 0, 0])), [3; 5; 7]) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
548 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
549 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
550 %! [i, j, v] = find (single ([0, 0, 2; 0, 3, 0; -1, 0, 0])); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
551 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
552 %! assert (i, [3; 2; 1]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
553 %! assert (j, [1; 2; 3]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
554 %! assert (v, single ([-1; 3; 2])); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
555 |
8955
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
556 %!test |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
557 %! pcol = [5 1 4 3 2]; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
558 %! P = eye (5) (:, pcol); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
559 %! [i, j, v] = find (P); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
560 %! [ifull, jfull, vfull] = find (full (P)); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
561 %! assert (i, ifull); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
562 %! assert (j, jfull); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
563 %! assert (all (v == 1)); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
564 |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
565 %!test |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
566 %! prow = [5 1 4 3 2]; |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
567 %! P = eye (5) (prow, :); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
568 %! [i, j, v] = find (P); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
569 %! [ifull, jfull, vfull] = find (full (P)); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
570 %! assert (i, ifull); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
571 %! assert (j, jfull); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
572 %! assert (all (v == 1)); |
6d3fcbf89267
Add an override to Octave's find() for permutation matrices.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
573 |
9310 | 574 %!assert (find ([2 0 1 0 5 0], 1), 1) |
575 %!assert (find ([2 0 1 0 5 0], 2, "last"), [3, 5]) | |
576 | |
577 %!assert (find ([2 0 1 0 5 0], Inf), [1, 3, 5]) | |
578 %!assert (find ([2 0 1 0 5 0], Inf, "last"), [1, 3, 5]) | |
579 | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
580 %!error find () |
2928 | 581 */ |