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
lo-array-gripes.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2003-2017 John W. Eaton
4 Copyright (C) 2009 VZLU Prague
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 // FIXME: All gripe_XXX functions deprecated in 4.2. Remove file in 4.6
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <sstream>
31 
32 #include "lo-array-gripes.h"
33 #include "lo-error.h"
34 
35 // Text constants used to shorten code below.
36 static const char *error_id_nonconformant_args = "Octave:nonconformant-args";
37 
38 static const char *error_id_index_out_of_bounds = "Octave:index-out-of-bounds";
39 
40 static const char *error_id_invalid_index = "Octave:invalid-index";
41 
43  "Octave:nearly-singular-matrix";
44 
45 static const char *warning_id_singular_matrix = "Octave:singular-matrix";
46 
47 void
49 {
50  (*current_liboctave_error_handler)
51  ("invalid conversion from NaN to logical");
52 }
53 
54 void
56 {
57  (*current_liboctave_error_handler)
58  ("invalid conversion from NaN to character");
59 }
60 
61 void
62 gripe_nonconformant (const char *op, octave_idx_type op1_len,
63  octave_idx_type op2_len)
64 {
65  const char *err_id = error_id_nonconformant_args;
66 
67  (*current_liboctave_error_with_id_handler)
68  (err_id, "%s: nonconformant arguments (op1 len: %d, op2 len: %d)",
69  op, op1_len, op2_len);
70 }
71 
72 void
73 gripe_nonconformant (const char *op,
74  octave_idx_type op1_nr, octave_idx_type op1_nc,
75  octave_idx_type op2_nr, octave_idx_type op2_nc)
76 {
77  const char *err_id = error_id_nonconformant_args;
78 
79  (*current_liboctave_error_with_id_handler)
80  (err_id, "%s: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)",
81  op, op1_nr, op1_nc, op2_nr, op2_nc);
82 }
83 
84 void
85 gripe_nonconformant (const char *op, const dim_vector& op1_dims,
86  const dim_vector& op2_dims)
87 {
88  const char *err_id = error_id_nonconformant_args;
89 
90  std::string op1_dims_str = op1_dims.str ();
91  std::string op2_dims_str = op2_dims.str ();
92 
93  (*current_liboctave_error_with_id_handler)
94  (err_id, "%s: nonconformant arguments (op1 is %s, op2 is %s)",
95  op, op1_dims_str.c_str (), op2_dims_str.c_str ());
96 }
97 
98 void
100  octave_idx_type ext)
101 {
102  const char *err_id = error_id_index_out_of_bounds;
103 
104  (*current_liboctave_error_with_id_handler)
105  (err_id, "A(%s) = []: index out of bounds: value %d out of bound %d",
106  is1d ? "I" : "..,I,..", idx, ext);
107 }
108 
109 namespace octave
110 {
111  class invalid_index : public index_exception
112  {
113  public:
114 
116  octave_idx_type dimen)
117  : index_exception (value, ndim, dimen)
118  { }
119 
120  std::string details (void) const
121  {
122 #if defined (OCTAVE_ENABLE_64)
123  return "subscripts must be either integers 1 to (2^63)-1 or logicals";
124 #else
125  return "subscripts must be either integers 1 to (2^31)-1 or logicals";
126 #endif
127  }
128 
129  // ID of error to throw
130  const char *err_id (void) const
131  {
132  return error_id_invalid_index;
133  }
134  };
135 }
136 
137 // Complain if an index is negative, fractional, or too big.
138 
139 void
141  octave_idx_type dim, const std::string&)
142 {
143  octave::invalid_index e (idx, nd, dim);
144 
145  throw e;
146 }
147 
148 void
150  octave_idx_type dim, const std::string& var)
151 {
152  std::ostringstream buf;
153  buf << n + 1;
154 
155 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
156 # pragma GCC diagnostic push
157 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
158 #endif
159 
160  gripe_invalid_index (buf.str (), nd, dim, var);
161 
162 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
163 # pragma GCC diagnostic pop
164 #endif
165 }
166 
167 void
169  const std::string& var)
170 {
171  std::ostringstream buf;
172  buf << n + 1;
173 
174 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
175 # pragma GCC diagnostic push
176 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
177 #endif
178 
179  gripe_invalid_index (buf.str (), nd, dim, var);
180 
181 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
182 # pragma GCC diagnostic pop
183 #endif
184 }
185 
186 namespace octave
187 {
188  // Gripe and exception for read access beyond the bounds of an array.
189 
190  class out_of_range : public index_exception
191  {
192  public:
193 
195  octave_idx_type dim_in)
196  : index_exception (value, nd_in, dim_in), extent (0)
197  { }
198 
199  std::string details (void) const
200  {
201  std::string expl;
202 
203  if (nd >= size.ndims ()) // if not an index slice
204  {
205  if (var != "")
206  expl = "but " + var + " has size ";
207  else
208  expl = "but object has size ";
209 
210  expl = expl + size.str ('x');
211  }
212  else
213  {
214  std::ostringstream buf;
215  buf << extent;
216  expl = "out of bound " + buf.str ();
217  }
218 
219  return expl;
220  }
221 
222  // ID of error to throw.
223  const char *err_id (void) const
224  {
226  }
227 
228  void set_size (const dim_vector& size_in) { size = size_in; }
229 
230  void set_extent (octave_idx_type ext) { extent = ext; }
231 
232  private:
233 
234  // Dimension of object being accessed.
236 
237  // Length of dimension being accessed.
239  };
240 }
241 
242 // Complain of an index that is out of range, but we don't know matrix size
243 void
245  octave_idx_type ext)
246 {
247  std::ostringstream buf;
248  buf << idx;
249  octave::out_of_range e (buf.str (), nd, dim);
250 
251  e.set_extent (ext);
252  // ??? Make details method give extent not size.
253  e.set_size (dim_vector (1, 1, 1, 1, 1, 1,1));
254 
255  throw e;
256 }
257 
258 // Complain of an index that is out of range
259 void
261  octave_idx_type ext, const dim_vector& d)
262 {
263  std::ostringstream buf;
264  buf << idx;
265  octave::out_of_range e (buf.str (), nd, dim);
266 
267  e.set_extent (ext);
268  e.set_size (d);
269 
270  throw e;
271 }
272 
273 void
275 {
276  (*current_liboctave_error_with_id_handler)
277  ("Octave:invalid-resize",
278  "Invalid resizing operation or ambiguous assignment to an out-of-bounds array element");
279 }
280 
281 void
282 gripe_singular_matrix (double rcond)
283 {
284  if (rcond == 0.0)
285  {
286  (*current_liboctave_warning_with_id_handler)
288  "matrix singular to machine precision");
289  }
290  else
291  {
292  (*current_liboctave_warning_with_id_handler)
294  "matrix singular to machine precision, rcond = %g", rcond);
295  }
296 }
297 
298 /* Tests in test/index.tst */
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
void gripe_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
out_of_range(const std::string &value, octave_idx_type nd_in, octave_idx_type dim_in)
std::string str(char sep= 'x') const
Definition: dim-vector.cc:73
in that an updated permutation matrix is returned Note that if var
Definition: lu.cc:606
void set_size(const dim_vector &size_in)
static const char * warning_id_nearly_singular_matrix
i e
Definition: data.cc:2724
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
static const char * error_id_nonconformant_args
void gripe_nan_to_logical_conversion(void)
octave_idx_type extent
void set_extent(octave_idx_type ext)
void gripe_invalid_resize(void)
void gripe_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
invalid_index(const std::string &value, octave_idx_type ndim, octave_idx_type dimen)
void gripe_nan_to_character_conversion(void)
void gripe_singular_matrix(double rcond)
static const char * error_id_index_out_of_bounds
const char * err_id(void) const
std::string details(void) const
const char * err_id(void) const
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
std::string details(void) const
static const char * error_id_invalid_index
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
void gripe_index_out_of_range(int nd, int dim, octave_idx_type idx, octave_idx_type ext)
void gripe_del_index_out_of_range(bool is1d, octave_idx_type idx, octave_idx_type ext)
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
static const char * warning_id_singular_matrix