# HG changeset patch # User jwe # Date 1158352158 0 # Node ID 4289ed95dde81e90aea9f6925e73505ae89bb4ce # Parent 265723390e7b3a87428be390eb21f7d65e209b70 [project @ 2006-09-15 20:29:18 by jwe] diff -r 265723390e7b -r 4289ed95dde8 liboctave/Array.cc --- a/liboctave/Array.cc Fri Sep 15 17:30:23 2006 +0000 +++ b/liboctave/Array.cc Fri Sep 15 20:29:18 2006 +0000 @@ -2358,7 +2358,7 @@ template Array -Array::index (Array& ra_idx, int resize_ok, const T&) const +Array::index (Array& 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); diff -r 265723390e7b -r 4289ed95dde8 liboctave/ChangeLog --- a/liboctave/ChangeLog Fri Sep 15 17:30:23 2006 +0000 +++ b/liboctave/ChangeLog Fri Sep 15 20:29:18 2006 +0000 @@ -1,3 +1,10 @@ +2006-09-15 John W. Eaton + + * Array.cc (Array::index (Array&, int, const T&) const): + Handle resizing. + + * intNDArray.h (intNDArray:elt_type): New typedef. + 2006-09-11 John W. Eaton * dMatrix.cc (operator * (const Matrix&, const Matrix&))): diff -r 265723390e7b -r 4289ed95dde8 liboctave/intNDArray.h --- a/liboctave/intNDArray.h Fri Sep 15 17:30:23 2006 +0000 +++ b/liboctave/intNDArray.h Fri Sep 15 20:29:18 2006 +0000 @@ -32,6 +32,8 @@ intNDArray : public MArrayN { public: + + typedef T elt_type; intNDArray (void) : MArrayN () { } diff -r 265723390e7b -r 4289ed95dde8 src/ChangeLog --- a/src/ChangeLog Fri Sep 15 17:30:23 2006 +0000 +++ b/src/ChangeLog Fri Sep 15 20:29:18 2006 +0000 @@ -1,3 +1,14 @@ +2006-09-15 John W. Eaton + + * 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::convert_to_str_internal, + octave_base_int_matrix::convert_to_str_internal): + New functions. + * ov-base-int.h: Provide decls. + 2006-09-15 Soren Hauberg . * data.cc (Fsize): If nargout > ndims, fill with 1. diff -r 265723390e7b -r 4289ed95dde8 src/OPERATORS/op-double-conv.cc --- a/src/OPERATORS/op-double-conv.cc Fri Sep 15 17:30:23 2006 +0000 +++ b/src/OPERATORS/op-double-conv.cc Fri Sep 15 20:29:18 2006 +0000 @@ -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); } diff -r 265723390e7b -r 4289ed95dde8 src/ops.h --- a/src/ops.h Fri Sep 15 17:30:23 2006 +0000 +++ b/src/ops.h Fri Sep 15 20:29:18 2006 +0000 @@ -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, ) diff -r 265723390e7b -r 4289ed95dde8 src/ov-base-int.cc --- a/src/ov-base-int.cc Fri Sep 15 17:30:23 2006 +0000 +++ b/src/ov-base-int.cc Fri Sep 15 20:29:18 2006 +0000 @@ -69,6 +69,48 @@ } template +octave_value +octave_base_int_matrix::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 (ival); + } + + retval = octave_value (chm, true, type); + + return retval; +} + +template bool octave_base_int_matrix::save_ascii (std::ostream& os, bool&) { @@ -330,6 +372,30 @@ } template +octave_value +octave_base_int_scalar::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 (ival)), type); + + return retval; +} + +template bool octave_base_int_scalar::save_ascii (std::ostream& os, bool&) { diff -r 265723390e7b -r 4289ed95dde8 src/ov-base-int.h --- a/src/ov-base-int.h Fri Sep 15 17:30:23 2006 +0000 +++ b/src/ov-base-int.h Fri Sep 15 20:29:18 2006 +0000 @@ -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); diff -r 265723390e7b -r 4289ed95dde8 src/ov-cell.cc --- a/src/ov-cell.cc Fri Sep 15 17:30:23 2006 +0000 +++ b/src/ov-cell.cc Fri Sep 15 20:29:18 2006 +0000 @@ -164,7 +164,7 @@ if (! error_state) { - Cell tcell = tmp.cell_value (); + const Cell tcell = tmp.cell_value (); if (! error_state && tcell.length () == 1) {