GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
sparse-util.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2005-2017 David Bateman
4 Copyright (C) 1998-2005 Andy Adler
5 
6 This file is part of Octave.
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
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
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
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <cstdarg>
29 #include <cstdio>
30 
31 #include "lo-error.h"
32 #include "oct-sparse.h"
33 #include "sparse-util.h"
34 
35 static inline void
36 sparse_chol_error_internal (int status, const char *file,
37  int line, const char *message)
38 {
39 #if defined (HAVE_CHOLMOD)
40 
41  // Ignore CHOLMOD_NOT_POSDEF, since we handle that in Fchol as an
42  // error or exit status.
43  if (status != CHOLMOD_NOT_POSDEF)
44  (*current_liboctave_warning_with_id_handler)
45  ("Octave:cholmod-message", "warning %i, at line %i in file %s: %s",
46  status, line, file, message);
47 
48 #else
49 
50  octave_unused_parameter (status);
51  octave_unused_parameter (file);
52  octave_unused_parameter (line);
53  octave_unused_parameter (message);
54 
55 #endif
56 }
57 
58 // FIXME: this overload is here due to API change in SuiteSparse (3.1 -> 3.2)
59 
60 void
61 SparseCholError (int status, char *file, int line, char *message)
62 {
63  sparse_chol_error_internal (status, file, line, message);
64 }
65 
66 void
67 SparseCholError (int status, const char *file, int line, const char *message)
68 {
69  sparse_chol_error_internal (status, file, line, message);
70 }
71 
72 int
73 SparseCholPrint (const char *fmt, ...)
74 {
75  va_list args;
76  va_start (args, fmt);
77  int ret = std::vfprintf (stderr, fmt, args);
78  std::fflush (stderr);
79  va_end (args);
80  return ret;
81 }
82 
83 bool
85  octave_idx_type nrows, octave_idx_type ncols,
86  octave_idx_type nnz)
87 {
88  if (nnz > 0)
89  {
90  if (c[0] != 0)
91  (*current_liboctave_error_handler)
92  ("invalid sparse matrix: cidx[0] must be zero");
93 
94  octave_idx_type jold = 0;
95 
96  for (octave_idx_type j = 1; j < ncols+1; j++)
97  {
98  if (c[j] < c[j-1])
99  (*current_liboctave_error_handler)
100  ("invalid sparse matrix: cidx elements must appear in ascending order");
101 
102  if (c[j] > nnz)
103  (*current_liboctave_error_handler)
104  ("invalid sparse matrix: cidx[%d] = %d "
105  "exceeds number of nonzero elements", j, c[j]+1);
106 
107  if (c[j] != jold)
108  {
109  for (octave_idx_type i = jold+1; i < c[j]; i++)
110  {
111  if (r[i] < r[i-1])
112  (*current_liboctave_error_handler)
113  ("invalid sparse matrix: ridx elements must appear "
114  "in ascending order for each column");
115 
116  if (r[i] >= nrows)
117  (*current_liboctave_error_handler)
118  ("invalid sparse matrix: ridx[%d] = %d out of range",
119  i, r[i]+1);
120  }
121 
122  jold = c[j];
123  }
124  }
125  }
126 
127  return true;
128 }
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
void SparseCholError(int status, char *file, int line, char *message)
Definition: sparse-util.cc:61
bool sparse_indices_ok(octave_idx_type *r, octave_idx_type *c, octave_idx_type nrows, octave_idx_type ncols, octave_idx_type nnz)
Definition: sparse-util.cc:84
JNIEnv void * args
Definition: ov-java.cc:67
void message(const char *name, const char *fmt,...)
Definition: error.cc:430
static void sparse_chol_error_internal(int status, const char *file, int line, const char *message)
Definition: sparse-util.cc:36
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
int SparseCholPrint(const char *fmt,...)
Definition: sparse-util.cc:73
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
enum echo_state fflush