Mercurial > hg > octave-nkf
annotate liboctave/util/sparse-util.cc @ 17296:3a9efb68272d ss-3-7-6
snapshot 3.7.6
* configure.ac (OCTAVE_VERSION): Bump to 3.7.6.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Aug 2013 15:17:54 -0400 |
parents | 648dabbb4c6b |
children | d63878346099 |
rev | line source |
---|---|
5506 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12912
diff
changeset
|
3 Copyright (C) 2005-2012 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 | |
8207
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
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 |
50156b22f87c
Don't define SparseCholError if there is no Suitesparse (bug #37134)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15185
diff
changeset
|
36 #ifdef HAVE_CHOLMOD |
50156b22f87c
Don't define SparseCholError if there is no Suitesparse (bug #37134)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15185
diff
changeset
|
37 |
5506 | 38 void |
39 SparseCholError (int status, char *file, int line, char *message) | |
40 { | |
8207
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
41 SparseCholError (status, file, line, message); |
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
42 } |
60b4c75287a1
fix for SuiteSparse 3.2
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
43 |
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) |
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
51 { |
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
52 (*current_liboctave_warning_handler)("warning %i, at line %i in file %s", |
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
53 status, line, file); |
5506 | 54 |
15185
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
55 (*current_liboctave_warning_handler)(message); |
82d51d6e470c
Proceed with the sparse Choleski computation when requested (bug #37095)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
56 } |
5506 | 57 } |
58 | |
59 int | |
60 SparseCholPrint (const char *fmt, ...) | |
61 { | |
62 va_list args; | |
63 va_start (args, fmt); | |
10411 | 64 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
|
65 gnulib::fflush (stderr); |
5506 | 66 va_end (args); |
67 return ret; | |
68 } | |
69 | |
15251
50156b22f87c
Don't define SparseCholError if there is no Suitesparse (bug #37134)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15185
diff
changeset
|
70 #endif //HAVE_CHOLMOD |
5506 | 71 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
72 bool |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
73 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
|
74 octave_idx_type nrows, octave_idx_type ncols, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
75 octave_idx_type nnz) |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
76 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
77 if (nnz > 0) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
78 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
79 if (c[0] != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
80 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
81 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
82 ("invalid sparse matrix: cidx[0] must be zero"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
83 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
85 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
86 octave_idx_type jold = 0; |
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 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
|
89 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 if (c[j] < c[j-1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
92 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 ("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
|
94 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
96 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 if (c[j] > nnz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
99 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
100 ("invalid sparse matrix: cidx[%d] = %d exceeds number of nonzero elements", j, c[j]+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
101 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
103 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
104 if (c[j] != jold) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
105 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
106 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
|
107 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
108 if (r[i] < r[i-1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
109 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
110 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
111 ("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
|
112 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
113 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
114 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 if (r[i] >= nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
116 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
117 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
118 ("invalid sparse matrix: ridx[%d] = %d out of range", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
119 i, r[i]+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
120 return false; |
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 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
123 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
124 jold = c[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
125 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
126 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
127 } |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
128 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
129 return true; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
130 } |