Mercurial > hg > octave-lyh
changeset 11130:7c573eb981eb
consistently give error for operator not applied to NaN values
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Oct 2010 16:12:13 -0400 |
parents | 0de5cc44e690 |
children | 953bb56af598 |
files | liboctave/Array-util.cc liboctave/Array-util.h liboctave/CMatrix.cc liboctave/CNDArray.cc liboctave/CSparse.cc liboctave/ChangeLog liboctave/Makefile.am liboctave/dMatrix.cc liboctave/dNDArray.cc liboctave/dSparse.cc liboctave/fCMatrix.cc liboctave/fCNDArray.cc liboctave/fMatrix.cc liboctave/fNDArray.cc src/ChangeLog src/gripes.h |
diffstat | 16 files changed, 60 insertions(+), 169 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array-util.cc +++ b/liboctave/Array-util.cc @@ -651,136 +651,3 @@ return pva->pidx > pvb->pidx; } - -const char *error_id_nonconformant_args = "Octave:nonconformant-args"; - -const char *error_id_index_out_of_bounds = "Octave:index-out-of-bounds"; - -const char *error_id_invalid_index = "Octave:invalid-index"; - -void -gripe_nan_to_logical_conversion (void) -{ - (*current_liboctave_error_handler) - ("invalid conversion from NaN to logical"); -} - -void -gripe_nan_to_character_conversion (void) -{ - (*current_liboctave_error_handler) - ("invalid conversion from NaN to character"); -} - -void -gripe_nonconformant (const char *op, int op1_len, int op2_len) -{ - const char *err_id = error_id_nonconformant_args; - - (*current_liboctave_error_with_id_handler) - (err_id, "%s: nonconformant arguments (op1 len: %d, op2 len: %d)", - op, op1_len, op2_len); -} - -void -gripe_nonconformant (const char *op, int op1_nr, int op1_nc, - int op2_nr, int op2_nc) -{ - const char *err_id = error_id_nonconformant_args; - - (*current_liboctave_error_with_id_handler) - (err_id, "%s: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)", - op, op1_nr, op1_nc, op2_nr, op2_nc); -} - -void -gripe_nonconformant (const char *op, const dim_vector& op1_dims, - const dim_vector& op2_dims) -{ - const char *err_id = error_id_nonconformant_args; - - std::string op1_dims_str = op1_dims.str (); - std::string op2_dims_str = op2_dims.str (); - - (*current_liboctave_error_with_id_handler) - (err_id, "%s: nonconformant arguments (op1 is %s, op2 is %s)", - op, op1_dims_str.c_str (), op2_dims_str.c_str ()); -} - -void -gripe_index_out_of_range (int nd, int dim, octave_idx_type idx, - octave_idx_type ext) -{ - const char *err_id = error_id_index_out_of_bounds; - - switch (nd) - { - case 1: - (*current_liboctave_error_with_id_handler) - (err_id, "A(I): index out of bounds; value %d out of bound %d", - idx, ext); - break; - - case 2: - (*current_liboctave_error_with_id_handler) - (err_id, "A(I,J): %s index out of bounds; value %d out of bound %d", - (dim == 1) ? "row" : "column", idx, ext); - break; - - default: - (*current_liboctave_error_with_id_handler) - (err_id, "A(I,J,...): index to dimension %d out of bounds; value %d out of bound %d", - dim, idx, ext); - break; - } -} - -void -gripe_del_index_out_of_range (bool is1d, octave_idx_type idx, - octave_idx_type ext) -{ - const char *err_id = error_id_index_out_of_bounds; - - (*current_liboctave_error_with_id_handler) - (err_id, "A(%s) = []: index out of bounds; value %d out of bound %d", - is1d ? "I" : "..,I,..", idx, ext); -} - -void -gripe_invalid_index (void) -{ - const char *err_id = error_id_invalid_index; - - (*current_liboctave_error_with_id_handler) - (err_id, "subscript indices must be either positive integers or logicals."); -} - -// FIXME -- the following is a common error message to resize, -// regardless of whether it's called from assign or elsewhere. It -// seems OK to me, but eventually the gripe can be specialized. -// Anyway, propagating various error messages into procedure is, IMHO, -// a nonsense. If anything, we should change error handling here (and -// throughout liboctave) to allow custom handling of errors - -void -gripe_invalid_resize (void) -{ - (*current_liboctave_error_with_id_handler) - ("Octave:invalid-resize", - "Invalid resizing operation or ambiguous assignment to an out-of-bounds array element."); -} - -void -gripe_invalid_assignment_size (void) -{ - (*current_liboctave_error_handler) - ("A(I) = X: X must have the same size as I"); -} - -void -gripe_assignment_dimension_mismatch (void) -{ - (*current_liboctave_error_handler) - ("A(I,J,...) = X: dimensions mismatch"); -} -
--- a/liboctave/Array-util.h +++ b/liboctave/Array-util.h @@ -23,12 +23,10 @@ #if !defined (octave_Array_util_h) #define octave_Array_util_h 1 -#include <cassert> - #include "Array.h" #include "dim-vector.h" #include "idx-vector.h" -#include "lo-error.h" +#include "lo-array-gripes.h" extern OCTAVE_API bool index_in_bounds (const Array<octave_idx_type>& ra_idx, const dim_vector& dimensions); @@ -104,37 +102,4 @@ extern int OCTAVE_API permute_vector_compare (const void *a, const void *b); -extern OCTAVE_API const char *error_id_nonconformant_args; - -extern OCTAVE_API const char *error_id_index_out_of_bounds; - -extern OCTAVE_API const char *error_id_invalid_index; - -extern void OCTAVE_API gripe_nan_to_logical_conversion (void); - -extern void OCTAVE_API gripe_nan_to_character_conversion (void); - -extern void OCTAVE_API gripe_nonconformant (const char *op, int op1_len, int op2_len); - -extern void OCTAVE_API gripe_nonconformant (const char *op, int op1_nr, int op1_nc, - int op2_nr, int op2_nc); - - -extern void OCTAVE_API gripe_nonconformant (const char *op, const dim_vector& op1_dims, - const dim_vector& op2_dims); - -extern void OCTAVE_API gripe_index_out_of_range (int nd, int dim, - octave_idx_type iext, octave_idx_type ext); - -extern void OCTAVE_API gripe_del_index_out_of_range (bool is1d, octave_idx_type iext, - octave_idx_type ext); - -extern void OCTAVE_API gripe_invalid_index (void); - -extern void OCTAVE_API gripe_invalid_resize (void); - -extern void OCTAVE_API gripe_invalid_assignment_size (void); - -extern void OCTAVE_API gripe_assignment_dimension_mismatch (void); - #endif
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -3044,6 +3044,9 @@ boolMatrix ComplexMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, Complex> (*this, mx_inline_not); }
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -500,6 +500,9 @@ boolNDArray ComplexNDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, Complex> (*this, mx_inline_not); }
--- a/liboctave/CSparse.cc +++ b/liboctave/CSparse.cc @@ -7145,6 +7145,9 @@ SparseBoolMatrix SparseComplexMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + octave_idx_type nr = rows (); octave_idx_type nc = cols (); octave_idx_type nz1 = nnz ();
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,24 @@ +2010-10-21 John W. Eaton <jwe@octave.org> + + * Makefile.am (INCS): Include lo-array-gripes.h in the list. + (LIBOCTAVE_CXX_SOURCES): Include lo-array-gripes.cc in the list. + + * lo-array-gripes.h: New file. Move gripe function decls here + from Array-util.h. + * lo-array-gripes.c: New file. Move gripe function definitions + here from Array-util.cc. + + * CMatrix.cc (ComplexMatrix::operator !): Gripe if any element is NaN. + * CNDArray.cc (ComplexNDArray::operator !): Likewise. + * CSparse.cc (SparseComplexMatrix::operator !): Likewise. + * dMatrix.cc (Matrix::operator !): Likewise. + * dNDArray.cc (NDArray::operator !): Likewise. + * dSparse.cc (SparseMatrix::operator !): Likewise. + * fCMatrix.cc (FloatComplexMatrix::operator !): Likewise. + * fCNDArray.cc (FloatComplexNDArray::operator !): Likewise. + * fMatrix.cc (FloatMatrix::operator !): Likewise. + * fNDArray.cc (FloatNDArray::operator !): Likewise. + 2010-10-21 John W. Eaton <jwe@octave.org> * Array-util.cc (gripe_nan_to_character_conversion): New function.
--- a/liboctave/Makefile.am +++ b/liboctave/Makefile.am @@ -202,6 +202,7 @@ glob-match.h \ idx-vector.h \ kpse-xfns.h \ + lo-array-gripes.h \ lo-ieee.h \ lo-macros.h \ lo-mappers.h \ @@ -424,6 +425,7 @@ file-stat.cc \ glob-match.cc \ idx-vector.cc \ + lo-array-gripes.cc \ lo-ieee.cc \ lo-mappers.cc \ lo-specfun.cc \
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -2586,6 +2586,9 @@ boolMatrix Matrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, double> (*this, mx_inline_not); }
--- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -541,6 +541,9 @@ boolNDArray NDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, double> (*this, mx_inline_not); }
--- a/liboctave/dSparse.cc +++ b/liboctave/dSparse.cc @@ -7442,6 +7442,9 @@ SparseBoolMatrix SparseMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + octave_idx_type nr = rows (); octave_idx_type nc = cols (); octave_idx_type nz1 = nnz ();
--- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -3037,6 +3037,9 @@ boolMatrix FloatComplexMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, FloatComplex> (*this, mx_inline_not); }
--- a/liboctave/fCNDArray.cc +++ b/liboctave/fCNDArray.cc @@ -495,6 +495,9 @@ boolNDArray FloatComplexNDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, FloatComplex> (*this, mx_inline_not); }
--- a/liboctave/fMatrix.cc +++ b/liboctave/fMatrix.cc @@ -2585,6 +2585,9 @@ boolMatrix FloatMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, float> (*this, mx_inline_not); }
--- a/liboctave/fNDArray.cc +++ b/liboctave/fNDArray.cc @@ -499,6 +499,9 @@ boolNDArray FloatNDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op<bool, float> (*this, mx_inline_not); }