Mercurial > hg > octave-lyh
changeset 4563:742993a501b9
[project @ 2003-10-29 06:25:12 by jwe]
author | jwe |
---|---|
date | Wed, 29 Oct 2003 06:25:12 +0000 |
parents | 4699bdb4c362 |
children | 8a0a0eb77f0b |
files | liboctave/CNDArray.cc liboctave/boolNDArray.cc liboctave/chNDArray.cc liboctave/dNDArray.cc liboctave/mx-inlines.cc src/Cell.h src/ChangeLog src/data.cc src/oct-map.cc src/ov-base-mat.cc src/ov-base-mat.h src/ov-base-scalar.h src/ov-base.h src/ov-cell.cc src/ov-cs-list.h src/ov-list.h src/ov-range.h src/ov-struct.h src/ov.cc src/ov.h |
diffstat | 20 files changed, 297 insertions(+), 189 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -77,15 +77,15 @@ boolNDArray ComplexNDArray::all (int dim) const { - MX_ND_ALL_ANY (MX_ND_ALL_EVAL (real (elem (iter_idx)) == 0 - && imag (elem (iter_idx)) == 0)); + MX_ND_ANY_ALL (MX_ND_ALL_EVAL (real (elem (iter_idx)) == 0 + && imag (elem (iter_idx)) == 0), true); } boolNDArray ComplexNDArray::any (int dim) const { - MX_ND_ALL_ANY (MX_ND_ANY_EVAL (real (elem (iter_idx)) - || imag (elem (iter_idx)))); + MX_ND_ANY_ALL (MX_ND_ANY_EVAL (real (elem (iter_idx)) != 0 + || imag (elem (iter_idx)) != 0), false); } ComplexMatrix
--- a/liboctave/boolNDArray.cc +++ b/liboctave/boolNDArray.cc @@ -53,13 +53,13 @@ boolNDArray boolNDArray::all (int dim) const { - MX_ND_ALL_ANY (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR)); + MX_ND_ANY_ALL (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR), true); } boolNDArray boolNDArray::any (int dim) const { - MX_ND_ALL_ANY (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR)); + MX_ND_ANY_ALL (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR), false); } boolMatrix
--- a/liboctave/chNDArray.cc +++ b/liboctave/chNDArray.cc @@ -40,13 +40,13 @@ boolNDArray charNDArray::all (int dim) const { - MX_ND_ALL_ANY (MX_ND_ALL_EVAL (elem (iter_idx) == ' ')); + MX_ND_ANY_ALL (MX_ND_ALL_EVAL (elem (iter_idx) == ' '), true); } boolNDArray charNDArray::any (int dim) const { - MX_ND_ALL_ANY (MX_ND_ANY_EVAL (elem (iter_idx) != ' ')); + MX_ND_ANY_ALL (MX_ND_ANY_EVAL (elem (iter_idx) != ' '), false); } charMatrix
--- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -68,13 +68,13 @@ boolNDArray NDArray::all (int dim) const { - MX_ND_ALL_ANY (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR)); + MX_ND_ANY_ALL (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR), true); } boolNDArray NDArray::any (int dim) const { - MX_ND_ALL_ANY (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR)); + MX_ND_ANY_ALL (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR), false); } Matrix
--- a/liboctave/mx-inlines.cc +++ b/liboctave/mx-inlines.cc @@ -350,9 +350,9 @@ #define MX_ANY_OP(DIM) MX_ANY_ALL_OP (DIM, false, !=, true) -#define MX_ND_ALL_EXPR elem (iter_idx) == 0 +#define MX_ND_ALL_EXPR elem (iter_idx) == 0 -#define MX_ND_ANY_EXPR elem (iter_idx) +#define MX_ND_ANY_EXPR elem (iter_idx) != 0 #define MX_ND_ALL_EVAL(TEST_EXPR) \ if (TEST_EXPR) \ @@ -362,7 +362,7 @@ retval (iter_idx) = 0; \ break; \ } \ - else \ + else \ { \ if (dim > -1) \ iter_idx (dim) = 0; \ @@ -378,77 +378,108 @@ break; \ } -#define MX_ND_ALL_ANY(EVAL_EXPR) \ +#define MX_ND_ANY_ALL(EVAL_EXPR, VAL) \ \ boolNDArray retval; \ \ dim_vector dv = dims (); \ - /* Check to see if we have a empty matrix: [] */ \ - for (int i = 0; i < dv.length (); i++)\ - if (dv (i) == 0) \ - { \ - dim_vector dv_temp (1, 1); \ - retval.resize (dv_temp, false); \ - return retval; \ - } \ - if (dim == -1)/* We need to find first non-singleton dim */ \ + \ + int empty = true; \ + \ + for (int i = 0; i < dv.length (); i++) \ + { \ + if (dv(i) > 0) \ + { \ + empty = false; \ + break; \ + } \ + } \ + \ + if (empty) \ + { \ + dim_vector retval_dv (1, 1); \ + retval.resize (retval_dv, VAL); \ + return retval; \ + } \ + \ + if (dim == -1) /* We need to find first non-singleton dim */ \ { \ - /* Be sure to return a scalar if we have a vector */ \ - if (dv.length () == 2 && dv (0) == 1 && dv (1) >= 1) \ - dim = 1; \ - else \ - for (int i = 0; i < dv.length (); i++) \ - { \ - if (dv (i) > 1) \ - { \ - dim = i; \ - break; \ - } \ - } \ + for (int i = 0; i < dv.length (); i++) \ + { \ + if (dv (i) != 1) \ + { \ + dim = i; \ + break; \ + } \ + } \ + \ if (dim == -1) \ + dim = 0; \ + } \ + \ + int squeezed = 0; \ + \ + for (int i = 0; i < dv.length (); i++) \ + { \ + if (dv(i) == 0) \ { \ - (*current_liboctave_error_handler) \ - ("all dimensions are singleton"); \ - return retval; \ - } \ + squeezed = 1;\ + break;\ + } \ } \ - /* Length of Dimension */\ + \ + if (squeezed) \ + { \ + dv(dim) = 1; \ + \ + retval.resize (dv, VAL); \ + \ + return retval; \ + } \ + \ + /* Length of Dimension */ \ int dim_length = 1; \ + \ /* dim = -1 means from here that the user specified a */ \ /* dimension which is larger that the number of dimensions */ \ /* of the array */ \ + \ if (dim >= dv.length ()) \ dim = -1; \ else \ - dim_length = dv (dim); \ + dim_length = dv(dim); \ + \ if (dim > -1) \ - dv (dim) = 1; \ + dv(dim) = 1; \ \ - /* We need to find the number of elements we need to */ \ - /* fill in retval. First we need to get last idx of */ \ - /* the dimension vector */ \ + /* We need to find the number of elements we need to */ \ + /* fill in retval. First we need to get last idx of */ \ + /* the dimension vector */ \ + \ Array<int> temp_dv (dv.length (), 0); \ + \ for (int x = 0; x < dv.length (); x++) \ - temp_dv (x) = dv (x) - 1; \ + temp_dv(x) = dv(x) - 1; \ \ - /* This finds the number of elements in retval */ \ + /* This finds the number of elements in retval */ \ int num_iter = compute_index (temp_dv, dv) + 1; \ \ - /* Make sure retval has correct dimensions */ \ - retval.resize (dv, false); \ + /* Make sure retval has correct dimensions */ \ + retval.resize (dv, false); \ \ Array<int> iter_idx (dv.length (), 0); \ \ - /* Filling in values. */ \ - /* First loop finds new index */ \ + /* Filling in values. */ \ + /* First loop finds new index */ \ + \ for (int j = 0; j < num_iter; j++) \ { \ for (int i = 0; i < dim_length; i++) \ { \ if (dim > -1) \ - iter_idx (dim) = i; \ + iter_idx(dim) = i; \ \ - EVAL_EXPR \ + EVAL_EXPR; \ } \ \ if (dim > -1) \ @@ -458,7 +489,7 @@ } \ \ return retval - + #endif
--- a/src/Cell.h +++ b/src/Cell.h @@ -56,6 +56,9 @@ Cell (int n, int m, const octave_value& val = resize_fill_value ()) : ArrayN<octave_value> (dim_vector (n, m), val) { } + Cell (const dim_vector& dims, const octave_value& val = resize_fill_value ()) + : ArrayN<octave_value> (dims, val) { } + Cell (const ArrayN<octave_value>& c) : ArrayN<octave_value> (c) { }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,59 @@ 2003-10-28 John W. Eaton <jwe@bevo.che.wisc.edu> + * ov-list.h (octave_list::nelem): Delete. + (octave_list::dims): New function. + * ov-range.h (octave_list::dims): New function. + * ov-struct.h (octave_struct::dims): New function. + * ov-base-scalar.h (octave_base_scalar::dims): New function. + + * ov.h (octave_value::rows): No longer virtual. + * ov.cc (octave_value::rows): Provide common implementation. + * ov-base.h (octave_base_value::rows): Delete. + * ov-base-mat.h (octave_base_matrix<T>::rows): Delete. + * ov-base-scalar.h (octave_base_scalar<T>::rows): Delete. + * ov-struct.h (octave_struct::rows): Delete. + * ov-range.h (octave_range::rows): Delete. + + * ov.h (octave_value::columns): No longer virtual. + * ov.cc (octave_value::columns): Provide common implementation. + * ov-base.h (octave_base_value::columns): Delete. + * ov-base-mat.h (octave_base_matrix<T>::columns): Delete. + * ov-base-scalar.h (octave_base_scalar<T>::columns): Delete. + * ov-struct.h (octave_struct::columns): Delete. + * ov-range.h (octave_range::columns): Delete. + + * ov.h (octave_value::numel): No longer virtual. + * ov.cc (octave_value::numel): Provide common implementation. + * ov-base.h (octave_base_value::numel): Delete. + * ov-base-mat.h (octave_base_matrix<T>::numel): Delete. + * ov-base-scalar.h (octave_base_scalar<T>::numel): Delete. + * ov-struct.h (octave_struct::numel): Delete. + + * ov-cs-list.h (octave_cs_list::dims): New function. + (octave_cs_list::length): Delete. + + * ov.h (octave_value::ndims): No longer virtual. + * ov.cc (octave_value::ndims): Provide common implementation. + * ov-base.h (octave_base_value::ndims): Delete. + * ov-base-mat.h (octave_base_matrix<T>::ndims): Delete. + * ov-base-scalar.h (octave_base_scalar<T>::ndims): Delete. + * ov-struct.h (octave_struct::ndims): Delete. + + * ov-cell.cc (Fcell): Make it work for N-d cells. + + * Cell.h (Cell::Cell (const dim_vector&, const octave_value&)): + New constructor. + + * ov.h (octave_value::length): No longer virtual. + * ov.cc (octave_value::length): Provide common implementation. + * ov-base.h (octave_base_value::length): Delete. + * ov-base-mat.h (octave_base_matrix<T>::length): Delete. + * ov-base-scalar.h (octave_base_scalar<T>::length): Delete. + * ov-struct.h (octave_struct::length): Delete. + * ov-cs-list.h (octave_cs_list::length): Delete. + * ov-list.h (octave_list::length): Delete. + * ov-range.h (octave_range::length): Delete. + * load-save.cc (save_mat5_binary_element): Use numel instead of array_length. * ov-struct.cc (octave_struct::print_raw): Likewise.
--- a/src/data.cc +++ b/src/data.cc @@ -1005,22 +1005,22 @@ get_dimensions (args(0), fcn, dims); break; - default: - { - dims.resize (nargin); + default: + { + dims.resize (nargin); - for (int i = 0; i < nargin; i++) - { - dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); - if (error_state) - { - error ("%s: expecting scalar arguments", fcn); - break; - } - } - } - break; + if (error_state) + { + error ("%s: expecting scalar arguments", fcn); + break; + } + } + } + break; } if (! error_state)
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -194,7 +194,11 @@ Octave_map::assign (const std::string& key, const Cell& rhs) { if (empty ()) - map[key] = rhs; + { + map[key] = rhs; + + dimensions = dim_vector (1, 1); + } else { if (dims () == rhs.dims ())
--- a/src/ov-base-mat.cc +++ b/src/ov-base-mat.cc @@ -193,47 +193,6 @@ } template <class MT> -int -octave_base_matrix<MT>::length (void) const -{ - int retval = 0; - - dim_vector dv = dims (); - - for (int i = 0; i < dv.length (); i++) - if (dv(i) > retval) - retval = dv(i); - - return retval; -} - -template <class MT> -int -octave_base_matrix<MT>::ndims (void) const -{ - dim_vector dv = dims (); - - int n_dims = dv.length (); - - // Remove trailing singleton dimensions. - - for (int i = n_dims; i > 2; i--) - { - if (dv(i-1) == 1) - n_dims--; - else - break; - } - - // The result is always >= 2. - - if (n_dims < 2) - n_dims = 2; - - return n_dims; -} - -template <class MT> bool octave_base_matrix<MT>::print_as_scalar (void) const {
--- a/src/ov-base-mat.h +++ b/src/ov-base-mat.h @@ -90,20 +90,11 @@ void assign (const octave_value_list& idx, const MT& rhs); - int rows (void) const { return matrix.rows (); } - int columns (void) const { return matrix.columns (); } - dim_vector dims (void) const { return matrix.dims (); } octave_value all (int dim = 0) const { return matrix.all (dim); } octave_value any (int dim = 0) const { return matrix.any (dim); } - int length (void) const; - - int ndims (void) const; - - int numel (void) const { return matrix.numel (); } - bool is_matrix_type (void) const { return true; } bool is_numeric_type (void) const { return true; }
--- a/src/ov-base-scalar.h +++ b/src/ov-base-scalar.h @@ -74,20 +74,12 @@ const std::list<octave_value_list>& idx, const octave_value& rhs); - int rows (void) const { return 1; } - - int columns (void) const { return 1; } - - int length (void) const { return 1; } - - int ndims (void) const { return 2; } - - int numel (void) const { return 1; } - bool is_constant (void) const { return true; } bool is_defined (void) const { return true; } + dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } + octave_value all (int = 0) const { return (scalar != 0.0); } octave_value any (int = 0) const { return (scalar != 0.0); }
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -94,17 +94,7 @@ const std::list<octave_value_list>& idx, const octave_value& rhs); - int rows (void) const { return -1; } - - int columns (void) const { return -1; } - - dim_vector dims (void) const { return dim_vector (rows (), columns ()); } - - int length (void) const { return -1; } - - int ndims (void) const { return -1; } - - int numel (void) const { return -1; } + dim_vector dims (void) const { return dim_vector (-1, -1); } bool is_defined (void) const { return false; }
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -445,33 +445,57 @@ int nargin = args.length (); + dim_vector dims; + switch (nargin) { - case 1: - { - int nr, nc; - get_dimensions (args(0), "cell", nr, nc); - - if (! error_state) - retval = Cell (nr, nc, Matrix ()); - } + case 0: + dims = dim_vector (0, 0); break; - case 2: - { - int nr, nc; - get_dimensions (args(0), args(1), "cell", nr, nc); - - if (! error_state) - retval = Cell (nr, nc, Matrix ()); - } + case 1: + get_dimensions (args(0), "cell", dims); break; default: - print_usage ("cell"); + { + dims.resize (nargin); + + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); + + if (error_state) + { + error ("cell: expecting scalar arguments"); + break; + } + } + } break; } + if (! error_state) + { + int ndim = dims.length (); + + check_dimensions (dims, "cell"); + + if (! error_state) + { + switch (ndim) + { + case 1: + retval = Cell (dims(0), dims(0), Matrix ()); + break; + + default: + retval = Cell (dims, Matrix ()); + break; + } + } + } + return retval; }
--- a/src/ov-cs-list.h +++ b/src/ov-cs-list.h @@ -79,8 +79,6 @@ void assign (const octave_value_list& idx, const octave_value& rhs); - int length (void) const { return lst.length (); } - bool is_defined (void) const { return true; } bool is_constant (void) const { return true; }
--- a/src/ov-list.h +++ b/src/ov-list.h @@ -85,9 +85,7 @@ void assign (const octave_value_list& idx, const octave_value& rhs); - int length (void) const { return lst.length (); } - - int nelem (void) const { return length (); } + dim_vector dims (void) const { return dim_vector (1, lst.length ()); } bool is_defined (void) const { return true; }
--- a/src/ov-range.h +++ b/src/ov-range.h @@ -103,10 +103,11 @@ idx_vector index_vector (void) const { return idx_vector (range); } - int rows (void) const { return (columns () > 0); } - int columns (void) const { return range.nelem (); } - - int length (void) const { return range.nelem (); } + dim_vector dims (void) const + { + int n = range.nelem (); + return dim_vector (n > 0, n); + } bool is_defined (void) const { return true; }
--- a/src/ov-struct.h +++ b/src/ov-struct.h @@ -87,17 +87,7 @@ const std::list<octave_value_list>& idx, const octave_value& rhs); - int rows (void) const { return map.rows (); } - - int columns (void) const { return map.columns (); } - - int length (void) const - { - int r = rows (); - int c = columns (); - - return (r == 0 || c == 0) ? 0 : ((r > c) ? r : c); - } + dim_vector dims (void) const { return map.dims (); } bool is_defined (void) const { return true; }
--- a/src/ov.cc +++ b/src/ov.cc @@ -817,6 +817,84 @@ return *this; } +int +octave_value::rows (void) const +{ + dim_vector dv = dims (); + + return (dv.length () > 0) ? dv(0) : -1; +} + +int +octave_value::columns (void) const +{ + dim_vector dv = dims (); + + return (dv.length () > 1) ? dv(1) : -1; +} + +int +octave_value::length (void) const +{ + int retval = 0; + + dim_vector dv = dims (); + + for (int i = 0; i < dv.length (); i++) + { + if (dv(i) < 0) + { + retval = -1; + break; + } + + if (dv(i) > retval) + retval = dv(i); + } + + return retval; +} + +int +octave_value::ndims (void) const +{ + dim_vector dv = dims (); + + int n_dims = dv.length (); + + // Remove trailing singleton dimensions. + + for (int i = n_dims; i > 2; i--) + { + if (dv(i-1) == 1) + n_dims--; + else + break; + } + + // The result is always >= 2. + + if (n_dims < 2) + n_dims = 2; + + return n_dims; +} + +int +octave_value::numel (void) const +{ + dim_vector dv = dims (); + + int n_dims = dv.length (); + + int retval = n_dims > 0 ? dv(0) : 0; + + for (int i = 1; i < n_dims; i++) + retval *= dv(i); + + return retval; +} + Cell octave_value::cell_value (void) const {
--- a/src/ov.h +++ b/src/ov.h @@ -316,23 +316,18 @@ // Size. - virtual int rows (void) const - { return rep->rows (); } - - virtual int columns (void) const - { return rep->columns (); } - virtual dim_vector dims (void) const { return rep->dims (); } - virtual int length (void) const - { return rep->length (); } + int rows (void) const; + + int columns (void) const; - virtual int ndims (void) const - { return rep->ndims (); } + int length (void) const; - virtual int numel (void) const - { return rep->numel (); } + int ndims (void) const; + + int numel (void) const; // Does this constant have a type? Both of these are provided since // it is sometimes more natural to write is_undefined() instead of