From octave-maintainers-request at bevo dot che dot wisc dot edu Fri May 3 15:05:44 2002 Subject: Cell array changes for Octave From: "John W. Eaton" To: Cai Jianming cc: octave-maintainers mailing list Date: Fri, 3 May 2002 15:04:39 -0500 Sorry for the long delay. I've included your cell array changes for Octave, along with some modifications. There is still some more work to do to properly support "x{ }" style indexing, but most of the other functionality is now present. We can start to write functions that depend on Cells and distribute them with Octave 2.1.x. These changes will appear in Octave 2.1.37, which I plan to release before the end of May. When N-dimensional matrices are added, Cell arrays should also become N-dimensional. I'm checking these changes in to my CVS archive now, and they should appear in the public CVS archive within a few minutes. Here are some examples: octave:1> x(2,2) = {rand (2)} x = { [1,1] = [](0x0) [2,1] = [](0x0) [1,2] = [](0x0) [2,2] = 0.69171 0.30553 0.51120 0.45207 } octave:2> y = {"foo", 1; "bar", rand (2) } y = { [1,1] = foo [2,1] = bar [1,2] = 1 [2,2] = 0.9085413 0.0066769 0.0300384 0.1790675 } octave:3> y(1,2) = x error: A(I, J) = X: X must be a scalar or the number of elements in I must error: match the number of rows in X and the number of elements in J must error: match the number of columns in X error: evaluating assignment expression near line 3, column 8 octave:3> y{1,2} = x error: A(I, J) = X: X must be a scalar or the number of elements in I must error: match the number of rows in X and the number of elements in J must error: match the number of columns in X error: evaluating assignment expression near line 3, column 8 octave:3> y(1,2) = rand (2) y = { [1,1] = foo [2,1] = bar [1,2] = 0.61576 0.64972 0.25928 0.22176 [2,2] = 0.9085413 0.0066769 0.0300384 0.1790675 } octave:4> y(1,2) = [] y = { [1,1] = foo [2,1] = bar [1,2] = [](0x0) [2,2] = 0.9085413 0.0066769 0.0300384 0.1790675 } octave:5> y(1,3) = 2 y = { [1,1] = foo [2,1] = bar [1,2] = [](0x0) [2,2] = 0.9085413 0.0066769 0.0300384 0.1790675 [1,3] = 2 [2,3] = [](0x0) } octave:6> y(:,1) ans = { [1,1] = foo [2,1] = bar } So you can see that indexing to insert a cell inside a cell doesn't work yet. I need to make "x{ }" style indexing and indexed assignment call different functions than are used for the "x( )" style indexing and indexed assignmend operations. Some questions: * Should the output look more like Matlab? I don't care, but I think the output needs to be formatted a little better than it is now (indented and no extra blank link between the "=" and the "{"). * What should happen for output that is going to be really large? Should Octave just generate it, or produce a short message? Should the behavior be different for interactive vs. batch usage? * Should we implement lists as a special case of Cell arrays? I think yes, but maybe there is a reason not to? Should lists be marked as deprecated and removed in a future version of Octave? Thanks, jwe src/ChangeLog ============= 2002-05-03 John W. Eaton * ov-base.cc (cell_conv): New conversion function. (install_base_type_conversions): Install it. Install conversion for indexed assignment of octave_cells to undefined values. * TEMPLATE-INST/Array-tc.cc: Instantiate assign functions too. (Array::resize_fill_value (void)): Provide specialization for octave_value. * ov-cell.cc (octave_cell::assign (const octave_value_list&, const octave_value&)): New function. * Cell.h (Cell::Cell (const octave_value&)): New function. * OPERATORS/op-cell.cc (install_list_ops): Use DEFASSIGNANYOP_FN and INSTALL_ASSIGNANYOP, not DEFASSIGNOP_FN and INSTALL_ASSIGNOP. 2002-05-03 Cai Jianming * OPERATORS/op-cell.cc: New file. * src/Makefile.in (OP_XSRC): Include it in the list. * parse.y (cell): Return a cell type instead of Matrix type. * ov.cc (install_types): Install octave_cell type. * pr-output.cc (octave_print_internal): Handle Cells. * pr-output.h (octave_print_internal): Provide decl. * ov-cell.h (octave_cell): Derive from octave_base_matrix. * ov-cell.cc (do_index_op, assign, print, print_raw, print_name_tag): Delete. * Cell.cc (allocator, index): Delete. * Cell.h (Cell): Derive from Array2. Most functions removed since we can use those from Array2 instead. 2002-05-02 Cai Jianming * ov-base-mat.cc (octave_base_matrix::assign): New function. * ov-base-mat.h (octave_base_matrix::assign): Provide decl. * ov-bool-mat.cc (octave_bool_matrix::assign): Delete. * ov-bool-mat.h (octave_bool_matrix:assign): Delete decl * ov-cx-mat.cc (octave_complex_matrix::assign (const octave_value_list& idx, const ComplexMatrix&)): Delete. * ov-cx-mat.h (octave_complex_matrix:assign (const octave_value_list& idx, const ComplexMatrix&)): Replace decl with function. * ov-re-mat.cc (octave_bool_matrix::assign): Delete. * ov-re-mat.h (octave_bool_matrix:assign): Delete decl. liboctave/ChangeLog =================== 2002-05-03 John W. Eaton * idx-vector.h (idx_vector::idx_vector (int)): New function. (idx_vector_rep::idx_vector_rep (int)): New decl. * idx-vector.cc (idx_vector_rep::idx_vector_rep (int)): New function. * Array.h (Array::resize_fill_value (void)): New static function. (assign (Array&, const Array&)): Use it. * Array2.h (assign (Array2&, const Array2&)): Use it. * ArrayN.h (assign (ArrayN&, const ArrayN&)): Use it. 2002-05-02 Cai Jianming * Array3.h (Array3::checkelem): Improve error message. * ArrayN.h (ArrayN::range_error): Likewise. * DiagArray2.cc (DiagArray2::checkelem): Likewise. * DiagArray2.cc (DiagArray2::operator ()): Likewise. Index: doc/interpreter/preface.txi =================================================================== RCS file: /usr/local/cvsroot/octave/doc/interpreter/preface.txi,v retrieving revision 1.5 diff -u -r1.5 preface.txi --- doc/interpreter/preface.txi 1 May 2002 02:51:30 -0000 1.5 +++ doc/interpreter/preface.txi 3 May 2002 19:33:37 -0000 at @ -117,6 +117,10 @@ new ideas for improving Octave. at item +Cai Jianming at email{caijianming@@yahoo dot co dot uk} contributed the inital +cell array implementation. + + at item Phil Johnson at email{johnsonp@@nicco dot sscnet dot ucla dot edu} has helped to make Linux releases available. Index: liboctave/Array.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Array.h,v retrieving revision 1.57 diff -u -r1.57 Array.h --- liboctave/Array.h 31 May 2001 19:30:50 -0000 1.57 +++ liboctave/Array.h 3 May 2002 19:33:38 -0000 at @ -248,6 +248,8 @@ Array index (idx_vector& i) const; #endif + + static T resize_fill_value (void) { return static_cast (0); } }; template at @ -258,7 +260,7 @@ int assign (Array& lhs, const Array& rhs) { - return assign (lhs, rhs, static_cast (0)); + return assign (lhs, rhs, Array::resize_fill_value ()); } #endif Index: liboctave/Array2.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Array2.h,v retrieving revision 1.20 diff -u -r1.20 Array2.h --- liboctave/Array2.h 31 May 2001 19:30:50 -0000 1.20 +++ liboctave/Array2.h 3 May 2002 19:33:38 -0000 at @ -194,7 +194,7 @@ int assign (Array2& lhs, const Array2& rhs) { - return assign (lhs, rhs, static_cast (0)); + return assign (lhs, rhs, Array::resize_fill_value ()); } #endif Index: liboctave/Array3.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Array3.h,v retrieving revision 1.11 diff -u -r1.11 Array3.h --- liboctave/Array3.h 31 May 2001 19:30:50 -0000 1.11 +++ liboctave/Array3.h 3 May 2002 19:33:38 -0000 at @ -113,7 +113,7 @@ { if (i < 0 || j < 0 || k < 0 || i >= d1 || j >= d2 || k >= d3) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in Array3"); static T foo; return foo; } at @ -132,7 +132,7 @@ { if (i < 0 || j < 0 || k < 0 || i >= d1 || j >= d2 || k >= d3) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in Array3"); return T (); } return Array2::elem (i, d1*k+j); Index: liboctave/ArrayN.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/ArrayN.cc,v retrieving revision 1.2 diff -u -r1.2 ArrayN.cc --- liboctave/ArrayN.cc 6 Feb 2001 01:57:00 -0000 1.2 +++ liboctave/ArrayN.cc 3 May 2002 19:33:38 -0000 at @ -137,7 +137,7 @@ { // XXX FIXME XXX -- report index values too! - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in ArrayN"); return T (); } at @ -148,7 +148,7 @@ { // XXX FIXME XXX -- report index values too! - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in ArrayN"); static T foo; return foo; Index: liboctave/ArrayN.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/ArrayN.h,v retrieving revision 1.2 diff -u -r1.2 ArrayN.h --- liboctave/ArrayN.h 31 May 2001 19:30:50 -0000 1.2 +++ liboctave/ArrayN.h 3 May 2002 19:33:38 -0000 at @ -193,7 +193,7 @@ int assign (ArrayN& lhs, const ArrayN& rhs) { - return assign (lhs, rhs, static_cast (0)); + return assign (lhs, rhs, Array::resize_fill_value ()); } template Index: liboctave/DiagArray2.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/DiagArray2.cc,v retrieving revision 1.5 diff -u -r1.5 DiagArray2.cc --- liboctave/DiagArray2.cc 1 Feb 2000 04:06:11 -0000 1.5 +++ liboctave/DiagArray2.cc 3 May 2002 19:33:41 -0000 at @ -55,7 +55,7 @@ static T foo (0); if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return foo; } return (r == c) ? Array::xelem (r) : foo; at @ -68,7 +68,7 @@ static T foo (0); if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return foo; } return (r == c) ? Array::xelem (r) : foo; at @ -88,7 +88,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return T (); } return (r == c) ? Array::xelem (r) : T (0); at @ -100,7 +100,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return T (); } return (r == c) ? Array::xelem (r) : T (0); Index: liboctave/DiagArray2.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/DiagArray2.h,v retrieving revision 1.5 diff -u -r1.5 DiagArray2.h --- liboctave/DiagArray2.h 8 Feb 2000 04:35:42 -0000 1.5 +++ liboctave/DiagArray2.h 3 May 2002 19:33:41 -0000 at @ -201,7 +201,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); } else at @ -212,7 +212,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); } else Index: liboctave/idx-vector.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/idx-vector.cc,v retrieving revision 1.49 diff -u -r1.49 idx-vector.cc --- liboctave/idx-vector.cc 8 Jun 2000 20:06:17 -0000 1.49 +++ liboctave/idx-vector.cc 3 May 2002 19:33:42 -0000 at @ -75,7 +75,15 @@ static inline int tree_to_mat_idx (double x) { - return (x > 0) ? ((int) (x + 0.5) - 1) : ((int) (x - 0.5) - 1); + return (x > 0) + ? (static_cast (x + 0.5) - 1) + : (static_cast (x - 0.5) - 1); +} + +static inline int +tree_to_mat_idx (int i) +{ + return i - 1; } static inline bool at @ -183,33 +191,6 @@ init_state (); } -IDX_VEC_REP::idx_vector_rep (double d) -{ - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 0; - - len = 1; - - orig_nr = 1; - orig_nc = 1; - - if (idx_is_inf_or_nan (d)) - return; - else - { - data = new int [len]; - - data[0] = tree_to_mat_idx (d); - } - - init_state (); -} - IDX_VEC_REP::idx_vector_rep (const Range& r) { data = 0; at @ -254,6 +235,55 @@ else data[i] = tree_to_mat_idx (val); } + + init_state (); +} + +IDX_VEC_REP::idx_vector_rep (double d) +{ + data = 0; + initialized = 0; + frozen = 0; + colon_equiv_checked = 0; + colon_equiv = 0; + colon = 0; + one_zero = 0; + + len = 1; + + orig_nr = 1; + orig_nc = 1; + + if (idx_is_inf_or_nan (d)) + return; + else + { + data = new int [len]; + + data[0] = tree_to_mat_idx (d); + } + + init_state (); +} + +IDX_VEC_REP::idx_vector_rep (int i) +{ + data = 0; + initialized = 0; + frozen = 0; + colon_equiv_checked = 0; + colon_equiv = 0; + colon = 0; + one_zero = 0; + + len = 1; + + orig_nr = 1; + orig_nc = 1; + + data = new int [len]; + + data[0] = tree_to_mat_idx (i); init_state (); } Index: liboctave/idx-vector.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/idx-vector.h,v retrieving revision 1.36 diff -u -r1.36 idx-vector.h --- liboctave/idx-vector.h 1 Feb 2000 10:07:15 -0000 1.36 +++ liboctave/idx-vector.h 3 May 2002 19:33:42 -0000 at @ -68,6 +68,8 @@ idx_vector_rep (double d); + idx_vector_rep (int i); + idx_vector_rep (char c); idx_vector_rep (bool b); at @ -167,6 +169,12 @@ idx_vector (double d) { rep = new idx_vector_rep (d); + rep->count = 1; + } + + idx_vector (int i) + { + rep = new idx_vector_rep (i); rep->count = 1; } Index: src/Cell.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/Cell.cc,v retrieving revision 1.2 diff -u -r1.2 Cell.cc --- src/Cell.cc 17 Nov 1999 19:06:13 -0000 1.2 +++ src/Cell.cc 3 May 2002 19:33:42 -0000 at @ -30,20 +30,6 @@ #include "Cell.h" -octave_allocator -Cell::allocator (sizeof (Cell)); - -Cell -Cell::index (idx_vector& i) const -{ - return Cell (data.index (i)); -} - -Cell -Cell::index (idx_vector& i, idx_vector& j) const -{ - return Cell (data.index (i, j)); -} /* ;;; Local Variables: *** Index: src/Cell.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/Cell.h,v retrieving revision 1.2 diff -u -r1.2 Cell.h --- src/Cell.h 17 Nov 1999 19:06:13 -0000 1.2 +++ src/Cell.h 3 May 2002 19:33:42 -0000 at @ -36,57 +36,28 @@ #include "ov.h" class -Cell +Cell : public Array2 { public: Cell (void) - : data () { } + : Array2 () { } + + Cell (const octave_value& val) + : Array2 (1, 1, val) { } Cell (int n, int m, const octave_value& val = octave_value ()) - : data (n, m, val) { } + : Array2 (n, m, val) { } Cell (const Array2& c) - : data (c) { } + : Array2 (c) { } Cell (const Cell& c) - : data (c.data) { } - - void *operator new (size_t size) - { return allocator.alloc (size); } - - void operator delete (void *p, size_t size) - { allocator.free (p, size); } - - Cell& operator = (const Cell& c) - { - if (this != &c) - data = c.data; - - return *this; - } - - int rows (void) const { return data.rows (); } - - int columns (void) const { return data.columns (); } - - octave_value& operator () (int i, int j) { return elem (i, j); } - - octave_value operator () (int i, int j) const { return elem (i, j); } - - octave_value& elem (int i, int j) { return data.elem (i, j); } - - octave_value elem (int i, int j) const { return data.elem (i, j); } - - Cell index (idx_vector& i) const; - - Cell index (idx_vector& i, idx_vector& j) const; - -private: - - static octave_allocator allocator; + : Array2 (c) { } - Array2 data; + boolMatrix all(void) const { return boolMatrix();} //FIXME + boolMatrix any(void) const {return boolMatrix();} //FIXME + bool is_true(void) const {return false;} //FIXME }; #endif Index: src/Makefile.in =================================================================== RCS file: /usr/local/cvsroot/octave/src/Makefile.in,v retrieving revision 1.270 diff -u -r1.270 Makefile.in --- src/Makefile.in 3 May 2002 02:13:42 -0000 1.270 +++ src/Makefile.in 3 May 2002 19:33:48 -0000 at @ -96,9 +96,10 @@ TI_SRC := $(addprefix TEMPLATE-INST/, $(TI_XSRC)) -OP_XSRC := op-b-b.cc op-bm-b.cc op-bm-bm.cc op-chm.cc op-cm-cm.cc \ - op-cm-cs.cc op-cm-m.cc op-cm-s.cc op-cs-cm.cc op-cs-cs.cc \ - op-cs-m.cc op-cs-s.cc op-fil-b.cc op-fil-bm.cc op-fil-cm.cc \ +OP_XSRC := op-b-b.cc op-bm-b.cc op-bm-bm.cc op-cell.cc \ + op-chm.cc op-cm-cm.cc op-cm-cs.cc op-cm-m.cc \ + op-cm-s.cc op-cs-cm.cc op-cs-cs.cc op-cs-m.cc \ + op-cs-s.cc op-fil-b.cc op-fil-bm.cc op-fil-cm.cc \ op-fil-cs.cc op-fil-m.cc op-fil-s.cc op-fil-lis.cc \ op-fil-rec.cc op-fil-str.cc op-list.cc op-m-cm.cc op-m-cs.cc \ op-m-m.cc op-m-s.cc op-range.cc op-s-cm.cc op-s-cs.cc op-s-m.cc \ Index: src/ov-base-mat.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-base-mat.cc,v retrieving revision 1.5 diff -u -r1.5 ov-base-mat.cc --- src/ov-base-mat.cc 3 Feb 2000 21:39:50 -0000 1.5 +++ src/ov-base-mat.cc 3 May 2002 19:33:48 -0000 at @ -75,6 +75,48 @@ return retval; } +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +template +extern void assign (MT&, const MT&); +#endif + +template +void +octave_base_matrix::assign (const octave_value_list& idx, const MT& rhs) +{ + int len = idx.length (); + + switch (len) + { + case 2: + { + idx_vector i = idx (0).index_vector (); + idx_vector j = idx (1).index_vector (); + + matrix.set_index (i); + matrix.set_index (j); + + ::assign (matrix, rhs); + } + break; + + case 1: + { + idx_vector i = idx (0).index_vector (); + + matrix.set_index (i); + + ::assign (matrix, rhs); + } + break; + + default: + error ("invalid number of indices (%d) for indexed assignment", + len); + break; + } +} + template bool octave_base_matrix::is_true (void) const Index: src/ov-base-mat.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-base-mat.h,v retrieving revision 1.7 diff -u -r1.7 ov-base-mat.h --- src/ov-base-mat.h 2 Feb 2000 10:26:04 -0000 1.7 +++ src/ov-base-mat.h 3 May 2002 19:33:48 -0000 at @ -67,6 +67,8 @@ octave_value do_index_op (const octave_value_list& idx); + void assign (const octave_value_list& idx, const MT& rhs); + int rows (void) const { return matrix.rows (); } int columns (void) const { return matrix.columns (); } Index: src/ov-base.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-base.cc,v retrieving revision 1.26 diff -u -r1.26 ov-base.cc --- src/ov-base.cc 2 Feb 2000 21:02:37 -0000 1.26 +++ src/ov-base.cc 3 May 2002 19:33:48 -0000 at @ -32,7 +32,6 @@ #include "lo-ieee.h" -#include "Cell.h" #include "gripes.h" #include "oct-map.h" #include "oct-obj.h" at @ -40,14 +39,15 @@ #include "oct-stream.h" #include "ops.h" #include "ov-base.h" -#include "ov-scalar.h" -#include "ov-re-mat.h" +#include "ov-cell.h" +#include "ov-ch-mat.h" #include "ov-complex.h" #include "ov-cx-mat.h" -#include "ov-ch-mat.h" -#include "ov-str-mat.h" -#include "ov-range.h" #include "ov-list.h" +#include "ov-range.h" +#include "ov-re-mat.h" +#include "ov-scalar.h" +#include "ov-str-mat.h" #include "variables.h" DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, ""); at @ -338,6 +338,11 @@ return new octave_char_matrix_str (); } +CONVDECLX (cell_conv) +{ + return new octave_cell (); +} + void install_base_type_conversions (void) { at @ -347,10 +352,12 @@ INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); + INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); + INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); } /* Index: src/ov-bool-mat.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-bool-mat.cc,v retrieving revision 1.10 diff -u -r1.10 ov-bool-mat.cc --- src/ov-bool-mat.cc 31 May 2001 19:30:52 -0000 1.10 +++ src/ov-bool-mat.cc 3 May 2002 19:33:48 -0000 at @ -78,43 +78,6 @@ return retval; } -void -octave_bool_matrix::assign (const octave_value_list& idx, - const boolMatrix& rhs) -{ - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - matrix.set_index (i); - matrix.set_index (j); - - ::assign (matrix, rhs); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - matrix.set_index (i); - - ::assign (matrix, rhs); - } - break; - - default: - error ("invalid number of indices (%d) for indexed matrix assignment", - len); - break; - } -} - bool octave_bool_matrix::valid_as_scalar_index (void) const { Index: src/ov-bool-mat.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-bool-mat.h,v retrieving revision 1.16 diff -u -r1.16 ov-bool-mat.h --- src/ov-bool-mat.h 8 Feb 2000 05:54:22 -0000 1.16 +++ src/ov-bool-mat.h 3 May 2002 19:33:48 -0000 at @ -72,8 +72,6 @@ octave_value *try_narrowing_conversion (void); - void assign (const octave_value_list& idx, const boolMatrix& rhs); - idx_vector index_vector (void) const { return idx_vector (matrix); } bool is_bool_matrix (void) const { return true; } Index: src/ov-cell.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-cell.cc,v retrieving revision 1.6 diff -u -r1.6 ov-cell.cc --- src/ov-cell.cc 2 Feb 2000 12:36:28 -0000 1.6 +++ src/ov-cell.cc 3 May 2002 19:33:48 -0000 at @ -39,139 +39,24 @@ #include "oct-obj.h" #include "unwind-prot.h" #include "utils.h" +#include "ov-base-mat.h" +#include "ov-base-mat.cc" +#include "ov-re-mat.h" +#include "ov-scalar.h" + +template class octave_base_matrix; DEFINE_OCTAVE_ALLOCATOR (octave_cell); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell"); -octave_value -octave_cell::do_index_op (const octave_value_list& idx) -{ - octave_value retval; - - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - retval = cell_val.index (i, j); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - retval = cell_val.index (i); - } - break; - - default: - { - std::string n = type_name (); - - error ("invalid number of indices (%d) for %s value", - len, n.c_str ()); - } - break; - } - - return retval; -} - void octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) { -#if 0 - if (idx.length () == 1) - { - int i = idx(0).int_value (true); - - if (! error_state) - { - int n = lst.length (); - - if (i > 0 && (Vresize_on_range_error || i <= n)) - lst(i-1) = rhs; - else - error ("list index = %d out of range", i); - } - else - error ("list index must be an integer"); - } - else - error ("lists may only be indexed by a single scalar"); -#endif -} - -void -octave_cell::print (std::ostream& os, bool) const -{ - print_raw (os); -} - -void -octave_cell::print_raw (std::ostream& os, bool) const -{ - unwind_protect::begin_frame ("octave_cell_print"); - - int nr = cell_val.rows (); - int nc = cell_val.columns(); - - if (nr > 0 && nc > 0) - { - indent (os); - os << "{"; - newline (os); - - increment_indent_level (); - - for (int j = 0; j < nc; j++) - { - for (int i = 0; i < nr; i++) - { - std::ostrstream buf; - buf << "[" << i+1 << "," << j+1 << "]" << std::ends; - const char *nm = buf.str (); - - octave_value val = cell_val(i,j); - - val.print_with_name (os, nm); - - delete [] nm; - } - } - - decrement_indent_level (); - - indent (os); - - os << "}"; - } - else - os << "{}"; - - newline (os); - - unwind_protect::run_frame ("octave_cell_print"); -} - -bool -octave_cell::print_name_tag (std::ostream& os, const std::string& name) const -{ - indent (os); - if (is_empty ()) - os << name << " = "; + if (rhs.is_cell ()) + octave_base_matrix::assign (idx, rhs.cell_value ()); else - { - os << name << " ="; - newline (os); - } - return false; + octave_base_matrix::assign (idx, Cell (rhs)); } DEFUN (iscell, args, , Index: src/ov-cell.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-cell.h,v retrieving revision 1.5 diff -u -r1.5 ov-cell.h --- src/ov-cell.h 12 Oct 2000 05:45:12 -0000 1.5 +++ src/ov-cell.h 3 May 2002 19:33:48 -0000 at @ -38,7 +38,7 @@ #include "Cell.h" #include "error.h" -#include "ov-base.h" +#include "ov-base-mat.h" #include "ov-typeinfo.h" class Octave_map; at @ -49,45 +49,36 @@ // Cells. class -octave_cell : public octave_base_value +octave_cell : public octave_base_matrix { public: octave_cell (void) - : octave_base_value () { } + : octave_base_matrix () { } octave_cell (const Cell& c) - : octave_base_value (), cell_val (c) { } + : octave_base_matrix (c) { } octave_cell (const octave_cell& c) - : octave_base_value (), cell_val (c.cell_val) { } + : octave_base_matrix (c) { } ~octave_cell (void) { } + void assign (const octave_value_list& idx, const octave_value& rhs); + octave_value *clone (void) { return new octave_cell (*this); } - octave_value do_index_op (const octave_value_list& idx); - - void assign (const octave_value_list& idx, const octave_value& rhs); +#if 0 + octave_value *try_narrowing_conversion (void); +#endif bool is_defined (void) const { return true; } - bool is_constant (void) const { return true; } - bool is_cell (void) const { return true; } - Cell cell_value (void) const { return cell_val; } - - void print (std::ostream& os, bool pr_as_read_syntax = false) const; - - void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - - bool print_name_tag (std::ostream& os, const std::string& name) const; + Cell cell_value (void) const { return matrix; } private: - - Cell cell_val; - DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA Index: src/ov-cx-mat.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-cx-mat.cc,v retrieving revision 1.20 diff -u -r1.20 ov-cx-mat.cc --- src/ov-cx-mat.cc 31 May 2001 19:30:52 -0000 1.20 +++ src/ov-cx-mat.cc 3 May 2002 19:33:48 -0000 at @ -78,43 +78,6 @@ void octave_complex_matrix::assign (const octave_value_list& idx, - const ComplexMatrix& rhs) -{ - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - matrix.set_index (i); - matrix.set_index (j); - - ::assign (matrix, rhs); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - matrix.set_index (i); - - ::assign (matrix, rhs); - } - break; - - default: - error ("invalid number of indices (%d) for indexed matrix assignment", - len); - break; - } -} - -void -octave_complex_matrix::assign (const octave_value_list& idx, const Matrix& rhs) { int len = idx.length (); Index: src/ov-cx-mat.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-cx-mat.h,v retrieving revision 1.19 diff -u -r1.19 ov-cx-mat.h --- src/ov-cx-mat.h 8 Feb 2000 05:54:22 -0000 1.19 +++ src/ov-cx-mat.h 3 May 2002 19:33:49 -0000 at @ -77,7 +77,8 @@ octave_value *try_narrowing_conversion (void); - void assign (const octave_value_list& idx, const ComplexMatrix& rhs); + void assign (const octave_value_list& idx, const ComplexMatrix& rhs) + { octave_base_matrix::assign (idx, rhs); } void assign (const octave_value_list& idx, const Matrix& rhs); Index: src/ov-re-mat.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-re-mat.cc,v retrieving revision 1.23 diff -u -r1.23 ov-re-mat.cc --- src/ov-re-mat.cc 31 May 2001 19:30:52 -0000 1.23 +++ src/ov-re-mat.cc 3 May 2002 19:33:49 -0000 at @ -66,42 +66,6 @@ return retval; } -void -octave_matrix::assign (const octave_value_list& idx, const Matrix& rhs) -{ - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - matrix.set_index (i); - matrix.set_index (j); - - ::assign (matrix, rhs); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - matrix.set_index (i); - - ::assign (matrix, rhs); - } - break; - - default: - error ("invalid number of indices (%d) for indexed matrix assignment", - len); - break; - } -} - bool octave_matrix::valid_as_scalar_index (void) const { Index: src/ov-re-mat.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-re-mat.h,v retrieving revision 1.20 diff -u -r1.20 ov-re-mat.h --- src/ov-re-mat.h 8 Feb 2000 05:54:23 -0000 1.20 +++ src/ov-re-mat.h 3 May 2002 19:33:49 -0000 at @ -77,8 +77,6 @@ octave_value *try_narrowing_conversion (void); - void assign (const octave_value_list& idx, const Matrix& rhs); - idx_vector index_vector (void) const { return idx_vector (matrix); } bool is_real_matrix (void) const { return true; } Index: src/ov.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov.cc,v retrieving revision 1.54 diff -u -r1.54 ov.cc --- src/ov.cc 2 Feb 2000 22:45:42 -0000 1.54 +++ src/ov.cc 3 May 2002 19:33:49 -0000 at @ -1525,6 +1525,7 @@ install_types (void) { octave_base_value::register_type (); + octave_cell::register_type (); octave_scalar::register_type (); octave_complex::register_type (); octave_matrix::register_type (); Index: src/parse.y =================================================================== RCS file: /usr/local/cvsroot/octave/src/parse.y,v retrieving revision 1.171 diff -u -r1.171 parse.y --- src/parse.y 23 Apr 2002 03:40:25 -0000 1.171 +++ src/parse.y 3 May 2002 19:33:50 -0000 at @ -40,6 +40,7 @@ #include +#include "Cell.h" #include "Matrix.h" #include "cmd-edit.h" #include "cmd-hist.h" at @ -606,9 +607,9 @@ ; cell : '{' '}' - { $$ = new tree_constant (octave_value (Matrix ())); } + { $$ = new tree_constant (octave_value (Cell ())); } | '{' ';' '}' - { $$ = new tree_constant (octave_value (Matrix ())); } + { $$ = new tree_constant (octave_value (Cell ())); } | '{' cell_rows '}' { $$ = finish_cell ($2); } ; Index: src/pr-output.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/pr-output.cc,v retrieving revision 1.97 diff -u -r1.97 pr-output.cc --- src/pr-output.cc 6 Feb 2001 05:21:33 -0000 1.97 +++ src/pr-output.cc 3 May 2002 19:33:51 -0000 at @ -38,6 +38,7 @@ #include "Range.h" #include "cmd-edit.h" #include "dMatrix.h" +#include "Cell.h" #include "lo-mappers.h" #include "mach-info.h" #include "oct-cmplx.h" at @ -1752,6 +1753,39 @@ { os << "sorry, printing char matrices not implemented yet\n"; } +} + +void +octave_print_internal (std::ostream& os, const Cell& cell_val, + bool pr_as_read_syntax, int extra_indent) +{ + int nr = cell_val.rows (); + int nc = cell_val.columns(); + + if (nr > 0 && nc > 0) + { + os << "{\n"; + + for (int j = 0; j < nc; j++) + { + for (int i = 0; i < nr; i++) + { + std::ostrstream buf; + buf << "[" << i+1 << "," << j+1 << "]" << std::ends; + const char *nm = buf.str (); + + octave_value val = cell_val(i,j); + + val.print_with_name (os, nm); + + delete [] nm; + } + } + + os << "}"; + } + else + os << "{}"; } DEFUN (disp, args, nargout, Index: src/pr-output.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/pr-output.h,v retrieving revision 1.24 diff -u -r1.24 pr-output.h --- src/pr-output.h 2 Feb 2000 10:26:12 -0000 1.24 +++ src/pr-output.h 3 May 2002 19:33:51 -0000 at @ -32,6 +32,7 @@ class Range; class boolMatrix; class charMatrix; +class Cell; extern void octave_print_internal (std::ostream& os, double d, at @ -66,6 +67,11 @@ bool pr_as_read_syntax = false, int extra_indent = 0, bool pr_as_string = false); + +extern void +octave_print_internal (std::ostream& os, const Cell& c, + bool pr_as_read_syntax = false, + int extra_indent = 0); #endif Index: src/TEMPLATE-INST/Array-tc.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/TEMPLATE-INST/Array-tc.cc,v retrieving revision 1.4 diff -u -r1.4 Array-tc.cc --- src/TEMPLATE-INST/Array-tc.cc 3 Feb 2000 03:05:31 -0000 1.4 +++ src/TEMPLATE-INST/Array-tc.cc 3 May 2002 19:33:51 -0000 at @ -38,7 +38,26 @@ #include "ov.h" template class Array; + +octave_value +Array::resize_fill_value (void) +{ + static octave_value retval = octave_value (Matrix ()); + return retval; +} + +template int assign (Array&, const Array&); + +template int assign (Array&, + const Array&, const octave_value&); + + template class Array2; + +template int assign (Array2&, const Array2&); + +template int assign (Array2&, + const Array2&, const octave_value&); /* ;;; Local Variables: ***