Mercurial > octave
annotate libinterp/corefcn/symbfact.cc @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 7d6709900da7 |
children | 83f9f8bda883 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
3 // Copyright (C) 1998-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
5506 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21229
diff
changeset
|
27 # include "config.h" |
5506 | 28 #endif |
29 | |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
30 #include <cmath> |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
31 |
25050
e376a35f168f
symfact.cc: Fix use of unitialized SparseBoolMatrix (bug #53507).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
32 #include <algorithm> |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
33 #include <string> |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
34 |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
35 #include "CSparse.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
36 #include "boolSparse.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
37 #include "dColVector.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
38 #include "dSparse.h" |
21186
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
39 #include "oct-locbuf.h" |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21145
diff
changeset
|
40 #include "oct-sparse.h" |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
41 #include "oct-spparms.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
42 #include "sparse-util.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7036
diff
changeset
|
43 |
28024
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
44 #include "defun.h" |
5506 | 45 #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
|
46 #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
|
47 #include "ovl.h" |
27859
1a75fca6ad5d
Lock amd and symbfact to avoid segmentation fault with SuiteSparse (bug #57435).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26389
diff
changeset
|
48 #include "parse.h" |
5506 | 49 #include "utils.h" |
50 | |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29872
diff
changeset
|
51 OCTAVE_NAMESPACE_BEGIN |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29872
diff
changeset
|
52 |
28024
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
53 DEFUN (symbfact, args, nargout, |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
54 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
55 @deftypefn {} {[@var{count}, @var{h}, @var{parent}, @var{post}, @var{R}] =} symbfact (@var{S}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
56 @deftypefnx {} {[@dots{}] =} symbfact (@var{S}, @var{typ}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
57 @deftypefnx {} {[@dots{}] =} symbfact (@var{S}, @var{typ}, @var{mode}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
58 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
59 Perform a symbolic factorization analysis of the sparse matrix @var{S}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
60 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
61 The input variables are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
62 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
63 @table @var |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
64 @item S |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
65 @var{S} is a real or complex sparse matrix. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
66 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
67 @item typ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
68 Is the type of the factorization and can be one of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
69 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
70 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
71 @item @qcode{"sym"} (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
72 Factorize @var{S}. Assumes @var{S} is symmetric and uses the upper |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
73 triangular portion of the matrix. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
74 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
75 @item @qcode{"col"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
76 Factorize @tcode{@var{S}' * @var{S}}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
77 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
78 @item @qcode{"row"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
79 Factorize @tcode{@var{S} * @var{S}'}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
80 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
81 @item @qcode{"lo"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
82 Factorize @tcode{@var{S}'}. Assumes @var{S} is symmetric and uses the lower |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
83 triangular portion of the matrix. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
84 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
85 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
86 @item mode |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
87 When @var{mode} is unspecified return the Cholesky@tie{}factorization for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
88 @var{R}. If @var{mode} is @qcode{"lower"} or @qcode{"L"} then return |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
89 the conjugate transpose @tcode{@var{R}'} which is a lower triangular factor. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
90 The conjugate transpose version is faster and uses less memory, but still |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
91 returns the same values for all other outputs: @var{count}, @var{h}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
92 @var{parent}, and @var{post}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
93 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
94 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
95 The output variables are: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
96 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
97 @table @var |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
98 @item count |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
99 The row counts of the Cholesky@tie{}factorization as determined by |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
100 @var{typ}. The computational difficulty of performing the true |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
101 factorization using @code{chol} is @code{sum (@var{count} .^ 2)}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
102 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
103 @item h |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
104 The height of the elimination tree. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
105 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
106 @item parent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
107 The elimination tree itself. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
108 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
109 @item post |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
110 A sparse boolean matrix whose structure is that of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
111 Cholesky@tie{}factorization as determined by @var{typ}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
112 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
113 @seealso{chol, etree, treelayout} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21937
diff
changeset
|
114 @end deftypefn */) |
5506 | 115 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
116 #if defined (HAVE_CHOLMOD) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
117 |
5506 | 118 int nargin = args.length (); |
119 | |
21585 | 120 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
|
121 print_usage (); |
5506 | 122 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
123 octave_value_list retval; |
21604
d7a268e68e69
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21585
diff
changeset
|
124 |
5506 | 125 double dummy; |
126 cholmod_sparse Astore; | |
127 cholmod_sparse *A = &Astore; | |
5527 | 128 A->packed = true; |
129 A->sorted = true; | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
130 A->nz = nullptr; |
21229
a83e7a384ee0
create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
131 #if defined (OCTAVE_ENABLE_64) |
5506 | 132 A->itype = CHOLMOD_LONG; |
133 #else | |
134 A->itype = CHOLMOD_INT; | |
135 #endif | |
136 A->dtype = CHOLMOD_DOUBLE; | |
137 A->stype = 1; | |
138 A->x = &dummy; | |
139 | |
29390
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
140 SparseMatrix sm; |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
141 SparseComplexMatrix scm; |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
142 |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
143 if (args(0).isreal ()) |
5506 | 144 { |
29390
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
145 sm = args(0).sparse_matrix_value (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
146 A->nrow = sm.rows (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
147 A->ncol = sm.cols (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
148 A->p = sm.cidx (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
149 A->i = sm.ridx (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
150 A->nzmax = sm.nnz (); |
5506 | 151 A->xtype = CHOLMOD_REAL; |
152 | |
29390
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
153 if (A->nrow > 0 && A->ncol > 0) |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
154 A->x = sm.data (); |
5506 | 155 } |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
156 else if (args(0).iscomplex ()) |
5506 | 157 { |
29390
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
158 scm = args(0).sparse_complex_matrix_value (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
159 A->nrow = scm.rows (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
160 A->ncol = scm.cols (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
161 A->p = scm.cidx (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
162 A->i = scm.ridx (); |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
163 A->nzmax = scm.nnz (); |
5506 | 164 A->xtype = CHOLMOD_COMPLEX; |
165 | |
29390
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
166 if (A->nrow > 0 && A->ncol > 0) |
1f9e755bd91e
Fix occasional segfault in symbfact (bug #60101).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
167 A->x = scm.data (); |
5506 | 168 } |
169 else | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
170 err_wrong_type_arg ("symbfact", args(0)); |
5506 | 171 |
26389
d0a061e6d70f
symbfact.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
172 bool coletree = false; |
5506 | 173 octave_idx_type n = A->nrow; |
174 | |
175 if (nargin > 1) | |
176 { | |
21585 | 177 std::string str = args(1).xstring_value ("TYP must be a string"); |
178 // FIXME: The input validation could be improved to use strncmp | |
5506 | 179 char ch; |
21585 | 180 ch = tolower (str[0]); |
181 if (ch == 'r') // 'row' | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
182 A->stype = 0; |
21585 | 183 else if (ch == 'c') // 'col' |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
184 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
185 n = A->ncol; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
186 coletree = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
187 A->stype = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
188 } |
21585 | 189 else if (ch == 's') // 'sym' (default) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
190 A->stype = 1; |
21585 | 191 else if (ch == 'l') // 'lo' |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
192 A->stype = -1; |
5506 | 193 else |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
194 error (R"(symbfact: unrecognized TYP "%s")", str.c_str ()); |
21585 | 195 } |
196 | |
197 if (nargin == 3) | |
198 { | |
199 std::string str = args(2).xstring_value ("MODE must be a string"); | |
200 // FIXME: The input validation could be improved to use strncmp | |
201 char ch; | |
202 ch = toupper (str[0]); | |
203 if (ch != 'L') | |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
204 error (R"(symbfact: unrecognized MODE "%s")", str.c_str ()); |
5506 | 205 } |
206 | |
207 if (A->stype && A->nrow != A->ncol) | |
21110
3d0d84305600
Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
208 err_square_matrix_required ("symbfact", "S"); |
5506 | 209 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
210 OCTAVE_LOCAL_BUFFER (suitesparse_integer, Parent, n); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
211 OCTAVE_LOCAL_BUFFER (suitesparse_integer, Post, n); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
212 OCTAVE_LOCAL_BUFFER (suitesparse_integer, ColCount, n); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
213 OCTAVE_LOCAL_BUFFER (suitesparse_integer, First, n); |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
214 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
|
215 |
21585 | 216 cholmod_common Common; |
217 cholmod_common *cm = &Common; | |
218 CHOLMOD_NAME(start) (cm); | |
219 | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
220 double spu = sparse_params::get_key ("spumoni"); |
26389
d0a061e6d70f
symbfact.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
221 if (spu == 0.0) |
21585 | 222 { |
223 cm->print = -1; | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
224 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, nullptr); |
21585 | 225 } |
226 else | |
227 { | |
228 cm->print = static_cast<int> (spu) + 2; | |
229 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint); | |
230 } | |
231 | |
232 cm->error_handler = &SparseCholError; | |
233 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide, divcomplex); | |
234 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot); | |
235 | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
236 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
|
237 cholmod_sparse *Aup, *Alo; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
238 |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
239 if (A->stype == 1 || coletree) |
5506 | 240 { |
21585 | 241 Aup = A; |
242 Alo = F; | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
243 } |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
244 else |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
245 { |
21585 | 246 Aup = F; |
247 Alo = A; | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
248 } |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
249 |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
250 CHOLMOD_NAME(etree) (Aup, Parent, cm); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
251 |
21585 | 252 ColumnVector tmp (n); // Declaration must precede any goto cleanup. |
253 std::string err_msg; | |
254 | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
255 if (cm->status < CHOLMOD_OK) |
21585 | 256 { |
257 err_msg = "symbfact: matrix corrupted"; | |
258 goto cleanup; | |
259 } | |
5506 | 260 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
261 if (CHOLMOD_NAME(postorder) (Parent, n, nullptr, Post, cm) != n) |
21585 | 262 { |
263 err_msg = "symbfact: postorder failed"; | |
264 goto cleanup; | |
265 } | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
266 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
267 CHOLMOD_NAME(rowcolcounts) (Alo, nullptr, 0, Parent, Post, nullptr, ColCount, |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
268 First, to_suitesparse_intptr (Level), cm); |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
269 |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
270 if (cm->status < CHOLMOD_OK) |
21585 | 271 { |
272 err_msg = "symbfact: matrix corrupted"; | |
273 goto cleanup; | |
274 } | |
20667
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 if (nargout > 4) |
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 cholmod_sparse *A1, *A2; |
5506 | 279 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
280 if (A->stype == 1) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
281 { |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
282 A1 = A; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
283 A2 = nullptr; |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
284 } |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
285 else if (A->stype == -1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
286 { |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
287 A1 = F; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
288 A2 = nullptr; |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
289 } |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
290 else if (coletree) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
291 { |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
292 A1 = F; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
293 A2 = A; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
294 } |
5506 | 295 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
296 { |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
297 A1 = A; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
298 A2 = F; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
299 } |
5506 | 300 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
301 // count the total number of entries in L |
21585 | 302 octave_idx_type lnz = 0; |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
303 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
|
304 lnz += ColCount[j]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
305 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
306 // allocate the output matrix L (pattern-only) |
25050
e376a35f168f
symfact.cc: Fix use of unitialized SparseBoolMatrix (bug #53507).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
307 SparseBoolMatrix L (dim_vector (n, n), lnz); |
5506 | 308 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
309 // initialize column pointers |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
310 lnz = 0; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
311 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
|
312 { |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
313 L.xcidx(j) = lnz; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
314 lnz += ColCount[j]; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
315 } |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
316 L.xcidx(n) = lnz; |
5506 | 317 |
20946 | 318 // create a copy of the column pointers |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
319 suitesparse_integer *W = First; |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
320 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
|
321 W[j] = L.xcidx (j); |
5506 | 322 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
323 // 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
|
324 cholmod_sparse *R |
21585 | 325 = CHOLMOD_NAME(allocate_sparse) (n, 1, n, false, true, |
326 0, CHOLMOD_PATTERN, cm); | |
327 octave_idx_type *Rp = static_cast<octave_idx_type *> (R->p); | |
328 octave_idx_type *Ri = static_cast<octave_idx_type *> (R->i); | |
5506 | 329 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
330 // compute L one row at a time |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
331 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
|
332 { |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
333 // get the kth row of L and store in the columns of L |
21585 | 334 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
|
335 for (octave_idx_type p = 0 ; p < Rp[1] ; p++) |
21585 | 336 L.xridx (W[Ri[p]]++) = k; |
5506 | 337 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
338 // add the diagonal entry |
21585 | 339 L.xridx (W[k]++) = k; |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
340 } |
5506 | 341 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
342 // free workspace |
21585 | 343 CHOLMOD_NAME(free_sparse) (&R, cm); |
5506 | 344 |
25050
e376a35f168f
symfact.cc: Fix use of unitialized SparseBoolMatrix (bug #53507).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
345 // fill L with one's |
e376a35f168f
symfact.cc: Fix use of unitialized SparseBoolMatrix (bug #53507).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
346 std::fill_n (L.xdata (), lnz, true); |
e376a35f168f
symfact.cc: Fix use of unitialized SparseBoolMatrix (bug #53507).
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
347 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
348 // 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
|
349 if (nargin < 3) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
350 L = L.transpose (); |
5506 | 351 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
352 retval(4) = L; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
353 } |
5506 | 354 |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
355 if (nargout > 3) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
356 { |
5506 | 357 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
|
358 tmp(i) = Post[i] + 1; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
359 retval(3) = tmp; |
5506 | 360 } |
361 | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
362 if (nargout > 2) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
363 { |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
364 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
|
365 tmp(i) = Parent[i] + 1; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
366 retval(2) = tmp; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
367 } |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
368 |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
369 if (nargout > 1) |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
370 { |
20946 | 371 // compute the elimination tree height |
21585 | 372 octave_idx_type height = 0; |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
373 for (int i = 0 ; i < n ; i++) |
21585 | 374 height = std::max (height, Level[i]); |
375 height++; | |
20667
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
376 retval(1) = static_cast<double> (height); |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
377 } |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
378 |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
379 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
|
380 tmp(i) = ColCount[i]; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
381 retval(0) = tmp; |
8742e0b1cc49
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20163
diff
changeset
|
382 |
21585 | 383 cleanup: |
384 CHOLMOD_NAME(free_sparse) (&F, cm); | |
385 CHOLMOD_NAME(finish) (cm); | |
386 | |
387 if (! err_msg.empty ()) | |
26149
242aa7b2c783
Silence unnecessary warnings about security-format (bug #55046).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
388 error ("%s", err_msg.c_str ()); |
21585 | 389 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
390 return retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
391 |
5512 | 392 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
393 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
394 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
395 octave_unused_parameter (nargout); |
21937
55f7de37b618
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
396 |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
397 err_disabled_feature ("symbfact", "CHOLMOD"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
398 |
5512 | 399 #endif |
5506 | 400 } |
21585 | 401 |
402 /* | |
403 %!testif HAVE_CHOLMOD | |
404 %! A = sparse (magic (3)); | |
405 %! [count, h, parent, post, r] = symbfact (A); | |
406 %! assert (count, [3; 2; 1]); | |
407 %! assert (h, 3); | |
408 %! assert (parent, [2; 3; 0]); | |
409 %! assert (r, sparse (triu (true (3)))); | |
410 | |
411 %!testif HAVE_CHOLMOD | |
412 %! ## Test MODE "lower" | |
413 %! A = sparse (magic (3)); | |
414 %! [~, ~, ~, ~, l] = symbfact (A, "sym", "lower"); | |
415 %! assert (l, sparse (tril (true (3)))); | |
416 | |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
417 %!testif HAVE_CHOLMOD <*42587> |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
418 %! ## singular matrix |
21585 | 419 %! A = sparse ([1 0 8;0 1 8;8 8 1]); |
420 %! [count, h, parent, post, r] = symbfact (A); | |
421 | |
422 ## Test input validation | |
423 %!testif HAVE_CHOLMOD | |
424 %! fail ("symbfact ()"); | |
425 %! fail ("symbfact (1,2,3,4)"); | |
426 %! fail ("symbfact ({1})", "wrong type argument 'cell'"); | |
427 %! fail ("symbfact (sparse (1), {1})", "TYP must be a string"); | |
21604
d7a268e68e69
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21585
diff
changeset
|
428 %! fail ("symbfact (sparse (1), 'foobar')", 'unrecognized TYP "foobar"'); |
21585 | 429 %! fail ("symbfact (sparse (1), 'sym', {'L'})", "MODE must be a string"); |
21604
d7a268e68e69
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21585
diff
changeset
|
430 %! fail ('symbfact (sparse (1), "sym", "foobar")', 'unrecognized MODE "foobar"'); |
21585 | 431 %! fail ("symbfact (sparse ([1, 2; 3, 4; 5, 6]))", "S must be a square matrix"); |
432 | |
433 */ | |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29872
diff
changeset
|
434 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29872
diff
changeset
|
435 OCTAVE_NAMESPACE_END |