changeset 4588:19bfd295f400

[project @ 2003-11-10 17:18:48 by jwe]
author jwe
date Mon, 10 Nov 2003 17:22:02 +0000
parents 7b957b442818
children 8dea9db3af09
files liboctave/Array-util.cc liboctave/Array-util.h liboctave/Array.cc liboctave/ArrayN-inline.h liboctave/ArrayN.cc liboctave/CNDArray.cc liboctave/ChangeLog liboctave/Makefile.in liboctave/boolNDArray.cc liboctave/chNDArray.cc liboctave/dNDArray.cc
diffstat 11 files changed, 639 insertions(+), 538 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/Array-util.cc	Mon Nov 10 17:22:02 2003 +0000
@@ -0,0 +1,517 @@
+/*
+
+Copyright (C) 2003 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "Array-util.h"
+
+bool
+index_in_bounds (const Array<int>& ra_idx, const dim_vector& dimensions)
+{
+  bool retval = true;
+
+  int n = ra_idx.length ();
+
+  if (n == dimensions.length ())
+    {
+      for (int i = 0; i < n; i++)
+	{
+	  if (ra_idx(i) < 0 || ra_idx(i) > dimensions (i))
+	    {
+	      retval = false;
+	      break;
+	    }
+	}
+    }
+  else
+    retval = false;
+
+  return retval;
+}
+
+void
+increment_index (Array<int>& ra_idx, const dim_vector& dimensions,
+		 int start_dimension)
+{
+  ra_idx(start_dimension)++;
+
+  int n = ra_idx.length () - 1;
+
+  for (int i = start_dimension; i < n; i++)
+    {
+      if (ra_idx(i) < dimensions(i))
+ 	break;
+      else
+ 	{
+ 	  ra_idx(i) = 0;
+ 	  ra_idx(i+1)++;
+ 	}
+    }
+}
+
+int
+get_scalar_idx (Array<int>& idx, dim_vector& dims)
+{
+  int retval (-1);
+
+  int n = idx.length ();
+
+  if (n > 0)
+    {
+      retval = idx(--n);
+
+      while (--n >= 0)
+	{      		
+	  retval *= dims (n);
+	
+	  retval += idx(n);
+	}
+    }
+  return retval;
+}
+
+int
+num_ones (const Array<int>& ra_idx)
+{
+  int retval (0);
+  for (int i = 0; i < ra_idx.length (); i++)
+    {
+      if (ra_idx (i) == 1)
+	retval++;
+    }
+  return retval;
+}
+
+bool
+is_scalar (const dim_vector& dim)
+{
+  bool retval = true;
+
+  int n = dim.length ();
+
+  if (n == 0)
+    {
+      retval = false;
+    }
+  else
+    {
+      for (int i = 0; i < n; i ++)
+	{
+	  if (dim (i) != 1)
+	    {
+	      retval = false;
+	
+	      break;
+	    }
+	}
+    }
+  return retval;
+}
+
+bool
+any_ones (const Array<int>& arr)
+{
+  bool retval = false;
+
+  for (int i = 0; i < arr.length (); i++)
+    {
+      if (arr (i) == 1)
+	{
+	  retval = true;
+	
+	  break;
+	}
+    }
+  return retval;
+}
+
+int
+compute_index (const Array<int>& ra_idx, const dim_vector& dims)
+{
+  int retval = -1;
+
+  int n = dims.length ();
+
+  if (n > 0 && n == ra_idx.length ())
+    {
+      retval = ra_idx(--n);
+
+      while (--n >= 0)
+	{
+	  retval *= dims(n);
+	
+	  retval += ra_idx(n);
+	}
+    }
+  else
+    (*current_liboctave_error_handler)
+      ("ArrayN<T>::compute_index: invalid ra_idxing operation");
+
+  return retval;
+}
+
+Array<int>
+conv_to_int_array (const Array<idx_vector>& a)
+{
+  Array<int> retval (a.length ());
+
+  for (int i = 0; i < a.length (); i++)
+    retval (i) = a(i).elem (0);
+
+  return retval;
+}
+
+Array<idx_vector>
+conv_to_array (const idx_vector *tmp, const int len)
+{
+  Array<idx_vector> retval (len);
+
+  for (int i = 0; i < len; i++)
+      retval (i) = tmp[i];
+
+  return retval;
+}
+
+dim_vector
+freeze (Array<idx_vector>& ra_idx, const dim_vector& dimensions, int resize_ok)
+{
+  dim_vector retval;
+
+  int n = ra_idx.length ();
+
+  assert (n == dimensions.length ());
+
+  retval.resize (n);
+
+  for (int i = 0; i < n; i++)
+    retval(i) = ra_idx(i).freeze (dimensions(i), "XXX FIXME XXX", resize_ok);
+
+  return retval;
+}
+
+bool
+vector_equivalent (const Array<int>& ra_idx)
+{
+  int n = ra_idx.length ();
+
+  bool found_first = false;
+
+  for (int i = 0; i < n; i++)
+    {
+      if (ra_idx(i) != 1)
+        {
+	  if (! found_first)
+	    found_first = true;
+	  else
+	    return false;
+	}
+    }
+
+  return true;
+}
+
+bool
+equal_arrays (const dim_vector& a, const dim_vector& b)
+{
+  bool retval = true;
+
+  if (a.length () != b.length ())
+    retval = false;
+  else
+    {
+      for (int i = 0; i < a.length (); i++)
+	{
+	  if (a(i) != b(i))
+	    retval = false;
+	}
+    }
+
+  return retval;
+}
+
+bool
+all_ok (const Array<idx_vector>& ra_idx)
+{
+  bool retval = true;
+
+  int n = ra_idx.length ();
+
+  for (int i = 0; i < n; i++)
+    {
+      if (! ra_idx(i))
+	{
+	  retval = false;
+	  break;
+	}
+    }
+
+  return retval;
+}
+
+bool
+any_orig_empty (const Array<idx_vector>& ra_idx)
+{
+  bool retval = false;
+
+  int n = ra_idx.length ();
+
+  for (int i = 0; i < n; i++)
+    {
+      if (ra_idx(i).orig_empty ())
+	{
+	  retval = true;
+	  break;
+	}
+    }
+
+  return retval;
+}
+
+bool
+any_zero_len (const dim_vector& frozen_lengths)
+{
+  bool retval = false;
+
+  int n = frozen_lengths.length ();
+
+  for (int i = 0; i < n; i++)
+    {
+      if (frozen_lengths(i) == 0)
+	{
+	  retval = true;
+	  break;
+	}
+    }
+
+  return retval;
+}
+
+dim_vector
+get_zero_len_size (const dim_vector& frozen_lengths,
+		   const dim_vector& dimensions)
+{
+  dim_vector retval;
+  assert (0);
+  return retval;
+}
+
+bool
+all_colon_equiv (const Array<idx_vector>& ra_idx,
+		 const dim_vector& frozen_lengths)
+{
+  bool retval = true;
+
+  int idx_n = ra_idx.length ();
+
+  int n = frozen_lengths.length ();
+
+  assert (idx_n == n);
+
+  for (int i = 0; i < n; i++)
+    {
+      if (! ra_idx(i).is_colon_equiv (frozen_lengths(i)))
+	{
+	  retval = false;
+	  break;
+	}
+    }
+
+  return retval;
+}
+
+bool
+is_in (int num, const idx_vector& idx)
+{
+  int n = idx.capacity ();
+
+  for (int i = 0; i < n; i++)
+    if (idx.elem (i) == num)
+      return true;
+
+  return false;
+}
+
+int
+how_many_lgt (const int num, idx_vector& idxv)
+{
+  int retval = 0;
+
+  int n = idxv.capacity ();
+
+  for (int i = 0; i < n; i++)
+    {
+      if (num > idxv.elem (i))
+	retval++;
+    }
+
+  return retval;
+}
+
+bool
+all_ones (const Array<int>& arr)
+{
+  bool retval = true;
+
+  for (int i = 0; i < arr.length (); i++)
+    {
+      if (arr(i) != 1)
+	{
+	  retval = false;
+	  break;
+	}
+    }
+
+  return retval;
+}
+
+Array<int>
+get_elt_idx (const Array<idx_vector>& ra_idx, const Array<int>& result_idx)
+{
+  int n = ra_idx.length ();
+
+  Array<int> retval (n);
+
+  for (int i = 0; i < n; i++)
+    retval(i) = ra_idx(i).elem (result_idx(i));
+
+  return retval;
+}
+
+int
+number_of_elements (const dim_vector ra_idx)
+{
+  int retval = 1;
+
+  int n = ra_idx.length ();
+
+  if (n == 0)
+    retval = 0;
+
+  for (int i = 0; i < n; i++)
+    retval *= ra_idx(i);
+
+  return retval;
+}
+
+Array<int>
+get_ra_idx (int idx, const dim_vector& dims)
+{
+  Array<int> retval;
+
+  int n_dims = dims.length ();
+
+  retval.resize (n_dims);
+
+  for (int i = 0; i < n_dims; i++)
+    retval(i) = 0;
+
+  assert (idx > 0 || idx < number_of_elements (dims));
+
+  for (int i = 0; i < idx; i++)
+    increment_index (retval, dims);
+
+  // XXX FIXME XXX -- the solution using increment_index is not
+  // efficient.
+
+#if 0
+  int var = 1;
+  for (int i = 0; i < n_dims; i++)
+    {
+      std::cout << "idx: " << idx << ", var: " << var << ", dims(" << i << "): " << dims(i) <<"\n";
+      retval(i) = ((int)floor(((idx) / (double)var))) % dims(i);
+      idx -= var * retval(i);
+      var = dims(i);
+    }
+#endif
+
+  return retval;
+}
+
+dim_vector
+short_freeze (Array<idx_vector>& ra_idx, const dim_vector& dimensions,
+	      int resize_ok)
+{
+  dim_vector retval;
+
+  int n = ra_idx.length ();
+
+  int n_dims = dimensions.length ();
+
+  if (n == n_dims)
+    {
+      retval = freeze (ra_idx, dimensions, resize_ok);
+    }
+  else if (n < n_dims)
+    {
+      retval.resize (n);
+      
+      for (int i = 0; i < n - 1; i++)
+        retval(i) = ra_idx(i).freeze (dimensions(i), "dimension", resize_ok);
+
+      int size_left = 1;
+
+      for (int i = n - 1; i < n_dims; i++)
+        size_left *= dimensions(i); 
+ 
+      if (ra_idx(n-1).is_colon())
+        {
+	  retval(n-1) = size_left;
+	}
+      else
+	{
+	  int last_ra_idx = ra_idx(n-1)(0);
+
+	  if (last_ra_idx < dimensions(n - 1))
+            {
+              retval(n - 1) = ra_idx(n - 1).freeze (dimensions(n-1),
+						    "dimension", resize_ok);
+            }
+          else
+            {
+              if (size_left <= last_ra_idx)
+                {
+         	  // Make it larger than it should be to get an error
+         	  // later.
+
+                  retval.resize(n_dims + 1);
+
+                  (*current_liboctave_error_handler)
+                    ("index exceeds N-d array dimensions");
+                }
+              else
+                {
+                  retval(n-1) = 1;
+                }
+	    }
+	}
+    }
+
+  return retval;
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/Array-util.h	Mon Nov 10 17:22:02 2003 +0000
@@ -0,0 +1,96 @@
+/*
+
+Copyright (C) 2000 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#if !defined (octave_Array_util_h)
+#define octave_Array_util_h 1
+
+#include <cassert>
+
+#include "Array.h"
+#include "dim-vector.h"
+#include "idx-vector.h"
+#include "lo-error.h"
+
+extern bool index_in_bounds (const Array<int>& ra_idx,
+			     const dim_vector& dimensions);
+
+extern void increment_index (Array<int>& ra_idx,
+			     const dim_vector& dimensions,
+			     int start_dimension = 0);
+
+extern int get_scalar_idx (Array<int>& idx, dim_vector& dims);
+
+extern int num_ones (const Array<int>& ra_idx);
+
+extern bool is_scalar (const dim_vector& dim);
+
+extern bool any_ones (const Array<int>& arr);
+
+extern int compute_index (const Array<int>& ra_idx, const dim_vector& dims);
+
+extern Array<int> conv_to_int_array (const Array<idx_vector>& a);
+
+extern Array<idx_vector> conv_to_array (const idx_vector *tmp, const int len);
+
+extern dim_vector freeze (Array<idx_vector>& ra_idx,
+			  const dim_vector& dimensions, int resize_ok);
+
+extern bool vector_equivalent (const Array<int>& ra_idx);
+
+extern bool equal_arrays (const dim_vector& a, const dim_vector& b);
+
+extern bool all_ok (const Array<idx_vector>& ra_idx);
+
+extern bool any_orig_empty (const Array<idx_vector>& ra_idx);
+
+extern bool any_zero_len (const dim_vector& frozen_lengths);
+
+extern dim_vector get_zero_len_size (const dim_vector& frozen_lengths,
+				     const dim_vector& dimensions);
+
+extern bool all_colon_equiv (const Array<idx_vector>& ra_idx,
+			     const dim_vector& frozen_lengths);
+
+extern bool is_in (int num, const idx_vector& idx);
+
+extern int how_many_lgt (const int num, idx_vector& idxv);
+
+extern bool all_ones (const Array<int>& arr);
+
+extern Array<int> get_elt_idx (const Array<idx_vector>& ra_idx,
+			       const Array<int>& result_idx);
+
+extern int number_of_elements (const dim_vector ra_idx);
+
+extern Array<int> get_ra_idx (int idx, const dim_vector& dims);
+
+extern dim_vector short_freeze (Array<idx_vector>& ra_idx,
+				const dim_vector& dimensions,
+				int resize_ok);
+
+#endif
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- a/liboctave/Array.cc	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/Array.cc	Mon Nov 10 17:22:02 2003 +0000
@@ -36,12 +36,11 @@
 
 #include "Array.h"
 #include "Array-flags.h"
+#include "Array-util.h"
 #include "Range.h"
 #include "idx-vector.h"
 #include "lo-error.h"
 
-#include "ArrayN-inline.h"
-
 // One dimensional array class.  Handles the reference counting for
 // all the derived classes.
 
@@ -1985,10 +1984,12 @@
 	      Array<int> result_idx (ra_idx.length (), 0);
 
 	      dim_vector this_dims = dims ();
-	
+
+	      Array<int> elt_idx;
+
 	      for (int i = 0; i < n; i++)
 		{
-		  Array<int> elt_idx = get_elt_idx (ra_idx, result_idx); 
+		  elt_idx = get_elt_idx (ra_idx, result_idx); 
 	
 		  int numelem_result = 
 		    get_scalar_idx (result_idx, frozen_lengths);
--- a/liboctave/ArrayN-inline.h	Mon Nov 10 15:50:40 2003 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,516 +0,0 @@
-// Inline functions used by ArrayN-idx.h and ArrayN.cc
-/*
-
-Copyright (C) 2000 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-#ifndef octave_ArrayN_inline_h
-#define octave_ArrayN_inline_h 1
-
-#include "idx-vector.h"
-
-static inline bool
-index_in_bounds (const Array<int>& ra_idx, const dim_vector& dimensions)
-{
-  bool retval = true;
-
-  int n = ra_idx.length ();
-
-  if (n == dimensions.length ())
-    {
-      for (int i = 0; i < n; i++)
-	{
-	  if (ra_idx(i) < 0 || ra_idx(i) > dimensions (i))
-	    {
-	      retval = false;
-	      break;
-	    }
-	}
-    }
-  else
-    retval = false;
-
-  return retval;
-}
-
-static inline void
-increment_index (Array<int>& ra_idx, const dim_vector& dimensions,
-		 int start_dimension = 0)
-{
-  ra_idx(start_dimension)++;
-
-  int n = ra_idx.length () - 1;
-
-  for (int i = start_dimension; i < n; i++)
-    {
-      if (ra_idx(i) < dimensions(i))
- 	break;
-      else
- 	{
- 	  ra_idx(i) = 0;
- 	  ra_idx(i+1)++;
- 	}
-    }
-}
-
-static inline int
-get_scalar_idx (Array<int>& idx, dim_vector& dims)
-{
-  int retval (-1);
-
-  int n = idx.length ();
-
-  if (n > 0)
-    {
-      retval = idx(--n);
-
-      while (--n >= 0)
-	{      		
-	  retval *= dims (n);
-	
-	  retval += idx(n);
-	}
-    }
-  return retval;
-}
-
-static inline int
-num_ones (const Array<int>& ra_idx)
-{
-  int retval (0);
-  for (int i = 0; i < ra_idx.length (); i++)
-    {
-      if (ra_idx (i) == 1)
-	retval++;
-    }
-  return retval;
-}
-
-static inline bool
-is_scalar (const dim_vector& dim)
-{
-  bool retval = true;
-
-  int n = dim.length ();
-
-  if (n == 0)
-    {
-      retval = false;
-    }
-  else
-    {
-      for (int i = 0; i < n; i ++)
-	{
-	  if (dim (i) != 1)
-	    {
-	      retval = false;
-	
-	      break;
-	    }
-	}
-    }
-  return retval;
-}
-
-static inline bool
-any_ones (const Array<int>& arr)
-{
-  bool retval = false;
-
-  for (int i = 0; i < arr.length (); i++)
-    {
-      if (arr (i) == 1)
-	{
-	  retval = true;
-	
-	  break;
-	}
-    }
-  return retval;
-}
-
-static inline int
-compute_index (const Array<int>& ra_idx, const dim_vector& dims)
-{
-  int retval = -1;
-
-  int n = dims.length ();
-
-  if (n > 0 && n == ra_idx.length ())
-    {
-      retval = ra_idx(--n);
-
-      while (--n >= 0)
-	{
-	  retval *= dims(n);
-	
-	  retval += ra_idx(n);
-	}
-    }
-  else
-    (*current_liboctave_error_handler)
-      ("ArrayN<T>::compute_index: invalid ra_idxing operation");
-
-  return retval;
-}
-
-static inline Array<int>
-conv_to_int_array (const Array<idx_vector>& a)
-{
-  Array<int> retval (a.length ());
-
-  for (int i = 0; i < a.length (); i++)
-    retval (i) = a(i).elem (0);
-
-  return retval;
-}
-
-static inline Array<idx_vector>
-conv_to_array (const idx_vector *tmp, const int len)
-{
-  Array<idx_vector> retval (len);
-
-  for (int i = 0; i < len; i++)
-      retval (i) = tmp[i];
-
-  return retval;
-}
-
-static inline dim_vector
-freeze (Array<idx_vector>& ra_idx, const dim_vector& dimensions, int resize_ok)
-{
-  dim_vector retval;
-
-  int n = ra_idx.length ();
-
-  assert (n == dimensions.length ());
-
-  retval.resize (n);
-
-  for (int i = 0; i < n; i++)
-    retval(i) = ra_idx(i).freeze (dimensions(i), "XXX FIXME XXX", resize_ok);
-
-  return retval;
-}
-
-static inline bool
-vector_equivalent (const Array<int>& ra_idx)
-{
-  int n = ra_idx.length ();
-
-  bool found_first = false;
-
-  for (int i = 0; i < n; i++)
-    {
-      if (ra_idx(i) != 1)
-        {
-	  if (! found_first)
-	    found_first = true;
-	  else
-	    return false;
-	}
-    }
-
-  return true;
-}
-
-static inline bool
-equal_arrays (const dim_vector& a, const dim_vector& b)
-{
-  bool retval = true;
-
-  if (a.length () != b.length ())
-    retval = false;
-  else
-    {
-      for (int i = 0; i < a.length (); i++)
-	{
-	  if (a(i) != b(i))
-	    retval = false;
-	}
-    }
-
-  return retval;
-}
-
-static inline bool
-all_ok (const Array<idx_vector>& ra_idx)
-{
-  bool retval = true;
-
-  int n = ra_idx.length ();
-
-  for (int i = 0; i < n; i++)
-    {
-      if (! ra_idx(i))
-	{
-	  retval = false;
-	  break;
-	}
-    }
-
-  return retval;
-}
-
-static inline bool
-any_orig_empty (const Array<idx_vector>& ra_idx)
-{
-  bool retval = false;
-
-  int n = ra_idx.length ();
-
-  for (int i = 0; i < n; i++)
-    {
-      if (ra_idx(i).orig_empty ())
-	{
-	  retval = true;
-	  break;
-	}
-    }
-
-  return retval;
-}
-
-static inline bool
-any_zero_len (const dim_vector& frozen_lengths)
-{
-  bool retval = false;
-
-  int n = frozen_lengths.length ();
-
-  for (int i = 0; i < n; i++)
-    {
-      if (frozen_lengths(i) == 0)
-	{
-	  retval = true;
-	  break;
-	}
-    }
-
-  return retval;
-}
-
-static inline dim_vector
-get_zero_len_size (const dim_vector& frozen_lengths,
-		   const dim_vector& dimensions)
-{
-  dim_vector retval;
-  assert (0);
-  return retval;
-}
-
-static inline bool
-all_colon_equiv (const Array<idx_vector>& ra_idx,
-		 const dim_vector& frozen_lengths)
-{
-  bool retval = true;
-
-  int idx_n = ra_idx.length ();
-
-  int n = frozen_lengths.length ();
-
-  assert (idx_n == n);
-
-  for (int i = 0; i < n; i++)
-    {
-      if (! ra_idx(i).is_colon_equiv (frozen_lengths(i)))
-	{
-	  retval = false;
-	  break;
-	}
-    }
-
-  return retval;
-}
-
-static inline bool
-is_in (int num, const idx_vector& idx)
-{
-  int n = idx.capacity ();
-
-  for (int i = 0; i < n; i++)
-    if (idx.elem (i) == num)
-      return true;
-
-  return false;
-}
-
-static inline int
-how_many_lgt (const int num, idx_vector& idxv)
-{
-  int retval = 0;
-
-  int n = idxv.capacity ();
-
-  for (int i = 0; i < n; i++)
-    if (num > idxv.elem (i))
-      retval++;
-
-  return retval;
-}
-
-static inline bool
-all_ones (const Array<int>& arr)
-{
-  bool retval = true;
-
-  for (int i = 0; i < arr.length (); i++)
-    {
-      if (arr(i) != 1)
-	{
-	  retval = false;
-	  break;
-	}
-    }
-
-  return retval;
-}
-
-static Array<int>
-get_elt_idx (const Array<idx_vector>& ra_idx, const Array<int>& result_idx)
-{
-  int n = ra_idx.length ();
-
-  Array<int> retval (n);
-
-  for (int i = 0; i < n; i++)
-    retval(i) = ra_idx(i).elem (result_idx(i));
-
-  return retval;
-}
-
-static inline int
-number_of_elements (const dim_vector ra_idx)
-{
-  int retval = 1;
-
-  int n = ra_idx.length ();
-
-  if (n == 0)
-    retval = 0;
-
-  for (int i = 0; i < n; i++)
-    retval *= ra_idx(i);
-
-  return retval;
-}
-
-static inline Array<int>
-get_ra_idx (int idx, const dim_vector& dims)
-{
-  Array<int> retval;
-
-  int n_dims = dims.length ();
-
-  retval.resize (n_dims);
-
-  for (int i = 0; i < n_dims; i++)
-    retval(i) = 0;
-
-  assert (idx > 0 || idx < number_of_elements (dims));
-
-  for (int i = 0; i < idx; i++)
-    increment_index (retval, dims);
-
-  // XXX FIXME XXX -- the solution using increment_index is not
-  // efficient.
-
-#if 0
-  int var = 1;
-  for (int i = 0; i < n_dims; i++)
-    {
-      std::cout << "idx: " << idx << ", var: " << var << ", dims(" << i << "): " << dims(i) <<"\n";
-      retval(i) = ((int)floor(((idx) / (double)var))) % dims(i);
-      idx -= var * retval(i);
-      var = dims(i);
-    }
-#endif
-
-  return retval;
-}
-
-static inline dim_vector
-short_freeze (Array<idx_vector>& ra_idx, const dim_vector& dimensions,
-	      int resize_ok)
-{
-  dim_vector retval;
-
-  int n = ra_idx.length ();
-
-  int n_dims = dimensions.length ();
-
-  if (n == n_dims)
-    {
-      retval = freeze (ra_idx, dimensions, resize_ok);
-    }
-  else if (n < n_dims)
-    {
-      retval.resize (n);
-      
-      for (int i = 0; i < n - 1; i++)
-        retval(i) = ra_idx(i).freeze (dimensions(i), "dimension", resize_ok);
-
-      int size_left = 1;
-
-      for (int i = n - 1; i < n_dims; i++)
-        size_left *= dimensions(i); 
- 
-      if (ra_idx(n-1).is_colon())
-        {
-	  retval(n-1) = size_left;
-	}
-      else
-	{
-	  int last_ra_idx = ra_idx(n-1)(0);
-
-	  if (last_ra_idx < dimensions(n - 1))
-            {
-              retval(n - 1) = ra_idx(n - 1).freeze (dimensions(n-1),
-						    "dimension", resize_ok);
-            }
-          else
-            {
-              if (size_left <= last_ra_idx)
-                {
-         	  // Make it larger than it should be to get an error
-         	  // later.
-
-                  retval.resize(n_dims + 1);
-
-                  (*current_liboctave_error_handler)
-                    ("index exceeds N-d array dimensions");
-                }
-              else
-                {
-                  retval(n-1) = 1;
-                }
-	    }
-	}
-    }
-
-  return retval;
-}
-#endif
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/liboctave/ArrayN.cc	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/ArrayN.cc	Mon Nov 10 17:22:02 2003 +0000
@@ -33,8 +33,8 @@
 
 #include <iostream>
 
+#include "Array-util.h"
 #include "ArrayN.h"
-#include "ArrayN-inline.h"
 #include "ArrayN-idx.h"
 #include "idx-vector.h"
 #include "lo-error.h"
--- a/liboctave/CNDArray.cc	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/CNDArray.cc	Mon Nov 10 17:22:02 2003 +0000
@@ -29,12 +29,11 @@
 #include <config.h>
 #endif
 
+#include "Array-util.h"
 #include "CNDArray.h"
 #include "mx-base.h"
 #include "lo-ieee.h"
 
-#include "ArrayN-inline.h"
-
 // XXX FIXME XXX -- could we use a templated mixed-type copy function
 // here?
 
--- a/liboctave/ChangeLog	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/ChangeLog	Mon Nov 10 17:22:02 2003 +0000
@@ -1,5 +1,12 @@
 2003-11-10  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* Array.cc, ArrayN.cc, dNDArray.cc, CNDArray.cc, boolNDArray.cc,
+	chNDArray.cc: Include Array-util.h instead of ArrayN-inline.h.
+
+	* ArrayN-inline.h: Delete.
+	* Array-util.h, Array-util.cc: New files, from ArrayN-inline.h.
+	* Makefile.in: Fix the appropriate lists.
+
 	* Array.cc, Array.h, ArrayN.h, CMatrix.cc, CNDArray.h,
 	CRowVector.cc, CmplxQR.cc, CollocWt.h, DASPK.h, DASRT.h, DASSL.h,
 	FEGrid.cc, LP.h, LSODE.h, MArrayN.h, ODE.h, ODES.h, ODESSA.cc,
--- a/liboctave/Makefile.in	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/Makefile.in	Mon Nov 10 17:22:02 2003 +0000
@@ -26,7 +26,7 @@
 endif
 
 MATRIX_INC := Array.h Array2.h Array3.h ArrayN.h DiagArray2.h \
-	Array-flags.h ArrayN-idx.h ArrayN-inline.h MArray-defs.h \
+	Array-flags.h Array-util.h ArrayN-idx.h MArray-defs.h \
 	MArray.h MArray2.h MDiagArray2.h Matrix.h MArrayN.h \
 	base-lu.h dim-vector.h mx-base.h mx-op-defs.h mx-ops.h \
 	mx-defs.h mx-ext.h CColVector.h CDiagMatrix.h CMatrix.h \
@@ -73,14 +73,14 @@
 	Array-s.cc Array-str.cc Array-idx-vec.cc \
 	MArray-C.cc MArray-ch.cc MArray-i.cc MArray-d.cc MArray-s.cc
 
-MATRIX_SRC := Array-flags.cc CColVector.cc CDiagMatrix.cc CMatrix.cc \
-	CNDArray.cc CRowVector.cc CmplxAEPBAL.cc CmplxCHOL.cc \
-	CmplxDET.cc CmplxHESS.cc CmplxLU.cc CmplxQR.cc CmplxQRP.cc \
-	CmplxSCHUR.cc CmplxSVD.cc EIG.cc MArray-misc.cc MArrayN.cc \
-	boolMatrix.cc boolNDArray.cc chMatrix.cc chNDArray.cc \
-	dColVector.cc dDiagMatrix.cc \
-	dMatrix.cc dNDArray.cc dRowVector.cc dbleAEPBAL.cc \
-	dbleCHOL.cc dbleDET.cc dbleHESS.cc dbleLU.cc \
+MATRIX_SRC := Array-flags.cc Array-util.cc CColVector.cc \
+	CDiagMatrix.cc CMatrix.cc CNDArray.cc CRowVector.cc \
+	CmplxAEPBAL.cc CmplxCHOL.cc CmplxDET.cc CmplxHESS.cc \
+	CmplxLU.cc CmplxQR.cc CmplxQRP.cc CmplxSCHUR.cc CmplxSVD.cc \
+	EIG.cc MArray-misc.cc MArrayN.cc boolMatrix.cc \
+	boolNDArray.cc chMatrix.cc chNDArray.cc dColVector.cc \
+	dDiagMatrix.cc dMatrix.cc dNDArray.cc dRowVector.cc \
+	dbleAEPBAL.cc dbleCHOL.cc dbleDET.cc dbleHESS.cc dbleLU.cc \
 	dbleQR.cc dbleQRP.cc dbleSCHUR.cc dbleSVD.cc
 
 MX_OP_SRC := $(shell $(AWK) -f $(srcdir)/mk-ops.awk prefix=mx list_cc_files=1 $(srcdir)/mx-ops)
--- a/liboctave/boolNDArray.cc	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/boolNDArray.cc	Mon Nov 10 17:22:02 2003 +0000
@@ -29,12 +29,11 @@
 #include <config.h>
 #endif
 
+#include "Array-util.h"
 #include "CNDArray.h"
 #include "mx-base.h"
 #include "lo-ieee.h"
 
-#include "ArrayN-inline.h"
-
 // unary operations
 
 boolNDArray
--- a/liboctave/chNDArray.cc	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/chNDArray.cc	Mon Nov 10 17:22:02 2003 +0000
@@ -29,12 +29,11 @@
 #include <config.h>
 #endif
 
+#include "Array-util.h"
 #include "chNDArray.h"
 #include "mx-base.h"
 #include "lo-ieee.h"
 
-#include "ArrayN-inline.h"
-
 // XXX FIXME XXX -- this is not quite the right thing.
 
 boolNDArray
--- a/liboctave/dNDArray.cc	Mon Nov 10 15:50:40 2003 +0000
+++ b/liboctave/dNDArray.cc	Mon Nov 10 17:22:02 2003 +0000
@@ -29,13 +29,12 @@
 #include <config.h>
 #endif
 
+#include "Array-util.h"
 #include "dNDArray.h"
 #include "mx-base.h"
 #include "lo-error.h"
 #include "lo-ieee.h"
 
-#include "ArrayN-inline.h"
-
 NDArray::NDArray (const boolNDArray& a)
   : MArrayN<double> (a.dims ())
 {