Mercurial > hg > octave-lyh
changeset 5992:4289ed95dde8
[project @ 2006-09-15 20:29:18 by jwe]
author | jwe |
---|---|
date | Fri, 15 Sep 2006 20:29:18 +0000 |
parents | 265723390e7b |
children | 401ca0de8506 |
files | liboctave/Array.cc liboctave/ChangeLog liboctave/intNDArray.h src/ChangeLog src/OPERATORS/op-double-conv.cc src/ops.h src/ov-base-int.cc src/ov-base-int.h src/ov-cell.cc |
diffstat | 9 files changed, 110 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2358,7 +2358,7 @@ template <class T> Array<T> -Array<T>::index (Array<idx_vector>& ra_idx, int resize_ok, const T&) const +Array<T>::index (Array<idx_vector>& ra_idx, int resize_ok, const T& rfv) const { // This function handles all calls with more than one idx. // For (3x3x3), the call can be A(2,5), A(2,:,:), A(3,2,3) etc. @@ -2381,14 +2381,17 @@ else trim_trailing_singletons = false; - for (octave_idx_type i = 0; i < iidx.capacity (); i++) - if (iidx (i) != 0) - { - (*current_liboctave_error_handler) - ("index exceeds N-d array dimensions"); - - return retval; - } + if (! resize_ok) + { + for (octave_idx_type i = 0; i < iidx.capacity (); i++) + if (iidx (i) != 0) + { + (*current_liboctave_error_handler) + ("index exceeds N-d array dimensions"); + + return retval; + } + } } ra_idx.resize (ra_idx_len); @@ -2437,9 +2440,8 @@ octave_idx_type numelem_elt = get_scalar_idx (elt_idx, new_dims); - if (numelem_elt > length () || numelem_elt < 0) - (*current_liboctave_error_handler) - ("invalid N-d array index"); + if (numelem_elt >= length () || numelem_elt < 0) + retval.elem (i) = rfv; else retval.elem (i) = elem (numelem_elt);
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,10 @@ +2006-09-15 John W. Eaton <jwe@octave.org> + + * Array.cc (Array<T>::index (Array<idx_vector>&, int, const T&) const): + Handle resizing. + + * intNDArray.h (intNDArray<T>:elt_type): New typedef. + 2006-09-11 John W. Eaton <jwe@octave.org> * dMatrix.cc (operator * (const Matrix&, const Matrix&))):
--- a/liboctave/intNDArray.h +++ b/liboctave/intNDArray.h @@ -32,6 +32,8 @@ intNDArray : public MArrayN<T> { public: + + typedef T elt_type; intNDArray (void) : MArrayN<T> () { }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2006-09-15 John W. Eaton <jwe@octave.org> + + * ops.h (DEFSTRDBLCONVFN): New arg, TFROM. + * OPERATORS/op-double-conv.cc: Declare and install sq_string + conversions too. + + * ov-base-int.cc (octave_base_int_scalar<T>::convert_to_str_internal, + octave_base_int_matrix<T>::convert_to_str_internal): + New functions. + * ov-base-int.h: Provide decls. + 2006-09-15 Soren Hauberg <soren@hauberg.org>. * data.cc (Fsize): If nargout > ndims, fill with 1.
--- a/src/OPERATORS/op-double-conv.cc +++ b/src/OPERATORS/op-double-conv.cc @@ -77,7 +77,8 @@ DEFDBLCONVFN (range_to_double_matrix, range, array) -DEFSTRDBLCONVFN(char_matrix_str_to_double_matrix) +DEFSTRDBLCONVFN(char_matrix_str_to_double_matrix, char_matrix_str) +DEFSTRDBLCONVFN(char_matrix_sq_str_to_double_matrix, char_matrix_sq_str) DEFDBLCONVFN (double_scalar_to_double_matrix, scalar, array) @@ -113,6 +114,7 @@ INSTALL_CONVOP (octave_range, octave_matrix, range_to_double_matrix); INSTALL_CONVOP (octave_char_matrix_str, octave_matrix, char_matrix_str_to_double_matrix); + INSTALL_CONVOP (octave_char_matrix_sq_str, octave_matrix, char_matrix_sq_str_to_double_matrix); INSTALL_CONVOP (octave_scalar, octave_matrix, double_scalar_to_double_matrix); }
--- a/src/ops.h +++ b/src/ops.h @@ -218,8 +218,8 @@ #define DEFSTRINTCONVFN(name, tto) \ DEFCONVFNX(name, char_matrix_str, tto ## _matrix, tto, char_) -#define DEFSTRDBLCONVFN(name) \ - DEFCONVFNX(name, char_matrix_str, matrix, , char_) +#define DEFSTRDBLCONVFN(name, tfrom) \ + DEFCONVFNX(name, tfrom, matrix, , char_) #define DEFCONVFN(name, tfrom, tto) \ DEFCONVFNX (name, tfrom, tto ## _matrix, tto, )
--- a/src/ov-base-int.cc +++ b/src/ov-base-int.cc @@ -69,6 +69,48 @@ } template <class T> +octave_value +octave_base_int_matrix<T>::convert_to_str_internal (bool, bool, char type) const +{ + octave_value retval; + dim_vector dv = this->dims (); + octave_idx_type nel = dv.numel (); + + charNDArray chm (dv); + + bool warned = false; + + for (octave_idx_type i = 0; i < nel; i++) + { + OCTAVE_QUIT; + + typename T::elt_type tmp = this->matrix(i); + + typename T::elt_type::val_type ival = tmp.value (); + + if (ival < 0 || ival > UCHAR_MAX) + { + // FIXME -- is there something better we could do? + + ival = 0; + + if (! warned) + { + + ::warning ("range error for conversion to character value"); + warned = true; + } + } + else + chm (i) = static_cast<char> (ival); + } + + retval = octave_value (chm, true, type); + + return retval; +} + +template <class T> bool octave_base_int_matrix<T>::save_ascii (std::ostream& os, bool&) { @@ -330,6 +372,30 @@ } template <class T> +octave_value +octave_base_int_scalar<T>::convert_to_str_internal (bool, bool, char type) const +{ + octave_value retval; + + T tmp = this->scalar; + + typename T::val_type ival = tmp.value (); + + if (ival < 0 || ival > UCHAR_MAX) + { + // FIXME -- is there something better we could do? + + ival = 0; + + ::warning ("range error for conversion to character value"); + } + else + retval = octave_value (std::string (1, static_cast<char> (ival)), type); + + return retval; +} + +template <class T> bool octave_base_int_scalar<T>::save_ascii (std::ostream& os, bool&) {
--- a/src/ov-base-int.h +++ b/src/ov-base-int.h @@ -67,6 +67,8 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; + octave_value convert_to_str_internal (bool, bool, char type) const; + bool save_ascii (std::ostream& os, bool& infnan_warned); bool load_ascii (std::istream& is); @@ -108,6 +110,8 @@ // void decrement (void) { scalar -= 1; } + octave_value convert_to_str_internal (bool, bool, char type) const; + bool save_ascii (std::ostream& os, bool&); bool load_ascii (std::istream& is);