Mercurial > hg > octave-lyh
changeset 4556:773a21e4fce8
[project @ 2003-10-28 05:02:10 by jwe]
author | jwe |
---|---|
date | Tue, 28 Oct 2003 05:02:10 +0000 |
parents | fe70d8074644 |
children | dd92abda6569 |
files | liboctave/CNDArray.cc liboctave/CNDArray.h liboctave/ChangeLog liboctave/boolNDArray.cc liboctave/boolNDArray.h liboctave/chNDArray.cc liboctave/chNDArray.h liboctave/dNDArray.cc liboctave/dNDArray.h liboctave/mx-inlines.cc src/ChangeLog src/data.cc src/ov-base-mat.cc |
diffstat | 13 files changed, 196 insertions(+), 120 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -74,38 +74,18 @@ // XXX FIXME XXX -- this is not quite the right thing. -boolMatrix +boolNDArray ComplexNDArray::all (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - ComplexMatrix tmp = matrix_value (); - retval = tmp.all (dim); - } - else - (*current_liboctave_error_handler) - ("all is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ALL_EVAL (real (elem (iter_idx)) == 0 + && imag (elem (iter_idx)) == 0)); } -boolMatrix +boolNDArray ComplexNDArray::any (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - ComplexMatrix tmp = matrix_value (); - retval = tmp.any (dim); - } - else - (*current_liboctave_error_handler) - ("any is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ANY_EVAL (real (elem (iter_idx)) + || imag (elem (iter_idx)))); } ComplexMatrix @@ -143,6 +123,13 @@ ::increment_index (ra_idx, dimensions, start_dimension); } +int +ComplexNDArray::compute_index (Array<int>& ra_idx, + const dim_vector& dimensions) +{ + return ::compute_index (ra_idx, dimensions); +} + NDS_CMP_OPS(ComplexNDArray, real, Complex, real) NDS_BOOL_OPS(ComplexNDArray, Complex, 0.0)
--- a/liboctave/CNDArray.h +++ b/liboctave/CNDArray.h @@ -74,8 +74,8 @@ // XXX FIXME XXX -- this is not quite the right thing. - boolMatrix all (int dim = -1) const; - boolMatrix any (int dim = -1) const; + boolNDArray all (int dim = -1) const; + boolNDArray any (int dim = -1) const; ComplexMatrix matrix_value (void) const; @@ -85,6 +85,9 @@ const dim_vector& dimensions, int start_dimension = 0); + static int compute_index (Array<int>& ra_idx, + const dim_vector& dimensions); + // i/o // friend std::ostream& operator << (std::ostream& os, const NDArray& a);
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,16 @@ +2003-10-27 Petter Risholm <risholm@stud.ntnu.no> + + * mx-inlines.cc (MX_ND_ALL_EXPR, MX_ND_ANY_EXPR, + MX_ND_ALL_EVAL, MX_ND_ANY_EVAL, MX_ND_ALL_ANY): New macros. + * dNDArray.h (NDArray::all, NDArray::any): Return type now boolNDArray. + * CNDArray.h (ComplexNDArray::all, ComplexNDArray::any): Likewise. + * boolNDArray.h (boolNDArray::all, boolNDArray::any): Likewise. + * chNDArray.h (charNDArray::all, charNDArray::any): Likewise. + * dNDArray.cc (NDArray::all, NDArray::any): Make them work. + * CNDArray.cc (ComplexNDArray::all, ComplexNDArray::any): Likewise. + * boolNDArray.cc (boolNDArray::all, boolNDArray::any): Likewise. + * chNDArray.cc (charNDArray::all, charNDArray::any): Likewise. + 2003-10-27 John W. Eaton <jwe@bevo.che.wisc.edu> * Array.cc (Array<T>::resize_and_fill): Allow number of dimensions
--- a/liboctave/boolNDArray.cc +++ b/liboctave/boolNDArray.cc @@ -50,38 +50,16 @@ // XXX FIXME XXX -- this is not quite the right thing. -boolMatrix +boolNDArray boolNDArray::all (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - boolMatrix tmp = matrix_value (); - retval = tmp.all (dim); - } - else - (*current_liboctave_error_handler) - ("all is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR)); } -boolMatrix +boolNDArray boolNDArray::any (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - boolMatrix tmp = matrix_value (); - retval = tmp.any (dim); - } - else - (*current_liboctave_error_handler) - ("any is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR)); } boolMatrix @@ -119,6 +97,13 @@ ::increment_index (ra_idx, dimensions, start_dimension); } +int +boolNDArray::compute_index (Array<int>& ra_idx, + const dim_vector& dimensions) +{ + return ::compute_index (ra_idx, dimensions); +} + NDND_CMP_OPS (boolNDArray, , boolNDArray, ) /*
--- a/liboctave/boolNDArray.h +++ b/liboctave/boolNDArray.h @@ -68,8 +68,8 @@ // XXX FIXME XXX -- this is not quite the right thing. - boolMatrix all (int dim = -1) const; - boolMatrix any (int dim = -1) const; + boolNDArray all (int dim = -1) const; + boolNDArray any (int dim = -1) const; boolMatrix matrix_value (void) const; @@ -79,6 +79,9 @@ const dim_vector& dimensions, int start_dimension = 0); + static int compute_index (Array<int>& ra_idx, + const dim_vector& dimensions); + // i/o // friend std::ostream& operator << (std::ostream& os, const NDArray& a);
--- a/liboctave/chNDArray.cc +++ b/liboctave/chNDArray.cc @@ -37,38 +37,16 @@ // XXX FIXME XXX -- this is not quite the right thing. -boolMatrix +boolNDArray charNDArray::all (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - charMatrix tmp = matrix_value (); - retval = tmp.all (dim); - } - else - (*current_liboctave_error_handler) - ("all is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ALL_EVAL (elem (iter_idx) == ' ')); } -boolMatrix +boolNDArray charNDArray::any (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - charMatrix tmp = matrix_value (); - retval = tmp.any (dim); - } - else - (*current_liboctave_error_handler) - ("any is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ANY_EVAL (elem (iter_idx) != ' ')); } charMatrix @@ -106,6 +84,13 @@ ::increment_index (ra_idx, dimensions, start_dimension); } +int +charNDArray::compute_index (Array<int>& ra_idx, + const dim_vector& dimensions) +{ + return ::compute_index (ra_idx, dimensions); +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/liboctave/chNDArray.h +++ b/liboctave/chNDArray.h @@ -69,8 +69,8 @@ // XXX FIXME XXX -- this is not quite the right thing. - boolMatrix all (int dim = -1) const; - boolMatrix any (int dim = -1) const; + boolNDArray all (int dim = -1) const; + boolNDArray any (int dim = -1) const; charMatrix matrix_value (void) const; @@ -80,6 +80,9 @@ const dim_vector& dimensions, int start_dimension = 0); + static int compute_index (Array<int>& ra_idx, + const dim_vector& dimensions); + // i/o // friend std::ostream& operator << (std::ostream& os, const charNDArray& a);
--- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -65,38 +65,16 @@ // XXX FIXME XXX -- this is not quite the right thing. -boolMatrix +boolNDArray NDArray::all (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - Matrix tmp = matrix_value (); - retval = tmp.all (dim); - } - else - (*current_liboctave_error_handler) - ("all is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR)); } -boolMatrix +boolNDArray NDArray::any (int dim) const { - boolMatrix retval; - - if (dimensions.length () == 2) - { - Matrix tmp = matrix_value (); - retval = tmp.any (dim); - } - else - (*current_liboctave_error_handler) - ("any is not yet implemented for N-d Arrays"); - - return retval; + MX_ND_ALL_ANY (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR)); } Matrix @@ -133,6 +111,13 @@ ::increment_index (ra_idx, dimensions, start_dimension); } +int +NDArray::compute_index (Array<int>& ra_idx, + const dim_vector& dimensions) +{ + return ::compute_index (ra_idx, dimensions); +} + bool NDArray::any_element_is_negative (bool neg_zero) const {
--- a/liboctave/dNDArray.h +++ b/liboctave/dNDArray.h @@ -72,8 +72,8 @@ // XXX FIXME XXX -- this is not quite the right thing. - boolMatrix all (int dim = -1) const; - boolMatrix any (int dim = -1) const; + boolNDArray all (int dim = -1) const; + boolNDArray any (int dim = -1) const; Matrix matrix_value (void) const; @@ -83,6 +83,9 @@ const dim_vector& dimensions, int start_dimension = 0); + static int compute_index (Array<int>& ra_idx, + const dim_vector& dimensions); + // i/o // friend std::ostream& operator << (std::ostream& os, const NDArray& a);
--- a/liboctave/mx-inlines.cc +++ b/liboctave/mx-inlines.cc @@ -350,6 +350,105 @@ #define MX_ANY_OP(DIM) MX_ANY_ALL_OP (DIM, false, !=, true) +#define MX_ND_ALL_EXPR elem (iter_idx) == 0 + +#define MX_ND_ANY_EXPR elem (iter_idx) + +#define MX_ND_ALL_EVAL(TEST_EXPR) \ + if (TEST_EXPR) \ + { \ + if (dim > -1) \ + iter_idx (dim) = 0; \ + retval (iter_idx) = 0; \ + break; \ + } \ + else \ + { \ + if (dim > -1) \ + iter_idx (dim) = 0; \ + retval (iter_idx) = 1; \ + } \ + +#define MX_ND_ANY_EVAL(TEST_EXPR) \ + if (TEST_EXPR) \ + { \ + if (dim > -1) \ + iter_idx (dim) = 0; \ + retval (iter_idx) = 1; \ + break; \ + } + +#define MX_ND_ALL_ANY(EVAL_EXPR) \ + \ + boolNDArray retval; \ + \ + dim_vector dv = dims (); \ + \ + if (dim == -1)/* We need to find first non-singleton dim */ \ + { \ + for (int i = 0; i < dv.length (); i++) \ + { \ + if (dv (i) > 1) \ + { \ + dim = i; \ + break; \ + } \ + } \ + if (dim == -1) \ + { \ + (*current_liboctave_error_handler) \ + ("all dimensions are singleton"); \ + 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); \ + if (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 */ \ + Array<int> temp_dv (dv.length (), 0); \ + for (int x = 0; x < dv.length (); x++) \ + temp_dv (x) = dv (x) - 1; \ + \ + /* 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); \ + \ + Array<int> iter_idx (dv.length (), 0); \ + \ + /* 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; \ + \ + EVAL_EXPR \ + } \ + \ + if (dim > -1) \ + iter_idx (dim) = 0; \ + \ + increment_index (iter_idx, dv); \ + } \ + \ + return retval + + #endif /*
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2003-10-27 Petter Risholm <risholm@stud.ntnu.no> + * ov-base-mat.cc (octave_base_matrix<MT>::is_true): + Only work for 2-dimensional objects. + * data.cc (ANY_ALL (FCN)): Allow dim to take values large than 2. + * ov.h (octave_value::ndims): New function. * ov-base.h (octave_base_value::ndims): Likewise. * ov-base-scalar.h (octave_base_scalar<T>::ndims): Likewise.
--- a/src/data.cc +++ b/src/data.cc @@ -53,7 +53,7 @@ \ if (! error_state) \ { \ - if (dim <= 1 && dim >= -1) \ + if (dim >= -1) \ retval = args(0).FCN (dim); \ else \ error (#FCN ": invalid dimension argument = %d", dim + 1); \ @@ -366,7 +366,7 @@ \ if (! error_state) \ { \ - if (dim <= 1 && dim >= -1) \ + if (dim >= -1) \ { \ if (arg.is_real_type ()) \ { \
--- a/src/ov-base-mat.cc +++ b/src/ov-base-mat.cc @@ -176,13 +176,19 @@ { bool retval = false; - if (rows () > 0 && columns () > 0) + if (matrix.dims () . length () == 2) { - boolMatrix m = (matrix.all () . all ()); - - retval = (m.rows () == 1 && m.columns () == 1 && m(0,0)); + if (rows () > 0 && columns () > 0) + { + boolNDArray m = (matrix.all () . all ()); + + retval = (m.rows () == 1 && m.columns () == 1 && m(0,0)); + } } - + else + (*current_liboctave_error_handler) + ("is_true not yet implemented for N-d Arrays"); + return retval; } @@ -192,7 +198,7 @@ { int retval = 0; - dim_vector dv = dims(); + dim_vector dv = dims (); for (int i = 0; i < dv.length (); i++) if (dv(i) > retval)