# HG changeset patch # User John W. Eaton # Date 1287691933 14400 # Node ID 7c573eb981eb8b6edd9d4135640dddbe165848cf # Parent 0de5cc44e69068f9d7ac6705bcc3a47c1c7d22f7 consistently give error for operator not applied to NaN values diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/Array-util.cc --- a/liboctave/Array-util.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/Array-util.cc Thu Oct 21 16:12:13 2010 -0400 @@ -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"); -} - diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/Array-util.h --- a/liboctave/Array-util.h Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/Array-util.h Thu Oct 21 16:12:13 2010 -0400 @@ -23,12 +23,10 @@ #if !defined (octave_Array_util_h) #define octave_Array_util_h 1 -#include - #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& 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 diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/CMatrix.cc --- a/liboctave/CMatrix.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/CMatrix.cc Thu Oct 21 16:12:13 2010 -0400 @@ -3044,6 +3044,9 @@ boolMatrix ComplexMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/CNDArray.cc Thu Oct 21 16:12:13 2010 -0400 @@ -500,6 +500,9 @@ boolNDArray ComplexNDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/CSparse.cc --- a/liboctave/CSparse.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/CSparse.cc Thu Oct 21 16:12:13 2010 -0400 @@ -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 (); diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/ChangeLog --- a/liboctave/ChangeLog Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/ChangeLog Thu Oct 21 16:12:13 2010 -0400 @@ -1,3 +1,24 @@ +2010-10-21 John W. Eaton + + * 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 * Array-util.cc (gripe_nan_to_character_conversion): New function. diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/Makefile.am --- a/liboctave/Makefile.am Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/Makefile.am Thu Oct 21 16:12:13 2010 -0400 @@ -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 \ diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/dMatrix.cc Thu Oct 21 16:12:13 2010 -0400 @@ -2586,6 +2586,9 @@ boolMatrix Matrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/dNDArray.cc Thu Oct 21 16:12:13 2010 -0400 @@ -541,6 +541,9 @@ boolNDArray NDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/dSparse.cc --- a/liboctave/dSparse.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/dSparse.cc Thu Oct 21 16:12:13 2010 -0400 @@ -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 (); diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/fCMatrix.cc --- a/liboctave/fCMatrix.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/fCMatrix.cc Thu Oct 21 16:12:13 2010 -0400 @@ -3037,6 +3037,9 @@ boolMatrix FloatComplexMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/fCNDArray.cc --- a/liboctave/fCNDArray.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/fCNDArray.cc Thu Oct 21 16:12:13 2010 -0400 @@ -495,6 +495,9 @@ boolNDArray FloatComplexNDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/fMatrix.cc --- a/liboctave/fMatrix.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/fMatrix.cc Thu Oct 21 16:12:13 2010 -0400 @@ -2585,6 +2585,9 @@ boolMatrix FloatMatrix::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb liboctave/fNDArray.cc --- a/liboctave/fNDArray.cc Thu Oct 21 16:12:00 2010 -0400 +++ b/liboctave/fNDArray.cc Thu Oct 21 16:12:13 2010 -0400 @@ -499,6 +499,9 @@ boolNDArray FloatNDArray::operator ! (void) const { + if (any_element_is_nan ()) + gripe_nan_to_logical_conversion (); + return do_mx_unary_op (*this, mx_inline_not); } diff -r 0de5cc44e690 -r 7c573eb981eb src/ChangeLog --- a/src/ChangeLog Thu Oct 21 16:12:00 2010 -0400 +++ b/src/ChangeLog Thu Oct 21 16:12:13 2010 -0400 @@ -1,3 +1,7 @@ +2010-10-21 John W. Eaton + + * gripes.h: Include lo-array-gripes.h. + 2010-10-21 John W. Eaton * ov-float.cc, ov-flt-re-mat.cc, ov-re-mat.cc, ov-re-sparse.cc, diff -r 0de5cc44e690 -r 7c573eb981eb src/gripes.h --- a/src/gripes.h Thu Oct 21 16:12:00 2010 -0400 +++ b/src/gripes.h Thu Oct 21 16:12:13 2010 -0400 @@ -26,6 +26,8 @@ #include +#include "lo-array-gripes.h" + class octave_value; extern OCTINTERP_API void