octave-maintainers
[Top][All Lists]
Advanced

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

Re: Slowup in 2.1.54


From: John W. Eaton
Subject: Re: Slowup in 2.1.54
Date: Wed, 18 Feb 2004 06:52:01 -0600

On 18-Feb-2004, David Bateman <address@hidden> wrote:

| So to me the problem is clearly in the concatenation operations, not
| the recursion. Interestingly the above allows an estimate of the slowup
| in the concatenation operation to be derived as
| 
| (40.233 - 2.6302) / (6.1742 - 2.9223) = 11.563
| 
| So there is a factor of roughly 11 slowup in the concatenation operations.

I think the following change should help.

Thanks,

jwe


liboctave/ChangeLog:

2004-02-18  John W. Eaton  <address@hidden>

        * Array.cc (Array<T>::insertN (const Array<T>&, int, int)):
        Rename from Array<T>::insert.
        (Array<T>::insert2 (const Array<T>&, int, int)):
        Reinstate old Array<T>::insert function under this name.
        (Array<T>::insert (const Array<T>&, int, int)):
        New function.  Dispatch to insert2 or insertN as appropriate.


Index: liboctave/Array.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/liboctave/Array.cc,v
retrieving revision 1.104
diff -u -r1.104 Array.cc
--- liboctave/Array.cc  16 Feb 2004 05:56:50 -0000      1.104
+++ liboctave/Array.cc  18 Feb 2004 12:50:17 -0000
@@ -931,6 +931,39 @@
 Array<T>&
 Array<T>::insert (const Array<T>& a, int r, int c)
 {
+  if (ndims () == 2 && a.ndims () == 2)
+    insert2 (a, r, c);
+  else
+    insertN (a, r, c);
+
+  return *this;
+}
+
+
+template <class T>
+Array<T>&
+Array<T>::insert2 (const Array<T>& a, int r, int c)
+{
+  int a_rows = a.rows ();
+  int a_cols = a.cols ();
+
+  if (r < 0 || r + a_rows > rows () || c < 0 || c + a_cols > cols ())
+    {
+      (*current_liboctave_error_handler) ("range error for insert");
+      return *this;
+    }
+
+  for (int j = 0; j < a_cols; j++)
+    for (int i = 0; i < a_rows; i++)
+      elem (r+i, c+j) = a.elem (i, j);
+
+  return *this;
+}
+
+template <class T>
+Array<T>&
+Array<T>::insertN (const Array<T>& a, int r, int c)
+{
   dim_vector a_dv = a.dims ();
 
   int n = a_dv.length ();
Index: liboctave/Array.h
===================================================================
RCS file: /usr/local/cvsroot/octave/liboctave/Array.h,v
retrieving revision 1.84
diff -u -r1.84 Array.h
--- liboctave/Array.h   16 Feb 2004 05:07:23 -0000      1.84
+++ liboctave/Array.h   18 Feb 2004 12:50:17 -0000
@@ -446,8 +446,10 @@
     { resize_and_fill (dv, val); }
 
   Array<T>& insert (const Array<T>& a, int r, int c);
+  Array<T>& insert2 (const Array<T>& a, int r, int c);
+  Array<T>& insertN (const Array<T>& a, int r, int c);
 
-  Array<T>& insert (const Array<T>& a, const Array<int>& dv);
+  Array<T>& insert (const Array<T>& a, const Array<int>& idx);
 
   bool is_square (void) const { return (dim1 () == dim2 ()); }
 



reply via email to

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