changeset 8811:20dfb885f877

int -> octave_idx fixes
author John W. Eaton <jwe@octave.org>
date Wed, 18 Feb 2009 23:34:03 -0500
parents c9e1db15035b
children 7d48766c21a5
files liboctave/CDiagMatrix.cc liboctave/CDiagMatrix.h liboctave/ChangeLog liboctave/CmplxQR.cc liboctave/CmplxQRP.cc liboctave/dDiagMatrix.cc liboctave/dDiagMatrix.h liboctave/dbleQR.cc liboctave/dbleQRP.cc liboctave/fCDiagMatrix.cc liboctave/fCDiagMatrix.h liboctave/fCmplxQR.cc liboctave/fCmplxQRP.cc liboctave/fDiagMatrix.cc liboctave/fDiagMatrix.h liboctave/floatQR.cc liboctave/floatQRP.cc src/ChangeLog src/DLD-FUNCTIONS/qr.cc src/ov.cc src/ov.h
diffstat 21 files changed, 157 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/CDiagMatrix.cc
+++ b/liboctave/CDiagMatrix.cc
@@ -355,12 +355,12 @@
 ComplexDiagMatrix
 ComplexDiagMatrix::inverse (void) const
 {
-  int info;
+  octave_idx_type info;
   return inverse (info);
 }
 
 ComplexDiagMatrix
-ComplexDiagMatrix::inverse (int& info) const
+ComplexDiagMatrix::inverse (octave_idx_type& info) const
 {
   octave_idx_type r = rows ();
   octave_idx_type c = cols ();
--- a/liboctave/CDiagMatrix.h
+++ b/liboctave/CDiagMatrix.h
@@ -110,7 +110,7 @@
   ComplexColumnVector column (octave_idx_type i) const;
   ComplexColumnVector column (char *s) const;
 
-  ComplexDiagMatrix inverse (int& info) const;
+  ComplexDiagMatrix inverse (octave_idx_type& info) const;
   ComplexDiagMatrix inverse (void) const;
 
   bool all_elements_are_real (void) const;
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,5 +1,24 @@
 2009-02-18  John W. Eaton  <jwe@octave.org>
 
+	* dbleQR.cc (QR::init, QR::form): Cast int to octave_idx_type in
+	call to std::max.
+	* floatQR.cc (FloatQR::init, FloatQR::form): Ditto.
+	* CmplxQR.cc (ComplexQR::init, ComplexQR::form): Ditto.
+	* fCmplxQR.cc (FloatComplexQR::init, FloatComplexQR::form): Ditto.
+
+	* dbleQRP.cc (QRP::init): Cast int to octave_idx_type in call to
+	std::max and as operand to -= operator.
+	* CmplxQRP.cc (ComplexQRP::init): Ditto.
+	* floatQRP.cc (FloatQRP::init): Ditto.
+	* fCmplxQRP.cc (FloatComplexQRP::init): Ditto.
+
+	* CDiagMatrix.cc, CDiagMatrix.h (ComplexDiagMatrix::inverse):
+	Declare info as octave_idx_type, not int.
+	* dDiagMatrix.cc, dDiagMatrix.h (DiagMatrix::inverse): Ditto.
+	* fDiagMatrix.cc, fCDiagMatrix.h (FloatDiagMatrix::inverse): Ditto.
+	* fCDiagMatrix.cc, fCDiagMatrix.h (FloatComplexDiagMatrix::inverse):
+	Ditto.
+
 	* dMatrix.cc (Matrix::determinant):
 	Declare local variables volatile as needed to avoid "maybe
 	clobbered by vfork" warning from GCC.
--- a/liboctave/CmplxQR.cc
+++ b/liboctave/CmplxQR.cc
@@ -110,7 +110,8 @@
       F77_XFCN (zgeqrf, ZGEQRF, (m, n, afact.fortran_vec (), m, tau, &clwork, -1, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = clwork.real (); lwork = std::max (lwork, 1);
+      octave_idx_type lwork = clwork.real ();
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (Complex, work, lwork);
       F77_XFCN (zgeqrf, ZGEQRF, (m, n, afact.fortran_vec (), m, tau, work, lwork, info));
     }
@@ -177,7 +178,8 @@
                                      &clwork, -1, info));
 
           // allocate buffer and do the job.
-          octave_idx_type lwork = clwork.real (); lwork = std::max (lwork, 1);
+          octave_idx_type lwork = clwork.real ();
+	  lwork = std::max (lwork, static_cast<octave_idx_type> (1));
           OCTAVE_LOCAL_BUFFER (Complex, work, lwork);
           F77_XFCN (zungqr, ZUNGQR, (m, k, min_mn, q.fortran_vec (), m, tau,
                                      work, lwork, info));
--- a/liboctave/CmplxQRP.cc
+++ b/liboctave/CmplxQRP.cc
@@ -77,7 +77,8 @@
                                  tau, &clwork, -1, rwork, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = clwork.real (); lwork = std::max (lwork, 1);
+      octave_idx_type lwork = clwork.real ();
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (Complex, work, lwork);
       F77_XFCN (zgeqp3, ZGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
                                  tau, work, lwork, rwork, info));
@@ -88,7 +89,7 @@
   // Form Permutation matrix (if economy is requested, return the
   // indices only!)
 
-  jpvt -= 1;
+  jpvt -= static_cast<octave_idx_type> (1);
   p = PermMatrix (jpvt, true);
 
 
--- a/liboctave/dDiagMatrix.cc
+++ b/liboctave/dDiagMatrix.cc
@@ -270,12 +270,12 @@
 DiagMatrix
 DiagMatrix::inverse (void) const
 {
-  int info;
+  octave_idx_type info;
   return inverse (info);
 }
 
 DiagMatrix
-DiagMatrix::inverse (int &info) const
+DiagMatrix::inverse (octave_idx_type &info) const
 {
   octave_idx_type r = rows ();
   octave_idx_type c = cols ();
--- a/liboctave/dDiagMatrix.h
+++ b/liboctave/dDiagMatrix.h
@@ -93,7 +93,7 @@
   ColumnVector column (char *s) const;
 
   DiagMatrix inverse (void) const;
-  DiagMatrix inverse (int& info) const;
+  DiagMatrix inverse (octave_idx_type& info) const;
 
   // other operations
 
--- a/liboctave/dbleQR.cc
+++ b/liboctave/dbleQR.cc
@@ -108,7 +108,8 @@
       F77_XFCN (dgeqrf, DGEQRF, (m, n, afact.fortran_vec (), m, tau, &rlwork, -1, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = rlwork; lwork = std::max (lwork, 1);
+      octave_idx_type lwork = rlwork;
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (double, work, lwork);
       F77_XFCN (dgeqrf, DGEQRF, (m, n, afact.fortran_vec (), m, tau, work, lwork, info));
     }
@@ -175,7 +176,8 @@
                                      &rlwork, -1, info));
 
           // allocate buffer and do the job.
-          octave_idx_type lwork = rlwork; lwork = std::max (lwork, 1);
+          octave_idx_type lwork = rlwork;
+	  lwork = std::max (lwork, static_cast<octave_idx_type> (1));
           OCTAVE_LOCAL_BUFFER (double, work, lwork);
           F77_XFCN (dorgqr, DORGQR, (m, k, min_mn, q.fortran_vec (), m, tau,
                                      work, lwork, info));
--- a/liboctave/dbleQRP.cc
+++ b/liboctave/dbleQRP.cc
@@ -75,7 +75,8 @@
                                  tau, &rlwork, -1, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = rlwork; lwork = std::max (lwork, 1);
+      octave_idx_type lwork = rlwork;
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (double, work, lwork);
       F77_XFCN (dgeqp3, DGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
                                  tau, work, lwork, info));
@@ -86,7 +87,7 @@
   // Form Permutation matrix (if economy is requested, return the
   // indices only!)
 
-  jpvt -= 1;
+  jpvt -= static_cast<octave_idx_type> (1);
   p = PermMatrix (jpvt, true);
 
 
--- a/liboctave/fCDiagMatrix.cc
+++ b/liboctave/fCDiagMatrix.cc
@@ -355,12 +355,12 @@
 FloatComplexDiagMatrix
 FloatComplexDiagMatrix::inverse (void) const
 {
-  int info;
+  octave_idx_type info;
   return inverse (info);
 }
 
 FloatComplexDiagMatrix
-FloatComplexDiagMatrix::inverse (int& info) const
+FloatComplexDiagMatrix::inverse (octave_idx_type& info) const
 {
   octave_idx_type r = rows ();
   octave_idx_type c = cols ();
--- a/liboctave/fCDiagMatrix.h
+++ b/liboctave/fCDiagMatrix.h
@@ -110,7 +110,7 @@
   FloatComplexColumnVector column (octave_idx_type i) const;
   FloatComplexColumnVector column (char *s) const;
 
-  FloatComplexDiagMatrix inverse (int& info) const;
+  FloatComplexDiagMatrix inverse (octave_idx_type& info) const;
   FloatComplexDiagMatrix inverse (void) const;
 
   bool all_elements_are_real (void) const;
--- a/liboctave/fCmplxQR.cc
+++ b/liboctave/fCmplxQR.cc
@@ -110,7 +110,8 @@
       F77_XFCN (cgeqrf, CGEQRF, (m, n, afact.fortran_vec (), m, tau, &clwork, -1, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = clwork.real (); lwork = std::max (lwork, 1);
+      octave_idx_type lwork = clwork.real ();
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (FloatComplex, work, lwork);
       F77_XFCN (cgeqrf, CGEQRF, (m, n, afact.fortran_vec (), m, tau, work, lwork, info));
     }
@@ -177,7 +178,8 @@
                                      &clwork, -1, info));
 
           // allocate buffer and do the job.
-          octave_idx_type lwork = clwork.real (); lwork = std::max (lwork, 1);
+          octave_idx_type lwork = clwork.real ();
+	  lwork = std::max (lwork, static_cast<octave_idx_type> (1));
           OCTAVE_LOCAL_BUFFER (FloatComplex, work, lwork);
           F77_XFCN (cungqr, CUNGQR, (m, k, min_mn, q.fortran_vec (), m, tau,
                                      work, lwork, info));
--- a/liboctave/fCmplxQRP.cc
+++ b/liboctave/fCmplxQRP.cc
@@ -77,7 +77,8 @@
                                  tau, &clwork, -1, rwork, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = clwork.real (); lwork = std::max (lwork, 1);
+      octave_idx_type lwork = clwork.real ();
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (FloatComplex, work, lwork);
       F77_XFCN (cgeqp3, CGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
                                  tau, work, lwork, rwork, info));
@@ -88,7 +89,7 @@
   // Form Permutation matrix (if economy is requested, return the
   // indices only!)
 
-  jpvt -= 1;
+  jpvt -= static_cast<octave_idx_type> (1);
   p = PermMatrix (jpvt, true);
 
 
--- a/liboctave/fDiagMatrix.cc
+++ b/liboctave/fDiagMatrix.cc
@@ -270,12 +270,12 @@
 FloatDiagMatrix
 FloatDiagMatrix::inverse (void) const
 {
-  int info;
+  octave_idx_type info;
   return inverse (info);
 }
 
 FloatDiagMatrix
-FloatDiagMatrix::inverse (int &info) const
+FloatDiagMatrix::inverse (octave_idx_type &info) const
 {
   octave_idx_type r = rows ();
   octave_idx_type c = cols ();
--- a/liboctave/fDiagMatrix.h
+++ b/liboctave/fDiagMatrix.h
@@ -93,7 +93,7 @@
   FloatColumnVector column (char *s) const;
 
   FloatDiagMatrix inverse (void) const;
-  FloatDiagMatrix inverse (int& info) const;
+  FloatDiagMatrix inverse (octave_idx_type& info) const;
 
   // other operations
 
--- a/liboctave/floatQR.cc
+++ b/liboctave/floatQR.cc
@@ -108,7 +108,8 @@
       F77_XFCN (sgeqrf, SGEQRF, (m, n, afact.fortran_vec (), m, tau, &rlwork, -1, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = rlwork; lwork = std::max (lwork, 1);
+      octave_idx_type lwork = rlwork;
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (float, work, lwork);
       F77_XFCN (sgeqrf, SGEQRF, (m, n, afact.fortran_vec (), m, tau, work, lwork, info));
     }
@@ -175,7 +176,8 @@
                                      &rlwork, -1, info));
 
           // allocate buffer and do the job.
-          octave_idx_type lwork = rlwork; lwork = std::max (lwork, 1);
+          octave_idx_type lwork = rlwork;
+	  lwork = std::max (lwork, static_cast<octave_idx_type> (1));
           OCTAVE_LOCAL_BUFFER (float, work, lwork);
           F77_XFCN (sorgqr, SORGQR, (m, k, min_mn, q.fortran_vec (), m, tau,
                                      work, lwork, info));
--- a/liboctave/floatQRP.cc
+++ b/liboctave/floatQRP.cc
@@ -75,7 +75,8 @@
                                  tau, &rlwork, -1, info));
 
       // allocate buffer and do the job.
-      octave_idx_type lwork = rlwork; lwork = std::max (lwork, 1);
+      octave_idx_type lwork = rlwork;
+      lwork = std::max (lwork, static_cast<octave_idx_type> (1));
       OCTAVE_LOCAL_BUFFER (float, work, lwork);
       F77_XFCN (sgeqp3, SGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
                                  tau, work, lwork, info));
@@ -86,7 +87,7 @@
   // Form Permutation matrix (if economy is requested, return the
   // indices only!)
 
-  jpvt -= 1;
+  jpvt -= static_cast<octave_idx_type> (1);
   p = PermMatrix (jpvt, true);
 
 
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
 2009-02-18  John W. Eaton  <jwe@octave.org>
- 
+
+	* ov.cc (convert_to_octave_idx_type_array): New static function.
+	(octave_value::octave_idx_type_vector_value): New function.
+	* ov.h (octave_value::octave_idx_type_vector_value): Provide decl.
+	* DLD-FUNCTIONS/qr.cc (Fqrdelete, Fqrinsert): Use it to convert
+	octave_value object to array of octave_idx_type values.
+
 	* DLD-FUNCTIONS/find.cc (find_nonzero_elem_idx): Likewise.
 	* DLD-FUNCTIONS/time.cc (strptime): Likewise.
 	* DLD-FUNCTIONS/quad.cc (Fquad): Eliminate unnecessary cast.
--- a/src/DLD-FUNCTIONS/qr.cc
+++ b/src/DLD-FUNCTIONS/qr.cc
@@ -989,7 +989,8 @@
           {
             if (check_index (argj, col))
               {
-                MArray<octave_idx_type> j = argj.int_vector_value ();
+                MArray<octave_idx_type> j
+		  = argj.octave_idx_type_vector_value ();
 
                 if (argq.is_real_type () 
 		    && argr.is_real_type () 
@@ -1202,7 +1203,8 @@
           {
             if (check_index (argj, col))
               {
-                MArray<octave_idx_type> j = argj.int_vector_value ();
+                MArray<octave_idx_type> j
+		  = argj.octave_idx_type_vector_value ();
 
                 if (argq.is_real_type ()
 		    && argr.is_real_type ())
--- a/src/ov.cc
+++ b/src/ov.cc
@@ -1494,6 +1494,88 @@
                                              type_name (), "integer vector"));
 }
 
+template <class T>
+static Array<octave_idx_type>
+convert_to_octave_idx_type_array (const Array<octave_int<T> >& A)
+{
+  Array<octave_idx_type> retval (A.dims ());
+  octave_idx_type n = A.numel ();
+
+  octave_int<int>::clear_conv_flag ();
+  for (octave_idx_type i = 0; i < n; i++)
+    retval.xelem (i) = octave_int<octave_idx_type> (A.xelem (i));
+
+  if (octave_int<int>::get_trunc_flag ())
+    gripe_truncated_conversion (octave_int<T>::type_name (), "int");
+
+  octave_int<int>::clear_conv_flag ();
+
+  return retval;
+}
+
+Array<octave_idx_type>
+octave_value::octave_idx_type_vector_value (bool force_string_conv,
+					    bool require_int,
+					    bool force_vector_conversion) const
+{
+  Array<octave_idx_type> retval;
+
+  if (is_integer_type ())
+    {
+      if (is_int32_type ())
+        retval = convert_to_octave_idx_type_array (int32_array_value ());
+      else if (is_int64_type ())
+        retval = convert_to_octave_idx_type_array (int64_array_value ());
+      else if (is_int16_type ())
+        retval = convert_to_octave_idx_type_array (int16_array_value ());
+      else if (is_int8_type ())
+        retval = convert_to_octave_idx_type_array (int8_array_value ());
+      else if (is_uint32_type ())
+        retval = convert_to_octave_idx_type_array (uint32_array_value ());
+      else if (is_uint64_type ())
+        retval = convert_to_octave_idx_type_array (uint64_array_value ());
+      else if (is_uint16_type ())
+        retval = convert_to_octave_idx_type_array (uint16_array_value ());
+      else if (is_uint8_type ())
+        retval = convert_to_octave_idx_type_array (uint8_array_value ());
+      else
+        retval = array_value (force_string_conv);
+    }
+  else 
+    {
+      const NDArray a = array_value (force_string_conv);
+      if (! error_state)
+        {
+          if (require_int)
+            {
+              retval.resize (a.dims ());
+              for (octave_idx_type i = 0; i < a.numel (); i++)
+                {
+                  double ai = a.elem (i);
+                  octave_idx_type v = static_cast<octave_idx_type> (ai);
+                  if (ai == v)
+                    retval.xelem (i) = v;
+                  else
+                    {
+                      error ("conversion to integer value failed");
+                      break;
+                    }
+                }
+            }
+          else
+            retval = Array<octave_idx_type> (a);
+        }
+    }
+
+
+  if (error_state)
+    return retval;
+  else
+    return retval.reshape (make_vector_dims (retval.dims (),
+                                             force_vector_conversion,
+                                             type_name (), "integer vector"));
+}
+
 Array<Complex>
 octave_value::complex_vector_value (bool force_string_conv,
                                     bool force_vector_conversion) const
--- a/src/ov.h
+++ b/src/ov.h
@@ -857,6 +857,11 @@
 			       bool frc_str_conv = false,
 			       bool frc_vec_conv = false) const;
 
+  Array<octave_idx_type>
+  octave_idx_type_vector_value (bool req_int = false,
+				bool frc_str_conv = false,
+				bool frc_vec_conv = false) const;
+
   Array<double> vector_value (bool frc_str_conv = false,
 			      bool frc_vec_conv = false) const;