octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error message does not make any sense


From: John W. Eaton
Subject: Error message does not make any sense
Date: Tue, 12 Nov 1996 11:17:07 -0600

On 12-Nov-1996, Andreas Weingessel <address@hidden> wrote:

: To: address@hidden
: Subject: Error message
: 
: Bug report for Octave 1.91 configured for i586-unknown-linux
: 
: Description:
: -----------
: 
: When using a vector or matrix index which is NaN, octave gives an
: error message like
: 
: error: invalid vector index = -2147483648
: error: evaluating index expression near line 11, column 1
: 
: So, if for example the following lines are part of an m-File
: 
: [dis pos]=min(a);
: c=b(pos);
: 
: and the vector grows for some reason out of bounds, the program
: terminates with the above error message which does not give any clue
: what has been the real reason for the error.

Please try the following patch.

I don't know if this will be any better at pointing to the real cause
of the error, but at least it will tell you if you have tried to index
something with NaN or Inf values.

jwe


Index: idx-vector.cc
===================================================================
RCS file: /home/jwe/src/master/octave/liboctave/idx-vector.cc,v
retrieving revision 1.34
diff -c -r1.34 idx-vector.cc
*** idx-vector.cc       1996/10/12 18:31:34     1.34
--- idx-vector.cc       1996/11/12 17:10:55
***************
*** 38,43 ****
--- 38,44 ----
  
  #include "idx-vector.h"
  #include "lo-error.h"
+ #include "lo-mappers.h"
  
  #define IDX_VEC_REP idx_vector::idx_vector_rep
  
***************
*** 73,82 ****
  static inline int
  tree_to_mat_idx (double x)
  {
!   if (x > 0)
!     return ((int) (x + 0.5) - 1);
!   else
!     return ((int) (x - 0.5) - 1);
  }
  
  IDX_VEC_REP::idx_vector_rep (const ColumnVector& v)
--- 74,99 ----
  static inline int
  tree_to_mat_idx (double x)
  {
!   return (x > 0) ? ((int) (x + 0.5) - 1) : ((int) (x - 0.5) - 1);
! }
! 
! static inline bool
! idx_is_inf_or_nan (double x)
! {
!   bool retval = false;
! 
!   if (xisnan (x))
!     {
!       (*current_liboctave_error_handler) ("NaN invalid as index");
!       retval = true;
!     }
!   else if (xisinf (x))
!     {
!       (*current_liboctave_error_handler) ("Inf invalid as index");
!       retval = true;
!     }
! 
!   return retval;
  }
  
  IDX_VEC_REP::idx_vector_rep (const ColumnVector& v)
***************
*** 106,113 ****
    else
      {
        data = new int [len];
        for (int i = 0; i < len; i++)
!       data[i] = tree_to_mat_idx (v.elem (i));
      }
  
    init_state ();
--- 123,138 ----
    else
      {
        data = new int [len];
+ 
        for (int i = 0; i < len; i++)
!       {
!         double d = v.elem (i);
! 
!         if (idx_is_inf_or_nan (d))
!           return;
!         else
!           data[i] = tree_to_mat_idx (d);
!       }
      }
  
    init_state ();
***************
*** 141,149 ****
      {
        int k = 0;
        data = new int [len];
        for (int j = 0; j < orig_nc; j++)
        for (int i = 0; i < orig_nr; i++)
!         data[k++] = tree_to_mat_idx (m.elem (i, j));
      }
  
    init_state ();
--- 166,182 ----
      {
        int k = 0;
        data = new int [len];
+ 
        for (int j = 0; j < orig_nc; j++)
        for (int i = 0; i < orig_nr; i++)
!         {
!           double d = m.elem (i, j);
! 
!           if (idx_is_inf_or_nan (d))
!             return;
!           else
!             data[k++] = tree_to_mat_idx (d);
!         }
      }
  
    init_state ();
***************
*** 163,173 ****
    orig_nr = 1;
    orig_nc = 1;
  
!   data = new int [len];
! 
!   data[0] = tree_to_mat_idx (d);
  
!   init_state ();
  }
  
  IDX_VEC_REP::idx_vector_rep (const Range& r)
--- 196,209 ----
    orig_nr = 1;
    orig_nc = 1;
  
!   if (idx_is_inf_or_nan (d))
!     return;
!   else
!     {
!       data = new int [len];
  
!       data[0] = tree_to_mat_idx (d);
!     }
  }
  
  IDX_VEC_REP::idx_vector_rep (const Range& r)
***************
*** 208,214 ****
    for (int i = 0; i < len; i++)
      {
        double val = b + i * step;
!       data[i] = tree_to_mat_idx (val);
      }
  
    init_state ();
--- 244,254 ----
    for (int i = 0; i < len; i++)
      {
        double val = b + i * step;
! 
!       if (idx_is_inf_or_nan (val))
!       return;
!       else
!       data[i] = tree_to_mat_idx (val);
      }
  
    init_state ();


reply via email to

[Prev in Thread] Current Thread [Next in Thread]