GNU Octave  4.0.0
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-2015 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 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include "lo-array-gripes.h"
29 #include "lo-error.h"
30 
31 const char *error_id_nonconformant_args = "Octave:nonconformant-args";
32 
33 const char *error_id_index_out_of_bounds = "Octave:index-out-of-bounds";
34 
35 const char *error_id_invalid_index = "Octave:invalid-index";
36 
37 const char *warning_id_nearly_singular_matrix = "Octave:nearly-singular-matrix";
38 
39 const char *warning_id_singular_matrix = "Octave:singular-matrix";
40 
41 void
43 {
44  (*current_liboctave_error_handler)
45  ("invalid conversion from NaN to logical");
46 }
47 
48 void
50 {
51  (*current_liboctave_error_handler)
52  ("invalid conversion from NaN to character");
53 }
54 
55 void
56 gripe_nonconformant (const char *op, octave_idx_type op1_len,
57  octave_idx_type op2_len)
58 {
59  const char *err_id = error_id_nonconformant_args;
60 
61  (*current_liboctave_error_with_id_handler)
62  (err_id, "%s: nonconformant arguments (op1 len: %d, op2 len: %d)",
63  op, op1_len, op2_len);
64 }
65 
66 void
67 gripe_nonconformant (const char *op,
68  octave_idx_type op1_nr, octave_idx_type op1_nc,
69  octave_idx_type op2_nr, octave_idx_type op2_nc)
70 {
71  const char *err_id = error_id_nonconformant_args;
72 
73  (*current_liboctave_error_with_id_handler)
74  (err_id, "%s: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)",
75  op, op1_nr, op1_nc, op2_nr, op2_nc);
76 }
77 
78 void
79 gripe_nonconformant (const char *op, const dim_vector& op1_dims,
80  const dim_vector& op2_dims)
81 {
82  const char *err_id = error_id_nonconformant_args;
83 
84  std::string op1_dims_str = op1_dims.str ();
85  std::string op2_dims_str = op2_dims.str ();
86 
87  (*current_liboctave_error_with_id_handler)
88  (err_id, "%s: nonconformant arguments (op1 is %s, op2 is %s)",
89  op, op1_dims_str.c_str (), op2_dims_str.c_str ());
90 }
91 
92 void
94  octave_idx_type ext)
95 {
96  const char *err_id = error_id_index_out_of_bounds;
97 
98  switch (nd)
99  {
100  case 1:
101  (*current_liboctave_error_with_id_handler)
102  (err_id, "A(I): index out of bounds; value %d out of bound %d",
103  idx, ext);
104  break;
105 
106  case 2:
107  (*current_liboctave_error_with_id_handler)
108  (err_id, "A(I,J): %s index out of bounds; value %d out of bound %d",
109  (dim == 1) ? "row" : "column", idx, ext);
110  break;
111 
112  default:
113  (*current_liboctave_error_with_id_handler)
114  (err_id, "A(I,J,...): index to dimension %d out of bounds; value %d out of bound %d",
115  dim, idx, ext);
116  break;
117  }
118 }
119 
120 void
122  octave_idx_type ext)
123 {
124  const char *err_id = error_id_index_out_of_bounds;
125 
126  (*current_liboctave_error_with_id_handler)
127  (err_id, "A(%s) = []: index out of bounds; value %d out of bound %d",
128  is1d ? "I" : "..,I,..", idx, ext);
129 }
130 
131 void
133 {
134  const char *err_id = error_id_invalid_index;
135 
136  (*current_liboctave_error_with_id_handler)
137 #ifdef USE_64_BIT_IDX_T
138  (err_id, "subscript indices must be either positive integers less than 2^63 or logicals");
139 #else
140  (err_id, "subscript indices must be either positive integers less than 2^31 or logicals");
141 #endif
142 }
143 
144 // FIXME: the following is a common error message to resize,
145 // regardless of whether it's called from assign or elsewhere. It
146 // seems OK to me, but eventually the gripe can be specialized.
147 // Anyway, propagating various error messages into procedure is, IMHO,
148 // a nonsense. If anything, we should change error handling here (and
149 // throughout liboctave) to allow custom handling of errors
150 
151 void
153 {
154  (*current_liboctave_error_with_id_handler)
155  ("Octave:invalid-resize",
156  "Invalid resizing operation or ambiguous assignment to an out-of-bounds array element");
157 }
158 
159 void
161 {
162  (*current_liboctave_error_handler)
163  ("A(I) = X: X must have the same size as I");
164 }
165 
166 void
168 {
169  (*current_liboctave_error_handler)
170  ("A(I,J,...) = X: dimensions mismatch");
171 }
172 
173 void
174 gripe_singular_matrix (double rcond)
175 {
176  if (rcond == 0.0)
177  {
178  (*current_liboctave_warning_with_id_handler)
180  "matrix singular to machine precision");
181  }
182  else
183  {
184  (*current_liboctave_warning_with_id_handler)
186  "matrix singular to machine precision, rcond = %g", rcond);
187  }
188 }
void gripe_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
std::string str(char sep= 'x') const
Definition: dim-vector.cc:63
const char * warning_id_nearly_singular_matrix
void gripe_assignment_dimension_mismatch(void)
void gripe_invalid_index(void)
const char * error_id_nonconformant_args
void gripe_nan_to_logical_conversion(void)
void gripe_invalid_resize(void)
void gripe_nan_to_character_conversion(void)
void gripe_singular_matrix(double rcond)
const char * error_id_index_out_of_bounds
void gripe_invalid_assignment_size(void)
const char * error_id_invalid_index
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)
const char * warning_id_singular_matrix