annotate libinterp/dldfcn/amd.cc @ 20898:8da80da1ac37

maint: Use ovl() more places in the code.
author Rik <rik@octave.org>
date Mon, 14 Dec 2015 17:53:27 -0800
parents 1142cf6abc0d
children b17fda023ca6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
1 /*
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19208
diff changeset
3 Copyright (C) 2008-2015 David Bateman
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
4
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
5 This file is part of Octave.
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
6
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
10 option) any later version.
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
11
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
15 for more details.
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
16
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
20
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
21 */
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
22
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
23 // This is the octave interface to amd, which bore the copyright given
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
24 // in the help of the functions.
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
25
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
27 #include <config.h>
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
28 #endif
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
29
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
30 #include <cstdlib>
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
31
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
32 #include <string>
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
33 #include <vector>
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
34
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
35 #include "ov.h"
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
36 #include "defun-dld.h"
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
37 #include "pager.h"
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
38 #include "ov-re-mat.h"
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
39
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
40 #include "ov-re-sparse.h"
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
41 #include "ov-cx-sparse.h"
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
42 #include "oct-map.h"
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
43
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
44 #include "oct-sparse.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
45 #include "oct-locbuf.h"
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
46
16313
6aafe87a3144 use int64_t for idx type if --enable-64
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
47 #ifdef USE_64_BIT_IDX_T
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
48 #define AMD_NAME(name) amd_l ## name
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
49 #else
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
50 #define AMD_NAME(name) amd ## name
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
51 #endif
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
52
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
53 DEFUN_DLD (amd, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
54 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20790
diff changeset
55 @deftypefn {} {@var{p} =} amd (@var{S})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20790
diff changeset
56 @deftypefnx {} {@var{p} =} amd (@var{S}, @var{opts})\n\
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
57 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
58 Return the approximate minimum degree permutation of a matrix.\n\
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
59 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
60 This is a permutation such that the Cholesky@tie{}factorization of\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
61 @code{@var{S} (@var{p}, @var{p})} tends to be sparser than the\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
62 Cholesky@tie{}factorization of @var{S} itself. @code{amd} is typically\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
63 faster than @code{symamd} but serves a similar purpose.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
64 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
65 The optional parameter @var{opts} is a structure that controls the behavior\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
66 of @code{amd}. The fields of the structure are\n\
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
67 \n\
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
68 @table @asis\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
69 @item @var{opts}.dense\n\
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
70 Determines what @code{amd} considers to be a dense row or column of the\n\
18679
a142f35f3cb6 doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents: 17787
diff changeset
71 input matrix. Rows or columns with more than @code{max (16, (dense *\n\
a142f35f3cb6 doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents: 17787
diff changeset
72 sqrt (@var{n})))} entries, where @var{n} is the order of the matrix @var{S},\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
73 are ignored by @code{amd} during the calculation of the permutation.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
74 The value of dense must be a positive scalar and the default value is 10.0\n\
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
75 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
76 @item @var{opts}.aggressive\n\
18809
53af80da6781 doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents: 17787
diff changeset
77 If this value is a nonzero scalar, then @code{amd} performs aggressive\n\
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
78 absorption. The default is not to perform aggressive absorption.\n\
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
79 @end table\n\
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
80 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
81 The author of the code itself is Timothy A. Davis\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
82 @email{davis@@cise.ufl.edu}, University of Florida\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
83 (see @url{http://www.cise.ufl.edu/research/sparse/amd}).\n\
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
84 @seealso{symamd, colamd}\n\
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
85 @end deftypefn")
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
86 {
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
87 #ifdef HAVE_AMD
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
88 int nargin = args.length ();
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
89
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
90 if (nargin < 1 || nargin > 2)
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
91 print_usage ();
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
92
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
93 octave_idx_type n_row, n_col;
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
94 const octave_idx_type *ridx, *cidx;
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
95 SparseMatrix sm;
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
96 SparseComplexMatrix scm;
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
97
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
98 if (args(0).is_sparse_type ())
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
99 {
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
100 if (args(0).is_complex_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
101 {
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
102 scm = args(0).sparse_complex_matrix_value ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
103 n_row = scm.rows ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
104 n_col = scm.cols ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
105 ridx = scm.xridx ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
106 cidx = scm.xcidx ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
107 }
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
108 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
109 {
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
110 sm = args(0).sparse_matrix_value ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
111 n_row = sm.rows ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
112 n_col = sm.cols ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
113 ridx = sm.xridx ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
114 cidx = sm.xcidx ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
115 }
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
116 }
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
117 else
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
118 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
119 if (args(0).is_complex_type ())
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
120 sm = SparseMatrix (real (args(0).complex_matrix_value ()));
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
121 else
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
122 sm = SparseMatrix (args(0).matrix_value ());
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
123
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
124 n_row = sm.rows ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
125 n_col = sm.cols ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
126 ridx = sm.xridx ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
127 cidx = sm.xcidx ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
128 }
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
129
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
130 if (n_row != n_col)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
131 error ("amd: matrix S must be square");
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
132
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
133 OCTAVE_LOCAL_BUFFER (double, Control, AMD_CONTROL);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
134 AMD_NAME (_defaults) (Control) ;
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
135 if (nargin > 1)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
136 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
137 octave_scalar_map arg1 = args(1).xscalar_map_value ("amd: OPTS argument must be a scalar structure");
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
138
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
139 octave_value tmp;
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
140
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
141 tmp = arg1.getfield ("dense");
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
142 if (tmp.is_defined ())
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
143 Control[AMD_DENSE] = tmp.double_value ();
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
144
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
145 tmp = arg1.getfield ("aggressive");
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
146 if (tmp.is_defined ())
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
147 Control[AMD_AGGRESSIVE] = tmp.double_value ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
148 }
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
149
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
150 OCTAVE_LOCAL_BUFFER (octave_idx_type, P, n_col);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
151 Matrix xinfo (AMD_INFO, 1);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
152 double *Info = xinfo.fortran_vec ();
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
153
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
154 // FIXME: how can we manage the memory allocation of amd
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
155 // in a cleaner manner?
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
156 SUITESPARSE_ASSIGN_FPTR (malloc_func, amd_malloc, malloc);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
157 SUITESPARSE_ASSIGN_FPTR (free_func, amd_free, free);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
158 SUITESPARSE_ASSIGN_FPTR (calloc_func, amd_calloc, calloc);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
159 SUITESPARSE_ASSIGN_FPTR (realloc_func, amd_realloc, realloc);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
160 SUITESPARSE_ASSIGN_FPTR (printf_func, amd_printf, printf);
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
161
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
162 octave_idx_type result = AMD_NAME (_order) (n_col, cidx, ridx, P,
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
163 Control, Info);
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
164
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
165 if (result == AMD_OUT_OF_MEMORY)
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
166 error ("amd: out of memory");
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
167 else if (result == AMD_INVALID)
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
168 error ("amd: matrix S is corrupted");
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
169
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
170 Matrix Pout (1, n_col);
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
171 for (octave_idx_type i = 0; i < n_col; i++)
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
172 Pout.xelem (i) = P[i] + 1;
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
173
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
174 if (nargout > 1)
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
175 return ovl (Pout, xinfo);
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
176 else
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
177 return ovl (Pout);
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
178
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
179 #else
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
180
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
181 error ("amd: not available in this version of Octave");
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
182
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
183 #endif
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents:
diff changeset
184 }
19144
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
185 /*
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
186 %!shared A, A2, opts
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
187 %! A = ones (20, 30);
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
188 %! A2 = ones (30, 30);
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
189 %!
19208
5f21e0bff135 Use %!testif HAVE_AMD for amd tests added in cset e99d7a2e7367
Mike Miller <mtmiller@ieee.org>
parents: 19144
diff changeset
190 %!testif HAVE_AMD
19144
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
191 %! assert(amd (A2), [1:30])
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
192 %! opts.dense = 25;
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
193 %! assert(amd (A2, opts), [1:30])
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
194 %! opts.aggressive = 1;
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
195 %! assert(amd (A2, opts), [1:30])
19208
5f21e0bff135 Use %!testif HAVE_AMD for amd tests added in cset e99d7a2e7367
Mike Miller <mtmiller@ieee.org>
parents: 19144
diff changeset
196
5f21e0bff135 Use %!testif HAVE_AMD for amd tests added in cset e99d7a2e7367
Mike Miller <mtmiller@ieee.org>
parents: 19144
diff changeset
197 %!error <matrix S must be square|not available in this version> amd (A)
5f21e0bff135 Use %!testif HAVE_AMD for amd tests added in cset e99d7a2e7367
Mike Miller <mtmiller@ieee.org>
parents: 19144
diff changeset
198 %!error amd (A2, 2)
5f21e0bff135 Use %!testif HAVE_AMD for amd tests added in cset e99d7a2e7367
Mike Miller <mtmiller@ieee.org>
parents: 19144
diff changeset
199 %!error <matrix S is corrupted|not available in this version> amd ([])
19144
e99d7a2e7367 * amd.cc: Tests added.
Eduardo Ramos (edu159) <eduradical951@gmail.com>
parents: 19139
diff changeset
200 */