# HG changeset patch # User John W. Eaton # Date 1216670817 14400 # Node ID a73b80cd1f10556e1e4641e5174aaf4ad60cfcb4 # Parent 9939bb6332a395818b081b79c5d8a9207757c826 allow empty matrix by cell (or struct) concatentation diff -r 9939bb6332a3 -r a73b80cd1f10 src/ChangeLog --- 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 + * 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. diff -r 9939bb6332a3 -r a73b80cd1f10 src/OPERATORS/op-cell.cc --- 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_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_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); } diff -r 9939bb6332a3 -r a73b80cd1f10 src/OPERATORS/op-struct.cc --- 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_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_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); } /* diff -r 9939bb6332a3 -r a73b80cd1f10 src/oct-map.cc --- 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; }