diff -r b83fca22bb4c libinterp/corefcn/find.cc
--- a/libinterp/corefcn/find.cc	Fri Mar 07 13:02:43 2014 -0500
+++ b/libinterp/corefcn/find.cc	Mon Mar 10 14:59:00 2014 -0600
@@ -31,306 +31,338 @@
 #include "gripes.h"
 #include "oct-obj.h"
 
+template<typename T, T v>
+struct integral_constant {};
+
+template<typename T>
+inline T range_start(T start, T, integral_constant<int, 1>)
+{ return start; }
+
+template<typename T>
+inline T range_start(T, T end, integral_constant<int, -1>)
+{ return end - 1; }
+
+template<typename T>
+inline bool finished(T i, T, T end, integral_constant<int, 1>)
+{ return i >= end; }
+
+template<typename T>
+inline bool finished(T i, T start, T, integral_constant<int, -1>)
+{ return i < start; }
+
+template<typename T>
+class array_nz_iter {
+private:
+  const Array<T>& mat;
+  octave_idx_type idx;
+  octave_idx_type row;
+  octave_idx_type col;
+  template<int direction>
+  void take_step(integral_constant<int,direction> dir)
+    {
+      idx += direction;
+      row += direction;
+      if (finished (row, 0, mat.rows (), dir))
+        {
+          row = range_start (0, mat.rows (), dir);
+          col += direction;
+        }
+    }
+  template<int direction>
+  void find_nz(integral_constant<int,direction> dir)
+    {
+      while(!iter_finished (dir) && mat(idx) == T(0))
+        {
+          take_step(dir);
+        }
+    }
+public:
+  template <int direction>
+  array_nz_iter(const Array<T>& arg_mat, integral_constant<int, direction> dir):mat(arg_mat)
+    {
+      row = range_start (0, mat.rows (), dir);
+      //The 'int' argument to numel is undocumented,
+      //but it seems like this is what it does. Can I
+      //use it safely?
+      col = range_start (0, mat.dims().numel(1), dir);
+      idx = range_start (0, mat.numel (), dir);
+      find_nz (dir);
+    }
+  template <int direction>
+  bool iter_finished(integral_constant<int, direction> dir) const
+  {
+    return finished<octave_idx_type>(idx, 0, mat.numel (), dir);
+  }
+  template <int direction>
+  void next(integral_constant<int, direction> dir)
+    {
+      take_step (dir);
+      find_nz (dir);
+    }
+  T operator*() const
+    {
+      return mat(idx);
+    }
+  octave_idx_type get_row() const { return row; }
+  octave_idx_type get_col() const { return col; }
+  double get_idx() const { return idx; }
+};
+
+template<typename T>
+class sparse_nz_iter {
+private:
+  const Sparse<T>& mat;
+  octave_idx_type nz_idx;
+  octave_idx_type col;
+  template <int direction>
+  void catchup_col(integral_constant<int, direction> dir)
+    {
+      while (!iter_finished (dir)
+          && finished (nz_idx, mat.cidx()[col], mat.cidx()[col + 1], dir))
+        col += direction;
+    }
+public:
+  template<int direction>
+  sparse_nz_iter(const Sparse<T>& arg_mat,
+      integral_constant<int, direction> dir) :
+      mat(arg_mat)
+    {
+      nz_idx = range_start(0, mat.nnz (), dir);
+      col = range_start(0, mat.cols (), dir);
+      catchup_col (dir);
+    }
+  template<int direction>
+  bool iter_finished(integral_constant<int, direction> dir) const
+    {
+      return finished<octave_idx_type>(nz_idx, 0, mat.nnz (), dir);
+    }
+  template<int direction>
+  void next(integral_constant<int, direction> dir)
+    {
+      nz_idx += direction;
+      catchup_col (dir);
+    }
+  T operator*() const
+    {
+      return mat.data()[nz_idx];
+    }
+  octave_idx_type get_row() const { return mat.ridx()[nz_idx]; }
+  octave_idx_type get_col() const { return col; }
+  double get_idx() const { return get_col () * double(mat.rows ()) + get_row (); }
+};
+
+class perm_nz_iter
+{
+private:
+  const PermMatrix& mat;
+  octave_idx_type col;
+public:
+  template<int direction>
+  perm_nz_iter(const PermMatrix& arg_mat, integral_constant<int, direction> dir) :
+      mat(arg_mat)
+  {
+    assert(mat.is_col_perm ());
+    col = range_start(0, mat.cols (), dir);
+  }
+  template<int direction>
+  bool iter_finished(integral_constant<int, direction> dir) const
+    {
+      return finished<octave_idx_type>(col, 0, mat.cols (), dir);
+    }
+  template<int direction>
+  void next(integral_constant<int, direction>)
+    {
+      col += direction;
+    }
+  double operator*() const
+    {
+      return 1;
+    }
+  octave_idx_type get_row() const { return mat.fortran_vec()[col]; }
+  octave_idx_type get_col() const { return col; }
+  double get_idx() const { return get_col() * double(mat.rows ()) + get_row (); }
+};
+
+//Surprisingly, this isn't already in the
+//code somewhere.  Perhaps it should be moved
+//to some util library.
+template<typename T>
+inline T min(T a, T b) {
+  return a < b ? a : b;
+}
+
+template<typename ItType, typename M>
+octave_idx_type
+min_with_nnz(const M& nda, octave_idx_type n_to_find)
+{
+  if(n_to_find == 0)
+    return 0;
+  octave_idx_type i = 0;
+  integral_constant<int, 1> dir;
+  for (ItType iter(nda, dir); !iter.iter_finished (dir); iter.next (dir))
+    {
+      ++i;
+      if (n_to_find >= 0 && i >= n_to_find)
+        return n_to_find;
+    }
+  return i;
+}
+
+template<typename ItType, typename T>
+octave_idx_type
+min_with_nnz(const Sparse<T>& nda, octave_idx_type n_to_find)
+{
+  if(n_to_find < 0)
+    return nda.nnz ();
+  else
+    return min<octave_idx_type> (nda.nnz (), n_to_find);
+}
+
+template<typename ItType>
+octave_idx_type
+min_with_nnz(const PermMatrix& nda, octave_idx_type n_to_find)
+{
+  if(n_to_find < 0)
+    return nda.cols ();
+  else
+    return min<octave_idx_type> (nda.cols (), n_to_find);
+}
+
 // Find at most N_TO_FIND nonzero elements in NDA.  Search forward if
 // DIRECTION is 1, backward if it is -1.  NARGOUT is the number of
 // output arguments.  If N_TO_FIND is -1, find all nonzero elements.
+template <int nargout, int direction, typename T, typename M, typename ItType>
+octave_value_list
+find_nonzero_elem_idx_iterized(const M& nda, octave_idx_type n_to_find, int dim)
+{
+  n_to_find = min_with_nnz<ItType> (nda, n_to_find);
+  dim_vector res_dims;
+  if (dim < 0)
+  {
+    //Absurd size rules for Matlab compatibility
+    if (n_to_find == 0
+        && ((nda.rows() == 0 && nda.cols() == 0) || nda.dims().all_ones()))
+      {
+        res_dims = dim_vector(0, 0);
+      }
+    else if(nda.rows() == 1)
+      {
+        res_dims = dim_vector(1, n_to_find);
+      }
+    else
+      {
+        res_dims = dim_vector(n_to_find, 1);
+      }
+  }
+  else
+  {
+    res_dims = dim_vector::alloc (dim + 1);
+    for(octave_idx_type i = 0; i < dim; ++i)
+      {
+        res_dims(i) = 1;
+      }
+    res_dims(dim) = n_to_find;
+  }
 
-template <typename T>
-octave_value_list
-find_nonzero_elem_idx (const Array<T>& nda, int nargout,
-                       octave_idx_type n_to_find, int direction)
-{
-  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
+  static const int retsize = min<int>(nargout, 2);
+  Array<double> retval[retsize];
+  for(int i = 0; i < retsize; ++i)
+    {
+      retval[i] = Array<double> (res_dims);
+    }
+  Array<T> vals;
+  if(nargout >= 3)
+    vals = Array<T> (res_dims);
 
-  Array<octave_idx_type> idx;
-  if (n_to_find >= 0)
-    idx = nda.find (n_to_find, direction == -1);
-  else
-    idx = nda.find ();
+  integral_constant<int,direction> dir;
+  octave_idx_type i = range_start (0, n_to_find, dir);
 
-  // The maximum element is always at the end.
-  octave_idx_type iext = idx.is_empty () ? 0 : idx.xelem (idx.numel () - 1) + 1;
-
-  switch (nargout)
+  for (ItType iter (nda, dir);
+      !(finished (i, 0, n_to_find, dir) || iter.iter_finished (dir)); iter.next (dir))
     {
-    default:
-    case 3:
-      retval(2) = Array<T> (nda.index (idx_vector (idx)));
-      // Fall through!
-
-    case 2:
-      {
-        Array<octave_idx_type> jdx (idx.dims ());
-        octave_idx_type n = idx.length ();
-        octave_idx_type nr = nda.rows ();
-        for (octave_idx_type i = 0; i < n; i++)
-          {
-            jdx.xelem (i) = idx.xelem (i) / nr;
-            idx.xelem (i) %= nr;
-          }
-        iext = -1;
-        retval(1) = idx_vector (jdx, -1);
-      }
-      // Fall through!
-
-    case 1:
-    case 0:
-      retval(0) = idx_vector (idx, iext);
-      break;
+      switch(nargout)
+        {
+        case 3:
+          vals(i) = *iter;
+          //Fall through!
+        case 2:
+          retval[1](i) = iter.get_col() + 1;
+          retval[0](i) = iter.get_row() + 1;
+          break;
+        case 1:
+          retval[0](i) = iter.get_idx() + 1;
+          break;
+        }
+      i += direction;
     }
-
-  return retval;
+  octave_value_list res (nargout);
+  for(int j = 0; j < retsize; ++j) {
+    res(j) = retval[j];
+  }
+  if (nargout >= 3){
+    res(2) = vals;
+  }
+  return res;
 }
 
-template <typename T>
+template<int nargout, int direction, typename T>
+octave_value_list find_nonzero_elem_idx_for(const Array<T>& nda,
+    octave_idx_type n_to_find, int dim)
+{
+  return find_nonzero_elem_idx_iterized<nargout, direction, T, Array<T>,
+      array_nz_iter<T> > (nda, n_to_find, dim);
+}
+
+template<int nargout, int direction, typename T>
+octave_value_list find_nonzero_elem_idx_for(const Sparse<T>& nda,
+    octave_idx_type n_to_find, int dim)
+{
+  return find_nonzero_elem_idx_iterized<nargout, direction, T, Sparse<T>,
+      sparse_nz_iter<T> > (nda, n_to_find, dim);
+}
+
+template<int nargout, int direction>
+octave_value_list find_nonzero_elem_idx_for(const PermMatrix& nda,
+    octave_idx_type n_to_find, int dim)
+{
+  return find_nonzero_elem_idx_iterized<nargout, direction, double, PermMatrix,
+      perm_nz_iter> (nda.is_col_perm () ? nda : nda.flip_repr (), n_to_find, dim);
+}
+
+
+template<int nargout, typename M>
 octave_value_list
-find_nonzero_elem_idx (const Sparse<T>& v, int nargout,
-                       octave_idx_type n_to_find, int direction)
+find_nonzero_elem_idx_for_nargout(const M& nda,
+    octave_idx_type n_to_find, int direction, int dim)
 {
-  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
-
-
-  octave_idx_type nc = v.cols ();
-  octave_idx_type nr = v.rows ();
-  octave_idx_type nz = v.nnz ();
-
-  // Search in the default range.
-  octave_idx_type start_nc = -1;
-  octave_idx_type end_nc = -1;
-  octave_idx_type count;
-
-  // Search for the range to search
-  if (n_to_find < 0)
-    {
-      start_nc = 0;
-      end_nc = nc;
-      n_to_find = nz;
-      count = nz;
-    }
-  else if (direction > 0)
-    {
-      for (octave_idx_type j = 0; j < nc; j++)
-        {
-          OCTAVE_QUIT;
-          if (v.cidx (j) == 0 && v.cidx (j+1) != 0)
-            start_nc = j;
-          if (v.cidx (j+1) >= n_to_find)
-            {
-              end_nc = j + 1;
-              break;
-            }
-        }
-    }
+  if (direction > 0)
+    return find_nonzero_elem_idx_for<nargout, 1> (nda, n_to_find, dim);
+  else if(direction < 0)
+    return find_nonzero_elem_idx_for<nargout, -1> (nda, n_to_find, dim);
   else
     {
-      for (octave_idx_type j = nc; j > 0; j--)
-        {
-          OCTAVE_QUIT;
-          if (v.cidx (j) == nz && v.cidx (j-1) != nz)
-            end_nc = j;
-          if (nz - v.cidx (j-1) >= n_to_find)
-            {
-              start_nc = j - 1;
-              break;
-            }
-        }
+      assert(false);
+      return octave_value_list ();
     }
+}
 
-  count = (n_to_find > v.cidx (end_nc) - v.cidx (start_nc) ?
-           v.cidx (end_nc) - v.cidx (start_nc) : n_to_find);
-
-  // If the original argument was a row vector, force a row vector of
-  // the overall indices to be returned.  But see below for scalar
-  // case...
-
-  octave_idx_type result_nr = count;
-  octave_idx_type result_nc = 1;
-
-  bool scalar_arg = false;
-
-  if (v.rows () == 1)
-    {
-      result_nr = 1;
-      result_nc = count;
-
-      scalar_arg = (v.columns () == 1);
-    }
-
-  Matrix idx (result_nr, result_nc);
-
-  Matrix i_idx (result_nr, result_nc);
-  Matrix j_idx (result_nr, result_nc);
-
-  Array<T> val (dim_vector (result_nr, result_nc));
-
-  if (count > 0)
-    {
-      // Search for elements to return.  Only search the region where
-      // there are elements to be found using the count that we want
-      // to find.
-      for (octave_idx_type j = start_nc, cx = 0; j < end_nc; j++)
-        for (octave_idx_type i = v.cidx (j); i < v.cidx (j+1); i++ )
-          {
-            OCTAVE_QUIT;
-            if (direction < 0 && i < nz - count)
-              continue;
-            i_idx(cx) = static_cast<double> (v.ridx (i) + 1);
-            j_idx(cx) = static_cast<double> (j + 1);
-            idx(cx) = j * nr + v.ridx (i) + 1;
-            val(cx) = v.data(i);
-            cx++;
-            if (cx == count)
-              break;
-          }
-    }
-  else if (scalar_arg)
-    {
-      idx.resize (0, 0);
-
-      i_idx.resize (0, 0);
-      j_idx.resize (0, 0);
-
-      val.resize (dim_vector (0, 0));
-    }
-
+template<typename M>
+octave_value_list find_nonzero_elem_idx(const M& nda, int nargout,
+    octave_idx_type n_to_find, int direction, int dim)
+{
   switch (nargout)
     {
     case 0:
     case 1:
-      retval(0) = idx;
-      break;
-
-    case 5:
-      retval(4) = nc;
-      // Fall through
-
-    case 4:
-      retval(3) = nr;
-      // Fall through
-
+      return find_nonzero_elem_idx_for_nargout<1> (nda, n_to_find, direction, dim);
+    case 2:
+      return find_nonzero_elem_idx_for_nargout<2> (nda, n_to_find, direction, dim);
     case 3:
-      retval(2) = val;
-      // Fall through!
-
-    case 2:
-      retval(1) = j_idx;
-      retval(0) = i_idx;
-      break;
-
+      return find_nonzero_elem_idx_for_nargout<3> (nda, n_to_find, direction, dim);
     default:
-      panic_impossible ();
-      break;
+      assert(false);
+      return octave_value_list();
     }
-
-  return retval;
-}
-
-octave_value_list
-find_nonzero_elem_idx (const PermMatrix& v, int nargout,
-                       octave_idx_type n_to_find, int direction)
-{
-  // There are far fewer special cases to handle for a PermMatrix.
-  octave_value_list retval ((nargout == 0 ? 1 : nargout), Matrix ());
-
-  octave_idx_type nc = v.cols ();
-  octave_idx_type start_nc, count;
-
-  // Determine the range to search.
-  if (n_to_find < 0 || n_to_find >= nc)
-    {
-      start_nc = 0;
-      n_to_find = nc;
-      count = nc;
-    }
-  else if (direction > 0)
-    {
-      start_nc = 0;
-      count = n_to_find;
-    }
-  else
-    {
-      start_nc = nc - n_to_find;
-      count = n_to_find;
-    }
-
-  bool scalar_arg = (v.rows () == 1 && v.cols () == 1);
-
-  Matrix idx (count, 1);
-  Matrix i_idx (count, 1);
-  Matrix j_idx (count, 1);
-  // Every value is 1.
-  Array<double> val (dim_vector (count, 1), 1.0);
-
-  if (count > 0)
-    {
-      const octave_idx_type* p = v.data ();
-      if (v.is_col_perm ())
-        {
-          for (octave_idx_type k = 0; k < count; k++)
-            {
-              OCTAVE_QUIT;
-              const octave_idx_type j = start_nc + k;
-              const octave_idx_type i = p[j];
-              i_idx(k) = static_cast<double> (1+i);
-              j_idx(k) = static_cast<double> (1+j);
-              idx(k) = j * nc + i + 1;
-            }
-        }
-      else
-        {
-          for (octave_idx_type k = 0; k < count; k++)
-            {
-              OCTAVE_QUIT;
-              const octave_idx_type i = start_nc + k;
-              const octave_idx_type j = p[i];
-              // Scatter into the index arrays according to
-              // j adjusted by the start point.
-              const octave_idx_type koff = j - start_nc;
-              i_idx(koff) = static_cast<double> (1+i);
-              j_idx(koff) = static_cast<double> (1+j);
-              idx(koff) = j * nc + i + 1;
-            }
-        }
-    }
-  else if (scalar_arg)
-    {
-      // Same odd compatibility case as the other overrides.
-      idx.resize (0, 0);
-      i_idx.resize (0, 0);
-      j_idx.resize (0, 0);
-      val.resize (dim_vector (0, 0));
-    }
-
-  switch (nargout)
-    {
-    case 0:
-    case 1:
-      retval(0) = idx;
-      break;
-
-    case 5:
-      retval(4) = nc;
-      // Fall through
-
-    case 4:
-      retval(3) = nc;
-      // Fall through
-
-    case 3:
-      retval(2) = val;
-      // Fall through!
-
-    case 2:
-      retval(1) = j_idx;
-      retval(0) = i_idx;
-      break;
-
-    default:
-      panic_impossible ();
-      break;
-    }
-
-  return retval;
 }
 
 DEFUN (find, args, nargout,
@@ -338,6 +370,7 @@
 @deftypefn  {Built-in Function} {@var{idx} =} find (@var{x})\n\
 @deftypefnx {Built-in Function} {@var{idx} =} find (@var{x}, @var{n})\n\
 @deftypefnx {Built-in Function} {@var{idx} =} find (@var{x}, @var{n}, @var{direction})\n\
+@deftypefnx {Built-in Function} {@var{idx} =} find (@var{x}, @var{n}, @var{direction}, @var{dim})\n\
 @deftypefnx {Built-in Function} {[i, j] =} find (@dots{})\n\
 @deftypefnx {Built-in Function} {[i, j, v] =} find (@dots{})\n\
 Return a vector of indices of nonzero elements of a matrix, as a row if\n\
@@ -383,6 +416,10 @@
 @var{n} indices, respectively.  However, the indices are always returned in\n\
 ascending order.\n\
 \n\
+If four inputs are given and @var{dim} > 0, then @var{dim} indicates the \n\
+dimension along which the output vectors should be returned (regardless \n\
+of the dimensions of the input matrix).\n\
+\n\
 Note that this function is particularly useful for sparse matrices, as\n\
 it extracts the non-zero elements as vectors, which can then be used to\n\
 create the original matrix.  For example:\n\
@@ -401,7 +438,7 @@
 
   int nargin = args.length ();
 
-  if (nargin > 3 || nargin < 1)
+  if (nargin > 4 || nargin < 1)
     {
       print_usage ();
       return retval;
@@ -445,8 +482,30 @@
         }
     }
 
+  int dim = -1;
+  if (nargin > 3)
+    {
+      double val = args(3).scalar_value ();
+      if (error_state || val < 0 || val != xround (val))
+        {
+          error ("find: DIM must be a non-negative integer");
+          return retval;
+        }
+      else if (! xisinf (val))
+        dim = val - 1;
+    }
+
   octave_value arg = args(0);
 
+  if (nargout <= 0)
+  {
+    nargout = 1;
+  }
+  else if(nargout > 3)
+  {
+    nargout = 3;
+  }
+
   if (arg.is_bool_type ())
     {
       if (arg.is_sparse_type ())
@@ -455,9 +514,10 @@
 
           if (! error_state)
             retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
+                                            n_to_find,
+                                            direction, dim);
         }
-      else if (nargout <= 1 && n_to_find == -1 && direction == 1)
+      else if (nargout <= 1 && n_to_find == -1 && direction == 1 && dim == -1)
         {
           // This case is equivalent to extracting indices from a logical
           // matrix. Try to reuse the possibly cached index vector.
@@ -469,7 +529,7 @@
 
           if (! error_state)
             retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
+                                            n_to_find, direction, dim);
         }
     }
   else if (arg.is_integer_type ())
@@ -481,7 +541,7 @@
           \
           if (! error_state) \
             retval = find_nonzero_elem_idx (v, nargout, \
-                                            n_to_find, direction);\
+                                            n_to_find, direction, dim);\
         }
 
       if (false)
@@ -505,7 +565,7 @@
 
           if (! error_state)
             retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
+                                            n_to_find, direction, dim);
         }
       else if (arg.is_complex_type ())
         {
@@ -513,7 +573,7 @@
 
           if (! error_state)
             retval = find_nonzero_elem_idx (v, nargout,
-                                            n_to_find, direction);
+                                            n_to_find, direction, dim);
         }
       else
         gripe_wrong_type_arg ("find", arg);
@@ -523,14 +583,14 @@
       PermMatrix P = arg.perm_matrix_value ();
 
       if (! error_state)
-        retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction);
+        retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction, dim);
     }
   else if (arg.is_string ())
     {
       charNDArray chnda = arg.char_array_value ();
 
       if (! error_state)
-        retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction);
+        retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction, dim);
     }
   else if (arg.is_single_type ())
     {
@@ -540,7 +600,7 @@
 
           if (! error_state)
             retval = find_nonzero_elem_idx (nda, nargout, n_to_find,
-                                            direction);
+                                            direction, dim);
         }
       else if (arg.is_complex_type ())
         {
@@ -548,7 +608,7 @@
 
           if (! error_state)
             retval = find_nonzero_elem_idx (cnda, nargout, n_to_find,
-                                            direction);
+                                            direction, dim);
         }
     }
   else if (arg.is_real_type ())
@@ -556,14 +616,14 @@
       NDArray nda = arg.array_value ();
 
       if (! error_state)
-        retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction);
+        retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction, dim);
     }
   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);
+        retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction, dim);
     }
   else
     gripe_wrong_type_arg ("find", arg);
diff -r b83fca22bb4c liboctave/array/PermMatrix.cc
--- a/liboctave/array/PermMatrix.cc	Fri Mar 07 13:02:43 2014 -0500
+++ b/liboctave/array/PermMatrix.cc	Mon Mar 10 14:59:00 2014 -0600
@@ -216,3 +216,15 @@
 
   return r;
 }
+
+PermMatrix PermMatrix::flip_repr() const
+{
+  octave_idx_type n = dim2();
+  PermMatrix r(n);
+  r._colp = !_colp;
+  for (octave_idx_type i = 0; i < n; ++i)
+    {
+      r.xelem(xelem(i)) = i;
+    }
+  return r;
+}
diff -r b83fca22bb4c liboctave/array/PermMatrix.h
--- a/liboctave/array/PermMatrix.h	Fri Mar 07 13:02:43 2014 -0500
+++ b/liboctave/array/PermMatrix.h	Mon Mar 10 14:59:00 2014 -0600
@@ -122,6 +122,8 @@
 
   static PermMatrix eye (octave_idx_type n);
 
+  PermMatrix flip_repr() const;
+
 private:
   bool _colp;
 };
diff -r b83fca22bb4c test/build-sparse-tests.sh
--- a/test/build-sparse-tests.sh	Fri Mar 07 13:02:43 2014 -0500
+++ b/test/build-sparse-tests.sh	Mon Mar 10 14:59:00 2014 -0600
@@ -569,7 +569,8 @@
 %!assert (as==af)
 %!assert (af==as)
 %!test
-%! [ii,jj,vv,nr,nc] = find (as);
+%! [ii,jj,vv] = find (as);
+%! [nr,nc] = size(as);
 %! assert (af, full (sparse (ii,jj,vv,nr,nc)));
 %!assert (nnz (as), sum (af(:)!=0))
 %!assert (nnz (as), nnz (af))
@@ -598,7 +599,8 @@
 %! x = sparse (i,j,v,m,n);
 %! assert (x, as);
 %!test
-%! [i,j,v,m,n] = find (as);
+%! [i,j,v] = find (as);
+%! [m,n] = size(as);
 %! x = sparse (i,j,v,m,n);
 %! assert (x, as);
 %!assert (issparse (horzcat (as,as)));
