Mercurial > octave
annotate libinterp/dldfcn/dmperm.cc @ 20818:cef0448a6ed2
eliminate unnecessary uses of nargin
* __glpk__.cc, chol.cc, dmperm.cc, qr.cc, symrcm.cc, ov-cell.cc,
ov-fcn-handle.cc, ov-fcn-inline.cc, ov-null-mat.cc, ov-struct.cc,
ov-type-conv.h, ov-usr-fcn.cc, oct-parse.in.yy, pt-misc.cc:
Don't use nargin variable unless it is used more than once.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 07 Dec 2015 13:26:03 -0500 |
parents | d9ca869ca124 |
children | 1142cf6abc0d |
rev | line source |
---|---|
5610 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19040
diff
changeset
|
3 Copyright (C) 2005-2015 David Bateman |
11523 | 4 Copyright (C) 1998-2005 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5610 | 7 |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5610 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5610 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "defun-dld.h" | |
29 #include "error.h" | |
30 #include "gripes.h" | |
31 #include "oct-obj.h" | |
32 #include "utils.h" | |
33 | |
5616 | 34 #include "oct-sparse.h" |
5610 | 35 #include "ov-re-sparse.h" |
36 #include "ov-cx-sparse.h" | |
37 #include "SparseQR.h" | |
38 #include "SparseCmplxQR.h" | |
39 | |
16313
6aafe87a3144
use int64_t for idx type if --enable-64
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
40 #ifdef USE_64_BIT_IDX_T |
5648 | 41 #define CXSPARSE_NAME(name) cs_dl ## name |
5610 | 42 #else |
5648 | 43 #define CXSPARSE_NAME(name) cs_di ## name |
5610 | 44 #endif |
45 | |
46 static RowVector | |
47 put_int (octave_idx_type *p, octave_idx_type n) | |
48 { | |
49 RowVector ret (n); | |
50 for (octave_idx_type i = 0; i < n; i++) | |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
51 ret.xelem (i) = p[i] + 1; |
5610 | 52 return ret; |
53 } | |
54 | |
6066 | 55 #if HAVE_CXSPARSE |
56 static octave_value_list | |
57 dmperm_internal (bool rank, const octave_value arg, int nargout) | |
5610 | 58 { |
59 octave_value_list retval; | |
60 octave_idx_type nr = arg.rows (); | |
61 octave_idx_type nc = arg.columns (); | |
62 SparseMatrix m; | |
63 SparseComplexMatrix cm; | |
5648 | 64 CXSPARSE_NAME () csm; |
5610 | 65 csm.m = nr; |
66 csm.n = nc; | |
7520 | 67 csm.x = 0; |
5610 | 68 csm.nz = -1; |
69 | |
70 if (arg.is_real_type ()) | |
71 { | |
72 m = arg.sparse_matrix_value (); | |
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
|
73 csm.nzmax = m.nnz (); |
5610 | 74 csm.p = m.xcidx (); |
75 csm.i = m.xridx (); | |
76 } | |
77 else | |
78 { | |
79 cm = arg.sparse_complex_matrix_value (); | |
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
|
80 csm.nzmax = cm.nnz (); |
5610 | 81 csm.p = cm.xcidx (); |
82 csm.i = cm.xridx (); | |
83 } | |
84 | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
85 if (nargout <= 1 || rank) |
5610 | 86 { |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20790
diff
changeset
|
87 #if defined (CS_VER) && (CS_VER >= 2) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
88 octave_idx_type *jmatch = CXSPARSE_NAME (_maxtrans) (&csm, 0); |
5792 | 89 #else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
90 octave_idx_type *jmatch = CXSPARSE_NAME (_maxtrans) (&csm); |
5792 | 91 #endif |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
92 if (rank) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
93 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
94 octave_idx_type r = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
95 for (octave_idx_type i = 0; i < nc; i++) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
96 if (jmatch[nr+i] >= 0) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
97 r++; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
98 retval(0) = static_cast<double>(r); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
99 } |
5610 | 100 else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
101 retval(0) = put_int (jmatch + nr, nc); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
102 CXSPARSE_NAME (_free) (jmatch); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
103 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
104 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
105 { |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20790
diff
changeset
|
106 #if defined (CS_VER) && (CS_VER >= 2) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
107 CXSPARSE_NAME (d) *dm = CXSPARSE_NAME(_dmperm) (&csm, 0); |
5792 | 108 #else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
109 CXSPARSE_NAME (d) *dm = CXSPARSE_NAME(_dmperm) (&csm); |
5792 | 110 #endif |
6066 | 111 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
112 //retval(5) = put_int (dm->rr, 5); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
113 //retval(4) = put_int (dm->cc, 5); |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20790
diff
changeset
|
114 #if defined (CS_VER) && (CS_VER >= 2) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
115 retval(3) = put_int (dm->s, dm->nb+1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
116 retval(2) = put_int (dm->r, dm->nb+1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
117 retval(1) = put_int (dm->q, nc); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
118 retval(0) = put_int (dm->p, nr); |
5792 | 119 #else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
120 retval(3) = put_int (dm->S, dm->nb+1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
121 retval(2) = put_int (dm->R, dm->nb+1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
122 retval(1) = put_int (dm->Q, nc); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
123 retval(0) = put_int (dm->P, nr); |
5792 | 124 #endif |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
125 CXSPARSE_NAME (_dfree) (dm); |
5610 | 126 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
127 |
6066 | 128 return retval; |
129 } | |
130 #endif | |
131 | |
132 DEFUN_DLD (dmperm, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 "-*- texinfo -*-\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
134 @deftypefn {Loadable Function} {@var{p} =} dmperm (@var{S})\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
135 @deftypefnx {Loadable Function} {[@var{p}, @var{q}, @var{r}, @var{S}] =} dmperm (@var{S})\n\ |
6066 | 136 \n\ |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
137 @cindex @nospell{Dulmage-Mendelsohn} decomposition\n\ |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
138 Perform a @nospell{Dulmage-Mendelsohn} permutation of the sparse matrix\n\ |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
139 @var{S}.\n\ |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
140 \n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
141 With a single output argument @code{dmperm} performs the row permutations\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
142 @var{p} such that @code{@var{S}(@var{p},:)} has no zero elements on the\n\ |
6066 | 143 diagonal.\n\ |
144 \n\ | |
145 Called with two or more output arguments, returns the row and column\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
146 permutations, such that @code{@var{S}(@var{p}, @var{q})} is in block\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
147 triangular form. The values of @var{r} and @var{S} define the boundaries\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
148 of the blocks. If @var{S} is square then @code{@var{r} == @var{S}}.\n\ |
6066 | 149 \n\ |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
150 The method used is described in: @nospell{A. Pothen & C.-J. Fan.}\n\ |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
151 @cite{Computing the Block Triangular Form of a Sparse Matrix}.\n\ |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
152 ACM Trans. Math. Software, 16(4):303-324, 1990.\n\ |
6066 | 153 @seealso{colamd, ccolamd}\n\ |
154 @end deftypefn") | |
155 { | |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
156 octave_value_list retval; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
157 |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
158 if (args.length () != 1) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
159 print_usage (); |
6066 | 160 |
161 #if HAVE_CXSPARSE | |
162 retval = dmperm_internal (false, args(0), nargout); | |
5610 | 163 #else |
164 error ("dmperm: not available in this version of Octave"); | |
165 #endif | |
166 | |
167 return retval; | |
168 } | |
169 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
170 /* |
7243 | 171 %!testif HAVE_CXSPARSE |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
172 %! n = 20; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
173 %! a = speye (n,n); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
174 %! a = a(randperm (n),:); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
175 %! assert (a(dmperm (a),:), speye (n)); |
5610 | 176 |
7243 | 177 %!testif HAVE_CXSPARSE |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
178 %! n = 20; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
179 %! d = 0.2; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
180 %! a = tril (sprandn (n,n,d), -1) + speye (n,n); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
181 %! a = a(randperm (n), randperm (n)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
182 %! [p,q,r,s] = dmperm (a); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
183 %! assert (tril (a(p,q), -1), sparse (n, n)); |
5610 | 184 */ |
185 | |
6066 | 186 DEFUN_DLD (sprank, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
187 "-*- texinfo -*-\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
188 @deftypefn {Loadable Function} {@var{p} =} sprank (@var{S})\n\ |
12578
f5a780d675a1
Clean up operator and function indices in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
189 @cindex structural rank\n\ |
6066 | 190 \n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
191 Calculate the structural rank of the sparse matrix @var{S}.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
192 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
193 Note that only the structure of the matrix is used in this calculation based\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
194 on a @nospell{Dulmage-Mendelsohn} permutation to block triangular form. As\n\ |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
195 such the numerical rank of the matrix @var{S} is bounded by\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
196 @code{sprank (@var{S}) >= rank (@var{S})}. Ignoring floating point errors\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
197 @code{sprank (@var{S}) == rank (@var{S})}.\n\ |
6066 | 198 @seealso{dmperm}\n\ |
199 @end deftypefn") | |
200 { | |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
201 octave_value_list retval; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
202 |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
203 if (args.length () != 1) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
204 print_usage (); |
6066 | 205 |
206 #if HAVE_CXSPARSE | |
207 retval = dmperm_internal (true, args(0), nargout); | |
208 #else | |
209 error ("sprank: not available in this version of Octave"); | |
210 #endif | |
211 | |
212 return retval; | |
213 } | |
214 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
215 /* |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
216 %!testif HAVE_CXSPARSE |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
217 %! assert (sprank (speye (20)), 20) |
7243 | 218 %!testif HAVE_CXSPARSE |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
219 %! assert (sprank ([1,0,2,0;2,0,4,0]), 2) |
6066 | 220 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
221 %!error sprank (1,2) |
6066 | 222 */ |