changeset 10826:9e6aed3c6704

fix find for character arrays
author John W. Eaton <jwe@octave.org>
date Wed, 28 Jul 2010 11:36:26 -0400
parents cace99cb01ab
children 228cd18455a6
files src/ChangeLog src/DLD-FUNCTIONS/find.cc
diffstat 2 files changed, 43 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Jul 28 09:22:41 2010 +0200
+++ b/src/ChangeLog	Wed Jul 28 11:36:26 2010 -0400
@@ -1,3 +1,10 @@
+2010-07-28  John W. Eaton  <jwe@octave.org>
+
+	* DLD-FUNCTIONS/find.cc (Ffind): Reorder cases to check for
+	character strings before numeric arrays.
+	Delete explicit instantiations of find_nonzero_elem_idx templates.
+	New test for char array argument.
+
 2010-07-27  Rik <octave@nomad.inbox5.com>
 
 	* DLD-FUNCTIONS/schur.cc (rsf2csf): Change first documentation line to
--- a/src/DLD-FUNCTIONS/find.cc	Wed Jul 28 09:22:41 2010 +0200
+++ b/src/DLD-FUNCTIONS/find.cc	Wed Jul 28 11:36:26 2010 -0400
@@ -82,24 +82,6 @@
   return retval;
 }
 
-#define INSTANTIATE_FIND_ARRAY(T) \
-template octave_value_list find_nonzero_elem_idx (const Array<T>&, int, \
-                                                  octave_idx_type, int)
-
-INSTANTIATE_FIND_ARRAY(double);
-INSTANTIATE_FIND_ARRAY(float);
-INSTANTIATE_FIND_ARRAY(Complex);
-INSTANTIATE_FIND_ARRAY(FloatComplex);
-INSTANTIATE_FIND_ARRAY(bool);
-INSTANTIATE_FIND_ARRAY(octave_int8);
-INSTANTIATE_FIND_ARRAY(octave_int16);
-INSTANTIATE_FIND_ARRAY(octave_int32);
-INSTANTIATE_FIND_ARRAY(octave_int64);
-INSTANTIATE_FIND_ARRAY(octave_uint8);
-INSTANTIATE_FIND_ARRAY(octave_uint16);
-INSTANTIATE_FIND_ARRAY(octave_uint32);
-INSTANTIATE_FIND_ARRAY(octave_uint64);
-
 template <typename T>
 octave_value_list
 find_nonzero_elem_idx (const Sparse<T>& v, int nargout, 
@@ -243,15 +225,6 @@
   return retval;
 }
 
-template octave_value_list find_nonzero_elem_idx (const Sparse<double>&, int,
-                                                  octave_idx_type, int);
-
-template octave_value_list find_nonzero_elem_idx (const Sparse<Complex>&, int,
-                                                  octave_idx_type, int);
-
-template octave_value_list find_nonzero_elem_idx (const Sparse<bool>&, int,
-                                                  octave_idx_type, int);
-
 octave_value_list
 find_nonzero_elem_idx (const PermMatrix& v, int nargout, 
                        octave_idx_type n_to_find, int direction)
@@ -552,64 +525,54 @@
       if (! error_state)
         retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction);
     }
-  else
+  else if (arg.is_string ())
     {
-      if (arg.is_single_type ())
-        {
-          if (arg.is_real_type ())
-            {
-              FloatNDArray nda = arg.float_array_value ();
+      charNDArray chnda = arg.char_array_value ();
 
-              if (! error_state)
-                retval = find_nonzero_elem_idx (nda, nargout, 
-                                                n_to_find, direction);
-            }
-          else if (arg.is_complex_type ())
-            {
-              FloatComplexNDArray cnda = arg.float_complex_array_value ();
-
-              if (! error_state)
-                retval = find_nonzero_elem_idx (cnda, nargout, 
-                                                n_to_find, direction);
-            }
-        }
-      else
+      if (! error_state)
+        retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction);
+    }
+  else if (arg.is_single_type ())
+    {
+      if (arg.is_real_type ())
         {
-          if (arg.is_real_type ())
-            {
-              NDArray nda = arg.array_value ();
-
-              if (! error_state)
-                retval = find_nonzero_elem_idx (nda, nargout, 
-                                                n_to_find, direction);
-            }
-          else if (arg.is_complex_type ())
-            {
-              ComplexNDArray cnda = arg.complex_array_value ();
+          FloatNDArray nda = arg.float_array_value ();
 
-              if (! error_state)
-                retval = find_nonzero_elem_idx (cnda, nargout, 
-                                                n_to_find, direction);
-            }
-          else if (arg.is_string ())
-            {
-              charNDArray cnda = arg.char_array_value ();
+          if (! error_state)
+            retval = find_nonzero_elem_idx (nda, nargout, n_to_find,
+                                            direction);
+        }
+      else if (arg.is_complex_type ())
+        {
+          FloatComplexNDArray cnda = arg.float_complex_array_value ();
 
-              if (! error_state)
-                retval = find_nonzero_elem_idx (cnda, nargout, 
-                                                n_to_find, direction);
-            }
-          else
-            {
-              gripe_wrong_type_arg ("find", arg);
-            }
+          if (! error_state)
+            retval = find_nonzero_elem_idx (cnda, nargout, n_to_find,
+                                            direction);
         }
     }
+  else if (arg.is_real_type ())
+    {
+      NDArray nda = arg.array_value ();
+
+      if (! error_state)
+        retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction);
+    }
+  else if (arg.is_complex_type ())
+    {
+      ComplexNDArray cnda = arg.complex_array_value ();
+
+      if (! error_state)
+        retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction);
+    }
+  else
+    gripe_wrong_type_arg ("find", arg);
 
   return retval;
 }
 
 /*
+%!assert(find (char ([0, 97])), 2);
 %!assert(find ([1, 0, 1, 0, 1]), [1, 3, 5]);
 %!assert(find ([1; 0; 3; 0; 1]), [1; 3; 5]);
 %!assert(find ([0, 0, 2; 0, 3, 0; -1, 0, 0]), [3; 5; 7]);