annotate libinterp/dldfcn/symbfact.cc @ 21585:bad3ed83330d

symbfact.cc: Overhaul dldfcn. * symbfact.cc: Redo docstring. Eliminate nargout input validation. Improve input validation for TYP and MODE variables. Add label cleanup: and use goto statements to guarantee that memory allocated in cholmod library is cleaned up. Use std::max rather than hand-coded max routine. Add BIST tests.
author Rik <rik@octave.org>
date Mon, 04 Apr 2016 09:00:22 -0700
parents ad0599a0acc6
children d7a268e68e69
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
1 /*
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
3 Copyright (C) 2005-2015 David Bateman
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
4 Copyright (C) 1998-2005 Andy Adler
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
5
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
6 This file is part of Octave.
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
7
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
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: 7001
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: 7001
diff changeset
11 option) any later version.
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
12
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
16 for more details.
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
17
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
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: 7001
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: 7001
diff changeset
20 <http://www.gnu.org/licenses/>.
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
21
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
22 */
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
23
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21229
diff changeset
25 # include "config.h"
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
26 #endif
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
27
21186
7f35125714b4 don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents: 21145
diff changeset
28 #include "oct-locbuf.h"
7f35125714b4 don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents: 21145
diff changeset
29 #include "oct-sparse.h"
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7036
diff changeset
30 #include "oct-spparms.h"
21186
7f35125714b4 don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents: 21145
diff changeset
31 #include "sparse-chol.h"
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7036
diff changeset
32 #include "sparse-util.h"
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7036
diff changeset
33
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7036
diff changeset
34 #include "ov-re-sparse.h"
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7036
diff changeset
35 #include "ov-cx-sparse.h"
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
36 #include "defun-dld.h"
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
37 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20946
diff changeset
38 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
39 #include "ovl.h"
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
40 #include "utils.h"
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
41
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
42 DEFUN_DLD (symbfact, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
43 "-*- texinfo -*-\n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
44 @deftypefn {} {[@var{count}, @var{h}, @var{parent}, @var{post}, @var{R}] =} symbfact (@var{S})\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20792
diff changeset
45 @deftypefnx {} {[@dots{}] =} symbfact (@var{S}, @var{typ})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20792
diff changeset
46 @deftypefnx {} {[@dots{}] =} symbfact (@var{S}, @var{typ}, @var{mode})\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
47 \n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
48 Perform a symbolic factorization analysis of the sparse 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
49 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
50 The input variables are\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
51 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
52 @table @var\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
53 @item S\n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
54 @var{S} is a real or complex sparse matrix.\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
55 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
56 @item typ\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
57 Is the type of the factorization and can be one of\n\
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
58 \n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
59 @table @asis\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
60 @item @qcode{\"sym\"} (default)\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
61 Factorize @var{S}. Assumes @var{S} is symmetric and uses the upper\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
62 triangular portion of the matrix.\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
63 \n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
64 @item @qcode{\"col\"}\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
65 Factorize @tcode{@var{S}' * @var{S}}.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
66 \n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
67 @item @qcode{\"row\"}\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 16316
diff changeset
68 Factorize @tcode{@var{S} * @var{S}'}.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
69 \n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
70 @item @qcode{\"lo\"}\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
71 Factorize @tcode{@var{S}'}. Assumes @var{S} is symmetric and uses the lower\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
72 triangular portion of the matrix.\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
73 @end table\n\
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
74 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
75 @item mode\n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
76 When @var{mode} is unspecified return the Cholesky@tie{}factorization for\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
77 @var{R}. If @var{mode} is @qcode{\"lower\"} or @qcode{\"L\"} then return\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
78 the conjugate transpose @tcode{@var{R}'} which is a lower triangular factor.\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
79 The conjugate transpose version is faster and uses less memory, but still\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
80 returns the same values for all other outputs: @var{count}, @var{h},\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
81 @var{parent}, and @var{post}.\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
82 @end table\n\
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
83 \n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
84 The output variables are:\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
85 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
86 @table @var\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
87 @item count\n\
21547
ad0599a0acc6 doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 21301
diff changeset
88 The row counts of the Cholesky@tie{}factorization as determined by\n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
89 @var{typ}. The computational difficulty of performing the true\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
90 factorization using @code{chol} is @code{sum (@var{count} .^ 2)}.\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
91 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
92 @item h\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
93 The height of the elimination tree.\n\
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
94 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
95 @item parent\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
96 The elimination tree itself.\n\
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
97 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
98 @item post\n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
99 A sparse boolean matrix whose structure is that of the\n\
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
100 Cholesky@tie{}factorization as determined by @var{typ}.\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
101 @end table\n\
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
102 @seealso{chol, etree, treelayout}\n\
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
103 @end deftypefn")
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
104 {
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
105 #ifdef HAVE_CHOLMOD
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
106
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
107 int nargin = args.length ();
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
108
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
109 if (nargin < 1 || nargin > 3)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
110 print_usage ();
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
111
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20853
diff changeset
112 octave_value_list retval;
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
113
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
114 double dummy;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
115 cholmod_sparse Astore;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
116 cholmod_sparse *A = &Astore;
5527
ce71ed4c6da6 [project @ 2005-11-01 22:15:49 by jwe]
jwe
parents: 5512
diff changeset
117 A->packed = true;
ce71ed4c6da6 [project @ 2005-11-01 22:15:49 by jwe]
jwe
parents: 5512
diff changeset
118 A->sorted = true;
7520
b166043585a8 use 0 instead of NULL
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
119 A->nz = 0;
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
120 #if defined (OCTAVE_ENABLE_64)
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
121 A->itype = CHOLMOD_LONG;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
122 #else
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
123 A->itype = CHOLMOD_INT;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
124 #endif
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
125 A->dtype = CHOLMOD_DOUBLE;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
126 A->stype = 1;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
127 A->x = &dummy;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
128
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
129 if (args(0).is_real_type ())
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
130 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
131 const SparseMatrix a = args(0).sparse_matrix_value ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
132 A->nrow = a.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
133 A->ncol = a.cols ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
134 A->p = a.cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
135 A->i = a.ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
136 A->nzmax = a.nnz ();
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
137 A->xtype = CHOLMOD_REAL;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
138
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
139 if (a.rows () > 0 && a.cols () > 0)
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
140 A->x = a.data ();
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
141 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
142 else if (args(0).is_complex_type ())
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
143 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
144 const SparseComplexMatrix a = args(0).sparse_complex_matrix_value ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
145 A->nrow = a.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
146 A->ncol = a.cols ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
147 A->p = a.cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
148 A->i = a.ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
149 A->nzmax = a.nnz ();
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
150 A->xtype = CHOLMOD_COMPLEX;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
151
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
152 if (a.rows () > 0 && a.cols () > 0)
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
153 A->x = a.data ();
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
154 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
155 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20946
diff changeset
156 err_wrong_type_arg ("symbfact", args(0));
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
157
5527
ce71ed4c6da6 [project @ 2005-11-01 22:15:49 by jwe]
jwe
parents: 5512
diff changeset
158 octave_idx_type coletree = false;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
159 octave_idx_type n = A->nrow;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
160
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
161 if (nargin > 1)
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
162 {
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
163 std::string str = args(1).xstring_value ("TYP must be a string");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
164 // FIXME: The input validation could be improved to use strncmp
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
165 char ch;
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
166 ch = tolower (str[0]);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
167 if (ch == 'r') // 'row'
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
168 A->stype = 0;
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
169 else if (ch == 'c') // 'col'
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
170 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
171 n = A->ncol;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
172 coletree = true;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
173 A->stype = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
174 }
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
175 else if (ch == 's') // 'sym' (default)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
176 A->stype = 1;
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
177 else if (ch == 'l') // 'lo'
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
178 A->stype = -1;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
179 else
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
180 error ("symbfact: unrecognized TYP \"%s\"", str.c_str ());
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
181 }
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
182
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
183 if (nargin == 3)
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
184 {
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
185 std::string str = args(2).xstring_value ("MODE must be a string");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
186 // FIXME: The input validation could be improved to use strncmp
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
187 char ch;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
188 ch = toupper (str[0]);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
189 if (ch != 'L')
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
190 error ("symbfact: unrecognized MODE \"%s\"", str.c_str ());
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
191 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
192
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
193 if (A->stype && A->nrow != A->ncol)
21110
3d0d84305600 Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents: 21109
diff changeset
194 err_square_matrix_required ("symbfact", "S");
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
195
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
196 OCTAVE_LOCAL_BUFFER (octave_idx_type, Parent, n);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
197 OCTAVE_LOCAL_BUFFER (octave_idx_type, Post, n);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
198 OCTAVE_LOCAL_BUFFER (octave_idx_type, ColCount, n);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
199 OCTAVE_LOCAL_BUFFER (octave_idx_type, First, n);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
200 OCTAVE_LOCAL_BUFFER (octave_idx_type, Level, n);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
201
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
202 cholmod_common Common;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
203 cholmod_common *cm = &Common;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
204 CHOLMOD_NAME(start) (cm);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
205
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
206 double spu = octave_sparse_params::get_key ("spumoni");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
207 if (spu == 0.)
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
208 {
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
209 cm->print = -1;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
210 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, 0);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
211 }
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
212 else
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
213 {
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
214 cm->print = static_cast<int> (spu) + 2;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
215 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
216 }
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
217
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
218 cm->error_handler = &SparseCholError;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
219 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide, divcomplex);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
220 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
221
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
222 cholmod_sparse *F = CHOLMOD_NAME(transpose) (A, 0, cm);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
223 cholmod_sparse *Aup, *Alo;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
224
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
225 if (A->stype == 1 || coletree)
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
226 {
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
227 Aup = A;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
228 Alo = F;
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
229 }
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
230 else
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
231 {
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
232 Aup = F;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
233 Alo = A;
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
234 }
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
235
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
236 CHOLMOD_NAME(etree) (Aup, Parent, cm);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
237
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
238 ColumnVector tmp (n); // Declaration must precede any goto cleanup.
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
239 std::string err_msg;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
240
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
241 if (cm->status < CHOLMOD_OK)
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
242 {
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
243 err_msg = "symbfact: matrix corrupted";
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
244 goto cleanup;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
245 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
246
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
247 if (CHOLMOD_NAME(postorder) (Parent, n, 0, Post, cm) != n)
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
248 {
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
249 err_msg = "symbfact: postorder failed";
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
250 goto cleanup;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
251 }
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
252
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
253 CHOLMOD_NAME(rowcolcounts) (Alo, 0, 0, Parent, Post, 0,
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
254 ColCount, First, Level, cm);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
255
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
256 if (cm->status < CHOLMOD_OK)
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
257 {
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
258 err_msg = "symbfact: matrix corrupted";
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
259 goto cleanup;
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
260 }
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
261
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
262 if (nargout > 4)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
263 {
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
264 cholmod_sparse *A1, *A2;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
265
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
266 if (A->stype == 1)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
267 {
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
268 A1 = A;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
269 A2 = 0;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
270 }
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
271 else if (A->stype == -1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
272 {
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
273 A1 = F;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
274 A2 = 0;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
275 }
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
276 else if (coletree)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
277 {
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
278 A1 = F;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
279 A2 = A;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
280 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
281 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
282 {
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
283 A1 = A;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
284 A2 = F;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
285 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
286
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
287 // count the total number of entries in L
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
288 octave_idx_type lnz = 0;
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
289 for (octave_idx_type j = 0 ; j < n ; j++)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
290 lnz += ColCount[j];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
291
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
292 // allocate the output matrix L (pattern-only)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
293 SparseBoolMatrix L (n, n, lnz);
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
294
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
295 // initialize column pointers
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
296 lnz = 0;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
297 for (octave_idx_type j = 0 ; j < n ; j++)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
298 {
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
299 L.xcidx(j) = lnz;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
300 lnz += ColCount[j];
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
301 }
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
302 L.xcidx(n) = lnz;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
303
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
304 // create a copy of the column pointers
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
305 octave_idx_type *W = First;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
306 for (octave_idx_type j = 0 ; j < n ; j++)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
307 W[j] = L.xcidx (j);
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
308
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
309 // get workspace for computing one row of L
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
310 cholmod_sparse *R
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
311 = CHOLMOD_NAME(allocate_sparse) (n, 1, n, false, true,
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
312 0, CHOLMOD_PATTERN, cm);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
313 octave_idx_type *Rp = static_cast<octave_idx_type *> (R->p);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
314 octave_idx_type *Ri = static_cast<octave_idx_type *> (R->i);
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
315
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
316 // compute L one row at a time
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
317 for (octave_idx_type k = 0 ; k < n ; k++)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
318 {
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
319 // get the kth row of L and store in the columns of L
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
320 CHOLMOD_NAME(row_subtree) (A1, A2, k, Parent, R, cm);
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
321 for (octave_idx_type p = 0 ; p < Rp[1] ; p++)
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
322 L.xridx (W[Ri[p]]++) = k;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
323
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
324 // add the diagonal entry
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
325 L.xridx (W[k]++) = k;
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
326 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
327
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
328 // free workspace
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
329 CHOLMOD_NAME(free_sparse) (&R, cm);
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
330
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
331 // transpose L to get R, or leave as is
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
332 if (nargin < 3)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
333 L = L.transpose ();
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
334
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
335 // fill numerical values of L with one's
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
336 for (octave_idx_type p = 0 ; p < lnz ; p++)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
337 L.xdata(p) = true;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
338
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
339 retval(4) = L;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
340 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
341
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
342 if (nargout > 3)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
343 {
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
344 for (octave_idx_type i = 0; i < n; i++)
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
345 tmp(i) = Post[i] + 1;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
346 retval(3) = tmp;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
347 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
348
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
349 if (nargout > 2)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
350 {
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
351 for (octave_idx_type i = 0; i < n; i++)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
352 tmp(i) = Parent[i] + 1;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
353 retval(2) = tmp;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
354 }
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
355
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
356 if (nargout > 1)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
357 {
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
358 // compute the elimination tree height
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
359 octave_idx_type height = 0;
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
360 for (int i = 0 ; i < n ; i++)
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
361 height = std::max (height, Level[i]);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
362 height++;
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
363 retval(1) = static_cast<double> (height);
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
364 }
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
365
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
366 for (octave_idx_type i = 0; i < n; i++)
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
367 tmp(i) = ColCount[i];
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
368 retval(0) = tmp;
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20163
diff changeset
369
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
370 cleanup:
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
371 CHOLMOD_NAME(free_sparse) (&F, cm);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
372 CHOLMOD_NAME(finish) (cm);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
373
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
374 if (! err_msg.empty ())
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
375 error (err_msg.c_str ());
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
376
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
377 return retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
378
5512
7c8767d0ffc0 [project @ 2005-10-27 02:20:17 by jwe]
jwe
parents: 5506
diff changeset
379 #else
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
380 err_disabled_feature ("symbfact", "CHOLMOD");
5512
7c8767d0ffc0 [project @ 2005-10-27 02:20:17 by jwe]
jwe
parents: 5506
diff changeset
381 #endif
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents:
diff changeset
382 }
21585
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
383
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
384 /*
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
385 %!testif HAVE_CHOLMOD
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
386 %! A = sparse (magic (3));
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
387 %! [count, h, parent, post, r] = symbfact (A);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
388 %! assert (count, [3; 2; 1]);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
389 %! assert (h, 3);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
390 %! assert (parent, [2; 3; 0]);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
391 %! assert (r, sparse (triu (true (3))));
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
392
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
393 %!testif HAVE_CHOLMOD
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
394 %! ## Test MODE "lower"
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
395 %! A = sparse (magic (3));
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
396 %! [~, ~, ~, ~, l] = symbfact (A, "sym", "lower");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
397 %! assert (l, sparse (tril (true (3))));
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
398
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
399 %!testif HAVE_CHOLMOD
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
400 %! ## Bug #42587, singular matrix
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
401 %! A = sparse ([1 0 8;0 1 8;8 8 1]);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
402 %! [count, h, parent, post, r] = symbfact (A);
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
403
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
404 ## Test input validation
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
405 %!testif HAVE_CHOLMOD
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
406 %! fail ("symbfact ()");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
407 %! fail ("symbfact (1,2,3,4)");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
408 %! fail ("symbfact ({1})", "wrong type argument 'cell'");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
409 %! fail ("symbfact (sparse (1), {1})", "TYP must be a string");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
410 %! fail ("symbfact (sparse (1), 'foobar')", 'unrecognized TYP "foobar"');
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
411 %! fail ("symbfact (sparse (1), 'sym', {'L'})", "MODE must be a string");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
412 %! fail ('symbfact (sparse (1), "sym", "foobar")', 'unrecognized MODE "foobar"');
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
413 %! fail ("symbfact (sparse ([1, 2; 3, 4; 5, 6]))", "S must be a square matrix");
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
414
bad3ed83330d symbfact.cc: Overhaul dldfcn.
Rik <rik@octave.org>
parents: 21547
diff changeset
415 */