annotate src/DLD-FUNCTIONS/find.cc @ 7505:f5005d9510f4

Remove dispatched sparse functions and treat in the generic versions of the functions
author David Bateman <dbateman@free.fr>
date Wed, 20 Feb 2008 15:52:11 -0500
parents a1dbe9d80eee
children 82be108cc558
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
1 /*
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 2007 John W. Eaton
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
5
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
7
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6524
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6524
diff changeset
11 option) any later version.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
12
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
16 for more details.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
17
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6524
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6524
diff changeset
20 <http://www.gnu.org/licenses/>.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
21
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
22 */
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
23
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
26 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 3418
diff changeset
28 #include "quit.h"
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 3418
diff changeset
29
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
30 #include "defun-dld.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
31 #include "error.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
32 #include "gripes.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
33 #include "oct-obj.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
34
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
35 // Find at most N_TO_FIND nonzero elements in NDA. Search forward if
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
36 // DIRECTION is 1, backward if it is -1. NARGOUT is the number of
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
37 // output arguments. If N_TO_FIND is -1, find all nonzero elements.
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
38
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
39 template <typename T>
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
40 octave_value_list
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
41 find_nonzero_elem_idx (const Array<T>& nda, int nargout,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
42 octave_idx_type n_to_find, int direction)
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
43 {
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
44 octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
45
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5131
diff changeset
46 octave_idx_type count = 0;
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
47
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5131
diff changeset
48 octave_idx_type nel = nda.nelem ();
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
49
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
50 // Set the starting element to the correct value based on the
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
51 // direction to search.
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
52 octave_idx_type k = 0;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
53 if (direction == -1)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
54 k = nel - 1;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
55
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
56 // Search in the default range.
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
57 octave_idx_type start_el = -1;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
58 octave_idx_type end_el = -1;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
59
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
60 // Search for the number of elements to return.
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
61 while (k < nel && k > -1 && n_to_find != count)
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
62 {
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
63 OCTAVE_QUIT;
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
64
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
65 if (nda(k) != 0.0)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
66 {
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
67 end_el = k;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
68 if (start_el == -1)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
69 start_el = k;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
70 count++;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
71 }
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
72 k = k + direction;
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
73 }
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
74
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
75 // Reverse the range if we're looking backward.
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
76 if (direction == -1)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
77 {
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
78 octave_idx_type tmp_el = start_el;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
79 start_el = end_el;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
80 end_el = tmp_el;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
81 }
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
82 // Fix an off by one error.
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
83 end_el++;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
84
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
85 // If the original argument was a row vector, force a row vector of
5130
3bf4c0cd775d [project @ 2005-02-08 03:01:13 by jwe]
jwe
parents: 5107
diff changeset
86 // the overall indices to be returned. But see below for scalar
3bf4c0cd775d [project @ 2005-02-08 03:01:13 by jwe]
jwe
parents: 5107
diff changeset
87 // case...
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
88
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5131
diff changeset
89 octave_idx_type result_nr = count;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5131
diff changeset
90 octave_idx_type result_nc = 1;
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
91
5130
3bf4c0cd775d [project @ 2005-02-08 03:01:13 by jwe]
jwe
parents: 5107
diff changeset
92 bool scalar_arg = false;
3bf4c0cd775d [project @ 2005-02-08 03:01:13 by jwe]
jwe
parents: 5107
diff changeset
93
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
94 if (nda.ndims () == 2 && nda.rows () == 1)
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
95 {
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
96 result_nr = 1;
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
97 result_nc = count;
5130
3bf4c0cd775d [project @ 2005-02-08 03:01:13 by jwe]
jwe
parents: 5107
diff changeset
98
3bf4c0cd775d [project @ 2005-02-08 03:01:13 by jwe]
jwe
parents: 5107
diff changeset
99 scalar_arg = (nda.columns () == 1);
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
100 }
3418
ca92c9d3f882 [project @ 2000-01-12 03:07:47 by jwe]
jwe
parents: 3369
diff changeset
101
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
102 Matrix idx (result_nr, result_nc);
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
103
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
104 Matrix i_idx (result_nr, result_nc);
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
105 Matrix j_idx (result_nr, result_nc);
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
106
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
107 ArrayN<T> val (dim_vector (result_nr, result_nc));
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
108
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
109 if (count > 0)
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
110 {
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
111 count = 0;
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
112
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5131
diff changeset
113 octave_idx_type nr = nda.rows ();
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
114
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5131
diff changeset
115 octave_idx_type i = 0;
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
116
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
117 // Search for elements to return. Only search the region where
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
118 // there are elements to be found using the count that we want
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
119 // to find.
6005
b4351cfb5659 [project @ 2006-09-26 21:38:16 by jwe]
jwe
parents: 6002
diff changeset
120
b4351cfb5659 [project @ 2006-09-26 21:38:16 by jwe]
jwe
parents: 6002
diff changeset
121 // For compatibility, all N-d arrays are handled as if they are
b4351cfb5659 [project @ 2006-09-26 21:38:16 by jwe]
jwe
parents: 6002
diff changeset
122 // 2-d, with the number of columns equal to "prod (dims (2:end))".
b4351cfb5659 [project @ 2006-09-26 21:38:16 by jwe]
jwe
parents: 6002
diff changeset
123
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
124 for (k = start_el; k < end_el; k++)
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
125 {
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
126 OCTAVE_QUIT;
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
127
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
128 if (nda(k) != 0.0)
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
129 {
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
130 idx(count) = k + 1;
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
131
6005
b4351cfb5659 [project @ 2006-09-26 21:38:16 by jwe]
jwe
parents: 6002
diff changeset
132 octave_idx_type xr = k % nr;
b4351cfb5659 [project @ 2006-09-26 21:38:16 by jwe]
jwe
parents: 6002
diff changeset
133 i_idx(count) = xr + 1;
b4351cfb5659 [project @ 2006-09-26 21:38:16 by jwe]
jwe
parents: 6002
diff changeset
134 j_idx(count) = (k - xr) / nr + 1;
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
135
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
136 val(count) = nda(k);
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
137
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
138 count++;
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
139 }
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
140
4826
a7b1e6122d0c [project @ 2004-03-09 19:57:29 by jwe]
jwe
parents: 4678
diff changeset
141 i++;
4678
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
142 }
e1c2d8ca8bc0 [project @ 2003-12-17 00:36:36 by jwe]
jwe
parents: 4628
diff changeset
143 }
5130
3bf4c0cd775d [project @ 2005-02-08 03:01:13 by jwe]
jwe
parents: 5107
diff changeset
144 else if (scalar_arg)
5131
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
145 {
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
146 idx.resize (0, 0);
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
147
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
148 i_idx.resize (0, 0);
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
149 j_idx.resize (0, 0);
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
150
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
151 val.resize (dim_vector (0, 0));
89cddd966068 [project @ 2005-02-08 03:32:25 by jwe]
jwe
parents: 5130
diff changeset
152 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
153
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
154 switch (nargout)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
155 {
6254
5b43c2332b69 [project @ 2007-01-29 17:35:15 by jwe]
jwe
parents: 6026
diff changeset
156 default:
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
157 case 3:
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
158 retval(2) = val;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
159 // Fall through!
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
160
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
161 case 2:
3418
ca92c9d3f882 [project @ 2000-01-12 03:07:47 by jwe]
jwe
parents: 3369
diff changeset
162 retval(1) = j_idx;
ca92c9d3f882 [project @ 2000-01-12 03:07:47 by jwe]
jwe
parents: 3369
diff changeset
163 retval(0) = i_idx;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
164 break;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
165
6254
5b43c2332b69 [project @ 2007-01-29 17:35:15 by jwe]
jwe
parents: 6026
diff changeset
166 case 1:
5b43c2332b69 [project @ 2007-01-29 17:35:15 by jwe]
jwe
parents: 6026
diff changeset
167 case 0:
5b43c2332b69 [project @ 2007-01-29 17:35:15 by jwe]
jwe
parents: 6026
diff changeset
168 retval(0) = idx;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
169 break;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
170 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
171
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
172 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
173 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
174
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
175 template octave_value_list find_nonzero_elem_idx (const Array<double>&, int,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
176 octave_idx_type, int);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
177
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
178 template octave_value_list find_nonzero_elem_idx (const Array<Complex>&, int,
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
179 octave_idx_type, int);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
180
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
181 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
182 octave_value_list
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
183 find_nonzero_elem_idx (const Sparse<T>& v, int nargout,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
184 octave_idx_type n_to_find, int direction)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
185 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
186 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
187
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
188
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
189 octave_idx_type nc = v.cols();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
190 octave_idx_type nr = v.rows();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
191 octave_idx_type nz = v.nnz();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
192
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
193 // 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
194 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
195 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
196 octave_idx_type count;
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 // 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
199 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
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 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
202 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
203 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
204 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
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 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
207 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
208 for (octave_idx_type j = 0; j < nc; j++)
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 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
211 if (v.cidx(j) == 0 && v.cidx(j+1) != 0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
212 start_nc = j;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
213 if (v.cidx(j+1) >= n_to_find)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
214 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
215 end_nc = j + 1;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
216 break;
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 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
219 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
220 else
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 for (octave_idx_type j = nc; j > 0; j--)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
223 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
224 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
225 if (v.cidx(j) == nz && v.cidx(j-1) != nz)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
226 end_nc = j;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
227 if (nz - v.cidx(j-1) >= n_to_find)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
228 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
229 start_nc = j - 1;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
230 break;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
231 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
232 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
233 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
234
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
235 count = (n_to_find > v.cidx(end_nc) - v.cidx(start_nc) ?
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
236 v.cidx(end_nc) - v.cidx(start_nc) : n_to_find);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
237
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
238 // If the original argument was a row vector, force a row vector of
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
239 // the overall indices to be returned. But see below for scalar
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
240 // case...
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
241
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
242 octave_idx_type result_nr = count;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
243 octave_idx_type result_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
244
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
245 bool scalar_arg = false;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
246
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
247 if (v.rows () == 1)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
248 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
249 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
250 result_nc = count;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
251
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
252 scalar_arg = (v.columns () == 1);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
253 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
254
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
255 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
256
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
257 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
258 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
259
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
260 ArrayN<T> val (dim_vector (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
261
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
262 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
263 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
264 // Search for elements to return. Only search the region where
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
265 // there are elements to be found using the count that we want
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
266 // to find.
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
267 for (octave_idx_type j = start_nc, cx = 0; j < end_nc; j++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
268 for (octave_idx_type i = v.cidx(j); i < v.cidx(j+1); i++ )
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
269 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
270 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
271 if (direction < 0 && i < nz - count)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
272 continue;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
273 i_idx (cx) = static_cast<double> (v.ridx(i) + 1);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
274 j_idx (cx) = static_cast<double> (j + 1);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
275 idx (cx) = j * nr + v.ridx(i) + 1;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
276 val (cx) = v.data(i);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
277 cx++;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
278 if (cx == count)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
279 break;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
280 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
281 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
282 else if (scalar_arg)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
283 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
284 idx.resize (0, 0);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
285
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
286 i_idx.resize (0, 0);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
287 j_idx.resize (0, 0);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
288
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
289 val.resize (dim_vector (0, 0));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
290 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
291
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
292 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
293 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
294 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
295 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
296 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
297 break;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
298
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
299 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
300 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
301 // 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
302
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
303 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
304 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
305 // 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
306
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
307 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
308 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
309 // 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
310
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
311 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
312 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
313 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
314 break;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
315
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
316 default:
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
317 panic_impossible ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
318 break;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
319 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
320
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
321 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
322 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
323
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
324 template octave_value_list find_nonzero_elem_idx (const Sparse<double>&, int,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
325 octave_idx_type, int);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
326
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
327 template octave_value_list find_nonzero_elem_idx (const Sparse<Complex>&, int,
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
328 octave_idx_type, int);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
329
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
330 DEFUN_DLD (find, args, nargout,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
331 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
332 @deftypefn {Loadable Function} {} find (@var{x})\n\
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
333 @deftypefnx {Loadable Function} {} find (@var{x}, @var{n})\n\
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
334 @deftypefnx {Loadable Function} {} find (@var{x}, @var{n}, @var{direction})\n\
6524
03c89ade4070 [project @ 2007-04-13 12:19:30 by jwe]
jwe
parents: 6254
diff changeset
335 Return a vector of indices of nonzero elements of a matrix, as a row if\n\
03c89ade4070 [project @ 2007-04-13 12:19:30 by jwe]
jwe
parents: 6254
diff changeset
336 @var{x} is a row or as a column otherwise. To obtain a single index for\n\
03c89ade4070 [project @ 2007-04-13 12:19:30 by jwe]
jwe
parents: 6254
diff changeset
337 each matrix element, Octave pretends that the columns of a matrix form one\n\
03c89ade4070 [project @ 2007-04-13 12:19:30 by jwe]
jwe
parents: 6254
diff changeset
338 long vector (like Fortran arrays are stored). For example,\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
339 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
340 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
341 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
342 find (eye (2))\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
343 @result{} [ 1; 4 ]\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
344 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
345 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
346 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
347 If two outputs are requested, @code{find} returns the row and column\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
348 indices of nonzero elements of a matrix. For example,\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
349 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
350 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
351 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
352 [i, j] = find (2 * eye (2))\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
353 @result{} i = [ 1; 2 ]\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
354 @result{} j = [ 1; 2 ]\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
355 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
356 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
357 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
358 If three outputs are requested, @code{find} also returns a vector\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
359 containing the nonzero values. For example,\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
360 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
361 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
362 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
363 [i, j, v] = find (3 * eye (2))\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
364 @result{} i = [ 1; 2 ]\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
365 @result{} j = [ 1; 2 ]\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
366 @result{} v = [ 3; 3 ]\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
367 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
368 @end example\n\
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
369 \n\
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
370 If two inputs are given, @var{n} indicates the number of elements to\n\
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
371 find from the beginning of the matrix or vector.\n\
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
372 \n\
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
373 If three inputs are given, @var{direction} should be one of \"first\" or\n\
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
374 \"last\" indicating that it should start counting found elements from the\n\
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
375 first or last element.\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
376 \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 Note that this function is particularly useful for sparse matrices, as\n\
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
378 it extracts the non-zero elements as vectors, which can then be used to\n\
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
379 create the original matrix. For 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
380 \n\
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
381 @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
382 @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
383 sz = size(a);\n\
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
384 [i, j, v] = find (a);\n\
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
385 b = sparse(i, j, v, sz(1), sz(2));\n\
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
386 @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
387 @end 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
388 @seealso{sparse}\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3014
diff changeset
389 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
390 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
391 octave_value_list retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
392
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
393 int nargin = args.length ();
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
394
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
395 if (nargin > 3 || nargin < 1)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
396 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5307
diff changeset
397 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
398 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
399 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
400
6002
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
401 // Setup the default options.
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
402 octave_idx_type n_to_find = -1;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
403 if (nargin > 1)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
404 {
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
405 n_to_find = args(1).int_value ();
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
406 if (error_state)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
407 {
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
408 error ("find: expecting second argument to be an integer");
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
409 return retval;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
410 }
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
411 }
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
412
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
413 // Direction to do the searching (1 == forward, -1 == reverse).
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
414 int direction = 1;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
415 if (nargin > 2)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
416 {
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
417 direction = 0;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
418
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
419 std::string s_arg = args(2).string_value ();
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
420
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
421 if (! error_state)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
422 {
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
423 if (s_arg == "first")
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
424 direction = 1;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
425 else if (s_arg == "last")
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
426 direction = -1;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
427 }
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
428
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
429 if (direction == 0)
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
430 {
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
431 error ("find: expecting third argument to be \"first\" or \"last\"");
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
432 return retval;
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
433 }
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
434 }
c5d0490aad55 [project @ 2006-09-26 19:45:42 by jwe]
jwe
parents: 5823
diff changeset
435
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
436 octave_value arg = args(0);
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
437
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
438 if (arg.is_sparse_type ())
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
439 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
440 if (arg.is_real_type ())
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
441 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
442 SparseMatrix v = arg.sparse_matrix_value ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
443
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
444 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
445 retval = find_nonzero_elem_idx (v, nargout,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
446 n_to_find, direction);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
447 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
448 else if (arg.is_complex_type ())
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
449 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
450 SparseComplexMatrix v = arg.sparse_complex_matrix_value ();
5107
c891dd97b837 [project @ 2005-01-12 19:49:18 by jwe]
jwe
parents: 4826
diff changeset
451
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
452 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
453 retval = find_nonzero_elem_idx (v, nargout,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
454 n_to_find, direction);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
455 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
456 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
457 gripe_wrong_type_arg ("find", arg);
5107
c891dd97b837 [project @ 2005-01-12 19:49:18 by jwe]
jwe
parents: 4826
diff changeset
458 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
459 else
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
460 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
461 if (arg.is_real_type ())
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
462 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
463 NDArray nda = arg.array_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
464
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
465 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
466 retval = find_nonzero_elem_idx (nda, nargout,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
467 n_to_find, direction);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
468 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
469 else if (arg.is_complex_type ())
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
470 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
471 ComplexNDArray cnda = arg.complex_array_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
472
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
473 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
474 retval = find_nonzero_elem_idx (cnda, nargout,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
475 n_to_find, direction);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
476 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
477 else if (arg.is_string ())
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
478 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
479 charNDArray cnda = arg.char_array_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
480
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
481 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
482 retval = find_nonzero_elem_idx (cnda, nargout,
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
483 n_to_find, direction);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
484 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
485 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
486 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
487 gripe_wrong_type_arg ("find", arg);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
488 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
489 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
490
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
491 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
492 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
493
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
494 /*
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
495 ;;; Local Variables: ***
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
496 ;;; mode: C++ ***
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
497 ;;; End: ***
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
498 */