changeset 8147:9a5ef4f632a3

Add class dispatch for [] operator to vertcat/horzcat methods
author David Bateman <dbateman@free.fr>
date Thu, 25 Sep 2008 13:03:17 -0400
parents a9ec011ead94
children 213dd524f96b
files src/ChangeLog src/pt-mat.cc
diffstat 2 files changed, 89 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Sep 25 10:19:17 2008 -0400
+++ b/src/ChangeLog	Thu Sep 25 13:03:17 2008 -0400
@@ -1,3 +1,11 @@
+2008-09-25  David Bateman  <dbateman@free.fr>
+
+	* pt-mat.cc (class tm_row_const): Add any_class test
+	(class tm_const): Ditto.
+	(octave_value tree_matrix::rvalue (void)): If any object to
+	concatenate is a class object, dispatch to the appropriate
+	vertcat/horzcat function.
+
 2008-09-25  John W. Eaton  <jwe@octave.org>
 
 	* symtab.cc (symbol_table::do_find): Don't set evaluated_args and
--- a/src/pt-mat.cc	Thu Sep 25 10:19:17 2008 -0400
+++ b/src/pt-mat.cc	Thu Sep 25 13:03:17 2008 -0400
@@ -67,14 +67,14 @@
       : count (1), dv (0, 0), all_str (false),
 	all_sq_str (false), all_dq_str (false),
 	some_str (false), all_real (false), all_cmplx (false),
-	all_mt (true), any_sparse (false),
+	all_mt (true), any_sparse (false), any_class (false),
 	class_nm (octave_base_value::static_class_name ()), ok (false)
     { }
 
     tm_row_const_rep (const tree_argument_list& row)
       : count (1), dv (0, 0), all_str (false), all_sq_str (false),
 	some_str (false), all_real (false), all_cmplx (false),
-	all_mt (true), any_sparse (false),
+	all_mt (true), any_sparse (false), any_class (false),
 	class_nm (octave_base_value::static_class_name ()), ok (false)
     { init (row); }
 
@@ -92,6 +92,7 @@
     bool all_cmplx;
     bool all_mt;
     bool any_sparse;
+    bool any_class;
 
     std::string class_nm;
 
@@ -158,6 +159,8 @@
 
   bool empty (void) const { return rep->empty (); }
 
+  size_t length (void) const { return rep->length (); }
+
   dim_vector dims (void) { return rep->dv; }
 
   bool all_strings_p (void) const { return rep->all_str; }
@@ -168,6 +171,7 @@
   bool all_complex_p (void) const { return rep->all_cmplx; }
   bool all_empty_p (void) const { return rep->all_mt; }
   bool any_sparse_p (void) const { return rep->any_sparse; }
+  bool any_class_p (void) const { return rep->any_class; }
 
   std::string class_name (void) const { return rep->class_nm; }
 
@@ -345,6 +349,9 @@
   if (!any_sparse && val.is_sparse_type ())
     any_sparse = true;
 
+  if (!any_class && val.is_object ())
+    any_class = true;
+
   return true;
 }
 
@@ -357,6 +364,7 @@
   all_real = true;
   all_cmplx = true;
   any_sparse = false;
+  any_class = false;
 
   bool first_elem = true;
 
@@ -438,7 +446,7 @@
   tm_const (const tree_matrix& tm)
     : dv (0, 0), all_str (false), all_sq_str (false), all_dq_str (false),
       some_str (false), all_real (false), all_cmplx (false),
-      all_mt (true), any_sparse (false),
+      all_mt (true), any_sparse (false), any_class (false),
       class_nm (octave_base_value::static_class_name ()), ok (false)
   { init (tm); }
 
@@ -457,6 +465,7 @@
   bool all_complex_p (void) const { return all_cmplx; }
   bool all_empty_p (void) const { return all_mt; }
   bool any_sparse_p (void) const { return any_sparse; }
+  bool any_class_p (void) const { return any_class; }
 
   std::string class_name (void) const { return class_nm; }
 
@@ -474,6 +483,7 @@
   bool all_cmplx;
   bool all_mt;
   bool any_sparse;
+  bool any_class;
 
   std::string class_nm;
 
@@ -497,6 +507,7 @@
   all_real = true;
   all_cmplx = true;
   any_sparse = false;
+  any_class = false;
 
   bool first_elem = true;
 
@@ -539,6 +550,9 @@
 	  if (!any_sparse && tmp.any_sparse_p ())
 	    any_sparse = true;
 
+	  if (!any_class && tmp.any_class_p ())
+	    any_class = true;
+
 	  append (tmp);
 	}
       else
@@ -769,6 +783,7 @@
   bool all_real_p = false;
   bool all_complex_p = false;
   bool any_sparse_p = false;
+  bool any_class_p = false;
   bool frc_str_conv = false;
 
   tm_const tmp (*this);
@@ -783,13 +798,75 @@
       all_real_p = tmp.all_real_p ();
       all_complex_p = tmp.all_complex_p ();
       any_sparse_p = tmp.any_sparse_p ();
+      any_class_p = tmp.any_class_p ();
       frc_str_conv = tmp.some_strings_p ();
 
       // Try to speed up the common cases.
 
       std::string result_type = tmp.class_name ();
 
-      if (result_type == "double")
+      if (any_class_p)
+	{
+	  octave_value_list tmp3 (tmp.length (), octave_value ());
+
+	  int j = 0;
+	  for (tm_const::iterator p = tmp.begin (); p != tmp.end (); p++)
+	    {
+	      OCTAVE_QUIT;
+
+	      tm_row_const row = *p;
+
+	      if (row.length () == 1)
+		tmp3 (j++) = *(row.begin ());
+	      else
+		{
+		  octave_value_list tmp1 (row.length (), octave_value ());
+
+		  int i = 0;
+		  for (tm_row_const::iterator q = row.begin (); 
+		       q != row.end (); q++)
+		    tmp1 (i++) = *q;
+
+		  octave_value_list tmp2;
+		  octave_value fcn = 
+		    symbol_table::find_function ("horzcat", tmp1);
+
+		  if (fcn.is_defined ())
+		    {
+		      tmp2 = fcn.do_multi_index_op (1, tmp1);
+		      
+		      if (error_state)
+			goto done;
+
+		      tmp3 (j++) = tmp2 (0);
+		    }
+		  else
+		    {
+		      ::error ("cat not find overloaded horzcat function");
+		      goto done;
+		    }
+		}
+	    }
+
+	  if (tmp.length () == 1)
+	    retval = tmp3 (0);
+	  else
+	    {
+	      octave_value_list tmp2;
+	      octave_value fcn = symbol_table::find_function ("vertcat", tmp3);
+
+	      if (fcn.is_defined ())
+		{
+		  tmp2 = fcn.do_multi_index_op (1, tmp3);
+		      
+		  if (! error_state)
+		    retval = tmp2 (0);
+		}
+	      else
+		::error ("cat not find overloaded vertcat function");
+	    }
+	}
+      else if (result_type == "double")
 	{
 	  if (any_sparse_p)
 	    {