changeset 8107:8655dc0906e6

Special case single type conacation in Fcat. Rework cell2mat to take advantage
author David Bateman <dbateman@free.fr>
date Wed, 17 Sep 2008 14:37:49 -0400
parents 8a42498edb30
children a7631489ecf5
files scripts/ChangeLog scripts/general/cell2mat.m src/ChangeLog src/data.cc src/pt-mat.cc src/pt-mat.h
diffstat 6 files changed, 96 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Sep 17 14:40:04 2008 -0400
+++ b/scripts/ChangeLog	Wed Sep 17 14:37:49 2008 -0400
@@ -1,3 +1,8 @@
+2008-09-17  David Bateman  <dbateman@free.fr>
+
+	* general/cell2mat.m: Backout previous change. Special case 2D
+	case for speed.
+
 2008-09-11  David Bateman  <dbateman@free.fr>
 
 	* general/cell2mat.m: Improve the speed.
--- a/scripts/general/cell2mat.m	Wed Sep 17 14:40:04 2008 -0400
+++ b/scripts/general/cell2mat.m	Wed Sep 17 14:37:49 2008 -0400
@@ -50,44 +50,34 @@
     endif
   elseif (ndims (c) == 2)
     nr = rows (c);
-    c1 = cell (nr, 1);
-    for i = 1 : nr
-      c1{i} = [c{i : nr : end}];
-    endfor
-    ## This is faster than "c = cat(1, c{:})"
-    m = [cellfun(@(x) x.', c1, "UniformOutput", false){:}].';
+    nc = columns (c);
+    if (nc > nr)
+      c1 = cell (nr, 1);
+      for i = 1 : nr
+	c1{i} = [c{i : nr : end}];
+      endfor
+      m = cat (1, c1 {:});
+    else
+      c1 = cell (nc, 1);
+      for i = 1 : nc
+	c1{i} = cat (1, c{(i - 1) * nr  + [1 : nr]});
+      endfor
+      m = [c1{:}];
+    endif
   else
-   nd = ndims (c);
-   for k = nd : -1 : 2
+    ## n dimensions case
+    for k = ndims (c):-1:2,
       sz = size (c);
-      if (k > ndims (c) || sz(end) == 1)
-	continue;
-      endif
       sz(end) = 1;
       c1 = cell (sz);
-      sz = prod (sz);
-      if (k == 2)
-        for i = 1 : sz
-	  c1{i} = [c{i : sz : end}];
-        endfor
-      else
-        ## This is faster than
-        ##   for i = 1:sz, c1{i} = cat (k, c{i:(prod (sz)):end}); endfor
-	idx = [1, k, (3 : (k - 1)), 2, ((k + 1): nd)];
-        c = cellfun(@(x) permute (x, idx), c, "UniformOutput", false);
-        for i = 1: sz
-	  c1{i} = ipermute ([c{i : sz : end}], idx);
-        endfor
-      endif
+      for i = 1:(prod (sz))
+        c1{i} = cat (k, c{i:(prod (sz)):end});
+      endfor
       c = c1;
     endfor
-    if (numel (c) > 1)
-      idx = [2, 1, 3 : nd];
-      m = ipermute([cellfun(@(x) permute (x, idx), c, "UniformOutput", false){:}], idx);
-    else
-      m = c{1};
-    endif
+    m = cat (1, c1{:});
   endif
+
 endfunction
 
 ## Tests
--- a/src/ChangeLog	Wed Sep 17 14:40:04 2008 -0400
+++ b/src/ChangeLog	Wed Sep 17 14:37:49 2008 -0400
@@ -2,6 +2,17 @@
 
 	* DLD-FUNCTIONS/sparse.cc (Fsparse): Clarify the help string.
 
+2008-09-17  David Bateman  <dbateman@free.fr>
+
+	* data.cc (SINGLE_TYPE_CONCAT, DO_SINGLE_TYPE_CONCAT): New macros
+	(do_cat): Special case single type concatenations for speed.
+	* pt.mat.cc (std::string get_concat_class (const std::string&,
+	const std::string&), void maybe_warn_string_concat (bool, bool)):
+	Remove static declaration.
+	* pt-mat.h (std::string get_concat_class (const std::string&,
+	const std::string&), void maybe_warn_string_concat (bool, bool)):
+	Define extern here.
+	
 2008-09-10  John W. Eaton  <jwe@octave.org>
 
 	* octave.cc (octave_main): Make all command-line arguments
--- a/src/data.cc	Wed Sep 17 14:40:04 2008 -0400
+++ b/src/data.cc	Wed Sep 17 14:37:49 2008 -0400
@@ -1718,6 +1718,51 @@
 
  */
 
+#define SINGLE_TYPE_CONCAT(TYPE, EXTRACTOR) \
+  do \
+    { \
+      int dv_len = dv.length (); \
+      Array<octave_idx_type> ra_idx (dv_len > 1 ? dv_len : 2, 0); \
+      \
+      for (int j = 1; j < n_args; j++) \
+	{ \
+	  OCTAVE_QUIT; \
+	  \
+	  TYPE ra = args(j).EXTRACTOR ();	\
+	  \
+	  if (! error_state) \
+	    { \
+	      result.insert (ra, ra_idx); \
+	      \
+	      if (error_state) \
+	        return retval; \
+	      \
+	      dim_vector dv_tmp = args (j).dims (); \
+	      \
+	      if (dim >= dv_len) \
+	        { \
+		  if (j > 1) \
+		    error ("%s: indexing error", fname.c_str ()); \
+		  break; \
+		} \
+	      else \
+		ra_idx (dim) += (dim < dv_tmp.length () ? dv_tmp (dim) : 1); \
+	    } \
+	} \
+    } \
+ while (0)
+
+#define DO_SINGLE_TYPE_CONCAT(TYPE, EXTRACTOR) \
+  do \
+    { \
+      TYPE result (dv); \
+      \
+      SINGLE_TYPE_CONCAT(TYPE, EXTRACTOR); \
+      \
+      retval = result; \
+    } \
+ while (0)
+
 static octave_value
 do_cat (const octave_value_list& args, std::string fname)
 {
@@ -1743,7 +1788,13 @@
 	{
  	  
  	  dim_vector  dv = args(1).dims ();
+	  std::string result_type = args(1).class_name ();
 	  
+	  bool all_sq_strings_p = args(1).is_sq_string ();
+	  bool all_dq_strings_p = args(1).is_dq_string ();
+	  bool all_real_p = args(1).is_real_type ();
+	  bool any_sparse_p = args(1).is_sparse_type();
+
  	  for (int i = 2; i < args.length (); i++)
   	    {
  	      // add_dims constructs a dimension vector which holds the
--- a/src/pt-mat.cc	Wed Sep 17 14:40:04 2008 -0400
+++ b/src/pt-mat.cc	Wed Sep 17 14:37:49 2008 -0400
@@ -184,7 +184,7 @@
   tm_row_const_rep *rep;
 };
 
-static std::string
+std::string
 get_concat_class (const std::string& c1, const std::string& c2)
 {
   std::string retval = octave_base_value::static_class_name ();
@@ -699,7 +699,7 @@
   return retval;
 }
 
-static void
+void
 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p)
 {
   if (! (all_dq_strings_p || all_sq_strings_p))
--- a/src/pt-mat.h	Wed Sep 17 14:40:04 2008 -0400
+++ b/src/pt-mat.h	Wed Sep 17 14:37:49 2008 -0400
@@ -81,6 +81,12 @@
 // The character to fill with when creating string arrays.
 extern char Vstring_fill_char;
 
+extern std::string 
+get_concat_class (const std::string& c1, const std::string& c2);
+
+extern void
+maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p);
+
 #endif
 
 /*