Mercurial > hg > octave-terminal
changeset 11793:db5518a14ea4 release-3-0-x
allow empty matrix by cell (or struct) concatentation
(transplanted from a73b80cd1f10556e1e4641e5174aaf4ad60cfcb4)
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 21 Jul 2008 16:06:57 -0400 |
parents | 70f6c0b493bc |
children | 77793a0fad3d |
files | src/ChangeLog src/OPERATORS/op-cell.cc src/OPERATORS/op-struct.cc src/oct-map.cc |
diffstat | 4 files changed, 87 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,12 @@ * dirfns.cc (Fmkdir): If directory already exists, return status = true, but also set error message. +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. + 2008-06-25 David Bateman <dbateman@free.fr> * pr-output.cc (Frats): Print usage if nargin == 0.
--- a/src/OPERATORS/op-cell.cc +++ b/src/OPERATORS/op-cell.cc @@ -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 +++ b/src/OPERATORS/op-struct.cc @@ -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 +++ b/src/oct-map.cc @@ -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; }