changeset 7959:a73b80cd1f10

allow empty matrix by cell (or struct) concatentation
author John W. Eaton <jwe@octave.org>
date Mon, 21 Jul 2008 16:06:57 -0400
parents 9939bb6332a3
children 22a18f206121
files src/ChangeLog src/OPERATORS/op-cell.cc src/OPERATORS/op-struct.cc src/oct-map.cc
diffstat 4 files changed, 85 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Jul 21 15:27:22 2008 -0400
+++ b/src/ChangeLog	Mon Jul 21 16:06:57 2008 -0400
@@ -1,5 +1,9 @@
 2008-07-21  John W. Eaton  <jwe@octave.org>
 
+	* OPERATORS/op-struct.cc: Define concatenation operators for
+	struct/matrix concatenation (valid if matrix is empty).
+	* OPERATORS/op-cell.cc (install_cell_ops): Likewise, for cells.
+
 	* DLD-FUNCTIONS/fltk_backend.cc: Don't include oct.h.
 	Make compilation of entire file conditional on HAVE_FLTK.
 
--- a/src/OPERATORS/op-cell.cc	Mon Jul 21 15:27:22 2008 -0400
+++ b/src/OPERATORS/op-cell.cc	Mon Jul 21 16:06:57 2008 -0400
@@ -50,6 +50,36 @@
 
 DEFCATOP_FN (c_c, cell, cell, concat)
 
+static octave_value
+oct_catop_cell_matrix (octave_base_value& a1, const octave_base_value& a2,
+			 const Array<octave_idx_type>&)
+{
+  octave_value retval;
+  CAST_BINOP_ARGS (const octave_cell&, const octave_matrix&);
+  NDArray tmp = v2.array_value ();
+  dim_vector dv = tmp.dims ();
+  if (dv.all_zero ())
+    retval = octave_value (v1.cell_value ());
+  else
+    error ("invalid concatenation of cell array with matrix");
+  return retval;
+}
+
+static octave_value
+oct_catop_matrix_cell (octave_base_value& a1, const octave_base_value& a2,
+			 const Array<octave_idx_type>&)
+{
+  octave_value retval;
+  CAST_BINOP_ARGS (const octave_cell&, const octave_matrix&);
+  NDArray tmp = v1.array_value ();
+  dim_vector dv = tmp.dims ();
+  if (dv.all_zero ())
+    retval = octave_value (v2.cell_value ());
+  else
+    error ("invalid concatenation of cell array with matrix");
+  return retval;
+}
+
 DEFASSIGNANYOP_FN (assign, cell, assign);
 
 void
@@ -60,6 +90,9 @@
 
   INSTALL_CATOP (octave_cell, octave_cell, c_c);
 
+  INSTALL_CATOP (octave_cell, octave_matrix, cell_matrix);
+  INSTALL_CATOP (octave_matrix, octave_cell, matrix_cell);
+
   INSTALL_ASSIGNANYOP (op_asn_eq, octave_cell, assign);
 }
 
--- a/src/OPERATORS/op-struct.cc	Mon Jul 21 15:27:22 2008 -0400
+++ b/src/OPERATORS/op-struct.cc	Mon Jul 21 16:06:57 2008 -0400
@@ -27,6 +27,7 @@
 #include "gripes.h"
 #include "oct-obj.h"
 #include "ov.h"
+#include "ov-re-mat.h"
 #include "ov-struct.h"
 #include "ov-typeinfo.h"
 #include "ops.h"
@@ -48,6 +49,36 @@
 
 DEFNDCATOP_FN (struct_struct, struct, struct, map, map, concat)
 
+static octave_value
+oct_catop_struct_matrix (octave_base_value& a1, const octave_base_value& a2,
+			 const Array<octave_idx_type>&)
+{
+  octave_value retval;
+  CAST_BINOP_ARGS (const octave_struct&, const octave_matrix&);
+  NDArray tmp = v2.array_value ();
+  dim_vector dv = tmp.dims ();
+  if (dv.all_zero ())
+    retval = octave_value (v1.map_value ());
+  else
+    error ("invalid concatenation of structure with matrix");
+  return retval;
+}
+
+static octave_value
+oct_catop_matrix_struct (octave_base_value& a1, const octave_base_value& a2,
+			 const Array<octave_idx_type>&)
+{
+  octave_value retval;
+  CAST_BINOP_ARGS (const octave_struct&, const octave_matrix&);
+  NDArray tmp = v1.array_value ();
+  dim_vector dv = tmp.dims ();
+  if (dv.all_zero ())
+    retval = octave_value (v2.map_value ());
+  else
+    error ("invalid concatenation of structure with matrix");
+  return retval;
+}
+
 void
 install_struct_ops (void)
 {
@@ -55,6 +86,8 @@
   INSTALL_UNOP (op_hermitian, octave_struct, transpose);
 
   INSTALL_CATOP (octave_struct, octave_struct, struct_struct);
+  INSTALL_CATOP (octave_struct, octave_matrix, struct_matrix);
+  INSTALL_CATOP (octave_matrix, octave_struct, matrix_struct);
 }
 
 /*
--- a/src/oct-map.cc	Mon Jul 21 15:27:22 2008 -0400
+++ b/src/oct-map.cc	Mon Jul 21 16:06:57 2008 -0400
@@ -222,7 +222,21 @@
 	}
     }
   else
-    error ("field name mismatch in structure concatenation");
+    {
+      dim_vector dv = dims ();
+
+      if (dv.all_zero ())
+	retval = rb;
+      else
+	{
+	  dv = rb.dims ();
+
+	  if (dv.all_zero ())
+	    retval = *this;
+	  else
+	    error ("invalid structure concatenation");
+	}
+    }
 
   return retval;
 }