Mercurial > octave-nkf
annotate liboctave/util/sparse-util.cc @ 20614:10ec79b47808
use new string_value method to handle value extraction errors
* __voronoi__.cc, chol.cc, colamd.cc, fftw.cc:
Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 18:15:56 -0400 |
parents | a0fab64685ab |
children |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19444
diff
changeset
|
3 Copyright (C) 2005-2015 David Bateman |
11523 | 4 Copyright (C) 1998-2005 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
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 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <stdio.h> | |
29 #include <stdarg.h> | |
30 #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
|
31 #include "oct-sparse.h" |
5506 | 32 #include "sparse-util.h" |
33 | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
34 // FIXME: this overload is here due to API change in SuiteSparse (3.1 -> 3.2) |
15251
50156b22f87c
Don't define SparseCholError if there is no Suitesparse (bug #37134)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15185
diff
changeset
|
35 |
5506 | 36 void |
37 SparseCholError (int status, char *file, int line, char *message) | |
38 { | |
8207
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
39 SparseCholError (status, file, line, message); |
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
40 } |
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
41 |
20318
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
42 #ifdef HAVE_CHOLMOD |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
43 |
8207
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
44 void |
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
45 SparseCholError (int status, const char *file, int line, const char *message) |
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
46 { |
15251
50156b22f87c
Don't define SparseCholError if there is no Suitesparse (bug #37134)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15185
diff
changeset
|
47 |
15185
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
48 // 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
|
49 // 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
|
50 if (status != CHOLMOD_NOT_POSDEF) |
19444
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
51 (*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
|
52 ("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
|
53 status, line, file, message); |
5506 | 54 } |
55 | |
20318
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
56 #else |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
57 |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
58 void |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
59 SparseCholError (int status, const char *, int, const char *) |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
60 { |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
61 } |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
62 |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
63 #endif //HAVE_CHOLMOD |
a0fab64685ab
Avoid HAVE_ macro in header file.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
64 |
5506 | 65 int |
66 SparseCholPrint (const char *fmt, ...) | |
67 { | |
68 va_list args; | |
69 va_start (args, fmt); | |
10411 | 70 int ret = gnulib::vfprintf (stderr, fmt, args); |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
71 gnulib::fflush (stderr); |
5506 | 72 va_end (args); |
73 return ret; | |
74 } | |
75 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
76 bool |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
77 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
|
78 octave_idx_type nrows, octave_idx_type ncols, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
79 octave_idx_type nnz) |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
80 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
81 if (nnz > 0) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
82 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
83 if (c[0] != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
85 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
86 ("invalid sparse matrix: cidx[0] must be zero"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
87 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 } |
9469
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 octave_idx_type jold = 0; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
91 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
92 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
|
93 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
94 if (c[j] < c[j-1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 ("invalid sparse matrix: cidx elements must appear in ascending order"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
99 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
100 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
101 if (c[j] > nnz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 (*current_liboctave_error_handler) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
104 ("invalid sparse matrix: cidx[%d] = %d exceeds number of nonzero elements", |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
105 j, c[j]+1); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
106 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
107 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
108 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
109 if (c[j] != jold) |
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 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
|
112 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
113 if (r[i] < r[i-1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
114 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
116 ("invalid sparse matrix: ridx elements must appear in ascending order for each column"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
117 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
118 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
119 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
120 if (r[i] >= nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
121 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
122 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
123 ("invalid sparse matrix: ridx[%d] = %d out of range", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
124 i, r[i]+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
125 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
126 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
127 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
128 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
129 jold = c[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
130 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
131 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
132 } |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
133 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
134 return true; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
135 } |