GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
sparse-util.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2005-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://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 {
64 }
65 
66 void
67 SparseCholError (int status, const char *file, int line, const char *message)
68 {
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:124
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
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
void message(const char *name, const char *fmt,...)
Definition: error.cc:435
static void sparse_chol_error_internal(int status, const char *file, int line, const char *message)
Definition: sparse-util.cc:36
int SparseCholPrint(const char *fmt,...)
Definition: sparse-util.cc:73
for i
Definition: data.cc:5264