# HG changeset patch # User jwe # Date 1093973225 0 # Node ID 48a39e2b2ab771511701fcbccde0643381d416b9 # Parent 4bd917f8a4a7510de22db3089502133586837b81 [project @ 2004-08-31 17:27:04 by jwe] diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 doc/interpreter/strings.txi --- a/doc/interpreter/strings.txi Tue Aug 31 15:09:17 2004 +0000 +++ b/doc/interpreter/strings.txi Tue Aug 31 17:27:05 2004 +0000 @@ -64,7 +64,7 @@ Represents a literal single-quote character, @samp{'}. @item \0 -Represents the ``nul'' character, control-@, ASCII code 0. +Represents the ``nul'' character, control-@@, ASCII code 0. @item \a Represents the ``alert'' character, control-g, ASCII code 7. diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 liboctave/ChangeLog --- a/liboctave/ChangeLog Tue Aug 31 15:09:17 2004 +0000 +++ b/liboctave/ChangeLog Tue Aug 31 17:27:05 2004 +0000 @@ -1,5 +1,7 @@ 2004-08-31 John W. Eaton + * Makefile.in (EXTRAS): Add intNDArray.cc to the list. + * data-conv.h (oct_data_conv::data_type): Include sized types. Explicitly number enum elements. diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 liboctave/Makefile.in --- a/liboctave/Makefile.in Tue Aug 31 15:09:17 2004 +0000 +++ b/liboctave/Makefile.in Tue Aug 31 17:27:05 2004 +0000 @@ -129,7 +129,7 @@ $(LIBOCT_READLINE_SOURCES) \ $(LIBOCT_PATHSEARCH_SOURCES) -EXTRAS := mx-inlines.cc kpse.cc +EXTRAS := mx-inlines.cc kpse.cc intNDArray.cc INCLUDES_FOR_INSTALL := $(INCLUDES) $(TEMPLATE_SRC) $(EXTRAS) diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/base/bode.m --- a/scripts/control/base/bode.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/base/bode.m Tue Aug 31 17:27:05 2004 +0000 @@ -80,7 +80,6 @@ ## the vector of frequency values used ## @end table ## -## @strong{Notes} ## @enumerate ## @item If no output arguments are given, e.g., ## @example diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/base/ctrb.m --- a/scripts/control/base/ctrb.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/base/ctrb.m Tue Aug 31 17:27:05 2004 +0000 @@ -27,7 +27,7 @@ ## ## of a system data structure or the pair (@var{a}, @var{b}). ## -## @strong{Note} @code{ctrb} forms the controllability matrix. +## @code{ctrb} forms the controllability matrix. ## The numerical properties of @code{is_controllable} ## are much better for controllability tests. ## @end deftypefn diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/hinf/is_dgkf.m --- a/scripts/control/hinf/is_dgkf.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/hinf/is_dgkf.m Tue Aug 31 17:27:05 2004 +0000 @@ -60,13 +60,13 @@ ## @item bu ## (@var{n} x @var{nu}) @var{ru}-transformed controlled input matrix; ## -## @strong{Note} @math{B = [Bw Bu]} +## @math{B = [Bw Bu]} ## @item cz ## (@var{nz} x @var{n}) Qz-transformed error output matrix ## @item cy ## (@var{ny} x @var{n}) @var{ry}-transformed measured output matrix ## -## @strong{Note} @math{C = [Cz; Cy]} +## @math{C = [Cz; Cy]} ## @item dzu ## @item dyw ## off-diagonal blocks of transformed system @math{D} matrix that enter diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/obsolete/qzval.m --- a/scripts/control/obsolete/qzval.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/obsolete/qzval.m Tue Aug 31 17:27:05 2004 +0000 @@ -32,7 +32,7 @@ ## ## @var{a} and @var{b} must be real matrices. ## -## @strong{Note} @code{qzval} is obsolete; use @code{qz} instead. +## @code{qzval} is obsolete; use @code{qz} instead. ## @end deftypefn ## Author: A. S. Hodel diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/system/c2d.m --- a/scripts/control/system/c2d.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/system/c2d.m Tue Aug 31 17:27:05 2004 +0000 @@ -44,7 +44,7 @@ ## @item t ## sampling time; required if sys is purely continuous. ## -## @strong{Note} If the 2nd argument is not a string, @code{c2d} assumes that +## If the 2nd argument is not a string, @code{c2d} assumes that ## the 2nd argument is @var{t} and performs appropriate argument checks. ## @item "matched" ## Use the matched pole/zero equivalent transformation (currently only @@ -66,7 +66,7 @@ ## @end example ## via the matrix exponential or bilinear transform ## -## @strong{Note} This function adds the suffix @code{_d} +## This function adds the suffix @code{_d} ## to the names of the new discrete states. ## @end deftypefn diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/system/ss.m --- a/scripts/control/system/ss.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/system/ss.m Tue Aug 31 17:27:05 2004 +0000 @@ -72,7 +72,7 @@ ## ## Unlike states, discrete/continous outputs may appear in any order. ## -## @strong{Note} @code{sys2ss} returns a vector @var{yd} where +## @code{sys2ss} returns a vector @var{yd} where ## @var{yd}(@var{outlist}) = 1; all other entries of @var{yd} are 0. ## ## @strong{Outputs} diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/system/ss2sys.m --- a/scripts/control/system/ss2sys.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/system/ss2sys.m Tue Aug 31 17:27:05 2004 +0000 @@ -72,7 +72,7 @@ ## ## Unlike states, discrete/continous outputs may appear in any order. ## -## @strong{Note} @code{sys2ss} returns a vector @var{yd} where +## @code{sys2ss} returns a vector @var{yd} where ## @var{yd}(@var{outlist}) = 1; all other entries of @var{yd} are 0. ## ## @strong{Outputs} diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/control/system/sysgettype.m --- a/scripts/control/system/sysgettype.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/control/system/sysgettype.m Tue Aug 31 17:27:05 2004 +0000 @@ -28,7 +28,7 @@ ## constructed: ## values: @code{"ss"}, @code{"zp"}, or @code{"tf"} ## -## @strong{Note} FIR initialized systems return @code{systype="tf"}. +## FIR initialized systems return @code{systype="tf"}. ## @end deftypefn function systype = sysgettype (sys) diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/strings/index.m --- a/scripts/strings/index.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/strings/index.m Tue Aug 31 17:27:05 2004 +0000 @@ -27,7 +27,7 @@ ## @result{} 4 ## @end example ## -## @strong{Note:} This function does not work for arrays of strings. +## @strong{Caution:} This function does not work for arrays of strings. ## @end deftypefn ## Author: Kurt Hornik diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/strings/rindex.m --- a/scripts/strings/rindex.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/strings/rindex.m Tue Aug 31 17:27:05 2004 +0000 @@ -27,7 +27,7 @@ ## @result{} 6 ## @end example ## -## @strong{Note:} This function does not work for arrays of strings. +## @strong{Caution:} This function does not work for arrays of strings. ## @end deftypefn ## Author: Kurt Hornik diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/strings/str2mat.m --- a/scripts/strings/str2mat.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/strings/str2mat.m Tue Aug 31 17:27:05 2004 +0000 @@ -23,7 +23,6 @@ ## its rows. Each string is padded with blanks in order to form a valid ## matrix. ## -## @strong{Note:} ## This function is modelled after @sc{Matlab}. In Octave, you can create ## a matrix of strings by @code{[@var{s_1}; @dots{}; @var{s_n}]} even if ## the strings are not all the same length. diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/strings/strcmp.m --- a/scripts/strings/strcmp.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/strings/strcmp.m Tue Aug 31 17:27:05 2004 +0000 @@ -21,7 +21,7 @@ ## @deftypefn {Function File} {} strcmp (@var{s1}, @var{s2}) ## Compares two strings, returning 1 if they are the same, and 0 otherwise. ## -## @strong{Note:} For compatibility with @sc{Matlab}, Octave's strcmp +## @strong{Caution:} For compatibility with @sc{Matlab}, Octave's strcmp ## function returns 1 if the strings are equal, and 0 otherwise. This is ## just the opposite of the corresponding C library function. ## @end deftypefn diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 scripts/strings/substr.m --- a/scripts/strings/substr.m Tue Aug 31 15:09:17 2004 +0000 +++ b/scripts/strings/substr.m Tue Aug 31 17:27:05 2004 +0000 @@ -34,7 +34,6 @@ ## @end example ## ## @quotation -## @strong{Note:} ## This function is patterned after AWK. You can get the same result by ## @code{@var{s} (@var{beg} : (@var{beg} + @var{len} - 1))}. ## @end quotation diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 src/ChangeLog --- a/src/ChangeLog Tue Aug 31 15:09:17 2004 +0000 +++ b/src/ChangeLog Tue Aug 31 17:27:05 2004 +0000 @@ -1,3 +1,13 @@ +2004-08-31 John W. Eaton + + * data.cc (fill_matrix, identity_matrix): Convert class name to + oct_data_conv::data_type and switch on that. + (identity_matrix (int, int)): New template. + (identity_matrix (int, int, const std::string&)): Use it. + + * ov.h (octave_type_traits, octave_array_type_traits): Move here. + * oct-stream.cc: From here. + 2004-08-31 David Bateman * data.cc (Fzeros, Fones, Feye): Update help text for optional diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 src/data.cc --- a/src/data.cc Tue Aug 31 15:09:17 2004 +0000 +++ b/src/data.cc Tue Aug 31 17:27:05 2004 +0000 @@ -1208,31 +1208,24 @@ int nargin = args.length (); - std::string nm = "double"; - - int ndim = 0; + oct_data_conv::data_type dt = oct_data_conv::dt_double; - dim_vector dims; + dim_vector dims (1, 1); - // Check for type information. - if (nargin > 0 && args(nargin-1).is_string ()) { - nm = args(nargin-1).string_value(); + std::string nm = args(nargin-1).string_value (); nargin--; - if (nm != "int8" && nm != "int16" && nm != "int32" && nm != "int64" && - nm != "uint8" && nm != "uint16" && nm != "uint32" && nm != "uint64" - && nm != "double") - error ("%s: Unrecognized or illegal classname", fcn); + dt = oct_data_conv::string_to_data_type (nm); + + if (error_state) + return retval; } - // determine matrix dimension - switch (nargin) { case 0: - ndim = 0; break; case 1: @@ -1259,78 +1252,62 @@ if (! error_state) { - ndim = dims.length (); - - for (int i = ndim-1; i > 1; i--) - { - if (dims(i) == 1) - ndim--; - else - break; - } - - dims.resize (ndim); + dims.chop_trailing_singletons (); check_dimensions (dims, fcn); + // XXX FIXME XXX -- perhaps this should be made extensible by + // using the class name to lookup a function to call to create + // the new value. + + // Note that automatic narrowing will handle conversion from + // NDArray to scalar. + if (! error_state) { + switch (dt) + { + case oct_data_conv::dt_int8: + retval = int8NDArray (dims, val); + break; -#define INT_FILL_MATRIX(TYPE) \ - { \ - switch (ndim) \ - { \ - case 0: \ - retval = octave_ ## TYPE (val); \ - break; \ - \ - default: \ - retval = TYPE ## NDArray (dims, val); \ - break; \ - } \ - } + case oct_data_conv::dt_uint8: + retval = uint8NDArray (dims, val); + break; + + case oct_data_conv::dt_int16: + retval = int16NDArray (dims, val); + break; + + case oct_data_conv::dt_uint16: + retval = uint16NDArray (dims, val); + break; + + case oct_data_conv::dt_int32: + retval = int32NDArray (dims, val); + break; - if (nm == "int8") - INT_FILL_MATRIX (int8) - else if (nm == "int16") - INT_FILL_MATRIX (int16) - else if (nm == "int32") - INT_FILL_MATRIX (int32) - else if (nm == "int64") - INT_FILL_MATRIX (int64) - else if (nm == "uint8") - INT_FILL_MATRIX (uint8) - else if (nm == "uint16") - INT_FILL_MATRIX (uint16) - else if (nm == "uint32") - INT_FILL_MATRIX (uint32) - else if (nm == "uint64") - INT_FILL_MATRIX (uint64) - else - { - // Construct either scalar, matrix or N-d array. - switch (ndim) - { - case 0: - retval = val; - break; + case oct_data_conv::dt_uint32: + retval = uint32NDArray (dims, val); + break; + + case oct_data_conv::dt_int64: + retval = int64NDArray (dims, val); + break; - case 1: - retval = Matrix (dims(0), dims(0), val); - break; - - case 2: - retval = Matrix (dims(0), dims(1), val); - break; + case oct_data_conv::dt_uint64: + retval = uint64NDArray (dims, val); + break; - default: - retval = NDArray (dims, val); - break; - } + case oct_data_conv::dt_single: // XXX FIXME XXX + case oct_data_conv::dt_double: + retval = NDArray (dims, val); + break; + + default: + error ("%s: invalid class name", fcn); + break; } - -#undef INT_FILL_MATRIX - } } @@ -1384,72 +1361,101 @@ return fill_matrix (args, 0.0, "zeros"); } +template +octave_value +identity_matrix (int nr, int nc) +{ + octave_value retval; + + typename octave_array_type_traits::element_type one (1); + + if (nr == 1 && nc == 1) + retval = one; + else + { + dim_vector dims (nr, nc); + + typename octave_array_type_traits::element_type zero (0); + + MT m (dims, zero); + + if (nr > 0 && nc > 0) + { + int n = std::min (nr, nc); + + for (int i = 0; i < n; i++) + m(i,i) = one; + } + + retval = m; + } + + return retval; +} + static octave_value identity_matrix (int nr, int nc, const std::string& nm) { octave_value retval; -#define INT_EYE_MATRIX(TYPE) \ - { \ - if (nr == 1 && nc == 1) \ - retval = octave_ ## TYPE (1); \ - else \ - { \ - dim_vector dims (nr, nc); \ - TYPE ## NDArray m (dims, octave_ ## TYPE (0));\ - if (nr > 0 && nc > 0) \ - { \ - int n = std::min (nr, nc); \ - \ - for (int i = 0; i < n; i++) \ - m (i, i) = octave_ ## TYPE (1); \ - } \ - retval = m; \ - } \ - } + oct_data_conv::data_type dt = oct_data_conv::string_to_data_type (nm); + + // XXX FIXME XXX -- perhaps this should be made extensible by using + // the class name to lookup a function to call to create the new + // value. + + if (! error_state) + { + switch (dt) + { + case oct_data_conv::dt_int8: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_uint8: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_int16: + retval = identity_matrix (nr, nc); + break; - if (nm == "int8") - INT_EYE_MATRIX (int8) - else if (nm == "int16") - INT_EYE_MATRIX (int16) - else if (nm == "int32") - INT_EYE_MATRIX (int32) - else if (nm == "int64") - INT_EYE_MATRIX (int64) - else if (nm == "uint8") - INT_EYE_MATRIX (uint8) - else if (nm == "uint16") - INT_EYE_MATRIX (uint16) - else if (nm == "uint32") - INT_EYE_MATRIX (uint32) - else if (nm == "uint64") - INT_EYE_MATRIX (uint64) - else - { - if (nr == 1 && nc == 1) - retval = 1.0; - else - { + case oct_data_conv::dt_uint16: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_int32: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_uint32: + retval = identity_matrix (nr, nc); + break; - Matrix m (nr, nc, 0.0); - - if (nr > 0 && nc > 0) - { - int n = std::min (nr, nc); + case oct_data_conv::dt_int64: + retval = identity_matrix (nr, nc); + break; + + case oct_data_conv::dt_uint64: + retval = identity_matrix (nr, nc); + break; - for (int i = 0; i < n; i++) - m (i, i) = 1.0; - } + case oct_data_conv::dt_single: // XXX FIXME XXX + case oct_data_conv::dt_double: + retval = identity_matrix (nr, nc); + break; - retval = m; + default: + error ("eye: invalid class name"); + break; } } -#undef INT_EYE_MATRIX - return retval; } +#undef INT_EYE_MATRIX + DEFUN (eye, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} eye (@var{x})\n\ diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 src/oct-stream.cc --- a/src/oct-stream.cc Tue Aug 31 15:09:17 2004 +0000 +++ b/src/oct-stream.cc Tue Aug 31 17:27:05 2004 +0000 @@ -2770,61 +2770,6 @@ rep->close (); } -// XXX FIXME XXX -- these trait classes probably belong somehwere else... - -template -class -octave_type_traits -{ -public: - typedef T val_type; -}; - -#define OCTAVE_TYPE_TRAIT(T, VAL_T) \ - template <> \ - class \ - octave_type_traits \ - { \ - public: \ - typedef VAL_T val_type; \ - } - -OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); -OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); -OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); -OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); -OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); -OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); -OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); -OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); - -template -class octave_array_type_traits -{ -public: - typedef T element_type; -}; - -#define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ - template <> \ - class \ - octave_array_type_traits \ - { \ - public: \ - typedef ELT_T element_type; \ - } - -OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); -OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); -OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); -OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); -OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); -OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); -OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); -OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); -OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); -OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); - template octave_value do_read (octave_stream& strm, int nr, int nc, int block_size, diff -r 4bd917f8a4a7 -r 48a39e2b2ab7 src/ov.h --- a/src/ov.h Tue Aug 31 15:09:17 2004 +0000 +++ b/src/ov.h Tue Aug 31 17:27:05 2004 +0000 @@ -951,6 +951,61 @@ extern void install_types (void); +// XXX FIXME XXX -- these trait classes probably belong somehwere else... + +template +class +octave_type_traits +{ +public: + typedef T val_type; +}; + +#define OCTAVE_TYPE_TRAIT(T, VAL_T) \ + template <> \ + class \ + octave_type_traits \ + { \ + public: \ + typedef VAL_T val_type; \ + } + +OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); +OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); +OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); +OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); +OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); +OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); +OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); +OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); + +template +class octave_array_type_traits +{ +public: + typedef T element_type; +}; + +#define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ + template <> \ + class \ + octave_array_type_traits \ + { \ + public: \ + typedef ELT_T element_type; \ + } + +OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); +OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); +OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); +OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); +OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); +OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); +OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); +OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); +OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); +OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); + #endif /*