Mercurial > octave
annotate liboctave/util/sparse-util.cc @ 23219:3ac9f9ecfae5 stable
maint: Update copyright dates.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:39:29 -0500 |
parents | e9a0469dedd9 |
children | 092078913d54 |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2005-2017 David Bateman |
11523 | 4 Copyright (C) 1998-2005 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5506 | 7 |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5506 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5506 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
25 # include "config.h" |
5506 | 26 #endif |
27 | |
21912
d92dcbcd7691
prefer C++ wrappers for C standard headers in C++ code
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
28 #include <cstdarg> |
d92dcbcd7691
prefer C++ wrappers for C standard headers in C++ code
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
29 #include <cstdio> |
d92dcbcd7691
prefer C++ wrappers for C standard headers in C++ code
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
30 |
5506 | 31 #include "lo-error.h" |
15185
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
32 #include "oct-sparse.h" |
5506 | 33 #include "sparse-util.h" |
34 | |
21342
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
35 static inline void |
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
36 sparse_chol_error_internal (int status, const char *file, |
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
37 int line, const char *message) |
5506 | 38 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
39 #if defined (HAVE_CHOLMOD) |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
40 |
15185
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
41 // Ignore CHOLMOD_NOT_POSDEF, since we handle that in Fchol as an |
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
42 // error or exit status. |
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
43 if (status != CHOLMOD_NOT_POSDEF) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
44 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
45 ("Octave:cholmod-message", "warning %i, at line %i in file %s: %s", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
46 status, line, file, message); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
47 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
48 #else |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
49 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
50 octave_unused_parameter (status); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
51 octave_unused_parameter (file); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
52 octave_unused_parameter (line); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
53 octave_unused_parameter (message); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21342
diff
changeset
|
54 |
21342
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
55 #endif |
5506 | 56 } |
57 | |
21342
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
58 // FIXME: this overload is here due to API change in SuiteSparse (3.1 -> 3.2) |
20283
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
59 |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
60 void |
21342
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
61 SparseCholError (int status, char *file, int line, char *message) |
20283
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
62 { |
21342
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
63 sparse_chol_error_internal (status, file, line, message); |
20283
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
64 } |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
65 |
21342
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
66 void |
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
67 SparseCholError (int status, const char *file, int line, const char *message) |
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
68 { |
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
69 sparse_chol_error_internal (status, file, line, message); |
798273bbe551
avoid infinite recursion in SparseCholError
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
70 } |
20283
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
71 |
5506 | 72 int |
73 SparseCholPrint (const char *fmt, ...) | |
74 { | |
75 va_list args; | |
76 va_start (args, fmt); | |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21912
diff
changeset
|
77 int ret = std::vfprintf (stderr, fmt, args); |
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21912
diff
changeset
|
78 std::fflush (stderr); |
5506 | 79 va_end (args); |
80 return ret; | |
81 } | |
82 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
83 bool |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
84 sparse_indices_ok (octave_idx_type *r, octave_idx_type *c, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
85 octave_idx_type nrows, octave_idx_type ncols, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
86 octave_idx_type nnz) |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
87 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
88 if (nnz > 0) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
89 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
90 if (c[0] != 0) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
91 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
92 ("invalid sparse matrix: cidx[0] must be zero"); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
93 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
94 octave_idx_type jold = 0; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
95 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
96 for (octave_idx_type j = 1; j < ncols+1; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 if (c[j] < c[j-1]) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
99 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
100 ("invalid sparse matrix: cidx elements must appear in ascending order"); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
101 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 if (c[j] > nnz) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
103 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
104 ("invalid sparse matrix: cidx[%d] = %d " |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
105 "exceeds number of nonzero elements", j, c[j]+1); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
106 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
107 if (c[j] != jold) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
108 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
109 for (octave_idx_type i = jold+1; i < c[j]; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
110 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
111 if (r[i] < r[i-1]) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
112 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
113 ("invalid sparse matrix: ridx elements must appear " |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
114 "in ascending order for each column"); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
115 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
116 if (r[i] >= nrows) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
117 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
118 ("invalid sparse matrix: ridx[%d] = %d out of range", |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
119 i, r[i]+1); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
120 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
121 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
122 jold = c[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
123 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
124 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
125 } |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
126 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
127 return true; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
128 } |