# HG changeset patch # User Rik # Date 1605820080 28800 # Node ID fa2cdef14442c6c2d815abbaa53895478250233d # Parent a5e267bc293070b18ad1b167535f88e21d0c6bd8# Parent dc3ee9616267490f27544ec7d64a873d7f4ce2c1 maint: merge stable to default. diff -r dc3ee9616267 -r fa2cdef14442 NEWS --- a/NEWS Thu Nov 19 13:05:51 2020 -0800 +++ b/NEWS Thu Nov 19 13:08:00 2020 -0800 @@ -1,269 +1,195 @@ -Summary of important user-visible changes for version 6.1.0 (2020-08-26): ------------------------------------------------------------------------- +Summary of important user-visible changes for version 7 (yyyy-mm-dd): +---------------------------------------------------------------------- ### General improvements -- The `intersect`, `setdiff`, `setxor`, `union`, and `unique` functions - accept a new sorting option `"stable"` which will return output values - in the same order as the input, rather than in ascending order. +- Many functions in Octave can be called in a command form---no +parentheses for invocation and no return argument assignment---or in a +functional form---parentheses and '=' for assignment of return values. -- Complex RESTful web services can now be accessed by the `webread` and - `webwrite` functions alongside with the `weboptions` structure. One - major feature is the support for cookies to enable RESTful - communication with the web service. + **Command Form Example** - Additionally, the system web browser can be opened by the `web` - function. + `mkdir new_directory` -- The `linspace` function now produces symmetrical sequences when the - endpoints are symmetric. This is more intuitive and also compatible - with recent changes made in Matlab R2019b. + **Function Form Example** -- The underlying algorithm of the `rand` function has been changed. - For single precision outputs, the algorithm has been fixed so that it - produces values strictly in the range (0, 1). Previously, it could - occasionally generate the right endpoint value of 1 (See bug #41742). - In addition, the new implementation uses a uniform interval between - floating point values in the range (0, 1) rather than targeting a - uniform density (# of random integers / length along real number - line). + `status = mkdir ("new_directory")` -- Numerical integration has been improved. The `quadv` function has - been re-written so that it can compute integrands of periodic - functions. At the same time, performance is better with ~3.5X fewer - function evaluations required. A bug in `quadgk` that caused complex - path integrals specified with `"Waypoints"` to occasionally be - calculated in the opposite direction was fixed. + Octave now handles errors that occur in a consistent manner. If + called in command form and there is a failure, an error is thrown + and a message printed. If called in functional form, no error or + message is printed and the failure is communicated to the programmer + via the output status variable. + + The following list of functions have been modified. -- The `edit` function option `"editinplace"` now defaults to `true` and - the option `"home"` now defaults to the empty matrix `[]`. Files will - no longer be copied to the user's HOME directory for editing. The old - behavior can be restored by setting `"editinplace"` to `false` and - `"home"` to `"~/octave"`. - -- The `format` command supports two new options: `uppercase` and - `lowercase` (default). With the default, print a lowercase 'e' for - the exponent character in scientific notation and lowercase 'a-f' for - the hex digits representing 10-15. With `uppercase`, print 'E' and - 'A-F' instead. The previous uppercase formats, `E` and `G`, no longer - control the case of the output. - - Additionally, the `format` command can be called with multiple options - for controlling the format, spacing, and case in arbitrary order. - For example: - - format long e uppercase loose + * `copyfile` + * `fcntl` + * `fileattrib` + * `kill` + * `link` + * `mkfifo` + * `movefile` + * `rename` + * `rmdir` + * `symlink` + * `unlink` - Note, in the case of multiple competing format options the rightmost - one is used, and, in case of an error, the previous format remains - unchanged. - -- L-value references (e.g., increment (++), decrement (--), and all - in-place assignment operators (+=, -=, *=, /=, etc.)) are no longer - allowed in anonymous functions. +- Calling a user-defined function with too many inputs or outputs is now +an error. The interpreter makes this check automatically. If a +function uses varargin then the check is skipped for function inputs, +and if a function uses varargout then the check is skipped for function +outputs. Input validation for functions typically begins with checking +the number of inputs and outputs match expectations. Existing code can +be simplified by removing these checks which are now done by the +interpreter. Typically, code blocks like the following can simply be +deleted. -- New warnings have been added about questionable uses of the colon ':' - range operator. Each has a new warning ID so that it can be disabled - if desired. + ## Checking number of inputs + if (nargin > 2) + print_usage (); + endif - > `Octave:colon-complex-argument` : when any arg is complex - > `Octave:colon-nonscalar-argument` : when any arg is non-scalar - -- The `regexp` and related functions now correctly handle and *require* - strings in UTF-8 encoding. As with any other function that requires - strings to be encoded in Octave's native encoding, you can use - `native2unicode` to convert from your preferred locale. For example, - the copyright symbol in UTF-8 is `native2unicode (169, "latin1")`. + ## Checking number of outputs + if (nargout > 1) + print_usage (); + endif -- The startup file `octaverc` can now be located in the platform - dependent location for user local configuration files (e.g., - ${XDG_CONFIG_HOME}/octave/octaverc on Unix-like operating systems or - %APPDATA%\octave\octaverc on Windows). - -- `pkg describe` now lists dependencies and inverse dependencies - (i.e., other installed packages that depend on the package in - question). - -- `pkg test` now tests all functions in a package. - -- When unloading a package, `pkg` now checks if any remaining loaded - packages depend on the one to be removed. If this is the case `pkg` - aborts with an explanatory error message. This behavior can be - overridden with the `-nodeps` option. - -- The command +- Binary and hexadecimal constants like `0b101` and `0xDEADBEEF` now +create integers (unsigned by default) with sizes determined from the +number of digits present. For example, `0xff` creates a `uint8` value +and `0xDEADBEEF` creates a `uint64` value. You may also use a suffix of +the form `s8`, `s16`, `s32`, `s64`, `u8`, `u16`, `u32`, or `u64` to +explicitly specify the data type to use (`u` or `s` to indicate signed +or unsigned and the number to indicate the integer size). - dbstop in CLASS at METHOD - - now works to set breakpoints in classdef constructors and methods. - -#### Graphics backend + Binary constants are limited to 64 binary digits and hexadecimal +constants are limited to 16 hexadecimal digits with no automatic +rounding or conversion to floating point values. Note that this may +cause problems in existing code. For example, an expression like +`[0x1; 0x100; 0x10000]` will be uint8 (because of the rules of +concatenating integers of different sizes) with the larger values +truncated (because of the saturation semantics of integer values). To +avoid these kinds of problems either: 1) declare the first integer to be +of the desired size such as `[0x1u32; 0x100; 0x10000]`, or 2) pad +constants in array expressions with leading zeros so that they use the +same number of digits for each value such as +`[0x00_00_01; 0x00_01_00; 0x01_00_00]`. -- The use of Qt4 for graphics and the GUI is deprecated in Octave - version 6 and no further bug fixes will be made. Qt4 support will be - removed completely in Octave version 7. +- As part of GSoC 2020, Abdallah K. Elshamy implemented the +`jsondecode` and `jsonencode` functions to read and write JSON data. -- The `legend` function has been entirely rewritten. This fixes a - number of historical bugs, and also implements new properties such as - `"AutoUpdate"` and `"NumColumns"`. The gnuplot toolkit---which is no - longer actively maintained---still uses the old legend function. - -- The `axis` function was updated which resolved 10 bugs affecting - axes to which `"equal"` had been applied. +- By default, the history file is now located at $DATA/octave/history, +where $DATA is a platform dependent location for (roaming) user data +files (e.g. ${XDG_DATA_HOME} or, if that is not set, ~/.local/share on +Unix-like operating systems or %APPDATA% on Windows). -- Graphic primitives now accept a color property value of `"none"` - which is useful when a particular primitive needs to be hidden - (for example, the Y-axis of an axes object with `"ycolor" = "none"`) - without hiding the entire primitive `"visibility" = "off"`. +- In debug mode, symbol values are now shown in tooltips when hovering +variables in the editor panel. + +### Graphics backend -- A new property `"FontSmoothing"` has been added to text and axes - objects that controls whether anti-aliasing is used during the - rendering of characters. The default is `"on"` which produces smooth, - more visually appealing text. +- Support for Qt4 for both graphics and the GUI has been removed. -- The figure property `"windowscrollwheelfcn"`is now implemented. - This makes it possible to provide a callback function to be executed - when users manipulate the mouse wheel on a given figure. - -- The figure properties `"pointer"`, `"pointershapecdata"`, and - `"pointershapehotspot"` are now implemented. This makes it possible - to change the shape of the cursor (pointer in Matlab-speak) displayed - in a plot window. +- The additional property `"contextmenu"` has been added to all graphics +objects. It is equivalent to the previously used `"uicontextmenu"` +property which is hidden now. -- The figure property `"paperpositionmode"` now has the default `"auto"` - rather than `"manual"`. This change is more intuitive and is - Matlab compatible. - -- The appearance of patterned lines `"LineStyle" = ":"|"--"|"-."` has - been improved for small widths (`"LineWidth"` less than 1.5 pixels) - which is a common scenario. - -- Printing to EPS files now uses a tight bounding box (`"-tight"` - argument to print) by default. This makes more sense for EPS - files which are normally embedded within other documents, and is - Matlab compatible. If necessary use the `"-loose"` option to - reproduce figures as they appeared in previous versions of Octave. - -- The following print devices are no longer officially supported: cdr, - corel, aifm, ill, cgm, hpgl, mf and dxf. A warning will be thrown - when using those devices, and the code for supporting those formats - will eventually be removed from a future version of Octave. - -- The placement of text subscripts and superscripts has been - re-engineered and now produces visually attractive results similar to - Latex. +- Additional properties have been added to the `axes` graphics object: + * `"alphamap"` (not yet implemented) + * `"alphascale"` (not yet implemented) + * `"colorscale"` (not yet implemented) + * `"fontsizemode"` (not yet implemented) + * `"innerposition"` (equivalent to `"position"`) + * `"interactions"` (not yet implemented) + * `"layout"` (not yet implemented) + * `"legend"` (not yet implemented) + * `"nextseriesindex"` (read-only, used by `scatter` + graphics objects) + * `"positionconstraint"` (replacement for `"activepositionproperty"` + which is now a hidden property. No plans for removal.) + * `"toolbar"` (not yet implemented) + * `"xaxis"` (not yet implemented) + * `"yaxis"` (not yet implemented) + * `"zaxis"` (not yet implemented) ### Matlab compatibility -- The function `unique` now returns column index vectors for the second - and third outputs. When duplicate values are present, the default - index to return is now the `"first"` occurrence. The previous Octave - behavior, or Matlab behavior from releases prior to R2012b, can be - obtained by using the `"legacy"` flag. - -- The function `setdiff` with the `"rows"` argument now returns Matlab - compatible results. The previous Octave behavior, or Matlab behavior - from releases prior to R2012b, can be obtained by using the `"legacy"` - flag. +- The function `griddata` now implements the "v4" Biharmonic Spline +Interpolation method. In adddition, the function now accepts 3-D inputs +by passing the data to `griddata3`. -- The functions `intersect`, `setxor`, and `union` now accept a - `"legacy"` flag which changes the index values (second and third - outputs) as well as the orientation of all outputs to match Matlab - releases prior to R2012b. +- Coordinate transformation functions `cart2sph`, `sph2cart`, +`cart2pol`, and `pol2cart` now accept either row or column vectors for +coordinate inputs. A single coordinate matrix with one variable per +column can still be used as function input, but a single output variable +will now contain just the first output coordinate, and will no longer +return the full output coordinate matrix. Output size matches the size +of input vectors, or in the case of an input matrix will be column +vectors with rows corresponding to the input coordinate matrix. -- The function `streamtube` is Matlab compatible and plots tubes along - streamlines which are scaled by the vector field divergence. The - Octave-only extension `ostreamtube` can be used to visualize the flow - expansion and contraction of the vector field due to the local - crossflow divergence. - -- The interpreter now supports handles to nested functions. +- The function `dec2bin` and `dec2hex` now support negative numbers. -- The graphics properties `"LineWidth"` and `"MarkerSize"` are now - measured in points, *not* pixels. Compared to previous versions - of Octave, some lines and markers will appear 4/3 larger. - -- The meta.class property "SuperClassList" has been renamed - "Superclasslist" for Matlab compatibility. The original name will - exist as an alias until Octave version 8.1. +- The function `importdata` now produces more compatible results when +the file contains a 2-D text matrix. -- Inline functions created by the function `inline` are now of type - "inline" when interrogated with the `class` function. In previous - versions of Octave, the class returned was "function_handle". This - change is Matlab compatible. Inline functions are deprecated in - both Matlab and Octave and support may eventually be removed. - Anonymous functions can be used to replace all instances of inline - functions. +- `uicontrol` objects now fully implement the "Off" and "Inactive" +values of the "Enable" property. When the value is "Off", no +interaction with the object occurs and the `uicontrol` changes color +(typically to gray) to indicate it is disabled. When the value is +"Inactive", the object appears normally (no change in color), but it is +not possible to change the value of the object (such as modifying text +in an `Edit` box or clicking on a `RadioButton`). -- The function `javaaddpath` now prepends new directories to the - existing dynamic classpath by default. To append them instead, use - the new `"-end"` argument. Multiple directories may now be specified - in a cell array of strings. - -- An undocumented function `gui_mainfcn` has been added, for compatibility - with figures created with Matlab's GUIDE. +- The functions `scatter` and `scatter3` now return a handle to a +scatter graphics object. For compatibility, they return an `hggroup` of +patch graphics objects when the "gnuplot" graphics toolkit is used. In +previous versions of Octave, these functions returned an `hggroup` of +patch graphics objects for all graphics toolkits. -- Several validator functions of type `mustBe*` have been added. See - the list of new functions below. +- The function `saveas` now defaults to saving in Octave figure format +(.ofig) rather than PDF (.pdf). + +- A new warning ID (`"Octave:unimplemented-matlab-functionality"`) has +been added which prints a warning when Octave's parser recognizes valid +Matlab code, but for which Octave does not yet implement the +functionality. By default, this warning is enabled. -### Alphabetical list of new functions added in Octave 6 +- The functions `bar` and `barh` now handle stacked negative bar values +in a Matlab-compatible manner. Negative values now stack below the zero +axis independently of a positive value bars in the same stack. +Previously the negative bars could overlap positive bars depending on +drawing order. + +### Alphabetical list of new functions added in Octave 7 -* `auto_repeat_debug_command` -* `commandhistory` -* `commandwindow` -* `filebrowser` -* `is_same_file` -* `lightangle` -* `mustBeFinite` -* `mustBeGreaterThan` -* `mustBeGreaterThanOrEqual` -* `mustBeInteger` -* `mustBeLessThan` -* `mustBeLessThanOrEqual` -* `mustBeMember` -* `mustBeNegative` -* `mustBeNonempty` -* `mustBeNonNan` -* `mustBeNonnegative` -* `mustBeNonpositive` -* `mustBeNonsparse` -* `mustBeNonzero` -* `mustBeNumeric` -* `mustBeNumericOrLogical` -* `mustBePositive` -* `mustBeReal` -* `namedargs2cell` -* `newline` -* `ode23s` -* `ostreamtube` -* `rescale` -* `rotx` -* `roty` -* `rotz` -* `stream2` -* `stream3` -* `streamline` -* `streamtube` -* `uisetfont` -* `verLessThan` -* `web` -* `weboptions` -* `webread` -* `webwrite` -* `workspace` - +* `getpixelposition` +* `endsWith` +* `jsondecode` +* `jsonencode` +* `listfonts` +* `matlab.net.base64decode` +* `matlab.net.base64encode` +* `memory` +* `ordqz` +* `rng` +* `startsWith` +* `streamribbon` +* `xtickangle` +* `ytickangle` +* `ztickangle` ### Deprecated functions and properties -The following functions and properties have been deprecated in Octave 6 -and will be removed from Octave 8 (or whatever version is the second -major release after 6): +The following functions and properties have been deprecated in Octave 7 +and will be removed from Octave 9 (or whatever version is the second +major release after 7): - Functions Function | Replacement -----------------------|------------------ - `runtests` | `oruntests` + | - Properties @@ -271,51 +197,31 @@ -----------------|---------------|------------ | | -- The environment variable used by `mkoctfile` for linker flags is now - `LDFLAGS` rather than `LFLAGS`. `LFLAGS` is deprecated, and a warning - is emitted if it is used, but it will continue to work. - - ### Removed functions and properties -The following functions and properties were deprecated in Octave 4.4 -and have been removed from Octave 6. +The following functions and properties were deprecated in Octave 5 +and have been removed from Octave 7. - Functions - Function | Replacement - ---------------------|------------------ - `chop` | `sprintf` for visual results - `desktop` | `isguirunning` - `tmpnam` | `tempname` - `toascii` | `double` - `java2mat` | `__java2mat__` + Function | Replacement + -------------------------|------------------ + `output_max_field_width` | `output_precision` + `is_keyword` | `iskeyword` - Properties - Object | Property | Value - ---------------------|---------------------------|----------------------- - `annotation` | `edgecolor ("rectangle")` | - `axes` | `drawmode` | - `figure` | `doublebuffer` | - | `mincolormap` | - | `wvisual` | - | `wvisualmode` | - | `xdisplay` | - | `xvisual` | - | `xvisualmode` | - `line` | `interpreter` | - `patch` | `interpreter` | - `surface` | `interpreter` | - `text` | `fontweight` | `"demi"` and `"light"` - `uibuttongroup` | `fontweight` | `"demi"` and `"light"` - `uicontrol` | `fontweight` | `"demi"` and `"light"` - `uipanel` | `fontweight` | `"demi"` and `"light"` - `uitable` | `fontweight` | `"demi"` and `"light"` - + Object | Property | Value + -----------------|---------------|------------ + `text` | `fontangle` | `"oblique"` + `uibuttongroup` | `fontangle` | `"oblique"` + `uicontrol` | `fontangle` | `"oblique"` + `uipanel` | `fontangle` | `"oblique"` + `uitable` | `fontangle` | `"oblique"` ### Old release news +- [Octave 6.x](etc/NEWS.6) - [Octave 5.x](etc/NEWS.5) - [Octave 4.x](etc/NEWS.4) - [Octave 3.x](etc/NEWS.3) diff -r dc3ee9616267 -r fa2cdef14442 bootstrap.conf --- a/bootstrap.conf Thu Nov 19 13:05:51 2020 -0800 +++ b/bootstrap.conf Thu Nov 19 13:08:00 2020 -0800 @@ -56,6 +56,7 @@ getrusage gettimeofday glob + intprops isatty largefile link @@ -117,9 +118,12 @@ unictype/ctype-upper unictype/ctype-xdigit unistd + unistr/u16-to-u8 + unistr/u32-to-u8 unistr/u8-check unistr/u8-strmblen unistr/u8-strmbtouc + unistr/u8-to-u16 unistr/u8-to-u32 unlink unsetenv diff -r dc3ee9616267 -r fa2cdef14442 build-aux/module.mk --- a/build-aux/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/build-aux/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -35,6 +35,7 @@ ### utility rules to aid development ALL_TEST_FILES = \ + $(addprefix $(srcdir)/, $(LIBOCTAVE_TST_FILES_SRC)) \ $(addprefix $(srcdir)/, $(LIBINTERP_TST_FILES_SRC)) \ $(addprefix $(srcdir)/, $(FCN_FILES_WITH_TESTS)) \ $(addprefix $(srcdir)/, $(TEST_FILES)) diff -r dc3ee9616267 -r fa2cdef14442 configure.ac --- a/configure.ac Thu Nov 19 13:05:51 2020 -0800 +++ b/configure.ac Thu Nov 19 13:08:00 2020 -0800 @@ -27,7 +27,7 @@ ### Initialize Autoconf AC_PREREQ([2.65]) -AC_INIT([GNU Octave], [6.0.93], [https://octave.org/bugs.html], [octave], +AC_INIT([GNU Octave], [7.0.0], [https://octave.org/bugs.html], [octave], [https://www.gnu.org/software/octave/]) ### Declare version numbers @@ -39,16 +39,16 @@ ## explains how to update these numbers for release and development ## versions. -OCTAVE_MAJOR_VERSION=6 +OCTAVE_MAJOR_VERSION=7 OCTAVE_MINOR_VERSION=0 -OCTAVE_PATCH_VERSION=93 +OCTAVE_PATCH_VERSION=0 dnl PACKAGE_VERSION is set by the AC_INIT VERSION argument. OCTAVE_VERSION="$PACKAGE_VERSION" OCTAVE_COPYRIGHT="Copyright (C) 2020 The Octave Project Developers." -OCTAVE_RELEASE_DATE="2020-10-23" +OCTAVE_RELEASE_DATE="2020-08-26" ## The "API version" is used as a way of checking that interfaces in the ## liboctave and libinterp libraries haven't changed in a backwardly @@ -63,7 +63,7 @@ dnl FIXME: Since we also set libtool versions for liboctave and libinterp, dnl perhaps we should be computing the "api version" from those versions numbers dnl in some way instead of setting it independently here. -OCTAVE_API_VERSION="api-v55" +OCTAVE_API_VERSION="api-v55+" AC_SUBST(OCTAVE_MAJOR_VERSION) AC_SUBST(OCTAVE_MINOR_VERSION) @@ -536,20 +536,6 @@ AC_DEFINE_UNQUOTED(OCTAVE_IDX_TYPE, [$OCTAVE_IDX_TYPE], [Define to the type of octave_idx_type (64 or 32 bit signed integer).]) -### Enable bounds checking on element references within Octave's array and -### matrix classes. -dnl This slows down some operations a bit, so it is turned off by default. - -ENABLE_BOUNDS_CHECK=no -AC_ARG_ENABLE([bounds-check], - [AS_HELP_STRING([--enable-bounds-check], - [OBSOLETE: use --enable-address-sanitizer-flags instead])], - [if test "$enableval" = yes; then ENABLE_BOUNDS_CHECK=yes; fi], []) -if test $ENABLE_BOUNDS_CHECK = yes; then - warn_bounds_check="--enable-bounds-check is obsolete; use --enable-address-sanitizer-flags instead" - OCTAVE_CONFIGURE_WARNING([warn_bounds_check]) -fi - ### Check for pthread library AX_PTHREAD @@ -1352,6 +1338,39 @@ ], [libpcre], [REQUIRED]) +### Check for RapidJSON header only library. + +AC_LANG_PUSH(C++) +AC_CHECK_HEADER([rapidjson/rapidjson.h], + [have_rapidjson=yes], [have_rapidjson=no]) + +if test $have_rapidjson = yes; then + AC_DEFINE(HAVE_RAPIDJSON, 1, [Define to 1 if RapidJSON is available.]) + + ## Additional check on RapidJSON library that was found + AC_CACHE_CHECK([for working PrettyWriter in RapidJSON], + [octave_cv_rapidjson_has_prettywriter], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #include + ]], [[ + rapidjson::StringBuffer json; + rapidjson::PrettyWriter, + rapidjson::UTF8<>, rapidjson::CrtAllocator, + rapidjson::kWriteNanAndInfFlag> writer (json); + ]])], + [octave_cv_rapidjson_has_prettywriter=yes], + [octave_cv_rapidjson_has_prettywriter=no]) + ]) + if test $octave_cv_rapidjson_has_prettywriter = yes; then + AC_DEFINE(HAVE_RAPIDJSON_PRETTYWRITER, 1, + [Define to 1 if the RapidJSON PrettyWriter function is available.]) + else + rapid_json_warning='Older RapidJSON library found. The "PrettyWriter" option in jsonencode will be disabled.' + OCTAVE_CONFIGURE_WARNING([rapid_json_warning]) + fi +fi +AC_LANG_POP([C++]) + ### Check for readline library. OCTAVE_ENABLE_READLINE @@ -1378,7 +1397,7 @@ [zlib.h], [gzclearerr]) ## Also define HAVE_ZLIB if libz is found. -if test -z "$warn_z"; then +if test -n "$Z_LIBS"; then AC_DEFINE(HAVE_ZLIB, 1, [Define to 1 if ZLIB is available.]) fi @@ -1617,7 +1636,7 @@ OCTAVE_CHECK_LIB(curl, cURL, [cURL library not found. The ftp objects, urlread, and urlwrite functions will be disabled.], [curl/curl.h], [curl_easy_escape]) -if test -z "$warn_curl"; then +if test -n "$CURL_LIBS"; then ## Additional check on cURL library that was found AC_CACHE_CHECK([for CURLOPT_DIRLISTONLY in curl/curl.h], [octave_cv_curl_has_curlopt_dirlistonly], @@ -1665,8 +1684,6 @@ [select library to use for image I/O (options: GraphicsMagick(default) or ImageMagick)])], [if test x"$withval" = xno; then check_magick=no - warn_magick_disabled="--without-magick specified. The imread, imwrite, and imfinfo functions for reading and writing image files will not be fully functional." - OCTAVE_CONFIGURE_WARNING([warn_magick_disabled]) else magick="$withval" fi], [magick="GraphicsMagick"]) @@ -1778,8 +1795,6 @@ [don't use OpenGL libraries, disable OpenGL graphics])], [if test x"$withval" = xno; then check_opengl=no - warn_opengl_disabled="--without-opengl specified. OpenGL graphics will be disabled." - OCTAVE_CONFIGURE_WARNING([warn_opengl_disabled]) fi]) ## Check for OpenGL library @@ -1800,7 +1815,6 @@ [don't use FreeType library, OpenGL graphics will not be fully functional])], [if test x"$withval" = xno; then check_freetype=no - warn_freetype="--without-freetype specified. OpenGL graphics will not be fully functional." fi]) if test $check_freetype = yes; then @@ -1841,26 +1855,9 @@ [fontconfig.h fontconfig/fontconfig.h], [FcInit], [], [don't use fontconfig library, OpenGL graphics will not be fully functional]) -## Check for gl2ps which is required for printing with OpenGL graphics. - -AC_CHECK_HEADERS([gl2ps.h], - [GL2PS_LIBS="-lgl2ps"], - [warn_gl2ps="gl2ps library not found. Printing of OpenGL graphics will be disabled."]) - -if test -n "$warn_gl2ps"; then - OCTAVE_CONFIGURE_WARNING([warn_gl2ps]) -else - save_LIBS="$LIBS" - LIBS="$GL2PS_LIBS $LIBS" - AC_CHECK_FUNCS([gl2psLineJoin]) - LIBS="$save_LIBS" -fi - -AC_SUBST(GL2PS_LIBS) - ### GUI/Qt related tests. -QT_VERSIONS="5 4" +QT_VERSIONS="5" AC_ARG_WITH([qt], [AS_HELP_STRING([--with-qt=VER], [use the Qt major version VER]) @@ -1871,8 +1868,6 @@ ;; no) QT_VERSIONS= - warn_qt_disabled="--without-qt specified. The Qt GUI will be disabled." - OCTAVE_CONFIGURE_WARNING([warn_qt_disabled]) ;; *) QT_VERSIONS="$withval" @@ -1884,8 +1879,6 @@ [AS_HELP_STRING([--without-qscintilla], [disable QScintilla editor])], [if test x"$withval" = xno; then check_qscintilla=no - warn_qscintilla_disabled="--without-qscintilla specified. The GUI editor will be disabled." - OCTAVE_CONFIGURE_WARNING([warn_qscintilla_disabled]) fi]) OCTAVE_CHECK_QT([$QT_VERSIONS]) @@ -2026,6 +2019,25 @@ opengl_graphics=yes fi +## Check for gl2ps which is required for printing with OpenGL graphics. + +if test $opengl_graphics = yes; then + AC_CHECK_HEADERS([gl2ps.h], + [GL2PS_LIBS="-lgl2ps"], + [warn_gl2ps="gl2ps library not found. Printing of OpenGL graphics will be disabled."]) + + if test -n "$warn_gl2ps"; then + OCTAVE_CONFIGURE_WARNING([warn_gl2ps]) + else + save_LIBS="$LIBS" + LIBS="$GL2PS_LIBS $LIBS" + AC_CHECK_FUNCS([gl2psLineJoin]) + LIBS="$save_LIBS" + fi + + AC_SUBST(GL2PS_LIBS) +fi + ### Check for the qrupdate library dnl No need to adjust FFLAGS because only link is attempted. @@ -2039,7 +2051,7 @@ [Fortran 77], [don't use qrupdate, disable QR & Cholesky updating functions]) ## Additional check to see if qrupdate lib found supports LU updates -if test -z "$warn_qrupdate"; then +if test -n "$QRUPDATE_LIBS"; then AC_CACHE_CHECK([for slup1up in $QRUPDATE_LIBS], [octave_cv_func_slup1up], [LIBS="$LIBS $QRUPDATE_LIBS" @@ -2137,7 +2149,7 @@ [cs${CXSPARSE_TAG}sqr], [C++], [don't use CXSparse library, disable some sparse matrix functionality]) -if test -z "$warn_cxsparse"; then +if test -n "$CXSPARSE_LIBS"; then ## Additional check for CXSparse version >= 2.2 if test $octave_cv_lib_cxsparse = yes; then OCTAVE_CHECK_CXSPARSE_VERSION_OK @@ -2230,50 +2242,56 @@ ### Check for SUNDIALS IDA library and header. -save_CPPFLAGS="$CPPFLAGS" -save_LDFLAGS="$LDFLAGS" -save_LIBS="$LIBS" -LIBS="$SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS" -LDFLAGS="$SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS" -CPPFLAGS="$SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS" -OCTAVE_CHECK_LIB(sundials_ida, [SUNDIALS IDA], - [SUNDIALS IDA library not found. The solvers ode15i and ode15s will be disabled.], - [ida/ida.h ida.h], [IDAInit], - [], [don't use SUNDIALS IDA library, disable solvers ode15i and ode15s]) -CPPFLAGS="$save_CPPFLAGS" -LDFLAGS="$save_LDFLAGS" -LIBS="$save_LIBS" +if test -n "$SUNDIALS_NVECSERIAL_LIBS"; then + + save_CPPFLAGS="$CPPFLAGS" + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + LIBS="$SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS" + LDFLAGS="$SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS" + CPPFLAGS="$SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS" + OCTAVE_CHECK_LIB(sundials_ida, [SUNDIALS IDA], + [SUNDIALS IDA library not found. The solvers ode15i and ode15s will be disabled.], + [ida/ida.h ida.h], [IDAInit], + [], [don't use SUNDIALS IDA library, disable solvers ode15i and ode15s]) + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" +fi ### Check for SUNDIALS library features, some required, some optional. -CPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS" -LDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS" -LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS" -if test -z "$warn_sundials_nvecserial" && test -z "$warn_sundials_ida"; then - dnl Any of the following tests could determine that SUNDIALS is incompatible - dnl and should be disabled. In that event, they all populate the same - dnl variable with appropriate warning messages, and further tests should be - dnl skipped if a warning message has already been generated that SUNDIALS is - dnl disabled. - warn_sundials_disabled= - if test -z "$warn_sundials_disabled"; then - OCTAVE_CHECK_SUNDIALS_COMPATIBLE_API +if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then + + CPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS $BLAS_CPPFLAGS $CPPFLAGS" + LDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS $BLAS_LDFLAGS $LDFLAGS" + LIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS $BLAS_LIBS $FLIBS $LIBS" + if test -z "$warn_sundials_nvecserial" && test -z "$warn_sundials_ida"; then + dnl Any of the following tests could determine that SUNDIALS is incompatible + dnl and should be disabled. In that event, they all populate the same + dnl variable with appropriate warning messages, and further tests should be + dnl skipped if a warning message has already been generated that SUNDIALS is + dnl disabled. + warn_sundials_disabled= + if test -z "$warn_sundials_disabled"; then + OCTAVE_CHECK_SUNDIALS_COMPATIBLE_API + fi + if test -z "$warn_sundials_disabled"; then + OCTAVE_CHECK_SUNDIALS_SIZEOF_REALTYPE + fi + if test -z "$warn_sundials_disabled"; then + OCTAVE_CHECK_SUNDIALS_SUNLINSOL_DENSE + fi + dnl The following tests determine whether certain optional features are + dnl present in the SUNDIALS libraries, but will not disable using SUNDIALS. + if test -z "$warn_sundials_disabled"; then + OCTAVE_CHECK_SUNDIALS_SUNLINSOL_KLU + fi fi - if test -z "$warn_sundials_disabled"; then - OCTAVE_CHECK_SUNDIALS_SIZEOF_REALTYPE - fi - if test -z "$warn_sundials_disabled"; then - OCTAVE_CHECK_SUNDIALS_SUNLINSOL_DENSE - fi - dnl The following tests determine whether certain optional features are - dnl present in the SUNDIALS libraries, but will not disable using SUNDIALS. - if test -z "$warn_sundials_disabled"; then - OCTAVE_CHECK_SUNDIALS_SUNLINSOL_KLU - fi + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" fi -CPPFLAGS="$save_CPPFLAGS" -LDFLAGS="$save_LDFLAGS" -LIBS="$save_LIBS" dnl Define this way instead of with an #if in oct-conf-post.h so that dnl the build features script will get the correct value. @@ -2282,36 +2300,36 @@ dnl How can we do a better job here? Do we need to disable sundials dnl any tests fail, or can we fix __ode15__.cc so that it still partially dnl works when some things are missing (for example, KLU)? -if test -n "$SUNDIALS_IDA_LIBS" \ - && test -n "$SUNDIALS_NVECSERIAL_LIBS" \ - && test "x$octave_cv_sundials_sunlinsol_dense" = xyes \ - && test "x$octave_cv_sundials_realtype_is_double" = xyes \ - && test "x$octave_have_sundials_compatible_api" = xyes; then - AC_DEFINE(HAVE_SUNDIALS, 1, [Define to 1 if SUNDIALS is available.]) - - ## Collections of options needed to build with SUNDIALS and its dependencies. - SUNDIALS_XCPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_SUNLINSOLKLU_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS" - SUNDIALS_XLDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_SUNLINSOLKLU_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS" - SUNDIALS_XLIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_SUNLINSOLKLU_LIBS $SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS" -else - SUNDIALS_IDA_CPPFLAGS= - SUNDIALS_IDA_LDFLAGS= - SUNDIALS_IDA_LIBS= - SUNDIALS_SUNLINSOLKLU_CPPFLAGS= - SUNDIALS_SUNLINSOLKLU_LDFLAGS= - SUNDIALS_SUNLINSOLKLU_LIBS= - SUNDIALS_NVECSERIAL_CPPFLAGS= - SUNDIALS_NVECSERIAL_LDFLAGS= - SUNDIALS_NVECSERIAL_LIBS= - SUNDIALS_XCPPFLAGS= - SUNDIALS_XLDFLAGS= - SUNDIALS_XLIBS= - dnl Emit a fallback warning message in case SUNDIALS has been disabled for - dnl some reason that hasn't already generated one of these known warnings. - if test -z "$warn_sundials_nvecserial" && test -z "$warn_sundials_ida" \ - && test -z "$warn_sundials_disabled"; then - warn_sundials_disabled="SUNDIALS libraries are missing some feature. The solvers ode15i and ode15s will be disabled." - OCTAVE_CONFIGURE_WARNING([warn_sundials_disabled]) +if test -n "$SUNDIALS_IDA_LIBS" && test -n "$SUNDIALS_NVECSERIAL_LIBS"; then + if test "x$octave_cv_sundials_sunlinsol_dense" = xyes \ + && test "x$octave_cv_sundials_realtype_is_double" = xyes \ + && test "x$octave_have_sundials_compatible_api" = xyes; then + AC_DEFINE(HAVE_SUNDIALS, 1, [Define to 1 if SUNDIALS is available.]) + + ## Options needed to build with SUNDIALS and its dependencies. + SUNDIALS_XCPPFLAGS="$SUNDIALS_IDA_CPPFLAGS $SUNDIALS_SUNLINSOLKLU_CPPFLAGS $SUNDIALS_NVECSERIAL_CPPFLAGS $KLU_CPPFLAGS" + SUNDIALS_XLDFLAGS="$SUNDIALS_IDA_LDFLAGS $SUNDIALS_SUNLINSOLKLU_LDFLAGS $SUNDIALS_NVECSERIAL_LDFLAGS $KLU_LDFLAGS" + SUNDIALS_XLIBS="$SUNDIALS_IDA_LIBS $SUNDIALS_SUNLINSOLKLU_LIBS $SUNDIALS_NVECSERIAL_LIBS $KLU_LIBS" + else + SUNDIALS_IDA_CPPFLAGS= + SUNDIALS_IDA_LDFLAGS= + SUNDIALS_IDA_LIBS= + SUNDIALS_SUNLINSOLKLU_CPPFLAGS= + SUNDIALS_SUNLINSOLKLU_LDFLAGS= + SUNDIALS_SUNLINSOLKLU_LIBS= + SUNDIALS_NVECSERIAL_CPPFLAGS= + SUNDIALS_NVECSERIAL_LDFLAGS= + SUNDIALS_NVECSERIAL_LIBS= + SUNDIALS_XCPPFLAGS= + SUNDIALS_XLDFLAGS= + SUNDIALS_XLIBS= + dnl Emit a fallback warning message in case SUNDIALS has been disabled for + dnl some reason that hasn't already generated one of these known warnings. + if test -z "$warn_sundials_nvecserial" && test -z "$warn_sundials_ida" \ + && test -z "$warn_sundials_disabled"; then + warn_sundials_disabled="SUNDIALS libraries are missing some feature. The solvers ode15i and ode15s will be disabled." + OCTAVE_CONFIGURE_WARNING([warn_sundials_disabled]) + fi fi fi @@ -2332,7 +2350,7 @@ OCTAVE_CHECK_LIB_ARPACK_OK_1( [AC_DEFINE(HAVE_ARPACK, 1, [Define to 1 if ARPACK is available.])], [warn_arpack="ARPACK library found, but does not seem to work properly; disabling eigs function"]) - if test -z "$warn_arpack"; then + if test -n "$ARPACK_LIBS"; then OCTAVE_CHECK_LIB_ARPACK_OK_2([], [AC_MSG_WARN([ARPACK library found, but is buggy; upgrade library (>= v3.3.0) for better results])]) fi @@ -2609,6 +2627,7 @@ warn_docs="building documentation disabled; make dist will fail." OCTAVE_CONFIGURE_WARNING([warn_docs]) fi], []) + if test $ENABLE_DOCS = yes; then if test $opengl_graphics = no || test "$have_qt_opengl_offscreen" = no; then if test -n "$warn_gnuplot"; then @@ -2627,6 +2646,7 @@ AC_DEFINE(ENABLE_DOCS, 1, [Define to 1 to build Octave documentation files.]) fi + AM_CONDITIONAL([AMCOND_BUILD_DOCS], [test $ENABLE_DOCS = yes]) AM_CONDITIONAL([AMCOND_BUILD_QT_DOCS], @@ -3010,7 +3030,7 @@ libgui/mk-default-qt-settings.sh liboctave/external/mk-f77-def.sh liboctave/mk-version-h.sh - libinterp/corefcn/mk-mxarray-h.sh + libinterp/corefcn/mk-mxtypes-h.sh build-aux/subst-config-vals.sh build-aux/subst-cross-config-vals.sh build-aux/subst-script-vals.sh]) diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/container.txi --- a/doc/interpreter/container.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/container.txi Thu Nov 19 13:08:00 2020 -0800 @@ -914,11 +914,11 @@ The following string functions support cell arrays of strings: @code{char}, @code{strvcat}, @code{strcat} (@pxref{Concatenating Strings}), @code{strcmp}, @code{strncmp}, @code{strcmpi}, -@code{strncmpi} (@pxref{Comparing Strings}), @code{str2double}, +@code{strncmpi} (@pxref{Searching in Strings}), @code{str2double}, @code{deblank}, @code{strtrim}, @code{strtrunc}, @code{strfind}, @code{strmatch}, , @code{regexp}, @code{regexpi} -(@pxref{Manipulating Strings}) and @code{str2double} -(@pxref{String Conversions}). +(@pxref{String Operations}) and @code{str2double} +(@pxref{Converting Strings}). The function @code{iscellstr} can be used to test if an object is a cell array of strings. diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/contributors.in --- a/doc/interpreter/contributors.in Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/contributors.in Thu Nov 19 13:08:00 2020 -0800 @@ -89,6 +89,7 @@ Paul Eggert Stephen Eglen Peter Ekberg +Abdallah K. Elshamy Garrett Euler Edmund Grimley Evans Rolf Fabian @@ -191,6 +192,7 @@ Alexander Klein Lasse Kliemann Geoffrey Knauth +Martin Köhler Heine Kolltveit Ken Kouno Kacper Kowalik @@ -247,6 +249,7 @@ Laurent Mazet G. D. McBain Ronald van der Meer +Markus Meisinger Júlio Hoffimann Mendes Ed Meyer Thorsten Meyer diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/doccheck/README --- a/doc/interpreter/doccheck/README Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/doccheck/README Thu Nov 19 13:08:00 2020 -0800 @@ -78,7 +78,7 @@ which can be added to the private dictionary. Instead the source is marked up: Manchester @nospell{Centre} for Computational Mathematics. -aspell will no longer reports any misspellings for linalg.texi. +aspell will no longer report any misspellings for linalg.texi. GRAMMAR: diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/doccheck/aspell-octave.en.pws --- a/doc/interpreter/doccheck/aspell-octave.en.pws Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/doccheck/aspell-octave.en.pws Thu Nov 19 13:08:00 2020 -0800 @@ -1,13 +1,14 @@ personal_ws-1.1 en 1 AbsTol accumarray +Acknowledgements acknowledgements -Acknowledgements adams Affero afterwards al aleph +allocatable amd amongst anisotropic @@ -21,8 +22,6 @@ arpack ArrayValued ascii -Associativity -associativity ast async atan @@ -30,12 +29,11 @@ audiodevinfo audioplayer audiorecorder -AutoCAD Autoconf autocorrelated autocovariances +autoload Autoload -autoload autoloaded Autoloading Automake @@ -52,29 +50,28 @@ Barycentric basevalue BaseValue +BDF bdf -BDF benchmarking betacdf betainc betainv betaln betapdf -betarnd BFGS BICG BiConjugate +biharmonic bincoeff binocdf binoinv binopdf -binornd Biomathematics -bitmapped bitwise blas bmp boolean +Booleans boolMatrix boxoff boxon @@ -102,8 +99,8 @@ cd cdata cdatamapping +CDF cdf -CDF cdot ceil cellstr @@ -146,11 +143,11 @@ colorcube colormap colormaps +colororder ColorOrder -colororder colperm +CommentStyle commentstyle -CommentStyle ComplexEqn cond condest @@ -159,10 +156,10 @@ const contextless contourc +ConvertInfAndNaN convhull Convolve copyrightable -CorelDraw corrcoef cosecant courseware @@ -201,8 +198,8 @@ daspk dasrt dassl +DataAspectRatio dataset -datasets datasource datenum datenums @@ -221,17 +218,16 @@ delaunay Delaunay delaunayn +deletefcn DeleteFcn -deletefcn delim deltaX -demi det dggsvd diag diagcomp +dialogs Dialogs -dialogs diamondsuit differentiable digamma @@ -254,7 +250,6 @@ doublearrow downarrow downdate -dpi droptol dt dx @@ -273,31 +268,31 @@ elementwise elseif emacs +EmptyValue emptyvalue -EmptyValue encodings endfunction +Endian endian -Endian endif +EndOfLine endofline -EndOfLine EOF EOLs eps eq equidistributed +Equilibration equilibration -Equilibration equispaced erf erfc erfi errno +Errorbar errorbar -Errorbar +Errorbars errorbars -Errorbars errordlg ErrorHandler ESC @@ -312,11 +307,10 @@ expcdf expinv exppdf -exprnd extendedtext extrema +FaceColor facecolor -FaceColor FaceLighting FaceNormals FaceVertexCData @@ -334,8 +328,8 @@ fieldname fieldnames FIFOs +filename FileName -filename filenames filepaths Filesystem @@ -346,11 +340,13 @@ fitboxtotext FIXME flac +fltk FLTK -fltk fminsearch fminunc +FontConfig fontconfig +FontName fontname forall forcecelloutput @@ -362,9 +358,8 @@ FreeBSD FreeSans freespacing +freetype FreeType -freetype -frnd Fs FSF fullpath @@ -374,7 +369,6 @@ gamcdf gaminv gampdf -gamrnd gaussian gca gcbo @@ -382,11 +376,9 @@ gcd ge GECOS -genvarname geocdf geoinv geopdf -geornd geotagging geq gesdd @@ -394,17 +386,17 @@ gfortran Ghostscript Ghostscript's +GIF gif -GIF glibc globbing glpk +GLS gls -GLS glyphs GMRES +gnuplot Gnuplot -gnuplot GNUTERM Goto goto @@ -428,13 +420,13 @@ HandleVisibility handlevisibility Hankel +Hanning hanning -Hanning hardcode hardcoded hardcoding +hdf HDF -hdf HeaderLines headerlines headlength @@ -451,20 +443,19 @@ hggroups hgid hgload +hh HH -hh histc holomorphic horizontalalignment horzcat hostname +HSV hsv -HSV html hygecdf hygeinv hygepdf -hygernd hypervolume ichol ict @@ -476,6 +467,7 @@ ifft ifftn ignorecase +IgnoreCase ij ilu ilutp @@ -492,7 +484,6 @@ InitialStep InitialValue inline -Inline inmax inmin inpolygon @@ -545,12 +536,13 @@ JConstant JDK JIS +jit JIT -jit JPattern jpeg JPEG jpg +JSON jvm JVM's kendall @@ -606,9 +598,8 @@ logncdf logninv lognpdf -lognrnd +lookup Lookup -lookup lookups lossless lsode @@ -649,11 +640,10 @@ meshgridded meshstyle metadata +metafile Metafile MetaFile -metafile metafiles -Metafont mex mget michol @@ -669,8 +659,8 @@ mkoctfile mldivide mmd +mmm MMM -mmm mmmm mmmyy mmmyyyy @@ -683,12 +673,12 @@ MStateDependence MSYS mtimes +Multi multi -Multi multibyte multipage +multipledelimsasone MultipleDelimsAsOne -multipledelimsasone MultiSelect multistep MvPattern @@ -696,8 +686,8 @@ myclass myfun nabla +namespace NAMESPACE -namespace nan NaN nancond @@ -705,10 +695,10 @@ NaNs nargin nargout +natively nbincdf nbininv nbinpdf -nbinrnd ncols nd ndgrid @@ -717,7 +707,6 @@ neq NeXT NextPlot -nfev nfft ni NLP @@ -730,7 +719,6 @@ nonconformant nondecreasing nonincreasing -nonmodal nonnan NonNegative nonnegativity @@ -747,7 +735,6 @@ normest norminv normpdf -normrnd northeastoutside northoutside NorthOutside @@ -775,8 +762,8 @@ onCleanup online OpenBLAS +OpenGL opengl -OpenGL OpenJDK oplus optimizations @@ -796,8 +783,8 @@ overdetermined overridable paperorientation +paperposition PaperPosition -paperposition paperpositionmode papersize paperunits @@ -805,7 +792,6 @@ parametrically parseparams pbm -PBM PBMplus pc PCG @@ -815,8 +801,8 @@ pcre PCRE PCX +PDF pdf -PDF pdflatex pentadiagonal periodogram @@ -825,16 +811,16 @@ PGMRES PHP pict +piecewise Piecewise -piecewise pinv PixelRegion +PlotBoxAspectRatio +png PNG -png poisscdf poissinv poisspdf -poissrnd polyderiv polyeig polyfit @@ -859,10 +845,11 @@ prepended preselected presolver +PrettyWriter printf priori +Profiler profiler -Profiler programmatically prolate PromptString @@ -877,12 +864,12 @@ pushbutton pushbuttons Pxx +Qhull qhull -Qhull QP QQ +qrupdate QRUPDATE -qrupdate QScintilla quadcc quadgk @@ -897,8 +884,8 @@ quartile questdlg Quickhull +qz QZ -qz radian radians radices @@ -927,7 +914,6 @@ relicensing RelTol renderer -renderers repelems replacechildren ReplacementStyle @@ -936,8 +922,8 @@ reproducibility resampled resampling +Resize resize -Resize resized resizing Resizing @@ -1029,8 +1015,8 @@ ss sT stairstep +Startup startup -Startup statinfo stdin stdout @@ -1038,9 +1024,12 @@ STFT str strcmp +streamribbon +Streamribbons +streamribbons streamtube +Streamtubes streamtubes -Streamtubes stringanchors strncmp strncmpi @@ -1101,12 +1090,12 @@ svd SVD svds +svg SVG -svg +Sym sym -Sym +symamd SYMAMD -symamd symbfact symrcm Syntaxes @@ -1114,8 +1103,8 @@ terminal's tex texi +Texinfo texinfo -Texinfo TextAlphaBits textarrow textbackgroundcolor @@ -1140,7 +1129,6 @@ togglebutton togglebuttons tokenExtents -TolF TolFun TolX toolchain @@ -1162,9 +1150,8 @@ triplot trisurf trivariate -trnd +TrueColor truecolor -TrueColor tuples txi typedefs @@ -1174,37 +1161,36 @@ uchar UHESS UI +uibuttongroup Uibuttongroup -uibuttongroup -uibuttongroups Uicontextmenu uicontextmenu +uicontrol Uicontrol -uicontrol uicontrols UID uimenu uint +Uipanel uipanel -Uipanel uipanels +Uipushtool uipushtool -Uipushtool uipushtools uiputfile uitab +Uitable uitable -Uitable Uitoggletool uitoggletool +Uitoolbar uitoolbar -Uitoolbar ulong Ultrix umfpack uminus +Unary unary -Unary unconvertible undirected unifcdf @@ -1212,7 +1198,6 @@ UniformOutput UniformValues unifpdf -unifrnd unimodal Uninstall uninstalled @@ -1249,8 +1234,8 @@ vech vectorization vectorize +Vectorized vectorized -Vectorized vectorizing vee versa @@ -1266,31 +1251,28 @@ Voronoi waitbar waitbars -warndlg wav WAV -WayPoints Waypoints waypoints +WayPoints wblcdf wblinv wblpdf -wblrnd westoutside WestOutside +whitespace Whitespace -whitespace whos -wienrnd Wikipedia wildcard +wildcards Wildcards -wildcards windowbuttondownfcn windowbuttonmotionfcn windowbuttonupfcn +WindowStyle windowstyle -WindowStyle WIPO wireframe wlen @@ -1346,8 +1328,8 @@ ypos yticklabels yticks +YY yy -YY YYYY yyyy yyyymmddTHHMMSS diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/doccheck/mk_undocumented_list --- a/doc/interpreter/doccheck/mk_undocumented_list Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/doccheck/mk_undocumented_list Thu Nov 19 13:08:00 2020 -0800 @@ -64,10 +64,12 @@ } # Second, remove functions based on directory location -# deprecated directory, doc/interpreter directory, test/ directory +# deprecated directory, legacy directory, doc/interpreter directory, +# test/ directory FUNC: foreach $idx (0 .. $#where) { next FUNC if ($where[$idx] =~ /deprecated/i); + next FUNC if ($where[$idx] =~ /legacy/i); next FUNC if ($where[$idx] =~ /interpreter/i); next FUNC if ($where[$idx] =~ m#test/#i); @@ -81,7 +83,8 @@ # Fourth, remove exceptions based on name that do not require documentation # Load list of function exceptions not requiring a DOCSTRING # Exception data is stored at the bottom of this script -map { chomp, $exceptions{$_}=1; } ; +foreach $_ () +{ chomp, $exceptions{$_}=1; } # Remove exception data from the list @functions = grep (! $exceptions{$_}, @functions); @@ -135,6 +138,7 @@ flipdim fmod gammaln +gui_mainfcn home i ifelse diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/func.txi --- a/doc/interpreter/func.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/func.txi Thu Nov 19 13:08:00 2020 -0800 @@ -924,6 +924,8 @@ @DOCSTRING(dir_in_loadpath) +@DOCSTRING(dir_encoding) + @node Subfunctions @subsection Subfunctions @@ -1804,6 +1806,8 @@ @DOCSTRING(str2func) +@DOCSTRING(symvar) + @node Anonymous Functions @subsection Anonymous Functions diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/genpropdoc.m --- a/doc/interpreter/genpropdoc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/genpropdoc.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,9 +39,10 @@ function genpropdoc (objname, fname = "", props = {}) objnames = {"root", "figure", "axes", "legend", ... - "image", "light", "line", "patch", "surface", "text", ... - "uibuttongroup", "uicontextmenu", "uicontrol", "uipanel", ... - "uimenu", "uipushtool", "uitable", "uitoggletool", "uitoolbar" + "image", "light", "line", "patch", "scatter", "surface", ... + "text", "uibuttongroup", "uicontextmenu", "uicontrol", ... + "uipanel", "uimenu", "uipushtool", "uitable", ... + "uitoggletool", "uitoolbar" }; ## Base properties @@ -169,6 +170,11 @@ s.doc = "If __prop__ is @qcode{\"on\"}, the __objname__ is \ clipped in its parent axes limits."; + case "contextmenu" + s.doc = "Graphics handle of the uicontextmenu object that is \ +currently associated to this __objname__ object."; + s.valid = valid_handle; + case "createfcn" s.doc = "Callback function executed immediately after __objname__ \ has been created. Function is set by using default property on root object, \ @@ -228,11 +234,6 @@ s.valid = valid_string; s.printdefault = false; - case "uicontextmenu" - s.doc = "Graphics handle of the uicontextmenu object that is \ -currently associated to this __objname__ object."; - s.valid = valid_handle; - case "userdata" s.doc = "User-defined data to associate with the graphics object."; s.valid = "Any Octave data"; @@ -656,12 +657,6 @@ s.doc = doc_unused; ## Specific properties - case "activepositionproperty" - s.doc = "Specify which of @qcode{\"position\"} or \ -@qcode{\"outerposition\"} properties takes precedence when axes \ -annotations extent changes. @xref{XREFaxesposition, , @w{position property}}, \ -and @ref{XREFaxesposition, , @w{outerposition property}}."; - case "alim" s.doc = sprintf (doc_notimpl, "Transparency"); @@ -769,6 +764,11 @@ case "gridlinestyle" + case "innerposition" + s.doc = "The @qcode{\"innerposition\"} property is the same as the \ +@ref{XREFaxesposition, , @w{@qcode{\"position\"} property}}."; + s.valid = valid_4elvec; + case "labelfontsizemultiplier" s.doc = "Ratio between the x/y/zlabel fontsize and the tick \ label fontsize"; @@ -844,6 +844,13 @@ endif s.valid = valid_4elvec; + case "positionconstraint" + s.doc = "Specify which of @qcode{\"innerposition\"} or \ +@qcode{\"outerposition\"} properties takes precedence when axes \ +annotations extent changes. \ +@xref{XREFaxesinnerposition, , @w{@qcode{\"innerposition\"} property}}, \ +and @ref{XREFaxesouterposition, , @w{@qcode{\"outerposition\"} property}}."; + case "projection" s.doc = doc_unused; @@ -1621,6 +1628,117 @@ endswitch + ## Scatter properties + elseif (strcmp (objname, "scatter")) + switch (field) + ## Overridden shared properties + case "children" + s.doc = doc_unused; + + ## Specific properties + case "cdatamode" + s.doc = "If @code{cdatamode} is @qcode{\"auto\"}, @code{cdata} is set \ +to the color from the @code{colororder} of the ancestor axes corresponding to \ +the @code{seriesindex}."; + + case "cdatasource" + s.doc = sprintf (doc_notimpl, "Data from workspace variables"); + + case "cdata" + s.doc = "Data defining the scatter object color.\n\ +\n\ +If @code{cdata} is a scalar index into the current colormap or a RGB triplet, \ +it defines the color of all scatter markers.\n\ +\n\ +If @code{cdata} is an N-by-1 vector of indices or an N-by-3 (RGB) matrix, \ +it defines the color of each one of the N scatter markers."; + s.valid = valid_scalmat; + + + case "displayname" + s.doc = "Text of the legend entry corresponding to this scatter object."; + + case "linewidth" + s.doc = "Line width of the edge of the markers."; + + case "marker" + s.doc = "@xref{XREFlinemarker, , @w{line marker property}}."; + + case "markeredgealpha" + s.doc = "Transparency level of the faces of the markers where a \ +value of 0 means complete transparency and a value of 1 means solid faces \ +without transparency. Note that the markers are not sorted from back to \ +front which might lead to unexpected results when rendering layered \ +transparent markers or in combination with other transparent objects."; + s.valid = "scalar"; + + case "markeredgecolor" + s.doc = "Color of the edge of the markers. @qcode{\"none\"} means \ +that the edges are transparent and @qcode{\"flat\"} means that the value \ +from @code{cdata} is used. @xref{XREFlinemarkeredgecolor, , \ +@w{line markeredgecolor property}}."; + s.valid = packopt ({markdef("@qcode{\"none\"}"), ... + "@qcode{\"flat\"}", ... + valid_color}); + + case "markerfacealpha" + s.doc = "Transparency level of the faces of the markers where a \ +value of 0 means complete transparency and a value of 1 means solid faces \ +without transparency. Note that the markers are not sorted from back to \ +front which might lead to unexpected results when rendering layered \ +transparent markers or in combination with other transparent objects."; + s.valid = "scalar"; + + case "markerfacecolor" + s.doc = "Color of the face of the markers. @qcode{\"none\"} means \ +that the faces are transparent, @qcode{\"flat\"} means that the value from \ +@code{cdata} is used, and @qcode{\"auto\"} uses the @code{color} property of \ +the ancestor axes. @xref{XREFlinemarkerfacecolor, , \ +@w{line markerfacecolor property}}."; + s.valid = packopt ({markdef("@qcode{\"none\"}"), ... + "@qcode{\"flat\"}", ... + "@qcode{\"auto\"}", ... + valid_color}); + + case "seriesindex" + s.doc = "Each scatter object in the same axes is asigned an \ +incrementing integer. This corresponds to the index into the \ +@code{colororder} of the ancestor axes that is used if @code{cdatamode} is \ +set to @qcode{\"auto\"}."; + + case "sizedatasource" + s.doc = sprintf (doc_notimpl, "Data from workspace variables"); + + case "sizedata" + s.doc = "Size of the area of the marker. A scalar value applies to \ +all markers. If @code{cdata} is an N-by-1 vector, it defines the color of \ +each one of the N scatter markers."; + s.valid = packopt ({"[]", "scalar", "vector"}); + + case "xdatasource" + s.doc = sprintf (doc_notimpl, "Data from workspace variables"); + + case "xdata" + s.doc = "Vector with the x coordinates of the scatter object."; + s.valid = "vector"; + + case "ydatasource" + s.doc = sprintf (doc_notimpl, "Data from workspace variables"); + + case "ydata" + s.doc = "Vector with the y coordinates of the scatter object."; + s.valid = "vector"; + + case "zdatasource" + s.doc = sprintf (doc_notimpl, "Data from workspace variables"); + + case "zdata" + s.doc = "For 3D data, vector with the y coordinates of the scatter \ +object."; + s.valid = packopt ({"[]", "vector"}); + + endswitch + ## Light properties elseif (strcmp (objname, "light")) switch (field) @@ -1962,6 +2080,10 @@ "location", "numcolumns", "orientation", "position", ... "string", "textcolor", "title", "units"}; endif + elseif (strcmp (objname, "scatter")) + ## Make sure to get a scatter object independent of graphics toolkit + hax = axes (hf); + h = __go_scatter__ (hax); else eval (["h = " objname " ();"]); endif diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/graphics_properties.mk --- a/doc/interpreter/graphics_properties.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/graphics_properties.mk Thu Nov 19 13:08:00 2020 -0800 @@ -5,6 +5,7 @@ interpreter/plot-lineproperties.texi \ interpreter/plot-patchproperties.texi \ interpreter/plot-rootproperties.texi \ + interpreter/plot-scatterproperties.texi \ interpreter/plot-surfaceproperties.texi \ interpreter/plot-textproperties.texi @@ -35,5 +36,8 @@ interpreter/plot-surfaceproperties.texi: interpreter/genpropdoc.m $(AM_V_GEN)$(call gen-propdoc-texi,surface) +interpreter/plot-scatterproperties.texi: interpreter/genpropdoc.m + $(AM_V_GEN)$(call gen-propdoc-texi,scatter) + interpreter/plot-textproperties.texi: interpreter/genpropdoc.m $(AM_V_GEN)$(call gen-propdoc-texi,text) diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/gui.txi --- a/doc/interpreter/gui.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/gui.txi Thu Nov 19 13:08:00 2020 -0800 @@ -141,6 +141,10 @@ @DOCSTRING(isguirunning) +@DOCSTRING(getpixelposition) + +@DOCSTRING(listfonts) + @DOCSTRING(movegui) @DOCSTRING(openvar) diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/linalg.txi --- a/doc/interpreter/linalg.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/linalg.txi Thu Nov 19 13:08:00 2020 -0800 @@ -183,6 +183,8 @@ @DOCSTRING(ordschur) +@DOCSTRING(ordqz) + @DOCSTRING(ordeig) @DOCSTRING(subspace) diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/matrix.txi --- a/doc/interpreter/matrix.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/matrix.txi Thu Nov 19 13:08:00 2020 -0800 @@ -175,6 +175,8 @@ @DOCSTRING(randg) +@DOCSTRING(rng) + The generators operate in the new or old style together, it is not possible to mix the two. Initializing any generator with @qcode{"state"} or @qcode{"seed"} causes the others to switch to the diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/module.mk --- a/doc/interpreter/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -9,6 +9,7 @@ %reldir%/plot-lineproperties.texi \ %reldir%/plot-patchproperties.texi \ %reldir%/plot-rootproperties.texi \ + %reldir%/plot-scatterproperties.texi \ %reldir%/plot-surfaceproperties.texi \ %reldir%/plot-textproperties.texi \ %reldir%/plot-uimenuproperties.texi \ @@ -55,6 +56,9 @@ %reldir%/plot-rootproperties.texi: %reldir%/genpropdoc.m $(GRAPHICS_PROPS_SRC) $(AM_V_GEN)$(call gen-propdoc-texi,root) +%reldir%/plot-scatterproperties.texi: %reldir%/genpropdoc.m $(GRAPHICS_PROPS_SRC) + $(AM_V_GEN)$(call gen-propdoc-texi,scatter) + %reldir%/plot-surfaceproperties.texi: %reldir%/genpropdoc.m $(GRAPHICS_PROPS_SRC) $(AM_V_GEN)$(call gen-propdoc-texi,surface) diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/octave.texi --- a/doc/interpreter/octave.texi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/octave.texi Thu Nov 19 13:08:00 2020 -0800 @@ -302,16 +302,23 @@ * Escape Sequences in String Constants:: * Character Arrays:: -* Creating Strings:: -* Comparing Strings:: -* Manipulating Strings:: -* String Conversions:: +* String Operations:: +* Converting Strings:: * Character Class Functions:: -Creating Strings +String Operations +* Common String Operations:: * Concatenating Strings:: -* Converting Numerical Data to Strings:: +* Splitting and Joining Strings:: +* Searching in Strings:: +* Searching and Replacing in Strings:: + +Converting Strings + +* String encoding:: +* Numerical Data and Strings:: +* JSON data encoding/decoding:: Data Containers @@ -576,6 +583,7 @@ * Text Properties:: * Image Properties:: * Patch Properties:: +* Scatter Properties:: * Surface Properties:: * Light Properties:: * Uimenu Properties:: @@ -608,7 +616,6 @@ * Error Bar Series:: * Line Series:: * Quiver Group:: -* Scatter Group:: * Stair Group:: * Stem Series:: * Surface Group:: diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/plot.txi --- a/doc/interpreter/plot.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/plot.txi Thu Nov 19 13:08:00 2020 -0800 @@ -259,6 +259,8 @@ @DOCSTRING(quiver3) +@DOCSTRING(streamribbon) + @DOCSTRING(streamtube) @DOCSTRING(ostreamtube) @@ -340,6 +342,16 @@ @findex zticklabels @DOCSTRING(xticklabels) +The @code{xtickangle}, @code{ytickangle}, and @code{ztickangle} functions +may be used to get or set the rotation angle of labels for the respective axis. +Each has the same form. + +@anchor{XREFytickangle} +@anchor{XREFztickangle} +@findex ytickangle +@findex ztickangle +@DOCSTRING(xtickangle) + @node Two-dimensional Function Plotting @subsubsection Two-dimensional Function Plotting @cindex plotting, two-dimensional functions @@ -1182,24 +1194,30 @@ The graphics functions use pointers, which are of class graphics_handle, in order to address the data structures which control visual display. A graphics handle may point to any one of a number of different base object -types and these objects are the graphics data structures themselves. The +types. These objects are the graphics data structures themselves. The primitive graphic object types are: @code{figure}, @code{axes}, @code{line}, -@code{text}, @code{patch}, @code{surface}, @code{text}, @code{image}, and -@code{light}. - -Each of these objects has a function by the same name, and, each of these +@code{text}, @code{patch}, @code{scatter}, @code{surface}, @code{text}, +@code{image}, and @code{light}. + +Each of these objects has a function by the same name, and each of these functions returns a graphics handle pointing to an object of the corresponding -type. In addition there are several functions which operate on properties of -the graphics objects and which also return handles: the functions @code{plot} -and @code{plot3} return a handle pointing to an object of type line, the -function @code{subplot} returns a handle pointing to an object of type axes, -the function @code{fill} returns a handle pointing to an object of type patch, -the functions @code{area}, @code{bar}, @code{barh}, @code{contour}, -@code{contourf}, @code{contour3}, @code{surf}, @code{mesh}, @code{surfc}, -@code{meshc}, @code{errorbar}, @code{quiver}, @code{quiver3}, @code{scatter}, -@code{scatter3}, @code{stair}, @code{stem}, @code{stem3} each return a handle -to a complex data structure as documented in -@ref{XREFdatasources,,Data Sources}. +type. + +In addition, there are several functions which operate on properties of the +graphics objects and which also return handles. This includes but is not +limited to the following functions: The functions @code{plot} and @code{plot3} +return a handle pointing to an object of type @code{line}. The function +@code{subplot} returns a handle pointing to an object of type @code{axes}. +The functions @code{fill}, @code{trimesh}, and @code{trisurf} return a handle +pointing to an object of type patch. The function @code{scatter3} returns a +handle to an object of type scatter. The functions @code{slice}, @code{surf}, +@code{surfl}, @code{mesh}, @code{meshz}, @code{pcolor}, and @code{waterfall} +each return a handle of type surface. The function @code{camlight} returns a +handle to an object of type light. The functions @code{area}, @code{bar}, +@code{barh}, @code{contour}, @code{contourf}, @code{contour3}, @code{surfc}, +@code{meshc}, @code{errorbar}, @code{quiver}, @code{quiver3}, @code{stair}, +@code{stem}, @code{stem3} each return a handle to a complex data structure as +documented in @ref{XREFdatasources,,Data Sources}. The graphics objects are arranged in a hierarchy: @@ -1211,8 +1229,12 @@ 3. Below the @code{figure} objects are @code{axes} or @code{hggroup} objects. -4. Below the @code{axes} objects are @code{line}, @code{text}, @code{patch}, -@code{surface}, @code{image}, and @code{light} objects. +4. Below the @code{axes} or @code{hggroup} objects are @code{line}, +@code{text}, @code{patch}, @code{scatter}, @code{surface}, @code{image}, and +@code{light} objects. + +It is possible to walk this hierarchical tree by querying the @qcode{"parent"} +and @qcode{"children"} properties of the graphics objects. Graphics handles may be distinguished from function handles (@pxref{Function Handles}) by means of the function @code{ishghandle}. @@ -1502,6 +1524,7 @@ * Text Properties:: * Image Properties:: * Patch Properties:: +* Scatter Properties:: * Surface Properties:: * Light Properties:: * Uimenu Properties:: @@ -1583,6 +1606,13 @@ @include plot-patchproperties.texi +@node Scatter Properties +@subsubsection Scatter Properties +@prindex @sortas{@ Scatter Properties} Scatter Properties + +@include plot-scatterproperties.texi + + @node Surface Properties @subsubsection Surface Properties @prindex @sortas{@ Surface Properties} Surface Properties @@ -2149,7 +2179,6 @@ * Error Bar Series:: * Line Series:: * Quiver Group:: -* Scatter Group:: * Stair Group:: * Stem Series:: * Surface Group:: @@ -2475,46 +2504,6 @@ Data source variables. @end table -@node Scatter Group -@subsubsection Scatter Group -@cindex group objects -@cindex scatter group - -Scatter series objects are created by the @code{scatter} or @code{scatter3} -functions. A single hggroup element contains as many children as there are -points in the scatter plot, with each child representing one of the points. -The properties of the stem series are - -@table @code -@item linewidth -The line width of the line objects of the points. @xref{Line Styles}. - -@item marker -@itemx markeredgecolor -@itemx markerfacecolor -The line and fill color of the markers of the points. @xref{Colors}. - -@item xdata -@itemx ydata -@itemx zdata -The original x, y and z data of the stems. - -@item cdata -The color data for the points of the plot. Each point can have a separate -color, or a unique color can be specified. - -@item sizedata -The size data for the points of the plot. Each point can its own size or a -unique size can be specified. - -@item xdatasource -@itemx ydatasource -@itemx zdatasource -@itemx cdatasource -@itemx sizedatasource -Data source variables. -@end table - @node Stair Group @subsubsection Stair Group @cindex group objects diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/stats.txi diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/strings.txi --- a/doc/interpreter/strings.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/strings.txi Thu Nov 19 13:08:00 2020 -0800 @@ -56,13 +56,17 @@ While strings can in principle store arbitrary content, most functions expect them to be UTF-8 encoded Unicode strings. +Furthermore, it is possible to create a string without actually writing a text. +The function @code{blanks} creates a string of a given length consisting only +of blank characters (ASCII code 32). + +@DOCSTRING(blanks) + @menu * Escape Sequences in String Constants:: * Character Arrays:: -* Creating Strings:: -* Comparing Strings:: -* Manipulating Strings:: -* String Conversions:: +* String Operations:: +* Converting Strings:: * Character Class Functions:: @end menu @@ -207,26 +211,65 @@ @DOCSTRING(string_fill_char) +Another useful function to control the text justification in this case is +the @code{strjust} function. + +@DOCSTRING(strjust) + This shows a problem with character matrices. It simply isn't possible to represent strings of different lengths. The solution is to use a cell array of strings, which is described in @ref{Cell Arrays of Strings}. -@node Creating Strings -@section Creating Strings +@node String Operations +@section String Operations + +Octave supports a wide range of functions for manipulating strings. +Since a string is just a matrix, simple manipulations can be accomplished +using standard operators. The following example shows how to replace +all blank characters with underscores. -The easiest way to create a string is, as illustrated in the introduction, -to enclose a text in double-quotes or single-quotes. It is however -possible to create a string without actually writing a text. The -function @code{blanks} creates a string of a given length consisting -only of blank characters (ASCII code 32). +@example +@group +quote = ... + "First things first, but not necessarily in that order"; +quote( quote == " " ) = "_" +@result{} quote = + First_things_first,_but_not_necessarily_in_that_order +@end group +@end example -@DOCSTRING(blanks) +For more complex manipulations, such as searching, replacing, and +general regular expressions, the following functions come with Octave. @menu +* Common String Operations:: * Concatenating Strings:: -* Converting Numerical Data to Strings:: +* Splitting and Joining Strings:: +* Searching in Strings:: +* Searching and Replacing in Strings:: @end menu +@node Common String Operations +@subsection Common String Operations + +The following functions are useful to perform common String operations. + +@DOCSTRING(tolower) + +@DOCSTRING(toupper) + +@DOCSTRING(deblank) + +@DOCSTRING(strtrim) + +@DOCSTRING(strtrunc) + +@DOCSTRING(untabify) + +@DOCSTRING(do_string_escapes) + +@DOCSTRING(undo_string_escapes) + @node Concatenating Strings @subsection Concatenating Strings @@ -370,25 +413,21 @@ @DOCSTRING(cstrcat) -@node Converting Numerical Data to Strings -@subsection Converting Numerical Data to Strings -Apart from the string concatenation functions (@pxref{Concatenating Strings}) -which cast numerical data to the corresponding UTF-8 encoded characters, there -are several functions that format numerical data as strings. @code{mat2str} -and @code{num2str} convert real or complex matrices, while @code{int2str} -converts integer matrices. @code{int2str} takes the real part of complex -values and round fractional values to integer. A more flexible way to format -numerical data as strings is the @code{sprintf} function -(@pxref{Formatted Output}, @ref{XREFsprintf,,sprintf}). +@node Splitting and Joining Strings +@subsection Splitting and Joining Strings + +@DOCSTRING(substr) + +@DOCSTRING(strtok) -@DOCSTRING(mat2str) +@DOCSTRING(strsplit) -@DOCSTRING(num2str) +@DOCSTRING(ostrsplit) -@DOCSTRING(int2str) +@DOCSTRING(strjoin) -@node Comparing Strings -@section Comparing Strings +@node Searching in Strings +@subsection Searching in Strings Since a string is a character array, comparisons between strings work element by element as the following example shows: @@ -416,32 +455,12 @@ @DOCSTRING(strncmpi) -@node Manipulating Strings -@section Manipulating Strings - -Octave supports a wide range of functions for manipulating strings. -Since a string is just a matrix, simple manipulations can be accomplished -using standard operators. The following example shows how to replace -all blank characters with underscores. +Despite those comparison functions, there are more specialized function to +find the index position of a search pattern within a string. -@example -@group -quote = ... - "First things first, but not necessarily in that order"; -quote( quote == " " ) = "_" -@result{} quote = - First_things_first,_but_not_necessarily_in_that_order -@end group -@end example +@DOCSTRING(startsWith) -For more complex manipulations, such as searching, replacing, and -general regular expressions, the following functions come with Octave. - -@DOCSTRING(deblank) - -@DOCSTRING(strtrim) - -@DOCSTRING(strtrunc) +@DOCSTRING(endsWith) @DOCSTRING(findstr) @@ -451,26 +470,19 @@ @DOCSTRING(rindex) -@DOCSTRING(strfind) +@DOCSTRING(unicode_idx) -@DOCSTRING(strjoin) +@DOCSTRING(strfind) @DOCSTRING(strmatch) -@DOCSTRING(strtok) - -@DOCSTRING(strsplit) - -@DOCSTRING(ostrsplit) - -@DOCSTRING(strread) +@node Searching and Replacing in Strings +@subsection Searching and Replacing in Strings @DOCSTRING(strrep) @DOCSTRING(erase) -@DOCSTRING(substr) - @DOCSTRING(regexp) @DOCSTRING(regexpi) @@ -479,23 +491,45 @@ @DOCSTRING(regexptranslate) -@DOCSTRING(untabify) +@node Converting Strings +@section Converting Strings + +Octave offers several kinds of conversion functions for Strings. -@DOCSTRING(unicode_idx) +@menu +* String encoding:: +* Numerical Data and Strings:: +* JSON data encoding/decoding:: +@end menu -@node String Conversions -@section String Conversions +@node String encoding +@subsection String encoding + +@DOCSTRING(unicode2native) + +@DOCSTRING(native2unicode) -Octave supports various kinds of conversions between strings and -numbers. As an example, it is possible to convert a string containing -a hexadecimal number to a floating point number. +@node Numerical Data and Strings +@subsection Numerical Data and Strings -@example -@group -hex2dec ("FF") - @result{} 255 -@end group -@end example +Apart from the string concatenation functions (@pxref{Concatenating Strings}) +which cast numerical data to the corresponding UTF-8 encoded characters, there +are several functions that format numerical data as strings. @code{mat2str} +and @code{num2str} convert real or complex matrices, while @code{int2str} +converts integer matrices. @code{int2str} takes the real part of complex +values and round fractional values to integer. A more flexible way to format +numerical data as strings is the @code{sprintf} function +(@pxref{Formatted Output}, @ref{XREFsprintf,,sprintf}). + +@DOCSTRING(mat2str) + +@DOCSTRING(num2str) + +@DOCSTRING(int2str) + +@DOCSTRING(str2double) + +@DOCSTRING(str2num) @DOCSTRING(bin2dec) @@ -513,23 +547,18 @@ @DOCSTRING(hex2num) -@DOCSTRING(str2double) - -@DOCSTRING(strjust) +@DOCSTRING(strread) -@DOCSTRING(str2num) - -@DOCSTRING(tolower) +@node JSON data encoding/decoding +@subsection JSON data encoding/decoding -@DOCSTRING(toupper) - -@DOCSTRING(unicode2native) +JavaScript Object Notation, in short JSON, is a very common human readable +and structured data format. GNU Octave supports encoding and decoding this +format with the following two functions. -@DOCSTRING(native2unicode) +@DOCSTRING(jsonencode) -@DOCSTRING(do_string_escapes) - -@DOCSTRING(undo_string_escapes) +@DOCSTRING(jsondecode) @node Character Class Functions @section Character Class Functions diff -r dc3ee9616267 -r fa2cdef14442 doc/interpreter/system.txi --- a/doc/interpreter/system.txi Thu Nov 19 13:05:51 2020 -0800 +++ b/doc/interpreter/system.txi Thu Nov 19 13:08:00 2020 -0800 @@ -324,6 +324,10 @@ @DOCSTRING(base64_decode) +@DOCSTRING(matlab.net.base64encode) + +@DOCSTRING(matlab.net.base64decode) + @node Controlling Subprocesses @section Controlling Subprocesses @@ -554,6 +558,8 @@ @DOCSTRING(license) +@DOCSTRING(memory) + @DOCSTRING(getrusage) @DOCSTRING(winqueryreg) diff -r dc3ee9616267 -r fa2cdef14442 etc/NEWS.6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/NEWS.6 Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,323 @@ +Summary of important user-visible changes for version 6.1.0 (2020-08-26): +------------------------------------------------------------------------ + +### General improvements + +- The `intersect`, `setdiff`, `setxor`, `union`, and `unique` functions + accept a new sorting option `"stable"` which will return output values + in the same order as the input, rather than in ascending order. + +- Complex RESTful web services can now be accessed by the `webread` and + `webwrite` functions alongside with the `weboptions` structure. One + major feature is the support for cookies to enable RESTful + communication with the web service. + + Additionally, the system web browser can be opened by the `web` + function. + +- The `linspace` function now produces symmetrical sequences when the + endpoints are symmetric. This is more intuitive and also compatible + with recent changes made in Matlab R2019b. + +- The underlying algorithm of the `rand` function has been changed. + For single precision outputs, the algorithm has been fixed so that it + produces values strictly in the range (0, 1). Previously, it could + occasionally generate the right endpoint value of 1 (See bug #41742). + In addition, the new implementation uses a uniform interval between + floating point values in the range (0, 1) rather than targeting a + uniform density (# of random integers / length along real number + line). + +- Numerical integration has been improved. The `quadv` function has + been re-written so that it can compute integrands of periodic + functions. At the same time, performance is better with ~3.5X fewer + function evaluations required. A bug in `quadgk` that caused complex + path integrals specified with `"Waypoints"` to occasionally be + calculated in the opposite direction was fixed. + +- The `edit` function option `"editinplace"` now defaults to `true` and + the option `"home"` now defaults to the empty matrix `[]`. Files will + no longer be copied to the user's HOME directory for editing. The old + behavior can be restored by setting `"editinplace"` to `false` and + `"home"` to `"~/octave"`. + +- The `format` command supports two new options: `uppercase` and + `lowercase` (default). With the default, print a lowercase 'e' for + the exponent character in scientific notation and lowercase 'a-f' for + the hex digits representing 10-15. With `uppercase`, print 'E' and + 'A-F' instead. The previous uppercase formats, `E` and `G`, no longer + control the case of the output. + + Additionally, the `format` command can be called with multiple options + for controlling the format, spacing, and case in arbitrary order. + For example: + + format long e uppercase loose + + Note, in the case of multiple competing format options the rightmost + one is used, and, in case of an error, the previous format remains + unchanged. + +- L-value references (e.g., increment (++), decrement (--), and all + in-place assignment operators (+=, -=, *=, /=, etc.)) are no longer + allowed in anonymous functions. + +- New warnings have been added about questionable uses of the colon ':' + range operator. Each has a new warning ID so that it can be disabled + if desired. + + > `Octave:colon-complex-argument` : when any arg is complex + > `Octave:colon-nonscalar-argument` : when any arg is non-scalar + +- The `regexp` and related functions now correctly handle and *require* + strings in UTF-8 encoding. As with any other function that requires + strings to be encoded in Octave's native encoding, you can use + `native2unicode` to convert from your preferred locale. For example, + the copyright symbol in UTF-8 is `native2unicode (169, "latin1")`. + +- The startup file `octaverc` can now be located in the platform + dependent location for user local configuration files (e.g., + ${XDG_CONFIG_HOME}/octave/octaverc on Unix-like operating systems or + %APPDATA%\octave\octaverc on Windows). + +- `pkg describe` now lists dependencies and inverse dependencies + (i.e., other installed packages that depend on the package in + question). + +- `pkg test` now tests all functions in a package. + +- When unloading a package, `pkg` now checks if any remaining loaded + packages depend on the one to be removed. If this is the case `pkg` + aborts with an explanatory error message. This behavior can be + overridden with the `-nodeps` option. + +- The command + + dbstop in CLASS at METHOD + + now works to set breakpoints in classdef constructors and methods. + +#### Graphics backend + +- The use of Qt4 for graphics and the GUI is deprecated in Octave + version 6 and no further bug fixes will be made. Qt4 support will be + removed completely in Octave version 7. + +- The `legend` function has been entirely rewritten. This fixes a + number of historical bugs, and also implements new properties such as + `"AutoUpdate"` and `"NumColumns"`. The gnuplot toolkit---which is no + longer actively maintained---still uses the old legend function. + +- The `axis` function was updated which resolved 10 bugs affecting + axes to which `"equal"` had been applied. + +- Graphic primitives now accept a color property value of `"none"` + which is useful when a particular primitive needs to be hidden + (for example, the Y-axis of an axes object with `"ycolor" = "none"`) + without hiding the entire primitive `"visibility" = "off"`. + +- A new property `"FontSmoothing"` has been added to text and axes + objects that controls whether anti-aliasing is used during the + rendering of characters. The default is `"on"` which produces smooth, + more visually appealing text. + +- The figure property `"windowscrollwheelfcn"`is now implemented. + This makes it possible to provide a callback function to be executed + when users manipulate the mouse wheel on a given figure. + +- The figure properties `"pointer"`, `"pointershapecdata"`, and + `"pointershapehotspot"` are now implemented. This makes it possible + to change the shape of the cursor (pointer in Matlab-speak) displayed + in a plot window. + +- The figure property `"paperpositionmode"` now has the default `"auto"` + rather than `"manual"`. This change is more intuitive and is + Matlab compatible. + +- The appearance of patterned lines `"LineStyle" = ":"|"--"|"-."` has + been improved for small widths (`"LineWidth"` less than 1.5 pixels) + which is a common scenario. + +- Printing to EPS files now uses a tight bounding box (`"-tight"` + argument to print) by default. This makes more sense for EPS + files which are normally embedded within other documents, and is + Matlab compatible. If necessary use the `"-loose"` option to + reproduce figures as they appeared in previous versions of Octave. + +- The following print devices are no longer officially supported: cdr, + corel, aifm, ill, cgm, hpgl, mf and dxf. A warning will be thrown + when using those devices, and the code for supporting those formats + will eventually be removed from a future version of Octave. + +- The placement of text subscripts and superscripts has been + re-engineered and now produces visually attractive results similar to + Latex. + +### Matlab compatibility + +- The function `unique` now returns column index vectors for the second + and third outputs. When duplicate values are present, the default + index to return is now the `"first"` occurrence. The previous Octave + behavior, or Matlab behavior from releases prior to R2012b, can be + obtained by using the `"legacy"` flag. + +- The function `setdiff` with the `"rows"` argument now returns Matlab + compatible results. The previous Octave behavior, or Matlab behavior + from releases prior to R2012b, can be obtained by using the `"legacy"` + flag. + +- The functions `intersect`, `setxor`, and `union` now accept a + `"legacy"` flag which changes the index values (second and third + outputs) as well as the orientation of all outputs to match Matlab + releases prior to R2012b. + +- The function `streamtube` is Matlab compatible and plots tubes along + streamlines which are scaled by the vector field divergence. The + Octave-only extension `ostreamtube` can be used to visualize the flow + expansion and contraction of the vector field due to the local + crossflow divergence. + +- The interpreter now supports handles to nested functions. + +- The graphics properties `"LineWidth"` and `"MarkerSize"` are now + measured in points, *not* pixels. Compared to previous versions + of Octave, some lines and markers will appear 4/3 larger. + +- The meta.class property "SuperClassList" has been renamed + "Superclasslist" for Matlab compatibility. The original name will + exist as an alias until Octave version 8.1. + +- Inline functions created by the function `inline` are now of type + "inline" when interrogated with the `class` function. In previous + versions of Octave, the class returned was "function_handle". This + change is Matlab compatible. Inline functions are deprecated in + both Matlab and Octave and support may eventually be removed. + Anonymous functions can be used to replace all instances of inline + functions. + +- The function `javaaddpath` now prepends new directories to the + existing dynamic classpath by default. To append them instead, use + the new `"-end"` argument. Multiple directories may now be specified + in a cell array of strings. + +- An undocumented function `gui_mainfcn` has been added, for compatibility + with figures created with Matlab's GUIDE. + +- Several validator functions of type `mustBe*` have been added. See + the list of new functions below. + +### Alphabetical list of new functions added in Octave 6 + +* `auto_repeat_debug_command` +* `commandhistory` +* `commandwindow` +* `filebrowser` +* `is_same_file` +* `lightangle` +* `mustBeFinite` +* `mustBeGreaterThan` +* `mustBeGreaterThanOrEqual` +* `mustBeInteger` +* `mustBeLessThan` +* `mustBeLessThanOrEqual` +* `mustBeMember` +* `mustBeNegative` +* `mustBeNonempty` +* `mustBeNonNan` +* `mustBeNonnegative` +* `mustBeNonpositive` +* `mustBeNonsparse` +* `mustBeNonzero` +* `mustBeNumeric` +* `mustBeNumericOrLogical` +* `mustBePositive` +* `mustBeReal` +* `namedargs2cell` +* `newline` +* `ode23s` +* `ostreamtube` +* `rescale` +* `rotx` +* `roty` +* `rotz` +* `stream2` +* `stream3` +* `streamline` +* `streamtube` +* `uisetfont` +* `verLessThan` +* `web` +* `weboptions` +* `webread` +* `webwrite` +* `workspace` + + +### Deprecated functions and properties + +The following functions and properties have been deprecated in Octave 6 +and will be removed from Octave 8 (or whatever version is the second +major release after 6): + +- Functions + + Function | Replacement + -----------------------|------------------ + `runtests` | `oruntests` + +- Properties + + Object | Property | Value + -----------------|---------------|------------ + | | + +- The environment variable used by `mkoctfile` for linker flags is now + `LDFLAGS` rather than `LFLAGS`. `LFLAGS` is deprecated, and a warning + is emitted if it is used, but it will continue to work. + + +### Removed functions and properties + +The following functions and properties were deprecated in Octave 4.4 +and have been removed from Octave 6. + +- Functions + + Function | Replacement + ---------------------|------------------ + `chop` | `sprintf` for visual results + `desktop` | `isguirunning` + `tmpnam` | `tempname` + `toascii` | `double` + `java2mat` | `__java2mat__` + +- Properties + + Object | Property | Value + ---------------------|---------------------------|----------------------- + `annotation` | `edgecolor ("rectangle")` | + `axes` | `drawmode` | + `figure` | `doublebuffer` | + | `mincolormap` | + | `wvisual` | + | `wvisualmode` | + | `xdisplay` | + | `xvisual` | + | `xvisualmode` | + `line` | `interpreter` | + `patch` | `interpreter` | + `surface` | `interpreter` | + `text` | `fontweight` | `"demi"` and `"light"` + `uibuttongroup` | `fontweight` | `"demi"` and `"light"` + `uicontrol` | `fontweight` | `"demi"` and `"light"` + `uipanel` | `fontweight` | `"demi"` and `"light"` + `uitable` | `fontweight` | `"demi"` and `"light"` + + +### Old release news + +- [Octave 5.x](etc/NEWS.5) +- [Octave 4.x](etc/NEWS.4) +- [Octave 3.x](etc/NEWS.3) +- [Octave 2.x](etc/NEWS.2) +- [Octave 1.x](etc/NEWS.1) diff -r dc3ee9616267 -r fa2cdef14442 examples/code/@FIRfilter/FIRfilter.m --- a/examples/code/@FIRfilter/FIRfilter.m Thu Nov 19 13:05:51 2020 -0800 +++ b/examples/code/@FIRfilter/FIRfilter.m Thu Nov 19 13:08:00 2020 -0800 @@ -6,10 +6,6 @@ function f = FIRfilter (p) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) p = @polynomial ([1]); elseif (! isa (p, "polynomial")) diff -r dc3ee9616267 -r fa2cdef14442 examples/code/@FIRfilter/FIRfilter_aggregation.m --- a/examples/code/@FIRfilter/FIRfilter_aggregation.m Thu Nov 19 13:05:51 2020 -0800 +++ b/examples/code/@FIRfilter/FIRfilter_aggregation.m Thu Nov 19 13:08:00 2020 -0800 @@ -6,10 +6,6 @@ function f = FIRfilter (p) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) f.polynomial = @polynomial ([1]); else diff -r dc3ee9616267 -r fa2cdef14442 examples/code/@polynomial/get.m --- a/examples/code/@polynomial/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/examples/code/@polynomial/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,6 @@ function val = get (p, prop) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 examples/code/@polynomial/polynomial.m --- a/examples/code/@polynomial/polynomial.m Thu Nov 19 13:05:51 2020 -0800 +++ b/examples/code/@polynomial/polynomial.m Thu Nov 19 13:08:00 2020 -0800 @@ -13,10 +13,6 @@ function p = polynomial (a) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) p.poly = 0; p = class (p, "polynomial"); diff -r dc3ee9616267 -r fa2cdef14442 examples/code/@polynomial/polynomial_superiorto.m --- a/examples/code/@polynomial/polynomial_superiorto.m Thu Nov 19 13:05:51 2020 -0800 +++ b/examples/code/@polynomial/polynomial_superiorto.m Thu Nov 19 13:08:00 2020 -0800 @@ -13,10 +13,6 @@ function p = polynomial (a) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) p.poly = [0]; p = class (p, "polynomial"); diff -r dc3ee9616267 -r fa2cdef14442 examples/code/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/code/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,75 @@ +%canon_reldir%_EXTRA_DIST = + +%canon_reldir%_CLEANFILES = +%canon_reldir%_DISTCLEANFILES = +%canon_reldir%_MAINTAINERCLEANFILES = + +%canon_reldir%_SRC = \ + %reldir%/@FIRfilter/FIRfilter.m \ + %reldir%/@FIRfilter/FIRfilter_aggregation.m \ + %reldir%/@FIRfilter/display.m \ + %reldir%/@FIRfilter/subsasgn.m \ + %reldir%/@FIRfilter/subsref.m \ + %reldir%/@polynomial/disp.m \ + %reldir%/@polynomial/double.m \ + %reldir%/@polynomial/end.m \ + %reldir%/@polynomial/get.m \ + %reldir%/@polynomial/mtimes.m \ + %reldir%/@polynomial/numel.m \ + %reldir%/@polynomial/plot.m \ + %reldir%/@polynomial/polynomial.m \ + %reldir%/@polynomial/polynomial_superiorto.m \ + %reldir%/@polynomial/polyval.m \ + %reldir%/@polynomial/roots.m \ + %reldir%/@polynomial/set.m \ + %reldir%/@polynomial/subsasgn.m \ + %reldir%/@polynomial/subsref.m \ + %reldir%/addtwomatrices.cc \ + %reldir%/celldemo.cc \ + %reldir%/embedded.cc \ + %reldir%/fortrandemo.cc \ + %reldir%/fortransub.f \ + %reldir%/funcdemo.cc \ + %reldir%/globaldemo.cc \ + %reldir%/helloworld.cc \ + %reldir%/make_int.cc \ + %reldir%/mex_demo.c \ + %reldir%/mycell.c \ + %reldir%/myfeval.c \ + %reldir%/myfevalf.f \ + %reldir%/myfunc.c \ + %reldir%/myhello.c \ + %reldir%/mypow2.c \ + %reldir%/myprop.c \ + %reldir%/myset.c \ + %reldir%/mysparse.c \ + %reldir%/mystring.c \ + %reldir%/mystruct.c \ + %reldir%/oct_demo.cc \ + %reldir%/oregonator.cc \ + %reldir%/oregonator.m \ + %reldir%/paramdemo.cc \ + %reldir%/polynomial2.m \ + %reldir%/standalone.cc \ + %reldir%/standalonebuiltin.cc \ + %reldir%/stringdemo.cc \ + %reldir%/structdemo.cc \ + %reldir%/unwinddemo.cc + +%canon_reldir%_EXTRA_DIST += \ + $(%canon_reldir%_SRC) + +EXTRA_DIST += $(%canon_reldir%_EXTRA_DIST) + +CLEANFILES += $(%canon_reldir%_CLEANFILES) +DISTCLEANFILES += $(%canon_reldir%_DISTCLEANFILES) +MAINTAINERCLEANFILES += $(%canon_reldir%_MAINTAINERCLEANFILES) + +examples-clean: + rm -f $(%canon_reldir%_CLEANFILES) + +examples-distclean: examples-clean + rm -f $(%canon_reldir%_DISTCLEANFILES) + +examples-maintainer-clean: examples-distclean + rm -f $(%canon_reldir%_MAINTAINERCLEANFILES) diff -r dc3ee9616267 -r fa2cdef14442 examples/code/polynomial2.m --- a/examples/code/polynomial2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/examples/code/polynomial2.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,10 +5,6 @@ methods function p = polynomial2 (a) - if (nargin > 1) - print_usage (); - endif - if (nargin == 1) if (isa (a, "polynomial2")) p.poly = a.poly; diff -r dc3ee9616267 -r fa2cdef14442 examples/data/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/data/README Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,51 @@ +* penny data file: + + See the discussion here: + https://savannah.gnu.org/patch/?func=detailitem&item_id=8472 + +* west0479 data file: + + Chemical engineering plant models Eight stage column section, all + rigorous from set CHEMWEST, from the Harwell-Boeing Collection. + + west0479.mtx: original file obtained from from + https://math.nist.gov/MatrixMarket/data/Harwell-Boeing/chemwest/west0479.html + + west0479.mat: generated from west0479.mtx as follows: + + x = load ("west0479.mtx"); + nr = x(1,1); + nc = x(1,2); + i = x(2:end,1); + j = x(2:end,2); + sv = x(2:end,3); + west0479 = sparse(i, j, sv, nr, nc); + save -text west0479.mat west0479 + + Note that the original file has 1910 entries but 22 of them are exact + zeros: + + 384 86 0.0000000000000e+00 + 360 116 0.0000000000000e+00 + 361 117 0.0000000000000e+00 + 362 118 0.0000000000000e+00 + 238 224 0.0000000000000e+00 + 239 225 0.0000000000000e+00 + 240 226 0.0000000000000e+00 + 250 240 0.0000000000000e+00 + 251 241 0.0000000000000e+00 + 252 242 0.0000000000000e+00 + 272 259 0.0000000000000e+00 + 273 260 0.0000000000000e+00 + 274 261 0.0000000000000e+00 + 294 278 0.0000000000000e+00 + 295 279 0.0000000000000e+00 + 296 280 0.0000000000000e+00 + 316 297 0.0000000000000e+00 + 317 298 0.0000000000000e+00 + 318 299 0.0000000000000e+00 + 338 316 0.0000000000000e+00 + 339 317 0.0000000000000e+00 + 340 318 0.0000000000000e+00 + + These are not explicitly included in the west0479.mat file. diff -r dc3ee9616267 -r fa2cdef14442 examples/data/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/data/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,15 @@ +%canon_reldir%_EXTRA_DIST = + +%canon_reldir%_DAT = \ + %reldir%/penny.mat \ + %reldir%/west0479.mat + +%canon_reldir%_EXTRA_DIST += \ + $(%canon_reldir%_DAT) \ + %reldir%/README \ + %reldir%/west0479.mtx + +octdata_DATA += \ + $(%canon_reldir%_DAT) + +EXTRA_DIST += $(%canon_reldir%_EXTRA_DIST) diff -r dc3ee9616267 -r fa2cdef14442 examples/data/west0479.mat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/data/west0479.mat Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1896 @@ +# Created by Octave 5.2.0, Thu Jun 04 22:49:15 2020 EDT +# name: west0479 +# type: sparse matrix +# nnz: 1888 +# rows: 479 +# columns: 479 +25 1 1 +31 1 -0.037648130000000002 +87 1 -0.34423959999999998 +26 2 1 +31 2 -0.024522619999999998 +88 2 -0.3737086 +27 3 1 +31 3 -0.036613039999999999 +89 3 -0.83693790000000001 +28 4 130 +29 4 -2.433767 +29 5 1 +30 5 -1.6140909999999999 +30 6 1.6140909999999999 +31 6 -0.21873210000000001 +87 6 -1 +88 6 -1 +89 6 -1 +32 7 -1.138352 +43 7 0.036694280000000003 +111 7 0.099316360000000006 +112 7 0.099316360000000006 +113 7 0.099316360000000006 +33 8 -0.5 +43 8 0.016117289999999999 +111 8 0.087245760000000006 +34 9 -0.36119180000000001 +43 9 0.01164286 +112 9 0.1050415 +35 10 -0.3218876 +43 10 0.01037591 +113 10 0.1404166 +36 11 -0.43624160000000001 +37 11 -0.76804249999999996 +38 11 -0.14302790000000001 +39 11 -0.15938859999999999 +37 12 1 +43 12 -0.048560819999999998 +111 12 -0.2628684 +38 13 1 +43 13 -0.030925950000000001 +112 13 -0.27901280000000001 +39 14 1 +43 14 -0.046123589999999999 +113 14 -0.62418819999999997 +40 15 5.2824359999999997 +42 15 -0.61239209999999999 +41 16 0.2886822 +42 16 -0.2163815 +42 17 1.3287739999999999 +43 17 -0.36946859999999998 +111 17 -1 +112 17 -1 +113 17 -1 +2 18 48.176470000000002 +8 18 -1 +11 18 -3.3474840000000003e-05 +3 19 83.5 +9 19 -1 +12 19 -4.1365390000000001e-05 +4 20 171.94120000000001 +10 20 -1 +13 20 -8.4843450000000005e-05 +5 21 96.651380000000003 +8 21 2.5 +11 21 3.3474840000000003e-05 +6 22 168.2706 +9 22 2.5 +12 22 4.1365390000000001e-05 +7 23 347.5872 +10 23 2.5 +13 23 8.4843450000000005e-05 +8 24 1 +17 24 -0.1106967 +27 24 1.605232 +9 25 1 +17 25 -0.089808520000000003 +10 26 1 +17 26 -0.15173690000000001 +11 27 1.0104550000000001 +18 27 -0.5 +12 28 1.005978 +18 28 -0.29999999999999999 +13 29 1.002885 +18 29 -0.20000000000000001 +14 30 1 +17 30 -0.1811855 +15 31 1 +17 31 -0.24002390000000001 +16 32 1 +17 32 -0.22654840000000001 +17 33 1 +19 33 -1 +30 33 1.5 +42 33 0.5 +18 34 1 +20 34 -316220 +23 34 -12323.690000000001 +24 34 -1 +30 34 -35226.800000000003 +41 34 18449.02 +19 35 5.2983390000000004 +21 35 0.0024526869999999998 +20 36 1080.8589999999999 +21 36 -0.2050215 +21 37 0.14419199999999999 +22 37 63.05986 +30 37 -0.1159299 +22 38 -18449.02 +24 38 0.84533389999999997 +40 38 -18449.02 +41 38 -15595.58 +23 39 1 +30 39 0.20204929999999999 +42 39 -0.88547100000000001 +24 40 0.0001000234 +30 40 2.4483389999999998 +42 40 0.81611299999999998 +68 41 1 +74 41 -0.0002278669 +99 41 -0.26243949999999999 +69 42 1 +74 42 -0.00041887629999999999 +100 42 -0.32161960000000001 +70 43 1 +74 43 -0.001576933 +101 43 -0.72647609999999996 +71 44 300 +72 44 -2.8518910000000002 +72 45 1 +73 45 -0.28701589999999999 +73 46 0.28701589999999999 +74 46 -0.0043413219999999999 +99 46 -1 +100 46 -1 +101 46 -1 +75 47 -1.138352 +86 47 0.042002860000000003 +123 47 0.9414806 +124 47 0.9414806 +125 47 0.9414806 +76 48 -0.3218876 +86 48 0.011877 +123 48 1.3310949999999999 +77 49 -0.36119180000000001 +86 49 0.013327240000000001 +124 49 0.99575290000000005 +78 50 -0.5 +86 50 0.01844898 +125 50 0.82705600000000001 +79 51 -1 +80 51 -19.239999999999998 +81 51 -3.8029999999999999 +82 51 -9.4809999999999999 +80 52 1 +86 52 -0.00088757840000000001 +123 52 -0.099473919999999993 +81 53 1 +86 53 -0.0013313680000000001 +124 53 -0.099473919999999993 +82 54 1 +86 54 -0.0022189459999999999 +125 54 -0.099473919999999993 +83 55 1.177613 +85 55 -3.1089630000000001 +84 56 0.99194249999999995 +85 56 -2.640056 +85 57 3.1921119999999998 +86 57 -0.044613630000000001 +123 57 -1 +124 57 -1 +125 57 -1 +45 58 109.86879999999999 +51 58 -1 +54 58 -3.3081099999999997e-05 +46 59 191.38460000000001 +52 59 -1 +55 59 -4.1084670000000001e-05 +47 60 395.4796 +53 60 -1 +56 60 -8.456383e-05 +48 61 221.73390000000001 +51 61 2.5 +54 61 3.3081099999999997e-05 +49 62 387.00920000000002 +52 62 2.5 +55 62 4.1084670000000001e-05 +50 63 800.81650000000002 +53 63 2.5 +56 63 8.456383e-05 +51 64 1 +60 64 -0.0091702290000000002 +52 65 1 +60 65 -0.046441099999999999 +53 66 1 +60 66 -0.48999189999999998 +54 67 1.0045299999999999 +61 67 -0.20000000000000001 +55 68 1.002591 +61 68 -0.29999999999999999 +56 69 1.00125 +61 69 -0.5 +57 70 1 +60 70 -0.037500529999999997 +58 71 1 +60 71 -0.124143 +59 72 1 +60 72 -0.29275319999999999 +60 73 1 +62 73 -1 +73 73 0.18537329999999999 +85 73 0.06179109 +61 74 1 +63 74 -316220 +66 74 -16364.190000000001 +67 74 -1 +73 74 -4696.7820000000002 +84 74 131.85400000000001 +62 75 22.12913 +64 75 0.95375259999999995 +63 76 2494.29 +64 76 -1.021587 +64 77 0.88782810000000001 +65 77 1.0400419999999999 +73 77 -2.640056 +65 78 -131.85400000000001 +67 78 0.0080574700000000006 +83 78 -131.85400000000001 +84 78 -1.0624089999999999 +66 79 1 +73 79 0.1016426 +85 79 -0.06179109 +67 80 0.0076452569999999999 +73 80 23.098949999999999 +85 80 7.699649 +31 81 1 +244 81 1 +43 82 1 +1 83 1 +17 83 -3.850231 +18 83 -8.4599350000000005e-05 +31 83 2.0159099999999999 +35 83 1 +43 83 1.596171 +243 83 -0.78975119999999999 +74 84 1 +388 84 0.88175619999999999 +86 85 1 +44 86 1 +60 86 -2.7937599999999998 +61 86 -8.4458229999999999e-05 +74 86 2.0156649999999998 +78 86 1 +86 86 1.5939939999999999 +387 86 -0.96191499999999996 +385 87 0.002424669 +386 87 0.030362779999999999 +387 87 0.67304509999999995 +388 87 1.45936 +96 88 0.016896609999999999 +97 88 0.034848030000000002 +98 88 -0.060080179999999997 +120 88 -0.55527170000000003 +121 88 -0.47703980000000001 +122 88 -0.1858293 +141 88 -1 +142 88 -1 +143 88 -1 +185 88 -55.188569999999999 +186 88 -95.676860000000005 +187 88 -215.83770000000001 +389 88 1 +438 88 1 +439 88 1 +440 88 1 +441 88 1 +442 88 1 +443 88 1 +450 88 -0.0018907559999999999 +451 88 -0.0015311400000000001 +452 88 -0.001013726 +455 88 2.5 +456 88 26.063700000000001 +458 88 1 +459 88 -1.5 +461 88 -9.6031809999999993 +462 88 -9.4541850000000007 +463 88 -9.4376809999999995 +464 88 -48.295720000000003 +472 88 0.90759219999999996 +473 88 -4.3759670000000002 +474 88 -8.997992 +475 88 -8.8819579999999991 +476 88 1 +182 89 1 +183 89 1 +184 89 1 +391 89 1 +455 89 -1 +456 89 -26.063700000000001 +458 89 -1 +468 89 1 +388 90 -1.45936 +467 90 1 +479 91 1 +203 92 -1 +204 92 -1 +205 92 -1 +209 92 1 +210 92 1 +211 92 1 +382 92 56.953099999999999 +385 92 0.70583249999999997 +437 92 1 +453 92 -0.64913719999999997 +454 92 -3.2948409999999999e-05 +467 92 0.53807479999999996 +469 92 1 +479 92 0.082471119999999995 +203 93 -1 +204 93 -1 +205 93 -1 +209 93 1 +210 93 1 +211 93 1 +383 93 11.58384 +386 93 0.70583249999999997 +437 93 1 +453 93 -1.021542 +454 93 -4.0990330000000002e-05 +467 93 -0.36302479999999998 +470 93 1 +479 93 0.069522609999999999 +203 94 -1 +204 94 -1 +205 94 -1 +209 94 1 +210 94 1 +211 94 1 +384 94 0.3209631 +387 94 0.70583249999999997 +437 94 1 +453 94 -2.049007 +454 94 -8.4470029999999998e-05 +467 94 0.91353620000000002 +471 94 1 +479 94 0.83976379999999995 +241 95 0.55083519999999997 +242 95 0.4489223 +243 95 0.0002425203 +244 95 0.40528330000000001 +108 96 -0.067276619999999995 +109 96 -0.15700610000000001 +110 96 -0.097475699999999998 +132 96 -0.25060070000000001 +133 96 -0.2802617 +134 96 0.1008491 +245 96 -1 +395 96 1 +396 96 1 +397 96 1 +398 96 1 +399 96 1 +400 96 1 +407 96 -0.0028636019999999998 +408 96 -0.0023162590000000002 +409 96 -0.00153089 +412 96 2.5 +413 96 11.5878 +415 96 1 +416 96 -1.101224 +418 96 -1.3644320000000001 +419 96 -1.2188209999999999 +420 96 -1.2108589999999999 +421 96 -34.621049999999997 +429 96 0.60313589999999995 +430 96 -0.59963840000000002 +431 96 -1.403392 +432 96 -1.3703860000000001 +433 96 1 +246 97 1 +412 97 -1 +413 97 -11.5878 +415 97 -1 +425 97 1 +244 98 -0.40528330000000001 +424 98 1 +436 99 1 +160 100 -0.85938400000000004 +161 100 -0.773339 +162 100 -0.79517400000000005 +238 100 -1 +241 100 1 +394 100 1 +410 100 -1.623659 +411 100 -3.3032779999999999e-05 +424 100 3.5720350000000001 +426 100 1 +436 100 0.92435319999999999 +160 101 -1.171821 +161 101 -1.277352 +162 101 -1.250508 +239 101 -1 +242 101 1 +394 101 1 +410 101 -2.4602889999999999 +411 101 -4.1050809999999997e-05 +424 101 -2.1785329999999998 +427 101 1 +436 101 0.65098420000000001 +160 102 -2.3280470000000002 +161 102 -2.4161549999999998 +162 102 -2.5121660000000001 +240 102 -1 +243 102 1 +394 102 1 +410 102 -4.7536199999999997 +411 102 -8.45305e-05 +424 102 6.1671399999999998 +428 102 1 +436 102 3.3966910000000001 +241 103 0.043736570000000002 +242 103 0.57396460000000005 +243 103 0.15834899999999999 +244 103 0.18781249999999999 +253 103 -0.044344130000000002 +254 103 -0.58193779999999995 +255 103 -0.16054869999999999 +256 103 -1 +135 104 -1 +136 104 -1 +137 104 -1 +151 104 -62.680900000000001 +152 104 -123.89 +153 104 -464.35550000000001 +245 104 1 +248 104 -0.051646549999999999 +249 104 -0.32417620000000003 +148 105 1 +149 105 1 +150 105 1 +247 105 1 +244 106 -0.18781249999999999 +248 106 1 +256 106 1 +249 107 1 +147 108 1 +169 108 -1 +170 108 -1 +171 108 -1 +175 108 1 +176 108 1 +177 108 1 +238 108 9.7738750000000003 +241 108 0.77605020000000002 +248 108 7.2528309999999996 +249 108 0.78041000000000005 +253 108 -0.78683060000000005 +147 109 1 +169 109 -1 +170 109 -1 +171 109 -1 +175 109 1 +176 109 1 +177 109 1 +239 109 0.60698209999999997 +242 109 0.77605020000000002 +248 109 -2.3895080000000002 +249 109 0.68493979999999999 +254 109 -0.78683060000000005 +147 110 1 +169 110 -1 +170 110 -1 +171 110 -1 +175 110 1 +176 110 1 +177 110 1 +240 110 0.001188564 +243 110 0.77605020000000002 +248 110 11.55883 +249 110 2.2026439999999998 +255 110 -0.78683060000000005 +363 111 -0.17051479999999999 +364 111 -0.43429630000000002 +365 111 -0.26674209999999998 +366 111 -2.609302 +385 111 0.1956447 +386 111 0.49830160000000001 +387 111 0.30605369999999998 +388 111 0.42239599999999999 +215 112 1 +216 112 1 +217 112 1 +218 112 1 +219 112 1 +220 112 1 +227 112 -0.0018907559999999999 +228 112 -0.0015311400000000001 +229 112 -0.001013726 +232 112 2.5 +233 112 16.672409999999999 +235 112 1 +236 112 -1.5 +389 112 -1 +392 112 -0.46212130000000001 +393 112 -0.1234962 +232 113 -1 +233 113 -16.672409999999999 +235 113 -1 +368 113 -1 +369 113 -1 +390 113 1 +366 114 2.609302 +388 114 -0.42239599999999999 +392 114 1 +393 115 1 +181 116 1 +194 116 -0.58697619999999995 +195 116 -0.50651550000000001 +196 116 -0.5139918 +230 116 -1.0366850000000001 +231 116 -3.2948409999999999e-05 +363 116 -0.87155309999999997 +382 116 -1 +385 116 1 +392 116 2.63998 +393 116 0.55742069999999999 +181 117 1 +194 117 -0.80016370000000003 +195 117 -0.83640899999999996 +196 117 -0.8081026 +230 117 -1.6376949999999999 +231 117 -4.0990330000000002e-05 +364 117 -0.87155309999999997 +383 117 -1 +386 117 1 +392 117 -1.7736780000000001 +393 117 0.40754220000000002 +181 118 1 +194 118 -1.5893889999999999 +195 118 -1.5818110000000001 +196 118 -1.6231180000000001 +230 118 -3.205686 +231 118 -8.4470029999999998e-05 +365 118 -0.87155309999999997 +384 118 -1 +387 118 1 +392 118 4.4676090000000004 +393 118 2.2475290000000001 +93 119 -1 +96 119 -1 +248 119 -0.40421560000000001 +262 119 -0.1818777 +284 119 -0.1563455 +306 119 -0.15456990000000001 +328 119 -0.1521778 +350 119 -0.091905799999999996 +372 119 -0.0078705370000000004 +94 120 -1 +97 120 -1 +248 120 -1.8091710000000001 +262 120 -3.1896550000000001 +284 120 -3.3490190000000002 +306 120 -3.358644 +328 120 -3.3085849999999999 +350 120 -1.96787 +372 120 -0.11333559999999999 +95 121 -1 +98 121 -1 +248 121 -2.4566020000000002 +262 121 -4.1011280000000001 +284 121 -4.2908920000000004 +306 121 -4.3026030000000004 +328 121 -4.2541469999999997 +350 121 -2.9523890000000002 +372 121 -1.157365 +93 122 -0.0081214960000000006 +96 122 -0.016896609999999999 +248 122 -0.0045387600000000002 +262 122 -0.00217052 +284 122 -0.0018740689999999999 +306 122 -0.0018533180000000001 +328 122 -0.0018248369999999999 +350 122 -0.001106561 +372 122 -0.0001054494 +94 123 -0.016749989999999999 +97 123 -0.034848030000000002 +248 123 -0.041896919999999997 +262 123 -0.078506679999999995 +284 123 -0.082793510000000001 +306 123 -0.083055320000000002 +328 123 -0.081826380000000004 +350 123 -0.048866050000000001 +372 123 -0.0031317319999999999 +95 124 -0.028878029999999999 +98 124 -0.060080179999999997 +248 124 -0.098082240000000001 +262 124 -0.17402809999999999 +284 124 -0.18288550000000001 +306 124 -0.1834374 +328 124 -0.18139140000000001 +350 124 -0.12639719999999999 +372 124 -0.055136770000000002 +105 125 -1 +108 125 -1 +264 125 -0.76362319999999995 +286 125 -0.5413211 +308 125 -0.52907530000000003 +330 125 -0.52832599999999996 +352 125 -0.52965340000000005 +374 125 -0.59901059999999995 +392 125 -0.57467679999999999 +106 126 -1 +109 126 -1 +264 126 -1.4679789999999999 +286 126 -1.289806 +308 126 -1.279992 +330 126 -1.279385 +352 126 -1.2801739999999999 +374 126 -1.3601430000000001 +392 126 -0.71491899999999997 +107 127 -1 +110 127 -1 +264 127 -0.0043708569999999997 +286 127 -0.0039541009999999998 +308 127 -0.0039318030000000002 +330 127 -0.0039476679999999997 +352 127 -0.0047490229999999998 +374 127 -0.072455389999999995 +392 127 -1.6023639999999999 +105 128 -0.1122933 +108 128 -0.067276619999999995 +264 128 -0.054601370000000003 +286 128 -0.038877219999999997 +308 128 -0.03800866 +330 128 -0.037958989999999998 +352 128 -0.038208859999999997 +374 128 -0.048085490000000002 +392 128 -0.05817862 +106 129 -0.2620633 +109 129 -0.15700610000000001 +264 129 -0.24496080000000001 +286 129 -0.2161806 +308 129 -0.21459739999999999 +330 129 -0.21451909999999999 +352 129 -0.21552299999999999 +374 129 -0.25480999999999998 +392 129 -0.16890749999999999 +107 130 -0.1626995 +110 130 -0.097475699999999998 +264 130 -0.00045281759999999999 +286 130 -0.00041145290000000001 +308 130 -0.00040925029999999999 +330 130 -0.0004109467 +352 130 -0.00049637369999999995 +374 130 -0.0084271850000000002 +392 130 -0.2350352 +117 131 -1 +120 131 -1 +249 131 -0.069702840000000002 +263 131 -0.019243320000000001 +285 131 -0.01583793 +307 131 -0.01561791 +329 131 -0.01558321 +351 131 -0.01471856 +373 131 -0.0057599519999999996 +118 132 -1 +121 132 -1 +249 132 -0.74171359999999997 +263 132 -0.80234939999999999 +285 132 -0.80658470000000004 +307 132 -0.80682860000000001 +329 132 -0.80550310000000003 +351 132 -0.74926979999999999 +373 132 -0.19719700000000001 +119 133 -1 +122 133 -1 +249 133 -0.51275979999999999 +263 133 -0.52522530000000001 +285 133 -0.52614130000000003 +307 133 -0.52622449999999998 +329 133 -0.52730270000000001 +351 133 -0.57231860000000001 +373 133 -1.025242 +117 134 -0.46575929999999999 +120 134 -0.96900310000000001 +249 134 -0.044884880000000002 +263 134 -0.01317012 +285 134 -0.01088739 +307 134 -0.010739240000000001 +329 134 -0.01071655 +351 134 -0.01016303 +373 134 -0.0044257189999999998 +118 135 -0.57440230000000003 +121 135 -1.195033 +249 135 -0.58903419999999995 +263 135 -0.67721739999999997 +285 135 -0.68380180000000002 +307 135 -0.68420530000000002 +329 135 -0.68315610000000004 +351 135 -0.63804399999999994 +373 135 -0.18686159999999999 +119 136 -0.2292285 +122 136 -0.47690549999999998 +249 136 -0.1625065 +263 136 -0.17691419999999999 +285 136 -0.1780062 +307 136 -0.17808560000000001 +329 136 -0.17846999999999999 +351 136 -0.19449250000000001 +373 136 -0.38770260000000001 +129 137 -1 +132 137 -1 +265 137 -0.34272789999999997 +287 137 -0.2911376 +309 137 -0.2876937 +331 137 -0.28748889999999999 +353 137 -0.28823179999999998 +375 137 -0.30269869999999999 +393 137 -0.17507890000000001 +130 138 -1 +133 138 -1 +265 138 -1.0623339999999999 +287 138 -1.118506 +309 138 -1.1222529999999999 +331 138 -1.122512 +353 138 -1.1232850000000001 +375 138 -1.1082339999999999 +393 138 -0.35118640000000001 +131 139 -1 +134 139 -1 +265 139 -0.0023999820000000002 +287 139 -0.00260173 +309 139 -0.0026156270000000001 +331 139 -0.0026280330000000001 +353 139 -0.0031617350000000002 +375 139 -0.044793810000000003 +393 139 -0.59723090000000001 +129 140 -2.0182530000000001 +132 140 -1.209166 +265 140 -0.44044889999999998 +287 140 -0.3758029 +309 140 -0.37146430000000003 +331 140 -0.37124049999999997 +353 140 -0.37371090000000001 +375 140 -0.43672879999999997 +393 140 -0.31856279999999998 +130 141 -2.5626880000000001 +133 141 -1.535345 +265 141 -1.7335130000000001 +287 141 -1.833245 +309 141 -1.839915 +331 141 -1.840541 +353 141 -1.849286 +375 141 -2.0302660000000001 +393 141 -0.81137049999999999 +131 142 -0.92554289999999995 +134 142 -0.55450670000000002 +265 142 -0.0014144089999999999 +287 142 -0.001540086 +309 142 -0.0015487579999999999 +331 142 -0.0015562740000000001 +353 142 -0.001879925 +375 142 -0.029637400000000001 +393 142 -0.49833870000000002 +135 143 -1.4338919999999999 +141 143 -2.1577039999999998 +266 143 -1.523971 +288 143 -1.530708 +310 143 -1.531148 +332 143 -1.5313159999999999 +354 143 -1.537533 +376 143 -1.710928 +136 144 -0.94320599999999999 +142 144 -1.4193260000000001 +267 144 -1.0024599999999999 +289 144 -1.006891 +311 144 -1.0071810000000001 +333 144 -1.0072909999999999 +355 144 -1.0113810000000001 +377 144 -1.1254390000000001 +137 145 -0.59645269999999995 +143 145 -0.89753530000000004 +268 145 -0.63392269999999995 +290 145 -0.63672519999999999 +312 145 -0.63690829999999998 +334 145 -0.63697809999999999 +356 145 -0.63956420000000003 +378 145 -0.71169090000000002 +135 146 -1 +141 146 -1 +266 146 -1 +288 146 -1 +310 146 -1 +332 146 -1 +354 146 -1 +376 146 -1 +136 147 -1 +142 147 -1 +267 147 -1 +289 147 -1 +311 147 -1 +333 147 -1 +355 147 -1 +377 147 -1 +137 148 -1 +143 148 -1 +268 148 -1 +290 148 -1 +312 148 -1 +334 148 -1 +356 148 -1 +378 148 -1 +138 149 -1 +148 149 1 +238 149 0.55083519999999997 +139 150 -1 +149 150 1.6474949999999999 +239 150 0.73959730000000001 +140 151 -1 +150 151 841.35159999999996 +240 151 0.2040448 +144 152 -1 +182 152 1 +382 152 0.1956447 +145 153 -1 +183 153 1 +383 153 0.49830160000000001 +146 154 -1 +184 154 3.1156220000000001 +384 154 0.95354779999999995 +395 155 66.224919999999997 +401 155 -1 +404 155 -3.3282569999999997e-05 +396 156 115.06229999999999 +402 156 -1 +405 156 -4.122831e-05 +397 157 237.33869999999999 +403 157 -1 +406 157 -8.4706899999999994e-05 +398 158 133.245 +401 158 2.5 +404 158 3.3282569999999997e-05 +399 159 232.26390000000001 +402 159 2.5 +405 159 4.122831e-05 +400 160 480.18209999999999 +403 160 2.5 +406 160 8.4706899999999994e-05 +160 161 -0.47337899999999999 +401 161 1 +410 161 -0.2116876 +161 162 -0.57343169999999999 +402 162 1 +410 162 -0.31667149999999999 +162 163 -0.00060925110000000003 +403 163 1 +410 163 -3.511874e-07 +163 164 -4575.0039999999999 +404 164 1.0075620000000001 +411 164 -0.55083519999999997 +164 165 -3681.4160000000002 +405 165 1.004324 +411 165 -0.4489223 +165 166 -1787.818 +406 166 1.002087 +411 166 -0.0002425203 +160 167 -0.52605639999999998 +161 167 -0.42598229999999998 +407 167 1 +410 167 -0.47048839999999997 +160 168 -0.00056459870000000005 +162 168 -0.4380098 +408 168 1 +410 168 -0.00050495930000000002 +161 169 -0.00058596669999999996 +162 169 -0.56138089999999996 +409 169 1 +410 169 -0.00064718760000000001 +163 170 -1 +164 170 -1 +165 170 -1 +410 170 1 +412 170 -1 +423 170 0.061444209999999999 +435 170 0.0204814 +157 171 -1 +163 171 4124.0600000000004 +164 171 4124.0600000000004 +165 171 4124.0600000000004 +411 171 1 +413 171 -316220 +416 171 -20034.240000000002 +417 171 -1 +423 171 -2625.6570000000002 +434 171 222.12899999999999 +412 172 18.737269999999999 +414 172 0.94488159999999999 +413 173 1494.367 +414 173 -1.02078 +158 174 -0.99186010000000002 +163 174 -17.922339999999998 +164 174 -17.922339999999998 +165 174 -17.922339999999998 +414 174 0.86282899999999996 +415 174 1.0497190000000001 +423 174 -0.73414950000000001 +157 175 0.0081398600000000005 +415 175 -222.12899999999999 +417 175 0.0081398600000000005 +433 175 -222.12899999999999 +434 175 -1.8080989999999999 +163 176 -1.0913280000000001 +164 176 -1.629397 +165 176 -1.4448529999999999 +416 176 1 +423 176 0.047364059999999999 +435 176 -0.027898139999999998 +417 177 0.0045385340000000003 +423 177 7.5792400000000004 +435 177 2.5264129999999998 +148 178 -1 +178 178 -1 +149 179 -1 +179 179 -1 +150 180 -1 +180 180 -1 +148 181 1.0266459999999999 +166 181 -1 +149 182 1.0737239999999999 +167 182 -1 +150 183 1.2081470000000001 +168 183 -1 +148 184 -1 +154 184 -1 +149 185 -1 +155 185 -1 +150 186 -1 +156 186 -1 +215 187 99.149730000000005 +221 187 -1 +224 187 -3.311398e-05 +216 188 172.6396 +222 188 -1 +225 188 -4.1108120000000002e-05 +217 189 356.63979999999998 +223 189 -1 +226 189 -8.4587179999999994e-05 +218 190 200.0008 +221 190 2.5 +224 190 3.311398e-05 +219 191 349.00330000000002 +222 191 2.5 +225 191 4.1108120000000002e-05 +220 192 722.06780000000003 +223 192 2.5 +226 192 8.4587179999999994e-05 +194 193 -0.1148388 +221 193 1 +230 193 -0.011645920000000001 +195 194 -0.41678389999999998 +222 194 1 +230 194 -0.17006160000000001 +196 195 -0.49676140000000002 +223 195 1 +230 195 -0.2436893 +197 196 -5276.8620000000001 +224 196 1.0050250000000001 +231 196 -0.1956447 +198 197 -4241.5910000000003 +225 197 1.002874 +231 197 -0.49830160000000001 +199 198 -2058.2939999999999 +226 198 1.001387 +231 198 -0.30605369999999998 +194 199 -0.39872279999999999 +195 199 -0.099097089999999999 +227 199 1 +230 199 -0.080869759999999999 +194 200 -0.48643839999999999 +196 200 -0.1005598 +228 200 1 +230 200 -0.098660410000000004 +195 201 -0.48411900000000002 +196 201 -0.4026788 +229 201 1 +230 201 -0.39507300000000001 +197 202 -1 +198 202 -1 +199 202 -1 +230 202 1 +232 202 -1 +191 203 -1 +197 203 3297.623 +198 203 3297.623 +199 203 3297.623 +231 203 1 +233 203 -316220 +236 203 -18966.66 +237 203 -1 +232 204 22.66987 +234 204 0.95486020000000005 +233 205 2248.7060000000001 +234 205 -1.0206550000000001 +192 206 -0.99229509999999999 +197 206 -21.898569999999999 +198 206 -21.898569999999999 +199 206 -21.898569999999999 +234 206 0.89000959999999996 +235 206 1.0392049999999999 +191 207 0.0077048969999999996 +235 207 -146.1362 +237 207 0.0077048969999999996 +197 208 -0.65890519999999997 +198 208 -1.1064970000000001 +199 208 -1.000909 +236 208 1 +237 209 0.0068956570000000003 +182 210 -1 +212 210 -1 +183 211 -1 +213 211 -1 +184 212 -1 +214 212 -1 +182 213 1 +200 213 -1 +183 214 1.0226759999999999 +201 214 -1 +184 215 1.091418 +202 215 -1 +182 216 -1 +188 216 -1 +183 217 -1 +189 217 -1 +184 218 -1 +190 218 -1 +241 219 -0.19969609999999999 +242 219 -0.78596160000000004 +243 219 -0.00064128229999999996 +244 219 0.40690409999999999 +253 219 0.20247019999999999 +254 219 0.79687960000000002 +255 219 0.00065019060000000002 +256 219 -2.166544 +257 220 -1 +264 220 -0.30001499999999998 +265 220 -0.40746149999999998 +246 221 -1 +247 221 -1 +258 221 1 +244 222 0.40690409999999999 +256 222 -2.166544 +264 222 1 +265 223 1 +241 224 -0.98629889999999998 +250 224 -1 +253 224 1 +261 224 1 +264 224 3.5018579999999999 +265 224 1.241884 +242 225 -0.98629889999999998 +251 225 -1 +254 225 1 +261 225 1 +264 225 -2.149559 +265 225 0.93602390000000002 +243 226 -0.98629889999999998 +252 226 -1 +255 226 1 +261 226 1 +264 226 6.0259859999999996 +265 226 4.0868380000000002 +253 227 0.0119553 +254 227 0.61475029999999997 +255 227 0.1605955 +256 227 0.59918099999999996 +275 227 -0.011949680000000001 +276 227 -0.61446120000000004 +277 227 -0.16052 +278 227 -1 +257 228 1 +262 228 -0.093350859999999994 +263 228 -0.34681810000000002 +266 228 -1 +267 228 -1 +268 228 -1 +259 229 1 +256 230 -0.59918099999999996 +262 230 1 +278 230 1 +263 231 1 +250 232 13.33342 +253 232 0.78730109999999998 +260 232 1 +262 232 12.12026 +263 232 0.77025089999999996 +275 232 -0.78693089999999999 +251 233 1.020551 +254 233 0.78730109999999998 +260 233 1 +262 233 -3.9843989999999998 +263 233 0.681342 +276 233 -0.78693089999999999 +252 234 0.0031874849999999999 +255 234 0.78730109999999998 +260 234 1 +262 234 19.25216 +263 234 2.236907 +277 234 -0.78693089999999999 +253 235 -0.17008129999999999 +254 235 -0.82969219999999999 +255 235 -0.00069701409999999996 +256 235 2.5673629999999998 +275 235 0.1700014 +276 235 0.82930199999999998 +277 235 0.00069668629999999996 +278 235 -4.2847869999999997 +279 236 -1 +286 236 -0.25546930000000001 +287 236 -0.41224569999999999 +258 237 -1 +259 237 -1 +280 237 1 +256 238 2.5673629999999998 +278 238 -4.2847869999999997 +286 238 1 +287 239 1 +253 240 -1.0004710000000001 +272 240 -1 +275 240 1 +283 240 1 +286 240 2.9555289999999999 +287 240 1.2544139999999999 +254 241 -1.0004710000000001 +273 241 -1 +276 241 1 +283 241 1 +286 241 -1.8159689999999999 +287 241 0.94521189999999999 +255 242 -1.0004710000000001 +274 242 -1 +277 242 1 +283 242 1 +286 242 5.0849970000000004 +287 242 4.1364789999999996 +250 243 0.20247019999999999 +269 243 -1 +251 244 0.79687960000000002 +270 244 -1 +252 245 0.20398230000000001 +271 245 -1 +275 246 0.0098180809999999993 +276 246 0.61664169999999996 +278 246 0.95579440000000004 +297 246 -0.0098175689999999999 +298 246 -0.61660959999999998 +299 246 -0.16051480000000001 +300 246 -1 +279 247 1 +284 247 -0.098217899999999997 +285 247 -0.34856389999999998 +288 247 -1 +289 247 -1 +290 247 -1 +281 248 1 +278 249 -0.95579440000000004 +284 249 1 +300 249 1 +285 250 1 +272 251 13.626709999999999 +275 251 0.78698299999999999 +282 251 1 +284 251 12.68233 +285 251 0.76942869999999997 +297 251 -0.78694200000000003 +273 252 1.058389 +276 252 0.78698299999999999 +282 252 1 +284 252 -4.1684890000000001 +285 252 0.68102850000000004 +298 252 -0.78694200000000003 +274 253 0.0034155829999999998 +277 253 0.78698299999999999 +282 253 1 +284 253 20.139959999999999 +285 253 2.2394150000000002 +299 253 -0.78694200000000003 +275 254 -0.16786980000000001 +276 254 -0.83148250000000001 +277 254 -0.00069990470000000002 +278 254 4.3289929999999996 +297 254 0.16786100000000001 +298 254 0.83143909999999999 +299 254 0.00069986820000000004 +300 254 -4.5292089999999998 +301 255 -1 +308 255 -0.2530153 +309 255 -0.4125625 +280 256 -1 +281 256 -1 +302 256 1 +278 257 4.3289929999999996 +300 257 -4.5292089999999998 +308 257 1 +309 258 1 +275 259 -1.0000519999999999 +294 259 -1 +297 259 1 +305 259 1 +308 259 2.9254359999999999 +309 259 1.2552490000000001 +276 260 -1.0000519999999999 +295 260 -1 +298 260 1 +305 260 1 +308 260 -1.797593 +309 260 0.94582429999999995 +277 261 -1.0000519999999999 +296 261 -1 +299 261 1 +305 261 1 +308 261 5.0331659999999996 +309 261 4.1397830000000004 +272 262 0.1700014 +291 262 -1 +273 263 0.82930199999999998 +292 263 -1 +274 264 0.20397290000000001 +293 264 -1 +297 265 0.0096798500000000003 +298 265 0.61671089999999995 +299 265 0.1605181 +300 265 0.99729840000000003 +319 265 -0.0096801700000000001 +320 265 -0.61673129999999998 +321 265 -0.16052340000000001 +322 265 -1 +301 266 1 +306 266 -0.09852872 +307 266 -0.34867100000000001 +310 266 -1 +311 266 -1 +312 266 -1 +303 267 1 +300 268 -0.99729840000000003 +306 268 1 +322 268 1 +307 269 1 +294 270 13.64601 +297 270 0.78690890000000002 +304 270 1 +306 270 12.716189999999999 +307 270 0.7693586 +319 270 -0.78693489999999999 +295 271 1.060897 +298 271 0.78690890000000002 +304 271 1 +306 271 -4.1795749999999998 +307 271 0.68099359999999998 +320 271 -0.78693489999999999 +296 272 0.003430968 +299 272 0.78690890000000002 +304 272 1 +306 272 20.19341 +307 272 2.2395320000000001 +321 272 -0.78693489999999999 +297 273 -0.16772329999999999 +298 273 -0.83154050000000002 +299 273 -0.00070311129999999996 +300 273 4.531911 +319 273 0.16772880000000001 +320 273 0.83156799999999997 +321 273 0.0007031346 +322 273 -4.5441880000000001 +323 274 -1 +330 274 -0.25288909999999998 +331 274 -0.41262900000000002 +302 275 -1 +303 275 -1 +324 275 1 +300 276 4.531911 +322 276 -4.5441880000000001 +330 276 1 +331 277 1 +297 278 -0.99996689999999999 +316 278 -1 +319 278 1 +327 278 1 +330 278 2.9235699999999998 +331 278 1.2552939999999999 +298 279 -0.99996689999999999 +317 279 -1 +320 279 1 +327 279 1 +330 279 -1.7964899999999999 +331 279 0.94585160000000001 +299 280 -0.99996689999999999 +318 280 -1 +321 280 1 +327 280 1 +330 280 5.029935 +331 280 4.1401399999999997 +294 281 0.16786100000000001 +313 281 -1 +295 282 0.83143909999999999 +314 282 -1 +296 283 0.20398559999999999 +315 283 -1 +319 284 0.0096473500000000007 +320 284 0.61499680000000001 +321 284 0.1606638 +322 284 1.012275 +341 284 -0.0096630710000000005 +342 284 -0.61599899999999996 +343 284 -0.1609257 +344 284 -1 +323 285 1 +328 285 -0.097740149999999998 +329 285 -0.348389 +332 285 -1 +333 285 -1 +334 285 -1 +325 286 1 +322 287 -1.012275 +328 287 1 +344 287 1 +329 288 1 +316 289 13.653370000000001 +319 289 0.78530800000000001 +326 289 1 +328 289 12.53604 +329 289 0.76861380000000001 +341 289 -0.7865877 +317 290 1.0618540000000001 +320 290 0.78530800000000001 +326 290 1 +328 290 -4.1203450000000004 +329 290 0.68034459999999997 +342 290 -0.7865877 +318 291 0.0034368480000000002 +321 291 0.78530800000000001 +326 291 1 +328 291 19.9072 +329 291 2.2374860000000001 +343 291 -0.7865877 +319 292 -0.16769600000000001 +320 292 -0.8298335 +321 292 -0.00084358209999999998 +322 292 4.5319130000000003 +341 292 0.16796929999999999 +342 292 0.83118579999999997 +343 292 0.00084495670000000003 +344 292 -4.4769569999999996 +345 293 -1 +352 293 -0.25422820000000002 +353 293 -0.41467850000000001 +324 294 -1 +325 294 -1 +346 294 1 +322 295 4.5319120000000002 +344 295 -4.4769569999999996 +352 295 1 +353 296 1 +319 297 -0.99837310000000001 +338 297 -1 +341 297 1 +349 297 1 +352 297 2.9258000000000002 +353 297 1.2548710000000001 +320 298 -0.99837310000000001 +339 298 -1 +342 298 1 +349 298 1 +352 298 -1.799474 +353 298 0.94529589999999997 +321 299 -0.99837310000000001 +340 299 -1 +343 299 1 +349 299 1 +352 299 5.032978 +353 299 4.1465319999999997 +316 300 0.16772880000000001 +335 300 -1 +317 301 0.83156799999999997 +336 301 -1 +318 302 0.20458699999999999 +337 302 -1 +341 303 0.0089580030000000008 +342 303 0.56239150000000004 +343 303 0.17143159999999999 +344 303 1.5349870000000001 +363 303 -0.0093684010000000002 +364 303 -0.58815669999999998 +365 303 -0.17928549999999999 +366 303 -1 +345 304 1 +350 304 -0.076424569999999997 +351 304 -0.33630700000000002 +354 304 -1 +355 304 -1 +356 304 -1 +347 305 1 +344 306 -1.5349870000000001 +350 306 1 +366 306 1 +351 307 1 +338 308 13.9277 +341 308 0.74278120000000003 +348 308 1 +350 308 7.7124139999999999 +351 308 0.73754050000000004 +363 308 -0.77681060000000002 +339 309 1.0977920000000001 +342 309 0.74278120000000003 +348 309 1 +350 309 -2.5345339999999998 +351 309 0.65320800000000001 +364 309 -0.77681060000000002 +340 310 0.00366104 +343 310 0.74278120000000003 +348 310 1 +350 310 12.244490000000001 +351 310 2.151386 +365 310 -0.77681060000000002 +341 311 -0.1672642 +342 311 -0.77757829999999994 +343 311 -0.01135093 +344 311 3.9419710000000001 +363 311 0.1749272 +364 311 0.81320190000000003 +365 311 0.01187095 +366 311 -2.568082 +367 312 -1 +374 312 -0.31132270000000001 +375 312 -0.45572679999999999 +346 313 -1 +347 313 -1 +368 313 1 +344 314 3.9419710000000001 +366 314 -2.568082 +374 314 1 +375 315 1 +341 316 -0.95619350000000003 +360 316 -1 +363 316 1 +371 316 1 +374 316 3.149454 +375 316 1.212998 +342 317 -0.95619350000000003 +361 317 -1 +364 317 1 +371 317 1 +374 317 -1.985919 +375 317 0.9070684 +343 318 -0.95619350000000003 +362 318 -1 +365 318 1 +371 318 1 +374 318 5.3936869999999999 +375 318 4.2274630000000002 +338 319 0.16796929999999999 +357 319 -1 +339 320 0.83118579999999997 +358 320 -1 +340 321 0.2307969 +359 321 -1 +363 322 0.0049560029999999996 +364 322 0.2092511 +365 322 0.4341566 +366 322 6.177384 +385 322 -0.0056864039999999999 +386 322 -0.24008989999999999 +387 322 -0.49814130000000001 +388 322 -1 +367 323 1 +372 323 -0.051899590000000002 +373 323 -0.22819929999999999 +376 323 -1 +377 323 -1 +378 323 -1 +369 324 1 +366 325 -6.177384 +372 325 1 +388 325 1 +373 326 1 +360 327 22.88466 +363 327 0.64836369999999999 +370 327 1 +372 327 1.04345 +373 327 0.42175859999999998 +385 327 -0.74391759999999996 +361 328 2.5197029999999998 +364 328 0.64836369999999999 +370 328 1 +372 328 -0.3414664 +373 328 0.3798898 +386 328 -0.74391759999999996 +362 329 0.017727920000000001 +365 329 0.64836369999999999 +370 329 1 +372 329 1.6460520000000001 +373 329 1.3054760000000001 +387 329 -0.74391759999999996 +360 330 0.1749272 +379 330 -1 +361 331 0.81320190000000003 +380 331 -1 +362 332 0.66961899999999996 +381 332 -1 +87 333 6.3180579999999997 +93 333 1.008121 +88 334 2.1016520000000001 +94 334 0.98324999999999996 +89 335 10.216340000000001 +95 335 0.97112200000000004 +90 336 4.7715329999999998 +96 336 1.0168969999999999 +91 337 1.5445530000000001 +97 337 0.96515200000000001 +92 338 7.4032580000000001 +98 338 0.93991979999999997 +99 339 276.76479999999998 +105 339 0.88770669999999996 +100 340 192.19040000000001 +106 340 1.2620629999999999 +101 341 465.29739999999998 +107 341 0.8373005 +102 342 402.63529999999997 +108 342 0.93272339999999998 +103 343 243.95160000000001 +109 343 1.157006 +104 344 694.42570000000001 +110 344 0.90252429999999995 +111 345 2.1471689999999999 +117 345 0.73310410000000004 +112 346 1.830354 +118 346 0.77070689999999997 +113 347 5.4194959999999996 +119 347 0.91067969999999998 +114 348 1.5934600000000001 +120 348 0.44472830000000002 +115 349 1.5193589999999999 +121 349 0.52296010000000004 +116 350 5.9272710000000002 +122 350 0.81417070000000002 +123 351 8.6013230000000007 +129 351 0.58171510000000004 +124 352 6.1974850000000004 +130 352 0.53220719999999999 +125 353 37.67033 +131 353 1.1683300000000001 +126 354 10.955349999999999 +132 354 0.74939929999999999 +127 355 8.2864269999999998 +133 355 0.71973830000000005 +128 356 35.092930000000003 +134 356 1.100849 +135 357 0.4338919 +138 357 2.2797130000000001 +136 358 0.1137572 +139 358 0.60698209999999997 +137 359 0.4035473 +140 359 0.0080049890000000005 +141 360 1.1577040000000001 +144 360 4.0422279999999997 +142 361 0.41932589999999997 +145 361 2.449611 +143 362 0.10246470000000001 +146 362 0.36475180000000001 +151 363 172.5745 +154 363 14.91761 +152 364 161.58449999999999 +155 364 12.0938 +153 365 145.31450000000001 +156 365 5.7400960000000003 +157 366 0.0045018890000000002 +158 366 0.95263589999999998 +159 366 -1 +158 367 0.94488159999999999 +163 367 19.882059999999999 +164 367 15.998699999999999 +165 367 7.7694989999999997 +159 368 1.00814 +163 368 98.828980000000001 +164 368 147.5558 +165 368 130.84370000000001 +160 369 1 +163 369 1.8011980000000001 +161 370 1 +164 370 2.196221 +162 371 1 +165 371 2.0607380000000002 +163 372 19.882059999999999 +166 372 0.9740453 +164 373 15.998699999999999 +167 373 0.93133779999999999 +165 374 7.7694989999999997 +168 374 0.82771399999999995 +169 375 -1 +172 375 -1 +175 375 0.056357909999999997 +176 375 0.056357909999999997 +177 375 0.056357909999999997 +170 376 -1 +173 376 -1 +175 376 0.73959730000000001 +176 376 0.73959730000000001 +177 376 0.73959730000000001 +171 377 -1 +174 377 -1 +175 377 0.2040448 +176 377 0.2040448 +177 377 0.2040448 +172 378 1 +175 378 -1 +173 379 1 +176 379 -1 +174 380 1 +177 380 -1 +175 381 1 +178 381 1 +176 382 1 +179 382 1 +177 383 1 +180 383 1 +102 384 -19.453890000000001 +418 384 1 +424 384 -0.09530421 +103 385 -22.090309999999999 +419 385 1 +424 385 -0.088197620000000004 +104 386 -49.563589999999998 +420 386 1 +424 386 -0.00010690420000000001 +421 387 179.7345 +422 387 -2.5957400000000002 +422 388 1 +423 388 -0.09621652 +102 389 -1 +103 389 -1 +104 389 -1 +423 389 0.09621652 +424 389 -0.0088937280000000001 +126 390 0.93082790000000004 +127 390 0.93082790000000004 +128 390 0.93082790000000004 +425 390 -1.138352 +436 390 0.095341780000000001 +126 391 0.81769789999999998 +426 391 -0.55083519999999997 +436 391 0.04613478 +127 392 0.81769789999999998 +427 392 -0.4489223 +436 392 0.037599149999999998 +128 393 6.8068650000000002 +428 393 -0.0020188419999999999 +436 393 0.0001690866 +429 394 -0.60313589999999995 +430 394 -1.1914260000000001 +431 394 -0.2090101 +432 394 -0.2323664 +126 395 -1.5881989999999999 +430 395 1 +436 395 -0.089606729999999996 +127 396 -1.7894779999999999 +431 396 1 +436 396 -0.082283250000000002 +128 397 -4.012804 +432 397 1 +436 397 -9.9680419999999997e-05 +433 398 1.186874 +435 398 -0.87134319999999998 +434 399 0.99186010000000002 +435 399 -0.73414950000000001 +126 400 -1 +127 400 -1 +128 400 -1 +435 400 0.89782490000000004 +436 400 -0.1024269 +185 401 263.30250000000001 +188 401 16.710229999999999 +186 402 252.3125 +189 402 15.091379999999999 +187 403 236.04249999999999 +190 403 11.440289999999999 +191 404 0.0068429329999999998 +192 404 0.96227439999999997 +193 404 -1 +192 405 0.95486020000000005 +197 405 35.042119999999997 +198 405 28.167190000000002 +199 405 13.66854 +193 406 1.0077050000000001 +197 406 85.846760000000003 +198 406 144.16210000000001 +199 406 130.40539999999999 +194 407 1 +197 407 1.6589050000000001 +195 408 1 +198 408 2.1064970000000001 +196 409 1 +199 409 2.000909 +197 410 35.042119999999997 +200 410 1 +198 411 28.167190000000002 +201 411 0.97782690000000005 +199 412 13.66854 +202 412 0.91623940000000004 +203 413 -1 +206 413 -1 +209 413 0.0034351899999999999 +210 413 0.0034351899999999999 +211 413 0.0034351899999999999 +204 414 -1 +207 414 -1 +209 414 0.043016970000000002 +210 414 0.043016970000000002 +211 414 0.043016970000000002 +205 415 -1 +208 415 -1 +209 415 0.95354779999999995 +210 415 0.95354779999999995 +211 415 0.95354779999999995 +206 416 1 +209 416 -1 +207 417 1 +210 417 -1 +208 418 1 +211 418 -1 +209 419 1 +212 419 1 +210 420 1 +213 420 1 +211 421 1 +214 421 1 +90 422 -0.047613129999999997 +461 422 1 +467 422 -2.3334699999999999e-05 +91 423 -0.057464349999999997 +462 423 1 +467 423 -0.00035266559999999999 +92 424 -0.12956039999999999 +463 424 1 +467 424 -0.017625419999999999 +464 425 270.46249999999998 +465 425 -2.8000669999999999 +465 426 1 +466 426 -1.6856930000000001 +90 427 -1 +91 427 -1 +92 427 -1 +466 427 1.6856930000000001 +467 427 -0.1426674 +114 428 0.12149740000000001 +115 428 0.12149740000000001 +116 428 0.12149740000000001 +468 428 -1.138352 +479 428 0.021230519999999999 +114 429 0.60555749999999997 +469 429 -0.019490179999999999 +479 429 0.00036349629999999998 +115 430 0.3357927 +470 430 -0.13533829999999999 +479 430 0.0025240900000000001 +116 431 0.1067309 +471 431 -0.95354779999999995 +479 431 0.017783879999999998 +472 432 -0.90759219999999996 +473 432 -5.7118219999999997 +474 432 -0.93568410000000002 +475 432 -1.0346550000000001 +114 433 -0.043240929999999997 +473 433 1 +479 433 -2.5956110000000001e-05 +115 434 -0.052174909999999998 +474 434 1 +479 434 -0.00039218899999999998 +116 435 -0.1176314 +475 435 1 +479 435 -0.019600159999999998 +476 436 5.3140780000000003 +478 436 -1.002184 +477 437 0.34483720000000001 +478 437 -0.26478620000000003 +114 438 -1 +115 438 -1 +116 438 -1 +478 438 1.7669710000000001 +479 438 -0.1747406 +438 439 99.149730000000005 +444 439 -1 +447 439 -3.311398e-05 +439 440 172.6396 +445 440 -1 +448 440 -4.1108120000000002e-05 +440 441 356.63979999999998 +446 441 -1 +449 441 -8.4587179999999994e-05 +441 442 200.0008 +444 442 2.5 +447 442 3.311398e-05 +442 443 349.00330000000002 +445 443 2.5 +448 443 4.1108120000000002e-05 +443 444 722.06780000000003 +446 444 2.5 +449 444 8.4587179999999994e-05 +444 445 1 +453 445 -1.4485650000000001e-06 +445 446 1 +453 446 -0.0005113292 +446 447 1 +453 447 -0.95438869999999998 +447 448 1.0050250000000001 +454 448 -0.0034351899999999999 +448 449 1.002874 +454 449 -0.043016970000000002 +449 450 1.001387 +454 450 -0.95354779999999995 +450 451 1 +453 451 -4.9455600000000001e-05 +451 452 1 +453 452 -0.0021775570000000001 +452 453 1 +453 453 -0.042871529999999998 +453 454 1 +455 454 -1 +466 454 1.5 +478 454 0.5 +454 455 1 +456 455 -316220 +459 455 -12132.58 +460 455 -1 +466 455 -20451.810000000001 +477 455 9152.7510000000002 +455 456 9.1463570000000001 +457 456 0.0037734919999999998 +456 457 2248.7060000000001 +457 457 -0.12505330000000001 +457 458 0.067588380000000003 +458 458 65.087119999999999 +466 458 -0.18859039999999999 +458 459 -9152.7510000000002 +460 459 0.75439429999999996 +476 459 -9152.7510000000002 +477 459 -6904.7830000000004 +459 460 1 +466 460 0.18569289999999999 +478 460 -0.5 +460 461 0.00019167939999999999 +466 461 2.6684519999999998 +478 461 0.88948400000000005 +266 462 0.52397099999999996 +269 462 2.5902729999999998 +267 463 0.1209036 +270 463 1 +268 464 0.36607729999999999 +271 464 0.018323329999999999 +288 465 0.53070830000000002 +291 465 2.6120320000000001 +289 466 0.12143809999999999 +292 466 1 +290 467 0.36327480000000001 +293 467 0.019398479999999999 +310 468 0.53114850000000002 +313 468 2.6134469999999999 +311 469 0.1214731 +314 469 1 +312 470 0.36309170000000002 +315 470 0.01947045 +332 471 0.53131620000000002 +335 471 2.6139860000000001 +333 472 0.12148639999999999 +336 472 1 +334 473 0.36302190000000001 +337 473 0.01949793 +354 474 0.53753340000000005 +357 474 2.63388 +355 475 0.12197959999999999 +358 475 1 +356 476 0.36043579999999997 +359 476 0.020538460000000001 +376 477 0.71092829999999996 +379 477 3.1304669999999999 +377 478 0.13573579999999999 +380 478 1 +378 479 0.28830909999999998 +381 479 0.071489880000000006 + + diff -r dc3ee9616267 -r fa2cdef14442 examples/data/west0479.mtx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/data/west0479.mtx Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1912 @@ +%%MatrixMarket matrix coordinate real general +479 479 1910 +25 1 1.0000000000000e+00 +31 1 -3.7648130000000e-02 +87 1 -3.4423960000000e-01 +26 2 1.0000000000000e+00 +31 2 -2.4522620000000e-02 +88 2 -3.7370860000000e-01 +27 3 1.0000000000000e+00 +31 3 -3.6613040000000e-02 +89 3 -8.3693790000000e-01 +28 4 1.3000000000000e+02 +29 4 -2.4337670000000e+00 +29 5 1.0000000000000e+00 +30 5 -1.6140910000000e+00 +30 6 1.6140910000000e+00 +31 6 -2.1873210000000e-01 +87 6 -1.0000000000000e+00 +88 6 -1.0000000000000e+00 +89 6 -1.0000000000000e+00 +32 7 -1.1383520000000e+00 +43 7 3.6694280000000e-02 +111 7 9.9316360000000e-02 +112 7 9.9316360000000e-02 +113 7 9.9316360000000e-02 +33 8 -5.0000000000000e-01 +43 8 1.6117290000000e-02 +111 8 8.7245760000000e-02 +34 9 -3.6119180000000e-01 +43 9 1.1642860000000e-02 +112 9 1.0504150000000e-01 +35 10 -3.2188760000000e-01 +43 10 1.0375910000000e-02 +113 10 1.4041660000000e-01 +36 11 -4.3624160000000e-01 +37 11 -7.6804250000000e-01 +38 11 -1.4302790000000e-01 +39 11 -1.5938860000000e-01 +37 12 1.0000000000000e+00 +43 12 -4.8560820000000e-02 +111 12 -2.6286840000000e-01 +38 13 1.0000000000000e+00 +43 13 -3.0925950000000e-02 +112 13 -2.7901280000000e-01 +39 14 1.0000000000000e+00 +43 14 -4.6123590000000e-02 +113 14 -6.2418820000000e-01 +40 15 5.2824360000000e+00 +42 15 -6.1239210000000e-01 +41 16 2.8868220000000e-01 +42 16 -2.1638150000000e-01 +42 17 1.3287740000000e+00 +43 17 -3.6946860000000e-01 +111 17 -1.0000000000000e+00 +112 17 -1.0000000000000e+00 +113 17 -1.0000000000000e+00 +2 18 4.8176470000000e+01 +8 18 -1.0000000000000e+00 +11 18 -3.3474840000000e-05 +3 19 8.3500000000000e+01 +9 19 -1.0000000000000e+00 +12 19 -4.1365390000000e-05 +4 20 1.7194120000000e+02 +10 20 -1.0000000000000e+00 +13 20 -8.4843450000000e-05 +5 21 9.6651380000000e+01 +8 21 2.5000000000000e+00 +11 21 3.3474840000000e-05 +6 22 1.6827060000000e+02 +9 22 2.5000000000000e+00 +12 22 4.1365390000000e-05 +7 23 3.4758720000000e+02 +10 23 2.5000000000000e+00 +13 23 8.4843450000000e-05 +8 24 1.0000000000000e+00 +17 24 -1.1069670000000e-01 +27 24 1.6052320000000e+00 +9 25 1.0000000000000e+00 +17 25 -8.9808520000000e-02 +10 26 1.0000000000000e+00 +17 26 -1.5173690000000e-01 +11 27 1.0104550000000e+00 +18 27 -5.0000000000000e-01 +12 28 1.0059780000000e+00 +18 28 -3.0000000000000e-01 +13 29 1.0028850000000e+00 +18 29 -2.0000000000000e-01 +14 30 1.0000000000000e+00 +17 30 -1.8118550000000e-01 +15 31 1.0000000000000e+00 +17 31 -2.4002390000000e-01 +16 32 1.0000000000000e+00 +17 32 -2.2654840000000e-01 +17 33 1.0000000000000e+00 +19 33 -1.0000000000000e+00 +30 33 1.5000000000000e+00 +42 33 5.0000000000000e-01 +18 34 1.0000000000000e+00 +20 34 -3.1622000000000e+05 +23 34 -1.2323690000000e+04 +24 34 -1.0000000000000e+00 +30 34 -3.5226800000000e+04 +41 34 1.8449020000000e+04 +19 35 5.2983390000000e+00 +21 35 2.4526870000000e-03 +20 36 1.0808590000000e+03 +21 36 -2.0502150000000e-01 +21 37 1.4419200000000e-01 +22 37 6.3059860000000e+01 +30 37 -1.1592990000000e-01 +22 38 -1.8449020000000e+04 +24 38 8.4533390000000e-01 +40 38 -1.8449020000000e+04 +41 38 -1.5595580000000e+04 +23 39 1.0000000000000e+00 +30 39 2.0204930000000e-01 +42 39 -8.8547100000000e-01 +24 40 1.0002340000000e-04 +30 40 2.4483390000000e+00 +42 40 8.1611300000000e-01 +68 41 1.0000000000000e+00 +74 41 -2.2786690000000e-04 +99 41 -2.6243950000000e-01 +69 42 1.0000000000000e+00 +74 42 -4.1887630000000e-04 +100 42 -3.2161960000000e-01 +70 43 1.0000000000000e+00 +74 43 -1.5769330000000e-03 +101 43 -7.2647610000000e-01 +71 44 3.0000000000000e+02 +72 44 -2.8518910000000e+00 +72 45 1.0000000000000e+00 +73 45 -2.8701590000000e-01 +73 46 2.8701590000000e-01 +74 46 -4.3413220000000e-03 +99 46 -1.0000000000000e+00 +100 46 -1.0000000000000e+00 +101 46 -1.0000000000000e+00 +75 47 -1.1383520000000e+00 +86 47 4.2002860000000e-02 +123 47 9.4148060000000e-01 +124 47 9.4148060000000e-01 +125 47 9.4148060000000e-01 +76 48 -3.2188760000000e-01 +86 48 1.1877000000000e-02 +123 48 1.3310950000000e+00 +77 49 -3.6119180000000e-01 +86 49 1.3327240000000e-02 +124 49 9.9575290000000e-01 +78 50 -5.0000000000000e-01 +86 50 1.8448980000000e-02 +125 50 8.2705600000000e-01 +79 51 -1.0000000000000e+00 +80 51 -1.9240000000000e+01 +81 51 -3.8030000000000e+00 +82 51 -9.4810000000000e+00 +80 52 1.0000000000000e+00 +86 52 -8.8757840000000e-04 +123 52 -9.9473920000000e-02 +81 53 1.0000000000000e+00 +86 53 -1.3313680000000e-03 +124 53 -9.9473920000000e-02 +82 54 1.0000000000000e+00 +86 54 -2.2189460000000e-03 +125 54 -9.9473920000000e-02 +83 55 1.1776130000000e+00 +85 55 -3.1089630000000e+00 +84 56 9.9194250000000e-01 +85 56 -2.6400560000000e+00 +85 57 3.1921120000000e+00 +86 57 -4.4613630000000e-02 +123 57 -1.0000000000000e+00 +124 57 -1.0000000000000e+00 +125 57 -1.0000000000000e+00 +45 58 1.0986880000000e+02 +51 58 -1.0000000000000e+00 +54 58 -3.3081100000000e-05 +46 59 1.9138460000000e+02 +52 59 -1.0000000000000e+00 +55 59 -4.1084670000000e-05 +47 60 3.9547960000000e+02 +53 60 -1.0000000000000e+00 +56 60 -8.4563830000000e-05 +48 61 2.2173390000000e+02 +51 61 2.5000000000000e+00 +54 61 3.3081100000000e-05 +49 62 3.8700920000000e+02 +52 62 2.5000000000000e+00 +55 62 4.1084670000000e-05 +50 63 8.0081650000000e+02 +53 63 2.5000000000000e+00 +56 63 8.4563830000000e-05 +51 64 1.0000000000000e+00 +60 64 -9.1702290000000e-03 +52 65 1.0000000000000e+00 +60 65 -4.6441100000000e-02 +53 66 1.0000000000000e+00 +60 66 -4.8999190000000e-01 +54 67 1.0045300000000e+00 +61 67 -2.0000000000000e-01 +55 68 1.0025910000000e+00 +61 68 -3.0000000000000e-01 +56 69 1.0012500000000e+00 +61 69 -5.0000000000000e-01 +57 70 1.0000000000000e+00 +60 70 -3.7500530000000e-02 +58 71 1.0000000000000e+00 +60 71 -1.2414300000000e-01 +59 72 1.0000000000000e+00 +60 72 -2.9275320000000e-01 +60 73 1.0000000000000e+00 +62 73 -1.0000000000000e+00 +73 73 1.8537330000000e-01 +85 73 6.1791090000000e-02 +61 74 1.0000000000000e+00 +63 74 -3.1622000000000e+05 +66 74 -1.6364190000000e+04 +67 74 -1.0000000000000e+00 +73 74 -4.6967820000000e+03 +84 74 1.3185400000000e+02 +62 75 2.2129130000000e+01 +64 75 9.5375260000000e-01 +63 76 2.4942900000000e+03 +64 76 -1.0215870000000e+00 +64 77 8.8782810000000e-01 +65 77 1.0400420000000e+00 +73 77 -2.6400560000000e+00 +65 78 -1.3185400000000e+02 +67 78 8.0574700000000e-03 +83 78 -1.3185400000000e+02 +84 78 -1.0624090000000e+00 +66 79 1.0000000000000e+00 +73 79 1.0164260000000e-01 +85 79 -6.1791090000000e-02 +67 80 7.6452570000000e-03 +73 80 2.3098950000000e+01 +85 80 7.6996490000000e+00 +31 81 1.0000000000000e+00 +244 81 1.0000000000000e+00 +43 82 1.0000000000000e+00 +1 83 1.0000000000000e+00 +17 83 -3.8502310000000e+00 +18 83 -8.4599350000000e-05 +31 83 2.0159100000000e+00 +35 83 1.0000000000000e+00 +43 83 1.5961710000000e+00 +243 83 -7.8975120000000e-01 +74 84 1.0000000000000e+00 +388 84 8.8175620000000e-01 +86 85 1.0000000000000e+00 +44 86 1.0000000000000e+00 +60 86 -2.7937600000000e+00 +61 86 -8.4458230000000e-05 +74 86 2.0156650000000e+00 +78 86 1.0000000000000e+00 +86 86 1.5939940000000e+00 +384 86 0.0000000000000e+00 +387 86 -9.6191500000000e-01 +385 87 2.4246690000000e-03 +386 87 3.0362780000000e-02 +387 87 6.7304510000000e-01 +388 87 1.4593600000000e+00 +96 88 1.6896610000000e-02 +97 88 3.4848030000000e-02 +98 88 -6.0080180000000e-02 +120 88 -5.5527170000000e-01 +121 88 -4.7703980000000e-01 +122 88 -1.8582930000000e-01 +141 88 -1.0000000000000e+00 +142 88 -1.0000000000000e+00 +143 88 -1.0000000000000e+00 +185 88 -5.5188570000000e+01 +186 88 -9.5676860000000e+01 +187 88 -2.1583770000000e+02 +389 88 1.0000000000000e+00 +438 88 1.0000000000000e+00 +439 88 1.0000000000000e+00 +440 88 1.0000000000000e+00 +441 88 1.0000000000000e+00 +442 88 1.0000000000000e+00 +443 88 1.0000000000000e+00 +450 88 -1.8907560000000e-03 +451 88 -1.5311400000000e-03 +452 88 -1.0137260000000e-03 +455 88 2.5000000000000e+00 +456 88 2.6063700000000e+01 +458 88 1.0000000000000e+00 +459 88 -1.5000000000000e+00 +461 88 -9.6031810000000e+00 +462 88 -9.4541850000000e+00 +463 88 -9.4376810000000e+00 +464 88 -4.8295720000000e+01 +472 88 9.0759220000000e-01 +473 88 -4.3759670000000e+00 +474 88 -8.9979920000000e+00 +475 88 -8.8819580000000e+00 +476 88 1.0000000000000e+00 +182 89 1.0000000000000e+00 +183 89 1.0000000000000e+00 +184 89 1.0000000000000e+00 +391 89 1.0000000000000e+00 +455 89 -1.0000000000000e+00 +456 89 -2.6063700000000e+01 +458 89 -1.0000000000000e+00 +468 89 1.0000000000000e+00 +388 90 -1.4593600000000e+00 +467 90 1.0000000000000e+00 +479 91 1.0000000000000e+00 +203 92 -1.0000000000000e+00 +204 92 -1.0000000000000e+00 +205 92 -1.0000000000000e+00 +209 92 1.0000000000000e+00 +210 92 1.0000000000000e+00 +211 92 1.0000000000000e+00 +382 92 5.6953100000000e+01 +385 92 7.0583250000000e-01 +437 92 1.0000000000000e+00 +453 92 -6.4913720000000e-01 +454 92 -3.2948410000000e-05 +467 92 5.3807480000000e-01 +469 92 1.0000000000000e+00 +479 92 8.2471120000000e-02 +203 93 -1.0000000000000e+00 +204 93 -1.0000000000000e+00 +205 93 -1.0000000000000e+00 +209 93 1.0000000000000e+00 +210 93 1.0000000000000e+00 +211 93 1.0000000000000e+00 +383 93 1.1583840000000e+01 +386 93 7.0583250000000e-01 +437 93 1.0000000000000e+00 +453 93 -1.0215420000000e+00 +454 93 -4.0990330000000e-05 +467 93 -3.6302480000000e-01 +470 93 1.0000000000000e+00 +479 93 6.9522610000000e-02 +203 94 -1.0000000000000e+00 +204 94 -1.0000000000000e+00 +205 94 -1.0000000000000e+00 +209 94 1.0000000000000e+00 +210 94 1.0000000000000e+00 +211 94 1.0000000000000e+00 +384 94 3.2096310000000e-01 +387 94 7.0583250000000e-01 +437 94 1.0000000000000e+00 +453 94 -2.0490070000000e+00 +454 94 -8.4470030000000e-05 +467 94 9.1353620000000e-01 +471 94 1.0000000000000e+00 +479 94 8.3976380000000e-01 +241 95 5.5083520000000e-01 +242 95 4.4892230000000e-01 +243 95 2.4252030000000e-04 +244 95 4.0528330000000e-01 +108 96 -6.7276620000000e-02 +109 96 -1.5700610000000e-01 +110 96 -9.7475700000000e-02 +132 96 -2.5060070000000e-01 +133 96 -2.8026170000000e-01 +134 96 1.0084910000000e-01 +245 96 -1.0000000000000e+00 +395 96 1.0000000000000e+00 +396 96 1.0000000000000e+00 +397 96 1.0000000000000e+00 +398 96 1.0000000000000e+00 +399 96 1.0000000000000e+00 +400 96 1.0000000000000e+00 +407 96 -2.8636020000000e-03 +408 96 -2.3162590000000e-03 +409 96 -1.5308900000000e-03 +412 96 2.5000000000000e+00 +413 96 1.1587800000000e+01 +415 96 1.0000000000000e+00 +416 96 -1.1012240000000e+00 +418 96 -1.3644320000000e+00 +419 96 -1.2188210000000e+00 +420 96 -1.2108590000000e+00 +421 96 -3.4621050000000e+01 +429 96 6.0313590000000e-01 +430 96 -5.9963840000000e-01 +431 96 -1.4033920000000e+00 +432 96 -1.3703860000000e+00 +433 96 1.0000000000000e+00 +246 97 1.0000000000000e+00 +412 97 -1.0000000000000e+00 +413 97 -1.1587800000000e+01 +415 97 -1.0000000000000e+00 +425 97 1.0000000000000e+00 +244 98 -4.0528330000000e-01 +424 98 1.0000000000000e+00 +436 99 1.0000000000000e+00 +160 100 -8.5938400000000e-01 +161 100 -7.7333900000000e-01 +162 100 -7.9517400000000e-01 +238 100 -1.0000000000000e+00 +241 100 1.0000000000000e+00 +394 100 1.0000000000000e+00 +410 100 -1.6236590000000e+00 +411 100 -3.3032780000000e-05 +424 100 3.5720350000000e+00 +426 100 1.0000000000000e+00 +436 100 9.2435320000000e-01 +160 101 -1.1718210000000e+00 +161 101 -1.2773520000000e+00 +162 101 -1.2505080000000e+00 +239 101 -1.0000000000000e+00 +242 101 1.0000000000000e+00 +394 101 1.0000000000000e+00 +410 101 -2.4602890000000e+00 +411 101 -4.1050810000000e-05 +424 101 -2.1785330000000e+00 +427 101 1.0000000000000e+00 +436 101 6.5098420000000e-01 +160 102 -2.3280470000000e+00 +161 102 -2.4161550000000e+00 +162 102 -2.5121660000000e+00 +240 102 -1.0000000000000e+00 +243 102 1.0000000000000e+00 +394 102 1.0000000000000e+00 +410 102 -4.7536200000000e+00 +411 102 -8.4530500000000e-05 +424 102 6.1671400000000e+00 +428 102 1.0000000000000e+00 +436 102 3.3966910000000e+00 +241 103 4.3736570000000e-02 +242 103 5.7396460000000e-01 +243 103 1.5834900000000e-01 +244 103 1.8781250000000e-01 +253 103 -4.4344130000000e-02 +254 103 -5.8193780000000e-01 +255 103 -1.6054870000000e-01 +256 103 -1.0000000000000e+00 +135 104 -1.0000000000000e+00 +136 104 -1.0000000000000e+00 +137 104 -1.0000000000000e+00 +151 104 -6.2680900000000e+01 +152 104 -1.2389000000000e+02 +153 104 -4.6435550000000e+02 +245 104 1.0000000000000e+00 +248 104 -5.1646550000000e-02 +249 104 -3.2417620000000e-01 +148 105 1.0000000000000e+00 +149 105 1.0000000000000e+00 +150 105 1.0000000000000e+00 +247 105 1.0000000000000e+00 +244 106 -1.8781250000000e-01 +248 106 1.0000000000000e+00 +256 106 1.0000000000000e+00 +249 107 1.0000000000000e+00 +147 108 1.0000000000000e+00 +169 108 -1.0000000000000e+00 +170 108 -1.0000000000000e+00 +171 108 -1.0000000000000e+00 +175 108 1.0000000000000e+00 +176 108 1.0000000000000e+00 +177 108 1.0000000000000e+00 +238 108 9.7738750000000e+00 +241 108 7.7605020000000e-01 +248 108 7.2528310000000e+00 +249 108 7.8041000000000e-01 +253 108 -7.8683060000000e-01 +147 109 1.0000000000000e+00 +169 109 -1.0000000000000e+00 +170 109 -1.0000000000000e+00 +171 109 -1.0000000000000e+00 +175 109 1.0000000000000e+00 +176 109 1.0000000000000e+00 +177 109 1.0000000000000e+00 +239 109 6.0698210000000e-01 +242 109 7.7605020000000e-01 +248 109 -2.3895080000000e+00 +249 109 6.8493980000000e-01 +254 109 -7.8683060000000e-01 +147 110 1.0000000000000e+00 +169 110 -1.0000000000000e+00 +170 110 -1.0000000000000e+00 +171 110 -1.0000000000000e+00 +175 110 1.0000000000000e+00 +176 110 1.0000000000000e+00 +177 110 1.0000000000000e+00 +240 110 1.1885640000000e-03 +243 110 7.7605020000000e-01 +248 110 1.1558830000000e+01 +249 110 2.2026440000000e+00 +255 110 -7.8683060000000e-01 +363 111 -1.7051480000000e-01 +364 111 -4.3429630000000e-01 +365 111 -2.6674210000000e-01 +366 111 -2.6093020000000e+00 +385 111 1.9564470000000e-01 +386 111 4.9830160000000e-01 +387 111 3.0605370000000e-01 +388 111 4.2239600000000e-01 +215 112 1.0000000000000e+00 +216 112 1.0000000000000e+00 +217 112 1.0000000000000e+00 +218 112 1.0000000000000e+00 +219 112 1.0000000000000e+00 +220 112 1.0000000000000e+00 +227 112 -1.8907560000000e-03 +228 112 -1.5311400000000e-03 +229 112 -1.0137260000000e-03 +232 112 2.5000000000000e+00 +233 112 1.6672410000000e+01 +235 112 1.0000000000000e+00 +236 112 -1.5000000000000e+00 +389 112 -1.0000000000000e+00 +392 112 -4.6212130000000e-01 +393 112 -1.2349620000000e-01 +232 113 -1.0000000000000e+00 +233 113 -1.6672410000000e+01 +235 113 -1.0000000000000e+00 +368 113 -1.0000000000000e+00 +369 113 -1.0000000000000e+00 +390 113 1.0000000000000e+00 +366 114 2.6093020000000e+00 +388 114 -4.2239600000000e-01 +392 114 1.0000000000000e+00 +393 115 1.0000000000000e+00 +181 116 1.0000000000000e+00 +194 116 -5.8697620000000e-01 +195 116 -5.0651550000000e-01 +196 116 -5.1399180000000e-01 +230 116 -1.0366850000000e+00 +231 116 -3.2948410000000e-05 +360 116 0.0000000000000e+00 +363 116 -8.7155310000000e-01 +382 116 -1.0000000000000e+00 +385 116 1.0000000000000e+00 +392 116 2.6399800000000e+00 +393 116 5.5742070000000e-01 +181 117 1.0000000000000e+00 +194 117 -8.0016370000000e-01 +195 117 -8.3640900000000e-01 +196 117 -8.0810260000000e-01 +230 117 -1.6376950000000e+00 +231 117 -4.0990330000000e-05 +361 117 0.0000000000000e+00 +364 117 -8.7155310000000e-01 +383 117 -1.0000000000000e+00 +386 117 1.0000000000000e+00 +392 117 -1.7736780000000e+00 +393 117 4.0754220000000e-01 +181 118 1.0000000000000e+00 +194 118 -1.5893890000000e+00 +195 118 -1.5818110000000e+00 +196 118 -1.6231180000000e+00 +230 118 -3.2056860000000e+00 +231 118 -8.4470030000000e-05 +362 118 0.0000000000000e+00 +365 118 -8.7155310000000e-01 +384 118 -1.0000000000000e+00 +387 118 1.0000000000000e+00 +392 118 4.4676090000000e+00 +393 118 2.2475290000000e+00 +93 119 -1.0000000000000e+00 +96 119 -1.0000000000000e+00 +248 119 -4.0421560000000e-01 +262 119 -1.8187770000000e-01 +284 119 -1.5634550000000e-01 +306 119 -1.5456990000000e-01 +328 119 -1.5217780000000e-01 +350 119 -9.1905800000000e-02 +372 119 -7.8705370000000e-03 +94 120 -1.0000000000000e+00 +97 120 -1.0000000000000e+00 +248 120 -1.8091710000000e+00 +262 120 -3.1896550000000e+00 +284 120 -3.3490190000000e+00 +306 120 -3.3586440000000e+00 +328 120 -3.3085850000000e+00 +350 120 -1.9678700000000e+00 +372 120 -1.1333560000000e-01 +95 121 -1.0000000000000e+00 +98 121 -1.0000000000000e+00 +248 121 -2.4566020000000e+00 +262 121 -4.1011280000000e+00 +284 121 -4.2908920000000e+00 +306 121 -4.3026030000000e+00 +328 121 -4.2541470000000e+00 +350 121 -2.9523890000000e+00 +372 121 -1.1573650000000e+00 +93 122 -8.1214960000000e-03 +96 122 -1.6896610000000e-02 +248 122 -4.5387600000000e-03 +262 122 -2.1705200000000e-03 +284 122 -1.8740690000000e-03 +306 122 -1.8533180000000e-03 +328 122 -1.8248370000000e-03 +350 122 -1.1065610000000e-03 +372 122 -1.0544940000000e-04 +94 123 -1.6749990000000e-02 +97 123 -3.4848030000000e-02 +248 123 -4.1896920000000e-02 +262 123 -7.8506680000000e-02 +284 123 -8.2793510000000e-02 +306 123 -8.3055320000000e-02 +328 123 -8.1826380000000e-02 +350 123 -4.8866050000000e-02 +372 123 -3.1317320000000e-03 +95 124 -2.8878030000000e-02 +98 124 -6.0080180000000e-02 +248 124 -9.8082240000000e-02 +262 124 -1.7402810000000e-01 +284 124 -1.8288550000000e-01 +306 124 -1.8343740000000e-01 +328 124 -1.8139140000000e-01 +350 124 -1.2639720000000e-01 +372 124 -5.5136770000000e-02 +105 125 -1.0000000000000e+00 +108 125 -1.0000000000000e+00 +264 125 -7.6362320000000e-01 +286 125 -5.4132110000000e-01 +308 125 -5.2907530000000e-01 +330 125 -5.2832600000000e-01 +352 125 -5.2965340000000e-01 +374 125 -5.9901060000000e-01 +392 125 -5.7467680000000e-01 +106 126 -1.0000000000000e+00 +109 126 -1.0000000000000e+00 +264 126 -1.4679790000000e+00 +286 126 -1.2898060000000e+00 +308 126 -1.2799920000000e+00 +330 126 -1.2793850000000e+00 +352 126 -1.2801740000000e+00 +374 126 -1.3601430000000e+00 +392 126 -7.1491900000000e-01 +107 127 -1.0000000000000e+00 +110 127 -1.0000000000000e+00 +264 127 -4.3708570000000e-03 +286 127 -3.9541010000000e-03 +308 127 -3.9318030000000e-03 +330 127 -3.9476680000000e-03 +352 127 -4.7490230000000e-03 +374 127 -7.2455390000000e-02 +392 127 -1.6023640000000e+00 +105 128 -1.1229330000000e-01 +108 128 -6.7276620000000e-02 +264 128 -5.4601370000000e-02 +286 128 -3.8877220000000e-02 +308 128 -3.8008660000000e-02 +330 128 -3.7958990000000e-02 +352 128 -3.8208860000000e-02 +374 128 -4.8085490000000e-02 +392 128 -5.8178620000000e-02 +106 129 -2.6206330000000e-01 +109 129 -1.5700610000000e-01 +264 129 -2.4496080000000e-01 +286 129 -2.1618060000000e-01 +308 129 -2.1459740000000e-01 +330 129 -2.1451910000000e-01 +352 129 -2.1552300000000e-01 +374 129 -2.5481000000000e-01 +392 129 -1.6890750000000e-01 +107 130 -1.6269950000000e-01 +110 130 -9.7475700000000e-02 +264 130 -4.5281760000000e-04 +286 130 -4.1145290000000e-04 +308 130 -4.0925030000000e-04 +330 130 -4.1094670000000e-04 +352 130 -4.9637370000000e-04 +374 130 -8.4271850000000e-03 +392 130 -2.3503520000000e-01 +117 131 -1.0000000000000e+00 +120 131 -1.0000000000000e+00 +249 131 -6.9702840000000e-02 +263 131 -1.9243320000000e-02 +285 131 -1.5837930000000e-02 +307 131 -1.5617910000000e-02 +329 131 -1.5583210000000e-02 +351 131 -1.4718560000000e-02 +373 131 -5.7599520000000e-03 +118 132 -1.0000000000000e+00 +121 132 -1.0000000000000e+00 +249 132 -7.4171360000000e-01 +263 132 -8.0234940000000e-01 +285 132 -8.0658470000000e-01 +307 132 -8.0682860000000e-01 +329 132 -8.0550310000000e-01 +351 132 -7.4926980000000e-01 +373 132 -1.9719700000000e-01 +119 133 -1.0000000000000e+00 +122 133 -1.0000000000000e+00 +249 133 -5.1275980000000e-01 +263 133 -5.2522530000000e-01 +285 133 -5.2614130000000e-01 +307 133 -5.2622450000000e-01 +329 133 -5.2730270000000e-01 +351 133 -5.7231860000000e-01 +373 133 -1.0252420000000e+00 +117 134 -4.6575930000000e-01 +120 134 -9.6900310000000e-01 +249 134 -4.4884880000000e-02 +263 134 -1.3170120000000e-02 +285 134 -1.0887390000000e-02 +307 134 -1.0739240000000e-02 +329 134 -1.0716550000000e-02 +351 134 -1.0163030000000e-02 +373 134 -4.4257190000000e-03 +118 135 -5.7440230000000e-01 +121 135 -1.1950330000000e+00 +249 135 -5.8903420000000e-01 +263 135 -6.7721740000000e-01 +285 135 -6.8380180000000e-01 +307 135 -6.8420530000000e-01 +329 135 -6.8315610000000e-01 +351 135 -6.3804400000000e-01 +373 135 -1.8686160000000e-01 +119 136 -2.2922850000000e-01 +122 136 -4.7690550000000e-01 +249 136 -1.6250650000000e-01 +263 136 -1.7691420000000e-01 +285 136 -1.7800620000000e-01 +307 136 -1.7808560000000e-01 +329 136 -1.7847000000000e-01 +351 136 -1.9449250000000e-01 +373 136 -3.8770260000000e-01 +129 137 -1.0000000000000e+00 +132 137 -1.0000000000000e+00 +265 137 -3.4272790000000e-01 +287 137 -2.9113760000000e-01 +309 137 -2.8769370000000e-01 +331 137 -2.8748890000000e-01 +353 137 -2.8823180000000e-01 +375 137 -3.0269870000000e-01 +393 137 -1.7507890000000e-01 +130 138 -1.0000000000000e+00 +133 138 -1.0000000000000e+00 +265 138 -1.0623340000000e+00 +287 138 -1.1185060000000e+00 +309 138 -1.1222530000000e+00 +331 138 -1.1225120000000e+00 +353 138 -1.1232850000000e+00 +375 138 -1.1082340000000e+00 +393 138 -3.5118640000000e-01 +131 139 -1.0000000000000e+00 +134 139 -1.0000000000000e+00 +265 139 -2.3999820000000e-03 +287 139 -2.6017300000000e-03 +309 139 -2.6156270000000e-03 +331 139 -2.6280330000000e-03 +353 139 -3.1617350000000e-03 +375 139 -4.4793810000000e-02 +393 139 -5.9723090000000e-01 +129 140 -2.0182530000000e+00 +132 140 -1.2091660000000e+00 +265 140 -4.4044890000000e-01 +287 140 -3.7580290000000e-01 +309 140 -3.7146430000000e-01 +331 140 -3.7124050000000e-01 +353 140 -3.7371090000000e-01 +375 140 -4.3672880000000e-01 +393 140 -3.1856280000000e-01 +130 141 -2.5626880000000e+00 +133 141 -1.5353450000000e+00 +265 141 -1.7335130000000e+00 +287 141 -1.8332450000000e+00 +309 141 -1.8399150000000e+00 +331 141 -1.8405410000000e+00 +353 141 -1.8492860000000e+00 +375 141 -2.0302660000000e+00 +393 141 -8.1137050000000e-01 +131 142 -9.2554290000000e-01 +134 142 -5.5450670000000e-01 +265 142 -1.4144090000000e-03 +287 142 -1.5400860000000e-03 +309 142 -1.5487580000000e-03 +331 142 -1.5562740000000e-03 +353 142 -1.8799250000000e-03 +375 142 -2.9637400000000e-02 +393 142 -4.9833870000000e-01 +135 143 -1.4338920000000e+00 +141 143 -2.1577040000000e+00 +266 143 -1.5239710000000e+00 +288 143 -1.5307080000000e+00 +310 143 -1.5311480000000e+00 +332 143 -1.5313160000000e+00 +354 143 -1.5375330000000e+00 +376 143 -1.7109280000000e+00 +136 144 -9.4320600000000e-01 +142 144 -1.4193260000000e+00 +267 144 -1.0024600000000e+00 +289 144 -1.0068910000000e+00 +311 144 -1.0071810000000e+00 +333 144 -1.0072910000000e+00 +355 144 -1.0113810000000e+00 +377 144 -1.1254390000000e+00 +137 145 -5.9645270000000e-01 +143 145 -8.9753530000000e-01 +268 145 -6.3392270000000e-01 +290 145 -6.3672520000000e-01 +312 145 -6.3690830000000e-01 +334 145 -6.3697810000000e-01 +356 145 -6.3956420000000e-01 +378 145 -7.1169090000000e-01 +135 146 -1.0000000000000e+00 +141 146 -1.0000000000000e+00 +266 146 -1.0000000000000e+00 +288 146 -1.0000000000000e+00 +310 146 -1.0000000000000e+00 +332 146 -1.0000000000000e+00 +354 146 -1.0000000000000e+00 +376 146 -1.0000000000000e+00 +136 147 -1.0000000000000e+00 +142 147 -1.0000000000000e+00 +267 147 -1.0000000000000e+00 +289 147 -1.0000000000000e+00 +311 147 -1.0000000000000e+00 +333 147 -1.0000000000000e+00 +355 147 -1.0000000000000e+00 +377 147 -1.0000000000000e+00 +137 148 -1.0000000000000e+00 +143 148 -1.0000000000000e+00 +268 148 -1.0000000000000e+00 +290 148 -1.0000000000000e+00 +312 148 -1.0000000000000e+00 +334 148 -1.0000000000000e+00 +356 148 -1.0000000000000e+00 +378 148 -1.0000000000000e+00 +138 149 -1.0000000000000e+00 +148 149 1.0000000000000e+00 +238 149 5.5083520000000e-01 +139 150 -1.0000000000000e+00 +149 150 1.6474950000000e+00 +239 150 7.3959730000000e-01 +140 151 -1.0000000000000e+00 +150 151 8.4135160000000e+02 +240 151 2.0404480000000e-01 +144 152 -1.0000000000000e+00 +182 152 1.0000000000000e+00 +382 152 1.9564470000000e-01 +145 153 -1.0000000000000e+00 +183 153 1.0000000000000e+00 +383 153 4.9830160000000e-01 +146 154 -1.0000000000000e+00 +184 154 3.1156220000000e+00 +384 154 9.5354780000000e-01 +395 155 6.6224920000000e+01 +401 155 -1.0000000000000e+00 +404 155 -3.3282570000000e-05 +396 156 1.1506230000000e+02 +402 156 -1.0000000000000e+00 +405 156 -4.1228310000000e-05 +397 157 2.3733870000000e+02 +403 157 -1.0000000000000e+00 +406 157 -8.4706900000000e-05 +398 158 1.3324500000000e+02 +401 158 2.5000000000000e+00 +404 158 3.3282570000000e-05 +399 159 2.3226390000000e+02 +402 159 2.5000000000000e+00 +405 159 4.1228310000000e-05 +400 160 4.8018210000000e+02 +403 160 2.5000000000000e+00 +406 160 8.4706900000000e-05 +160 161 -4.7337900000000e-01 +401 161 1.0000000000000e+00 +410 161 -2.1168760000000e-01 +161 162 -5.7343170000000e-01 +402 162 1.0000000000000e+00 +410 162 -3.1667150000000e-01 +162 163 -6.0925110000000e-04 +403 163 1.0000000000000e+00 +410 163 -3.5118740000000e-07 +163 164 -4.5750040000000e+03 +404 164 1.0075620000000e+00 +411 164 -5.5083520000000e-01 +164 165 -3.6814160000000e+03 +405 165 1.0043240000000e+00 +411 165 -4.4892230000000e-01 +165 166 -1.7878180000000e+03 +406 166 1.0020870000000e+00 +411 166 -2.4252030000000e-04 +160 167 -5.2605640000000e-01 +161 167 -4.2598230000000e-01 +407 167 1.0000000000000e+00 +410 167 -4.7048840000000e-01 +160 168 -5.6459870000000e-04 +162 168 -4.3800980000000e-01 +408 168 1.0000000000000e+00 +410 168 -5.0495930000000e-04 +161 169 -5.8596670000000e-04 +162 169 -5.6138090000000e-01 +409 169 1.0000000000000e+00 +410 169 -6.4718760000000e-04 +163 170 -1.0000000000000e+00 +164 170 -1.0000000000000e+00 +165 170 -1.0000000000000e+00 +410 170 1.0000000000000e+00 +412 170 -1.0000000000000e+00 +423 170 6.1444210000000e-02 +435 170 2.0481400000000e-02 +157 171 -1.0000000000000e+00 +163 171 4.1240600000000e+03 +164 171 4.1240600000000e+03 +165 171 4.1240600000000e+03 +411 171 1.0000000000000e+00 +413 171 -3.1622000000000e+05 +416 171 -2.0034240000000e+04 +417 171 -1.0000000000000e+00 +423 171 -2.6256570000000e+03 +434 171 2.2212900000000e+02 +412 172 1.8737270000000e+01 +414 172 9.4488160000000e-01 +413 173 1.4943670000000e+03 +414 173 -1.0207800000000e+00 +158 174 -9.9186010000000e-01 +163 174 -1.7922340000000e+01 +164 174 -1.7922340000000e+01 +165 174 -1.7922340000000e+01 +414 174 8.6282900000000e-01 +415 174 1.0497190000000e+00 +423 174 -7.3414950000000e-01 +157 175 8.1398600000000e-03 +415 175 -2.2212900000000e+02 +417 175 8.1398600000000e-03 +433 175 -2.2212900000000e+02 +434 175 -1.8080990000000e+00 +163 176 -1.0913280000000e+00 +164 176 -1.6293970000000e+00 +165 176 -1.4448530000000e+00 +416 176 1.0000000000000e+00 +423 176 4.7364060000000e-02 +435 176 -2.7898140000000e-02 +417 177 4.5385340000000e-03 +423 177 7.5792400000000e+00 +435 177 2.5264130000000e+00 +148 178 -1.0000000000000e+00 +178 178 -1.0000000000000e+00 +149 179 -1.0000000000000e+00 +179 179 -1.0000000000000e+00 +150 180 -1.0000000000000e+00 +180 180 -1.0000000000000e+00 +148 181 1.0266460000000e+00 +166 181 -1.0000000000000e+00 +149 182 1.0737240000000e+00 +167 182 -1.0000000000000e+00 +150 183 1.2081470000000e+00 +168 183 -1.0000000000000e+00 +148 184 -1.0000000000000e+00 +154 184 -1.0000000000000e+00 +149 185 -1.0000000000000e+00 +155 185 -1.0000000000000e+00 +150 186 -1.0000000000000e+00 +156 186 -1.0000000000000e+00 +215 187 9.9149730000000e+01 +221 187 -1.0000000000000e+00 +224 187 -3.3113980000000e-05 +216 188 1.7263960000000e+02 +222 188 -1.0000000000000e+00 +225 188 -4.1108120000000e-05 +217 189 3.5663980000000e+02 +223 189 -1.0000000000000e+00 +226 189 -8.4587180000000e-05 +218 190 2.0000080000000e+02 +221 190 2.5000000000000e+00 +224 190 3.3113980000000e-05 +219 191 3.4900330000000e+02 +222 191 2.5000000000000e+00 +225 191 4.1108120000000e-05 +220 192 7.2206780000000e+02 +223 192 2.5000000000000e+00 +226 192 8.4587180000000e-05 +194 193 -1.1483880000000e-01 +221 193 1.0000000000000e+00 +230 193 -1.1645920000000e-02 +195 194 -4.1678390000000e-01 +222 194 1.0000000000000e+00 +230 194 -1.7006160000000e-01 +196 195 -4.9676140000000e-01 +223 195 1.0000000000000e+00 +230 195 -2.4368930000000e-01 +197 196 -5.2768620000000e+03 +224 196 1.0050250000000e+00 +231 196 -1.9564470000000e-01 +198 197 -4.2415910000000e+03 +225 197 1.0028740000000e+00 +231 197 -4.9830160000000e-01 +199 198 -2.0582940000000e+03 +226 198 1.0013870000000e+00 +231 198 -3.0605370000000e-01 +194 199 -3.9872280000000e-01 +195 199 -9.9097090000000e-02 +227 199 1.0000000000000e+00 +230 199 -8.0869760000000e-02 +194 200 -4.8643840000000e-01 +196 200 -1.0055980000000e-01 +228 200 1.0000000000000e+00 +230 200 -9.8660410000000e-02 +195 201 -4.8411900000000e-01 +196 201 -4.0267880000000e-01 +229 201 1.0000000000000e+00 +230 201 -3.9507300000000e-01 +197 202 -1.0000000000000e+00 +198 202 -1.0000000000000e+00 +199 202 -1.0000000000000e+00 +230 202 1.0000000000000e+00 +232 202 -1.0000000000000e+00 +191 203 -1.0000000000000e+00 +197 203 3.2976230000000e+03 +198 203 3.2976230000000e+03 +199 203 3.2976230000000e+03 +231 203 1.0000000000000e+00 +233 203 -3.1622000000000e+05 +236 203 -1.8966660000000e+04 +237 203 -1.0000000000000e+00 +232 204 2.2669870000000e+01 +234 204 9.5486020000000e-01 +233 205 2.2487060000000e+03 +234 205 -1.0206550000000e+00 +192 206 -9.9229510000000e-01 +197 206 -2.1898570000000e+01 +198 206 -2.1898570000000e+01 +199 206 -2.1898570000000e+01 +234 206 8.9000960000000e-01 +235 206 1.0392050000000e+00 +191 207 7.7048970000000e-03 +235 207 -1.4613620000000e+02 +237 207 7.7048970000000e-03 +197 208 -6.5890520000000e-01 +198 208 -1.1064970000000e+00 +199 208 -1.0009090000000e+00 +236 208 1.0000000000000e+00 +237 209 6.8956570000000e-03 +182 210 -1.0000000000000e+00 +212 210 -1.0000000000000e+00 +183 211 -1.0000000000000e+00 +213 211 -1.0000000000000e+00 +184 212 -1.0000000000000e+00 +214 212 -1.0000000000000e+00 +182 213 1.0000000000000e+00 +200 213 -1.0000000000000e+00 +183 214 1.0226760000000e+00 +201 214 -1.0000000000000e+00 +184 215 1.0914180000000e+00 +202 215 -1.0000000000000e+00 +182 216 -1.0000000000000e+00 +188 216 -1.0000000000000e+00 +183 217 -1.0000000000000e+00 +189 217 -1.0000000000000e+00 +184 218 -1.0000000000000e+00 +190 218 -1.0000000000000e+00 +241 219 -1.9969610000000e-01 +242 219 -7.8596160000000e-01 +243 219 -6.4128230000000e-04 +244 219 4.0690410000000e-01 +253 219 2.0247020000000e-01 +254 219 7.9687960000000e-01 +255 219 6.5019060000000e-04 +256 219 -2.1665440000000e+00 +257 220 -1.0000000000000e+00 +264 220 -3.0001500000000e-01 +265 220 -4.0746150000000e-01 +246 221 -1.0000000000000e+00 +247 221 -1.0000000000000e+00 +258 221 1.0000000000000e+00 +244 222 4.0690410000000e-01 +256 222 -2.1665440000000e+00 +264 222 1.0000000000000e+00 +265 223 1.0000000000000e+00 +238 224 0.0000000000000e+00 +241 224 -9.8629890000000e-01 +250 224 -1.0000000000000e+00 +253 224 1.0000000000000e+00 +261 224 1.0000000000000e+00 +264 224 3.5018580000000e+00 +265 224 1.2418840000000e+00 +239 225 0.0000000000000e+00 +242 225 -9.8629890000000e-01 +251 225 -1.0000000000000e+00 +254 225 1.0000000000000e+00 +261 225 1.0000000000000e+00 +264 225 -2.1495590000000e+00 +265 225 9.3602390000000e-01 +240 226 0.0000000000000e+00 +243 226 -9.8629890000000e-01 +252 226 -1.0000000000000e+00 +255 226 1.0000000000000e+00 +261 226 1.0000000000000e+00 +264 226 6.0259860000000e+00 +265 226 4.0868380000000e+00 +253 227 1.1955300000000e-02 +254 227 6.1475030000000e-01 +255 227 1.6059550000000e-01 +256 227 5.9918100000000e-01 +275 227 -1.1949680000000e-02 +276 227 -6.1446120000000e-01 +277 227 -1.6052000000000e-01 +278 227 -1.0000000000000e+00 +257 228 1.0000000000000e+00 +262 228 -9.3350860000000e-02 +263 228 -3.4681810000000e-01 +266 228 -1.0000000000000e+00 +267 228 -1.0000000000000e+00 +268 228 -1.0000000000000e+00 +259 229 1.0000000000000e+00 +256 230 -5.9918100000000e-01 +262 230 1.0000000000000e+00 +278 230 1.0000000000000e+00 +263 231 1.0000000000000e+00 +250 232 1.3333420000000e+01 +253 232 7.8730110000000e-01 +260 232 1.0000000000000e+00 +262 232 1.2120260000000e+01 +263 232 7.7025090000000e-01 +275 232 -7.8693090000000e-01 +251 233 1.0205510000000e+00 +254 233 7.8730110000000e-01 +260 233 1.0000000000000e+00 +262 233 -3.9843990000000e+00 +263 233 6.8134200000000e-01 +276 233 -7.8693090000000e-01 +252 234 3.1874850000000e-03 +255 234 7.8730110000000e-01 +260 234 1.0000000000000e+00 +262 234 1.9252160000000e+01 +263 234 2.2369070000000e+00 +277 234 -7.8693090000000e-01 +253 235 -1.7008130000000e-01 +254 235 -8.2969220000000e-01 +255 235 -6.9701410000000e-04 +256 235 2.5673630000000e+00 +275 235 1.7000140000000e-01 +276 235 8.2930200000000e-01 +277 235 6.9668630000000e-04 +278 235 -4.2847870000000e+00 +279 236 -1.0000000000000e+00 +286 236 -2.5546930000000e-01 +287 236 -4.1224570000000e-01 +258 237 -1.0000000000000e+00 +259 237 -1.0000000000000e+00 +280 237 1.0000000000000e+00 +256 238 2.5673630000000e+00 +278 238 -4.2847870000000e+00 +286 238 1.0000000000000e+00 +287 239 1.0000000000000e+00 +250 240 0.0000000000000e+00 +253 240 -1.0004710000000e+00 +272 240 -1.0000000000000e+00 +275 240 1.0000000000000e+00 +283 240 1.0000000000000e+00 +286 240 2.9555290000000e+00 +287 240 1.2544140000000e+00 +251 241 0.0000000000000e+00 +254 241 -1.0004710000000e+00 +273 241 -1.0000000000000e+00 +276 241 1.0000000000000e+00 +283 241 1.0000000000000e+00 +286 241 -1.8159690000000e+00 +287 241 9.4521190000000e-01 +252 242 0.0000000000000e+00 +255 242 -1.0004710000000e+00 +274 242 -1.0000000000000e+00 +277 242 1.0000000000000e+00 +283 242 1.0000000000000e+00 +286 242 5.0849970000000e+00 +287 242 4.1364790000000e+00 +250 243 2.0247020000000e-01 +269 243 -1.0000000000000e+00 +251 244 7.9687960000000e-01 +270 244 -1.0000000000000e+00 +252 245 2.0398230000000e-01 +271 245 -1.0000000000000e+00 +275 246 9.8180810000000e-03 +276 246 6.1664170000000e-01 +278 246 9.5579440000000e-01 +297 246 -9.8175690000000e-03 +298 246 -6.1660960000000e-01 +299 246 -1.6051480000000e-01 +300 246 -1.0000000000000e+00 +279 247 1.0000000000000e+00 +284 247 -9.8217900000000e-02 +285 247 -3.4856390000000e-01 +288 247 -1.0000000000000e+00 +289 247 -1.0000000000000e+00 +290 247 -1.0000000000000e+00 +281 248 1.0000000000000e+00 +278 249 -9.5579440000000e-01 +284 249 1.0000000000000e+00 +300 249 1.0000000000000e+00 +285 250 1.0000000000000e+00 +272 251 1.3626710000000e+01 +275 251 7.8698300000000e-01 +282 251 1.0000000000000e+00 +284 251 1.2682330000000e+01 +285 251 7.6942870000000e-01 +297 251 -7.8694200000000e-01 +273 252 1.0583890000000e+00 +276 252 7.8698300000000e-01 +282 252 1.0000000000000e+00 +284 252 -4.1684890000000e+00 +285 252 6.8102850000000e-01 +298 252 -7.8694200000000e-01 +274 253 3.4155830000000e-03 +277 253 7.8698300000000e-01 +282 253 1.0000000000000e+00 +284 253 2.0139960000000e+01 +285 253 2.2394150000000e+00 +299 253 -7.8694200000000e-01 +275 254 -1.6786980000000e-01 +276 254 -8.3148250000000e-01 +277 254 -6.9990470000000e-04 +278 254 4.3289930000000e+00 +297 254 1.6786100000000e-01 +298 254 8.3143910000000e-01 +299 254 6.9986820000000e-04 +300 254 -4.5292090000000e+00 +301 255 -1.0000000000000e+00 +308 255 -2.5301530000000e-01 +309 255 -4.1256250000000e-01 +280 256 -1.0000000000000e+00 +281 256 -1.0000000000000e+00 +302 256 1.0000000000000e+00 +278 257 4.3289930000000e+00 +300 257 -4.5292090000000e+00 +308 257 1.0000000000000e+00 +309 258 1.0000000000000e+00 +272 259 0.0000000000000e+00 +275 259 -1.0000520000000e+00 +294 259 -1.0000000000000e+00 +297 259 1.0000000000000e+00 +305 259 1.0000000000000e+00 +308 259 2.9254360000000e+00 +309 259 1.2552490000000e+00 +273 260 0.0000000000000e+00 +276 260 -1.0000520000000e+00 +295 260 -1.0000000000000e+00 +298 260 1.0000000000000e+00 +305 260 1.0000000000000e+00 +308 260 -1.7975930000000e+00 +309 260 9.4582430000000e-01 +274 261 0.0000000000000e+00 +277 261 -1.0000520000000e+00 +296 261 -1.0000000000000e+00 +299 261 1.0000000000000e+00 +305 261 1.0000000000000e+00 +308 261 5.0331660000000e+00 +309 261 4.1397830000000e+00 +272 262 1.7000140000000e-01 +291 262 -1.0000000000000e+00 +273 263 8.2930200000000e-01 +292 263 -1.0000000000000e+00 +274 264 2.0397290000000e-01 +293 264 -1.0000000000000e+00 +297 265 9.6798500000000e-03 +298 265 6.1671090000000e-01 +299 265 1.6051810000000e-01 +300 265 9.9729840000000e-01 +319 265 -9.6801700000000e-03 +320 265 -6.1673130000000e-01 +321 265 -1.6052340000000e-01 +322 265 -1.0000000000000e+00 +301 266 1.0000000000000e+00 +306 266 -9.8528720000000e-02 +307 266 -3.4867100000000e-01 +310 266 -1.0000000000000e+00 +311 266 -1.0000000000000e+00 +312 266 -1.0000000000000e+00 +303 267 1.0000000000000e+00 +300 268 -9.9729840000000e-01 +306 268 1.0000000000000e+00 +322 268 1.0000000000000e+00 +307 269 1.0000000000000e+00 +294 270 1.3646010000000e+01 +297 270 7.8690890000000e-01 +304 270 1.0000000000000e+00 +306 270 1.2716190000000e+01 +307 270 7.6935860000000e-01 +319 270 -7.8693490000000e-01 +295 271 1.0608970000000e+00 +298 271 7.8690890000000e-01 +304 271 1.0000000000000e+00 +306 271 -4.1795750000000e+00 +307 271 6.8099360000000e-01 +320 271 -7.8693490000000e-01 +296 272 3.4309680000000e-03 +299 272 7.8690890000000e-01 +304 272 1.0000000000000e+00 +306 272 2.0193410000000e+01 +307 272 2.2395320000000e+00 +321 272 -7.8693490000000e-01 +297 273 -1.6772330000000e-01 +298 273 -8.3154050000000e-01 +299 273 -7.0311130000000e-04 +300 273 4.5319110000000e+00 +319 273 1.6772880000000e-01 +320 273 8.3156800000000e-01 +321 273 7.0313460000000e-04 +322 273 -4.5441880000000e+00 +323 274 -1.0000000000000e+00 +330 274 -2.5288910000000e-01 +331 274 -4.1262900000000e-01 +302 275 -1.0000000000000e+00 +303 275 -1.0000000000000e+00 +324 275 1.0000000000000e+00 +300 276 4.5319110000000e+00 +322 276 -4.5441880000000e+00 +330 276 1.0000000000000e+00 +331 277 1.0000000000000e+00 +294 278 0.0000000000000e+00 +297 278 -9.9996690000000e-01 +316 278 -1.0000000000000e+00 +319 278 1.0000000000000e+00 +327 278 1.0000000000000e+00 +330 278 2.9235700000000e+00 +331 278 1.2552940000000e+00 +295 279 0.0000000000000e+00 +298 279 -9.9996690000000e-01 +317 279 -1.0000000000000e+00 +320 279 1.0000000000000e+00 +327 279 1.0000000000000e+00 +330 279 -1.7964900000000e+00 +331 279 9.4585160000000e-01 +296 280 0.0000000000000e+00 +299 280 -9.9996690000000e-01 +318 280 -1.0000000000000e+00 +321 280 1.0000000000000e+00 +327 280 1.0000000000000e+00 +330 280 5.0299350000000e+00 +331 280 4.1401400000000e+00 +294 281 1.6786100000000e-01 +313 281 -1.0000000000000e+00 +295 282 8.3143910000000e-01 +314 282 -1.0000000000000e+00 +296 283 2.0398560000000e-01 +315 283 -1.0000000000000e+00 +319 284 9.6473500000000e-03 +320 284 6.1499680000000e-01 +321 284 1.6066380000000e-01 +322 284 1.0122750000000e+00 +341 284 -9.6630710000000e-03 +342 284 -6.1599900000000e-01 +343 284 -1.6092570000000e-01 +344 284 -1.0000000000000e+00 +323 285 1.0000000000000e+00 +328 285 -9.7740150000000e-02 +329 285 -3.4838900000000e-01 +332 285 -1.0000000000000e+00 +333 285 -1.0000000000000e+00 +334 285 -1.0000000000000e+00 +325 286 1.0000000000000e+00 +322 287 -1.0122750000000e+00 +328 287 1.0000000000000e+00 +344 287 1.0000000000000e+00 +329 288 1.0000000000000e+00 +316 289 1.3653370000000e+01 +319 289 7.8530800000000e-01 +326 289 1.0000000000000e+00 +328 289 1.2536040000000e+01 +329 289 7.6861380000000e-01 +341 289 -7.8658770000000e-01 +317 290 1.0618540000000e+00 +320 290 7.8530800000000e-01 +326 290 1.0000000000000e+00 +328 290 -4.1203450000000e+00 +329 290 6.8034460000000e-01 +342 290 -7.8658770000000e-01 +318 291 3.4368480000000e-03 +321 291 7.8530800000000e-01 +326 291 1.0000000000000e+00 +328 291 1.9907200000000e+01 +329 291 2.2374860000000e+00 +343 291 -7.8658770000000e-01 +319 292 -1.6769600000000e-01 +320 292 -8.2983350000000e-01 +321 292 -8.4358210000000e-04 +322 292 4.5319130000000e+00 +341 292 1.6796930000000e-01 +342 292 8.3118580000000e-01 +343 292 8.4495670000000e-04 +344 292 -4.4769570000000e+00 +345 293 -1.0000000000000e+00 +352 293 -2.5422820000000e-01 +353 293 -4.1467850000000e-01 +324 294 -1.0000000000000e+00 +325 294 -1.0000000000000e+00 +346 294 1.0000000000000e+00 +322 295 4.5319120000000e+00 +344 295 -4.4769570000000e+00 +352 295 1.0000000000000e+00 +353 296 1.0000000000000e+00 +316 297 0.0000000000000e+00 +319 297 -9.9837310000000e-01 +338 297 -1.0000000000000e+00 +341 297 1.0000000000000e+00 +349 297 1.0000000000000e+00 +352 297 2.9258000000000e+00 +353 297 1.2548710000000e+00 +317 298 0.0000000000000e+00 +320 298 -9.9837310000000e-01 +339 298 -1.0000000000000e+00 +342 298 1.0000000000000e+00 +349 298 1.0000000000000e+00 +352 298 -1.7994740000000e+00 +353 298 9.4529590000000e-01 +318 299 0.0000000000000e+00 +321 299 -9.9837310000000e-01 +340 299 -1.0000000000000e+00 +343 299 1.0000000000000e+00 +349 299 1.0000000000000e+00 +352 299 5.0329780000000e+00 +353 299 4.1465320000000e+00 +316 300 1.6772880000000e-01 +335 300 -1.0000000000000e+00 +317 301 8.3156800000000e-01 +336 301 -1.0000000000000e+00 +318 302 2.0458700000000e-01 +337 302 -1.0000000000000e+00 +341 303 8.9580030000000e-03 +342 303 5.6239150000000e-01 +343 303 1.7143160000000e-01 +344 303 1.5349870000000e+00 +363 303 -9.3684010000000e-03 +364 303 -5.8815670000000e-01 +365 303 -1.7928550000000e-01 +366 303 -1.0000000000000e+00 +345 304 1.0000000000000e+00 +350 304 -7.6424570000000e-02 +351 304 -3.3630700000000e-01 +354 304 -1.0000000000000e+00 +355 304 -1.0000000000000e+00 +356 304 -1.0000000000000e+00 +347 305 1.0000000000000e+00 +344 306 -1.5349870000000e+00 +350 306 1.0000000000000e+00 +366 306 1.0000000000000e+00 +351 307 1.0000000000000e+00 +338 308 1.3927700000000e+01 +341 308 7.4278120000000e-01 +348 308 1.0000000000000e+00 +350 308 7.7124140000000e+00 +351 308 7.3754050000000e-01 +363 308 -7.7681060000000e-01 +339 309 1.0977920000000e+00 +342 309 7.4278120000000e-01 +348 309 1.0000000000000e+00 +350 309 -2.5345340000000e+00 +351 309 6.5320800000000e-01 +364 309 -7.7681060000000e-01 +340 310 3.6610400000000e-03 +343 310 7.4278120000000e-01 +348 310 1.0000000000000e+00 +350 310 1.2244490000000e+01 +351 310 2.1513860000000e+00 +365 310 -7.7681060000000e-01 +341 311 -1.6726420000000e-01 +342 311 -7.7757830000000e-01 +343 311 -1.1350930000000e-02 +344 311 3.9419710000000e+00 +363 311 1.7492720000000e-01 +364 311 8.1320190000000e-01 +365 311 1.1870950000000e-02 +366 311 -2.5680820000000e+00 +367 312 -1.0000000000000e+00 +374 312 -3.1132270000000e-01 +375 312 -4.5572680000000e-01 +346 313 -1.0000000000000e+00 +347 313 -1.0000000000000e+00 +368 313 1.0000000000000e+00 +344 314 3.9419710000000e+00 +366 314 -2.5680820000000e+00 +374 314 1.0000000000000e+00 +375 315 1.0000000000000e+00 +338 316 0.0000000000000e+00 +341 316 -9.5619350000000e-01 +360 316 -1.0000000000000e+00 +363 316 1.0000000000000e+00 +371 316 1.0000000000000e+00 +374 316 3.1494540000000e+00 +375 316 1.2129980000000e+00 +339 317 0.0000000000000e+00 +342 317 -9.5619350000000e-01 +361 317 -1.0000000000000e+00 +364 317 1.0000000000000e+00 +371 317 1.0000000000000e+00 +374 317 -1.9859190000000e+00 +375 317 9.0706840000000e-01 +340 318 0.0000000000000e+00 +343 318 -9.5619350000000e-01 +362 318 -1.0000000000000e+00 +365 318 1.0000000000000e+00 +371 318 1.0000000000000e+00 +374 318 5.3936870000000e+00 +375 318 4.2274630000000e+00 +338 319 1.6796930000000e-01 +357 319 -1.0000000000000e+00 +339 320 8.3118580000000e-01 +358 320 -1.0000000000000e+00 +340 321 2.3079690000000e-01 +359 321 -1.0000000000000e+00 +363 322 4.9560030000000e-03 +364 322 2.0925110000000e-01 +365 322 4.3415660000000e-01 +366 322 6.1773840000000e+00 +385 322 -5.6864040000000e-03 +386 322 -2.4008990000000e-01 +387 322 -4.9814130000000e-01 +388 322 -1.0000000000000e+00 +367 323 1.0000000000000e+00 +372 323 -5.1899590000000e-02 +373 323 -2.2819930000000e-01 +376 323 -1.0000000000000e+00 +377 323 -1.0000000000000e+00 +378 323 -1.0000000000000e+00 +369 324 1.0000000000000e+00 +366 325 -6.1773840000000e+00 +372 325 1.0000000000000e+00 +388 325 1.0000000000000e+00 +373 326 1.0000000000000e+00 +360 327 2.2884660000000e+01 +363 327 6.4836370000000e-01 +370 327 1.0000000000000e+00 +372 327 1.0434500000000e+00 +373 327 4.2175860000000e-01 +385 327 -7.4391760000000e-01 +361 328 2.5197030000000e+00 +364 328 6.4836370000000e-01 +370 328 1.0000000000000e+00 +372 328 -3.4146640000000e-01 +373 328 3.7988980000000e-01 +386 328 -7.4391760000000e-01 +362 329 1.7727920000000e-02 +365 329 6.4836370000000e-01 +370 329 1.0000000000000e+00 +372 329 1.6460520000000e+00 +373 329 1.3054760000000e+00 +387 329 -7.4391760000000e-01 +360 330 1.7492720000000e-01 +379 330 -1.0000000000000e+00 +361 331 8.1320190000000e-01 +380 331 -1.0000000000000e+00 +362 332 6.6961900000000e-01 +381 332 -1.0000000000000e+00 +87 333 6.3180580000000e+00 +93 333 1.0081210000000e+00 +88 334 2.1016520000000e+00 +94 334 9.8325000000000e-01 +89 335 1.0216340000000e+01 +95 335 9.7112200000000e-01 +90 336 4.7715330000000e+00 +96 336 1.0168970000000e+00 +91 337 1.5445530000000e+00 +97 337 9.6515200000000e-01 +92 338 7.4032580000000e+00 +98 338 9.3991980000000e-01 +99 339 2.7676480000000e+02 +105 339 8.8770670000000e-01 +100 340 1.9219040000000e+02 +106 340 1.2620630000000e+00 +101 341 4.6529740000000e+02 +107 341 8.3730050000000e-01 +102 342 4.0263530000000e+02 +108 342 9.3272340000000e-01 +103 343 2.4395160000000e+02 +109 343 1.1570060000000e+00 +104 344 6.9442570000000e+02 +110 344 9.0252430000000e-01 +111 345 2.1471690000000e+00 +117 345 7.3310410000000e-01 +112 346 1.8303540000000e+00 +118 346 7.7070690000000e-01 +113 347 5.4194960000000e+00 +119 347 9.1067970000000e-01 +114 348 1.5934600000000e+00 +120 348 4.4472830000000e-01 +115 349 1.5193590000000e+00 +121 349 5.2296010000000e-01 +116 350 5.9272710000000e+00 +122 350 8.1417070000000e-01 +123 351 8.6013230000000e+00 +129 351 5.8171510000000e-01 +124 352 6.1974850000000e+00 +130 352 5.3220720000000e-01 +125 353 3.7670330000000e+01 +131 353 1.1683300000000e+00 +126 354 1.0955350000000e+01 +132 354 7.4939930000000e-01 +127 355 8.2864270000000e+00 +133 355 7.1973830000000e-01 +128 356 3.5092930000000e+01 +134 356 1.1008490000000e+00 +135 357 4.3389190000000e-01 +138 357 2.2797130000000e+00 +136 358 1.1375720000000e-01 +139 358 6.0698210000000e-01 +137 359 4.0354730000000e-01 +140 359 8.0049890000000e-03 +141 360 1.1577040000000e+00 +144 360 4.0422280000000e+00 +142 361 4.1932590000000e-01 +145 361 2.4496110000000e+00 +143 362 1.0246470000000e-01 +146 362 3.6475180000000e-01 +151 363 1.7257450000000e+02 +154 363 1.4917610000000e+01 +152 364 1.6158450000000e+02 +155 364 1.2093800000000e+01 +153 365 1.4531450000000e+02 +156 365 5.7400960000000e+00 +157 366 4.5018890000000e-03 +158 366 9.5263590000000e-01 +159 366 -1.0000000000000e+00 +158 367 9.4488160000000e-01 +163 367 1.9882060000000e+01 +164 367 1.5998700000000e+01 +165 367 7.7694990000000e+00 +159 368 1.0081400000000e+00 +163 368 9.8828980000000e+01 +164 368 1.4755580000000e+02 +165 368 1.3084370000000e+02 +160 369 1.0000000000000e+00 +163 369 1.8011980000000e+00 +161 370 1.0000000000000e+00 +164 370 2.1962210000000e+00 +162 371 1.0000000000000e+00 +165 371 2.0607380000000e+00 +163 372 1.9882060000000e+01 +166 372 9.7404530000000e-01 +164 373 1.5998700000000e+01 +167 373 9.3133780000000e-01 +165 374 7.7694990000000e+00 +168 374 8.2771400000000e-01 +169 375 -1.0000000000000e+00 +172 375 -1.0000000000000e+00 +175 375 5.6357910000000e-02 +176 375 5.6357910000000e-02 +177 375 5.6357910000000e-02 +170 376 -1.0000000000000e+00 +173 376 -1.0000000000000e+00 +175 376 7.3959730000000e-01 +176 376 7.3959730000000e-01 +177 376 7.3959730000000e-01 +171 377 -1.0000000000000e+00 +174 377 -1.0000000000000e+00 +175 377 2.0404480000000e-01 +176 377 2.0404480000000e-01 +177 377 2.0404480000000e-01 +172 378 1.0000000000000e+00 +175 378 -1.0000000000000e+00 +173 379 1.0000000000000e+00 +176 379 -1.0000000000000e+00 +174 380 1.0000000000000e+00 +177 380 -1.0000000000000e+00 +175 381 1.0000000000000e+00 +178 381 1.0000000000000e+00 +176 382 1.0000000000000e+00 +179 382 1.0000000000000e+00 +177 383 1.0000000000000e+00 +180 383 1.0000000000000e+00 +102 384 -1.9453890000000e+01 +418 384 1.0000000000000e+00 +424 384 -9.5304210000000e-02 +103 385 -2.2090310000000e+01 +419 385 1.0000000000000e+00 +424 385 -8.8197620000000e-02 +104 386 -4.9563590000000e+01 +420 386 1.0000000000000e+00 +424 386 -1.0690420000000e-04 +421 387 1.7973450000000e+02 +422 387 -2.5957400000000e+00 +422 388 1.0000000000000e+00 +423 388 -9.6216520000000e-02 +102 389 -1.0000000000000e+00 +103 389 -1.0000000000000e+00 +104 389 -1.0000000000000e+00 +423 389 9.6216520000000e-02 +424 389 -8.8937280000000e-03 +126 390 9.3082790000000e-01 +127 390 9.3082790000000e-01 +128 390 9.3082790000000e-01 +425 390 -1.1383520000000e+00 +436 390 9.5341780000000e-02 +126 391 8.1769790000000e-01 +426 391 -5.5083520000000e-01 +436 391 4.6134780000000e-02 +127 392 8.1769790000000e-01 +427 392 -4.4892230000000e-01 +436 392 3.7599150000000e-02 +128 393 6.8068650000000e+00 +428 393 -2.0188420000000e-03 +436 393 1.6908660000000e-04 +429 394 -6.0313590000000e-01 +430 394 -1.1914260000000e+00 +431 394 -2.0901010000000e-01 +432 394 -2.3236640000000e-01 +126 395 -1.5881990000000e+00 +430 395 1.0000000000000e+00 +436 395 -8.9606730000000e-02 +127 396 -1.7894780000000e+00 +431 396 1.0000000000000e+00 +436 396 -8.2283250000000e-02 +128 397 -4.0128040000000e+00 +432 397 1.0000000000000e+00 +436 397 -9.9680420000000e-05 +433 398 1.1868740000000e+00 +435 398 -8.7134320000000e-01 +434 399 9.9186010000000e-01 +435 399 -7.3414950000000e-01 +126 400 -1.0000000000000e+00 +127 400 -1.0000000000000e+00 +128 400 -1.0000000000000e+00 +435 400 8.9782490000000e-01 +436 400 -1.0242690000000e-01 +185 401 2.6330250000000e+02 +188 401 1.6710230000000e+01 +186 402 2.5231250000000e+02 +189 402 1.5091380000000e+01 +187 403 2.3604250000000e+02 +190 403 1.1440290000000e+01 +191 404 6.8429330000000e-03 +192 404 9.6227440000000e-01 +193 404 -1.0000000000000e+00 +192 405 9.5486020000000e-01 +197 405 3.5042120000000e+01 +198 405 2.8167190000000e+01 +199 405 1.3668540000000e+01 +193 406 1.0077050000000e+00 +197 406 8.5846760000000e+01 +198 406 1.4416210000000e+02 +199 406 1.3040540000000e+02 +194 407 1.0000000000000e+00 +197 407 1.6589050000000e+00 +195 408 1.0000000000000e+00 +198 408 2.1064970000000e+00 +196 409 1.0000000000000e+00 +199 409 2.0009090000000e+00 +197 410 3.5042120000000e+01 +200 410 1.0000000000000e+00 +198 411 2.8167190000000e+01 +201 411 9.7782690000000e-01 +199 412 1.3668540000000e+01 +202 412 9.1623940000000e-01 +203 413 -1.0000000000000e+00 +206 413 -1.0000000000000e+00 +209 413 3.4351900000000e-03 +210 413 3.4351900000000e-03 +211 413 3.4351900000000e-03 +204 414 -1.0000000000000e+00 +207 414 -1.0000000000000e+00 +209 414 4.3016970000000e-02 +210 414 4.3016970000000e-02 +211 414 4.3016970000000e-02 +205 415 -1.0000000000000e+00 +208 415 -1.0000000000000e+00 +209 415 9.5354780000000e-01 +210 415 9.5354780000000e-01 +211 415 9.5354780000000e-01 +206 416 1.0000000000000e+00 +209 416 -1.0000000000000e+00 +207 417 1.0000000000000e+00 +210 417 -1.0000000000000e+00 +208 418 1.0000000000000e+00 +211 418 -1.0000000000000e+00 +209 419 1.0000000000000e+00 +212 419 1.0000000000000e+00 +210 420 1.0000000000000e+00 +213 420 1.0000000000000e+00 +211 421 1.0000000000000e+00 +214 421 1.0000000000000e+00 +90 422 -4.7613130000000e-02 +461 422 1.0000000000000e+00 +467 422 -2.3334700000000e-05 +91 423 -5.7464350000000e-02 +462 423 1.0000000000000e+00 +467 423 -3.5266560000000e-04 +92 424 -1.2956040000000e-01 +463 424 1.0000000000000e+00 +467 424 -1.7625420000000e-02 +464 425 2.7046250000000e+02 +465 425 -2.8000670000000e+00 +465 426 1.0000000000000e+00 +466 426 -1.6856930000000e+00 +90 427 -1.0000000000000e+00 +91 427 -1.0000000000000e+00 +92 427 -1.0000000000000e+00 +466 427 1.6856930000000e+00 +467 427 -1.4266740000000e-01 +114 428 1.2149740000000e-01 +115 428 1.2149740000000e-01 +116 428 1.2149740000000e-01 +468 428 -1.1383520000000e+00 +479 428 2.1230520000000e-02 +114 429 6.0555750000000e-01 +469 429 -1.9490180000000e-02 +479 429 3.6349630000000e-04 +115 430 3.3579270000000e-01 +470 430 -1.3533830000000e-01 +479 430 2.5240900000000e-03 +116 431 1.0673090000000e-01 +471 431 -9.5354780000000e-01 +479 431 1.7783880000000e-02 +472 432 -9.0759220000000e-01 +473 432 -5.7118220000000e+00 +474 432 -9.3568410000000e-01 +475 432 -1.0346550000000e+00 +114 433 -4.3240930000000e-02 +473 433 1.0000000000000e+00 +479 433 -2.5956110000000e-05 +115 434 -5.2174910000000e-02 +474 434 1.0000000000000e+00 +479 434 -3.9218900000000e-04 +116 435 -1.1763140000000e-01 +475 435 1.0000000000000e+00 +479 435 -1.9600160000000e-02 +476 436 5.3140780000000e+00 +478 436 -1.0021840000000e+00 +477 437 3.4483720000000e-01 +478 437 -2.6478620000000e-01 +114 438 -1.0000000000000e+00 +115 438 -1.0000000000000e+00 +116 438 -1.0000000000000e+00 +478 438 1.7669710000000e+00 +479 438 -1.7474060000000e-01 +438 439 9.9149730000000e+01 +444 439 -1.0000000000000e+00 +447 439 -3.3113980000000e-05 +439 440 1.7263960000000e+02 +445 440 -1.0000000000000e+00 +448 440 -4.1108120000000e-05 +440 441 3.5663980000000e+02 +446 441 -1.0000000000000e+00 +449 441 -8.4587180000000e-05 +441 442 2.0000080000000e+02 +444 442 2.5000000000000e+00 +447 442 3.3113980000000e-05 +442 443 3.4900330000000e+02 +445 443 2.5000000000000e+00 +448 443 4.1108120000000e-05 +443 444 7.2206780000000e+02 +446 444 2.5000000000000e+00 +449 444 8.4587180000000e-05 +444 445 1.0000000000000e+00 +453 445 -1.4485650000000e-06 +445 446 1.0000000000000e+00 +453 446 -5.1132920000000e-04 +446 447 1.0000000000000e+00 +453 447 -9.5438870000000e-01 +447 448 1.0050250000000e+00 +454 448 -3.4351900000000e-03 +448 449 1.0028740000000e+00 +454 449 -4.3016970000000e-02 +449 450 1.0013870000000e+00 +454 450 -9.5354780000000e-01 +450 451 1.0000000000000e+00 +453 451 -4.9455600000000e-05 +451 452 1.0000000000000e+00 +453 452 -2.1775570000000e-03 +452 453 1.0000000000000e+00 +453 453 -4.2871530000000e-02 +453 454 1.0000000000000e+00 +455 454 -1.0000000000000e+00 +466 454 1.5000000000000e+00 +478 454 5.0000000000000e-01 +454 455 1.0000000000000e+00 +456 455 -3.1622000000000e+05 +459 455 -1.2132580000000e+04 +460 455 -1.0000000000000e+00 +466 455 -2.0451810000000e+04 +477 455 9.1527510000000e+03 +455 456 9.1463570000000e+00 +457 456 3.7734920000000e-03 +456 457 2.2487060000000e+03 +457 457 -1.2505330000000e-01 +457 458 6.7588380000000e-02 +458 458 6.5087120000000e+01 +466 458 -1.8859040000000e-01 +458 459 -9.1527510000000e+03 +460 459 7.5439430000000e-01 +476 459 -9.1527510000000e+03 +477 459 -6.9047830000000e+03 +459 460 1.0000000000000e+00 +466 460 1.8569290000000e-01 +478 460 -5.0000000000000e-01 +460 461 1.9167940000000e-04 +466 461 2.6684520000000e+00 +478 461 8.8948400000000e-01 +266 462 5.2397100000000e-01 +269 462 2.5902730000000e+00 +267 463 1.2090360000000e-01 +270 463 1.0000000000000e+00 +268 464 3.6607730000000e-01 +271 464 1.8323330000000e-02 +288 465 5.3070830000000e-01 +291 465 2.6120320000000e+00 +289 466 1.2143810000000e-01 +292 466 1.0000000000000e+00 +290 467 3.6327480000000e-01 +293 467 1.9398480000000e-02 +310 468 5.3114850000000e-01 +313 468 2.6134470000000e+00 +311 469 1.2147310000000e-01 +314 469 1.0000000000000e+00 +312 470 3.6309170000000e-01 +315 470 1.9470450000000e-02 +332 471 5.3131620000000e-01 +335 471 2.6139860000000e+00 +333 472 1.2148640000000e-01 +336 472 1.0000000000000e+00 +334 473 3.6302190000000e-01 +337 473 1.9497930000000e-02 +354 474 5.3753340000000e-01 +357 474 2.6338800000000e+00 +355 475 1.2197960000000e-01 +358 475 1.0000000000000e+00 +356 476 3.6043580000000e-01 +359 476 2.0538460000000e-02 +376 477 7.1092830000000e-01 +379 477 3.1304670000000e+00 +377 478 1.3573580000000e-01 +380 478 1.0000000000000e+00 +378 479 2.8830910000000e-01 +381 479 7.1489880000000e-02 diff -r dc3ee9616267 -r fa2cdef14442 examples/module.mk --- a/examples/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/examples/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,84 +1,9 @@ %canon_reldir%_EXTRA_DIST = -%canon_reldir%_CLEANFILES = -%canon_reldir%_DISTCLEANFILES = -%canon_reldir%_MAINTAINERCLEANFILES = - -%canon_reldir%_data_SRC = \ - %reldir%/data/penny.mat - -octdata_DATA += \ - $(%canon_reldir%_data_SRC) - -%canon_reldir%_code_SRC = \ - %reldir%/code/@FIRfilter/FIRfilter.m \ - %reldir%/code/@FIRfilter/FIRfilter_aggregation.m \ - %reldir%/code/@FIRfilter/display.m \ - %reldir%/code/@FIRfilter/subsasgn.m \ - %reldir%/code/@FIRfilter/subsref.m \ - %reldir%/code/@polynomial/disp.m \ - %reldir%/code/@polynomial/double.m \ - %reldir%/code/@polynomial/end.m \ - %reldir%/code/@polynomial/get.m \ - %reldir%/code/@polynomial/mtimes.m \ - %reldir%/code/@polynomial/numel.m \ - %reldir%/code/@polynomial/plot.m \ - %reldir%/code/@polynomial/polynomial.m \ - %reldir%/code/@polynomial/polynomial_superiorto.m \ - %reldir%/code/@polynomial/polyval.m \ - %reldir%/code/@polynomial/roots.m \ - %reldir%/code/@polynomial/set.m \ - %reldir%/code/@polynomial/subsasgn.m \ - %reldir%/code/@polynomial/subsref.m \ - %reldir%/code/addtwomatrices.cc \ - %reldir%/code/celldemo.cc \ - %reldir%/code/embedded.cc \ - %reldir%/code/fortrandemo.cc \ - %reldir%/code/fortransub.f \ - %reldir%/code/funcdemo.cc \ - %reldir%/code/globaldemo.cc \ - %reldir%/code/helloworld.cc \ - %reldir%/code/make_int.cc \ - %reldir%/code/mex_demo.c \ - %reldir%/code/mycell.c \ - %reldir%/code/myfeval.c \ - %reldir%/code/myfevalf.f \ - %reldir%/code/myfunc.c \ - %reldir%/code/myhello.c \ - %reldir%/code/mypow2.c \ - %reldir%/code/myprop.c \ - %reldir%/code/myset.c \ - %reldir%/code/mysparse.c \ - %reldir%/code/mystring.c \ - %reldir%/code/mystruct.c \ - %reldir%/code/oct_demo.cc \ - %reldir%/code/oregonator.cc \ - %reldir%/code/oregonator.m \ - %reldir%/code/paramdemo.cc \ - %reldir%/code/polynomial2.m \ - %reldir%/code/standalone.cc \ - %reldir%/code/standalonebuiltin.cc \ - %reldir%/code/stringdemo.cc \ - %reldir%/code/structdemo.cc \ - %reldir%/code/unwinddemo.cc +include %reldir%/code/module.mk +include %reldir%/data/module.mk %canon_reldir%_EXTRA_DIST += \ - $(%canon_reldir%_data_SRC) \ - $(%canon_reldir%_code_SRC) \ - %reldir%/code/COPYING \ - %reldir%/module.mk + %reldir%/code/COPYING EXTRA_DIST += $(%canon_reldir%_EXTRA_DIST) - -CLEANFILES += $(%canon_reldir%_CLEANFILES) -DISTCLEANFILES += $(%canon_reldir%_DISTCLEANFILES) -MAINTAINERCLEANFILES += $(%canon_reldir%_MAINTAINERCLEANFILES) - -examples-clean: - rm -f $(%canon_reldir%_CLEANFILES) - -examples-distclean: examples-clean - rm -f $(%canon_reldir%_DISTCLEANFILES) - -examples-maintainer-clean: examples-distclean - rm -f $(%canon_reldir%_MAINTAINERCLEANFILES) diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/BaseControl.cc --- a/libgui/graphics/BaseControl.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/BaseControl.cc Thu Nov 19 13:08:00 2020 -0800 @@ -50,18 +50,30 @@ if (props.style_is ("edit") || props.style_is ("listbox")) { - p.setColor (QPalette::Base, - Utils::fromRgb (props.get_backgroundcolor_rgb ())); - p.setColor (QPalette::Text, + Matrix bg_color = props.get_backgroundcolor_rgb (); + // Matlab compatibility: Default color is ignored, and rendered as + // white ([1.0, 1.0, 1.0]). See bug #58261. + if (bg_color(0) == bg_color(1) && bg_color(0) == bg_color(2) + && (std::abs (bg_color(1) - 0.94) < .005)) + bg_color.fill (1.0); + + p.setColor (QPalette::Active, QPalette::Base, + Utils::fromRgb (bg_color)); + p.setColor (QPalette::Inactive, QPalette::Base, + Utils::fromRgb (bg_color)); + p.setColor (QPalette::Active, QPalette::Text, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::Text, Utils::fromRgb (props.get_foregroundcolor_rgb ())); } else if (props.style_is ("popupmenu")) { - // popumenu (QComboBox) is a listbox with a button, so needs set colors for both + // popupmenu (QComboBox) is a listbox with a button. + // This requires setting colors for both. QColor bcol = Utils::fromRgb (props.get_backgroundcolor_rgb ()); QColor fcol = Utils::fromRgb (props.get_foregroundcolor_rgb ()); - QString qss = QString ("background: %1 none;\n" - "color: %2;") + QString qss = QString (":enabled { background: %1 none;\n" + "color: %2; }") .arg(bcol.name ()).arg (fcol.name ()); w->setStyleSheet(qss); return; @@ -69,9 +81,13 @@ else if (props.style_is ("radiobutton") || props.style_is ("checkbox")) { - p.setColor (QPalette::Button, + p.setColor (QPalette::Active, QPalette::Button, + Utils::fromRgb (props.get_backgroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::Button, Utils::fromRgb (props.get_backgroundcolor_rgb ())); - p.setColor (QPalette::WindowText, + p.setColor (QPalette::Active, QPalette::WindowText, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::WindowText, Utils::fromRgb (props.get_foregroundcolor_rgb ())); } else if (props.style_is ("pushbutton") @@ -79,17 +95,21 @@ { QColor bcol = Utils::fromRgb (props.get_backgroundcolor_rgb ()); QColor fcol = Utils::fromRgb (props.get_foregroundcolor_rgb ()); - QString qss = QString ("background: %1 none;\n" - "color: %2;") + QString qss = QString (":enabled { background: %1 none;\n" + "color: %2; }") .arg(bcol.name ()).arg (fcol.name ()); w->setStyleSheet(qss); return; } else { - p.setColor (QPalette::Window, + p.setColor (QPalette::Active, QPalette::Window, + Utils::fromRgb (props.get_backgroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::Window, Utils::fromRgb (props.get_backgroundcolor_rgb ())); - p.setColor (QPalette::WindowText, + p.setColor (QPalette::Active, QPalette::WindowText, + Utils::fromRgb (props.get_foregroundcolor_rgb ())); + p.setColor (QPalette::Inactive, QPalette::WindowText, Utils::fromRgb (props.get_foregroundcolor_rgb ())); } @@ -119,7 +139,10 @@ octave::math::round (bb(2)), octave::math::round (bb(3))); w->setFont (Utils::computeFont (up, bb(3))); updatePalette (up, w); - w->setEnabled (up.enable_is ("on")); + if (up.enable_is ("inactive")) + w->blockSignals (true); + else + w->setEnabled (up.enable_is ("on")); w->setToolTip (Utils::fromStdString (up.get_tooltipstring ())); w->setVisible (up.is_visible ()); m_keyPressHandlerDefined = ! up.get_keypressfcn ().isempty (); @@ -174,7 +197,16 @@ break; case uicontrol::properties::ID_ENABLE: - w->setEnabled (up.enable_is ("on")); + if (up.enable_is ("inactive")) + { + w->blockSignals (true); + w->setEnabled (true); + } + else + { + w->blockSignals (false); + w->setEnabled (up.enable_is ("on")); + } break; case uicontrol::properties::ID_TOOLTIPSTRING: diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/Canvas.cc Thu Nov 19 13:08:00 2020 -0800 @@ -371,11 +371,7 @@ r.adjust (-5, -5, 5, 5); -#if defined (HAVE_QMOUSEEVENT_LOCALPOS) bool rect_contains_pos = r.contains (event->localPos ()); -#else - bool rect_contains_pos = r.contains (event->posF ()); -#endif if (rect_contains_pos) { currentObj = childObj; @@ -429,11 +425,7 @@ // the axes and still select it. r.adjust (-20, -20, 20, 20); -#if defined (HAVE_QMOUSEEVENT_LOCALPOS) bool rect_contains_pos = r.contains (event->localPos ()); -#else - bool rect_contains_pos = r.contains (event->posF ()); -#endif if (rect_contains_pos) axesObj = *it; } @@ -885,7 +877,7 @@ props.prepend (figObj.get_handle ().as_octave_value ()); emit interpreter_event - ([this, props] (octave::interpreter& interp) + ([=] (octave::interpreter& interp) { // INTERPRETER THREAD diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/CheckBoxControl.cc --- a/libgui/graphics/CheckBoxControl.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/CheckBoxControl.cc Thu Nov 19 13:08:00 2020 -0800 @@ -61,10 +61,37 @@ const graphics_object& go, QCheckBox *box) : ButtonControl (oct_obj, interp, go, box) { + uicontrol::properties& up = properties (); + box->setAutoFillBackground (true); + if (up.enable_is ("inactive")) + box->setCheckable (false); } CheckBoxControl::~CheckBoxControl (void) { } + void + CheckBoxControl::update (int pId) + { + uicontrol::properties& up = properties (); + QCheckBox *box = qWidget (); + + switch (pId) + { + case uicontrol::properties::ID_ENABLE: + { + if (up.enable_is ("inactive")) + box->setCheckable (false); + else + box->setCheckable (true); + ButtonControl::update (pId); + } + break; + + default: + ButtonControl::update (pId); + break; + } + } }; diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/CheckBoxControl.h --- a/libgui/graphics/CheckBoxControl.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/CheckBoxControl.h Thu Nov 19 13:08:00 2020 -0800 @@ -50,6 +50,9 @@ static CheckBoxControl * create (octave::base_qobject& oct_qobj, octave::interpreter& interp, const graphics_object& go); + + protected: + void update (int pId); }; } diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/EditControl.cc --- a/libgui/graphics/EditControl.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/EditControl.cc Thu Nov 19 13:08:00 2020 -0800 @@ -85,6 +85,10 @@ uicontrol::properties& up = properties (); + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + edit->setEnabled (up.enable_is ("on")); edit->setText (Utils::fromStdString (up.get_string_string ())); edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), up.get_verticalalignment ())); @@ -117,9 +121,15 @@ uicontrol::properties& up = properties (); + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + edit->setEnabled (up.enable_is ("on")); edit->setAcceptRichText (false); edit->setPlainText (Utils::fromStringVector (up.get_string_vector ()).join ("\n")); + edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); connect (edit, SIGNAL (textChanged (void)), SLOT (textChanged (void))); @@ -177,6 +187,16 @@ up.get_verticalalignment ())); return true; + case uicontrol::properties::ID_ENABLE: + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + { + edit->setReadOnly (false); + edit->setEnabled (up.enable_is ("on")); + } + return true; + case uicontrol::properties::ID_MIN: case uicontrol::properties::ID_MAX: if ((up.get_max () - up.get_min ()) > 1) @@ -208,6 +228,22 @@ (up.get_string_vector ()).join ("\n")); return true; + case uicontrol::properties::ID_HORIZONTALALIGNMENT: + case uicontrol::properties::ID_VERTICALALIGNMENT: + edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), + up.get_verticalalignment ())); + return true; + + case uicontrol::properties::ID_ENABLE: + if (up.enable_is ("inactive")) + edit->setReadOnly (true); + else + { + edit->setReadOnly (false); + edit->setEnabled (up.enable_is ("on")); + } + return true; + case uicontrol::properties::ID_MIN: case uicontrol::properties::ID_MAX: if ((up.get_max () - up.get_min ()) <= 1) diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/GLCanvas.cc --- a/libgui/graphics/GLCanvas.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/GLCanvas.cc Thu Nov 19 13:08:00 2020 -0800 @@ -188,7 +188,7 @@ catch (octave::execution_exception& ee) { emit interpreter_event - ([ee] (void) + ([=] (void) { // INTERPRETER THREAD diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/PushButtonControl.cc --- a/libgui/graphics/PushButtonControl.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/PushButtonControl.cc Thu Nov 19 13:08:00 2020 -0800 @@ -71,6 +71,7 @@ QImage img = Utils::makeImageFromCData (cdat, cdat.columns (), cdat.rows ()); btn->setIcon (QIcon (QPixmap::fromImage (img))); + btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); } PushButtonControl::~PushButtonControl (void) diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/QtHandlesUtils.cc --- a/libgui/graphics/QtHandlesUtils.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/QtHandlesUtils.cc Thu Nov 19 13:08:00 2020 -0800 @@ -288,8 +288,12 @@ int w = qMin (dv(1), static_cast (width)); int h = qMin (dv(0), static_cast (height)); - int x_off = (w < width ? (width - w) / 2 : 0); - int y_off = (h < height ? (height - h) / 2 : 0); + // If size mismatch, take data from center of CDATA and + // place in in center of QImage. + int x_img_off = (w < width ? (width - w) / 2 : 0); + int y_img_off = (h < height ? (height - h) / 2 : 0); + int x_cdat_off = (dv(1) > w ? (dv(1) - w) / 2 : 0); + int y_cdat_off = (dv(0) > h ? (dv(0) - h) / 2 : 0); QImage img (width, height, QImage::Format_ARGB32); img.fill (qRgba (0, 0, 0, 0)); @@ -298,23 +302,25 @@ { uint8NDArray d = v.uint8_array_value (); - for (int i = 0; i < w; i++) - for (int j = 0; j < h; j++) + for (int i = x_cdat_off; i < w + x_cdat_off; i++) + for (int j = y_cdat_off; j < h + y_cdat_off; j++) { int r = d(j, i, 0); int g = d(j, i, 1); int b = d(j, i, 2); int a = 255; - img.setPixel (x_off + i, y_off + j, qRgba (r, g, b, a)); + img.setPixel (x_img_off + i - x_cdat_off, + y_img_off + j - y_cdat_off, + qRgba (r, g, b, a)); } } else if (v.is_single_type ()) { FloatNDArray f = v.float_array_value (); - for (int i = 0; i < w; i++) - for (int j = 0; j < h; j++) + for (int i = x_cdat_off; i < w + x_cdat_off; i++) + for (int j = y_cdat_off; j < h + y_cdat_off; j++) { float r = f(j, i, 0); float g = f(j, i, 1); @@ -322,7 +328,8 @@ int a = (octave::math::isnan (r) || octave::math::isnan (g) || octave::math::isnan (b) ? 0 : 255); - img.setPixel (x_off + i, y_off + j, + img.setPixel (x_img_off + i - x_cdat_off, + y_img_off + j - y_cdat_off, qRgba (octave::math::round (r * 255), octave::math::round (g * 255), octave::math::round (b * 255), @@ -333,8 +340,8 @@ { NDArray d = v.array_value (); - for (int i = 0; i < w; i++) - for (int j = 0; j < h; j++) + for (int i = x_cdat_off; i < w + x_cdat_off; i++) + for (int j = y_cdat_off; j < h + y_cdat_off; j++) { double r = d(j, i, 0); double g = d(j, i, 1); @@ -342,7 +349,8 @@ int a = (octave::math::isnan (r) || octave::math::isnan (g) || octave::math::isnan (b) ? 0 : 255); - img.setPixel (x_off + i, y_off + j, + img.setPixel (x_img_off + i - x_cdat_off, + y_img_off + j - y_cdat_off, qRgba (octave::math::round (r * 255), octave::math::round (g * 255), octave::math::round (b * 255), @@ -394,12 +402,7 @@ // We assume a standard mouse with 15 degree steps and Qt returns // 1/8 of a degree. -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) int ydelta = -(event->angleDelta().y ()); -#else - int ydelta = (event->orientation () == Qt::Vertical - ? -(event->delta ()) : 0); -#endif retval.setfield ("VerticalScrollCount", octave_value (ydelta / 120)); // FIXME: Is there any way to access the number of lines a scroll step diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/RadioButtonControl.cc --- a/libgui/graphics/RadioButtonControl.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/RadioButtonControl.cc Thu Nov 19 13:08:00 2020 -0800 @@ -69,11 +69,39 @@ if (btnGroup) btnGroup->addButton (radio); + uicontrol::properties& up = properties (); + radio->setAutoFillBackground (true); radio->setAutoExclusive (false); + if (up.enable_is ("inactive")) + radio->setCheckable (false); } RadioButtonControl::~RadioButtonControl (void) { } + void + RadioButtonControl::update (int pId) + { + uicontrol::properties& up = properties (); + QRadioButton *btn = qWidget (); + + switch (pId) + { + case uicontrol::properties::ID_ENABLE: + { + if (up.enable_is ("inactive")) + btn->setCheckable (false); + else + btn->setCheckable (true); + ButtonControl::update (pId); + } + break; + + default: + ButtonControl::update (pId); + break; + } + } + }; diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/RadioButtonControl.h --- a/libgui/graphics/RadioButtonControl.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/RadioButtonControl.h Thu Nov 19 13:08:00 2020 -0800 @@ -50,6 +50,9 @@ static RadioButtonControl * create (octave::base_qobject& oct_qobj, octave::interpreter& interp, const graphics_object& go); + + protected: + void update (int pId); }; } diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/Table.cc --- a/libgui/graphics/Table.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/Table.cc Thu Nov 19 13:08:00 2020 -0800 @@ -1321,11 +1321,7 @@ : QAbstractItemView::NoSelection); // Set rearrangeablecolumns - #if defined (HAVE_QT4) - m_tableWidget->horizontalHeader ()->setMovable (enabled && rearrangeableColumns); - #elif defined (HAVE_QT5) - m_tableWidget->horizontalHeader ()->setSectionsMovable (enabled && rearrangeableColumns); - #endif + m_tableWidget->horizontalHeader ()->setSectionsMovable (enabled && rearrangeableColumns); m_tableWidget->horizontalHeader ()->setDragEnabled (enabled && rearrangeableColumns); m_tableWidget->horizontalHeader ()->setDragDropMode (QAbstractItemView::InternalMove); @@ -1504,11 +1500,7 @@ bool rearrangeableColumns = tp.is_rearrangeablecolumns (); bool enabled = tp.is_enable (); - #if defined (HAVE_QT4) - m_tableWidget->horizontalHeader ()->setMovable (enabled && rearrangeableColumns); - #elif defined (HAVE_QT5) m_tableWidget->horizontalHeader ()->setSectionsMovable (enabled && rearrangeableColumns); - #endif m_tableWidget->horizontalHeader ()->setDragEnabled (enabled && rearrangeableColumns); m_tableWidget->horizontalHeader ()->setDragDropMode (QAbstractItemView::InternalMove); } diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/ToggleButtonControl.cc --- a/libgui/graphics/ToggleButtonControl.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/ToggleButtonControl.cc Thu Nov 19 13:08:00 2020 -0800 @@ -77,6 +77,7 @@ QImage img = Utils::makeImageFromCData (cdat, cdat.columns (), cdat.rows ()); btn->setIcon (QIcon (QPixmap::fromImage (img))); + btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); } ToggleButtonControl::~ToggleButtonControl (void) diff -r dc3ee9616267 -r fa2cdef14442 libgui/graphics/ToolBarButton.cc --- a/libgui/graphics/ToolBarButton.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/graphics/ToolBarButton.cc Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ action->setVisible (tp.is_visible ()); // Get the icon data from cdata or as a named icon - QImage img = Utils::makeImageFromCData (tp.get_cdata (), 32, 32); + QImage img = Utils::makeImageFromCData (tp.get_cdata (), 24, 24); if (img.width () == 0) { @@ -104,7 +104,7 @@ case T::properties::ID_CDATA: { // Get the icon data from cdata or as a named icon - QImage img = Utils::makeImageFromCData (tp.get_cdata (), 32, 32); + QImage img = Utils::makeImageFromCData (tp.get_cdata (), 24, 24); if (img.width () == 0) { diff -r dc3ee9616267 -r fa2cdef14442 libgui/qterminal/libqterminal/unix/TerminalView.cpp diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/files-dock-widget.cc --- a/libgui/src/files-dock-widget.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/files-dock-widget.cc Thu Nov 19 13:08:00 2020 -0800 @@ -245,16 +245,8 @@ (settings->value (fb_column_state.key).toByteArray ()); // Set header properties for sorting -#if defined (HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE) m_file_tree_view->header ()->setSectionsClickable (true); -#else - m_file_tree_view->header ()->setClickable (true); -#endif -#if defined (HAVE_QHEADERVIEW_SETSECTIONSMOVABLE) m_file_tree_view->header ()->setSectionsMovable (true); -#else - m_file_tree_view->header ()->setMovable (true); -#endif m_file_tree_view->header ()->setSortIndicatorShown (true); QStringList mru_dirs = @@ -723,17 +715,38 @@ QItemSelectionModel *m = m_file_tree_view->selectionModel (); QModelIndexList rows = m->selectedRows (); + int file_cnt = rows.size (); + bool multiple_files = (file_cnt > 1); + for (auto it = rows.begin (); it != rows.end (); it++) { QModelIndex index = *it; QFileInfo info = m_file_system_model->fileInfo (index); - if (QMessageBox::question (this, tr ("Delete file/directory"), - tr ("Are you sure you want to delete\n") - + info.filePath (), - QMessageBox::Yes | QMessageBox::No) - == QMessageBox::Yes) + QMessageBox::StandardButton dlg_answer; + if (multiple_files) + if (it == rows.begin ()) + { + dlg_answer = QMessageBox::question (this, + tr ("Delete file/directory"), + tr ("Are you sure you want to delete all %1 selected files?\n").arg (file_cnt), + QMessageBox::Yes | QMessageBox::No); + if (dlg_answer != QMessageBox::Yes) + return; + } + else + dlg_answer = QMessageBox::Yes; + else + { + dlg_answer = QMessageBox::question (this, + tr ("Delete file/directory"), + tr ("Are you sure you want to delete\n") + + info.filePath (), + QMessageBox::Yes | QMessageBox::No); + } + + if (dlg_answer) { if (info.isDir ()) { diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/find-files-dialog.cc --- a/libgui/src/find-files-dialog.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/find-files-dialog.cc Thu Nov 19 13:08:00 2020 -0800 @@ -126,11 +126,7 @@ m_file_list->setSortingEnabled (true); m_file_list->horizontalHeader ()->restoreState (settings->value (ff_column_state.key).toByteArray ()); m_file_list->horizontalHeader ()->setSortIndicatorShown (true); -#if defined (HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE) m_file_list->horizontalHeader ()->setSectionsClickable (true); -#else - m_file_list->horizontalHeader ()->setClickable (true); -#endif m_file_list->horizontalHeader ()->setStretchLastSection (true); m_file_list->sortByColumn (settings->value (ff_sort_files_by_column).toInt (), static_cast diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/graphics-init.cc --- a/libgui/src/graphics-init.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/graphics-init.cc Thu Nov 19 13:08:00 2020 -0800 @@ -63,7 +63,7 @@ graphics_toolkit tk (qt_gtk); - octave::gtk_manager& gtk_mgr = interp.get_gtk_manager (); + gtk_manager& gtk_mgr = interp.get_gtk_manager (); gtk_mgr.register_toolkit ("qt"); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/gui-preferences-ed.h --- a/libgui/src/gui-preferences-ed.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/gui-preferences-ed.h Thu Nov 19 13:08:00 2020 -0800 @@ -215,6 +215,12 @@ const gui_pref ed_notebook_tab_width_max ("editor/notebook_tab_width_max", QVariant (300)); +const gui_pref +ed_force_newline ("editor/force_newline", QVariant (true)); + +const gui_pref +ed_rm_trailing_spaces ("editor/rm_trailing_spaces", QVariant (true)); + #if defined (HAVE_QSCINTILLA) #if defined (Q_OS_WIN32) const int os_eol_mode = QsciScintilla::EolWindows; diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/gui-preferences-global.h --- a/libgui/src/gui-preferences-global.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/gui-preferences-global.h Thu Nov 19 13:08:00 2020 -0800 @@ -136,4 +136,13 @@ const gui_pref global_proxy_pass ("proxyPassword", QVariant (QString ())); +const QStringList +global_proxy_all_types (QStringList () + << "HttpProxy" + << "Socks5Proxy" + << QT_TRANSLATE_NOOP ("octave::settings_dialog", "Environment Variables") +); +const QList +global_proxy_manual_types (QList () << 0 << 1); + #endif diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/gui-preferences-sc.h --- a/libgui/src/gui-preferences-sc.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/gui-preferences-sc.h Thu Nov 19 13:08:00 2020 -0800 @@ -96,6 +96,13 @@ const sc_pref sc_main_debug_continue (sc_main_debug + ":continue", PRE + Qt::Key_F5); const sc_pref sc_main_debug_quit (sc_main_debug + ":quit", PRE + Qt::ShiftModifier + Qt::Key_F5); +// tools +const QString sc_main_tools ("main_tools"); +const sc_pref sc_main_tools_start_profiler (sc_main_tools + ":start_profiler", CTRL_SHIFT + Qt::Key_P); +const sc_pref sc_main_tools_resume_profiler (sc_main_tools + ":resume_profiler", QKeySequence::UnknownKey); +const sc_pref sc_main_tools_show_profiler (sc_main_tools + ":show_profiler", Qt::AltModifier + Qt::ShiftModifier + Qt::Key_P); + + // window const QString sc_main_window ("main_window"); const sc_pref sc_main_window_show_command (sc_main_window + ":show_command", PRE + CTRL_SHIFT + Qt::Key_0); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/led-indicator.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/led-indicator.cc Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,83 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2013-2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include +#include "led-indicator.h" + +namespace octave +{ + + led_indicator::led_indicator (led_state initial_state, QWidget *p) + : QLabel (p) + { + setFixedSize(12,12); + set_state (initial_state); + } + + void led_indicator::set_state (led_state state) + { + QColor col (Qt::gray); + + switch (state) + { + case LED_STATE_NO: + break; + + case LED_STATE_INACTIVE: + col = QColor (Qt::darkRed); + break; + + case LED_STATE_ACTIVE: + col = QColor (Qt::darkGreen); + break; + } + + setStyleSheet (style_sheet (col)); + } + + QString led_indicator::style_sheet (const QColor& col) + { + int h, s, v; + + col.getHsv (&h, &s, &v); + s = s/4; + v = 232; + + QColor col_light = QColor::fromHsv (h,s,v); + + const QString style = QString ( + "border-radius: %1; background-color: " + "qlineargradient(spread:pad, x1:0.2, y1:0.2, x2:1, y2:1, stop:0 " + "%2, stop:1 %3);" + ).arg (width ()/2).arg (col_light.name ()).arg (col.name ()); + + return style; + } + +} \ No newline at end of file diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/led-indicator.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/led-indicator.h Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2013-2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (led_indicator_h) +#define led_indicator_h 1 + +#include + +namespace octave +{ + + class led_indicator: public QLabel + { + Q_OBJECT + + public: + + enum led_state + { + LED_STATE_NO = -1, + LED_STATE_INACTIVE, + LED_STATE_ACTIVE + }; + + led_indicator (led_state initial_state = LED_STATE_INACTIVE, + QWidget *parent = 0); + + public slots: + + void set_state (led_state state); + + private: + + QString style_sheet (const QColor& col); + + }; +} + +#endif \ No newline at end of file diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/m-editor/file-editor-tab.cc Thu Nov 19 13:08:00 2020 -0800 @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -430,7 +431,7 @@ if (ok && ! new_cond.isEmpty ()) { emit interpreter_event - ([this, line, new_cond] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -687,8 +688,11 @@ // Update settings, which are lexer related and have to be updated - // when a) the lexer changes or b) the settings have changed. - void file_editor_tab::update_lexer_settings (void) + // when + // a) the lexer changes, + // b) the settings have changed, or + // c) a package was loaded/unloaded + void file_editor_tab::update_lexer_settings (bool update_apis_only) { QsciLexer *lexer = m_edit_area->lexer (); @@ -759,7 +763,8 @@ // if the file is older than a few minutes preventing from // re-preparing data when the user opens several files. QDateTime apis_time = apis_file.lastModified (); - if (QDateTime::currentDateTime () > apis_time.addSecs (180)) + if (update_apis_only + || QDateTime::currentDateTime () > apis_time.addSecs (180)) update_apis = true; } @@ -791,10 +796,12 @@ // create raw apis info + m_lexer_apis->clear (); // Clear current contents + if (m_is_octave_file) { emit interpreter_event - ([this, octave_functions, octave_builtins] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -856,6 +863,9 @@ } } + if (update_apis_only) + return; // We are done here + lexer->readSettings (*settings); m_edit_area->setCaretForegroundColor (lexer->color (0)); @@ -1159,7 +1169,7 @@ bp_info info (m_file_name, line); emit interpreter_event - ([info] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1248,7 +1258,7 @@ bp_info info (m_file_name); emit interpreter_event - ([info] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1356,7 +1366,7 @@ void file_editor_tab::add_breakpoint_event (const bp_info& info) { emit interpreter_event - ([this, info] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1834,7 +1844,23 @@ QApplication::setOverrideCursor (Qt::WaitCursor); // read the file binary, decoding later - const QByteArray text_data = file.readAll (); + QByteArray text_data = file.readAll (); + + // remove newline at end of file if we add one again when saving + resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings *settings = rmgr.get_settings (); + + if (settings->value (ed_force_newline).toBool ()) + { + const QByteArray eol_lf = QByteArray (1,0x0a); + const QByteArray eol_cr = QByteArray (1,0x0d); + + if (text_data.endsWith (eol_lf)) + text_data.chop (1); // remove LF + + if (text_data.endsWith (eol_cr)) // remove CR (altogether CRLF, too) + text_data.chop (1); + } // decode QTextCodec::ConverterState st; @@ -2015,7 +2041,7 @@ // Create and queue the command object. emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -2078,7 +2104,7 @@ if (ans == QMessageBox::Save) { emit interpreter_event - ([this, file_to_save, base_name, remove_on_success, restore_breakpoints] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -2133,7 +2159,7 @@ QString base_name = file_info.baseName (); emit interpreter_event - ([this, file_to_save, base_name, remove_on_success, restore_breakpoints] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -2256,10 +2282,23 @@ if (! codec) return; // No valid codec + // Remove trailing white spaces if desired + resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings *settings = rmgr.get_settings (); + + if (settings->value (ed_rm_trailing_spaces).toBool ()) + m_edit_area->replace_all ("[ \\t]+$", "", true, false, false); + + // Save the file out.setCodec (codec); QApplication::setOverrideCursor (Qt::WaitCursor); + out << m_edit_area->text (); + if (settings->value (ed_force_newline).toBool () + && m_edit_area->text ().length ()) + out << m_edit_area->eol_string (); // Add newline if desired + out.flush (); QApplication::restoreOverrideCursor (); file.flush (); @@ -2476,9 +2515,6 @@ void file_editor_tab::handle_save_file_as_answer (const QString& saveFileName) { - if (m_save_as_desired_eol != m_edit_area->eolMode ()) - convert_eol (this,m_save_as_desired_eol); - if (saveFileName == m_file_name) { save_file (saveFileName); @@ -2495,13 +2531,6 @@ void file_editor_tab::handle_save_file_as_answer_close (const QString& saveFileName) { - if (m_save_as_desired_eol != m_edit_area->eolMode ()) - { - m_edit_area->setReadOnly (false); // was set to read-only in save_file_as - convert_eol (this,m_save_as_desired_eol); - m_edit_area->setReadOnly (true); // restore read-only mode - } - // saveFileName == m_file_name can not happen, because we only can get here // when we close a tab and m_file_name is not a valid filename yet @@ -3152,7 +3181,7 @@ // remember first visible line and x-offset for restoring the view afterwards int first_line = m_edit_area->firstVisibleLine (); - int x_offset = m_edit_area->SendScintilla(QsciScintillaBase::SCI_GETXOFFSET); + int x_offset = m_edit_area->SendScintilla (QsciScintillaBase::SCI_GETXOFFSET); // search for first occurrence of the detected word bool find_result_available @@ -3187,7 +3216,7 @@ // restore the visible area of the file, the cursor position, // and the selection m_edit_area->setFirstVisibleLine (first_line); - m_edit_area->SendScintilla(QsciScintillaBase::SCI_SETXOFFSET, x_offset); + m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETXOFFSET, x_offset); m_edit_area->setCursorPosition (line, col); m_edit_area->setSelection (line, col - wlen, line, col); m_edit_area->set_word_selection (word); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/m-editor/file-editor-tab.h Thu Nov 19 13:08:00 2020 -0800 @@ -204,6 +204,8 @@ void update_breakpoints_handler (const octave_value_list& argout); + void update_lexer_settings (bool update_apis_only = false); + private slots: // When user closes message box for decoding problems @@ -281,7 +283,6 @@ bool unchanged_or_saved (void); void update_lexer (void); - void update_lexer_settings (void); void show_dialog (QDialog *dlg, bool modal); public: diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/m-editor/file-editor.cc Thu Nov 19 13:08:00 2020 -0800 @@ -77,9 +77,7 @@ setTabsClosable (true); setUsesScrollButtons (true); -#if defined (HAVE_QTABWIDGET_SETMOVABLE) setMovable (true); -#endif } tab_bar * file_editor_tab_widget::get_tab_bar (void) const @@ -193,6 +191,8 @@ m_run_action->setShortcut (QKeySequence ()); // prevent ambiguous shortcuts m_run_action->setToolTip (tr ("Continue")); // update tool tip + + emit enter_debug_mode_signal (); } void file_editor::handle_exit_debug_mode (void) @@ -200,6 +200,8 @@ shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); scmgr.set_shortcut (m_run_action, sc_edit_run_run_file); m_run_action->setToolTip (tr ("Save File and Run")); // update tool tip + + emit exit_debug_mode_signal (); } void file_editor::check_actions (void) @@ -631,7 +633,7 @@ void file_editor::request_run_file (bool) { emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -2372,6 +2374,13 @@ connect (f->qsci_edit_area (), SIGNAL (SCN_AUTOCCANCELLED (void)), this, SLOT (handle_autoc_cancelled (void))); + // signals from the qscintilla edit area + connect (this, SIGNAL (enter_debug_mode_signal (void)), + f->qsci_edit_area (), SLOT (handle_enter_debug_mode (void))); + + connect (this, SIGNAL (exit_debug_mode_signal (void)), + f->qsci_edit_area (), SLOT (handle_exit_debug_mode (void))); + // Signals from the file editor_tab connect (f, SIGNAL (autoc_closed (void)), this, SLOT (reset_focus (void))); @@ -2410,7 +2419,7 @@ connect (f, SIGNAL (set_focus_editor_signal (QWidget*)), this, SLOT (set_focus (QWidget*))); - // Signals from the file_editor non-trivial operations + // Signals from the file_editor or main-win non-trivial operations connect (this, SIGNAL (fetab_settings_changed (const gui_settings *)), f, SLOT (notice_settings (const gui_settings *))); @@ -2421,6 +2430,9 @@ bool)), f, SLOT (save_file (const QWidget*, const QString&, bool))); + connect (main_win (), SIGNAL (update_gui_lexer_signal (bool)), + f, SLOT (update_lexer_settings (bool))); + // Signals from the file_editor trivial operations connect (this, SIGNAL (fetab_recover_from_exit (void)), f, SLOT (recover_from_exit (void))); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/m-editor/file-editor.h Thu Nov 19 13:08:00 2020 -0800 @@ -112,9 +112,6 @@ SELECTALL_ACTION }; - void handle_enter_debug_mode (void); - void handle_exit_debug_mode (void); - void check_actions (void); void empty_script (bool startup, bool visible); void restore_session (gui_settings *settings); @@ -175,6 +172,9 @@ void editor_tabs_changed_signal (bool); void request_dbcont_signal (void); + void enter_debug_mode_signal (void); + void exit_debug_mode_signal (void); + public slots: void activate (void); @@ -183,6 +183,9 @@ bool check_closing (void); void handle_tab_ready_to_close (void); + void handle_enter_debug_mode (void); + void handle_exit_debug_mode (void); + void request_new_file (const QString& commands); void request_close_file (bool); void request_close_all_files (bool); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/m-editor/find-dialog.cc --- a/libgui/src/m-editor/find-dialog.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/m-editor/find-dialog.cc Thu Nov 19 13:08:00 2020 -0800 @@ -398,21 +398,7 @@ int lbeg, lend, cbeg, cend; _edit_area->getSelection (&lbeg,&cbeg,&lend,&cend); if (lbeg == lend) -#if defined (HAVE_QCOMBOBOX_SETCURRENTTEXT) _search_line_edit->setCurrentText (_edit_area->selectedText ()); -#else - if (_search_line_edit->isEditable ()) - { - _search_line_edit->setEditText (_edit_area->selectedText ()); - } - else - { - int i = _search_line_edit->findText (_edit_area->selectedText ()); - - if (i > -1) - _search_line_edit->setCurrentIndex (i); - } -#endif } // set focus to "Find what" and select all text diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/m-editor/octave-qscintilla.cc Thu Nov 19 13:08:00 2020 -0800 @@ -110,9 +110,10 @@ } octave_qscintilla::octave_qscintilla (QWidget *p, base_qobject& oct_qobj) - : QsciScintilla (p), m_octave_qobj (oct_qobj), m_word_at_cursor (), - m_selection (), m_selection_replacement (), m_selection_line (-1), - m_selection_col (-1), m_indicator_id (1) + : QsciScintilla (p), m_octave_qobj (oct_qobj), m_debug_mode (false), + m_word_at_cursor (), m_selection (), m_selection_replacement (), + m_selection_line (-1), m_selection_col (-1), m_indicator_id (1), + m_tooltip_font (QToolTip::font ()) { connect (this, SIGNAL (textChanged (void)), this, SLOT (text_changed (void))); @@ -381,6 +382,22 @@ markerDeleteAll (marker::selection); } + QString octave_qscintilla::eol_string (void) + { + switch (eolMode ()) + { + case QsciScintilla::EolWindows: + return ("\r\n"); + case QsciScintilla::EolMac: + return ("\r"); + case QsciScintilla::EolUnix: + return ("\n"); + } + + // Last resort, if the above goes wrong (should never happen) + return ("\r\n"); + } + // Function returning the true cursor position where the tab length // is taken into account. void octave_qscintilla::get_current_position (int *pos, int *line, int *col) @@ -860,7 +877,7 @@ // Add commands to the history emit interpreter_event - ([tmp_hist] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -877,7 +894,7 @@ // Let the interpreter execute the tmp file emit interpreter_event - ([this, tmp_file, tmp_hist, show_dbg_file] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -957,8 +974,8 @@ dbg, auto_repeat); // New exception with updated message and stack - octave::execution_exception ee (e.err_type (),e.identifier (), - new_msg.toStdString (), stack); + execution_exception ee (e.err_type (),e.identifier (), + new_msg.toStdString (), stack); // Throw throw (ee); @@ -1085,6 +1102,75 @@ QToolTip::showText (global_pos, msg); } + void octave_qscintilla::replace_all (const QString& o_str, const QString& n_str, + bool re, bool cs, bool wo) + { + // get the resulting cursor position + int pos, line, col, nline, ncol; + get_current_position (&pos, &line, &col); + + // remember first visible line for restoring the view afterwards + int first_line = firstVisibleLine (); + + // search for first occurrence of the detected word + bool find_result_available = findFirst (o_str, re, cs, wo, + false, true, 0, 0); + // replace and find more occurrences in a loop + beginUndoAction (); + while (find_result_available) + { + // findNext doesn't work properly if the length of the replacement + // text is different from the original + replace (n_str); + get_current_position (&pos, &nline, &ncol); + + find_result_available = findFirst (o_str, re, cs, wo, + false, true, nline, ncol); + } + endUndoAction (); + + // restore the visible area + setFirstVisibleLine (first_line); + + // fix cursor column if outside of new line length + int eol_len = eol_string ().length (); + if (line == lines () - 1) + eol_len = 0; + const int col_max = text (line).length () - eol_len; + if (col_max < col) + col = col_max; + + setCursorPosition (line, col); + } + + bool octave_qscintilla::event (QEvent *e) + { + if (m_debug_mode && e->type() == QEvent::ToolTip) + { + QHelpEvent *help_e = static_cast(e); + QString variable = wordAtPoint (help_e->pos()); + QStringList symbol_names + = m_octave_qobj.get_workspace_model ()->get_symbol_names (); + int symbol_idx = symbol_names.indexOf (variable); + if (symbol_idx > -1) + { + QStringList symbol_values + = m_octave_qobj.get_workspace_model ()->get_symbol_values (); + QToolTip::showText (help_e->globalPos(), variable + + " = " + symbol_values.at (symbol_idx)); + } + else + { + QToolTip::hideText(); + e->ignore(); + } + + return true; + } + + return QsciScintilla::event(e); + } + void octave_qscintilla::keyPressEvent (QKeyEvent *key_event) { if (m_selection.isEmpty ()) @@ -1096,59 +1182,8 @@ if (key == Qt::Key_Return && modifiers == Qt::ShiftModifier) { - // get the resulting cursor position - // (required if click was beyond a line ending) - int pos, line, col; - get_current_position (&pos, &line, &col); - - // remember first visible line for restoring the view afterwards - int first_line = firstVisibleLine (); - - // search for first occurrence of the detected word - bool find_result_available - = findFirst (m_selection, - false, // no regexp - true, // case sensitive - true, // whole words only - false, // do not wrap - true, // forward - 0, 0, // from the beginning - false -#if defined (HAVE_QSCI_VERSION_2_6_0) - , true -#endif - ); - - while (find_result_available) - { - replace (m_selection_replacement); - - // FIXME: is this the right thing to do? findNext doesn't - // work properly if the length of the replacement text is - // different from the original. - - int new_line, new_col; - get_current_position (&pos, &new_line, &new_col); - - find_result_available - = findFirst (m_selection, - false, // no regexp - true, // case sensitive - true, // whole words only - false, // do not wrap - true, // forward - new_line, new_col, // from new pos - false -#if defined (HAVE_QSCI_VERSION_2_6_0) - , true -#endif - ); - } - - // restore the visible area of the file, the cursor position, - // and the selection - setFirstVisibleLine (first_line); - setCursorPosition (line, col); + replace_all (m_selection, m_selection_replacement, + false, true, true); // Clear the selection. set_word_selection (); @@ -1291,6 +1326,24 @@ e->ignore(); } } + + void octave_qscintilla::handle_enter_debug_mode (void) + { + // Set tool tip font to the lexers default font + m_tooltip_font = QToolTip::font (); // Save current font + QToolTip::setFont (lexer ()->defaultFont ()); + + m_debug_mode = true; + } + + void octave_qscintilla::handle_exit_debug_mode (void) + { + m_debug_mode = false; + + // Reset tool tip font + QToolTip::setFont (m_tooltip_font); + } + } #endif diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/m-editor/octave-qscintilla.h --- a/libgui/src/m-editor/octave-qscintilla.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/m-editor/octave-qscintilla.h Thu Nov 19 13:08:00 2020 -0800 @@ -65,6 +65,7 @@ void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos); bool get_actual_word (void); void clear_selection_markers (void); + QString eol_string (void); void get_current_position (int *pos, int *line, int *col); QStringList comment_string (bool comment = true); int get_style (int pos = -1); @@ -80,6 +81,9 @@ void set_selection_marker_color (const QColor& c); + void replace_all (const QString& o_str, const QString& n_str, + bool re, bool cs, bool wo); + signals: void execute_command_in_terminal_signal (const QString&); @@ -95,6 +99,11 @@ QTemporaryFile*, bool, bool); void focus_console_after_command_signal (void); + public slots: + + void handle_enter_debug_mode (void); + void handle_exit_debug_mode (void); + private slots: void ctx_menu_run_finished (bool, int, QTemporaryFile*, QTemporaryFile*, @@ -119,6 +128,8 @@ void show_replace_action_tooltip (void); + bool event (QEvent *e); + void keyPressEvent (QKeyEvent *e); void dragEnterEvent (QDragEnterEvent *e); @@ -130,6 +141,8 @@ base_qobject& m_octave_qobj; + bool m_debug_mode; + QString m_word_at_cursor; QString m_selection; @@ -137,6 +150,8 @@ int m_selection_line; int m_selection_col; int m_indicator_id; + + QFont m_tooltip_font; }; } diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/main-window.cc Thu Nov 19 13:08:00 2020 -0800 @@ -164,10 +164,16 @@ shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); scmgr.init_data (); + m_workspace_model = m_octave_qobj.get_workspace_model (); + construct_central_widget (); - m_workspace_model = new workspace_model (m_octave_qobj); m_status_bar = new QStatusBar (); + m_profiler_status_indicator = new led_indicator (); + QLabel *text = new QLabel (tr ("Profiler")); + m_status_bar->addPermanentWidget (text); + m_status_bar->addPermanentWidget (m_profiler_status_indicator); + m_command_window = new terminal_dock_widget (this, m_octave_qobj); m_history_window = new history_dock_widget (this, m_octave_qobj); m_file_browser_window = new files_dock_widget (this, m_octave_qobj); @@ -251,7 +257,6 @@ delete m_file_browser_window; delete m_history_window; delete m_status_bar; - delete m_workspace_model; delete m_variable_editor_window; delete m_find_files_dlg; @@ -405,7 +410,7 @@ if (! file.isEmpty ()) { emit interpreter_event - ([file] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -432,7 +437,7 @@ if (! file.isEmpty ()) { emit interpreter_event - ([file] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -454,7 +459,7 @@ std::string file = file_arg.toStdString (); emit interpreter_event - ([file] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -532,7 +537,7 @@ std::string new_name = new_name_arg.toStdString (); emit interpreter_event - ([old_name, new_name] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -558,7 +563,7 @@ bool rm, bool subdirs) { emit interpreter_event - ([dir_list, rm, subdirs, this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -769,9 +774,7 @@ QTextBrowser *browser = m_community_news_window->findChild("OctaveNews" -#if defined (QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS) , Qt::FindDirectChildrenOnly -#endif ); if (browser) browser->setHtml (news); @@ -1025,7 +1028,7 @@ if (fileInfo.exists () && fileInfo.isDir ()) { emit interpreter_event - ([xdir] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1060,7 +1063,7 @@ void main_window::execute_command_in_terminal (const QString& command) { emit interpreter_event - ([command] (void) + ([=] (void) { // INTERPRETER THREAD @@ -1079,7 +1082,7 @@ void main_window::run_file_in_terminal (const QFileInfo& info) { emit interpreter_event - ([info] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1141,10 +1144,6 @@ m_debug_step_over->setEnabled (true); m_debug_step_out->setEnabled (true); m_debug_quit->setEnabled (true); - -#if defined (HAVE_QSCINTILLA) - m_editor_window->handle_enter_debug_mode (); -#endif } void main_window::handle_exit_debugger (void) @@ -1156,16 +1155,12 @@ m_debug_step_over->setEnabled (m_editor_has_tabs); m_debug_step_out->setEnabled (false); m_debug_quit->setEnabled (false); - -#if defined (HAVE_QSCINTILLA) - m_editor_window->handle_exit_debug_mode (); -#endif } void main_window::debug_continue (void) { emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1179,7 +1174,7 @@ void main_window::debug_step_into (void) { emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1197,7 +1192,7 @@ // We are in debug mode, just call dbstep. emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1218,7 +1213,7 @@ void main_window::debug_step_out (void) { emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1329,7 +1324,7 @@ int line) { emit interpreter_event - ([this, fname, ffile, curr_dir, line] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1653,6 +1648,21 @@ emit unregister_doc_signal (file); } + void main_window::handle_gui_status_update (const QString& feature, + const QString& status) + { + // Put actions that are required for updating a gui features here + + // Profiler on/off + if (! feature.compare ("profiler")) + { + if (! status.compare ("on", Qt::CaseInsensitive)) + handle_profiler_status_update (true); + else if (! status.compare ("off", Qt::CaseInsensitive)) + handle_profiler_status_update (false); + } + } + void main_window::handle_octave_ready (void) { // actions after the startup files are executed @@ -1832,7 +1842,7 @@ void main_window::set_screen_size (int ht, int wd) { emit interpreter_event - ([ht, wd] (void) + ([=] (void) { // INTERPRETER THREAD @@ -1931,6 +1941,60 @@ }); } + void main_window::profiler_session (void) + { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + Ffeval (interp, ovl ("profile","on")); + }); + } + + void main_window::profiler_session_resume (void) + { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + Ffeval (interp, ovl ("profile","resume")); + }); + } + + void main_window::profiler_stop (void) + { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + Ffeval (interp, ovl ("profile","off")); + }); + } + + void main_window::handle_profiler_status_update (bool active) + { + m_profiler_start->setEnabled (! active); + m_profiler_resume->setEnabled (! active); + m_profiler_stop->setEnabled (active); + + led_indicator::led_state state = led_indicator::LED_STATE_INACTIVE; + if (active) + state = led_indicator::LED_STATE_ACTIVE; + m_profiler_status_indicator->set_state (state); + } + + void main_window::profiler_show (void) + { + // Do not use a separate interpreter event as in the other + // profiler slots since the output of the command "profshow" + // would obscure the prompt and we do not need to emimt a signal + // for action that is required in the gui after rhe command + execute_command_in_terminal ("profshow"); + } + void main_window::closeEvent (QCloseEvent *e) { if (confirm_shutdown ()) @@ -2150,6 +2214,13 @@ // Signals for removing/renaming files/dirs in the terminal window connect (qt_link, SIGNAL (file_renamed_signal (bool)), m_editor_window, SLOT (handle_file_renamed (bool))); + + // Signals for entering/exiting debug mode + connect (qt_link, SIGNAL (enter_debugger_signal (void)), + m_editor_window, SLOT (handle_enter_debug_mode (void))); + + connect (qt_link, SIGNAL (exit_debugger_signal (void)), + m_editor_window, SLOT (handle_exit_debug_mode (void))); #endif // Signals for removing/renaming files/dirs in the temrinal window @@ -2256,6 +2327,14 @@ connect (qt_link, SIGNAL (unregister_doc_signal (const QString &)), this, SLOT (handle_unregister_doc (const QString &))); + + connect (qt_link, SIGNAL (gui_status_update_signal (const QString &, + const QString &)), + this, SLOT (handle_gui_status_update (const QString &, + const QString &))); + + connect (qt_link, SIGNAL (update_gui_lexer_signal (bool)), + this, SIGNAL (update_gui_lexer_signal (bool))); } QAction* main_window::add_action (QMenu *menu, const QIcon& icon, @@ -2302,6 +2381,8 @@ construct_debug_menu (menu_bar); + construct_tools_menu (menu_bar); + construct_window_menu (menu_bar); construct_help_menu (menu_bar); @@ -2539,6 +2620,24 @@ SLOT (debug_quit (void))); } + void main_window::construct_tools_menu (QMenuBar *p) + { + QMenu *tools_menu = m_add_menu (p, tr ("&Tools")); + + m_profiler_start = add_action (tools_menu, QIcon (), + tr ("Start &Profiler Session"), SLOT (profiler_session ())); + + m_profiler_resume = add_action (tools_menu, QIcon (), + tr ("&Resume Profiler Session"), SLOT (profiler_session_resume ())); + + m_profiler_stop = add_action (tools_menu, QIcon (), + tr ("&Stop Profiler"), SLOT (profiler_stop ())); + m_profiler_stop->setEnabled (false); + + m_profiler_show = add_action (tools_menu, QIcon (), + tr ("&Show Profile Data"), SLOT (profiler_show ())); + } + void main_window::editor_tabs_changed (bool have_tabs) { // Set state of actions which depend on the existence of editor tabs @@ -2787,6 +2886,12 @@ scmgr.set_shortcut (m_debug_continue, sc_main_debug_continue); scmgr.set_shortcut (m_debug_quit, sc_main_debug_quit); + // tools menu + scmgr.set_shortcut (m_profiler_start, sc_main_tools_start_profiler); + scmgr.set_shortcut (m_profiler_resume, sc_main_tools_resume_profiler); + scmgr.set_shortcut (m_profiler_stop, sc_main_tools_start_profiler); // same, toggling + scmgr.set_shortcut (m_profiler_show, sc_main_tools_show_profiler); + // window menu scmgr.set_shortcut (m_show_command_window_action, sc_main_window_show_command); scmgr.set_shortcut (m_show_history_action, sc_main_window_show_history); @@ -2842,7 +2947,7 @@ mfile_encoding = "SYSTEM"; emit interpreter_event - ([mfile_encoding] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/main-window.h --- a/libgui/src/main-window.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/main-window.h Thu Nov 19 13:08:00 2020 -0800 @@ -53,6 +53,7 @@ #include "find-files-dialog.h" #include "history-dock-widget.h" #include "interpreter-qobject.h" +#include "led-indicator.h" #include "octave-dock-widget.h" #include "octave-qobject.h" #include "qt-interpreter-events.h" @@ -106,6 +107,7 @@ void show_doc_signal (const QString&); void register_doc_signal (const QString&); void unregister_doc_signal (const QString&); + void update_gui_lexer_signal (bool); void insert_debugger_pointer_signal (const QString& file, int line); void delete_debugger_pointer_signal (const QString& file, int line); @@ -205,11 +207,19 @@ void pasteClipboard (void); void selectAll (void); + void handle_gui_status_update (const QString& feature, const QString& status); + void focus_console_after_command (void); void handle_show_doc (const QString& file); void handle_register_doc (const QString& file); void handle_unregister_doc (const QString& file); + void profiler_session (void); + void profiler_session_resume (void); + void profiler_stop (void); + void handle_profiler_status_update (bool); + void profiler_show (void); + void handle_octave_ready (); void handle_set_path_dialog_request (void); @@ -282,6 +292,7 @@ void construct_debug_menu (QMenuBar *p); QAction * construct_window_menu_item (QMenu *p, const QString& item, bool checkable, QWidget*); + void construct_tools_menu (QMenuBar *p); void construct_window_menu (QMenuBar *p); void construct_help_menu (QMenuBar *p); void construct_documentation_menu (QMenu *p); @@ -309,6 +320,7 @@ //! Toolbar. QStatusBar *m_status_bar; + led_indicator *m_profiler_status_indicator; //! Dock widgets. //!@{ @@ -359,6 +371,11 @@ QAction *m_find_files_action; QAction *m_select_all_action; + QAction *m_profiler_start; + QAction *m_profiler_resume; + QAction *m_profiler_stop; + QAction *m_profiler_show; + QAction *m_show_command_window_action; QAction *m_show_history_action; QAction *m_show_workspace_action; diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/module.mk --- a/libgui/src/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -140,6 +140,7 @@ %reldir%/moc-gui-settings.cc \ %reldir%/moc-history-dock-widget.cc \ %reldir%/moc-interpreter-qobject.cc \ + %reldir%/moc-led-indicator.cc \ %reldir%/moc-main-window.cc \ %reldir%/moc-news-reader.cc \ %reldir%/moc-octave-qobject.cc \ @@ -210,6 +211,7 @@ %reldir%/graphics-init.h \ %reldir%/history-dock-widget.h \ %reldir%/interpreter-qobject.h \ + %reldir%/led-indicator.h \ %reldir%/m-editor/file-editor-interface.h \ %reldir%/m-editor/file-editor-tab.h \ %reldir%/m-editor/file-editor.h \ @@ -251,6 +253,7 @@ %reldir%/gui-settings.cc \ %reldir%/history-dock-widget.cc \ %reldir%/interpreter-qobject.cc \ + %reldir%/led-indicator.cc \ %reldir%/m-editor/file-editor-tab.cc \ %reldir%/m-editor/file-editor.cc \ %reldir%/m-editor/find-dialog.cc \ diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/octave-qobject.cc --- a/libgui/src/octave-qobject.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/octave-qobject.cc Thu Nov 19 13:08:00 2020 -0800 @@ -119,11 +119,7 @@ // Disable all Qt messages by default. static void -#if defined (QTMESSAGEHANDLER_ACCEPTS_QMESSAGELOGCONTEXT) message_handler (QtMsgType, const QMessageLogContext &, const QString &) -#else - message_handler (QtMsgType, const char *) -#endif { } //! Reimplement QApplication::notify. Octave's own exceptions are @@ -138,7 +134,7 @@ catch (execution_exception& ee) { emit interpreter_event - ([ee] (void) + ([=] (void) { // INTERPRETER THREAD @@ -164,6 +160,7 @@ m_argv (m_app_context.sys_argv ()), m_qapplication (new octave_qapplication (m_argc, m_argv)), m_resource_manager (), m_shortcut_manager (*this), + m_workspace_model (new workspace_model (*this)), m_qt_tr (new QTranslator ()), m_gui_tr (new QTranslator ()), m_qsci_tr (new QTranslator ()), m_translators_installed (false), m_qt_interpreter_events (new qt_interpreter_events (*this)), @@ -177,11 +174,7 @@ if (show_gui_msgs.empty ()) { -#if defined (HAVE_QINSTALLMESSAGEHANDLER) qInstallMessageHandler (message_handler); -#else - qInstallMsgHandler (message_handler); -#endif } // Set the codec for all strings (before wizard or any GUI object) @@ -189,10 +182,6 @@ QTextCodec::setCodecForLocale (QTextCodec::codecForName ("UTF-8")); #endif -#if defined (HAVE_QT4) - QTextCodec::setCodecForCStrings (QTextCodec::codecForName ("UTF-8")); -#endif - // Initialize global Qt application metadata. QCoreApplication::setApplicationName ("GNU Octave"); @@ -202,7 +191,6 @@ qRegisterMetaType ("octave_value_list"); - // Bug #55940 (Disable App Nap on Mac) #if defined (Q_OS_MAC) // Mac App Nap feature causes pause() and sleep() to misbehave. @@ -250,6 +238,7 @@ delete m_gui_tr; delete m_qt_tr; delete m_qapplication; + delete m_workspace_model; string_vector::delete_c_str_vec (m_argv); } diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/octave-qobject.h --- a/libgui/src/octave-qobject.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/octave-qobject.h Thu Nov 19 13:08:00 2020 -0800 @@ -37,6 +37,7 @@ #include "interpreter-qobject.h" #include "resource-manager.h" #include "shortcut-manager.h" +#include "workspace-model.h" namespace octave { @@ -48,7 +49,7 @@ //! reimplement QApplication::notify. The octave_qapplication object //! should behave identically to a QApplication object except that it //! overrides the notify method so we can handle forward Octave - //! octave::execution_exception exceptions from the GUI thread to the + //! execution_exception exceptions from the GUI thread to the //! interpreter thread. class octave_qapplication : public QApplication @@ -108,6 +109,11 @@ return m_shortcut_manager; } + workspace_model * get_workspace_model (void) + { + return m_workspace_model; + } + std::shared_ptr get_qt_interpreter_events (void) { return m_qt_interpreter_events; @@ -159,6 +165,8 @@ shortcut_manager m_shortcut_manager; + workspace_model *m_workspace_model; + QTranslator *m_qt_tr; QTranslator *m_gui_tr; QTranslator *m_qsci_tr; diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/qt-application.h --- a/libgui/src/qt-application.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/qt-application.h Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ // must be included only in the corresponding .cc file. //! This class inherits from the pure-virtual base class - //! octave::application and provides an implementation of the + //! application and provides an implementation of the //! application::execute method that starts an interface to Octave //! that is based on Qt. It may start a command-line interface that //! allows Qt graphics to be used or it may start an interface that diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/qt-interpreter-events.cc --- a/libgui/src/qt-interpreter-events.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/qt-interpreter-events.cc Thu Nov 19 13:08:00 2020 -0800 @@ -447,6 +447,18 @@ emit unregister_doc_signal (QString::fromStdString (file)); } + void qt_interpreter_events::gui_status_update (const std::string& feature, + const std::string& status) + { + emit gui_status_update_signal (QString::fromStdString (feature), + QString::fromStdString (status)); + } + + void qt_interpreter_events::update_gui_lexer (void) + { + emit update_gui_lexer_signal (true); + } + void qt_interpreter_events::directory_changed (const std::string& dir) { emit directory_changed_signal (QString::fromStdString (dir)); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/qt-interpreter-events.h --- a/libgui/src/qt-interpreter-events.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/qt-interpreter-events.h Thu Nov 19 13:08:00 2020 -0800 @@ -141,6 +141,10 @@ void unregister_doc (const std::string& file); + void gui_status_update (const std::string& feature, const std::string& status); + + void update_gui_lexer (void); + void directory_changed (const std::string& dir); void file_remove (const std::string& old_name, @@ -240,6 +244,10 @@ void unregister_doc_signal (const QString& file); + void gui_status_update_signal (const QString& feature, const QString& status); + + void update_gui_lexer_signal (bool update_apis_only); + void edit_variable_signal (const QString& name, const octave_value& val); void refresh_variable_editor_signal (void); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/resource-manager.cc --- a/libgui/src/resource-manager.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/resource-manager.cc Thu Nov 19 13:08:00 2020 -0800 @@ -28,6 +28,7 @@ #endif #include +#include #include #include @@ -221,30 +222,30 @@ QString default_family; #if defined (Q_OS_MAC) - // Use hard coded default on macOS, since selection of fixed width - // default font is unreliable (see bug #59128). + // Use hard coded default on macOS, since selection of fixed width + // default font is unreliable (see bug #59128). - // Get all available fixed width fonts via a font combobox - QFontComboBox font_combo_box; - font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts); - QStringList fonts; + // Get all available fixed width fonts via a font combobox + QFontComboBox font_combo_box; + font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts); + QStringList fonts; - for (int index = 0; index < font_combo_box.count(); index++) - fonts << font_combo_box.itemText(index); + for (int index = 0; index < font_combo_box.count(); index++) + fonts << font_combo_box.itemText(index); - // Test for macOS default fixed width font - if (fonts.contains (global_mono_font.def.toString ())) - default_family = global_mono_font.def.toString (); + // Test for macOS default fixed width font + if (fonts.contains (global_mono_font.def.toString ())) + default_family = global_mono_font.def.toString (); #endif - // If default font is still empty (on all other platforms or - // if macOS default font is not available): use QFontDatabase - if (default_family.isEmpty ()) - { - // Get the system's default monospaced font - QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont); - default_family = fixed_font.defaultFamily (); - } + // If default font is still empty (on all other platforms or + // if macOS default font is not available): use QFontDatabase + if (default_family.isEmpty ()) + { + // Get the system's default monospaced font + QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont); + default_family = fixed_font.defaultFamily (); + } // Test env variable which has preference std::string env_default_family = sys::env::getenv ("OCTAVE_DEFAULT_FONT"); @@ -363,39 +364,108 @@ void resource_manager::update_network_settings (void) { - if (m_settings) + if (! m_settings) + return; + + QNetworkProxy proxy; + + // Assume no proxy and empty proxy data + QNetworkProxy::ProxyType proxy_type = QNetworkProxy::NoProxy; + QString scheme; + QString host; + int port = 0; + QString user; + QString pass; + QUrl proxy_url = QUrl (); + + if (m_settings->value (global_use_proxy.key, global_use_proxy.def).toBool ()) { - QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy; + // Use a proxy, collect all required information + QString proxy_type_string + = m_settings->value (global_proxy_type.key, global_proxy_type.def).toString (); - if (m_settings->value (global_use_proxy.key, global_use_proxy.def).toBool ()) + // The proxy type for the Qt proxy settings + if (proxy_type_string == "Socks5Proxy") + proxy_type = QNetworkProxy::Socks5Proxy; + else if (proxy_type_string == "HttpProxy") + proxy_type = QNetworkProxy::HttpProxy; + + // The proxy data from the settings + if (proxy_type_string == "HttpProxy" + || proxy_type_string == "Socks5Proxy") { - QString proxyTypeString - = m_settings->value (global_proxy_type.key, global_proxy_type.def).toString (); + host = m_settings->value (global_proxy_host.key, + global_proxy_host.def).toString (); + port = m_settings->value (global_proxy_port.key, + global_proxy_port.def).toInt (); + user = m_settings->value (global_proxy_user.key, + global_proxy_user.def).toString (); + pass = m_settings->value (global_proxy_pass.key, + global_proxy_pass.def).toString (); + if (proxy_type_string == "HttpProxy") + scheme = "http"; + else if (proxy_type_string == "Socks5Proxy") + scheme = "socks5"; - if (proxyTypeString == "Socks5Proxy") - proxyType = QNetworkProxy::Socks5Proxy; - else if (proxyTypeString == "HttpProxy") - proxyType = QNetworkProxy::HttpProxy; + QUrl env_var_url = QUrl (); + proxy_url.setScheme (scheme); + proxy_url.setHost (host); + proxy_url.setPort (port); + if (! user.isEmpty ()) + proxy_url.setUserName (user); + if (! pass.isEmpty ()) + proxy_url.setPassword (pass); } - QNetworkProxy proxy; + // The proxy data from environment variables + if (proxy_type_string == global_proxy_all_types.at (2)) + { + const std::array env_vars = + { "ALL_PROXY", "all_proxy", + "HTTP_PROXY", "http_proxy", + "HTTPS_PROXY", "https_proxy" }; + + unsigned int count = 0; + while (! proxy_url.isValid () && count < env_vars.size ()) + { + proxy_url = QUrl (QString::fromStdString + (sys::env::getenv (env_vars[count]))); + count++; + } + + if (proxy_url.isValid ()) + { + // Found an entry, get the data from the string + scheme = proxy_url.scheme (); - proxy.setType (proxyType); - proxy.setHostName (m_settings->value (global_proxy_host.key, - global_proxy_host.def).toString ()); - proxy.setPort (m_settings->value (global_proxy_port.key, - global_proxy_port.def).toInt ()); - proxy.setUser (m_settings->value (global_proxy_user.key, - global_proxy_user.def).toString ()); - proxy.setPassword (m_settings->value (global_proxy_pass.key, - global_proxy_pass.def).toString ()); + if (scheme.contains ("socks", Qt::CaseInsensitive)) + proxy_type = QNetworkProxy::Socks5Proxy; + else + proxy_type = QNetworkProxy::HttpProxy; + + host = proxy_url.host (); + port = proxy_url.port (); + user = proxy_url.userName (); + pass = proxy_url.password (); + } + } + } - QNetworkProxy::setApplicationProxy (proxy); - } - else - { - // FIXME: Is this an error? If so, what should we do? - } + // Set proxy for Qt framework + proxy.setType (proxy_type); + proxy.setHostName (host); + proxy.setPort (port); + proxy.setUser (user); + proxy.setPassword (pass); + + QNetworkProxy::setApplicationProxy (proxy); + + // Set proxy for curl library if not based on environment variables + std::string proxy_url_str = proxy_url.toString().toStdString (); + sys::env::putenv ("http_proxy", proxy_url_str); + sys::env::putenv ("HTTP_PROXY", proxy_url_str); + sys::env::putenv ("https_proxy", proxy_url_str); + sys::env::putenv ("HTTPS_PROXY", proxy_url_str); } QIcon resource_manager::icon (const QString& icon_name, bool fallback) diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/set-path-model.cc --- a/libgui/src/set-path-model.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/set-path-model.cc Thu Nov 19 13:08:00 2020 -0800 @@ -77,7 +77,7 @@ std::string path_str = to_string (); emit interpreter_event - ([path_str] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -283,7 +283,7 @@ void set_path_model::path_to_model (void) { emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/settings-dialog.cc Thu Nov 19 13:08:00 2020 -0800 @@ -350,6 +350,8 @@ editor_restoreSession->setChecked (settings->value (ed_restore_session).toBool ()); editor_create_new_file->setChecked (settings->value (ed_create_new_file).toBool ()); editor_reload_changed_files->setChecked (settings->value (ed_always_reload_changed_files).toBool ()); + editor_force_newline->setChecked (settings->value (ed_force_newline).toBool ()); + editor_remove_trailing_spaces->setChecked (settings->value (ed_rm_trailing_spaces).toBool ()); editor_hiding_closes_files->setChecked (settings->value (ed_hiding_closes_files).toBool ()); editor_show_dbg_file->setChecked (settings->value (ed_show_dbg_file).toBool ()); @@ -395,21 +397,33 @@ le_file_browser_extensions->setText (settings->value (fb_txt_file_ext).toString ()); checkbox_allow_web_connect->setChecked (settings->value (nr_allow_connection).toBool ()); - useProxyServer->setChecked ( - settings->value (global_use_proxy.key, global_use_proxy.def).toBool ()); - proxyHostName->setText (settings->value (global_proxy_host.key, global_proxy_host.def).toString ()); - int currentIndex = 0; - QString proxyTypeString = settings->value (global_proxy_type.key, global_proxy_type.def).toString (); - while ((currentIndex < proxyType->count ()) - && (proxyType->currentText () != proxyTypeString)) + // Proxy + bool use_proxy = settings->value (global_use_proxy.key, global_use_proxy.def).toBool (); + use_proxy_server->setChecked (use_proxy); + // Fill combo box and activate current one + QString proxy_type_string = settings->value (global_proxy_type.key, global_proxy_type.def).toString (); + proxy_type->addItems (global_proxy_all_types); + for (int i = 0; i < global_proxy_all_types.length (); i++) { - currentIndex++; - proxyType->setCurrentIndex (currentIndex); + if (proxy_type->itemText (i) == proxy_type_string) + { + proxy_type->setCurrentIndex (i); + break; + } } - proxyPort->setText (settings->value (global_proxy_port.key, global_proxy_port.def).toString ()); - proxyUserName->setText (settings->value (global_proxy_user.key, global_proxy_user.def).toString ()); - proxyPassword->setText (settings->value (global_proxy_pass.key, global_proxy_pass.def).toString ()); + // Fill all line edits + proxy_host_name->setText (settings->value (global_proxy_host.key, global_proxy_host.def).toString ()); + proxy_port->setText (settings->value (global_proxy_port.key, global_proxy_port.def).toString ()); + proxy_username->setText (settings->value (global_proxy_user.key, global_proxy_user.def).toString ()); + proxy_password->setText (settings->value (global_proxy_pass.key, global_proxy_pass.def).toString ()); + // Connect relevant signals for dis-/enabling some elements + connect (proxy_type, SIGNAL (currentIndexChanged (int)), + this, SLOT (proxy_items_update (void))); + connect (use_proxy_server, SIGNAL (toggled (bool)), + this, SLOT (proxy_items_update (void))); + // Check whehter line edits have to be enabled + proxy_items_update (); // Workspace read_workspace_colors (settings); @@ -594,6 +608,32 @@ } } + // slot for updating enabled state of proxy settings + void settings_dialog::proxy_items_update (void) + { + bool use_proxy = use_proxy_server->isChecked (); + + bool manual = false; + for (int i = 0; i < global_proxy_manual_types.length (); i++) + { + if (proxy_type->currentIndex () == global_proxy_manual_types.at (i)) + { + manual = true; + break; + } + } + + proxy_type->setEnabled (use_proxy); + proxy_host_name_label->setEnabled (use_proxy && manual); + proxy_host_name->setEnabled (use_proxy && manual); + proxy_port_label->setEnabled (use_proxy && manual); + proxy_port->setEnabled (use_proxy && manual); + proxy_username_label->setEnabled (use_proxy && manual); + proxy_username->setEnabled (use_proxy && manual); + proxy_password_label->setEnabled (use_proxy && manual); + proxy_password->setEnabled (use_proxy && manual); + } + // slots for import/export of shortcut sets void settings_dialog::import_shortcut_set (void) @@ -935,6 +975,8 @@ settings->setValue (ed_create_new_file.key, editor_create_new_file->isChecked ()); settings->setValue (ed_hiding_closes_files.key, editor_hiding_closes_files->isChecked ()); settings->setValue (ed_always_reload_changed_files.key, editor_reload_changed_files->isChecked ()); + settings->setValue (ed_force_newline.key, editor_force_newline->isChecked ()); + settings->setValue (ed_rm_trailing_spaces.key, editor_remove_trailing_spaces->isChecked ()); settings->setValue (ed_show_dbg_file.key, editor_show_dbg_file->isChecked ()); settings->setValue (cs_font_size.key, terminal_fontSize->value ()); @@ -947,12 +989,12 @@ settings->setValue (fb_txt_file_ext.key, le_file_browser_extensions->text ()); settings->setValue (nr_allow_connection.key, checkbox_allow_web_connect->isChecked ()); - settings->setValue (global_use_proxy.key, useProxyServer->isChecked ()); - settings->setValue (global_proxy_type.key, proxyType->currentText ()); - settings->setValue (global_proxy_host.key, proxyHostName->text ()); - settings->setValue (global_proxy_port.key, proxyPort->text ()); - settings->setValue (global_proxy_user.key, proxyUserName->text ()); - settings->setValue (global_proxy_pass.key, proxyPassword->text ()); + settings->setValue (global_use_proxy.key, use_proxy_server->isChecked ()); + settings->setValue (global_proxy_type.key, proxy_type->currentText ()); + settings->setValue (global_proxy_host.key, proxy_host_name->text ()); + settings->setValue (global_proxy_port.key, proxy_port->text ()); + settings->setValue (global_proxy_user.key, proxy_username->text ()); + settings->setValue (global_proxy_pass.key, proxy_password->text ()); settings->setValue (cs_cursor_use_fgcol.key, terminal_cursorUseForegroundColor->isChecked ()); settings->setValue (mw_dir_list.key, terminal_focus_command->isChecked ()); settings->setValue (cs_dbg_location.key, terminal_print_dbg_location->isChecked ()); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/settings-dialog.h --- a/libgui/src/settings-dialog.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/settings-dialog.h Thu Nov 19 13:08:00 2020 -0800 @@ -65,6 +65,7 @@ void get_file_browser_dir (void); void get_dir (QLineEdit*, const QString&); void set_disabled_pref_file_browser_dir (bool disable); + void proxy_items_update (void); // slots for dialog's buttons void button_clicked (QAbstractButton *button); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/settings-dialog.ui Thu Nov 19 13:08:00 2020 -0800 @@ -32,7 +32,7 @@ - 5 + 7 @@ -843,7 +843,7 @@ 0 0 1021 - 1467 + 1529 @@ -2053,7 +2053,7 @@ - + 0 @@ -2111,7 +2111,7 @@ - + @@ -2138,7 +2138,7 @@ - + Close all files when the editor widget is closed/hidden @@ -2148,6 +2148,26 @@ + + + + Force newline at end when saving file + + + true + + + + + + + Remove trailing spaces when saving file + + + true + + + @@ -2809,124 +2829,151 @@ - - - - - Allow Octave to connect to the Octave web site to display current news and information - - - - - - - - - false - - - Hostname: - - - - - - - false - - - - HttpProxy - - - - - Socks5Proxy - - - - - - - - false - - - Username: - - - - - - - Use proxy server - - - - - - - false - - - Proxy type: - - - - - - - false - - - Port: - - - - - - - false - - - Password: - - - - - - - false - - - - - - - false - - - - - - - false - - - - - - - false - - - QLineEdit::Password - - - - - - + + + General + + + + + + Allow Octave to connect to the Octave web site to display current news and information + + + + + + + + + + Proxy Server + + + + + + + + + + false + + + Hostname: + + + + + + + true + + + <html><head/><body><p>Select <span style=" font-style:italic;">HttpProxy</span>, <span style=" font-style:italic;">Sock5Proxy</span> or <span style=" font-style:italic;">Environment Variables</span>. With the last selection, the proxy is taken from the first non-empty environment variable ALL_PROXY, HTTP_PROXY or HTTPS_PROXY .</p></body></html> + + + + + + + false + + + Username: + + + + + + + true + + + Proxy type: + + + + + + + false + + + Port: + + + + + + + false + + + Password: + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + false + + + QLineEdit::Password + + + + + + + Use proxy server + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + @@ -2961,102 +3008,6 @@ - useProxyServer - toggled(bool) - label_4 - setEnabled(bool) - - - 249 - 59 - - - 69 - 122 - - - - - useProxyServer - toggled(bool) - label_3 - setEnabled(bool) - - - 249 - 59 - - - 59 - 91 - - - - - useProxyServer - toggled(bool) - proxyHostName - setEnabled(bool) - - - 249 - 59 - - - 291 - 124 - - - - - useProxyServer - toggled(bool) - label_5 - setEnabled(bool) - - - 249 - 59 - - - 44 - 152 - - - - - useProxyServer - toggled(bool) - proxyType - setEnabled(bool) - - - 249 - 59 - - - 291 - 91 - - - - - useProxyServer - toggled(bool) - proxyPort - setEnabled(bool) - - - 249 - 59 - - - 364 - 154 - - - - useCustomFileEditor toggled(bool) customFileEditor @@ -3073,70 +3024,6 @@ - useProxyServer - toggled(bool) - label_7 - setEnabled(bool) - - - 249 - 59 - - - 67 - 212 - - - - - useProxyServer - toggled(bool) - label_6 - setEnabled(bool) - - - 249 - 59 - - - 68 - 182 - - - - - useProxyServer - toggled(bool) - proxyPassword - setEnabled(bool) - - - 249 - 59 - - - 364 - 214 - - - - - useProxyServer - toggled(bool) - proxyUserName - setEnabled(bool) - - - 249 - 59 - - - 364 - 184 - - - - useCustomFileEditor toggled(bool) customEditorLabel diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/shortcut-manager.cc --- a/libgui/src/shortcut-manager.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/shortcut-manager.cc Thu Nov 19 13:08:00 2020 -0800 @@ -75,11 +75,7 @@ if (key == Qt::Key_unknown || key == 0) return; -#if defined (HAVE_QGUIAPPLICATION) Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers (); //e->modifiers (); -#else - Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers (); //e->modifiers (); -#endif if (m_shift_modifier || (modifiers & Qt::ShiftModifier)) key += Qt::SHIFT; @@ -168,6 +164,11 @@ init (tr ("Continue"), sc_main_debug_continue); init (tr ("Quit Debug Mode"), sc_main_debug_quit); + // tools + init (tr ("Start/Stop Profiler Session"), sc_main_tools_start_profiler); + init (tr ("Resume Profiler Session"), sc_main_tools_resume_profiler); + init (tr ("Show Profile Data"), sc_main_tools_show_profiler); + // window init (tr ("Show Command Window"), sc_main_window_show_command); init (tr ("Show Command History"), sc_main_window_show_history); @@ -372,11 +373,7 @@ m_dialog = nullptr; m_level_hash.clear (); -#if defined (HAVE_QHEADERVIEW_SETSECTIONRESIZEMODE) tree_view->header ()->setSectionResizeMode (QHeaderView::ResizeToContents); -#else - tree_view->header ()->setResizeMode (QHeaderView::ResizeToContents); -#endif QTreeWidgetItem *main = new QTreeWidgetItem (tree_view); main->setText (0, tr ("Global")); @@ -387,6 +384,8 @@ main_edit->setText (0, tr ("Edit Menu")); QTreeWidgetItem *main_debug = new QTreeWidgetItem (main); main_debug->setText (0, tr ("Debug Menu")); + QTreeWidgetItem *main_tools = new QTreeWidgetItem (main); + main_tools->setText (0, tr ("Tools Menu")); QTreeWidgetItem *main_window = new QTreeWidgetItem (main); main_window->setText (0, tr ("Window Menu")); QTreeWidgetItem *main_help = new QTreeWidgetItem (main); @@ -405,6 +404,7 @@ m_level_hash[sc_main_file] = main_file; m_level_hash[sc_main_edit] = main_edit; m_level_hash[sc_main_debug] = main_debug; + m_level_hash[sc_main_tools] = main_tools; m_level_hash[sc_main_window] = main_window; m_level_hash[sc_main_help] = main_help; m_level_hash[sc_main_news] = main_news; diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/tab-bar.cc --- a/libgui/src/tab-bar.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/tab-bar.cc Thu Nov 19 13:08:00 2020 -0800 @@ -56,16 +56,12 @@ void tab_bar::move_tab_left (void) { -#if defined (HAVE_QTABWIDGET_SETMOVABLE) switch_tab (-1, true); -#endif } void tab_bar::move_tab_right (void) { -#if defined (HAVE_QTABWIDGET_SETMOVABLE) switch_tab (1, true); -#endif } void tab_bar::switch_tab (int direction, bool movetab) @@ -83,11 +79,9 @@ if (movetab) { -#if defined (HAVE_QTABWIDGET_SETMOVABLE) moveTab (old_pos, new_pos); setCurrentIndex (old_pos); setCurrentIndex (new_pos); -#endif } else setCurrentIndex (new_pos); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/variable-editor-model.cc --- a/libgui/src/variable-editor-model.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/variable-editor-model.cc Thu Nov 19 13:08:00 2020 -0800 @@ -1024,7 +1024,7 @@ std::string expr = os.str (); emit interpreter_event - ([this, nm, expr, idx] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1173,7 +1173,7 @@ std::string expr = expr_arg.toStdString (); emit interpreter_event - ([this, expr] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD @@ -1245,7 +1245,7 @@ variable_editor_model::update_data_cache (void) { emit interpreter_event - ([this] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER_THREAD diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/variable-editor-model.h --- a/libgui/src/variable-editor-model.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/variable-editor-model.h Thu Nov 19 13:08:00 2020 -0800 @@ -263,11 +263,21 @@ return rep->display_rows (); } + octave_idx_type data_rows (void) const + { + return rep->data_rows (); + } + int display_columns (void) const { return rep->display_columns (); } + octave_idx_type data_columns (void) const + { + return rep->data_columns (); + } + void maybe_resize_rows (int rows); void maybe_resize_columns (int cols); @@ -318,16 +328,6 @@ return rep->is_valid (); } - octave_idx_type data_rows (void) const - { - return rep->data_rows (); - } - - octave_idx_type data_columns (void) const - { - return rep->data_columns (); - } - void change_display_size (int old_rows, int old_cols, int new_rows, int new_cols); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/variable-editor.cc --- a/libgui/src/variable-editor.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/variable-editor.cc Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -63,14 +62,6 @@ { // Code reuse functions - static QString - idx_to_expr (int32_t from, int32_t to) - { - return (from == to - ? QString ("%1").arg (from) - : QString ("%1:%2").arg (from).arg (to)); - } - static QSignalMapper * make_plot_mapper (QMenu *menu) { @@ -80,11 +71,8 @@ QSignalMapper *plot_mapper = new QSignalMapper (menu); for (int i = 0; i < list.size(); ++i) - { - plot_mapper->setMapping - (menu->addAction (list.at (i), plot_mapper, SLOT (map ())), - "figure (); " + list.at (i) + " (%1); title (\"%1\");"); - } + plot_mapper->setMapping + (menu->addAction (list.at (i), plot_mapper, SLOT (map ())), list.at (i)); return plot_mapper; } @@ -112,7 +100,6 @@ connect (p, SIGNAL (visibilityChanged (bool)), this, SLOT (setVisible (bool))); -#if defined (HAVE_QGUIAPPLICATION) #define DOCKED_FULLSCREEN_BUTTON_TOOLTIP "Fullscreen undock" #define UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP "Fullscreen" // Add a fullscreen button @@ -142,7 +129,6 @@ if (first != nullptr) index = h_layout->indexOf (first); h_layout->insertWidget (index, fullscreen_button); -#endif // Custom title bars cause loss of decorations, add a frame m_frame = new QFrame (this); @@ -154,7 +140,6 @@ void variable_dock_widget::change_floating (bool) { -#if defined (HAVE_QGUIAPPLICATION) if (isFloating ()) { if (m_full_screen) @@ -168,7 +153,6 @@ } else m_fullscreen_action->setToolTip (tr (UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP)); -#endif setFloating (! isFloating ()); } @@ -218,7 +202,6 @@ void variable_dock_widget::change_fullscreen (void) { -#if defined (HAVE_QGUIAPPLICATION) resource_manager& rmgr = m_octave_qobj.get_resource_manager (); if (! m_full_screen) @@ -258,7 +241,6 @@ } #undef DOCKED_FULLSCREEN_BUTTON_TOOLTIP #undef UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP -#endif } void @@ -502,11 +484,7 @@ setHorizontalScrollMode (QAbstractItemView::ScrollPerPixel); setVerticalScrollMode (QAbstractItemView::ScrollPerPixel); -#if defined (HAVE_QHEADERVIEW_SETSECTIONRESIZEMODE) verticalHeader ()->setSectionResizeMode (QHeaderView::Interactive); -#else - verticalHeader ()->setResizeMode (QHeaderView::Interactive); -#endif } void @@ -514,11 +492,7 @@ { QTableView::setModel (model); -#if defined (HAVE_QHEADERVIEW_SETSECTIONRESIZEMODE) horizontalHeader ()->setSectionResizeMode (QHeaderView::Interactive); -#else - horizontalHeader ()->setResizeMode (QHeaderView::Interactive); -#endif m_var_model = parent ()->findChild (); @@ -567,30 +541,39 @@ return range; } - QString - variable_editor_view::selected_to_octave (void) - { - QList range = range_selected (); - if (range.isEmpty ()) - return objectName (); - - QString rows = idx_to_expr (range.at (0), range.at (1)); - QString cols = idx_to_expr (range.at (2), range.at (3)); - - // FIXME: Does cell need separate handling? Maybe use '{.,.}'? - - return QString ("%1(%2, %3)").arg (objectName ()).arg (rows).arg (cols); - } - void variable_editor_view::selected_command_requested (const QString& cmd) { if (! hasFocus ()) return; - QString selarg = selected_to_octave (); - if (! selarg.isEmpty ()) - emit command_signal (cmd.arg (selarg)); + QList range = range_selected (); + if (range.isEmpty ()) + return; + + int s1 = m_var_model->data_rows (); + int s2 = m_var_model->data_columns (); + if (s1 < range.at (0) || s2 < range.at (2)) + return; // Selected range does not contain data + + s1 = std::min (s1, range.at (1)); + s2 = std::min (s2, range.at (3)); + + // Variable with desired range as string + QString variable = QString ("%1(%2:%3,%4:%5)") + .arg (objectName ()) + .arg (range.at (0)).arg (s1) + .arg (range.at (2)).arg (s2); + + // Desired command as string + QString command; + if (cmd == "create") + command = QString ("unnamed = %1;").arg (variable); + else + command = QString ("figure (); %1 (%2); title ('%2');") + .arg (cmd).arg (variable); + + emit command_signal (command); } void @@ -765,7 +748,7 @@ { // FIXME: Create unnamed1..n if exist ('unnamed', 'var') is true. - selected_command_requested ("unnamed = %1"); + selected_command_requested ("create"); } void @@ -1064,6 +1047,7 @@ m_table_colors (), m_current_focus_vname (""), m_hovered_focus_vname (""), + m_plot_mapper (nullptr), m_focus_widget (nullptr), m_focus_widget_vdw (nullptr) { @@ -1142,29 +1126,6 @@ } } - // Add an action to a menu or the widget itself. - - QAction* - variable_editor::add_action (QMenu *menu, const QIcon& icon, - const QString& text, - const char *member) - { - QAction *a; - - if (menu) - a = menu->addAction (icon, text, this, member); - else - { - a = new QAction (this); - connect (a, SIGNAL (triggered ()), this, member); - } - - addAction (a); // important for shortcut context - a->setShortcutContext (Qt::WidgetWithChildrenShortcut); - - return a; - } - void variable_editor::edit_variable (const QString& name, const octave_value& val) { @@ -1244,6 +1205,9 @@ edit_view->verticalHeader ()->setDefaultSectionSize (m_default_height + m_add_font_height); + connect (m_plot_mapper, SIGNAL (mapped (const QString&)), + edit_view, SLOT (selected_command_requested (const QString&))); + connect (edit_view, SIGNAL (command_signal (const QString&)), this, SIGNAL (command_signal (const QString&))); connect (this, SIGNAL (delete_selected_signal ()), @@ -1254,8 +1218,6 @@ edit_view, SLOT (copyClipboard ())); connect (this, SIGNAL (paste_clipboard_signal ()), edit_view, SLOT (pasteClipboard ())); - connect (this, SIGNAL (selected_command_signal (const QString&)), - edit_view, SLOT (selected_command_requested (const QString&))); connect (edit_view->horizontalHeader (), SIGNAL (customContextMenuRequested (const QPoint&)), edit_view, SLOT (createColumnMenu (const QPoint&))); @@ -1523,12 +1485,6 @@ emit level_up_signal (); } - void - variable_editor::relay_selected_command (const QString& cmd) - { - emit selected_command_signal (cmd); - } - // Also updates the font. void variable_editor::update_colors (void) @@ -1647,10 +1603,7 @@ plot_menu->setTitle (tr ("Plot")); plot_menu->setSeparatorsCollapsible (false); - QSignalMapper *plot_mapper = make_plot_mapper (plot_menu); - - connect (plot_mapper, SIGNAL (mapped (const QString&)), - this, SLOT (relay_selected_command (const QString&))); + m_plot_mapper = make_plot_mapper (plot_menu); plot_tool_button->setMenu (plot_menu); @@ -1667,9 +1620,7 @@ // that restores active window and focus before acting. QList hbuttonlist = m_tool_bar->findChildren ("" -#if defined (QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS) , Qt::FindDirectChildrenOnly -#endif ); for (int i = 0; i < hbuttonlist.size (); i++) { @@ -1681,9 +1632,7 @@ QList rfbuttonlist = m_tool_bar->findChildren ("" -#if defined (QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS) , Qt::FindDirectChildrenOnly -#endif ); for (int i = 0; i < rfbuttonlist.size (); i++) { diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/variable-editor.h --- a/libgui/src/variable-editor.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/variable-editor.h Thu Nov 19 13:08:00 2020 -0800 @@ -27,6 +27,7 @@ #define octave_variable_editor_h 1 #include +#include #include #include @@ -86,8 +87,6 @@ QFrame *m_frame; -#if defined (HAVE_QGUIAPPLICATION) - QAction *m_fullscreen_action; bool m_full_screen; @@ -96,8 +95,6 @@ QRect m_prev_geom; -#endif - // See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 #define QTBUG_44813_FIX_VERSION 0x999999 signals: @@ -207,9 +204,6 @@ void createRowMenu (const QPoint& pt); - // Convert selection to an Octave expression. - QString selected_to_octave (void); - void selected_command_requested (const QString& cmd); private: @@ -321,8 +315,6 @@ void delete_selected_signal (void); - void selected_command_signal (const QString& cmd); - public slots: void callUpdate (const QModelIndex&, const QModelIndex&); @@ -353,19 +345,12 @@ void levelUp (void); - // Send command to Octave interpreter. - // %1 in CMD is replaced with the value of selected_to_octave. - void relay_selected_command (const QString& cmd); - protected: void focusInEvent (QFocusEvent *ev); private: - QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, - const char *member); - dw_main_window *m_main; QToolBar *m_tool_bar; @@ -401,6 +386,8 @@ QString m_hovered_focus_vname; + QSignalMapper *m_plot_mapper; + QWidget *m_focus_widget; variable_dock_widget *m_focus_widget_vdw; diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/workspace-model.h --- a/libgui/src/workspace-model.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/workspace-model.h Thu Nov 19 13:08:00 2020 -0800 @@ -75,6 +75,9 @@ symbol_info_list get_symbol_info (void) const { return m_syminfo_list; } + QStringList get_symbol_names (void) const { return m_symbols; } + QStringList get_symbol_values (void) const { return m_values; } + signals: void model_changed (void); diff -r dc3ee9616267 -r fa2cdef14442 libgui/src/workspace-view.cc --- a/libgui/src/workspace-view.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libgui/src/workspace-view.cc Thu Nov 19 13:08:00 2020 -0800 @@ -120,16 +120,8 @@ (settings->value (ws_column_state.key).toByteArray ()); // Set header properties for sorting -#if defined (HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE) m_view->horizontalHeader ()->setSectionsClickable (true); -#else - m_view->horizontalHeader ()->setClickable (true); -#endif -#if defined (HAVE_QHEADERVIEW_SETSECTIONSMOVABLE) m_view->horizontalHeader ()->setSectionsMovable (true); -#else - m_view->horizontalHeader ()->setMovable (true); -#endif m_view->horizontalHeader ()->setSortIndicator ( settings->value (ws_sort_column).toInt (), static_cast (settings->value (ws_sort_order).toUInt ())); @@ -217,7 +209,7 @@ .arg (m_model->storage_class_color (i).name ()) .arg (m_model->storage_class_color (i + ws_colors_count).name ()) .arg (QCoreApplication::translate ("octave::settings_dialog", - ws_color_names.at (i).toStdString ().data ())); + ws_color_names.at (i).toStdString ().data ())); } } @@ -413,7 +405,7 @@ QString var_name = get_var_name (index); emit interpreter_event - ([var_name] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER THREAD diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/Cell.cc --- a/libinterp/corefcn/Cell.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/Cell.cc Thu Nov 19 13:08:00 2020 -0800 @@ -234,7 +234,7 @@ %% This behavior is required for Matlab compatibility. %!shared a %! a = {"foo", "bar"}; -%!assert (a(), a); +%!assert (a(), a) %!error a{} */ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/__betainc__.cc --- a/libinterp/corefcn/__betainc__.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/__betainc__.cc Thu Nov 19 13:08:00 2020 -0800 @@ -37,9 +37,7 @@ Continued fraction for incomplete beta function. @end deftypefn */) { - int nargin = args.length (); - - if (nargin != 3) + if (args.length () != 3) print_usage (); bool is_single = (args(0).is_single_type () || args(1).is_single_type () diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/__dsearchn__.cc --- a/libinterp/corefcn/__dsearchn__.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/__dsearchn__.cc Thu Nov 19 13:08:00 2020 -0800 @@ -48,7 +48,7 @@ Matrix xi = args(1).matrix_value ().transpose (); if (x.rows () != xi.rows () || x.columns () < 1) - error ("__dsearch__: number of rows of X and XI must match"); + error ("__dsearchn__: number of rows of X and XI must match"); octave_idx_type n = x.rows (); octave_idx_type nx = x.columns (); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/__eigs__.cc --- a/libinterp/corefcn/__eigs__.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/__eigs__.cc Thu Nov 19 13:08:00 2020 -0800 @@ -199,9 +199,7 @@ warned_imaginary = false; - octave::unwind_protect frame; - - frame.protect_var (call_depth); + octave::unwind_protect_var restore_var (call_depth); call_depth++; if (call_depth > 1) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/__expint__.cc --- a/libinterp/corefcn/__expint__.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/__expint__.cc Thu Nov 19 13:08:00 2020 -0800 @@ -37,9 +37,7 @@ Continued fraction expansion for the exponential integral. @end deftypefn */) { - int nargin = args.length (); - - if (nargin != 1) + if (args.length () != 1) print_usage (); octave_value_list retval; diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/__ftp__.cc --- a/libinterp/corefcn/__ftp__.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/__ftp__.cc Thu Nov 19 13:08:00 2020 -0800 @@ -425,7 +425,7 @@ else { // FIXME: Does ascii mode need to be flagged here? - std::ifstream ifile = + std::ifstream ifile = octave::sys::ifstream (file.c_str (), std::ios::in | std::ios::binary); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/__gammainc__.cc --- a/libinterp/corefcn/__gammainc__.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/__gammainc__.cc Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ Continued fraction for incomplete gamma function. @end deftypefn */) { - int nargin = args.length (); - - if (nargin != 2) + if (args.length () != 2) print_usage (); bool is_single = args(0).is_single_type () || args(1).is_single_type (); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/__magick_read__.cc --- a/libinterp/corefcn/__magick_read__.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/__magick_read__.cc Thu Nov 19 13:08:00 2020 -0800 @@ -28,6 +28,7 @@ #endif #include "file-stat.h" +#include "lo-sysdep.h" #include "oct-env.h" #include "oct-time.h" @@ -140,17 +141,17 @@ // width 1. In those cases, the type will come as scalar instead of range // since that's the behavior of the colon operator (1:1:1 will be a scalar, // not a range). -static Range +static octave::range get_region_range (const octave_value& region) { - Range output; + octave::range output; if (region.is_range ()) output = region.range_value (); else if (region.is_scalar_type ()) { double value = region.scalar_value (); - output = Range (value, value); + output = octave::range (value, value); } else if (region.is_matrix_type ()) { @@ -158,7 +159,7 @@ double base = array(0); double limit = array(array.numel () - 1); double incr = array(1) - base; - output = Range (base, limit, incr); + output = octave::range (base, incr, limit); } else error ("__magick_read__: unknown datatype for Region option"); @@ -180,8 +181,8 @@ // Subtract 1 to account for 0 indexing. - const Range rows = get_region_range (pixel_region (0)); - const Range cols = get_region_range (pixel_region (1)); + const octave::range rows = get_region_range (pixel_region (0)); + const octave::range cols = get_region_range (pixel_region (1)); m_row_start = rows.base () - 1; m_col_start = cols.base () - 1; @@ -191,8 +192,8 @@ m_row_cache = m_row_end - m_row_start + 1; m_col_cache = m_col_end - m_col_start + 1; - m_row_shift = m_col_cache * rows.inc (); - m_col_shift = m_col_cache * (m_row_cache + rows.inc () - 1) - cols.inc (); + m_row_shift = m_col_cache * rows.increment (); + m_col_shift = m_col_cache * (m_row_cache + rows.increment () - 1) - cols.increment (); m_row_out = rows.numel (); m_col_out = cols.numel (); @@ -754,9 +755,15 @@ void static read_file (const std::string& filename, std::vector& imvec) { + // FIXME: We need this on Windows because GraphicsMagick uses the ANSI API + // to open files on disc. In contrast, the API of ImageMagick uses UTF-8 + // encoded strings. Should we somehow detect which is used on runtime and + // pass the file names accordingly? (See also bug #58493.) + std::string ascii_fname = octave::sys::get_ASCII_filename (filename, true); + try { - Magick::readImages (&imvec, filename); + Magick::readImages (&imvec, ascii_fname); } catch (Magick::Warning& w) { @@ -1551,7 +1558,7 @@ encode_indexed_images (imvec, img.uint16_array_value (), cmap); else - error ("__magick_write__: indexed image must be uint8, uint16 or float."); + error ("__magick_write__: indexed image must be uint8, uint16 or float"); } static std::map disposal_methods = init_reverse_disposal_methods (); @@ -1687,9 +1694,16 @@ Magick::Image img; img.subImage (idx); // start ping from this image (in case of multi-page) img.subRange (1); // ping only one of them + + // FIXME: We need this on Windows because GraphicsMagick uses the ANSI API + // to open files on disc. In contrast, the API of ImageMagick uses UTF-8 + // encoded strings. Should we somehow detect which is used on runtime and + // pass the file names accordingly? (See also bug #58493.) + std::string ascii_fname = octave::sys::get_ASCII_filename (filename, true); + try { - img.ping (filename); + img.ping (ascii_fname); } catch (Magick::Warning& w) { diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/besselj.cc --- a/libinterp/corefcn/besselj.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/besselj.cc Thu Nov 19 13:08:00 2020 -0800 @@ -737,12 +737,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %!assert (besselj (-alpha,x), jx, 100*eps) %!assert (bessely (-alpha,x), yx, 100*eps) @@ -751,12 +751,12 @@ %!assert (besselh (-alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (-alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (-alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (-alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (-alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (-alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (-alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %! x *= -1; %! yx = -1.193199310178553861283790424 + 0.3421822624810469647226182835*I; @@ -769,12 +769,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %! ## Bessel functions, odd order, positive and negative x %! alpha = 3; x = 2.5; @@ -790,12 +790,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %!assert (besselj (-alpha,x), -jx, 100*eps) %!assert (bessely (-alpha,x), -yx, 100*eps) @@ -804,12 +804,12 @@ %!assert (besselh (-alpha,1,x), -(jx + I*yx), 100*eps) %!assert (besselh (-alpha,2,x), -(jx - I*yx), 100*eps) %! -%!assert (besselj (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (-alpha,x,1), -yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (-alpha,x,1), -jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (-alpha,x,1), -yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (-alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (-alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp (I*x), 100*eps) %! %! x *= -1; %! jx = -jx; @@ -824,12 +824,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %! ## Bessel functions, fractional order, positive and negative x %! @@ -846,12 +846,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %! nix = 0.2119931212254662995364461998; %! @@ -862,12 +862,12 @@ %!assert (besselh (-alpha,1,x), -I*(jx + I*yx), 100*eps) %!assert (besselh (-alpha,2,x), I*(jx - I*yx), 100*eps) %! -%!assert (besselj (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (-alpha,x,1), nix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (-alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (-alpha,x,1), -jx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (-alpha,x,1), nix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (-alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp (I*x), 100*eps) %! %! x *= -1; %! jx *= -I; @@ -882,12 +882,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %! ## Bessel functions, even order, complex x %! @@ -904,12 +904,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %!assert (besselj (-alpha,x), jx, 100*eps) %!assert (bessely (-alpha,x), yx, 100*eps) @@ -918,12 +918,12 @@ %!assert (besselh (-alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (-alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (-alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (-alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (-alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (-alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (-alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (-alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (-alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %! ## Bessel functions, odd order, complex x %! @@ -940,12 +940,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %!assert (besselj (-alpha,x), -jx, 100*eps) %!assert (bessely (-alpha,x), -yx, 100*eps) @@ -954,12 +954,12 @@ %!assert (besselh (-alpha,1,x), -(jx + I*yx), 100*eps) %!assert (besselh (-alpha,2,x), -(jx - I*yx), 100*eps) %! -%!assert (besselj (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (-alpha,x,1), -yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (-alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (-alpha,x,1), -jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (-alpha,x,1), -yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (-alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (-alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (-alpha,1,x,1), -(jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (-alpha,2,x,1), -(jx - I*yx)*exp (I*x), 100*eps) %! %! ## Bessel functions, fractional order, complex x %! @@ -976,12 +976,12 @@ %!assert (besselh (alpha,1,x), jx + I*yx, 100*eps) %!assert (besselh (alpha,2,x), jx - I*yx, 100*eps) %! -%!assert (besselj (alpha,x,1), jx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (alpha,x,1), ix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (alpha,x,1), jx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (alpha,x,1), ix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (alpha,1,x,1), (jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (alpha,2,x,1), (jx - I*yx)*exp (I*x), 100*eps) %! %! nix = 0.09822388691172060573913739253 - 0.7110230642207380127317227407*I; %! @@ -992,12 +992,12 @@ %!assert (besselh (-alpha,1,x), -I*(jx + I*yx), 100*eps) %!assert (besselh (-alpha,2,x), I*(jx - I*yx), 100*eps) %! -%!assert (besselj (-alpha,x,1), yx*exp(-abs(imag(x))), 100*eps) -%!assert (bessely (-alpha,x,1), -jx*exp(-abs(imag(x))), 100*eps) -%!assert (besseli (-alpha,x,1), nix*exp(-abs(real(x))), 100*eps) -%!assert (besselk (-alpha,x,1), kx*exp(x), 100*eps) -%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp(-I*x), 100*eps) -%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp(I*x), 100*eps) +%!assert (besselj (-alpha,x,1), yx*exp (-abs (imag (x))), 100*eps) +%!assert (bessely (-alpha,x,1), -jx*exp (-abs (imag (x))), 100*eps) +%!assert (besseli (-alpha,x,1), nix*exp (-abs (real (x))), 100*eps) +%!assert (besselk (-alpha,x,1), kx*exp (x), 100*eps) +%!assert (besselh (-alpha,1,x,1), -I*(jx + I*yx)*exp (-I*x), 100*eps) +%!assert (besselh (-alpha,2,x,1), I*(jx - I*yx)*exp (I*x), 100*eps) Tests contributed by Robert T. Short. Tests are based on the properties and tables in A&S: diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/bsxfun.cc --- a/libinterp/corefcn/bsxfun.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/bsxfun.cc Thu Nov 19 13:08:00 2020 -0800 @@ -540,7 +540,7 @@ { have_NDArray = false; C = result_NDArray; - C = do_cat_op (C, tmp(0), ra_idx); + C = octave::cat_op (C, tmp(0), ra_idx); } else if (tmp(0).isreal ()) result_NDArray.insert (tmp(0).array_value (), ra_idx); @@ -560,7 +560,7 @@ { have_FloatNDArray = false; C = result_FloatNDArray; - C = do_cat_op (C, tmp(0), ra_idx); + C = octave::cat_op (C, tmp(0), ra_idx); } else if (tmp(0).isreal ()) result_FloatNDArray.insert @@ -583,7 +583,7 @@ { \ have_ ## T = false; \ C = result_ ## T; \ - C = do_cat_op (C, tmp(0), ra_idx); \ + C = octave::cat_op (C, tmp(0), ra_idx); \ } \ else \ result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \ @@ -601,7 +601,7 @@ else if BSXLOOP(uint32NDArray, "uint32", uint32) else if BSXLOOP(uint64NDArray, "uint64", uint64) else - C = do_cat_op (C, tmp(0), ra_idx); + C = octave::cat_op (C, tmp(0), ra_idx); } } @@ -637,12 +637,12 @@ %! b = mean (a, 1); %! c = mean (a, 2); %! f = @minus; -%!error (bsxfun (f)) -%!error (bsxfun (f, a)) -%!error (bsxfun (a, b)) -%!error (bsxfun (a, b, c)) -%!error (bsxfun (f, a, b, c)) -%!error (bsxfun (f, ones (4, 0), ones (4, 4))) +%!error bsxfun (f) +%!error bsxfun (f, a) +%!error bsxfun (a, b) +%!error bsxfun (a, b, c) +%!error bsxfun (f, a, b, c) +%!error bsxfun (f, ones (4, 0), ones (4, 4)) %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0)) %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4)) %!assert (bsxfun (f, a, b), a - repmat (b, 4, 1)) @@ -655,12 +655,12 @@ %! b = mean (a, 1); %! c = mean (a, 2); %! f = @minus; -%!error (bsxfun (f)) -%!error (bsxfun (f, a)) -%!error (bsxfun (a, b)) -%!error (bsxfun (a, b, c)) -%!error (bsxfun (f, a, b, c)) -%!error (bsxfun (f, ones (4, 0), ones (4, 4))) +%!error bsxfun (f) +%!error bsxfun (f, a) +%!error bsxfun (a, b) +%!error bsxfun (a, b, c) +%!error bsxfun (f, a, b, c) +%!error bsxfun (f, ones (4, 0), ones (4, 4)) %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0)) %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4)) %!assert (bsxfun (f, a, b), a - repmat (b, 4, 1)) @@ -673,12 +673,12 @@ %! b = mean (a, 1); %! c = mean (a, 2); %! f = @minus; -%!error (bsxfun (f)) -%!error (bsxfun (f, a)) -%!error (bsxfun (a, b)) -%!error (bsxfun (a, b, c)) -%!error (bsxfun (f, a, b, c)) -%!error (bsxfun (f, ones (4, 0), ones (4, 4))) +%!error bsxfun (f) +%!error bsxfun (f, a) +%!error bsxfun (a, b) +%!error bsxfun (a, b, c) +%!error bsxfun (f, a, b, c) +%!error bsxfun (f, ones (4, 0), ones (4, 4)) %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0)) %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4)) %!assert (bsxfun (f, a, b), a - repmat (b, 4, 1)) @@ -690,12 +690,12 @@ %! b = a (1, :); %! c = a (:, 1); %! f = @(x, y) x == y; -%!error (bsxfun (f)) -%!error (bsxfun (f, a)) -%!error (bsxfun (a, b)) -%!error (bsxfun (a, b, c)) -%!error (bsxfun (f, a, b, c)) -%!error (bsxfun (f, ones (4, 0), ones (4, 4))) +%!error bsxfun (f) +%!error bsxfun (f, a) +%!error bsxfun (a, b) +%!error bsxfun (a, b, c) +%!error bsxfun (f, a, b, c) +%!error bsxfun (f, ones (4, 0), ones (4, 4)) %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0, "logical")) %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), ones (4, 4, "logical")) %!assert (bsxfun (f, a, b), a == repmat (b, 4, 1)) @@ -707,7 +707,7 @@ %! c = mean (a, 2); %! d = mean (a, 3); %! f = @minus; -%!error (bsxfun (f, ones ([4, 0, 4]), ones ([4, 4, 4]))) +%!error bsxfun (f, ones ([4, 0, 4]), ones ([4, 4, 4])) %!assert (bsxfun (f, ones ([4, 0, 4]), ones ([4, 1, 4])), zeros ([4, 0, 4])) %!assert (bsxfun (f, ones ([4, 4, 0]), ones ([4, 1, 1])), zeros ([4, 4, 0])) %!assert (bsxfun (f, ones ([1, 4, 4]), ones ([4, 1, 4])), zeros ([4, 4, 4])) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/call-stack.cc --- a/libinterp/corefcn/call-stack.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/call-stack.cc Thu Nov 19 13:08:00 2020 -0800 @@ -823,7 +823,7 @@ void call_stack::clear_global_variable_regexp (const std::string& pattern) { - octave::regexp pat (pattern); + regexp pat (pattern); for (auto& nm_ov : m_global_values) { @@ -968,14 +968,13 @@ // implement this option there so that the variables are never // stored at all. - unwind_protect frame; - // Set up temporary scope. symbol_scope tmp_scope ("$dummy_scope$"); push (tmp_scope); - frame.add_method (*this, &call_stack::pop); + + unwind_action restore_scope ([=] (void) { pop (); }); feval ("load", octave_value (file_name), 0); @@ -1025,7 +1024,7 @@ if (have_regexp) { - octave::regexp pat (pattern); + regexp pat (pattern); for (auto& nm_ov : m_global_values) { @@ -1162,7 +1161,7 @@ %! max_stack_depth (orig_val); %! assert (max_stack_depth (), orig_val); -%!error (max_stack_depth (1, 2)) +%!error max_stack_depth (1, 2) */ DEFMETHOD (who, interp, args, nargout, diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/cellfun.cc --- a/libinterp/corefcn/cellfun.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/cellfun.cc Thu Nov 19 13:08:00 2020 -0800 @@ -1259,7 +1259,7 @@ for (int j = 0; j < nargin; j++) { if (mask[j]) - inputlist.xelem (j) = inputs[j].do_index_op (idx_list); + inputlist.xelem (j) = inputs[j].index_op (idx_list); } const octave_value_list tmp @@ -1351,7 +1351,7 @@ for (int j = 0; j < nargin; j++) { if (mask[j]) - inputlist.xelem (j) = inputs[j].do_index_op (idx_list); + inputlist.xelem (j) = inputs[j].index_op (idx_list); } const octave_value_list tmp @@ -1579,14 +1579,14 @@ %! A = arrayfun (@(x,y) x.a:y.a, a, b, "UniformOutput", false); %! assert (isequal (A, {[1.1, 2.1, 3.1]})); %!test -%! A = arrayfun (@(x) mat2str(x), "a", "ErrorHandler", @__arrayfunerror); +%! A = arrayfun (@(x) mat2str (x), "a", "ErrorHandler", @__arrayfunerror); %! assert (isfield (A, "identifier"), true); %! assert (isfield (A, "message"), true); %! assert (isfield (A, "index"), true); %! assert (isempty (A.message), false); %! assert (A.index, 1); %!test # Overwriting setting of "UniformOutput" true -%! A = arrayfun (@(x) mat2str(x), "a", "UniformOutput", true, ... +%! A = arrayfun (@(x) mat2str (x), "a", "UniformOutput", true, ... %! "ErrorHandler", @__arrayfunerror); %! assert (isfield (A, "identifier"), true); %! assert (isfield (A, "message"), true); @@ -2100,7 +2100,7 @@ for (int i = 0; i < nd; i++) ra_idx(i) = idx[i][ridx[i]]; - retval.xelem (j) = a.do_index_op (ra_idx); + retval.xelem (j) = a.index_op (ra_idx); rdv.increment_index (ridx); } @@ -2434,8 +2434,8 @@ octave_value_list idx (ndims, octave_value::magic_colon_t); for (octave_idx_type i = 0; i < n; i++) { - idx(dim) = Range (lb(i), ub(i)); - retcell.xelem (i) = x.do_index_op (idx); + idx(dim) = octave::range (lb(i), ub(i)); + retcell.xelem (i) = x.index_op (idx); } } @@ -2486,7 +2486,7 @@ octave_value tmp = x(i); - y.xelem (i) = tmp.do_index_op (idx); + y.xelem (i) = tmp.index_op (idx); } return octave_value (y); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/chol.cc --- a/libinterp/corefcn/chol.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/chol.cc Thu Nov 19 13:08:00 2020 -0800 @@ -581,11 +581,11 @@ %! sparse_chol2inv (B, eps*100); %!testif HAVE_CHOLMOD -%! C = gallery("tridiag", 5); +%! C = gallery ("tridiag", 5); %! sparse_chol2inv (C, eps*10); %!testif HAVE_CHOLMOD -%! D = gallery("wathen", 1, 1); +%! D = gallery ("wathen", 1, 1); %! sparse_chol2inv (D, eps*10^4); */ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/colamd.cc --- a/libinterp/corefcn/colamd.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/colamd.cc Thu Nov 19 13:08:00 2020 -0800 @@ -692,6 +692,15 @@ ridx = scm.xridx (); cidx = scm.xcidx (); } + else if (args(0).islogical ()) + { + SparseBoolMatrix sbm = args(0).sparse_bool_matrix_value (); + + n_row = sbm.rows (); + n_col = sbm.cols (); + ridx = sbm.xridx (); + cidx = sbm.xcidx (); + } else { SparseMatrix sm = args(0).sparse_matrix_value (); @@ -763,8 +772,10 @@ } /* -%!assert (etree (speye (2)), [0, 0]); -%!assert (etree (gallery ("poisson", 16)), [2:256, 0]); +%!assert (etree (sparse ([1,2], [1,2], [1,1], 2, 2)), [0, 0]) +%!assert (etree (sparse ([1,2], [1,2], [true, true], 2, 2)), [0, 0]) +%!assert (etree (sparse ([1,2], [1,2], [i,i], 2, 2)), [0, 0]) +%!assert (etree (gallery ("poisson", 16)), [2:256, 0]) %!error etree () %!error etree (1, 2, 3) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/colloc.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/conv2.cc --- a/libinterp/corefcn/conv2.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/conv2.cc Thu Nov 19 13:08:00 2020 -0800 @@ -550,18 +550,18 @@ %! 925 1976 2363 1971 1636 1600 1844 2239 1664 626 %! 372 1133 1558 1687 1570 1401 1243 1122 883 264 %! 60 270 556 857 1024 870 569 282 66 0]; -%!assert (convn(a, b, "full"), c) -%!assert (convn(a, b, "same"), c(3:6,2:9,2:5,:)) -%!assert (convn(a, b, "valid"), c(4,3:8,3:4,:)) +%!assert (convn (a, b, "full"), c) +%!assert (convn (a, b, "same"), c(3:6,2:9,2:5,:)) +%!assert (convn (a, b, "valid"), c(4,3:8,3:4,:)) ## test correct class -%!assert (class (convn (rand(5), rand(3))), "double") -%!assert (class (convn (rand(5, "single"), rand(3))), "single") -%!assert (class (convn (rand(5), rand(3, "single"))), "single") -%!assert (class (convn (true (5), rand(3))), "double") -%!assert (class (convn (true (5), rand(3, "single"))), "single") -%!assert (class (convn (ones(5, "uint8"), rand(3))), "double") -%!assert (class (convn (rand (3, "single"), ones(5, "uint8"))), "single") +%!assert (class (convn (rand (5), rand (3))), "double") +%!assert (class (convn (rand (5, "single"), rand (3))), "single") +%!assert (class (convn (rand (5), rand (3, "single"))), "single") +%!assert (class (convn (true (5), rand (3))), "double") +%!assert (class (convn (true (5), rand (3, "single"))), "single") +%!assert (class (convn (ones (5, "uint8"), rand (3))), "double") +%!assert (class (convn (rand (3, "single"), ones (5, "uint8"))), "single") %!error convn () %!error convn (1) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/daspk.cc --- a/libinterp/corefcn/daspk.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/daspk.cc Thu Nov 19 13:08:00 2020 -0800 @@ -269,9 +269,7 @@ octave_value_list retval (4); - octave::unwind_protect frame; - - frame.protect_var (call_depth); + octave::unwind_protect_var restore_var (call_depth); call_depth++; if (call_depth > 1) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dasrt.cc --- a/libinterp/corefcn/dasrt.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dasrt.cc Thu Nov 19 13:08:00 2020 -0800 @@ -348,9 +348,7 @@ octave_value_list retval (5); - octave::unwind_protect frame; - - frame.protect_var (call_depth); + octave::unwind_protect_var restore_var (call_depth); call_depth++; if (call_depth > 1) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dassl.cc --- a/libinterp/corefcn/dassl.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dassl.cc Thu Nov 19 13:08:00 2020 -0800 @@ -269,9 +269,7 @@ octave_value_list retval (4); - octave::unwind_protect frame; - - frame.protect_var (call_depth); + octave::unwind_protect_var restore_var (call_depth); call_depth++; if (call_depth > 1) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/data.cc --- a/libinterp/corefcn/data.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/data.cc Thu Nov 19 13:08:00 2020 -0800 @@ -889,7 +889,7 @@ %!assert (mod (uint8 (5), uint8 (4)), uint8 (1)) %!assert (mod (uint8 ([1:5]), uint8 (4)), uint8 ([1,2,3,0,1])) %!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5])) -%!error (mod (uint8 (5), int8 (4))) +%!error mod (uint8 (5), int8 (4)) ## mixed integer/real types %!assert (mod (uint8 (5), 4), uint8 (1)) @@ -1040,8 +1040,8 @@ @end group @end example -See @code{sum} for an explanation of the optional parameters @qcode{"native"} -and @qcode{"double"}. +For an explanation of the optional parameters @qcode{"native"} and +@qcode{"double"}, @pxref{XREFsum,,@code{sum}}. @seealso{sum, cumprod} @end deftypefn */) { @@ -1955,7 +1955,7 @@ // Can't fast return here to skip empty matrices as something // like cat (1,[],single ([])) must return an empty matrix of // the right type. - tmp = do_cat_op (tmp, args(j), ra_idx); + tmp = octave::cat_op (tmp, args(j), ra_idx); dim_vector dv_tmp = args(j).dims (); @@ -2213,8 +2213,8 @@ %!error horzcat (struct ("foo", "bar"), cell (1)) -%!test <*39041> assert (class (horzcat (cell(0), struct())), "cell") -%!test <51086> assert (class (horzcat (struct(), cell(0))), "struct") +%!test <*39041> assert (class (horzcat (cell (0), struct ())), "cell") +%!test <51086> assert (class (horzcat (struct (), cell (0))), "struct") */ DEFUN (vertcat, args, , @@ -2796,10 +2796,10 @@ %!assert (nnz (-5:0), 5) %!assert (nnz (-5:5), 10) %!assert (nnz (-2:1:2), 4) -%!assert (nnz (-2+eps(2):1:2), 5) -%!assert (nnz (-2-eps(2):1:2), 5) -%!assert (nnz (-2:1+eps(1):2), 5) -%!assert (nnz (-2:1-eps(1):2), 5) +%!assert (nnz (-2+eps (2):1:2), 5) +%!assert (nnz (-2-eps (2):1:2), 5) +%!assert (nnz (-2:1+eps (1):2), 5) +%!assert (nnz (-2:1-eps (1):2), 5) %!assert (nnz ([1:5] * 0), 0) %!assert (nnz ([-5:-1] * 0), 0) %!assert (nnz ([-1:1] * 0), 0) @@ -3631,7 +3631,7 @@ /* ## Debian bug #706376 -%!assert (isempty (speye(2^16)), false) +%!assert (isempty (speye (2^16)), false) */ DEFUN (isnumeric, args, , @@ -4023,7 +4023,13 @@ case oct_data_conv::dt_double: { if (dims.ndims () == 2 && dims(0) == 1) - retval = Range (static_cast (val), 0.0, dims(1)); + { + // FIXME: If this optimization provides a significant + // benefit, then maybe there should be a special storage + // type for constant value arrays. + double dval = static_cast (val); + retval = octave::range::make_constant (dval, dims(1)); + } else retval = NDArray (dims, val); } @@ -4095,7 +4101,10 @@ case oct_data_conv::dt_double: if (dims.ndims () == 2 && dims(0) == 1 && octave::math::isfinite (val)) - retval = Range (val, 0.0, dims(1)); // Packed form + // FIXME: If this optimization provides a significant benefit, + // then maybe there should be a special storage type for + // constant value arrays. + retval = octave::range::make_constant (val, dims(1)); else retval = NDArray (dims, val); break; @@ -4161,7 +4170,10 @@ case oct_data_conv::dt_double: if (dims.ndims () == 2 && dims(0) == 1 && octave::math::isfinite (val)) - retval = Range (val, 0.0, dims(1)); // Packed form + // FIXME: If this optimization provides a significant benefit, + // then maybe there should be a special storage type for + // constant value arrays. + retval = octave::range::make_constant (val, dims(1)); else retval = NDArray (dims, val); break; @@ -4248,6 +4260,18 @@ dim_vector dims (1, 1); + // The TYPE argument is required to be "logical" if present. This + // feature appears to be undocumented in Matlab. + + if (nargin > 0 && args(nargin-1).is_string ()) + { + std::string nm = args(nargin-1).string_value (); + nargin--; + + if (oct_data_conv::string_to_data_type (nm) != oct_data_conv::dt_logical) + error ("%s: invalid data type '%s'", fcn, nm.c_str ()); + } + switch (nargin) { case 0: @@ -4461,10 +4485,10 @@ %!assert (inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf])) %!assert (size (inf (3, 4, 5, "single")), [3, 4, 5]) -%!error (inf (3, "int8")) -%!error (inf (2, 3, "int8")) -%!error (inf (3, 2, "int8")) -%!error (inf (3, 4, 5, "int8")) +%!error inf (3, "int8") +%!error inf (2, 3, "int8") +%!error inf (3, 2, "int8") +%!error inf (3, 4, 5, "int8") */ DEFUN (NaN, args, , @@ -4526,10 +4550,10 @@ %!assert (NaN (3, 2, "single"), single ([NaN, NaN; NaN, NaN; NaN, NaN])) %!assert (size (NaN (3, 4, 5, "single")), [3, 4, 5]) -%!error (NaN (3, "int8")) -%!error (NaN (2, 3, "int8")) -%!error (NaN (3, 2, "int8")) -%!error (NaN (3, 4, 5, "int8")) +%!error NaN (3, "int8") +%!error NaN (2, 3, "int8") +%!error NaN (3, 2, "int8") +%!error NaN (3, 4, 5, "int8") */ DEFUN (e, args, , @@ -4908,6 +4932,12 @@ return fill_matrix (args, false, "false"); } +/* +%!assert (false (2, 3), logical (zeros (2, 3))) +%!assert (false (2, 3, "logical"), logical (zeros (2, 3))) +%!error false (2, 3, "double") +*/ + DEFUN (true, args, , doc: /* -*- texinfo -*- @deftypefn {} {} true (@var{x}) @@ -4926,6 +4956,12 @@ return fill_matrix (args, true, "true"); } +/* +%!assert (true (2, 3), logical (ones (2, 3))) +%!assert (true (2, 3, "logical"), logical (ones (2, 3))) +%!error true (2, 3, "double") +*/ + template octave_value identity_matrix (int nr, int nc) @@ -5931,7 +5967,7 @@ if (args.length () != 1) print_usage (); - return do_unary_op (op, args(0)); + return octave::unary_op (op, args(0)); } DEFUN (not, args, , @@ -6037,7 +6073,7 @@ if (args.length () != 2) print_usage (); - return do_binary_op (op, args(0), args(1)); + return octave::binary_op (op, args(0), args(1)); } static octave_value @@ -6053,10 +6089,10 @@ octave_value retval; if (nargin == 2) - retval = do_binary_op (op, args(0), args(1)); + retval = octave::binary_op (op, args(0), args(1)); else { - retval = do_binary_op (op, args(0), args(1)); + retval = octave::binary_op (op, args(0), args(1)); for (int i = 2; i < nargin; i++) retval.assign (aop, args(i)); @@ -6351,8 +6387,9 @@ if (nargin < 2 || nargin > 3) print_usage (); - return (nargin == 2 ? do_colon_op (args(0), args(1)) - : do_colon_op (args(0), args(1), args(2))); + return (nargin == 2 + ? octave::colon_op (args(0), args(1)) + : octave::colon_op (args(0), args(1), args(2))); } static double tic_toc_timestamp = -1.0; @@ -6471,7 +6508,7 @@ } if (start_time < 0) - error ("toc called before timer set"); + error ("toc: function called before timer initialization with tic()"); octave::sys::time now; @@ -7195,8 +7232,8 @@ if (vals.is_range ()) { - Range r = vals.range_value (); - if (r.inc () == 0) + octave::range r = vals.range_value (); + if (r.increment () == 0) vals = r.base (); } @@ -7941,7 +7978,7 @@ Encode a double matrix or array @var{x} into the base64 format string @var{s}. -@seealso{base64_decode} +@seealso{base64_decode, matlab.net.base64decode, matlab.net.base64encode} @end deftypefn */) { if (args.length () != 1) @@ -8049,7 +8086,7 @@ The optional input parameter @var{dims} should be a vector containing the dimensions of the decoded array. -@seealso{base64_encode} +@seealso{base64_encode, matlab.net.base64decode, matlab.net.base64encode} @end deftypefn */) { int nargin = args.length (); @@ -8095,3 +8132,57 @@ %!error base64_decode ("AQ=") %!error base64_decode ("AQ==") */ + +DEFUN (__base64_decode_bytes__, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {@var{x} =} base64_decode_bytes (@var{s}) +@deftypefnx {} {@var{x} =} base64_decode_bytes (@var{s}, @var{dims}) +Decode the uint8 matrix or array @var{x} from the base64 encoded string +@var{s}. + +The optional input parameter @var{dims} should be a vector containing the +dimensions of the decoded array. +@seealso{base64_decode} +@end deftypefn */) +{ + int nargin = args.length (); + + if (nargin < 1 || nargin > 2) + print_usage (); + + std::string str = args(0).string_value (); + + intNDArray retval = octave::base64_decode_bytes (str); + + if (nargin == 2) + { + dim_vector dims; + + const Array size + = args(1).octave_idx_type_vector_value (); + + dims = dim_vector::alloc (size.numel ()); + for (octave_idx_type i = 0; i < size.numel (); i++) + dims(i) = size(i); + + retval = retval.reshape (dims); + } + + return ovl (retval); +} + +/* +%!assert (__base64_decode_bytes__ (base64_encode (uint8 (1))), uint8 (1)) + +%!test +%! in = uint8 (rand (10)*255); +%! outv = __base64_decode_bytes__ (base64_encode (in)); +%! outm = __base64_decode_bytes__ (base64_encode (in), size (in)); +%! assert (outv, in(:).'); +%! assert (outm, in); + +%!error __base64_decode_bytes__ () +%!error __base64_decode_bytes__ (1,2,3) +%!error __base64_decode_bytes__ (1, "this is not a valid set of dimensions") +%!error __base64_decode_bytes__ (1) +*/ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/debug.cc --- a/libinterp/corefcn/debug.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/debug.cc Thu Nov 19 13:08:00 2020 -0800 @@ -222,10 +222,7 @@ && bkpt.cell_value () (0).isstruct ()) mv = bkpt.cell_value () (0).map_value (); else - { - error ("dbstop: invalid 'bkpt' field"); - mv = octave_map (); - } + error ("dbstop: invalid 'bkpt' field"); } } if (mv.isempty ()) @@ -235,7 +232,6 @@ else if (! mv.isfield ("name") || ! mv.isfield ("line")) { error ("dbstop: Cell array must contain fields 'name' and 'line'"); - retval = octave_value (0); } else { @@ -293,7 +289,7 @@ @item event An event such as @code{error}, @code{interrupt}, or @code{warning} -(@pxref{XREFdbstop,,dbstop} for details). +(@pxref{XREFdbstop,,@code{dbstop}} for details). @end table When called without a line number specification all breakpoints in the named @@ -838,8 +834,6 @@ octave_value_list retval; - octave::unwind_protect frame; - octave_idx_type curr_frame = -1; size_t nskip = 0; diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/det.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dirfns.cc --- a/libinterp/corefcn/dirfns.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dirfns.cc Thu Nov 19 13:08:00 2020 -0800 @@ -224,7 +224,7 @@ } } -DEFMETHODX ("rmdir", Frmdir, interp, args, , +DEFMETHODX ("rmdir", Frmdir, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} rmdir @var{dir} @deftypefnx {} {} rmdir (@var{dir}, "s") @@ -250,6 +250,7 @@ std::string dirname = args(0).xstring_value ("rmdir: DIR must be a string"); std::string fulldir = octave::sys::file_ops::tilde_expand (dirname); + octave_value_list retval; int status = -1; std::string msg; @@ -287,20 +288,30 @@ evmgr.file_renamed (status >= 0); - if (status < 0) - return ovl (false, msg, "rmdir"); + if (nargout == 0) + { + if (status < 0) + error ("rmdir: operation failed: %s", msg.c_str ()); + } else - return ovl (true, "", ""); + { + if (status < 0) + retval = ovl (0.0, msg, "rmdir"); + else + retval = ovl (1.0, "", ""); + } + + return retval; } -DEFUNX ("link", Flink, args, , +DEFUNX ("link", Flink, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} link @var{old} @var{new} -@deftypefnx {} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new}) +@deftypefnx {} {[@var{status}, @var{msg}] =} link (@var{old}, @var{new}) Create a new link (also known as a hard link) to an existing file. -If successful, @var{err} is 0 and @var{msg} is an empty string. -Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent +If successful, @var{status} is 0 and @var{msg} is an empty string. +Otherwise, @var{status} is -1 and @var{msg} contains a system-dependent error message. @seealso{symlink, unlink, readlink, lstat} @end deftypefn */) @@ -314,24 +325,35 @@ from = octave::sys::file_ops::tilde_expand (from); to = octave::sys::file_ops::tilde_expand (to); + octave_value_list retval; std::string msg; int status = octave::sys::link (from, to, msg); - if (status < 0) - return ovl (-1.0, msg); + if (nargout == 0) + { + if (status < 0) + error ("link: operation failed: %s", msg.c_str ()); + } else - return ovl (status, ""); + { + if (status < 0) + retval = ovl (-1.0, msg); + else + retval = ovl (0.0, ""); + } + + return retval; } -DEFUNX ("symlink", Fsymlink, args, , +DEFUNX ("symlink", Fsymlink, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} symlink @var{old} @var{new} -@deftypefnx {} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new}) +@deftypefnx {} {[@var{status}, @var{msg}] =} symlink (@var{old}, @var{new}) Create a symbolic link @var{new} which contains the string @var{old}. -If successful, @var{err} is 0 and @var{msg} is an empty string. -Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent +If successful, @var{status} is 0 and @var{msg} is an empty string. +Otherwise, @var{status} is -1 and @var{msg} contains a system-dependent error message. @seealso{link, unlink, readlink, lstat} @end deftypefn */) @@ -345,14 +367,25 @@ from = octave::sys::file_ops::tilde_expand (from); to = octave::sys::file_ops::tilde_expand (to); + octave_value_list retval; std::string msg; int status = octave::sys::symlink (from, to, msg); - if (status < 0) - return ovl (-1.0, msg); + if (nargout == 0) + { + if (status < 0) + error ("symlink: operation failed: %s", msg.c_str ()); + } else - return ovl (status, ""); + { + if (status < 0) + retval = ovl (-1.0, msg); + else + retval = ovl (0.0, ""); + } + + return retval; } DEFUNX ("readlink", Freadlink, args, , @@ -385,14 +418,14 @@ return ovl (result, status, ""); } -DEFMETHODX ("rename", Frename, interp, args, , +DEFMETHODX ("rename", Frename, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} rename @var{old} @var{new} -@deftypefnx {} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new}) +@deftypefnx {} {[@var{status}, @var{msg}] =} rename (@var{old}, @var{new}) Change the name of file @var{old} to @var{new}. -If successful, @var{err} is 0 and @var{msg} is an empty string. -Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent +If successful, @var{status} is 0 and @var{msg} is an empty string. +Otherwise, @var{status} is -1 and @var{msg} contains a system-dependent error message. @seealso{movefile, copyfile, ls, dir} @end deftypefn */) @@ -406,6 +439,7 @@ from = octave::sys::file_ops::tilde_expand (from); to = octave::sys::file_ops::tilde_expand (to); + octave_value_list retval; std::string msg; octave::event_manager& evmgr = interp.get_event_manager (); @@ -414,16 +448,22 @@ int status = octave::sys::rename (from, to, msg); - if (status < 0) + evmgr.file_renamed (status >= 0); + + if (nargout == 0) { - evmgr.file_renamed (false); - return ovl (-1.0, msg); + if (status < 0) + error ("rename: operation failed: %s", msg.c_str ()); } else { - evmgr.file_renamed (true); - return ovl (status, ""); + if (status < 0) + retval = ovl (-1.0, msg); + else + retval = ovl (0.0, ""); } + + return retval; } DEFUN (glob, args, , @@ -474,13 +514,18 @@ [2,1] = file2 @} @end example + +Note: On Windows, patterns that contain non-ASCII characters are not +supported. + @seealso{ls, dir, readdir, what} @end deftypefn */) { if (args.length () != 1) print_usage (); - string_vector pat = args(0).xstring_vector_value ("glob: PATTERN must be a string"); + string_vector pat + = args(0).xstring_vector_value ("glob: PATTERN must be a string"); glob_match pattern (octave::sys::file_ops::tilde_expand (pat)); @@ -556,10 +601,10 @@ /* %!test -%! tmpdir = tempname; +%! tmpdir = tempname (); %! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"}; %! if (mkdir (tmpdir)) -%! cwd = pwd; +%! cwd = pwd (); %! cd (tmpdir); %! if (strcmp (canonicalize_file_name (pwd), canonicalize_file_name (tmpdir))) %! a = 0; @@ -567,8 +612,8 @@ %! save (filename{n}, "a"); %! endfor %! else -%! rmdir (tmpdir); -%! error ("Couldn't change to temporary dir"); +%! sts = rmdir (tmpdir); +%! error ("Couldn't change to temporary directory"); %! endif %! else %! error ("Couldn't create temporary directory"); @@ -580,7 +625,7 @@ %! delete (filename{n}); %! endfor %! cd (cwd); -%! rmdir (tmpdir); +%! sts = rmdir (tmpdir); %! assert (result1, {"file1"; "myfile1"}); %! assert (result2, {"myfile1"}); %! assert (result3, {"file1"; "file2"}); @@ -656,9 +701,7 @@ @seealso{filesep} @end deftypefn */) { - int nargin = args.length (); - - if (nargin > 0) + if (args.length () > 0) print_usage (); return ovl (octave::directory_path::path_sep_str ()); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dlmread.cc --- a/libinterp/corefcn/dlmread.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dlmread.cc Thu Nov 19 13:08:00 2020 -0800 @@ -305,6 +305,32 @@ bool sep_is_wspace = (sep.find_first_of (" \t") != std::string::npos); bool auto_sep_is_wspace = false; + if (r0 == 0) + { + // Peek into stream and potentially strip Byte Order Mark (BOM) + const char BOM[3] = {'\xEF', '\xBB', '\xBF'}; + char buf[3]; + int i_bom; + bool found_bom = true; + for (i_bom = 0; i_bom < 3; i_bom++) + { + char ch_p = input->peek (); + if (ch_p == BOM[i_bom]) + buf[i_bom] = input->get (); + else + { + found_bom = false; + break; + } + } + // Put back read characters if it wasn't a BOM + if (! found_bom) + { + for (int i_ret = i_bom-1; i_ret >= 0; i_ret--) + input->putback (buf[i_ret]); + } + } + std::string line; // Skip the r0 leading lines @@ -443,7 +469,7 @@ tmp_stream.str (str); tmp_stream.clear (); - double x = octave_read_double (tmp_stream); + double x = octave::read_value (tmp_stream); if (tmp_stream) { if (tmp_stream.eof ()) @@ -485,7 +511,7 @@ } else { - double y = octave_read_double (tmp_stream); + double y = octave::read_value (tmp_stream); if (! iscmplx && y != 0.0) { @@ -502,7 +528,7 @@ } else { - // octave_read_double() parsing failed + // octave::read_value() parsing failed j++; // Leave data initialized to empty_value } @@ -713,4 +739,18 @@ %! unlink (file); %! end_unwind_protect +## Verify UTF-8 Byte Order Mark does not cause problems with reading +%!test <*58813> +%! file = tempname (); +%! unwind_protect +%! fid = fopen (file, "wt"); +%! fwrite (fid, char ([0xEF, 0xBB, 0xBF])); # UTF-8 BOM +%! fwrite (fid, "1,2\n3,4"); +%! fclose (fid); +%! +%! assert (dlmread (file), [1, 2; 3, 4]); +%! unwind_protect_cleanup +%! unlink (file); +%! end_unwind_protect + */ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dmperm.cc --- a/libinterp/corefcn/dmperm.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dmperm.cc Thu Nov 19 13:08:00 2020 -0800 @@ -103,10 +103,9 @@ { CXSPARSE_NAME (d) *dm = CXSPARSE_NAME(_dmperm) (&csm, 0); - //retval(5) = put_int (dm->rr, 5); - //retval(4) = put_int (dm->cc, 5); retval = ovl (put_int (dm->p, nr), put_int (dm->q, nc), - put_int (dm->r, dm->nb+1), put_int (dm->s, dm->nb+1)); + put_int (dm->r, dm->nb+1), put_int (dm->s, dm->nb+1), + put_int (dm->cc, 5), put_int (dm->rr, 5)); CXSPARSE_NAME (_dfree) (dm); } @@ -116,23 +115,68 @@ #endif +// NOTE: the docstring for dmperm is adapted from the text found in the +// file cs_dmperm.m that is distributed with the CSparse portion of the +// SuiteSparse library, version 5.6.0. CSparse is distributed under the +// terms of the LGPL v2.1 or any later version. + DEFUN (dmperm, args, nargout, doc: /* -*- texinfo -*- -@deftypefn {} {@var{p} =} dmperm (@var{S}) -@deftypefnx {} {[@var{p}, @var{q}, @var{r}, @var{S}] =} dmperm (@var{S}) +@deftypefn {} {@var{p} =} dmperm (@var{A}) +@deftypefnx {} {[@var{p}, @var{q}, @var{r}, @var{s}, @var{cc}, @var{rr}] =} dmperm (@var{A}) @cindex @nospell{Dulmage-Mendelsohn} decomposition Perform a @nospell{Dulmage-Mendelsohn} permutation of the sparse matrix -@var{S}. +@var{A}. + +With a single output argument @code{dmperm}, return a maximum matching @var{p} +such that @code{p(j) = i} if column @var{j} is matched to row @var{i}, or 0 if +column @var{j} is unmatched. If @var{A} is square and full structural rank, +@var{p} is a row permutation and @code{A(p,:)} has a zero-free diagonal. The +structural rank of @var{A} is @code{sprank(A) = sum(p>0)}. + +Called with two or more output arguments, return the +@nospell{Dulmage-Mendelsohn} decomposition of @var{A}. @var{p} and @var{q} are +permutation vectors. @var{cc} and @var{rr} are vectors of length 5. +@code{c = A(p,q)} is split into a 4-by-4 set of coarse blocks: + +@example +@group + A11 A12 A13 A14 + 0 0 A23 A24 + 0 0 0 A34 + 0 0 0 A44 +@end group +@end example -With a single output argument @code{dmperm} performs the row permutations -@var{p} such that @code{@var{S}(@var{p},:)} has no zero elements on the -diagonal. +@noindent +where @code{A12}, @code{A23}, and @code{A34} are square with zero-free +diagonals. The columns of @code{A11} are the unmatched columns, and the rows +of @code{A44} are the unmatched rows. Any of these blocks can be empty. In +the "coarse" decomposition, the (i,j)-th block is +@code{C(rr(i):rr(i+1)-1,cc(j):cc(j+1)-1)}. In terms of a linear system, +@code{[A11 A12]} is the underdetermined part of the system (it is always +rectangular and with more columns and rows, or 0-by-0), @code{A23} is the +well-determined part of the system (it is always square), and +@code{[A34 ; A44]} is the over-determined part of the system (it is always +rectangular with more rows than columns, or 0-by-0). -Called with two or more output arguments, returns the row and column -permutations, such that @code{@var{S}(@var{p}, @var{q})} is in block -triangular form. The values of @var{r} and @var{S} define the boundaries -of the blocks. If @var{S} is square then @code{@var{r} == @var{S}}. +The structural rank of @var{A} is @code{sprank (A) = rr(4)-1}, which is an +upper bound on the numerical rank of @var{A}. +@code{sprank(A) = rank(full(sprand(A)))} with probability 1 in exact +arithmetic. + +The @code{A23} submatrix is further subdivided into block upper triangular form +via the "fine" decomposition (the strongly-connected components of @code{A23}). +If @var{A} is square and structurally non-singular, @code{A23} is the entire +matrix. + +@code{C(r(i):r(i+1)-1,s(j):s(j+1)-1)} is the (i,j)-th block of the fine +decomposition. The (1,1) block is the rectangular block @code{[A11 A12]}, +unless this block is 0-by-0. The (b,b) block is the rectangular block +@code{[A34 ; A44]}, unless this block is 0-by-0, where @code{b = length(r)-1}. +All other blocks of the form @code{C(r(i):r(i+1)-1,s(i):s(i+1)-1)} are diagonal +blocks of @code{A23}, and are square with a zero-free diagonal. The method used is described in: @nospell{A. Pothen & C.-J. Fan.} @cite{Computing the Block Triangular Form of a Sparse Matrix}. diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dot.cc --- a/libinterp/corefcn/dot.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dot.cc Thu Nov 19 13:08:00 2020 -0800 @@ -190,7 +190,7 @@ // exceed intmax. octave_value_list tmp; tmp(1) = dim + 1; - tmp(0) = do_binary_op (octave_value::op_el_mul, argx, argy); + tmp(0) = octave::binary_op (octave_value::op_el_mul, argx, argy); tmp = Fsum (tmp, 1); if (! tmp.empty ()) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dynamic-ld.cc --- a/libinterp/corefcn/dynamic-ld.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dynamic-ld.cc Thu Nov 19 13:08:00 2020 -0800 @@ -152,11 +152,7 @@ { octave_function *retval = nullptr; - unwind_protect frame; - - frame.protect_var (m_doing_load); - - m_doing_load = true; + unwind_protect_var restore_var (m_doing_load, true); dynamic_library oct_file = m_loaded_shlibs.find_file (file_name); @@ -199,18 +195,42 @@ return retval; } + void * + dynamic_loader::try_load_mex (dynamic_library& mex_file, + const std::string& fcn_name, bool& have_fmex) + { + // FCN_NAME is not used here, the mangler functions always return + // some form of "mexFunction". + + have_fmex = false; + + void *function = mex_file.search (fcn_name, mex_mangler); + + if (! function) + { + // FIXME: Can we determine this C mangling scheme + // automatically at run time or configure time? + + function = mex_file.search (fcn_name, mex_uscore_mangler); + + if (! function) + { + function = mex_file.search (fcn_name, mex_f77_mangler); + + if (function) + have_fmex = true; + } + } + + return function; + } + octave_function * dynamic_loader::load_mex (const std::string& fcn_name, const std::string& file_name, bool /*relative*/) { - octave_function *retval = nullptr; - - unwind_protect frame; - - frame.protect_var (m_doing_load); - - m_doing_load = true; + unwind_protect_var restore_var (m_doing_load, true); dynamic_library mex_file = m_loaded_shlibs.find_file (file_name); @@ -230,29 +250,17 @@ bool have_fmex = false; - void *function = mex_file.search (fcn_name, mex_mangler); - - if (! function) - { - // FIXME: Can we determine this C mangling scheme - // automatically at run time or configure time? - function = mex_file.search (fcn_name, mex_uscore_mangler); - - if (! function) - { - function = mex_file.search (fcn_name, mex_f77_mangler); - - if (function) - have_fmex = true; - } - } + void *function = try_load_mex (mex_file, fcn_name, have_fmex); if (! function) error ("failed to install .mex file function '%s'", fcn_name.c_str ()); - retval = new octave_mex_function (function, have_fmex, mex_file, fcn_name); + void *symbol = mex_file.search ("__mx_has_interleaved_complex__"); - return retval; + bool interleaved = symbol != nullptr; + + return new octave_mex_function (function, interleaved, have_fmex, + mex_file, fcn_name); } bool diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/dynamic-ld.h --- a/libinterp/corefcn/dynamic-ld.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/dynamic-ld.h Thu Nov 19 13:08:00 2020 -0800 @@ -128,6 +128,9 @@ static std::string mex_uscore_mangler (const std::string& name); static std::string mex_f77_mangler (const std::string& name); + + static void * try_load_mex (dynamic_library& mex_file, + const std::string& fcn_name, bool& have_fmex); }; } diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/eig.cc --- a/libinterp/corefcn/eig.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/eig.cc Thu Nov 19 13:08:00 2020 -0800 @@ -532,22 +532,22 @@ ## column vector if 1 output is specified %!function test_shapes (args) %! d = eig (args{:}); -%! assert (isvector(d)) +%! assert (isvector (d)) %! d2 = eig (args{:}, "vector"); -%! assert (isvector(d2)) +%! assert (isvector (d2)) %! [v, d3] = eig (args{:}); -%! assert (isdiag(d3)) +%! assert (isdiag (d3)) %! d4 = eig (args{:}, "matrix"); -%! assert (isdiag(d4)) +%! assert (isdiag (d4)) %! [v, d5, w] = eig (args{:}); -%! assert (isdiag(d5)) +%! assert (isdiag (d5)) %! d6 = eig (args{:}, "matrix"); -%! assert (isdiag(d6)) +%! assert (isdiag (d6)) %! assert (d, d2) %! assert (d3, d4) %! assert (d5, d6) -%! assert (d, diag(d3)) -%! assert (d, diag(d5)) +%! assert (d, diag (d3)) +%! assert (d, diag (d5)) %!endfunction %!function shapes_AEP (A) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/ellipj.cc --- a/libinterp/corefcn/ellipj.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/ellipj.cc Thu Nov 19 13:08:00 2020 -0800 @@ -338,7 +338,7 @@ ## tests taken from inst/test_sncndn.m %!test -%! k = (tan(pi/8.))^2; m = k*k; +%! k = (tan (pi/8))^2; m = k*k; %! SN = [ %! -1. + I * 0. , -0.8392965923 + 0. * I %! -1. + I * 0.2 , -0.8559363407 + 0.108250955 * I @@ -729,13 +729,13 @@ %! assert ([sn,cn,dn], res1, 10*eps); %!test -%! u2 = log(2); m2 = 1; +%! u2 = log (2); m2 = 1; %! res2 = [ 3/5, 4/5, 4/5 ]; %! [sn,cn,dn] = ellipj (u2,m2); %! assert ([sn,cn,dn], res2, 10*eps); %!test -%! u3 = log(2)*1i; m3 = 0; +%! u3 = log (2)*1i; m3 = 0; %! res3 = [3i/4,5/4,1]; %! [sn,cn,dn] = ellipj (u3,m3); %! assert ([sn,cn,dn], res3, 10*eps); @@ -747,7 +747,7 @@ %! assert ([sn,cn,dn], res4, 1e-10); %!test -%! u5 = -0.2 + 0.4i; m5 = tan(pi/8)^4; +%! u5 = -0.2 + 0.4i; m5 = tan (pi/8)^4; %! res5 = [ -0.2152524522 + 0.402598347i, ... %! 1.059453907 + 0.08179712295i, ... %! 1.001705496 + 0.00254669712i ]; @@ -755,7 +755,7 @@ %! assert ([sn,cn,dn], res5, 1e-9); %!test -%! u6 = 0.2 + 0.6i; m6 = tan(pi/8)^4; +%! u6 = 0.2 + 0.6i; m6 = tan (pi/8)^4; %! res6 = [ 0.2369100139 + 0.624633635i, ... %! 1.16200643 - 0.1273503824i, ... %! 1.004913944 - 0.004334880912i ]; diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/environment.cc --- a/libinterp/corefcn/environment.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/environment.cc Thu Nov 19 13:08:00 2020 -0800 @@ -186,7 +186,7 @@ %! EDITOR (orig_val); %! assert (EDITOR (), orig_val); -%!error (EDITOR (1, 2)) +%!error EDITOR (1, 2) */ DEFMETHOD (EXEC_PATH, interp, args, nargout, @@ -223,7 +223,7 @@ %! EXEC_PATH (orig_val); %! assert (EXEC_PATH (), orig_val); -%!error (EXEC_PATH (1, 2)) +%!error EXEC_PATH (1, 2) */ DEFMETHOD (IMAGE_PATH, interp, args, nargout, @@ -255,5 +255,5 @@ %! IMAGE_PATH (orig_val); %! assert (IMAGE_PATH (), orig_val); -%!error (IMAGE_PATH (1, 2)) +%!error IMAGE_PATH (1, 2) */ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/error.cc Thu Nov 19 13:08:00 2020 -0800 @@ -368,7 +368,7 @@ static const octave_fields bt_fields (bt_fieldnames); octave_map - error_system::make_stack_map (const std::list& frames) + error_system::make_stack_map (const std::list& frames) { size_t nframes = frames.size (); @@ -404,10 +404,10 @@ return retval; } - std::list + std::list error_system::make_stack_frame_list (const octave_map& stack) { - std::list frames; + std::list frames; Cell file = stack.contents ("file"); Cell name = stack.contents ("name"); @@ -423,11 +423,11 @@ octave_idx_type nel = name.numel (); for (octave_idx_type i = 0; i < nel; i++) - frames.push_back (octave::frame_info (file(i).string_value (), - name(i).string_value (), - line(i).int_value (), - (have_column - ? column(i).int_value () : -1))); + frames.push_back (frame_info (file(i).string_value (), + name(i).string_value (), + line(i).int_value (), + (have_column + ? column(i).int_value () : -1))); return frames; } @@ -571,10 +571,7 @@ || application::forced_interactive ()) && debug_on_warning () && in_user_code && bptab.debug_on_warn (id)) { - unwind_protect frame; - - frame.protect_var (m_debug_on_warning); - m_debug_on_warning = false; + unwind_protect_var restore_var (m_debug_on_warning, false); tw.enter_debugger (); } @@ -751,9 +748,13 @@ panic_impossible (); if (nel > 1) - os << "\n\n"; + { + os << "\n"; + os << "Non-default warning states are:\n\n"; + os << " State Warning ID\n"; + } - // The state for all is always supposed to be first in the list. + // The state for "all" is always supposed to be first in the list. for (octave_idx_type i = 1; i < nel; i++) { @@ -1377,7 +1378,7 @@ The optional warning identifier @var{id} allows users to enable or disable warnings tagged by this identifier. A message identifier is a string of the form @qcode{"NAMESPACE:WARNING-NAME"}. Octave's own warnings use the -@qcode{"Octave"} namespace (@pxref{XREFwarning_ids,,warning_ids}). For +@qcode{"Octave"} namespace (@pxref{XREFwarning_ids,,@code{warning_ids}}). For example: @example @@ -1506,7 +1507,6 @@ octave_value curr_state = val.contents ("state"); // FIXME: this might be better with a dictionary object. - octave::tree_evaluator& tw = interp.get_evaluator (); octave_value curr_warning_states @@ -1560,39 +1560,28 @@ tw.set_auto_fcn_var (octave::stack_frame::SAVED_WARNING_STATES, m); - // Now ignore the "local" argument and continue to - // handle the current setting. + // Now ignore the "local" argument, + // and continue to handle the current setting. nargin--; } } - if (nargin >= 2 && arg2_lc == "all") + if ((nargin == 1 + && (arg1 == "on" || arg1 == "off" || arg1 == "error")) + || (nargin >= 2 && arg2_lc == "all")) { - // If "all" is explicitly given as ID. + // If "all" is given implicitly or explicitly as ID. + if (arg1 == "error") + error (R"(warning: cannot specify "all" warning ID with state "error")"); octave_map tmp; - int is_error = (arg1 == "error"); - Cell id (1, 1 + 2*is_error); - Cell st (1, 1 + 2*is_error); + Cell id (1, 1); + Cell st (1, 1); id(0) = "all"; st(0) = arg1; - // Since internal Octave functions are not compatible, - // and "all"=="error" causes any "on" to throw an error, - // turning all warnings into errors should disable - // Octave:language-extension. - - if (is_error) - { - id(1) = "Octave:language-extension"; - st(1) = "off"; - - id(2) = "Octave:single-quote-string"; - st(2) = "off"; - } - tmp.assign ("identifier", id); tmp.assign ("state", st); @@ -1648,25 +1637,63 @@ else if (arg1 == "query") { if (arg2_lc == "all") - retval = es.warning_options (); + { + if (nargout > 0) + retval = es.warning_options (); + else + es.display_warning_options (octave_stdout); + } else if (arg2_lc == "backtrace" || arg2_lc == "debug" || arg2_lc == "verbose" || arg2_lc == "quiet") { - octave_scalar_map tmp; - tmp.assign ("identifier", arg2_lc); - if (arg2_lc == "backtrace") - tmp.assign ("state", es.backtrace_on_warning () ? "on" : "off"); - else if (arg2_lc == "debug") - tmp.assign ("state", es.debug_on_warning () ? "on" : "off"); - else if (arg2_lc == "verbose") - tmp.assign ("state", es.verbose_warning () ? "on" : "off"); + if (nargout > 0) + { + octave_scalar_map tmp; + tmp.assign ("identifier", arg2_lc); + if (arg2_lc == "backtrace") + tmp.assign ("state", es.backtrace_on_warning () ? "on" : "off"); + else if (arg2_lc == "debug") + tmp.assign ("state", es.debug_on_warning () ? "on" : "off"); + else if (arg2_lc == "verbose") + tmp.assign ("state", es.verbose_warning () ? "on" : "off"); + else + tmp.assign ("state", es.quiet_warning () ? "on" : "off"); + + retval = tmp; + } else - tmp.assign ("state", es.quiet_warning () ? "on" : "off"); - - retval = tmp; + { + if (arg2_lc == "backtrace") + octave_stdout << R"("backtrace" warning state is ")" << + (es.backtrace_on_warning () ? "on" : "off") << + "\"\n"; + else if (arg2_lc == "debug") + octave_stdout << R"("debug" warning state is ")" << + (es.debug_on_warning () ? "on" : "off") << + "\"\n"; + else if (arg2_lc == "verbose") + octave_stdout << R"("verbose" warning state is ")" << + (es.verbose_warning () ? "on" : "off") << + "\"\n"; + else + octave_stdout << R"("quiet" warning state is ")" << + (es.quiet_warning () ? "on" : "off") << + "\"\n"; + } } else - retval = es.warning_query (arg2); + { + if (nargout > 0) + retval = es.warning_query (arg2); + else + { + octave_scalar_map tmp = es.warning_query (arg2); + + octave_stdout << '"' << arg2 << R"(" warning state is ")" << + tmp.getfield ("state").string_value () << + "\"\n"; + } + } done = true; } @@ -1749,9 +1776,6 @@ } /* -%!test <*45753> -%! warning ("error"); -%! assert (! isempty (help ("warning"))); %!test <*51997> %! id = "Octave:logical-conversion"; @@ -1774,6 +1798,8 @@ %! idx = strcmp ({warnst.identifier}, "Octave:test-57290-ID"); %! assert (warnst(idx).state, "off"); +%!error warning ("error") + */ octave_value_list diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/error.h --- a/libinterp/corefcn/error.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/error.h Thu Nov 19 13:08:00 2020 -0800 @@ -239,9 +239,9 @@ } static octave_map - make_stack_map (const std::list& frames); + make_stack_map (const std::list& frames); - static std::list + static std::list make_stack_frame_list (const octave_map& stack); //! For given warning ID, return 0 if warnings are disabled, 1 if @@ -291,7 +291,7 @@ void initialize_default_warning_state (void); - void interpreter_try (octave::unwind_protect& frame); + void interpreter_try (unwind_protect& frame); // Throw execution_exception or, if debug_on_error is TRUE, enter // debugger. If stack_info is empty, use current call stack. diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/event-manager.cc --- a/libinterp/corefcn/event-manager.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/event-manager.cc Thu Nov 19 13:08:00 2020 -0800 @@ -577,6 +577,51 @@ return ovl (evmgr.unregister_doc (file)); } +DEFMETHOD (__event_manager_gui_status_update__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_gui_status_update__ (@var{feature}, @var{status}) +Internal function for updating the status of some features in the GUI. +@end deftypefn */) +{ + // This is currently a stub and should only be activated some + // interpreter action only implemented in m-files requires to update + // a status indicator in the gui. BUT: This internal function can + // be activated by the user leading to gui indicators not reflecting + // the real state of the related feature. + return ovl (); + + std::string feature; + std::string status; + + if (! (Fisguirunning ())(0).is_true ()) + return ovl (); + + if (args.length () < 2) + error ("__event_manager_gui_status_update__: two parameters required"); + if (! (args(0).is_string ())) + error ("__event_manager_gui_status_update__: FEATURE must be a string"); + if (! (args(1).is_string ())) + error ("__event_manager_gui_status_update__: STATUS must be a string"); + + feature = args(0).string_value (); + status = args(1).string_value (); + + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.gui_status_update (feature, status)); +} + +DEFMETHOD (__event_manager_update_gui_lexer__, interp, , , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_update_gui_lexer__ () +Undocumented internal function. +@end deftypefn */) +{ + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.update_gui_lexer ()); +} + DEFMETHOD (__event_manager_copy_image_to_clipboard__, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {} __event_manager_copy_image_to_clipboard__ (@var{filename}) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/event-manager.h --- a/libinterp/corefcn/event-manager.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/event-manager.h Thu Nov 19 13:08:00 2020 -0800 @@ -44,7 +44,7 @@ namespace octave { typedef std::function fcn_callback; - typedef std::function meth_callback; + typedef std::function meth_callback; class symbol_info_list; @@ -195,6 +195,11 @@ virtual void unregister_doc (const std::string& /*file*/) { } + virtual void gui_status_update (const std::string& /*feature*/, + const std::string& /*status*/) { } + + virtual void update_gui_lexer (void) { } + // Notifications of events in the interpreter that a GUI will // normally wish to respond to. @@ -208,7 +213,7 @@ virtual void set_workspace (bool /*top_level*/, bool /*debug*/, - const octave::symbol_info_list& /*syminfo*/, + const symbol_info_list& /*syminfo*/, bool /*update_variable_editor*/) { } @@ -369,7 +374,7 @@ void update_path_dialog (void) { - if (octave::application::is_gui_running () && enabled ()) + if (application::is_gui_running () && enabled ()) instance->update_path_dialog (); } @@ -495,7 +500,28 @@ } else return false; + } + bool gui_status_update (const std::string& feature, const std::string& status) + { + if (enabled ()) + { + instance->gui_status_update (feature, status); + return true; + } + else + return false; + } + + bool update_gui_lexer (void) + { + if (enabled ()) + { + instance->update_gui_lexer (); + return true; + } + else + return false; } void directory_changed (const std::string& dir) @@ -507,19 +533,19 @@ // Methods for removing/renaming files which might be open in editor void file_remove (const std::string& old_name, const std::string& new_name) { - if (octave::application::is_gui_running () && enabled ()) + if (application::is_gui_running () && enabled ()) instance->file_remove (old_name, new_name); } void file_renamed (bool load_new) { - if (octave::application::is_gui_running () && enabled ()) + if (application::is_gui_running () && enabled ()) instance->file_renamed (load_new); } void set_workspace (void); - void set_workspace (bool top_level, const octave::symbol_info_list& syminfo, + void set_workspace (bool top_level, const symbol_info_list& syminfo, bool update_variable_editor = true) { if (enabled ()) @@ -609,10 +635,10 @@ protected: // Semaphore to lock access to the event queue. - octave::mutex *event_queue_mutex; + mutex *event_queue_mutex; // Event Queue. - octave::event_queue gui_event_queue; + event_queue gui_event_queue; bool debugging; bool link_enabled; diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/fcn-info.cc --- a/libinterp/corefcn/fcn-info.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/fcn-info.cc Thu Nov 19 13:08:00 2020 -0800 @@ -86,7 +86,7 @@ tmpfcn->mark_as_private_function (class_name); - private_functions[octave::sys::canonicalize_file_name (dir_name)] = ov_fcn; + private_functions[sys::canonicalize_file_name (dir_name)] = ov_fcn; return ov_fcn; } @@ -409,21 +409,59 @@ // would not check for it when finding symbol definitions. static inline bool - load_out_of_date_fcn (const std::string& ff, const std::string& dir_name, + load_out_of_date_fcn (const std::string& file_name, + const std::string& dir_name_arg, octave_value& function, const std::string& dispatch_type = "", const std::string& package_name = "") { bool retval = false; + std::string dir_name = dir_name_arg; + + if (dir_name.empty ()) + { + size_t pos = file_name.find_last_of (sys::file_ops::dir_sep_chars ()); + + dir_name = file_name.substr (0, pos); + } + + // FIXME: do the following job of determining private status and + // class membership in a separate function? + + size_t pos = dir_name.find_last_of (sys::file_ops::dir_sep_chars ()); + + bool is_private_fcn + = pos != std::string::npos && dir_name.substr (pos+1) == "private"; + + if (is_private_fcn) + dir_name = dir_name.substr (0, pos); + + std::string class_name; + + pos = dir_name.find_last_of (sys::file_ops::dir_sep_chars ()); + + if (pos != std::string::npos) + { + std::string tmp = dir_name.substr (pos+1); + + if (tmp[0] == '@') + class_name = tmp.substr (1); + } + octave_value ov_fcn - = load_fcn_from_file (ff, dir_name, dispatch_type, + = load_fcn_from_file (file_name, dir_name, dispatch_type, package_name); if (ov_fcn.is_defined ()) { retval = true; + octave_function *fcn = ov_fcn.function_value (); + + if (is_private_fcn) + fcn->mark_as_private_function (class_name); + function = ov_fcn; } else @@ -1185,7 +1223,7 @@ %! ignore_function_time_stamp (old_state); ## Test input validation -%!error (ignore_function_time_stamp ("all", "all")) -%!error (ignore_function_time_stamp ("UNKNOWN_VALUE")) -%!error (ignore_function_time_stamp (42)) +%!error ignore_function_time_stamp ("all", "all") +%!error ignore_function_time_stamp ("UNKNOWN_VALUE") +%!error ignore_function_time_stamp (42) */ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/fft.cc --- a/libinterp/corefcn/fft.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/fft.cc Thu Nov 19 13:08:00 2020 -0800 @@ -113,7 +113,7 @@ idx(i) = idx_vector::colon; idx(dim) = idx_vector (static_cast (0)); - return arg.do_index_op (idx); + return arg.index_op (idx); } if (arg.is_single_type ()) @@ -187,7 +187,7 @@ %!testif HAVE_FFTW %! assert (fft (eye (2,2,"single")), single ([1,1; 1,-1])) -%!error (fft ()) +%!error fft () */ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/file-io.cc Thu Nov 19 13:08:00 2020 -0800 @@ -273,7 +273,8 @@ If there are no more characters to read, @code{fgetl} returns @minus{}1. -To read a line and return the terminating newline see @code{fgets}. +To read a line and return the terminating newline, +@pxref{XREFfgets,,@code{fgets}}. @seealso{fgets, fscanf, fread, fopen} @end deftypefn */) { @@ -315,7 +316,8 @@ If there are no more characters to read, @code{fgets} returns @minus{}1. -To read a line and discard the terminating newline see @code{fgetl}. +To read a line and discard the terminating newline, +@pxref{XREFfgetl,,@code{fgetl}}. @seealso{fputs, fgetl, fscanf, fread, fopen} @end deftypefn */) { @@ -1641,8 +1643,10 @@ %! c = textscan (str, "%4f %f", "delimiter", ";", "collectOutput", 1); %! assert (c, {[12, 34; 1234, 56789; 7, NaN]}); +## FIXME: Not Matlab compatible. Matlab prioritizes precision over field width +## so "12.234e+2", when read with "%10.2f %f", yields "12.23" and "4e+2". ## Ignore trailing delimiter, but use leading one -%!test +%!#test %! str = "12.234e+2,34, \n12345.789-9876j,78\n,10|3"; %! c = textscan (str, "%10.2f %f", "delimiter", ",", "collectOutput", 1, %! "expChars", "e|"); @@ -2285,7 +2289,46 @@ %! obs = textscan (str, "%q", "delimiter", ","); %! assert (obs, { { "a,b"; "c" } }); +%!test <*58008> +%! txt = sprintf ('literal_other_1_1;literal_other_1_2\nliteral_other_2_1;literal_other_2_2\nliteral_other_3_1;literal_other_3_2'); +%! nm1 = textscan (txt, 'literal%s literal%s', 'Delimiter', ';'); +%! assert (nm1{1}, {"_other_1_1" ; "_other_2_1" ; "_other_3_1"}); +%! assert (nm1{2}, {"_other_1_2" ; "_other_2_2" ; "_other_3_2"}); +%! nm2 = textscan (txt, 'literal%s;literal%s', 'Delimiter', ';'); +%! assert (nm1, nm2); + +%!test <*57612> +%! str = sprintf (['101,' '\n' '201,']); +%! C = textscan (str, '%s%q', 'Delimiter', ','); +%! assert (size (C), [1, 2]); +%! assert (C{1}, { "101"; "201" }); +%! assert (C{2}, { ""; "" }); + +%!test <*57612> +%! str = sprintf (['101,' '\n' '201,']); +%! C = textscan (str, '%s%f', 'Delimiter', ','); +%! assert (size (C), [1, 2]); +%! assert (C{1}, { "101"; "201" }); +%! assert (C{2}, [ NaN; NaN ]); + +%!test <*57612> +%! str = sprintf (['101,' '\n' '201,']); +%! C = textscan (str, '%s%d', 'Delimiter', ','); +%! assert (size (C), [1, 2]); +%! assert (C{1}, { "101"; "201" }); +%! assert (C{2}, int32 ([ 0; 0 ])); + +%!test <*51093> +%! str = sprintf ('a\t\tb\tc'); +%! C = textscan (str, '%s', 'Delimiter', '\t', 'MultipleDelimsAsOne', false); +%! assert (C{1}, {'a'; ''; 'b'; 'c'}); + +%!xtest <50743> +%! C = textscan ('5973459727478852968', '%u64'); +%! assert (C{1}, uint64 (5973459727478852968)); + */ + // These tests have end-comment sequences, so can't just be in a comment #if 0 ## Test unfinished comment @@ -2824,7 +2867,7 @@ Programming Note: Because the named file is not opened by @code{tempname}, it is possible, though relatively unlikely, that it will not be available by the time your program attempts to open it. If this is a concern, -see @code{tmpfile}. +@pxref{XREFtmpfile,,@code{tmpfile}}. @seealso{mkstemp, tempdir, P_tmpdir, tmpfile} @end deftypefn */) { @@ -2890,7 +2933,7 @@ %! assert (tmpdir, tmp_tmpdir); %! assert (tmpfname (1:4), "file"); %! unwind_protect_cleanup -%! rmdir (tmp_tmpdir); +%! sts = rmdir (tmp_tmpdir); %! for i = 1:numel (envvar) %! if (isempty (envdir{i})) %! unsetenv (envvar{i}); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/filter.cc --- a/libinterp/corefcn/filter.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/filter.cc Thu Nov 19 13:08:00 2020 -0800 @@ -605,7 +605,7 @@ %!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]), [2 2]) %!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]'), [2 2]) %!assert (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]), [5 7; 6 10; 14 18]) -%!error (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]')) +%!error filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]') %!assert (filter ([1, 3, 2], [1], [1 2; 3 4; 5 6], [1 0 0; 1 0 0], 2), [2 6; 3 13; 5 21]) ## Test of DIM parameter diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/find.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/ft-text-renderer.cc --- a/libinterp/corefcn/ft-text-renderer.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/ft-text-renderer.cc Thu Nov 19 13:08:00 2020 -0800 @@ -980,9 +980,10 @@ m_strlist = std::list (); - unwind_protect frame; - frame.protect_var (m_do_strlist); - frame.protect_var (m_strlist); + unwind_protect_var restore_var1 (m_do_strlist); + unwind_protect_var> + restore_var2 (m_strlist); + m_do_strlist = true; text_to_pixels (txt, pxls, box, ha, va, rot, interp, false); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/gcd.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/givens.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/gl-render.cc --- a/libinterp/corefcn/gl-render.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/gl-render.cc Thu Nov 19 13:08:00 2020 -0800 @@ -27,6 +27,7 @@ # include "config.h" #endif +#include #include #if defined (HAVE_WINDOWS_H) @@ -734,6 +735,8 @@ draw_surface (dynamic_cast (props)); else if (go.isa ("patch")) draw_patch (dynamic_cast (props)); + else if (go.isa ("scatter")) + draw_scatter (dynamic_cast (props)); else if (go.isa ("light")) draw_light (dynamic_cast (props)); else if (go.isa ("hggroup")) @@ -1277,8 +1280,21 @@ Matrix x_zlim = props.get_transform_zlim (); - xZ1 = std::max (-1e6, x_zlim(0)-(x_zlim(1)-x_zlim(0))*100.0); - xZ2 = std::min (1e6, x_zlim(1)+(x_zlim(1)-x_zlim(0))*100.0); + // Expand the distance between the clipping planes symmetrically by + // an arbitrary factor (see bug #54551). + const double expansion_fac = 100.0; + // Also make sure that the distance between the clipping planes + // differs in single precision (see bug #58956). This factor is also + // arbitrary. Different values (>2) might also work. + const double single_prec_fac = 10.0; + + double avgZ = x_zlim(0) / 2.0 + x_zlim(1) / 2.0; + double span + = std::max (expansion_fac * (x_zlim(1)-x_zlim(0)), + single_prec_fac * std::abs (avgZ) + * std::numeric_limits::epsilon ()); + xZ1 = avgZ - span; + xZ2 = avgZ + span; Matrix x_mat1 = props.get_opengl_matrix_1 (); Matrix x_mat2 = props.get_opengl_matrix_2 (); @@ -3695,6 +3711,116 @@ } void + opengl_renderer::draw_scatter (const scatter::properties& props) + { +#if defined (HAVE_OPENGL) + + // Do not render if the scatter object has incoherent data + std::string msg; + if (props.has_bad_data (msg)) + { + warning ("opengl_renderer: %s. Not rendering.", msg.c_str ()); + return; + } + + bool draw_all = selecting; + + if (draw_all || (! props.marker_is ("none") + && ! (props.markeredgecolor_is ("none") + && props.markerfacecolor_is ("none")))) + { + bool do_edge = draw_all || ! props.markeredgecolor_is ("none"); + bool do_face = draw_all || ! props.markerfacecolor_is ("none"); + + const Matrix x = props.get_xdata ().matrix_value (); + const Matrix y = props.get_ydata ().matrix_value (); + const Matrix z = props.get_zdata ().matrix_value (); + const Matrix c = props.get_color_data ().matrix_value (); + const Matrix s = props.get_sizedata ().matrix_value (); + + int np = x.rows (); + bool has_z = ! z.isempty (); + + // If markeredgecolor is "flat", mecolor is empty + Matrix mecolor = (draw_all ? Matrix (1, 3, 0.0) : + props.get_markeredgecolor_rgb ()); + Matrix mfcolor = (draw_all ? Matrix (1, 3, 0.0) : + props.get_markerfacecolor_rgb ()); + const double mea = props.get_markeredgealpha (); + const double mfa = props.get_markerfacealpha (); + + if (props.markerfacecolor_is ("auto")) + { + gh_manager& gh_mgr + = __get_gh_manager__ ("opengl_renderer::draw_scatter"); + graphics_object go = gh_mgr.get_object (props.get___myhandle__ ()); + graphics_object ax = go.get_ancestor ("axes"); + const axes::properties& ax_props + = dynamic_cast (ax.get_properties ()); + + mfcolor = ax_props.get_color ().matrix_value (); + } + + init_marker (props.get_marker (), std::sqrt (s(0)), + props.get_linewidth ()); + + uint8_t clip_mask = (props.is_clipping () ? 0x7F : 0x40); + uint8_t clip_ok = 0x40; + + Matrix cc; + if (! c.isempty ()) + { + if (c.rows () == 1) + cc = c; + else + { + cc.resize (1, 3); + cc(0) = c(0,0); + cc(1) = c(0,1); + cc(2) = c(0,2); + } + } + + for (int i = 0; i < np; i++) + { + if ((clip_code (x(i), y(i), (has_z ? z(i) : 0.0)) & clip_mask) + != clip_ok) + continue; + + if (c.rows () > 1) + { + cc(0) = c(i,0); + cc(1) = c(i,1); + cc(2) = c(i,2); + } + + Matrix lc = (do_edge ? (mecolor.isempty () ? cc : mecolor) + : Matrix ()); + Matrix fc = (do_face ? (mfcolor.isempty () ? cc : mfcolor) + : Matrix ()); + + if (s.numel () > 1) + change_marker (props.get_marker (), std::sqrt (s(i))); + + draw_marker (x(i), y(i), (has_z ? z(i) : 0.0), lc, fc, mea, mfa); + } + + end_marker (); + } + +#else + + octave_unused_parameter (props); + + // This shouldn't happen because construction of opengl_renderer + // objects is supposed to be impossible if OpenGL is not available. + + panic_impossible (); + +#endif + } + + void opengl_renderer::draw_light (const light::properties& props) { #if defined (HAVE_OPENGL) @@ -4275,6 +4401,27 @@ } void + opengl_renderer::change_marker (const std::string& m, double size) + { +#if defined (HAVE_OPENGL) + + marker_id = make_marker_list (m, size, false); + filled_marker_id = make_marker_list (m, size, true); + +#else + + octave_unused_parameter (m); + octave_unused_parameter (size); + + // This shouldn't happen because construction of opengl_renderer + // objects is supposed to be impossible if OpenGL is not available. + + panic_impossible (); + +#endif + } + + void opengl_renderer::end_marker (void) { #if defined (HAVE_OPENGL) @@ -4300,7 +4447,8 @@ void opengl_renderer::draw_marker (double x, double y, double z, - const Matrix& lc, const Matrix& fc) + const Matrix& lc, const Matrix& fc, + const double la, const double fa) { #if defined (HAVE_OPENGL) @@ -4311,12 +4459,12 @@ if (filled_marker_id > 0 && fc.numel () > 0) { - m_glfcns.glColor3dv (fc.data ()); + m_glfcns.glColor4d (fc(0), fc(1), fc(2), fa); set_polygon_offset (true, -1.0); m_glfcns.glCallList (filled_marker_id); if (lc.numel () > 0) { - m_glfcns.glColor3dv (lc.data ()); + m_glfcns.glColor4d (lc(0), lc(1), lc(2), la); m_glfcns.glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); m_glfcns.glEdgeFlag (GL_TRUE); set_polygon_offset (true, -2.0); @@ -4327,7 +4475,7 @@ } else if (marker_id > 0 && lc.numel () > 0) { - m_glfcns.glColor3dv (lc.data ()); + m_glfcns.glColor4d (lc(0), lc(1), lc(2), la); m_glfcns.glCallList (marker_id); } @@ -4338,6 +4486,8 @@ octave_unused_parameter (z); octave_unused_parameter (lc); octave_unused_parameter (fc); + octave_unused_parameter (la); + octave_unused_parameter (fa); // This shouldn't happen because construction of opengl_renderer // objects is supposed to be impossible if OpenGL is not available. diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/gl-render.h --- a/libinterp/corefcn/gl-render.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/gl-render.h Thu Nov 19 13:08:00 2020 -0800 @@ -81,6 +81,7 @@ virtual void draw_line (const line::properties& props); virtual void draw_surface (const surface::properties& props); virtual void draw_patch (const patch::properties& props); + virtual void draw_scatter (const scatter::properties& props); virtual void draw_light (const light::properties& props); virtual void draw_hggroup (const hggroup::properties& props); virtual void draw_text (const text::properties& props); @@ -115,9 +116,11 @@ } virtual void init_marker (const std::string& m, double size, float width); + virtual void change_marker (const std::string& m, double size); virtual void end_marker (void); virtual void draw_marker (double x, double y, double z, - const Matrix& lc, const Matrix& fc); + const Matrix& lc, const Matrix& fc, + const double la = 1.0, const double fa = 1.0); virtual void text_to_pixels (const std::string& txt, uint8NDArray& pixels, diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/gl2ps-print.cc --- a/libinterp/corefcn/gl2ps-print.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/gl2ps-print.cc Thu Nov 19 13:08:00 2020 -0800 @@ -39,6 +39,7 @@ #include +#include "file-ops.h" #include "lo-mappers.h" #include "oct-locbuf.h" #include "tmpfile-wrapper.h" @@ -55,20 +56,6 @@ namespace octave { - static void - safe_pclose (FILE *f) - { - if (f) - octave::pclose (f); - } - - static void - safe_fclose (FILE *f) - { - if (f) - std::fclose (f); - } - class OCTINTERP_API gl2ps_renderer : public opengl_renderer @@ -128,6 +115,13 @@ && fa.double_value () < 1) retval = true; } + else if (go.isa ("scatter")) + { + octave_value fa = go.get ("markerfacealpha"); + if (fa.is_scalar_type () && fa.is_double_type () + && fa.double_value () < 1) + retval = true; + } return retval; } @@ -373,7 +367,7 @@ if (! tmpf) error ("gl2ps_renderer::draw: couldn't open temporary file for printing"); - frame.add_fcn (safe_fclose, tmpf); + frame.add ([=] () { std::fclose (tmpf); }); // Reset buffsize, unless this is 2nd pass of a texstandalone print. if (term.find ("tex") == std::string::npos) @@ -406,13 +400,17 @@ else include_graph = old_print_cmd; - size_t n_begin = include_graph.find_first_not_of (" \"'"); + size_t n_begin = include_graph.find_first_not_of (R"( "')"); if (n_begin != std::string::npos) { - size_t n_end = include_graph.find_last_not_of (" \"'"); + // Strip any quote characters characters around filename + size_t n_end = include_graph.find_last_not_of (R"( "')"); include_graph = include_graph.substr (n_begin, n_end - n_begin + 1); + // Strip path from filename + n_begin = include_graph.find_last_of (sys::file_ops::dir_sep_chars ()); + include_graph = include_graph.substr (n_begin + 1); } else include_graph = "foobar-inc"; @@ -807,7 +805,7 @@ ColumnVector coord_pix = get_transform ().transform (x, y, z, false); std::ostringstream os; - os << "get_family ())) - os << "font-family=\"" << p->get_family () << "\" "; + os << "font-family=\"" << p->get_family () << "\" "; if (weight.compare (p->get_weight ())) os << "font-weight=\"" << p->get_weight () << "\" "; @@ -853,12 +851,12 @@ // provide an x coordinate for each character in the string os << "x=\""; - std::vector xdata = p->get_xdata (); + std::vector xdata = p->get_xdata (); for (auto q = xdata.begin (); q != xdata.end (); q++) os << (*q) << " "; - os << "\""; + os << '"'; - os << ">"; + os << '>'; // translate unicode and special xml characters if (p->get_code ()) @@ -1433,7 +1431,8 @@ if (! fp) error (R"(print: failed to open pipe "%s")", stream.c_str ()); - frame.add_fcn (safe_pclose, fp); + // Need octave:: qualifier here to avoid ambiguity. + frame.add ([=] () { octave::pclose (fp); }); } else { @@ -1444,7 +1443,7 @@ if (! fp) error (R"(gl2ps_print: failed to create file "%s")", stream.c_str ()); - frame.add_fcn (safe_fclose, fp); + frame.add ([=] () { std::fclose (fp); }); } gl2ps_renderer rend (glfcns, fp, term); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/graphics-toolkit.cc --- a/libinterp/corefcn/graphics-toolkit.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/graphics-toolkit.cc Thu Nov 19 13:08:00 2020 -0800 @@ -36,8 +36,7 @@ void base_graphics_toolkit::update (const graphics_handle& h, int id) { - gh_manager& gh_mgr - = octave::__get_gh_manager__ ("base_graphics_toolkit::update"); + gh_manager& gh_mgr = __get_gh_manager__ ("base_graphics_toolkit::update"); graphics_object go = gh_mgr.get_object (h); @@ -48,7 +47,7 @@ base_graphics_toolkit::initialize (const graphics_handle& h) { gh_manager& gh_mgr - = octave::__get_gh_manager__ ("base_graphics_toolkit::initialize"); + = __get_gh_manager__ ("base_graphics_toolkit::initialize"); graphics_object go = gh_mgr.get_object (h); @@ -59,7 +58,7 @@ base_graphics_toolkit::finalize (const graphics_handle& h) { gh_manager& gh_mgr - = octave::__get_gh_manager__ ("base_graphics_toolkit::finalize"); + = __get_gh_manager__ ("base_graphics_toolkit::finalize"); graphics_object go = gh_mgr.get_object (h); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/graphics.cc Thu Nov 19 13:08:00 2020 -0800 @@ -1157,8 +1157,9 @@ { pfx = name.substr (0, 7); - if (pfx.compare ("surface") || pfx.compare ("hggroup") - || pfx.compare ("uipanel") || pfx.compare ("uitable")) + if (pfx.compare ("surface") || pfx.compare ("scatter") + || pfx.compare ("hggroup") || pfx.compare ("uipanel") + || pfx.compare ("uitable")) offset = 7; else if (len >= 9) { @@ -1226,6 +1227,8 @@ go = new light (h, p); else if (type.compare ("patch")) go = new patch (h, p); + else if (type.compare ("scatter")) + go = new scatter (h, p); else if (type.compare ("surface")) go = new surface (h, p); else if (type.compare ("hggroup")) @@ -1784,18 +1787,18 @@ } /* -## Test validation of uicontextmenu property +## Test validation of contextmenu property %!test %! hf = figure ("visible", "off"); %! unwind_protect %! hax = axes ("parent", hf); %! hpa = patch ("parent", hax); %! try -%! set (hax, "uicontextmenu", hpa); +%! set (hax, "contextmenu", hpa); %! catch %! err = lasterr (); %! end_try_catch -%! assert (err, 'set: invalid graphics object type for property "uicontextmenu"'); +%! assert (err, 'set: invalid graphics object type for property "contextmenu"'); %! unwind_protect_cleanup %! delete (hf); %! end_unwind_protect @@ -1940,12 +1943,11 @@ void callback_property::execute (const octave_value& data) const { - octave::unwind_protect frame; - // We are executing a callback function, so allow handles that have // their handlevisibility property set to "callback" to be visible. - frame.add_method (executing_callbacks, &callback_props::erase, this); + octave::unwind_action executing_callbacks_cleanup + ([=] () { executing_callbacks.erase (this); }); if (! executing_callbacks.contains (this)) { @@ -2297,8 +2299,9 @@ { pfx = name.substr (0, 7); - if (pfx.compare ("surface") || pfx.compare ("hggroup") - || pfx.compare ("uipanel") || pfx.compare ("uitable")) + if (pfx.compare ("surface") || pfx.compare ("scatter") + || pfx.compare ("hggroup")|| pfx.compare ("uipanel") + || pfx.compare ("uitable")) offset = 7; else if (len > 9) { @@ -2357,6 +2360,8 @@ has_property = image::properties::has_core_property (pname); else if (pfx == "patch") has_property = patch::properties::has_core_property (pname); + else if (pfx == "scatter") + has_property = scatter::properties::has_core_property (pname); else if (pfx == "surface") has_property = surface::properties::has_core_property (pname); else if (pfx == "hggroup") @@ -2439,8 +2444,9 @@ { pfx = name.substr (0, 7); - if (pfx.compare ("surface") || pfx.compare ("hggroup") - || pfx.compare ("uipanel") || pfx.compare ("uitable")) + if (pfx.compare ("surface") || pfx.compare ("scatter") + || pfx.compare ("hggroup") || pfx.compare ("uipanel") + || pfx.compare ("uitable")) offset = 7; else if (len > 9) { @@ -2729,7 +2735,7 @@ graphics_object::set_value_or_default (const caseless_str& pname, const octave_value& val) { - if (val.is_string ()) + if (val.is_string () && val.rows () == 1) { std::string sval = val.string_value (); @@ -3055,9 +3061,7 @@ delete_graphics_objects (const NDArray vals, bool from_root = false) { // Prevent redraw of partially deleted objects. - octave::unwind_protect frame; - frame.protect_var (delete_executing); - delete_executing = true; + octave::unwind_protect_var restore_var (delete_executing, true); for (octave_idx_type i = 0; i < vals.numel (); i++) delete_graphics_object (vals.elem (i), from_root); @@ -3122,7 +3126,7 @@ hlist = figure_handle_list (true); if (hlist.numel () != 0) - warning ("gh_manager::close_all_figures: some graphics elements failed to close."); + warning ("gh_manager::close_all_figures: some graphics elements failed to close"); // Clear all callback objects from our list. @@ -3296,7 +3300,7 @@ /* ## test defaults are set in the order they were stored %!test -%! set(0, "defaultfigureunits", "normalized"); +%! set (0, "defaultfigureunits", "normalized"); %! set(0, "defaultfigureposition", [0.7 0 0.3 0.3]); %! hf = figure ("visible", "off"); %! tol = 20 * eps; @@ -3304,8 +3308,8 @@ %! assert (get (hf, "position"), [0.7 0 0.3 0.3], tol); %! unwind_protect_cleanup %! close (hf); -%! set(0, "defaultfigureunits", "remove"); -%! set(0, "defaultfigureposition", "remove"); +%! set (0, "defaultfigureunits", "remove"); +%! set (0, "defaultfigureposition", "remove"); %! end_unwind_protect */ @@ -3483,15 +3487,15 @@ } void -base_properties::update_uicontextmenu (void) const -{ - if (uicontextmenu.get ().isempty ()) +base_properties::update_contextmenu (void) const +{ + if (contextmenu.get ().isempty ()) return; gh_manager& gh_mgr - = octave::__get_gh_manager__ ("base_properties::update_uicontextmenu"); - - graphics_object go = gh_mgr.get_object (uicontextmenu.get ()); + = octave::__get_gh_manager__ ("base_properties::update_contextmenu"); + + graphics_object go = gh_mgr.get_object (contextmenu.get ()); if (go && go.isa ("uicontextmenu")) { @@ -3605,7 +3609,7 @@ %! hf = figure ("handlevisibility", "off", "visible", "off"); %! hax = axes ("parent", hf, "handlevisibility", "off"); %! unwind_protect -%! fcn = @(h) setappdata (h, "testdata", gcbo ()); +%! fcn = @(h, ~) setappdata (h, "testdata", gcbo ()); %! addlistener (hf, "color", fcn); %! addlistener (hax, "color", fcn); %! set (hf, "color", "b"); @@ -4185,7 +4189,7 @@ figure::properties::set___graphics_toolkit__ (const octave_value& val) { if (! val.is_string ()) - error ("set___graphics_toolkit__ must be a string"); + error ("set___graphics_toolkit__: toolkit must be a string"); std::string nm = val.string_value (); @@ -5267,7 +5271,7 @@ axes::properties::sync_positions (void) { // First part is equivalent to 'update_tightinset ()' - if (activepositionproperty.is ("position")) + if (positionconstraint.is ("innerposition")) update_position (); else update_outerposition (); @@ -5284,7 +5288,7 @@ tightinset = tinset; set_units (old_units); update_transform (); - if (activepositionproperty.is ("position")) + if (positionconstraint.is ("innerposition")) update_position (); else update_outerposition (); @@ -5295,13 +5299,13 @@ %! hf = figure ("visible", "off"); %! graphics_toolkit (hf, "qt"); %! unwind_protect -%! subplot(2,1,1); plot(rand(10,1)); subplot(2,1,2); plot(rand(10,1)); +%! subplot (2,1,1); plot (rand (10,1)); subplot (2,1,2); plot (rand (10,1)); %! hax = findall (gcf (), "type", "axes"); %! positions = cell2mat (get (hax, "position")); %! outerpositions = cell2mat (get (hax, "outerposition")); %! looseinsets = cell2mat (get (hax, "looseinset")); %! tightinsets = cell2mat (get (hax, "tightinset")); -%! subplot(2,1,1); plot(rand(10,1)); subplot(2,1,2); plot(rand(10,1)); +%! subplot (2,1,1); plot (rand (10,1)); subplot (2,1,2); plot (rand (10,1)); %! hax = findall (gcf (), "type", "axes"); %! assert (cell2mat (get (hax, "position")), positions, 1e-4); %! assert (cell2mat (get (hax, "outerposition")), outerpositions, 1e-4); @@ -5335,7 +5339,7 @@ %! hf = figure ("visible", "off"); %! graphics_toolkit (hf, "qt"); %! fpos = get (hf, "position"); -%! set (gca, "activepositionproperty", "position"); +%! set (gca, "positionconstraint", "innerposition"); %! unwind_protect %! plot (rand (3)); %! position = get (gca, "position"); @@ -6269,9 +6273,7 @@ zPlaneN = (zPlane == z_min ? z_max : z_min); fz = (z_max - z_min) / sqrt (dir(0)*dir(0) + dir(1)*dir(1)); - octave::unwind_protect frame; - frame.protect_var (updating_axes_layout); - updating_axes_layout = true; + octave::unwind_protect_var restore_var (updating_axes_layout, true); xySym = (xd*yd*(xPlane-xPlaneN)*(yPlane-yPlaneN) > 0); zSign = (zd*(zPlane-zPlaneN) <= 0); @@ -6431,9 +6433,8 @@ bool isempty = xlabel_props.get_string ().isempty (); - octave::unwind_protect frame; - frame.protect_var (updating_xlabel_position); - updating_xlabel_position = true; + octave::unwind_protect_var + restore_var (updating_xlabel_position, true); if (! isempty) { @@ -6536,9 +6537,8 @@ bool isempty = ylabel_props.get_string ().isempty (); - octave::unwind_protect frame; - frame.protect_var (updating_ylabel_position); - updating_ylabel_position = true; + octave::unwind_protect_var + restore_var (updating_ylabel_position, true); if (! isempty) { @@ -6642,9 +6642,8 @@ bool camAuto = cameraupvectormode_is ("auto"); bool isempty = zlabel_props.get_string ().isempty (); - octave::unwind_protect frame; - frame.protect_var (updating_zlabel_position); - updating_zlabel_position = true; + octave::unwind_protect_var + restore_updating_zlabel_position (updating_zlabel_position, true); if (! isempty) { @@ -6767,9 +6766,7 @@ text::properties& title_props = reinterpret_cast (go.get_properties ()); - octave::unwind_protect frame; - frame.protect_var (updating_title_position); - updating_title_position = true; + octave::unwind_protect_var restore_var (updating_title_position, true); if (title_props.positionmode_is ("auto")) { @@ -6920,8 +6917,8 @@ if (modified_limits) { - octave::unwind_protect frame; - frame.protect_var (updating_aspectratios); + octave::unwind_protect_var> + restore_var (updating_aspectratios); updating_aspectratios.insert (get___myhandle__ ().value ()); @@ -7503,7 +7500,7 @@ void axes::properties::update_outerposition (void) { - set_activepositionproperty ("outerposition"); + set_positionconstraint ("outerposition"); caseless_str old_units = get_units (); set_units ("normalized"); @@ -7562,7 +7559,7 @@ void axes::properties::update_position (void) { - set_activepositionproperty ("position"); + set_positionconstraint ("innerposition"); caseless_str old_units = get_units (); set_units ("normalized"); @@ -7621,7 +7618,7 @@ double right_margin = std::max (linset(2), tinset(2)); double top_margin = std::max (linset(3), tinset(3)); - if (activepositionproperty.is ("position")) + if (positionconstraint.is ("innerposition")) { Matrix innerbox = position.get ().matrix_value (); @@ -8595,8 +8592,8 @@ #undef FIX_LIMITS - octave::unwind_protect frame; - frame.protect_var (updating_axis_limits); + octave::unwind_protect_var> + restore_var (updating_axis_limits); updating_axis_limits.insert (get_handle ().value ()); bool is_auto; @@ -8721,6 +8718,11 @@ xproperties.set_has3Dkids ((max_val - min_val) > std::numeric_limits::epsilon ()); + // FIXME: How to correctly handle (positive or negative) log scale? + if ((! octave::math::isfinite (min_val) + || ! octave::math::isfinite (max_val)) + && ! xproperties.zscale_is ("log")) + min_val = max_val = 0.; limits = xproperties.get_axis_limits (min_val, max_val, min_pos, max_neg, @@ -8795,8 +8797,8 @@ } - octave::unwind_protect frame; - frame.protect_var (updating_axis_limits); + octave::unwind_protect_var> + restore_var (updating_axis_limits); updating_axis_limits.insert (get_handle ().value ()); bool is_auto; @@ -9700,9 +9702,7 @@ // FIXME: shouldn't we update facevertexalphadata here ? - octave::unwind_protect frame; - frame.protect_var (updating_patch_data); - updating_patch_data = true; + octave::unwind_protect_var restore_var (updating_patch_data, true); faces.set (idx); vertices.set (vert); @@ -9942,9 +9942,7 @@ // Update normals update_normals (true); - octave::unwind_protect frame; - frame.protect_var (updating_patch_data); - updating_patch_data = true; + octave::unwind_protect_var restore_var (updating_patch_data, true); set_xdata (xd); set_ydata (yd); @@ -10206,6 +10204,120 @@ // --------------------------------------------------------------------- octave_value +scatter::properties::get_color_data (void) const +{ + octave_value c = get_cdata (); + if (c.is_undefined () || c.isempty ()) + return Matrix (); + else + return convert_cdata (*this, c, c.columns () == 1, 2); +} + +void +scatter::properties::update_data (void) +{ + Matrix xd = get_xdata ().matrix_value (); + Matrix yd = get_ydata ().matrix_value (); + Matrix zd = get_zdata ().matrix_value (); + Matrix cd = get_cdata ().matrix_value (); + Matrix sd = get_sizedata ().matrix_value (); + + bad_data_msg = ""; + if (xd.dims () != yd.dims () + || (xd.dims () != zd.dims () && ! zd.isempty ())) + { + bad_data_msg = "x/y/zdata must have the same dimensions"; + return; + } + + octave_idx_type x_rows = xd.rows (); + octave_idx_type c_cols = cd.columns (); + octave_idx_type c_rows = cd.rows (); + + if (! cd.isempty () && (c_rows != 1 || c_cols != 3) + && (c_rows != x_rows || (c_cols != 1 && c_cols != 3))) + { + bad_data_msg = "cdata must be an rgb triplet or have the same number of " + "rows as X and one or three columns"; + return; + } + + octave_idx_type s_rows = sd.rows (); + if (s_rows != 1 && s_rows != x_rows) + { + bad_data_msg = "sizedata must be a scalar or a vector with the same " + "dimensions as X"; + return; + } +} + +static bool updating_scatter_cdata = false; + +void +scatter::properties::update_color (void) +{ + if (updating_scatter_cdata) + return; + + Matrix series_idx = get_seriesindex ().matrix_value (); + if (series_idx.isempty ()) + return; + + gh_manager& gh_mgr + = octave::__get_gh_manager__ ("scatter::properties::update_color"); + + graphics_object go = gh_mgr.get_object (get___myhandle__ ()); + + axes::properties& parent_axes_prop + = dynamic_cast + (go.get_ancestor ("axes").get_properties ()); + + Matrix color_order = parent_axes_prop.get_colororder ().matrix_value (); + octave_idx_type s = (static_cast (series_idx(0)) - 1) + % color_order.rows (); + + Matrix color = Matrix (1, 3, 0.); + color(0) = color_order(s,0); + color(1) = color_order(s,1); + color(2) = color_order(s,2); + + octave::unwind_protect_var restore_var (updating_scatter_cdata, true); + + set_cdata (color); + set_cdatamode ("auto"); +} + +void +scatter::initialize (const graphics_object& go) +{ + base_graphics_object::initialize (go); + + Matrix series_idx = xproperties.get_seriesindex ().matrix_value (); + if (series_idx.isempty ()) + { + // Increment series index counter in parent axes + axes::properties& parent_axes_prop + = dynamic_cast + (go.get_ancestor ("axes").get_properties ()); + + if (! parent_axes_prop.nextplot_is ("add")) + parent_axes_prop.set_nextseriesindex (1); + + series_idx.resize (1, 1); + series_idx(0) = parent_axes_prop.get_nextseriesindex (); + xproperties.set_seriesindex (series_idx); + + parent_axes_prop.set_nextseriesindex + (parent_axes_prop.get_nextseriesindex () + 1); + } + + if (xproperties.cdatamode_is ("auto")) + xproperties.update_color (); +} + +// --------------------------------------------------------------------- + +octave_value surface::properties::get_color_data (void) const { return convert_cdata (*this, get_cdata (), cdatamapping_is ("scaled"), 3); @@ -10649,10 +10761,7 @@ get_children_limits (min_val, max_val, min_pos, max_neg, kids, update_type); - octave::unwind_protect frame; - frame.protect_var (updating_hggroup_limits); - - updating_hggroup_limits = true; + octave::unwind_protect_var restore_var (updating_hggroup_limits, true); if (limits(0) != min_val || limits(1) != max_val || limits(2) != min_pos || limits(3) != max_neg) @@ -10739,10 +10848,7 @@ update_type = 'a'; } - octave::unwind_protect frame; - frame.protect_var (updating_hggroup_limits); - - updating_hggroup_limits = true; + octave::unwind_protect_var restore_var (updating_hggroup_limits, true); Matrix limits (1, 4); @@ -10798,8 +10904,8 @@ graphics_object go = gh_mgr.get_object (hobj); if (go.valid_object () - && go.get ("uicontextmenu") == get___myhandle__ ()) - go.set ("uicontextmenu", Matrix ()); + && go.get ("contextmenu") == get___myhandle__ ()) + go.set ("contextmenu", Matrix ()); } } } @@ -11470,7 +11576,7 @@ { octave_value p = popup(j); if (! p.is_string () || p.isempty ()) - error ("set: pop-up menu definitions must be non-empty strings."); + error ("set: pop-up menu definitions must be non-empty strings"); } } else if (! (v.is_string () || v.isempty ())) @@ -11492,7 +11598,7 @@ } else { - error ("set: expecting cell of strings."); + error ("set: expecting cell of strings"); } } @@ -11528,7 +11634,7 @@ error_exists = true; if (error_exists) - error ("set: expecting either 'auto' or a cell of pixel values or auto."); + error ("set: expecting either 'auto' or a cell of pixel values or auto"); else { if (columnwidth.set (val, true)) @@ -12350,7 +12456,7 @@ /* ## Test interruptible/busyaction properties -%!function cb (h) +%!function cb (h, ~) %! setappdata (gcbf (), "cb_exec", [getappdata(gcbf (), "cb_exec") h]); %! drawnow (); %! setappdata (gcbf (), "cb_exec", [getappdata(gcbf (), "cb_exec") h]); @@ -12433,6 +12539,7 @@ plist_map["text"] = text::properties::factory_defaults (); plist_map["image"] = image::properties::factory_defaults (); plist_map["patch"] = patch::properties::factory_defaults (); + plist_map["scatter"] = scatter::properties::factory_defaults (); plist_map["surface"] = surface::properties::factory_defaults (); plist_map["light"] = light::properties::factory_defaults (); plist_map["hggroup"] = hggroup::properties::factory_defaults (); @@ -12477,8 +12584,8 @@ %! unwind_protect %! assert (ishghandle (hf)); %! assert (! ishghandle (-hf)); -%! ax = gca; -%! l = line; +%! ax = gca (); +%! l = line (); %! assert (ishghandle (ax)); %! assert (! ishghandle (-ax)); %! assert (ishghandle ([l, -1, ax, hf]), logical ([1, 0, 1, 1])); @@ -13228,7 +13335,7 @@ if (go.isa ("surface")) nd = 3; - else if ((go.isa ("line") || go.isa ("patch")) + else if ((go.isa ("line") || go.isa ("patch") || go.isa ("scatter")) && ! go.get ("zdata").isempty ()) nd = 3; else @@ -13331,6 +13438,15 @@ GO_BODY (patch); } +DEFMETHOD (__go_scatter__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __go_scatter__ (@var{parent}) +Undocumented internal function. +@end deftypefn */) +{ + GO_BODY (scatter); +} + DEFMETHOD (__go_light__, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {} __go_light__ (@var{parent}) @@ -13700,9 +13816,7 @@ if (args.length () > 3) print_usage (); - octave::unwind_protect frame; - - frame.protect_var (Vdrawnow_requested, false); + octave::unwind_protect_var restore_var (Vdrawnow_requested, false); // Redraw unless we are in the middle of a deletion. @@ -14528,6 +14642,42 @@ return ovl (go.get_toolkit ().get_pixels (go)); } +DEFMETHOD (__get_position__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {@var{pos} =} __get_position__ (@var{h}, @var{units}) +Internal function. + +Return the position of the graphics object @var{h} in the specified +@var{units}. +@end deftypefn */) +{ + if (args.length () != 2) + print_usage (); + + double h + = args(0).xdouble_value ("__get_position__: H must be a graphics handle"); + + std::string units + = args(1).xstring_value ("__get_position__: UNITS must be a string"); + + gh_manager& gh_mgr = interp.get_gh_manager (); + + graphics_object go = gh_mgr.get_object (h); + + if (h == 0 || ! go) + error ("__get_position__: H must be a handle to a valid graphics object"); + + graphics_object parent_go = gh_mgr.get_object (go.get_parent ()); + Matrix bbox = parent_go.get_properties ().get_boundingbox (true) + .extract_n (0, 2, 1, 2); + + Matrix pos = convert_position (go.get ("position").matrix_value (), + go.get ("units").string_value (), + units, bbox); + + return ovl (pos); +} + DEFUN (__get_system_fonts__, args, , doc: /* -*- texinfo -*- @deftypefn {} {@var{font_struct} =} __get_system_fonts__ () diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/graphics.in.h --- a/libinterp/corefcn/graphics.in.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/graphics.in.h Thu Nov 19 13:08:00 2020 -0800 @@ -2312,6 +2312,18 @@ void set___modified__ (const octave_value& val) { __modified__ = val; } + // Redirect calls to "uicontextmenu" to "contextmenu". + + graphics_handle get_uicontextmenu (void) const + { + return get_contextmenu (); + } + + void set_uicontextmenu (const octave_value& val) + { + set_contextmenu (val); + } + void reparent (const graphics_handle& new_parent) { parent = new_parent; } // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent @@ -2322,7 +2334,7 @@ virtual void update_axis_limits (const std::string& axis_type, const graphics_handle& h) const; - virtual void update_uicontextmenu (void) const; + virtual void update_contextmenu (void) const; virtual void delete_children (bool clear = false, bool from_root = false) { @@ -2382,6 +2394,7 @@ callback_property buttondownfcn , Matrix () children_property children gf , Matrix () bool_property clipping , "on" + handle_property contextmenu u , graphics_handle () callback_property createfcn , Matrix () callback_property deletefcn , Matrix () radio_property handlevisibility u , "{on}|callback|off" @@ -2393,7 +2406,7 @@ bool_property selectionhighlight , "on" string_property tag s , "" string_property type frs , ty - handle_property uicontextmenu u , graphics_handle () + handle_property uicontextmenu gsh , graphics_handle () any_property userdata , Matrix () bool_property visible u , "on" @@ -2431,7 +2444,7 @@ virtual void init (void) { - uicontextmenu.add_constraint ("uicontextmenu"); + contextmenu.add_constraint ("uicontextmenu"); } }; @@ -3471,6 +3484,43 @@ void sync_positions (void); + // Redirect calls to "activepositionproperty" to "positionconstraint". + + std::string get_activepositionproperty (void) const + { + std::string cur_val; + + if (positionconstraint.is ("innerposition")) + cur_val = "position"; + else + cur_val = "outerposition"; + + return cur_val; + } + + void set_activepositionproperty (const octave_value& val) + { + // call set method to validate the input + activepositionproperty.set (val); + + if (val.char_matrix_value ().row_as_string (0) == "position") + set_positionconstraint ("innerposition"); + else + set_positionconstraint (val); + } + + // Redirect calls to "innerposition" to "position". + + octave_value get_innerposition (void) const + { + return get_position (); + } + + void set_innerposition (const octave_value& val) + { + set_position (val); + } + void update_autopos (const std::string& elem_type); void update_xlabel_position (void); void update_ylabel_position (void); @@ -3640,9 +3690,12 @@ // Programming note: Keep property list sorted if new ones are added. BEGIN_PROPERTIES (axes) - radio_property activepositionproperty , "{outerposition}|position" + radio_property activepositionproperty gsh , "{outerposition}|position" row_vector_property alim m , default_lim () radio_property alimmode , "{auto}|manual" + // FIXME: not yet implemented + array_property alphamap , Matrix () + radio_property alphascale , "{linear}|log" color_property ambientlightcolor , color_values (1, 1, 1) bool_property box u , "off" radio_property boxstyle , "{back}|full" @@ -3661,12 +3714,15 @@ array_property colormap sg , Matrix () array_property colororder , default_colororder () double_property colororderindex , 1.0 + radio_property colorscale , "{linear}|log" array_property currentpoint , Matrix (2, 3, 0.0) row_vector_property dataaspectratio mu , Matrix (1, 3, 1.0) radio_property dataaspectratiomode u , "{auto}|manual" radio_property fontangle u , "{normal}|italic" string_property fontname u , OCTAVE_DEFAULT_FONTNAME - double_property fontsize u , 10 + double_property fontsize mu , 10 + // FIXME: not yet implemented + radio_property fontsizemode , "{auto}|manual" bool_property fontsmoothing u , "on" radio_property fontunits SU , "{points}|inches|centimeters|normalized|pixels" radio_property fontweight u , "{normal}|bold" @@ -3675,8 +3731,15 @@ color_property gridcolor m , color_property (color_values (0.15, 0.15, 0.15), radio_values ("none")) radio_property gridcolormode , "{auto}|manual" radio_property gridlinestyle , "{-}|--|:|-.|none" + array_property innerposition sg , default_axes_position () + // FIXME: Should be an array of "interaction objects". Make it read-only for now. + any_property interactions r , Matrix () double_property labelfontsizemultiplier u , 1.1 radio_property layer u , "{bottom}|top" + // FIXME: Should be a "layoutoptions" object. Make it read-only for now. + handle_property layout r , graphics_handle () + // FIXME: Should be a "legend" object. Make it read-only for now. + handle_property legend r , graphics_handle () // FIXME: should be kind of string array. any_property linestyleorder S , "-" double_property linestyleorderindex , 1.0 @@ -3687,10 +3750,12 @@ radio_property minorgridcolormode , "{auto}|manual" radio_property minorgridlinestyle , "{:}|-|--|-.|none" radio_property nextplot , "{replace}|add|replacechildren" + double_property nextseriesindex r , 1.0 array_property outerposition u , default_axes_outerposition () row_vector_property plotboxaspectratio mu , Matrix (1, 3, 1.0) radio_property plotboxaspectratiomode u , "{auto}|manual" array_property position u , default_axes_position () + radio_property positionconstraint , "{outerposition}|innerposition" radio_property projection , "{orthographic}|perspective" radio_property sortmethod , "{depth}|childorder" radio_property tickdir mu , "{in}|out" @@ -3702,9 +3767,12 @@ handle_property title SOf , make_graphics_handle ("text", __myhandle__, false, false, false) double_property titlefontsizemultiplier u , 1.1 radio_property titlefontweight u , "{bold}|normal" - // FIXME: uicontextmenu should be moved here. + // FIXME: Should be a "axestoolbar" object. Make it read-only for now. + handle_property toolbar r , graphics_handle () radio_property units SU , "{normalized}|inches|centimeters|points|pixels|characters" array_property view u , default_axes_view () + // FIXME: Should be a "ruler" object. Make it read-only for now. + handle_property xaxis r , graphics_handle () radio_property xaxislocation u , "{bottom}|top|origin" color_property xcolor mu , color_property (color_values (0.15, 0.15, 0.15), radio_values ("none")) radio_property xcolormode , "{auto}|manual" @@ -3722,6 +3790,8 @@ radio_property xticklabelmode u , "{auto}|manual" double_property xticklabelrotation , 0.0 radio_property xtickmode u , "{auto}|manual" + // FIXME: Should be a "ruler" object. Make it read-only for now. + handle_property yaxis r , graphics_handle () radio_property yaxislocation u , "{left}|right|origin" color_property ycolor mu , color_property (color_values (0.15, 0.15, 0.15), radio_values ("none")) radio_property ycolormode , "{auto}|manual" @@ -3738,6 +3808,8 @@ radio_property yticklabelmode u , "{auto}|manual" double_property yticklabelrotation , 0.0 radio_property ytickmode u , "{auto}|manual" + // FIXME: Should be a "ruler" object. Make it read-only for now. + handle_property zaxis r , graphics_handle () color_property zcolor mu , color_property (color_values (0.15, 0.15, 0.15), radio_values ("none")) radio_property zcolormode , "{auto}|manual" radio_property zdir u , "{normal}|reverse" @@ -4382,8 +4454,7 @@ color_property edgecolor , color_property (radio_values ("{none}"), color_values (0, 0, 0)) bool_property editing , "off" array_property extent rG , Matrix (1, 4, 0.0) - // FIXME: DEPRECATED: Remove "oblique" in version 7. - radio_property fontangle u , "{normal}|italic|oblique" + radio_property fontangle u , "{normal}|italic" string_property fontname u , OCTAVE_DEFAULT_FONTNAME double_property fontsize u , 10 bool_property fontsmoothing u , "on" @@ -4490,11 +4561,6 @@ { update_font (); update_text_extent (); - // FIXME: DEPRECATED: Remove warning for "oblique" in version 7. - if (fontangle.is ("oblique")) - warning_with_id ("Octave:deprecated-property", - "Setting 'fontangle' to '%s' is deprecated, \ -use 'italic' or 'normal'.", fontangle.current_value ().c_str ()); } void update_fontweight (void) { update_font (); update_text_extent (); } @@ -5078,6 +5144,238 @@ // --------------------------------------------------------------------- +class OCTINTERP_API scatter : public base_graphics_object +{ +public: + class OCTINTERP_API properties : public base_properties + { + public: + octave_value get_color_data (void) const; + + // Matlab allows incoherent data to be stored in scatter properties. + // The scatter object should then be ignored by the renderer. + bool has_bad_data (std::string& msg) const + { + msg = bad_data_msg; + return ! msg.empty (); + } + + bool is_aliminclude (void) const + { return aliminclude.is_on (); } + std::string get_aliminclude (void) const + { return aliminclude.current_value (); } + + bool is_climinclude (void) const + { return climinclude.is_on (); } + std::string get_climinclude (void) const + { return climinclude.current_value (); } + + // See the genprops.awk script for an explanation of the + // properties declarations. + // Programming note: Keep property list sorted if new ones are added. + + BEGIN_PROPERTIES (scatter) + array_property annotation , Matrix () + array_property cdata mu , Matrix () + radio_property cdatamode u , "{auto}|manual" + string_property cdatasource , "" + array_property datatiptemplate , Matrix () + string_property displayname , "" + array_property latitudedata , Matrix () + string_property latitudedatasource , "" + double_property linewidth , 0.5 + array_property longitudedata , Matrix () + string_property longitudedatasource , "" + radio_property marker , "{o}|+|*|.|x|s|square|d|diamond|^|v|>|<|p|pentagram|h|hexagram|none" + double_property markeredgealpha , 1.0 + color_property markeredgecolor , color_property (radio_values ("{flat}|none"), color_values (0, 0, 0)) + double_property markerfacealpha , 1.0 + color_property markerfacecolor , color_property (radio_values ("{none}|auto|flat"), color_values (0, 0, 0)) + array_property rdata , Matrix () + string_property rdatasource , "" + array_property seriesindex u , Matrix () + array_property sizedata u , Matrix () + string_property sizedatasource , "" + array_property thetadata , Matrix () + string_property thetadatasource , "" + array_property xdata u , Matrix () + string_property xdatasource , "" + array_property ydata u , Matrix () + string_property ydatasource , "" + array_property zdata u , Matrix () + string_property zdatasource , "" + + // hidden properties for limit computation + row_vector_property alim hlr , Matrix () + row_vector_property clim hlr , Matrix () + row_vector_property xlim hlr , Matrix () + row_vector_property ylim hlr , Matrix () + row_vector_property zlim hlr , Matrix () + bool_property aliminclude hlg , "on" + bool_property climinclude hlg , "on" + bool_property xliminclude hl , "on" + bool_property yliminclude hl , "on" + bool_property zliminclude hl , "on" + END_PROPERTIES + + protected: + void init (void) + { + xdata.add_constraint (dim_vector (-1, 1)); + xdata.add_constraint (dim_vector (1, -1)); + xdata.add_constraint (dim_vector (-1, 0)); + xdata.add_constraint (dim_vector (0, -1)); + ydata.add_constraint (dim_vector (-1, 1)); + ydata.add_constraint (dim_vector (1, -1)); + ydata.add_constraint (dim_vector (-1, 0)); + ydata.add_constraint (dim_vector (0, -1)); + zdata.add_constraint (dim_vector (-1, 1)); + zdata.add_constraint (dim_vector (1, -1)); + zdata.add_constraint (dim_vector (-1, 0)); + zdata.add_constraint (dim_vector (0, -1)); + sizedata.add_constraint ("min", 0.0, false); + sizedata.add_constraint (dim_vector (-1, 1)); + sizedata.add_constraint (dim_vector (1, -1)); + sizedata.add_constraint (dim_vector (-1, 0)); + sizedata.add_constraint (dim_vector (0, -1)); + cdata.add_constraint ("double"); + cdata.add_constraint ("single"); + cdata.add_constraint ("logical"); + cdata.add_constraint ("int8"); + cdata.add_constraint ("int16"); + cdata.add_constraint ("int32"); + cdata.add_constraint ("int64"); + cdata.add_constraint ("uint8"); + cdata.add_constraint ("uint16"); + cdata.add_constraint ("uint32"); + cdata.add_constraint ("uint64"); + cdata.add_constraint ("real"); + cdata.add_constraint (dim_vector (-1, 1)); + cdata.add_constraint (dim_vector (-1, 3)); + cdata.add_constraint (dim_vector (-1, 0)); + cdata.add_constraint (dim_vector (0, -1)); + + linewidth.add_constraint ("min", 0.0, false); + seriesindex.add_constraint (dim_vector (1, 1)); + seriesindex.add_constraint (dim_vector (-1, 0)); + seriesindex.add_constraint (dim_vector (0, -1)); + } + + public: + void update_color (void); + + private: + std::string bad_data_msg; + + void update_xdata (void) + { + if (get_xdata ().isempty ()) + { + // For compatibility with Matlab behavior, + // if x/ydata are set empty, silently empty other *data properties. + set_ydata (Matrix ()); + set_zdata (Matrix ()); + bool cdatamode_auto = cdatamode.is ("auto"); + set_cdata (Matrix ()); + if (cdatamode_auto) + set_cdatamode ("auto"); + } + + set_xlim (xdata.get_limits ()); + + update_data (); + } + + void update_ydata (void) + { + if (get_ydata ().isempty ()) + { + set_xdata (Matrix ()); + set_zdata (Matrix ()); + bool cdatamode_auto = cdatamode.is ("auto"); + set_cdata (Matrix ()); + if (cdatamode_auto) + set_cdatamode ("auto"); + } + + set_ylim (ydata.get_limits ()); + + update_data (); + } + + void update_zdata (void) + { + set_zlim (zdata.get_limits ()); + + update_data (); + } + + void update_sizedata (void) + { + update_data (); + } + + void update_cdata (void) + { + if (get_cdata ().matrix_value ().rows () == 1) + set_clim (cdata.get_limits ()); + else + clim = cdata.get_limits (); + + update_data (); + } + + void update_cdatamode (void) + { + if (cdatamode.is ("auto")) + update_color (); + } + + void update_seriesindex (void) + { + if (cdatamode.is ("auto")) + update_color (); + } + + void update_data (void); + + }; + +private: + properties xproperties; + property_list default_properties; + +public: + scatter (const graphics_handle& mh, const graphics_handle& p) + : base_graphics_object (), xproperties (mh, p) + { + // FIXME: seriesindex should increment by one each time a new scatter + // object is added to the axes. + } + + ~scatter (void) = default; + + base_properties& get_properties (void) { return xproperties; } + + const base_properties& get_properties (void) const { return xproperties; } + + bool valid_object (void) const { return true; } + + bool has_readonly_property (const caseless_str& pname) const + { + bool retval = xproperties.has_readonly_property (pname); + if (! retval) + retval = base_properties::has_readonly_property (pname); + return retval; + } + +protected: + void initialize (const graphics_object& go); + +}; + +// --------------------------------------------------------------------- + class OCTINTERP_API surface : public base_graphics_object { public: @@ -5430,6 +5728,7 @@ // --------------------------------------------------------------------- +// FIXME: This class has been renamed to "contextmenu" in Matlab R2020a. class OCTINTERP_API uicontextmenu : public base_graphics_object { public: @@ -5523,8 +5822,7 @@ bool_property clipping , "on" radio_property enable , "{on}|inactive|off" array_property extent rG , Matrix (1, 4, 0.0) - // FIXME: DEPRECATED: Remove "oblique" in version 7. - radio_property fontangle u , "{normal}|italic|oblique" + radio_property fontangle u , "{normal}|italic" string_property fontname u , OCTAVE_DEFAULT_FONTNAME double_property fontsize u , 10 radio_property fontunits S , "inches|centimeters|normalized|{points}|pixels" @@ -5574,11 +5872,6 @@ void update_fontangle (void) { update_text_extent (); - // FIXME: DEPRECATED: Remove warning for "oblique" in version 7. - if (fontangle.is ("oblique")) - warning_with_id ("Octave:deprecated-property", - "Setting 'fontangle' to '%s' is deprecated, \ -use 'italic' or 'normal'.", fontangle.current_value ().c_str ()); } void update_fontweight (void) { update_text_extent (); } @@ -5639,8 +5932,7 @@ radio_property bordertype , "none|{etchedin}|etchedout|beveledin|beveledout|line" double_property borderwidth , 1 bool_property clipping , "on" - // FIXME: DEPRECATED: Remove "oblique" in version 7. - radio_property fontangle , "{normal}|italic|oblique" + radio_property fontangle , "{normal}|italic" string_property fontname , OCTAVE_DEFAULT_FONTNAME double_property fontsize , 10 radio_property fontunits S , "inches|centimeters|normalized|{points}|pixels" @@ -5731,8 +6023,7 @@ color_property backgroundcolor , color_values (0.94, 0.94, 0.94) radio_property bordertype , "none|{etchedin}|etchedout|beveledin|beveledout|line" double_property borderwidth , 1 - // FIXME: DEPRECATED: Remove "oblique" in version 7. - radio_property fontangle , "{normal}|italic|oblique" + radio_property fontangle , "{normal}|italic" string_property fontname , OCTAVE_DEFAULT_FONTNAME double_property fontsize , 10 radio_property fontunits S , "inches|centimeters|normalized|{points}|pixels" @@ -5825,8 +6116,7 @@ any_property data u , Matrix () bool_property enable , "on" array_property extent rG , Matrix (1, 4, 0.0) - // FIXME: DEPRECATED: Remove "oblique" in version 7. - radio_property fontangle u , "{normal}|italic|oblique" + radio_property fontangle u , "{normal}|italic" string_property fontname u , OCTAVE_DEFAULT_FONTNAME double_property fontsize u , 10 radio_property fontunits S , "inches|centimeters|normalized|{points}|pixels" @@ -5867,11 +6157,6 @@ void update_fontangle (void) { update_table_extent (); - // FIXME: DEPRECATED: Remove warning for "oblique" in version 7. - if (fontangle.is ("oblique")) - warning_with_id ("Octave:deprecated-property", - "Setting 'fontangle' to '%s' is deprecated, \ -use 'italic' or 'normal'.", fontangle.current_value ().c_str ()); } void update_fontweight (void) { update_table_extent (); } }; diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/gsvd.cc --- a/libinterp/corefcn/gsvd.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/gsvd.cc Thu Nov 19 13:08:00 2020 -0800 @@ -319,7 +319,7 @@ %! B = B0; %! A(:, 3) = 2*A(:, 1) - A(:, 2); %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(5, 3); D1(1:3, 1:3) = C; +%! D1 = zeros (5, 3); D1(1:3, 1:3) = C; %! D2 = S; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (3, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*R) <= 1e-6); @@ -329,7 +329,7 @@ %!test <48807> %! B(:, 3) = 2*B(:, 1) - B(:, 2); %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(5, 2); D1(1:2, 1:2) = C; +%! D1 = zeros (5, 2); D1(1:2, 1:2) = C; %! D2 = [S; zeros(1, 2)]; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (2, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*[zeros(2, 1) R]) <= 1e-6); @@ -351,8 +351,8 @@ %!test <48807> %! B(2, 2) = 0; %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(3, 5); D1(1, 1) = 1; D1(2:3, 2:3) = C; -%! D2 = zeros(5, 5); D2(1:2, 2:3) = S; D2(3:4, 4:5) = eye (2); +%! D1 = zeros (3, 5); D1(1, 1) = 1; D1(2:3, 2:3) = C; +%! D2 = zeros (5, 5); D2(1:2, 2:3) = S; D2(3:4, 4:5) = eye (2); %! assert (norm (diag (C).^2 + diag (S).^2 - ones (2, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*R) <= 1e-6); %! assert (norm ((V'*B*X) - D2*R) <= 1e-6); @@ -374,7 +374,7 @@ %! A(:, 3) = 2*A(:, 1) - A(:, 2); %! B(:, 3) = 2*B(:, 1) - B(:, 2); %! [U, V, X, C, S, R]=gsvd (A, B); -%! D1 = zeros(3, 4); D1(1:3, 1:3) = C; +%! D1 = zeros (3, 4); D1(1:3, 1:3) = C; %! D2 = eye (4); D2(1:3, 1:3) = S; D2(5,:) = 0; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (3, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*[zeros(4, 1) R]) <= 1e-6); @@ -387,7 +387,7 @@ %! A = A0; %! B = B0; %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(5, 3); D1(1:3, 1:3) = C; +%! D1 = zeros (5, 3); D1(1:3, 1:3) = C; %! D2 = S; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (3, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*R) <= 1e-6); @@ -397,7 +397,7 @@ %!test <48807> %! B(2, 2) = 0; %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(5, 3); D1(1, 1) = 1; D1(2:3, 2:3) = C; +%! D1 = zeros (5, 3); D1(1, 1) = 1; D1(2:3, 2:3) = C; %! D2 = [zeros(2, 1) S; zeros(1, 3)]; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (2, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*R) <= 1e-6); @@ -408,7 +408,7 @@ %! B = B0; %! A(:, 3) = 2*A(:, 1) - A(:, 2); %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(5, 3); D1(1:3, 1:3) = C; +%! D1 = zeros (5, 3); D1(1:3, 1:3) = C; %! D2 = S; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (3, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*R) <= 1e-6); @@ -418,7 +418,7 @@ %!test <48807> %! B(:, 3) = 2*B(:, 1) - B(:, 2); %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(5, 2); D1(1:2, 1:2) = C; +%! D1 = zeros (5, 2); D1(1:2, 1:2) = C; %! D2 = [S; zeros(1, 2)]; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (2, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*[zeros(2, 1) R]) <= 1e-6); @@ -441,8 +441,8 @@ %!test <48807> %! B(2, 2) = 0; %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(3, 5); D1(1, 1) = 1; D1(2:3, 2:3) = C; -%! D2 = zeros(5,5); D2(1:2, 2:3) = S; D2(3:4, 4:5) = eye (2); +%! D1 = zeros (3, 5); D1(1, 1) = 1; D1(2:3, 2:3) = C; +%! D2 = zeros (5,5); D2(1:2, 2:3) = S; D2(3:4, 4:5) = eye (2); %! assert (norm (diag (C).^2 + diag (S).^2 - ones (2, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*R) <= 1e-6); %! assert (norm ((V'*B*X) - D2*R) <= 1e-6); @@ -452,8 +452,8 @@ %! B = B0; %! A(3, :) = 2*A(1, :) - A(2, :); %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(3, 5); D1(1:3, 1:3) = C; -%! D2 = zeros(5,5); D2(1:3, 1:3) = S; D2(4:5, 4:5) = eye (2); +%! D1 = zeros (3, 5); D1(1:3, 1:3) = C; +%! D2 = zeros (5,5); D2(1:3, 1:3) = S; D2(4:5, 4:5) = eye (2); %! assert (norm (diag (C).^2 + diag (S).^2 - ones (3, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*R) <= 1e-6); %! assert (norm ((V'*B*X) - D2*R) <= 1e-6); @@ -465,7 +465,7 @@ %! A(:, 3) = 2*A(:, 1) - A(:, 2); %! B(:, 3) = 2*B(:, 1) - B(:, 2); %! [U, V, X, C, S, R] = gsvd (A, B); -%! D1 = zeros(3, 4); D1(1:3, 1:3) = C; +%! D1 = zeros (3, 4); D1(1:3, 1:3) = C; %! D2 = eye (4); D2(1:3, 1:3) = S; D2(5,:) = 0; %! assert (norm (diag (C).^2 + diag (S).^2 - ones (3, 1)) <= 1e-6); %! assert (norm ((U'*A*X) - D1*[zeros(4, 1) R]) <= 1e-6); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/hash.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/help.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/hess.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/hex2num.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/input.cc --- a/libinterp/corefcn/input.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/input.cc Thu Nov 19 13:08:00 2020 -0800 @@ -525,7 +525,7 @@ error ("__mfile_encoding__: conversion from encoding '%s' " "not supported", encoding.c_str ()); else - error ("__mfile_encoding__: error %d opening encoding '%s'.", + error ("__mfile_encoding__: error %d opening encoding '%s'", errno, encoding.c_str ()); } else @@ -541,6 +541,92 @@ return retval; } + // Get part of the directory that would be added to the load path + static std::string load_path_dir (const std::string& dir) + { + std::string lp_dir = dir; + + // strip trailing filesep + size_t ipos = lp_dir.find_last_not_of (sys::file_ops::dir_sep_chars ()); + if (ipos != std::string::npos) + lp_dir = lp_dir.erase (ipos+1); + + // strip trailing private folder + ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); + if (ipos != std::string::npos + && lp_dir.substr (ipos+1).compare ("private") == 0) + { + lp_dir = lp_dir.erase (ipos); + ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); + } + + // strip trailing @class folder + if (ipos != std::string::npos && lp_dir[ipos+1] == '@') + { + lp_dir = lp_dir.erase (ipos); + ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); + } + + // strip (nested) +namespace folders + while (ipos != std::string::npos && lp_dir[ipos+1] == '+') + { + lp_dir = lp_dir.erase (ipos); + ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ()); + } + + return lp_dir; + } + + std::string input_system::dir_encoding (const std::string& dir) + { + std::string enc = m_mfile_encoding; + + auto enc_it = m_dir_encoding.find (load_path_dir (dir)); + if (enc_it != m_dir_encoding.end ()) + enc = enc_it->second; + + return enc; + } + + void input_system::set_dir_encoding (const std::string& dir, + std::string& enc) + { + // use lower case + std::transform (enc.begin (), enc.end (), enc.begin (), ::tolower); + + if (enc.compare ("delete") == 0) + { + // Remove path from map + m_dir_encoding.erase (load_path_dir (dir)); + return; + } + else if (enc.compare ("utf-8")) + { + // Check for valid encoding name. + // FIXME: This will probably not happen very often and opening the + // encoder doesn't take long. + // Should we cache working encoding identifiers anyway? + void *codec + = octave_iconv_open_wrapper (enc.c_str (), "utf-8"); + + if (codec == reinterpret_cast (-1)) + { + if (errno == EINVAL) + error ("dir_encoding: conversion from encoding '%s' " + "not supported", enc.c_str ()); + else + error ("dir_encoding: error %d opening encoding '%s'.", + errno, enc.c_str ()); + } + else + octave_iconv_close_wrapper (codec); + } + + m_dir_encoding[load_path_dir (dir)] = enc; + + return; + } + octave_value input_system::auto_repeat_debug_command (const octave_value_list& args, int nargout) @@ -816,7 +902,14 @@ public: file_reader (interpreter& interp, FILE *f_arg) - : base_reader (interp), m_file (f_arg) { } + : base_reader (interp), m_file (f_arg) + { + octave::input_system& input_sys = interp.get_input_system (); + m_encoding = input_sys.mfile_encoding (); + } + + file_reader (interpreter& interp, FILE *f_arg, const std::string& enc) + : base_reader (interp), m_file (f_arg), m_encoding (enc) { } std::string get_input (const std::string& prompt, bool& eof); @@ -828,6 +921,8 @@ FILE *m_file; + std::string m_encoding; + static const std::string s_in_src; }; @@ -861,6 +956,10 @@ : m_rep (new file_reader (interp, file)) { } + input_reader::input_reader (interpreter& interp, FILE *file, const std::string& enc) + : m_rep (new file_reader (interp, file, enc)) + { } + input_reader::input_reader (interpreter& interp, const std::string& str) : m_rep (new eval_string_reader (interp, str)) { } @@ -890,9 +989,15 @@ std::string src_str = octave_fgets (m_file, eof); - input_system& input_sys = m_interpreter.get_input_system (); + std::string mfile_encoding; - std::string mfile_encoding = input_sys.mfile_encoding (); + if (m_encoding.empty ()) + { + input_system& input_sys = m_interpreter.get_input_system (); + mfile_encoding = input_sys.mfile_encoding (); + } + else + mfile_encoding = m_encoding; std::string encoding; if (mfile_encoding.compare ("system") == 0) @@ -934,8 +1039,7 @@ "converting from codepage '%s' to UTF-8: %s", encoding.c_str (), std::strerror (errno)); - unwind_protect frame; - frame.add_fcn (::free, static_cast (utf8_str)); + unwind_action free_utf8_str ([=] () { ::free (utf8_str); }); src_str = std::string (reinterpret_cast (utf8_str), length); } @@ -1412,6 +1516,73 @@ return input_sys.mfile_encoding (args, nargout); } +DEFMETHOD (dir_encoding, interp, args, nargout, + doc: /* -*- texinfo -*- +@deftypefn {} {@var{current_encoding} =} dir_encoding (@var{dir}) +@deftypefnx {} {@var{prev_encoding} =} dir_encoding (@var{dir}, @var{encoding}) +@deftypefnx {} {} dir_encoding (@dots{}) +Set and query the @var{encoding} that is used for reading m-files in @var{dir}. + +That encoding overrides the (globally set) m-file encoding. + +The string @var{DIR} must match the form how the directory would appear in the +load path. + +The @var{encoding} must be a valid encoding identifier or @code{"delete"}. In +the latter case, the (globally set) m-file encoding will be used for the given +@var{dir}. + +The currently or previously used encoding is returned in @var{current_encoding} +or @var{prev_encoding}, respectively. The output argument must be explicitly +requested. + +The directory encoding is automatically read from the file @file{.oct-config} +when a new path is added to the load path (for example with @code{addpath}). +To set the encoding for all files in the same folder, that file must contain +a line starting with @code{"encoding="} followed by the encoding identifier. + +For example to set the file encoding for all files in the same folder to +ISO 8859-1 (Latin-1), create a file @file{.oct-config} with the following +content: + +@example +encoding=iso8859-1 +@end example + +If the file encoding is changed after the files have already been parsed, the +files have to be parsed again for that change to take effect. That can be done +with the command @code{clear all}. + +@seealso{addpath, path} +@end deftypefn */) +{ + int nargin = args.length (); + + if (nargin < 1 || nargin > 2) + print_usage (); + + std::string dir + = args(0).xstring_value ("dir_encoding: DIR must be a string"); + + octave_value retval; + + octave::input_system& input_sys = interp.get_input_system (); + + if (nargout > 0) + retval = input_sys.dir_encoding (dir); + + if (nargin > 1) + { + std::string encoding + = args(1).xstring_value ("dir_encoding: ENCODING must be a string"); + + input_sys.set_dir_encoding (dir, encoding); + } + + return ovl (retval); + +} + DEFMETHOD (auto_repeat_debug_command, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {@var{val} =} auto_repeat_debug_command () @@ -1430,40 +1601,3 @@ return input_sys.auto_repeat_debug_command (args, nargout); } - -// Always define these functions. The macro is intended to allow the -// declarations to be hidden, not so that Octave will not provide the -// functions if they are requested. - -// #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) - -bool -octave_yes_or_no (const std::string& prompt) -{ - octave::input_system& input_sys - = octave::__get_input_system__ ("set_default_prompts"); - - return input_sys.yes_or_no (prompt); -} - -void -remove_input_event_hook_functions (void) -{ - octave::input_system& input_sys - = octave::__get_input_system__ ("remove_input_event_hook_functions"); - - input_sys.clear_input_event_hooks (); -} - -// Fix things up so that input can come from the standard input. This -// may need to become much more complicated, which is why it's in a -// separate function. - -FILE * -get_input_from_stdin (void) -{ - octave::command_editor::set_input_stream (stdin); - return octave::command_editor::get_input_stream (); -} - -// #endif diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/input.h --- a/libinterp/corefcn/input.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/input.h Thu Nov 19 13:08:00 2020 -0800 @@ -34,6 +34,7 @@ #include #include +#include #include "hook-fcn.h" #include "oct-time.h" @@ -147,6 +148,10 @@ void set_mfile_encoding (const std::string& s) { m_mfile_encoding = s; } + std::string dir_encoding (const std::string& dir); + + void set_dir_encoding (const std::string& dir, std::string& enc); + octave_value auto_repeat_debug_command (const octave_value_list& args, int nargout); @@ -199,6 +204,9 @@ // Codepage which is used to read .m files std::string m_mfile_encoding; + // map of directories -> used mfile encoding + std::unordered_map m_dir_encoding; + // TRUE means repeat last debug command if the user just types RET. bool m_auto_repeat_debug_command; @@ -259,6 +267,8 @@ input_reader (interpreter& interp, FILE *file); + input_reader (interpreter& interp, FILE *file, const std::string& enc); + input_reader (interpreter& interp, const std::string& str); input_reader (const input_reader& ir) = default; @@ -298,17 +308,4 @@ }; } -#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) - -OCTAVE_DEPRECATED (5, "use 'octave::input_system::yes_or_no' instead") -extern bool octave_yes_or_no (const std::string& prompt); - -OCTAVE_DEPRECATED (5, "use 'octave::input_system::clear_input_event_hooks' instead") -extern void remove_input_event_hook_functions (void); - -OCTAVE_DEPRECATED (5, "this function will be removed in a future version of Octave") -extern OCTINTERP_API FILE * get_input_from_stdin (void); - #endif - -#endif diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/interpreter.cc --- a/libinterp/corefcn/interpreter.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/interpreter.cc Thu Nov 19 13:08:00 2020 -0800 @@ -295,6 +295,15 @@ return retval; } +DEFMETHOD (__traditional__, interp, , , + doc: /* -*- texinfo -*- +@deftypefn {} {} __traditional__ () +Undocumented internal function. +@end deftypefn */) +{ + return ovl (interp.traditional ()); +} + namespace octave { temporary_file_list::~temporary_file_list (void) @@ -463,6 +472,7 @@ m_read_site_files (true), m_read_init_files (m_app_context != nullptr), m_verbose (false), + m_traditional (false), m_inhibit_startup_message (false), m_load_path_initialized (false), m_history_initialized (false), @@ -513,7 +523,6 @@ m_display_info.initialize (); bool line_editing = false; - bool traditional = false; if (m_app_context) { @@ -565,7 +574,7 @@ && ! options.forced_line_editing ()) line_editing = false; - traditional = options.traditional (); + m_traditional = options.traditional (); // FIXME: if possible, perform the following actions directly // instead of using the interpreter-level functions. @@ -625,7 +634,7 @@ // This should be done before initializing the load path because // some PKG_ADD files might need --traditional behavior. - if (traditional) + if (m_traditional) maximum_braindamage (); octave_interpreter_ready = true; @@ -700,7 +709,7 @@ frame.add_method (m_load_path, &load_path::set_add_hook, m_load_path.get_add_hook ()); - m_load_path.set_add_hook ([this] (const std::string& dir) + m_load_path.set_add_hook ([=] (const std::string& dir) { this->execute_pkg_add (dir); }); m_load_path.initialize (set_initial_path); @@ -1383,6 +1392,7 @@ // FIXME: should these actions be handled as a list of functions // to call so users can add their own chdir handlers? + m_load_path.read_dir_config ("."); m_load_path.update (); m_event_manager.directory_changed (sys::env::get_current_directory ()); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/interpreter.h --- a/libinterp/corefcn/interpreter.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/interpreter.h Thu Nov 19 13:08:00 2020 -0800 @@ -180,6 +180,16 @@ m_verbose = flag; } + void traditional (bool flag) + { + m_traditional = flag; + } + + bool traditional (void) const + { + return m_traditional; + } + void inhibit_startup_message (bool flag) { m_inhibit_startup_message = flag; @@ -554,6 +564,8 @@ bool m_verbose; + bool m_traditional; + bool m_inhibit_startup_message; bool m_load_path_initialized; diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/inv.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/jsondecode.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/jsondecode.cc Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,557 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "defun.h" +#include "error.h" +#include "errwarn.h" +#include "ovl.h" +#include "parse.h" + +#if defined (HAVE_RAPIDJSON) +# include +# include +#endif + +#if defined (HAVE_RAPIDJSON) + +octave_value +decode (const rapidjson::Value& val, const octave_value_list& options); + +//! Decodes a numerical JSON value into a scalar number. +//! +//! @param val JSON value that is guaranteed to be a numerical value. +//! +//! @return @ref octave_value that contains the numerical value of @p val. +//! +//! @b Example: +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("123"); +//! octave_value num = decode_number (d); +//! @endcode + +octave_value +decode_number (const rapidjson::Value& val) +{ + if (val.IsUint ()) + return octave_value (val.GetUint ()); + else if (val.IsInt ()) + return octave_value (val.GetInt ()); + else if (val.IsUint64 ()) + return octave_value (val.GetUint64 ()); + else if (val.IsInt64 ()) + return octave_value (val.GetInt64 ()); + else if (val.IsDouble ()) + return octave_value (val.GetDouble ()); + else + error ("jsondecode: unidentified type"); +} + +//! Decodes a JSON object into a scalar struct. +//! +//! @param val JSON value that is guaranteed to be a JSON object. +//! @param options @c ReplacementStyle and @c Prefix options with their values. +//! +//! @return @ref octave_value that contains the equivalent scalar struct of @p val. +//! +//! @b Example: +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("{\"a\": 1, \"b\": 2}"); +//! octave_value struct = decode_object (d, octave_value_list ()); +//! @endcode + +octave_value +decode_object (const rapidjson::Value& val, const octave_value_list& options) +{ + octave_scalar_map retval; + + // Validator function to guarantee legitimate variable name. + std::string fcn_name = "matlab.lang.makeValidName"; + + for (const auto& pair : val.GetObject ()) + { + octave_value_list args = octave_value_list (pair.name.GetString ()); + args.append (options); + std::string validName = octave::feval (fcn_name,args)(0).string_value (); + retval.assign (validName, decode (pair.value, options)); + } + + return retval; +} + +//! Decodes a JSON array that contains only numerical or null values +//! into an NDArray. +//! +//! @param val JSON value that is guaranteed to be a numeric array. +//! +//! @return @ref octave_value that contains the equivalent NDArray of @p val. +//! +//! @b Example: +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[1, 2, 3, 4]"); +//! octave_value numeric_array = decode_numeric_array (d); +//! @endcode + +octave_value +decode_numeric_array (const rapidjson::Value& val) +{ + NDArray retval (dim_vector (val.Size (), 1)); + octave_idx_type index = 0; + for (const auto& elem : val.GetArray ()) + retval(index++) = elem.IsNull () ? octave_NaN + : decode_number (elem).double_value (); + return retval; +} + +//! Decodes a JSON array that contains only boolean values into a boolNDArray. +//! +//! @param val JSON value that is guaranteed to be a boolean array. +//! +//! @return @ref octave_value that contains the equivalent boolNDArray of @p val. +//! +//! @b Example: +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[true, false, true]"); +//! octave_value boolean_array = decode_boolean_array (d); +//! @endcode + +octave_value +decode_boolean_array (const rapidjson::Value& val) +{ + boolNDArray retval (dim_vector (val.Size (), 1)); + octave_idx_type index = 0; + for (const auto& elem : val.GetArray ()) + retval(index++) = elem.GetBool (); + return retval; +} + +//! Decodes a JSON array that contains different types +//! or string values only into a Cell. +//! +//! @param val JSON value that is guaranteed to be a mixed or string array. +//! @param options @c ReplacementStyle and @c Prefix options with their values. +//! +//! @return @ref octave_value that contains the equivalent Cell of @p val. +//! +//! @b Example (decoding a string array): +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[\"foo\", \"bar\", \"baz\"]"); +//! octave_value cell = decode_string_and_mixed_array (d, octave_value_list ()); +//! @endcode +//! +//! @b Example (decoding a mixed array): +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[\"foo\", 123, true]"); +//! octave_value cell = decode_string_and_mixed_array (d, octave_value_list ()); +//! @endcode + +octave_value +decode_string_and_mixed_array (const rapidjson::Value& val, + const octave_value_list& options) +{ + Cell retval (dim_vector (val.Size (), 1)); + octave_idx_type index = 0; + for (const auto& elem : val.GetArray ()) + retval(index++) = decode (elem, options); + return retval; +} + +//! Decodes a JSON array that contains only objects into a Cell or struct array +//! depending on the similarity of the objects' keys. +//! +//! @param val JSON value that is guaranteed to be an object array. +//! @param options @c ReplacementStyle and @c Prefix options with their values. +//! +//! @return @ref octave_value that contains the equivalent Cell +//! or struct array of @p val. +//! +//! @b Example (returns a struct array): +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[{\"a\":1,\"b\":2},{\"a\":3,\"b\":4}]"); +//! octave_value object_array = decode_object_array (d, octave_value_list ()); +//! @endcode +//! +//! @b Example (returns a Cell): +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[{\"a\":1,\"b\":2},{\"b\":3,\"a\":4}]"); +//! octave_value object_array = decode_object_array (d, octave_value_list ()); +//! @endcode + +octave_value +decode_object_array (const rapidjson::Value& val, + const octave_value_list& options) +{ + Cell struct_cell = decode_string_and_mixed_array (val, options).cell_value (); + string_vector field_names = struct_cell(0).scalar_map_value ().fieldnames (); + + bool same_field_names = true; + for (octave_idx_type i = 1; i < struct_cell.numel (); ++i) + if (field_names.std_list () + != struct_cell(i).scalar_map_value ().fieldnames ().std_list ()) + { + same_field_names = false; + break; + } + + if (same_field_names) + { + octave_map struct_array; + Cell value (dim_vector (struct_cell.numel (), 1)); + for (octave_idx_type i = 0; i < field_names.numel (); ++i) + { + for (octave_idx_type k = 0; k < struct_cell.numel (); ++k) + value(k) = struct_cell(k).scalar_map_value ().getfield (field_names(i)); + struct_array.assign (field_names(i), value); + } + return struct_array; + } + else + return struct_cell; +} + +//! Decodes a JSON array that contains only arrays into a Cell or an NDArray +//! depending on the dimensions and element types of the sub-arrays. +//! +//! @param val JSON value that is guaranteed to be an array of arrays. +//! @param options @c ReplacementStyle and @c Prefix options with their values. +//! +//! @return @ref octave_value that contains the equivalent Cell +//! or NDArray of @p val. +//! +//! @b Example (returns an NDArray): +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[[1, 2], [3, 4]]"); +//! octave_value array = decode_array_of_arrays (d, octave_value_list ()); +//! @endcode +//! +//! @b Example (returns a Cell): +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[[1, 2], [3, 4, 5]]"); +//! octave_value cell = decode_array_of_arrays (d, octave_value_list ()); +//! @endcode + +octave_value +decode_array_of_arrays (const rapidjson::Value& val, + const octave_value_list& options) +{ + // Some arrays should be decoded as NDArrays and others as cell arrays + Cell cell = decode_string_and_mixed_array (val, options).cell_value (); + + // Only arrays with sub-arrays of booleans and numericals will return NDArray + bool is_bool = cell(0).is_bool_matrix (); + dim_vector sub_array_dims = cell(0).dims (); + octave_idx_type sub_array_ndims = cell(0).ndims (); + octave_idx_type cell_numel = cell.numel (); + for (octave_idx_type i = 0; i < cell_numel; ++i) + { + // If one element is cell return the cell array as at least one of the + // sub-arrays area either an array of: strings, objects or mixed array + if (cell(i).iscell ()) + return cell; + // If not the same dim of elements or dim = 0, return cell array + if (cell(i).dims () != sub_array_dims || sub_array_dims == dim_vector ()) + return cell; + // If not numeric sub-arrays only or bool sub-arrays only, + // return cell array + if (cell(i).is_bool_matrix () != is_bool) + return cell; + } + + // Calculate the dims of the output array + dim_vector array_dims; + array_dims.resize (sub_array_ndims + 1); + array_dims(0) = cell_numel; + for (auto i = 1; i < sub_array_ndims + 1; i++) + array_dims(i) = sub_array_dims(i-1); + NDArray array (array_dims); + + // Populate the array with specific order to generate MATLAB-identical output + octave_idx_type array_index = 0; + for (octave_idx_type i = 0; i < array.numel () / cell_numel; ++i) + for (octave_idx_type k = 0; k < cell_numel; ++k) + array(array_index++) = cell(k).array_value ()(i); + + if (is_bool) + return boolNDArray (array); + else + return array; +} + +//! Decodes any type of JSON arrays. This function only serves as an interface +//! by choosing which function to call from the previous functions. +//! +//! @param val JSON value that is guaranteed to be an array. +//! @param options @c ReplacementStyle and @c Prefix options with their values. +//! +//! @return @ref octave_value that contains the output of decoding @p val. +//! +//! @b Example: +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[[1, 2], [3, 4, 5]]"); +//! octave_value array = decode_array (d, octave_value_list ()); +//! @endcode + +octave_value +decode_array (const rapidjson::Value& val, const octave_value_list& options) +{ + // Handle empty arrays + if (val.Empty ()) + return NDArray (); + + // Compare with other elements to know if the array has multiple types + rapidjson::Type array_type = val[0].GetType (); + // Check if the array is numeric and if it has multiple types + bool same_type = true; + bool is_numeric = true; + for (const auto& elem : val.GetArray ()) + { + rapidjson::Type current_elem_type = elem.GetType (); + if (is_numeric && ! (current_elem_type == rapidjson::kNullType + || current_elem_type == rapidjson::kNumberType)) + is_numeric = false; + if (same_type && (current_elem_type != array_type)) + // RapidJSON doesn't have kBoolean Type it has kTrueType and kFalseType + if (! ((current_elem_type == rapidjson::kTrueType + && array_type == rapidjson::kFalseType) + || (current_elem_type == rapidjson::kFalseType + && array_type == rapidjson::kTrueType))) + same_type = false; + } + + if (is_numeric) + return decode_numeric_array (val); + + if (same_type && (array_type != rapidjson::kStringType)) + { + if (array_type == rapidjson::kTrueType + || array_type == rapidjson::kFalseType) + return decode_boolean_array (val); + else if (array_type == rapidjson::kObjectType) + return decode_object_array (val, options); + else if (array_type == rapidjson::kArrayType) + return decode_array_of_arrays (val, options); + else + error ("jsondecode: unidentified type"); + } + else + return decode_string_and_mixed_array (val, options); +} + +//! Decodes any JSON value. This function only serves as an interface +//! by choosing which function to call from the previous functions. +//! +//! @param val JSON value. +//! @param options @c ReplacementStyle and @c Prefix options with their values. +//! +//! @return @ref octave_value that contains the output of decoding @p val. +//! +//! @b Example: +//! +//! @code{.cc} +//! rapidjson::Document d; +//! d.Parse ("[{\"a\":1,\"b\":2},{\"b\":3,\"a\":4}]"); +//! octave_value value = decode (d, octave_value_list ()); +//! @endcode + +octave_value +decode (const rapidjson::Value& val, const octave_value_list& options) +{ + if (val.IsBool ()) + return val.GetBool (); + else if (val.IsNumber ()) + return decode_number (val); + else if (val.IsString ()) + return val.GetString (); + else if (val.IsObject ()) + return decode_object (val, options); + else if (val.IsNull ()) + return NDArray (); + else if (val.IsArray ()) + return decode_array (val, options); + else + error ("jsondecode: unidentified type"); +} + +#endif + +DEFUN (jsondecode, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {@var{object} =} jsondecode (@var{JSON_txt}) +@deftypefnx {} {@var{object} =} jsondecode (@dots{}, "ReplacementStyle", @var{rs}) +@deftypefnx {} {@var{object} =} jsondecode (@dots{}, "Prefix", @var{pfx}) + +Decode text that is formatted in JSON. + +The input @var{JSON_txt} is a string that contains JSON text. + +The output @var{object} is an Octave object that contains the result of +decoding @var{JSON_txt}. + +For more information about the options @qcode{"ReplacementStyle"} and +@qcode{"Prefix"}, see +@ref{XREFmatlab_lang_makeValidName,,matlab.lang.makeValidName}. + +NOTE: Decoding and encoding JSON text is not guaranteed to reproduce the +original text as some names may be changed by @code{matlab.lang.makeValidName}. + +This table shows the conversions from JSON data types to Octave data types: + +@multitable @columnfractions 0.50 0.50 +@headitem JSON data type @tab Octave data type +@item Boolean @tab scalar logical +@item Number @tab scalar double +@item String @tab vector of characters +@item Object @tab scalar struct (field names of the struct may be different from the keys of the JSON object due to @code{matlab_lang_makeValidName} +@item null, inside a numeric array @tab @code{NaN} +@item null, inside a non-numeric array @tab empty double array @code{[]} +@item Array, of different data types @tab cell array +@item Array, of Booleans @tab logical array +@item Array, of Numbers @tab double array +@item Array, of Strings @tab cell array of character vectors (@code{cellstr}) +@item Array of Objects, same field names @tab struct array +@item Array of Objects, different field names @tab cell array of scalar structs +@end multitable + +Examples: + +@example +@group +jsondecode ('[1, 2, null, 3]') + @result{} ans = + + 1 + 2 + NaN + 3 +@end group + +@group +jsondecode ('["foo", "bar", ["foo", "bar"]]') + @result{} ans = + @{ + [1,1] = foo + [2,1] = bar + [3,1] = + @{ + [1,1] = foo + [2,1] = bar + @} + + @} +@end group + +@group +jsondecode ('@{"nu#m#ber": 7, "s#tr#ing": "hi"@}', ... + 'ReplacementStyle', 'delete') + @result{} scalar structure containing the fields: + + number = 7 + string = hi +@end group + +@group +jsondecode ('@{"1": "one", "2": "two"@}', 'Prefix', 'm_') + @result{} scalar structure containing the fields: + + m_1 = one + m_2 = two +@end group +@end example + +@seealso{jsonencode, matlab.lang.makeValidName} +@end deftypefn */) +{ +#if defined (HAVE_RAPIDJSON) + + int nargin = args.length (); + + // makeValidName options are pairs, the number of arguments must be odd. + if (! (nargin % 2)) + print_usage (); + + if (! args(0).is_string ()) + error ("jsondecode: JSON_TXT must be a character string"); + + std::string json = args(0).string_value (); + rapidjson::Document d; + // DOM is chosen instead of SAX as SAX publishes events to a handler that + // decides what to do depending on the event only. This will cause a + // problem in decoding JSON arrays as the output may be an array or a cell + // and that doesn't only depend on the event (startArray) but also on the + // types of the elements inside the array. + d.Parse (json.c_str ()); + + if (d.HasParseError ()) + error ("jsondecode: parse error at offset %u: %s\n", + static_cast (d.GetErrorOffset ()) + 1, + rapidjson::GetParseError_En (d.GetParseError ())); + + return decode (d, args.slice (1, nargin - 1)); + +#else + + octave_unused_parameter (args); + + err_disabled_feature ("jsondecode", "JSON decoding through RapidJSON"); + +#endif +} + +/* +Functional BIST tests are located in test/json/jsondecode_BIST.tst + +## Input validation tests +%!testif HAVE_RAPIDJSON +%! fail ("jsondecode ()"); +%! fail ("jsondecode ('1', 2)"); +%! fail ("jsondecode (1)", "JSON_TXT must be a character string"); +%! fail ("jsondecode ('12-')", "parse error at offset 3"); + +*/ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/jsonencode.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/jsonencode.cc Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,668 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "builtin-defun-decls.h" +#include "defun.h" +#include "error.h" +#include "errwarn.h" +#include "oct-string.h" +#include "ovl.h" + +#if defined (HAVE_RAPIDJSON) +# include +# include +# if defined (HAVE_RAPIDJSON_PRETTYWRITER) +# include +# endif +#endif + +#if defined (HAVE_RAPIDJSON) + +//! Encodes a scalar Octave value into a numerical JSON value. +//! +//! @param writer RapidJSON's writer that is responsible for generating JSON. +//! @param obj scalar Octave value. +//! @param ConvertInfAndNaN @c bool that converts @c Inf and @c NaN to @c null. +//! +//! @b Example: +//! +//! @code{.cc} +//! octave_value obj (7); +//! encode_numeric (writer, obj, true); +//! @endcode + +template void +encode_numeric (T& writer, const octave_value& obj, + const bool& ConvertInfAndNaN) +{ + double value = obj.scalar_value (); + + if (obj.is_bool_scalar ()) + writer.Bool (obj.bool_value ()); + // Any numeric input from the interpreter will be in double type so in order + // to detect ints, we will check if the floor of the input and the input are + // equal using fabs (A - B) < epsilon method as it is more accurate. + // If value > 999999, MATLAB will encode it in scientific notation (double) + else if (fabs (floor (value) - value) < std::numeric_limits::epsilon () + && value <= 999999 && value >= -999999) + writer.Int64 (value); + // Possibly write NULL for non-finite values (-Inf, Inf, NaN, NA) + else if (ConvertInfAndNaN && ! octave::math::isfinite (value)) + writer.Null (); + else if (obj.is_double_type ()) + writer.Double (value); + else + error ("jsonencode: unsupported type"); +} + +//! Encodes character vectors and arrays into JSON strings. +//! +//! @param writer RapidJSON's writer that is responsible for generating JSON. +//! @param obj character vectors or character arrays. +//! @param original_dims The original dimensions of the array being encoded. +//! @param level The level of recursion for the function. +//! +//! @b Example: +//! +//! @code{.cc} +//! octave_value obj ("foo"); +//! encode_string (writer, obj, true); +//! @endcode + +template void +encode_string (T& writer, const octave_value& obj, + const dim_vector& original_dims, int level = 0) +{ + charNDArray array = obj.char_array_value (); + + if (array.isempty ()) + writer.String (""); + else if (array.isvector ()) + { + // Handle the special case where the input is a vector with more than + // 2 dimensions (e.g. cat (8, ['a'], ['c'])). In this case, we don't + // split the inner vectors of the input; we merge them into one. + if (level == 0) + { + std::string char_vector = ""; + for (octave_idx_type i = 0; i < array.numel (); ++i) + char_vector += array(i); + writer.String (char_vector.c_str ()); + } + else + for (octave_idx_type i = 0; i < array.numel () / original_dims(1); ++i) + { + std::string char_vector = ""; + for (octave_idx_type k = 0; k < original_dims(1); ++k) + char_vector += array(i * original_dims(1) + k); + writer.String (char_vector.c_str ()); + } + } + else + { + octave_idx_type idx; + octave_idx_type ndims = array.ndims (); + dim_vector dims = array.dims (); + + // In this case, we already have a vector. So, we transform it to 2-D + // vector in order to be detected by "isvector" in the recursive call + if (dims.num_ones () == ndims - 1) + { + // Handle the special case when the input is a vector with more than + // 2 dimensions (e.g. cat (8, ['a'], ['c'])). In this case, we don't + // add dimension brackets and treat it as if it is a vector + if (level != 0) + // Place an opening and a closing bracket (represents a dimension) + // for every dimension that equals 1 until we reach the 2-D vector + for (int i = level; i < ndims - 1; ++i) + writer.StartArray (); + + encode_string (writer, array.as_row (), original_dims, level); + + if (level != 0) + for (int i = level; i < ndims - 1; ++i) + writer.EndArray (); + } + else + { + // We place an opening and a closing bracket for each dimension + // that equals 1 to preserve the number of dimensions when decoding + // the array after encoding it. + if (original_dims(level) == 1 && level != 1) + { + writer.StartArray (); + encode_string (writer, array, original_dims, level + 1); + writer.EndArray (); + } + else + { + // The second dimension contains the number of the chars in + // the char vector. We want to treat them as a one object, + // so we replace it with 1 + dims(1) = 1; + + for (idx = 0; idx < ndims; ++idx) + if (dims(idx) != 1) + break; + // Create the dimensions that will be used to call "num2cell" + // We called "num2cell" to divide the array to smaller sub-arrays + // in order to encode it recursively. + // The recursive encoding is necessary to support encoding of + // higher-dimensional arrays. + RowVector conversion_dims; + conversion_dims.resize (ndims - 1); + for (octave_idx_type i = 0; i < idx; ++i) + conversion_dims(i) = i + 1; + for (octave_idx_type i = idx ; i < ndims - 1; ++i) + conversion_dims(i) = i + 2; + + octave_value_list args (obj); + args.append (conversion_dims); + + Cell sub_arrays = Fnum2cell (args)(0).cell_value (); + + writer.StartArray (); + + for (octave_idx_type i = 0; i < sub_arrays.numel (); ++i) + encode_string (writer, sub_arrays(i), original_dims, + level + 1); + + writer.EndArray (); + } + } + } +} + +//! Encodes a struct Octave value into a JSON object or a JSON array depending +//! on the type of the struct (scalar struct or struct array.) +//! +//! @param writer RapidJSON's writer that is responsible for generating JSON. +//! @param obj struct Octave value. +//! @param ConvertInfAndNaN @c bool that converts @c Inf and @c NaN to @c null. +//! +//! @b Example: +//! +//! @code{.cc} +//! octave_value obj (octave_map ()); +//! encode_struct (writer, obj,true); +//! @endcode + +template void +encode_struct (T& writer, const octave_value& obj, const bool& ConvertInfAndNaN) +{ + octave_map struct_array = obj.map_value (); + octave_idx_type numel = struct_array.numel (); + bool is_array = (numel > 1); + string_vector keys = struct_array.keys (); + + if (is_array) + writer.StartArray (); + + for (octave_idx_type i = 0; i < numel; ++i) + { + writer.StartObject (); + for (octave_idx_type k = 0; k < keys.numel (); ++k) + { + writer.Key (keys(k).c_str ()); + encode (writer, struct_array(i).getfield (keys(k)), ConvertInfAndNaN); + } + writer.EndObject (); + } + + if (is_array) + writer.EndArray (); +} + +//! Encodes a Cell Octave value into a JSON array +//! +//! @param writer RapidJSON's writer that is responsible for generating JSON. +//! @param obj Cell Octave value. +//! @param ConvertInfAndNaN @c bool that converts @c Inf and @c NaN to @c null. +//! +//! @b Example: +//! +//! @code{.cc} +//! octave_value obj (cell ()); +//! encode_cell (writer, obj,true); +//! @endcode + +template void +encode_cell (T& writer, const octave_value& obj, const bool& ConvertInfAndNaN) +{ + Cell cell = obj.cell_value (); + + writer.StartArray (); + + for (octave_idx_type i = 0; i < cell.numel (); ++i) + encode (writer, cell(i), ConvertInfAndNaN); + + writer.EndArray (); +} + +//! Encodes a numeric or logical Octave array into a JSON array +//! +//! @param writer RapidJSON's writer that is responsible for generating JSON. +//! @param obj numeric or logical Octave array. +//! @param ConvertInfAndNaN @c bool that converts @c Inf and @c NaN to @c null. +//! @param original_dims The original dimensions of the array being encoded. +//! @param level The level of recursion for the function. +//! @param is_logical optional @c bool that indicates if the array is logical. +//! +//! @b Example: +//! +//! @code{.cc} +//! octave_value obj (NDArray ()); +//! encode_array (writer, obj,true); +//! @endcode + +template void +encode_array (T& writer, const octave_value& obj, const bool& ConvertInfAndNaN, + const dim_vector& original_dims, int level = 0, + bool is_logical = false) +{ + NDArray array = obj.array_value (); + // is_logical is assigned at level 0. I think this is better than changing + // many places in the code, and it makes the function more modular. + if (level == 0) + is_logical = obj.islogical (); + + if (array.isempty ()) + { + writer.StartArray (); + writer.EndArray (); + } + else if (array.isvector ()) + { + writer.StartArray (); + for (octave_idx_type i = 0; i < array.numel (); ++i) + { + if (is_logical) + encode_numeric (writer, bool (array(i)), ConvertInfAndNaN); + else + encode_numeric (writer, array(i), ConvertInfAndNaN); + } + writer.EndArray (); + } + else + { + octave_idx_type idx; + octave_idx_type ndims = array.ndims (); + dim_vector dims = array.dims (); + + // In this case, we already have a vector. So, we transform it to 2-D + // vector in order to be detected by "isvector" in the recursive call + if (dims.num_ones () == ndims - 1) + { + // Handle the special case when the input is a vector with more than + // 2 dimensions (e.g. ones ([1 1 1 1 1 6])). In this case, we don't + // add dimension brackets and treat it as if it is a vector + if (level != 0) + // Place an opening and a closing bracket (represents a dimension) + // for every dimension that equals 1 till we reach the 2-D vector + for (int i = level; i < ndims - 1; ++i) + writer.StartArray (); + + encode_array (writer, array.as_row (), ConvertInfAndNaN, + original_dims, level + 1, is_logical); + + if (level != 0) + for (int i = level; i < ndims - 1; ++i) + writer.EndArray (); + } + else + { + // We place an opening and a closing bracket for each dimension + // that equals 1 to preserve the number of dimensions when decoding + // the array after encoding it. + if (original_dims (level) == 1) + { + writer.StartArray (); + encode_array (writer, array, ConvertInfAndNaN, + original_dims, level + 1, is_logical); + writer.EndArray (); + } + else + { + for (idx = 0; idx < ndims; ++idx) + if (dims(idx) != 1) + break; + + // Create the dimensions that will be used to call "num2cell" + // We called "num2cell" to divide the array to smaller sub-arrays + // in order to encode it recursively. + // The recursive encoding is necessary to support encoding of + // higher-dimensional arrays. + RowVector conversion_dims; + conversion_dims.resize (ndims - 1); + for (octave_idx_type i = 0; i < idx; ++i) + conversion_dims(i) = i + 1; + for (octave_idx_type i = idx ; i < ndims - 1; ++i) + conversion_dims(i) = i + 2; + + octave_value_list args (obj); + args.append (conversion_dims); + + Cell sub_arrays = Fnum2cell (args)(0).cell_value (); + + writer.StartArray (); + + for (octave_idx_type i = 0; i < sub_arrays.numel (); ++i) + encode_array (writer, sub_arrays(i), ConvertInfAndNaN, + original_dims, level + 1, is_logical); + + writer.EndArray (); + } + } + } +} + +//! Encodes any Octave object. This function only serves as an interface +//! by choosing which function to call from the previous functions. +//! +//! @param writer RapidJSON's writer that is responsible for generating JSON. +//! @param obj any @ref octave_value that is supported. +//! @param ConvertInfAndNaN @c bool that converts @c Inf and @c NaN to @c null. +//! +//! @b Example: +//! +//! @code{.cc} +//! octave_value obj (true); +//! encode (writer, obj,true); +//! @endcode + +template void +encode (T& writer, const octave_value& obj, const bool& ConvertInfAndNaN) +{ + if (obj.is_real_scalar ()) + encode_numeric (writer, obj, ConvertInfAndNaN); + // As I checked for scalars, this will detect numeric & logical arrays + else if (obj.isnumeric () || obj.islogical ()) + encode_array (writer, obj, ConvertInfAndNaN, obj.dims ()); + else if (obj.is_string ()) + encode_string (writer, obj, obj.dims ()); + else if (obj.isstruct ()) + encode_struct (writer, obj, ConvertInfAndNaN); + else if (obj.iscell ()) + encode_cell (writer, obj, ConvertInfAndNaN); + else if (obj.class_name () == "containers.Map") + // To extract the data in containers.Map, convert it to a struct. + // The struct will have a "map" field whose value is a struct that + // contains the desired data. + // To avoid warnings due to that conversion, disable the + // "Octave:classdef-to-struct" warning and re-enable it. + { + octave::unwind_action restore_warning_state + ([] (const octave_value_list& old_warning_state) + { + set_warning_state (old_warning_state); + }, set_warning_state ("Octave:classdef-to-struct", "off")); + + encode_struct (writer, obj.scalar_map_value ().getfield ("map"), + ConvertInfAndNaN); + } + else if (obj.isobject ()) + { + octave::unwind_action restore_warning_state + ([] (const octave_value_list& old_warning_state) + { + set_warning_state (old_warning_state); + }, set_warning_state ("Octave:classdef-to-struct", "off")); + + encode_struct (writer, obj.scalar_map_value (), ConvertInfAndNaN); + } + else + error ("jsonencode: unsupported type"); +} + +#endif + +DEFUN (jsonencode, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {@var{JSON_txt} =} jsonencode (@var{object}) +@deftypefnx {} {@var{JSON_txt} =} jsonencode (@dots{}, "ConvertInfAndNaN", @var{TF}) +@deftypefnx {} {@var{JSON_txt} =} jsonencode (@dots{}, "PrettyWriter", @var{TF}) + +Encode Octave data types into JSON text. + +The input @var{object} is an Octave variable to encode. + +The output @var{JSON_txt} is the JSON text that contains the result of encoding +@var{object}. + +If the value of the option @qcode{"ConvertInfAndNaN"} is true then @code{NaN}, +@code{NA}, @code{-Inf}, and @code{Inf} values will be converted to +@qcode{"null"} in the output. If it is false then they will remain as their +original values. The default value for this option is true. + +If the value of the option @qcode{"PrettyWriter"} is true, the output text will +have indentations and line feeds. If it is false, the output will be condensed +and written without whitespace. The default value for this option is false. + +Programming Notes: + +@itemize @bullet +@item +Complex numbers are not supported. + +@item +classdef objects are first converted to structs and then encoded. + +@item +To preserve escape characters (e.g., @qcode{"\n"}), use single-quoted strings. + +@item +Every character after the null character (@qcode{"\0"}) in a double-quoted +string will be dropped during encoding. + +@item +Encoding and decoding an array is not guaranteed to preserve the dimensions +of the array. In particular, row vectors will be reshaped to column vectors. + +@item +Encoding and decoding is not guaranteed to preserve the Octave data type +because JSON supports fewer data types than Octave. For example, if you +encode an @code{int8} and then decode it, you will get a @code{double}. +@end itemize + +This table shows the conversions from Octave data types to JSON data types: + +@multitable @columnfractions 0.50 0.50 +@headitem Octave data type @tab JSON data type +@item logical scalar @tab Boolean +@item logical vector @tab Array of Boolean, reshaped to row vector +@item logical array @tab nested Array of Boolean +@item numeric scalar @tab Number +@item numeric vector @tab Array of Number, reshaped to row vector +@item numeric array @tab nested Array of Number +@item @code{NaN}, @code{NA}, @code{Inf}, @code{-Inf}@* +when @qcode{"ConvertInfAndNaN" = true} @tab @qcode{"null"} +@item @code{NaN}, @code{NA}, @code{Inf}, @code{-Inf}@* +when @qcode{"ConvertInfAndNaN" = false} @tab @qcode{"NaN"}, @qcode{"NaN"}, +@qcode{"Infinity"}, @qcode{"-Infinity"} +@item empty array @tab @qcode{"[]"} +@item character vector @tab String +@item character array @tab Array of String +@item empty character array @tab @qcode{""} +@item cell scalar @tab Array +@item cell vector @tab Array, reshaped to row vector +@item cell array @tab Array, flattened to row vector +@item struct scalar @tab Object +@item struct vector @tab Array of Object, reshaped to row vector +@item struct array @tab nested Array of Object +@item classdef object @tab Object +@end multitable + +Examples: + +@example +@group +jsonencode ([1, NaN; 3, 4]) +@result{} [[1,null],[3,4]] +@end group + +@group +jsonencode ([1, NaN; 3, 4], "ConvertInfAndNaN", false) +@result{} [[1,NaN],[3,4]] +@end group + +@group +## Escape characters inside a single-quoted string +jsonencode ('\0\a\b\t\n\v\f\r') +@result{} "\\0\\a\\b\\t\\n\\v\\f\\r" +@end group + +@group +## Escape characters inside a double-quoted string +jsonencode ("\a\b\t\n\v\f\r") +@result{} "\u0007\b\t\n\u000B\f\r" +@end group + +@group +jsonencode ([true; false], "PrettyWriter", true) +@result{} ans = [ + true, + false + ] +@end group + +@group +jsonencode (['foo', 'bar'; 'foo', 'bar']) +@result{} ["foobar","foobar"] +@end group + +@group +jsonencode (struct ('a', Inf, 'b', [], 'c', struct ())) +@result{} @{"a":null,"b":[],"c":@{@}@} +@end group + +@group +jsonencode (struct ('structarray', struct ('a', @{1; 3@}, 'b', @{2; 4@}))) +@result{} @{"structarray":[@{"a":1,"b":2@},@{"a":3,"b":4@}]@} +@end group + +@group +jsonencode (@{'foo'; 'bar'; @{'foo'; 'bar'@}@}) +@result{} ["foo","bar",["foo","bar"]] +@end group + +@group +jsonencode (containers.Map(@{'foo'; 'bar'; 'baz'@}, [1, 2, 3])) +@result{} @{"bar":2,"baz":3,"foo":1@} +@end group +@end example + +@seealso{jsondecode} +@end deftypefn */) +{ +#if defined (HAVE_RAPIDJSON) + + int nargin = args.length (); + // jsonencode has two options 'ConvertInfAndNaN' and 'PrettyWriter' + if (nargin != 1 && nargin != 3 && nargin != 5) + print_usage (); + + // Initialize options with their default values + bool ConvertInfAndNaN = true; + bool PrettyWriter = false; + + for (octave_idx_type i = 1; i < nargin; ++i) + { + if (! args(i).is_string ()) + error ("jsonencode: option must be a string"); + if (! args(i+1).is_bool_scalar ()) + error ("jsonencode: option value must be a logical scalar"); + + std::string option_name = args(i++).string_value (); + if (octave::string::strcmpi (option_name, "ConvertInfAndNaN")) + ConvertInfAndNaN = args(i).bool_value (); + else if (octave::string::strcmpi (option_name, "PrettyWriter")) + PrettyWriter = args(i).bool_value (); + else + error ("jsonencode: " + R"(Valid options are "ConvertInfAndNaN" and "PrettyWriter")"); + } + +# if ! defined (HAVE_RAPIDJSON_PRETTYWRITER) + if (PrettyWriter) + { + warn_disabled_feature ("jsonencode", + R"(the "PrettyWriter" option of RapidJSON)"); + PrettyWriter = false; + } +# endif + + rapidjson::StringBuffer json; + if (PrettyWriter) + { +# if defined (HAVE_RAPIDJSON_PRETTYWRITER) + rapidjson::PrettyWriter, + rapidjson::UTF8<>, rapidjson::CrtAllocator, + rapidjson::kWriteNanAndInfFlag> writer (json); + encode (writer, args(0), ConvertInfAndNaN); +# endif + } + else + { + rapidjson::Writer, + rapidjson::UTF8<>, rapidjson::CrtAllocator, + rapidjson::kWriteNanAndInfFlag> writer (json); + encode (writer, args(0), ConvertInfAndNaN); + } + + return octave_value (json.GetString ()); + +#else + + octave_unused_parameter (args); + + err_disabled_feature ("jsonencode", "JSON encoding through RapidJSON"); + +#endif +} + +/* +Functional BIST tests are located in test/json/jsonencode_BIST.tst + +## Input validation tests +%!testif HAVE_RAPIDJSON +%! fail ("jsonencode ()"); +%! fail ("jsonencode (1, 2)"); +%! fail ("jsonencode (1, 2, 3, 4)"); +%! fail ("jsonencode (1, 2, 3, 4, 5, 6)"); +%! fail ("jsonencode (1, 2, true)", "option must be a string"); +%! fail ("jsonencode (1, 'string', ones (2,2))", ... +%! "option value must be a logical scalar"); +%! fail ("jsonencode (1, 'foobar', true)", ... +%! 'Valid options are "ConvertInfAndNaN"'); + +%!testif HAVE_RAPIDJSON; ! __have_feature__ ("RAPIDJSON_PRETTYWRITER") +%! fail ("jsonencode (1, 'PrettyWriter', true)", ... +%! "warning", 'the "PrettyWriter" option of RapidJSON was unavailable'); + +*/ diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/kron.cc --- a/libinterp/corefcn/kron.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/kron.cc Thu Nov 19 13:08:00 2020 -0800 @@ -310,7 +310,7 @@ %!assert (kron (single (1:4), ones (3, 1)), single (z)) %!assert (kron (sparse (1:4), ones (3, 1)), sparse (z)) %!assert (kron (complex (1:4), ones (3, 1)), z) -%!assert (kron (complex (single(1:4)), ones (3, 1)), single(z)) +%!assert (kron (complex (single (1:4)), ones (3, 1)), single (z)) %!assert (kron (x, y, z), kron (kron (x, y), z)) %!assert (kron (x, y, z), kron (x, kron (y, z))) %!assert (kron (p1, p1), kron (p2, p2)) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/load-path.cc --- a/libinterp/corefcn/load-path.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/load-path.cc Thu Nov 19 13:08:00 2020 -0800 @@ -28,6 +28,7 @@ #endif #include +#include #include "dir-ops.h" #include "file-ops.h" @@ -56,9 +57,9 @@ static std::string maybe_canonicalize (const std::string& dir_arg) { - bool is_absolute_path = octave::sys::env::absolute_pathname (dir_arg); - - std::string canonical_dir = octave::sys::canonicalize_file_name (dir_arg); + bool is_absolute_path = sys::env::absolute_pathname (dir_arg); + + std::string canonical_dir = sys::canonicalize_file_name (dir_arg); std::string dir; if (canonical_dir.empty ()) dir = dir_arg; @@ -70,7 +71,7 @@ { // Remove current path from absolute path generated by // canonicalize_file_name. - std::string cwd = octave::sys::canonicalize_file_name ("."); + std::string cwd = sys::canonicalize_file_name ("."); if (dir.compare (0, cwd.length (), cwd) == 0) dir.erase (0, cwd.length ()+1); if (dir.empty ()) @@ -230,8 +231,8 @@ load_path::load_path (interpreter& interp) : m_interpreter (interp), package_map (), top_level_package (), dir_info_list (), init_dirs (), m_command_line_path (), - add_hook ([this] (const std::string& dir) { this->execute_pkg_add (dir); }), - remove_hook ([this] (const std::string& dir) { this->execute_pkg_del (dir); }) + add_hook ([=] (const std::string& dir) { this->execute_pkg_add (dir); }), + remove_hook ([=] (const std::string& dir) { this->execute_pkg_del (dir); }) { } void @@ -963,8 +964,6 @@ if (! octave_interpreter_ready) return; - unwind_protect frame; - std::string file = sys::file_ops::concat (dir, script_file); sys::file_stat fs (file); @@ -1086,6 +1085,8 @@ { if (fs.is_dir ()) { + read_dir_config (dir); + dir_info di (dir); if (at_end) @@ -1136,6 +1137,78 @@ } } + void + load_path::read_dir_config (const std::string& dir) const + { + // read file with directory configuration + std::string conf_file = dir + sys::file_ops::dir_sep_str () + + ".oct-config"; + + FILE* cfile = sys::fopen (conf_file, "rb"); + + if (! cfile) + { + // reset directory encoding + input_system& input_sys + = __get_input_system__ ("load_path::read_dir_config"); + + std::string enc_val = "delete"; + input_sys.set_dir_encoding (dir, enc_val); + return; + } + + unwind_action close_file ([cfile] (void) { fclose (cfile); }); + + // find line with character encoding and read it + bool eof = false; + const std::string enc_prop = "encoding"; + while (! eof) + { + std::string conf_str = octave_fgets (cfile, eof); + + // delete any preceeding whitespace + auto it = std::find_if_not (conf_str.begin (), conf_str.end (), + [] (unsigned char c) + { return std::isblank (c); }); + conf_str.erase (conf_str.begin (), it); + + // match identifier + if (conf_str.compare (0, enc_prop.size (), enc_prop) == 0) + { + // skip delimiter characters + size_t pos = conf_str.find_first_not_of (" \t=:", + enc_prop.size ()); + if (pos == std::string::npos) + continue; + + std::string enc_val = conf_str.substr (pos); + + // take alphanumeric and '-' characters + it = std::find_if_not (enc_val.begin (), enc_val.end (), + [] (unsigned char c) + { return std::isalnum (c) || c == '-'; }); + enc_val.erase(it, enc_val.end ()); + + if (enc_val.empty ()) + continue; + + // set encoding for this directory in input system + input_system& input_sys + = __get_input_system__ ("load_path::read_dir_config"); + input_sys.set_dir_encoding (dir, enc_val); + return; + } + } + + // reset directory encoding + input_system& input_sys + = __get_input_system__ ("load_path::read_dir_config"); + + std::string enc_val = "delete"; + input_sys.set_dir_encoding (dir, enc_val); + + } + bool load_path::is_package (const std::string& name) const { diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/load-path.h --- a/libinterp/corefcn/load-path.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/load-path.h Thu Nov 19 13:08:00 2020 -0800 @@ -191,6 +191,8 @@ remove_hook = f; } + void read_dir_config (const std::string& dir) const; + void execute_pkg_add (const std::string& dir); void execute_pkg_del (const std::string& dir); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/load-save.cc Thu Nov 19 13:08:00 2020 -0800 @@ -645,6 +645,10 @@ warning (R"(save: "-tabs" option only has an effect with "-ascii")"); } + if (append && use_zlib + && (fmt.type () != TEXT && fmt.type () != MAT_ASCII)) + error ("save: -append and -zip options can only be used together with a text format (-text or -ascii)"); + return retval; } @@ -1812,6 +1816,53 @@ return load_save_sys.save (args, nargout); } +/* +## Save and load strings with "-v6" +%!test +%! A = A2 = ["foo"; "bar"]; +%! B = B2 = "foobar"; +%! C = C2 = {"foo", "bar"}; +%! D = D2 = {"Saint Barthélemy", "Saint Kitts and Nevis"}; +%! mat_file = [tempname(), ".mat"]; +%! unwind_protect +%! save (mat_file, "A", "B", "C", "D", "-v6"); +%! clear ("A", "B", "C", "D"); +%! load (mat_file); +%! unwind_protect_cleanup +%! unlink (mat_file); +%! end_unwind_protect +%! assert (A, A2); +%! assert (B, B2); +%! assert (C, C2); +%! assert (D, D2); + +## Save and load strings with "-v7" +%!testif HAVE_ZLIB +%! A = A2 = ["foo"; "bar"]; +%! B = B2 = "foobar"; +%! C = C2 = {"foo", "bar"}; +%! D = D2 = {"Saint Barthélemy", "Saint Kitts and Nevis"}; +%! mat_file = [tempname(), ".mat"]; +%! unwind_protect +%! save (mat_file, "A", "B", "C", "D", "-v7"); +%! clear ("A", "B", "C", "D"); +%! load (mat_file); +%! unwind_protect_cleanup +%! unlink (mat_file); +%! end_unwind_protect +%! assert (A, A2); +%! assert (B, B2); +%! assert (C, C2); +%! assert (D, D2); + +## Test input validation +%!testif HAVE_ZLIB <*59225> +%! fname = tempname (); +%! x = 1; +%! fail ('save ("-append", "-zip", "-binary", fname, "x")', +%! "-append and -zip options .* with a text format"); +*/ + DEFMETHOD (crash_dumps_octave_core, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {@var{val} =} crash_dumps_octave_core () diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/ls-mat-ascii.cc --- a/libinterp/corefcn/ls-mat-ascii.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/ls-mat-ascii.cc Thu Nov 19 13:08:00 2020 -0800 @@ -154,7 +154,7 @@ { std::istringstream tmp_stream (buf.substr (beg, end-beg)); - octave_read_double (tmp_stream); + octave::read_value (tmp_stream); if (tmp_stream.fail ()) { @@ -285,7 +285,7 @@ { octave_quit (); - d = octave_read_value (tmp_stream); + d = octave::read_value (tmp_stream); if (! tmp_stream && ! tmp_stream.eof ()) error ("load: failed to read matrix from file '%s'", @@ -381,7 +381,7 @@ { // Omit leading tabs. if (j != 0) os << '\t'; - octave_write_double (os, m(i, j)); + octave::write_value (os, m(i, j)); } os << "\n"; } diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/ls-mat4.cc --- a/libinterp/corefcn/ls-mat4.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/ls-mat4.cc Thu Nov 19 13:08:00 2020 -0800 @@ -465,9 +465,9 @@ } else if (tc.is_range ()) { - Range r = tc.range_value (); + octave::range r = tc.range_value (); double base = r.base (); - double inc = r.inc (); + double inc = r.increment (); octave_idx_type nel = r.numel (); for (octave_idx_type i = 0; i < nel; i++) { diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/ls-mat5.cc --- a/libinterp/corefcn/ls-mat5.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/ls-mat5.cc Thu Nov 19 13:08:00 2020 -0800 @@ -50,6 +50,7 @@ #include "oct-time.h" #include "quit.h" #include "str-vec.h" +#include "unistr-wrappers.h" #include "Cell.h" #include "defaults.h" @@ -1417,58 +1418,84 @@ tc = ctmp; } - else + else if (arrayclass == MAT_FILE_CHAR_CLASS) { - if (arrayclass == MAT_FILE_CHAR_CLASS) + bool converted = false; + if (re.isvector () && (type == miUTF16 || type == miUINT16)) { - if (type == miUTF16 || type == miUTF32) - { - bool found_big_char = false; - for (octave_idx_type i = 0; i < n; i++) - { - if (re(i) > 127) - { - re(i) = '?'; - found_big_char = true; - } - } - - if (found_big_char) - warning_with_id ("Octave:load:unsupported-utf-char", - "load: can not read non-ASCII portions of UTF characters; replacing unreadable characters with '?'"); - } - else if (type == miUTF8) + uint16NDArray u16 = re; + const uint16_t *u16_str + = reinterpret_cast (u16.data ()); + + // Convert to UTF-8. + size_t n8; + uint8_t *u8_str = octave_u16_to_u8_wrapper (u16_str, + u16.numel (), + nullptr, &n8); + if (u8_str) { - // Search for multi-byte encoded UTF8 characters and - // replace with 0x3F for '?'... Give the user a warning - - bool utf8_multi_byte = false; - for (octave_idx_type i = 0; i < n; i++) + // FIXME: Is there a better way to construct a charMatrix + // from a non zero terminated buffer? + tc = charMatrix (std::string (reinterpret_cast (u8_str), n8)); + free (u8_str); + converted = true; + } + } + else if (re.isvector () && (type == miUTF32 || type == miUINT32)) + { + uint32NDArray u32 = re; + const uint32_t *u32_str + = reinterpret_cast (u32.data ()); + + // Convert to UTF-8. + size_t n8; + uint8_t *u8_str = octave_u32_to_u8_wrapper (u32_str, + u32.numel (), + nullptr, &n8); + if (u8_str) + { + // FIXME: Is there a better way to construct a charMatrix + // from a non zero terminated buffer? + tc = charMatrix (std::string (reinterpret_cast (u8_str), n8)); + free (u8_str); + converted = true; + } + } + else if (type == miUTF8 || type == miUINT8) + { + // Octave's internal encoding is UTF-8. So we should be + // able to use this natively. + tc = re; + tc = tc.convert_to_str (false, true, '\''); + converted = true; + } + + if (! converted) + { + // Fall back to manually replacing non-ASCII + // characters by "?". + bool found_big_char = false; + for (octave_idx_type i = 0; i < n; i++) + { + if (re(i) > 127) { - unsigned char a = static_cast (re(i)); - if (a > 0x7f) - utf8_multi_byte = true; - } - - if (utf8_multi_byte) - { - warning_with_id ("Octave:load:unsupported-utf-char", - "load: can not read multi-byte encoded UTF8 characters; replacing unreadable characters with '?'"); - for (octave_idx_type i = 0; i < n; i++) - { - unsigned char a - = static_cast (re(i)); - if (a > 0x7f) - re(i) = '?'; - } + re(i) = '?'; + found_big_char = true; } } + + if (found_big_char) + warning_with_id ("Octave:load:unsupported-utf-char", + "load: failed to convert from input to UTF-8; " + "replacing non-ASCII characters with '?'"); + tc = re; tc = tc.convert_to_str (false, true, '\''); } - else - tc = re; + } + else + tc = re; } } @@ -2070,6 +2097,24 @@ return ret; } +static uint16_t * +maybe_convert_to_u16 (const charNDArray& chm, size_t& n16_str) +{ + uint16_t *u16_str; + dim_vector dv = chm.dims (); + + if (chm.ndims () == 2 && dv(0) == 1) + { + const uint8_t *u8_str = reinterpret_cast (chm.data ()); + u16_str = octave_u8_to_u16_wrapper (u8_str, chm.numel (), + nullptr, &n16_str); + } + else + u16_str = nullptr; + + return u16_str; +} + int save_mat5_element_length (const octave_value& tc, const std::string& name, bool save_as_floats, bool mat7_format) @@ -2087,9 +2132,23 @@ if (tc.is_string ()) { charNDArray chm = tc.char_array_value (); + // convert to UTF-16 + size_t n16_str; + uint16_t *u16_str = maybe_convert_to_u16 (chm, n16_str); ret += 8; - if (chm.numel () > 2) - ret += PAD (2 * chm.numel ()); + + octave_idx_type str_len; + if (u16_str) + { + // Count number of elements in converted string + str_len = 2 * n16_str; + free (u16_str); + } + else + str_len = chm.numel (); + + if (str_len > 2) + ret += PAD (str_len); } else if (tc.issparse ()) { @@ -2414,15 +2473,36 @@ write_mat5_tag (os, miINT32, dim_len); - for (int i = 0; i < nd; i++) + // Strings need to be converted here (or dim-vector will be off). + charNDArray chm; + uint16_t *u16_str; + size_t n16_str; + bool conv_u16 = false; + if (tc.is_string ()) { - int32_t n = dv(i); + chm = tc.char_array_value (); + u16_str = maybe_convert_to_u16 (chm, n16_str); + + if (u16_str) + conv_u16 = true; + } + + if (conv_u16) + { + int32_t n = 1; os.write (reinterpret_cast (&n), 4); + os.write (reinterpret_cast (&n16_str), 4); } + else + for (int i = 0; i < nd; i++) + { + int32_t n = dv(i); + os.write (reinterpret_cast (&n), 4); + } if (PAD (dim_len) > dim_len) { - static char buf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; + static char buf[9] = "\x00\x00\x00\x00\x00\x00\x00\x00"; os.write (buf, PAD (dim_len) - dim_len); } @@ -2445,24 +2525,35 @@ // data element if (tc.is_string ()) { - charNDArray chm = tc.char_array_value (); - octave_idx_type nel = chm.numel (); - octave_idx_type len = nel*2; - octave_idx_type paddedlength = PAD (len); - - OCTAVE_LOCAL_BUFFER (int16_t, buf, nel+3); - write_mat5_tag (os, miUINT16, len); - - const char *s = chm.data (); - - for (octave_idx_type i = 0; i < nel; i++) - buf[i] = *s++ & 0x00FF; - - os.write (reinterpret_cast (buf), len); + octave_idx_type len; + octave_idx_type paddedlength; + + if (conv_u16) + { + // converted UTF-16 + len = n16_str*2; + paddedlength = PAD (len); + + write_mat5_tag (os, miUTF16, len); + + os.write (reinterpret_cast (u16_str), len); + + free (u16_str); + } + else + { + // write as UTF-8 + len = chm.numel (); + paddedlength = PAD (len); + + write_mat5_tag (os, miUTF8, len); + + os.write (chm.data (), len); + } if (paddedlength > len) { - static char padbuf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; + static char padbuf[9] = "\x00\x00\x00\x00\x00\x00\x00\x00"; os.write (padbuf, paddedlength - len); } } diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/lsode.cc --- a/libinterp/corefcn/lsode.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/lsode.cc Thu Nov 19 13:08:00 2020 -0800 @@ -269,9 +269,7 @@ warned_fcn_imaginary = false; warned_jac_imaginary = false; - octave::unwind_protect frame; - - frame.protect_var (call_depth); + octave::unwind_protect_var restore_var (call_depth); call_depth++; if (call_depth > 1) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/lu.cc --- a/libinterp/corefcn/lu.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/lu.cc Thu Nov 19 13:08:00 2020 -0800 @@ -801,15 +801,15 @@ %! [L,U,P] = lu (A); %! [~,ordcols] = max (P,[],1); %! [~,ordrows] = max (P,[],2); -%! P1 = eye (size(P))(:,ordcols); -%! P2 = eye (size(P))(ordrows,:); -%! assert(P1 == P); -%! assert(P2 == P); +%! P1 = eye (size (P))(:,ordcols); +%! P2 = eye (size (P))(ordrows,:); +%! assert (P1 == P); +%! assert (P2 == P); %! [L,U,P] = luupdate (L,U,P,u,v); %! [L,U,P1] = luupdate (L,U,P1,u,v); %! [L,U,P2] = luupdate (L,U,P2,u,v); -%! assert(P1 == P); -%! assert(P2 == P); +%! assert (P1 == P); +%! assert (P2 == P); %! %!testif HAVE_QRUPDATE_LUU %! [L,U,P] = lu (Ac); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mappers.cc --- a/libinterp/corefcn/mappers.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/mappers.cc Thu Nov 19 13:08:00 2020 -0800 @@ -223,7 +223,7 @@ DEFUN (angle, args, , doc: /* -*- texinfo -*- @deftypefn {} {} angle (@var{z}) -See @code{arg}. +@xref{XREFarg,,@code{arg}}. @seealso{arg} @end deftypefn */) { @@ -841,7 +841,7 @@ %!test %! x = [1+2i,-1+2i,1e-6+2e-6i,0+2i]; -%! assert (erfcx (x), exp (x.^2) .* erfc(x), -1.e-10); +%! assert (erfcx (x), exp (x.^2) .* erfc (x), -1.e-10); %!test %! x = [100, 100+20i]; @@ -883,7 +883,7 @@ %!test %! x = [-0.1, 0.1, 1, 1+2i,-1+2i,1e-6+2e-6i,0+2i]; -%! assert (erfi (x), -i * erf(i*x), -1.e-10); +%! assert (erfi (x), -i * erf (i*x), -1.e-10); %!error erfi () %!error erfi (1, 2) @@ -1216,7 +1216,7 @@ %! result(double ("0":"9") + 1) = true; %! result(double ("a":"z") + 1) = true; %! assert (isalnum (charset), result); -%!assert (isalnum(["Ä8Aa?"; "(Uß ;"]), logical ([1 1 1 1 1 0; 0 1 1 1 0 0])); +%!assert (isalnum(["Ä8Aa?"; "(Uß ;"]), logical ([1 1 1 1 1 0; 0 1 1 1 0 0])) %!error isalnum () %!error isalnum (1, 2) @@ -1245,7 +1245,7 @@ %! result(double ("A":"Z") + 1) = true; %! result(double ("a":"z") + 1) = true; %! assert (isalpha (charset), result); -%!assert (isalpha("Ä8Aa(Uß ;"), logical ([1 1 0 1 1 0 1 1 1 0 0])); +%!assert (isalpha("Ä8Aa(Uß ;"), logical ([1 1 0 1 1 0 1 1 1 0 0])) %!error isalpha () %!error isalpha (1, 2) @@ -1321,7 +1321,7 @@ %! result = false (1, 128); %! result(double ("0":"9") + 1) = true; %! assert (isdigit (charset), result); -%!assert (isdigit("Ä8Aa(Uß ;"), logical ([0 0 1 0 0 0 0 0 0 0 0])); +%!assert (isdigit("Ä8Aa(Uß ;"), logical ([0 0 1 0 0 0 0 0 0 0 0])) %!error isdigit () %!error isdigit (1, 2) @@ -1388,7 +1388,7 @@ %! result = false (1, 128); %! result(34:127) = true; %! assert (isgraph (charset), result); -%!assert (isgraph("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 0 1])); +%!assert (isgraph("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 0 1])) %!error isgraph () %!error isgraph (1, 2) @@ -1414,7 +1414,7 @@ %! result = false (1, 128); %! result(double ("a":"z") + 1) = true; %! assert (islower (charset), result); -%!assert (islower("Ä8Aa(Uß ;"), logical ([0 0 0 0 1 0 0 1 1 0 0])); +%!assert (islower("Ä8Aa(Uß ;"), logical ([0 0 0 0 1 0 0 1 1 0 0])) %!error islower () %!error islower (1, 2) @@ -1521,7 +1521,7 @@ %! result = false (1, 128); %! result(33:127) = true; %! assert (isprint (charset), result); -%!assert (isprint("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 1 1])); +%!assert (isprint("Ä8Aa(Uß ;"), logical ([1 1 1 1 1 1 1 1 1 1 1])) %!error isprint () %!error isprint (1, 2) @@ -1550,7 +1550,7 @@ %! result(92:97) = true; %! result(124:127) = true; %! assert (ispunct (charset), result); -%!assert (ispunct("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 1 0 0 0 0 1])); +%!assert (ispunct("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 1 0 0 0 0 1])) %!error ispunct () %!error ispunct (1, 2) @@ -1577,7 +1577,7 @@ %! result = false (1, 128); %! result(double (" \f\n\r\t\v") + 1) = true; %! assert (isspace (charset), result); -%!assert (isspace("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 0 0 0 0 1 0])); +%!assert (isspace("Ä8Aa(Uß ;"), logical ([0 0 0 0 0 0 0 0 0 1 0])) %!error isspace () %!error isspace (1, 2) @@ -1603,7 +1603,7 @@ %! result = false (1, 128); %! result(double ("A":"Z") + 1) = true; %! assert (isupper (charset), result); -%!assert (isupper("Ä8Aa(Uß ;"), logical ([1 1 0 1 0 0 1 0 0 0 0])); +%!assert (isupper("Ä8Aa(Uß ;"), logical ([1 1 0 1 0 0 1 0 0 0 0])) %!error isupper () %!error isupper (1, 2) @@ -1631,7 +1631,7 @@ %! result(double ("0":"9") + 1) = true; %! result(double ("a":"f") + 1) = true; %! assert (isxdigit (charset), result); -%!assert (isxdigit("Ä8Aa(Uß ;"), logical ([0 0 1 1 1 0 0 0 0 0 0])); +%!assert (isxdigit("Ä8Aa(Uß ;"), logical ([0 0 1 1 1 0 0 0 0 0 0])) %!error isxdigit () %!error isxdigit (1, 2) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/matrix_type.cc --- a/libinterp/corefcn/matrix_type.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/matrix_type.cc Thu Nov 19 13:08:00 2020 -0800 @@ -540,10 +540,10 @@ %! a = matrix_type (spdiags (randn (10,3),[-1,0,1],10,10), "Singular"); %! assert (matrix_type (a), "Singular"); -%!assert (matrix_type (triu (ones(10,10))), "Upper") -%!assert (matrix_type (triu (ones(10,10),-1)), "Full") -%!assert (matrix_type (tril (ones(10,10))), "Lower") -%!assert (matrix_type (tril (ones(10,10),1)), "Full") +%!assert (matrix_type (triu (ones (10,10))), "Upper") +%!assert (matrix_type (triu (ones (10,10),-1)), "Full") +%!assert (matrix_type (tril (ones (10,10))), "Lower") +%!assert (matrix_type (tril (ones (10,10),1)), "Full") %!assert (matrix_type (10*eye (10,10) + ones (10,10)), "Positive Definite") %!assert (matrix_type (ones (11,10)), "Rectangular") %!test diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/max.cc --- a/libinterp/corefcn/max.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/max.cc Thu Nov 19 13:08:00 2020 -0800 @@ -269,7 +269,7 @@ { if (arg.is_range () && (dim == -1 || dim == 1)) { - Range range = arg.range_value (); + octave::range range = arg.range_value (); if (range.numel () < 1) { retval(0) = arg; @@ -281,14 +281,14 @@ retval(0) = range.min (); if (nargout > 1) retval(1) = static_cast - (range.inc () < 0 ? range.numel () : 1); + (range.increment () < 0 ? range.numel () : 1); } else { retval(0) = range.max (); if (nargout > 1) retval(1) = static_cast - (range.inc () >= 0 ? range.numel () : 1); + (range.increment () >= 0 ? range.numel () : 1); } } else if (arg.issparse ()) diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mex.cc --- a/libinterp/corefcn/mex.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/mex.cc Thu Nov 19 13:08:00 2020 -0800 @@ -62,6 +62,197 @@ #include "variables.h" #include "graphics.h" +// These must be declared extern "C" but may be omitted from the set of +// symbols declared in mexproto.h, so we declare them here as well. + +extern "C" +{ + extern OCTINTERP_API const mxArray * + mexGet_interleaved (double handle, const char *property); + + extern OCTINTERP_API mxArray * + mxCreateCellArray (mwSize ndims, const mwSize *dims); + + extern OCTINTERP_API mxArray * + mxCreateCellMatrix (mwSize m, mwSize n); + + extern OCTINTERP_API mxArray * + mxCreateCharArray (mwSize ndims, const mwSize *dims); + + extern OCTINTERP_API mxArray * + mxCreateCharMatrixFromStrings (mwSize m, const char **str); + + extern OCTINTERP_API mxArray * + mxCreateDoubleMatrix (mwSize nr, mwSize nc, mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateDoubleScalar (double val); + + extern OCTINTERP_API mxArray * + mxCreateLogicalArray (mwSize ndims, const mwSize *dims); + + extern OCTINTERP_API mxArray * + mxCreateLogicalMatrix (mwSize m, mwSize n); + + extern OCTINTERP_API mxArray * + mxCreateLogicalScalar (mxLogical val); + + extern OCTINTERP_API mxArray * + mxCreateNumericArray (mwSize ndims, const mwSize *dims, mxClassID class_id, + mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateNumericMatrix (mwSize m, mwSize n, mxClassID class_id, + mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateUninitNumericArray (mwSize ndims, const mwSize *dims, + mxClassID class_id, mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateUninitNumericMatrix (mwSize m, mwSize n, mxClassID class_id, + mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateSparse (mwSize m, mwSize n, mwSize nzmax, mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateSparseLogicalMatrix (mwSize m, mwSize n, mwSize nzmax); + + extern OCTINTERP_API mxArray * + mxCreateString (const char *str); + + extern OCTINTERP_API mxArray * + mxCreateStructArray (mwSize ndims, const mwSize *dims, int num_keys, + const char **keys); + + extern OCTINTERP_API mxArray * + mxCreateStructMatrix (mwSize rows, mwSize cols, int num_keys, + const char **keys); + + extern OCTINTERP_API mxArray * + mxCreateCellArray_interleaved (mwSize ndims, const mwSize *dims); + + extern OCTINTERP_API mxArray * + mxCreateCellMatrix_interleaved (mwSize m, mwSize n); + + extern OCTINTERP_API mxArray * + mxCreateCharArray_interleaved (mwSize ndims, const mwSize *dims); + + extern OCTINTERP_API mxArray * + mxCreateCharMatrixFromStrings_interleaved (mwSize m, const char **str); + + extern OCTINTERP_API mxArray * + mxCreateDoubleMatrix_interleaved (mwSize nr, mwSize nc, mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateDoubleScalar_interleaved (double val); + + extern OCTINTERP_API mxArray * + mxCreateLogicalArray_interleaved (mwSize ndims, const mwSize *dims); + + extern OCTINTERP_API mxArray * + mxCreateLogicalMatrix_interleaved (mwSize m, mwSize n); + + extern OCTINTERP_API mxArray * + mxCreateLogicalScalar_interleaved (mxLogical val); + + extern OCTINTERP_API mxArray * + mxCreateNumericArray_interleaved (mwSize ndims, const mwSize *dims, + mxClassID class_id, mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateNumericMatrix_interleaved (mwSize m, mwSize n, mxClassID class_id, + mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateUninitNumericArray_interleaved (mwSize ndims, const mwSize *dims, + mxClassID class_id, + mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateUninitNumericMatrix_interleaved (mwSize m, mwSize n, + mxClassID class_id, + mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateSparse_interleaved (mwSize m, mwSize n, mwSize nzmax, + mxComplexity flag); + + extern OCTINTERP_API mxArray * + mxCreateSparseLogicalMatrix_interleaved (mwSize m, mwSize n, mwSize nzmax); + + extern OCTINTERP_API mxArray * + mxCreateString_interleaved (const char *str); + + extern OCTINTERP_API mxArray * + mxCreateStructArray_interleaved (mwSize ndims, const mwSize *dims, + int num_keys, const char **keys); + + extern OCTINTERP_API mxArray * + mxCreateStructMatrix_interleaved (mwSize rows, mwSize cols, int num_keys, + const char **keys); + + extern OCTINTERP_API int mxMakeArrayReal (mxArray *ptr); + extern OCTINTERP_API int mxMakeArrayComplex (mxArray *ptr); + + extern OCTINTERP_API mxDouble * mxGetDoubles (const mxArray *p); + extern OCTINTERP_API mxSingle * mxGetSingles (const mxArray *p); + extern OCTINTERP_API mxInt8 * mxGetInt8s (const mxArray *p); + extern OCTINTERP_API mxInt16 * mxGetInt16s (const mxArray *p); + extern OCTINTERP_API mxInt32 * mxGetInt32s (const mxArray *p); + extern OCTINTERP_API mxInt64 * mxGetInt64s (const mxArray *p); + extern OCTINTERP_API mxUint8 * mxGetUint8s (const mxArray *p); + extern OCTINTERP_API mxUint16 * mxGetUint16s (const mxArray *p); + extern OCTINTERP_API mxUint32 * mxGetUint32s (const mxArray *p); + extern OCTINTERP_API mxUint64 * mxGetUint64s (const mxArray *p); + + extern OCTINTERP_API mxComplexDouble * mxGetComplexDoubles (const mxArray *p); + extern OCTINTERP_API mxComplexSingle * mxGetComplexSingles (const mxArray *p); +#if 0 + /* We don't have these yet. */ + extern OCTINTERP_API mxComplexInt8 * mxGetComplexInt8s (const mxArray *p); + extern OCTINTERP_API mxComplexInt16 * mxGetComplexInt16s (const mxArray *p); + extern OCTINTERP_API mxComplexInt32 * mxGetComplexInt32s (const mxArray *p); + extern OCTINTERP_API mxComplexInt64 * mxGetComplexInt64s (const mxArray *p); + extern OCTINTERP_API mxComplexUint8 * mxGetComplexUint8s (const mxArray *p); + extern OCTINTERP_API mxComplexUint16 * mxGetComplexUint16s (const mxArray *p); + extern OCTINTERP_API mxComplexUint32 * mxGetComplexUint32s (const mxArray *p); + extern OCTINTERP_API mxComplexUint64 * mxGetComplexUint64s (const mxArray *p); +#endif + + extern OCTINTERP_API double * mxGetPi (const mxArray *ptr); + extern OCTINTERP_API void * mxGetImagData (const mxArray *ptr); + + extern OCTINTERP_API int mxSetDoubles (mxArray *p, mxDouble *d); + extern OCTINTERP_API int mxSetSingles (mxArray *p, mxSingle *d); + extern OCTINTERP_API int mxSetInt8s (mxArray *p, mxInt8 *d); + extern OCTINTERP_API int mxSetInt16s (mxArray *p, mxInt16 *d); + extern OCTINTERP_API int mxSetInt32s (mxArray *p, mxInt32 *d); + extern OCTINTERP_API int mxSetInt64s (mxArray *p, mxInt64 *d); + extern OCTINTERP_API int mxSetUint8s (mxArray *p, mxUint8 *d); + extern OCTINTERP_API int mxSetUint16s (mxArray *p, mxUint16 *d); + extern OCTINTERP_API int mxSetUint32s (mxArray *p, mxUint32 *d); + extern OCTINTERP_API int mxSetUint64s (mxArray *p, mxUint64 *d); + + extern OCTINTERP_API int mxSetComplexDoubles (mxArray *p, mxComplexDouble *d); + extern OCTINTERP_API int mxSetComplexSingles (mxArray *p, mxComplexSingle *d); +#if 0 + /* We don't have these yet. */ + extern OCTINTERP_API int mxSetComplexInt8s (mxArray *p, mxComplexInt8 *d); + extern OCTINTERP_API int mxSetComplexInt16s (mxArray *p, mxComplexInt16 *d); + extern OCTINTERP_API int mxSetComplexInt32s (mxArray *p, mxComplexInt32 *d); + extern OCTINTERP_API int mxSetComplexInt64s (mxArray *p, mxComplexInt64 *d); + extern OCTINTERP_API int mxSetComplexUint8s (mxArray *p, mxComplexUint8 *d); + extern OCTINTERP_API int mxSetComplexUint16s (mxArray *p, mxComplexUint16 *d); + extern OCTINTERP_API int mxSetComplexUint32s (mxArray *p, mxComplexUint32 *d); + extern OCTINTERP_API int mxSetComplexUint64s (mxArray *p, mxComplexUint64 *d); +#endif + + extern OCTINTERP_API void mxSetPi (mxArray *ptr, double *pi); + extern OCTINTERP_API void mxSetImagData (mxArray *ptr, void *pi); +} + // #define DEBUG 1 static void @@ -112,6 +303,10 @@ // ------------------------------------------------------------------ +mxArray_base::mxArray_base (bool interleaved) + : m_interleaved (interleaved) +{ } + static mwIndex calc_single_subscript_internal (mwSize ndims, const mwSize *dims, mwSize nsubs, const mwIndex *subs) @@ -157,13 +352,26 @@ static inline void * maybe_mark_foreign (void *ptr); +#define VOID_MUTATION_METHOD(FCN_NAME, ARG_LIST) \ + void FCN_NAME ARG_LIST { request_mutation (); } + +#define CONST_VOID_MUTATION_METHOD(FCN_NAME, ARG_LIST) \ + void FCN_NAME ARG_LIST const { request_mutation (); } + +#define MUTATION_METHOD(RET_TYPE, FCN_NAME, ARG_LIST, RET_VAL) \ + RET_TYPE FCN_NAME ARG_LIST { request_mutation (); return RET_VAL; } + +#define CONST_MUTATION_METHOD(RET_TYPE, FCN_NAME, ARG_LIST, RET_VAL) \ + RET_TYPE FCN_NAME ARG_LIST const { request_mutation (); return RET_VAL; } + class mxArray_octave_value : public mxArray_base { public: - mxArray_octave_value (const octave_value& ov) - : mxArray_base (), val (ov), mutate_flag (false), - id (mxUNKNOWN_CLASS), class_name (nullptr), ndims (-1), dims (nullptr) { } + mxArray_octave_value (bool interleaved, const octave_value& ov) + : mxArray_base (interleaved), val (ov), mutate_flag (false), + id (mxUNKNOWN_CLASS), class_name (nullptr), ndims (-1), dims (nullptr) + { } // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. @@ -174,7 +382,7 @@ mxArray * as_mxArray (void) const { - mxArray *retval = val.as_mxArray (); + mxArray *retval = val.as_mxArray (m_interleaved); // RETVAL is assumed to be an mxArray_matlab object. Should we // assert that condition here? @@ -303,16 +511,10 @@ return ndims; } - void set_m (mwSize /*m*/) { request_mutation (); } - - void set_n (mwSize /*n*/) { request_mutation (); } - - int set_dimensions (mwSize * /*dims_arg*/, mwSize /*ndims_arg*/) - { - request_mutation (); - - return 0; - } + VOID_MUTATION_METHOD (set_m, (mwSize)) + VOID_MUTATION_METHOD (set_n, (mwSize)) + + MUTATION_METHOD (int, set_dimensions, (mwSize *, mwSize), 0) mwSize get_number_of_elements (void) const { return val.numel (); } @@ -378,7 +580,7 @@ } // Not allowed. - void set_class_name (const char * /*name_arg*/) { request_mutation (); } + VOID_MUTATION_METHOD (set_class_name, (const char *)) mxArray * get_property (mwIndex idx, const char *pname) const { @@ -393,7 +595,7 @@ octave_value pval = ov_cdef->get_property (idx, pname); if (pval.is_defined()) - retval = new mxArray (pval); + retval = new mxArray (m_interleaved, pval); } } @@ -410,17 +612,13 @@ ov_cdef->set_property (idx, pname, pval->as_octave_value ()); } else - err_invalid_type (); + err_invalid_type ("set_property"); } - mxArray * get_cell (mwIndex /*idx*/) const - { - request_mutation (); - return nullptr; - } + CONST_MUTATION_METHOD (mxArray *, get_cell, (mwIndex), nullptr) // Not allowed. - void set_cell (mwIndex /*idx*/, mxArray * /*val*/) { request_mutation (); } + VOID_MUTATION_METHOD (set_cell, (mwIndex, mxArray *)) double get_scalar (void) const { @@ -454,6 +652,61 @@ return retval; } + template + T * get_data (mxClassID class_id, mxComplexity complexity) const + { + T *retval = static_cast (val.mex_get_data (class_id, complexity)); + + if (retval) + maybe_mark_foreign (retval); + else + request_mutation (); + + return retval; + } + + CONST_MUTATION_METHOD (mxDouble *, get_doubles, (void), nullptr); + + CONST_MUTATION_METHOD (mxSingle *, get_singles, (void), nullptr); + + CONST_MUTATION_METHOD (mxInt8 *, get_int8s, (void), nullptr); + + CONST_MUTATION_METHOD (mxInt16 *, get_int16s, (void), nullptr); + + CONST_MUTATION_METHOD (mxInt32 *, get_int32s, (void), nullptr); + + CONST_MUTATION_METHOD (mxInt64 *, get_int64s, (void), nullptr); + + CONST_MUTATION_METHOD (mxUint8 *, get_uint8s, (void), nullptr); + + CONST_MUTATION_METHOD (mxUint16 *, get_uint16s, (void), nullptr); + + CONST_MUTATION_METHOD (mxUint32 *, get_uint32s, (void), nullptr); + + CONST_MUTATION_METHOD (mxUint64 *, get_uint64s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexDouble *, get_complex_doubles, (void), nullptr); + CONST_MUTATION_METHOD (mxComplexSingle *, get_complex_singles, (void), nullptr); + +#if 0 + /* We don't have these yet. */ + CONST_MUTATION_METHOD (mxComplexInt8 *, get_complex_int8s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexInt16 *, get_complex_int16s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexInt32 *, get_complex_int32s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexInt64 *, get_complex_int64s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexUint8 *, get_complex_uint8s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexUint16 *, get_complex_uint16s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexUint32 *, get_complex_uint32s, (void), nullptr); + + CONST_MUTATION_METHOD (mxComplexUint64 *, get_complex_uint64s, (void), nullptr); +#endif + void * get_imag_data (void) const { void *retval = nullptr; @@ -467,10 +720,35 @@ } // Not allowed. - void set_data (void * /*pr*/) { request_mutation (); } + VOID_MUTATION_METHOD (set_data, (void *)) + + MUTATION_METHOD (int, set_doubles, (mxDouble *), 0) + MUTATION_METHOD (int, set_singles, (mxSingle *), 0) + MUTATION_METHOD (int, set_int8s, (mxInt8 *), 0) + MUTATION_METHOD (int, set_int16s, (mxInt16 *), 0) + MUTATION_METHOD (int, set_int32s, (mxInt32 *), 0) + MUTATION_METHOD (int, set_int64s, (mxInt64 *), 0) + MUTATION_METHOD (int, set_uint8s, (mxUint8 *), 0) + MUTATION_METHOD (int, set_uint16s, (mxUint16 *), 0) + MUTATION_METHOD (int, set_uint32s, (mxUint32 *), 0) + MUTATION_METHOD (int, set_uint64s, (mxUint64 *), 0) + + MUTATION_METHOD (int, set_complex_doubles, (mxComplexDouble *), 0) + MUTATION_METHOD (int, set_complex_singles, (mxComplexSingle *), 0) +#if 0 + /* We don't have these yet. */ + MUTATION_METHOD (int, set_complex_int8s, (mxComplexInt8 *), 0) + MUTATION_METHOD (int, set_complex_int16s, (mxComplexInt16 *), 0) + MUTATION_METHOD (int, set_complex_int32s, (mxComplexInt32 *), 0) + MUTATION_METHOD (int, set_complex_int64s, (mxComplexInt64 *), 0) + MUTATION_METHOD (int, set_complex_uint8s, (mxComplexUint8 *), 0) + MUTATION_METHOD (int, set_complex_uint16s, (mxComplexUint16 *), 0) + MUTATION_METHOD (int, set_complex_uint32s, (mxComplexUint32 *), 0) + MUTATION_METHOD (int, set_complex_uint64s, (mxComplexUint64 *), 0) +#endif // Not allowed. - void set_imag_data (void * /*pi*/) { request_mutation (); } + VOID_MUTATION_METHOD (set_imag_data, (void *)) mwIndex * get_ir (void) const { @@ -485,50 +763,30 @@ mwSize get_nzmax (void) const { return val.nzmax (); } // Not allowed. - void set_ir (mwIndex * /*ir*/) { request_mutation (); } - - // Not allowed. - void set_jc (mwIndex * /*jc*/) { request_mutation (); } + VOID_MUTATION_METHOD (set_ir, (mwIndex *)) // Not allowed. - void set_nzmax (mwSize /*nzmax*/) { request_mutation (); } + VOID_MUTATION_METHOD (set_jc, (mwIndex *)) // Not allowed. - int add_field (const char * /*key*/) - { - request_mutation (); - return 0; - } + VOID_MUTATION_METHOD (set_nzmax, (mwSize)) + + // Not allowed. + MUTATION_METHOD (int, add_field, (const char *), 0) // Not allowed. - void remove_field (int /*key_num*/) { request_mutation (); } - - mxArray * get_field_by_number (mwIndex /*index*/, int /*key_num*/) const - { - request_mutation (); - return nullptr; - } + VOID_MUTATION_METHOD (remove_field, (int)) + + CONST_MUTATION_METHOD (mxArray *, get_field_by_number, (mwIndex, int), nullptr) // Not allowed. - void set_field_by_number (mwIndex /*index*/, int /*key_num*/, - mxArray * /*val*/) - { - request_mutation (); - } + VOID_MUTATION_METHOD (set_field_by_number, (mwIndex, int, mxArray *)) int get_number_of_fields (void) const { return val.nfields (); } - const char * get_field_name_by_number (int /*key_num*/) const - { - request_mutation (); - return nullptr; - } - - int get_field_number (const char * /*key*/) const - { - request_mutation (); - return 0; - } + CONST_MUTATION_METHOD (const char *, get_field_name_by_number, (int), nullptr) + + CONST_MUTATION_METHOD (int, get_field_number, (const char *), 0) int get_string (char *buf, mwSize buflen) const { @@ -596,21 +854,21 @@ switch (id) { - case mxDOUBLE_CLASS: return sizeof (double); - case mxSINGLE_CLASS: return sizeof (float); - case mxCHAR_CLASS: return sizeof (mxChar); - case mxLOGICAL_CLASS: return sizeof (mxLogical); case mxCELL_CLASS: return sizeof (mxArray *); case mxSTRUCT_CLASS: return sizeof (mxArray *); + case mxLOGICAL_CLASS: return sizeof (mxLogical); + case mxCHAR_CLASS: return sizeof (mxChar); + case mxDOUBLE_CLASS: return get_numeric_element_size (sizeof (mxDouble)); + case mxSINGLE_CLASS: return get_numeric_element_size (sizeof (mxSingle)); + case mxINT8_CLASS: return get_numeric_element_size (sizeof (mxInt8)); + case mxUINT8_CLASS: return get_numeric_element_size (sizeof (mxUint8)); + case mxINT16_CLASS: return get_numeric_element_size (sizeof (mxInt16)); + case mxUINT16_CLASS: return get_numeric_element_size (sizeof (mxUint16)); + case mxINT32_CLASS: return get_numeric_element_size (sizeof (mxInt32)); + case mxUINT32_CLASS: return get_numeric_element_size (sizeof (mxUint32)); + case mxINT64_CLASS: return get_numeric_element_size (sizeof (mxInt64)); + case mxUINT64_CLASS: return get_numeric_element_size (sizeof (mxUint64)); case mxFUNCTION_CLASS: return 0; - case mxINT8_CLASS: return 1; - case mxUINT8_CLASS: return 1; - case mxINT16_CLASS: return 2; - case mxUINT16_CLASS: return 2; - case mxINT32_CLASS: return 4; - case mxUINT32_CLASS: return 4; - case mxINT64_CLASS: return 8; - case mxUINT64_CLASS: return 8; // FIXME: user-defined objects need their own class ID. // What should they return, size of pointer? default: return 0; @@ -637,9 +895,9 @@ : mxArray_base (arg), val (arg.val), mutate_flag (arg.mutate_flag), id (arg.id), class_name (mxArray::strsave (arg.class_name)), ndims (arg.ndims), - dims (ndims > 0 ? static_cast - (mxArray::malloc (ndims * sizeof (mwSize))) - : nullptr) + dims (ndims > 0 + ? static_cast (mxArray::malloc (ndims * sizeof (mwSize))) + : nullptr) { if (dims) { @@ -671,13 +929,14 @@ { protected: - mxArray_matlab (mxClassID id_arg = mxUNKNOWN_CLASS) - : mxArray_base (), class_name (nullptr), id (id_arg), ndims (0), + mxArray_matlab (bool interleaved, mxClassID id_arg = mxUNKNOWN_CLASS) + : mxArray_base (interleaved), class_name (nullptr), id (id_arg), ndims (0), dims (nullptr) { } - mxArray_matlab (mxClassID id_arg, mwSize ndims_arg, const mwSize *dims_arg) - : mxArray_base (), class_name (nullptr), id (id_arg), + mxArray_matlab (bool interleaved, mxClassID id_arg, mwSize ndims_arg, + const mwSize *dims_arg) + : mxArray_base (interleaved), class_name (nullptr), id (id_arg), ndims (ndims_arg < 2 ? 2 : ndims_arg), dims (static_cast (mxArray::malloc (ndims * sizeof (mwSize)))) { @@ -704,8 +963,8 @@ } } - mxArray_matlab (mxClassID id_arg, const dim_vector& dv) - : mxArray_base (), class_name (nullptr), id (id_arg), + mxArray_matlab (bool interleaved, mxClassID id_arg, const dim_vector& dv) + : mxArray_base (interleaved), class_name (nullptr), id (id_arg), ndims (dv.ndims ()), dims (static_cast (mxArray::malloc (ndims * sizeof (mwSize)))) { @@ -721,8 +980,8 @@ } } - mxArray_matlab (mxClassID id_arg, mwSize m, mwSize n) - : mxArray_base (), class_name (nullptr), id (id_arg), ndims (2), + mxArray_matlab (bool interleaved, mxClassID id_arg, mwSize m, mwSize n) + : mxArray_base (interleaved), class_name (nullptr), id (id_arg), ndims (2), dims (static_cast (mxArray::malloc (ndims * sizeof (mwSize)))) { dims[0] = m; @@ -900,98 +1159,304 @@ mxArray * get_cell (mwIndex /*idx*/) const { - err_invalid_type (); + err_invalid_type ("get_cell"); } void set_cell (mwIndex /*idx*/, mxArray * /*val*/) { - err_invalid_type (); + err_invalid_type ("set_cell"); } double get_scalar (void) const { - err_invalid_type (); + err_invalid_type ("get_scalar"); } void * get_data (void) const { - err_invalid_type (); + err_invalid_type ("get_data"); + } + + mxDouble * get_doubles (void) const + { + err_invalid_type ("get_doubles"); + } + + mxSingle * get_singles (void) const + { + err_invalid_type ("get_singles"); + } + + mxInt8 * get_int8s (void) const + { + err_invalid_type ("get_int8s"); + } + + mxInt16 * get_int16s (void) const + { + err_invalid_type ("get_int16s"); + } + + mxInt32 * get_int32s (void) const + { + err_invalid_type ("get_int32s"); + } + + mxInt64 * get_int64s (void) const + { + err_invalid_type ("get_int64s"); + } + + mxUint8 * get_uint8s (void) const + { + err_invalid_type ("get_uint8s"); + } + + mxUint16 * get_uint16s (void) const + { + err_invalid_type ("get_uint16s"); + } + + mxUint32 * get_uint32s (void) const + { + err_invalid_type ("get_uint32s"); + } + + mxUint64 * get_uint64s (void) const + { + err_invalid_type ("get_uint64s"); } + mxComplexDouble * get_complex_doubles (void) const + { + err_invalid_type ("get_complex_doubles"); + } + + mxComplexSingle * get_complex_singles (void) const + { + err_invalid_type ("get_complex_singles"); + } + +#if 0 + /* We don't have these yet. */ + mxComplexInt8 * get_complex_int8s (void) const + { + err_invalid_type ("get_complex_int8s"); + } + + mxComplexInt16 * get_complex_int16s (void) const + { + err_invalid_type ("get_complex_int16s"); + } + + mxComplexInt32 * get_complex_int32s (void) const + { + err_invalid_type ("get_complex_int32s"); + } + + mxComplexInt64 * get_complex_int64s (void) const + { + err_invalid_type ("get_complex_int64s"); + } + + mxComplexUint8 * get_complex_uint8s (void) const + { + err_invalid_type ("get_complex_uint8s"); + } + + mxComplexUint16 * get_complex_uint16s (void) const + { + err_invalid_type ("get_complex_uint16s"); + } + + mxComplexUint32 * get_complex_uint32s (void) const + { + err_invalid_type ("get_complex_uint32s"); + } + + mxComplexUint64 * get_complex_uint64s (void) const + { + err_invalid_type ("get_complex_uint64s"); + } +#endif + void * get_imag_data (void) const { - err_invalid_type (); + err_invalid_type ("get_imag_data"); } void set_data (void * /*pr*/) { - err_invalid_type (); + err_invalid_type ("set_data"); + } + + int set_doubles (mxDouble *) + { + err_invalid_type ("set_doubles"); + } + + int set_singles (mxSingle *) + { + err_invalid_type ("set_singles"); + } + + int set_int8s (mxInt8 *) + { + err_invalid_type ("set_int8s"); + } + + int set_int16s (mxInt16 *) + { + err_invalid_type ("set_int16s"); + } + + int set_int32s (mxInt32 *) + { + err_invalid_type ("set_int32s"); + } + + int set_int64s (mxInt64 *) + { + err_invalid_type ("set_int64s"); + } + + int set_uint8s (mxUint8 *) + { + err_invalid_type ("set_uint8s"); + } + + int set_uint16s (mxUint16 *) + { + err_invalid_type ("set_uint16s"); + } + + int set_uint32s (mxUint32 *) + { + err_invalid_type ("set_uint32s"); + } + + int set_uint64s (mxUint64 *) + { + err_invalid_type ("set_uint64s"); } + int set_complex_doubles (mxComplexDouble *) + { + err_invalid_type ("set_complex_doubles"); + } + + int set_complex_singles (mxComplexSingle *) + { + err_invalid_type ("set_complex_singles"); + } + +#if 0 + /* We don't have these yet. */ + int set_complex_int8s (mxComplexInt8 *) + { + err_invalid_type ("set_complex_int8s"); + } + + int set_complex_int16s (mxComplexInt16 *) + { + err_invalid_type ("set_complex_int16s"); + } + + int set_complex_int32s (mxComplexInt32 *) + { + err_invalid_type ("set_complex_int32s"); + } + + int set_complex_int64s (mxComplexInt64 *) + { + err_invalid_type ("set_complex_int64s"); + } + + int set_complex_uint8s (mxComplexUint8 *) + { + err_invalid_type ("set_complex_uint8s"); + } + + int set_complex_uint16s (mxComplexUint16 *) + { + err_invalid_type ("set_complex_uint16s"); + } + + int set_complex_uint32s (mxComplexUint32 *) + { + err_invalid_type ("set_complex_uint32s"); + } + + int set_complex_uint64s (mxComplexUint64 *) + { + err_invalid_type ("set_complex_uint64s"); + } +#endif + void set_imag_data (void * /*pi*/) { - err_invalid_type (); + err_invalid_type ("set_imag_data"); } mwIndex * get_ir (void) const { - err_invalid_type (); + err_invalid_type ("get_ir"); } mwIndex * get_jc (void) const { - err_invalid_type (); + err_invalid_type ("get_jc"); } mwSize get_nzmax (void) const { - err_invalid_type (); + err_invalid_type ("get_nzmax"); } void set_ir (mwIndex * /*ir*/) { - err_invalid_type (); + err_invalid_type ("set_ir"); } void set_jc (mwIndex * /*jc*/) { - err_invalid_type (); + err_invalid_type ("set_jc"); } void set_nzmax (mwSize /*nzmax*/) { - err_invalid_type (); + err_invalid_type ("set_nzmax"); } int add_field (const char * /*key*/) { - err_invalid_type (); + err_invalid_type ("add_field"); } void remove_field (int /*key_num*/) { - err_invalid_type (); + err_invalid_type ("remove_field"); } mxArray * get_field_by_number (mwIndex /*index*/, int /*key_num*/) const { - err_invalid_type (); + err_invalid_type ("get_field_by_number"); } void set_field_by_number (mwIndex /*index*/, int /*key_num*/, mxArray * /*val*/) { - err_invalid_type (); + err_invalid_type ("set_field_by_number"); } int get_number_of_fields (void) const { - err_invalid_type (); + err_invalid_type ("get_number_of_fields"); } const char * get_field_name_by_number (int /*key_num*/) const { - err_invalid_type (); + err_invalid_type ("get_field_name_by_number"); } int get_field_number (const char * /*key*/) const @@ -1001,12 +1466,12 @@ int get_string (char * /*buf*/, mwSize /*buflen*/) const { - err_invalid_type (); + err_invalid_type ("get_string"); } char * array_to_string (void) const { - err_invalid_type (); + err_invalid_type ("array_to_string"); } mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const @@ -1022,16 +1487,16 @@ case mxSTRUCT_CLASS: return sizeof (mxArray *); case mxLOGICAL_CLASS: return sizeof (mxLogical); case mxCHAR_CLASS: return sizeof (mxChar); - case mxDOUBLE_CLASS: return sizeof (double); - case mxSINGLE_CLASS: return sizeof (float); - case mxINT8_CLASS: return 1; - case mxUINT8_CLASS: return 1; - case mxINT16_CLASS: return 2; - case mxUINT16_CLASS: return 2; - case mxINT32_CLASS: return 4; - case mxUINT32_CLASS: return 4; - case mxINT64_CLASS: return 8; - case mxUINT64_CLASS: return 8; + case mxDOUBLE_CLASS: return get_numeric_element_size (sizeof (mxDouble)); + case mxSINGLE_CLASS: return get_numeric_element_size (sizeof (mxSingle)); + case mxINT8_CLASS: return get_numeric_element_size (sizeof (mxInt8)); + case mxUINT8_CLASS: return get_numeric_element_size (sizeof (mxUint8)); + case mxINT16_CLASS: return get_numeric_element_size (sizeof (mxInt16)); + case mxUINT16_CLASS: return get_numeric_element_size (sizeof (mxUint16)); + case mxINT32_CLASS: return get_numeric_element_size (sizeof (mxInt32)); + case mxUINT32_CLASS: return get_numeric_element_size (sizeof (mxUint32)); + case mxINT64_CLASS: return get_numeric_element_size (sizeof (mxInt64)); + case mxUINT64_CLASS: return get_numeric_element_size (sizeof (mxUint64)); case mxFUNCTION_CLASS: return 0; // FIXME: user-defined objects need their own class ID. // What should they return, size of pointer? @@ -1065,59 +1530,79 @@ mwSize ndims; mwSize *dims; - - OCTAVE_NORETURN void err_invalid_type (void) const - { - error ("invalid type for operation"); - } }; + // Matlab-style numeric, character, and logical data. +#define TYPED_GET_METHOD(TYPE, FCN_NAME) \ + TYPE FCN_NAME (void) const \ + { \ + if (! m_interleaved) \ + panic_impossible (); \ + \ + return static_cast (pr); \ + } + +#define TYPED_SET_METHOD(TYPE, FCN_NAME) \ + int FCN_NAME (TYPE d) \ + { \ + if (! m_interleaved) \ + panic_impossible (); \ + \ + pr = d; \ + return 0; \ + } + class mxArray_number : public mxArray_matlab { public: - mxArray_number (mxClassID id_arg, mwSize ndims_arg, const mwSize *dims_arg, - mxComplexity flag = mxREAL, bool init = true) - : mxArray_matlab (id_arg, ndims_arg, dims_arg), - pr (init ? mxArray::calloc (get_number_of_elements (), - get_element_size ()) - : mxArray::malloc (get_number_of_elements () - * get_element_size ())), - pi (flag == mxCOMPLEX - ? (init ? mxArray::calloc (get_number_of_elements (), - get_element_size ()) - : mxArray::malloc (get_number_of_elements () - * get_element_size ())) - : nullptr) { } - - mxArray_number (mxClassID id_arg, const dim_vector& dv, + mxArray_number (bool interleaved, mxClassID id_arg, mwSize ndims_arg, + const mwSize *dims_arg, mxComplexity flag = mxREAL, + bool init = true) + : mxArray_matlab (interleaved, id_arg, ndims_arg, dims_arg), + m_complex (flag == mxCOMPLEX), + pr (init + ? mxArray::calloc (get_number_of_elements (), get_element_size ()) + : mxArray::malloc (get_number_of_elements () * get_element_size ())), + pi (m_interleaved + ? nullptr + : (m_complex + ? (init + ? mxArray::calloc (get_number_of_elements (), get_element_size ()) + : mxArray::malloc (get_number_of_elements () * get_element_size ())) + : nullptr)) + { } + + mxArray_number (bool interleaved, mxClassID id_arg, const dim_vector& dv, mxComplexity flag = mxREAL) - : mxArray_matlab (id_arg, dv), + : mxArray_matlab (interleaved, id_arg, dv), m_complex (flag == mxCOMPLEX), pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), - pi (flag == mxCOMPLEX ? mxArray::calloc (get_number_of_elements (), - get_element_size ()) - : nullptr) + pi (m_interleaved + ? nullptr + : (m_complex + ? mxArray::calloc (get_number_of_elements (), get_element_size ()) + : nullptr)) { } - mxArray_number (mxClassID id_arg, mwSize m, mwSize n, + mxArray_number (bool interleaved, mxClassID id_arg, mwSize m, mwSize n, mxComplexity flag = mxREAL, bool init = true) - : mxArray_matlab (id_arg, m, n), - pr (init ? mxArray::calloc (get_number_of_elements (), - get_element_size ()) - : mxArray::malloc (get_number_of_elements () - * get_element_size ())), - pi (flag == mxCOMPLEX - ? (init ? mxArray::calloc (get_number_of_elements (), - get_element_size ()) - : mxArray::malloc (get_number_of_elements () - * get_element_size ())) - : nullptr) + : mxArray_matlab (interleaved, id_arg, m, n), m_complex (flag == mxCOMPLEX), + pr (init + ? mxArray::calloc (get_number_of_elements (), get_element_size ()) + : mxArray::malloc (get_number_of_elements () * get_element_size ())), + pi (m_interleaved + ? nullptr + : (m_complex + ? (init + ? mxArray::calloc (get_number_of_elements (), get_element_size ()) + : mxArray::malloc (get_number_of_elements () * get_element_size ())) + : nullptr)) { } - mxArray_number (mxClassID id_arg, double val) - : mxArray_matlab (id_arg, 1, 1), + mxArray_number (bool interleaved, mxClassID id_arg, double val) + : mxArray_matlab (interleaved, id_arg, 1, 1), m_complex (false), pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), pi (nullptr) { @@ -1125,8 +1610,8 @@ dpr[0] = val; } - mxArray_number (mxClassID id_arg, mxLogical val) - : mxArray_matlab (id_arg, 1, 1), + mxArray_number (bool interleaved, mxClassID id_arg, mxLogical val) + : mxArray_matlab (interleaved, id_arg, 1, 1), m_complex (false), pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), pi (nullptr) { @@ -1134,10 +1619,11 @@ lpr[0] = val; } - mxArray_number (const char *str) - : mxArray_matlab (mxCHAR_CLASS, + mxArray_number (bool interleaved, const char *str) + : mxArray_matlab (interleaved, mxCHAR_CLASS, str ? (strlen (str) ? 1 : 0) : 0, str ? strlen (str) : 0), + m_complex (false), pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), pi (nullptr) { @@ -1148,8 +1634,9 @@ } // FIXME: ??? - mxArray_number (mwSize m, const char **str) - : mxArray_matlab (mxCHAR_CLASS, m, max_str_len (m, str)), + mxArray_number (bool interleaved, mwSize m, const char **str) + : mxArray_matlab (interleaved, mxCHAR_CLASS, m, max_str_len (m, str)), + m_complex (false), pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), pi (nullptr) { @@ -1176,11 +1663,13 @@ protected: mxArray_number (const mxArray_number& val) - : mxArray_matlab (val), + : mxArray_matlab (val), m_complex (val.m_complex), pr (mxArray::malloc (get_number_of_elements () * get_element_size ())), - pi (val.pi ? mxArray::malloc (get_number_of_elements () - * get_element_size ()) - : nullptr) + pi (m_interleaved + ? nullptr + : (val.pi + ? mxArray::malloc (get_number_of_elements () * get_element_size ()) + : nullptr)) { size_t nbytes = get_number_of_elements () * get_element_size (); @@ -1198,7 +1687,10 @@ mxArray_number& operator = (const mxArray_number&); - mxArray_base * dup (void) const { return new mxArray_number (*this); } + mxArray_base * dup (void) const + { + return new mxArray_number (*this); + } ~mxArray_number (void) { @@ -1206,10 +1698,15 @@ mxFree (pi); } - int is_complex (void) const { return pi != nullptr; } + int is_complex (void) const + { + return m_interleaved ? m_complex : (pi != nullptr); + } double get_scalar (void) const { + // FIXME: how does this work for interleaved complex arrays? + double retval = 0; switch (get_class_id ()) @@ -1271,11 +1768,73 @@ void * get_data (void) const { return pr; } - void * get_imag_data (void) const { return pi; } + void * get_imag_data (void) const + { + if (m_interleaved) + panic_impossible (); + + return pi; + } void set_data (void *pr_arg) { pr = pr_arg; } - void set_imag_data (void *pi_arg) { pi = pi_arg; } + void set_imag_data (void *pi_arg) + { + if (m_interleaved) + panic_impossible (); + + pi = pi_arg; + } + + TYPED_GET_METHOD (mxDouble *, get_doubles) + TYPED_GET_METHOD (mxSingle *, get_singles) + TYPED_GET_METHOD (mxInt8 *, get_int8s) + TYPED_GET_METHOD (mxInt16 *, get_int16s) + TYPED_GET_METHOD (mxInt32 *, get_int32s) + TYPED_GET_METHOD (mxInt64 *, get_int64s) + TYPED_GET_METHOD (mxUint8 *, get_uint8s) + TYPED_GET_METHOD (mxUint16 *, get_uint16s) + TYPED_GET_METHOD (mxUint32 *, get_uint32s) + TYPED_GET_METHOD (mxUint64 *, get_uint64s) + + TYPED_GET_METHOD (mxComplexDouble *, get_complex_doubles) + TYPED_GET_METHOD (mxComplexSingle *, get_complex_singles) +#if 0 + /* We don't have these yet. */ + TYPED_GET_METHOD (mxComplexInt8 *, get_complex_int8s) + TYPED_GET_METHOD (mxComplexInt16 *, get_complex_int16s) + TYPED_GET_METHOD (mxComplexInt32 *, get_complex_int32s) + TYPED_GET_METHOD (mxComplexInt64 *, get_complex_int64s) + TYPED_GET_METHOD (mxComplexUint8 *, get_complex_uint8s) + TYPED_GET_METHOD (mxComplexUint16 *, get_complex_uint16s) + TYPED_GET_METHOD (mxComplexUint32 *, get_complex_uint32s) + TYPED_GET_METHOD (mxComplexUint64 *, get_complex_uint64s) +#endif + + TYPED_SET_METHOD (mxDouble *, set_doubles) + TYPED_SET_METHOD (mxSingle *, set_singles) + TYPED_SET_METHOD (mxInt8 *, set_int8s) + TYPED_SET_METHOD (mxInt16 *, set_int16s) + TYPED_SET_METHOD (mxInt32 *, set_int32s) + TYPED_SET_METHOD (mxInt64 *, set_int64s) + TYPED_SET_METHOD (mxUint8 *, set_uint8s) + TYPED_SET_METHOD (mxUint16 *, set_uint16s) + TYPED_SET_METHOD (mxUint32 *, set_uint32s) + TYPED_SET_METHOD (mxUint64 *, set_uint64s) + + TYPED_SET_METHOD (mxComplexDouble *, set_complex_doubles) + TYPED_SET_METHOD (mxComplexSingle *, set_complex_singles) +#if 0 + /* We don't have these yet. */ + TYPED_SET_METHOD (mxComplexInt8 *, set_complex_int8s) + TYPED_SET_METHOD (mxComplexInt16 *, set_complex_int16s) + TYPED_SET_METHOD (mxComplexInt32 *, set_complex_int32s) + TYPED_SET_METHOD (mxComplexInt64 *, set_complex_int64s) + TYPED_SET_METHOD (mxComplexUint8 *, set_complex_uint8s) + TYPED_SET_METHOD (mxComplexUint16 *, set_complex_uint16s) + TYPED_SET_METHOD (mxComplexUint32 *, set_complex_uint32s) + TYPED_SET_METHOD (mxComplexUint64 *, set_complex_uint64s) +#endif int get_string (char *buf, mwSize buflen) const { @@ -1336,23 +1895,40 @@ { mwSize nel = get_number_of_elements (); - double *ppr = static_cast (pr); - - if (pi) + if (is_complex ()) { - ComplexNDArray val (dv); - - Complex *ptr = val.fortran_vec (); - - double *ppi = static_cast (pi); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = Complex (ppr[i], ppi[i]); - - retval = val; + if (m_interleaved) + { + Complex *ppr = static_cast (pr); + + ComplexNDArray val (dv); + Complex *ptr = val.fortran_vec (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = ppr[i]; + + retval = val; + } + else + { + double *ppr = static_cast (pr); + + ComplexNDArray val (dv); + + Complex *ptr = val.fortran_vec (); + + double *ppi = static_cast (pi); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = Complex (ppr[i], ppi[i]); + + retval = val; + } } else { + double *ppr = static_cast (pr); + NDArray val (dv); double *ptr = val.fortran_vec (); @@ -1369,23 +1945,40 @@ { mwSize nel = get_number_of_elements (); - float *ppr = static_cast (pr); - - if (pi) + if (is_complex ()) { - FloatComplexNDArray val (dv); - - FloatComplex *ptr = val.fortran_vec (); - - float *ppi = static_cast (pi); - - for (mwIndex i = 0; i < nel; i++) - ptr[i] = FloatComplex (ppr[i], ppi[i]); - - retval = val; + if (m_interleaved) + { + FloatComplex *ppr = static_cast (pr); + + FloatComplexNDArray val (dv); + FloatComplex *ptr = val.fortran_vec (); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = ppr[i]; + + retval = val; + } + else + { + float *ppr = static_cast (pr); + + FloatComplexNDArray val (dv); + + FloatComplex *ptr = val.fortran_vec (); + + float *ppi = static_cast (pi); + + for (mwIndex i = 0; i < nel; i++) + ptr[i] = FloatComplex (ppr[i], ppi[i]); + + retval = val; + } } else { + float *ppr = static_cast (pr); + FloatNDArray val (dv); float *ptr = val.fortran_vec (); @@ -1464,7 +2057,7 @@ octave_value int_to_ov (const dim_vector& dv) const { - if (pi) + if (is_complex ()) error ("complex integer types are not supported"); mwSize nel = get_number_of_elements (); @@ -1483,7 +2076,17 @@ private: + // Flag to identify complex object if using interleaved data and PI is + // always nullptr. + bool m_complex; + + // If using interleaved complex storage, this is the pointer to data + // (real, complex, or logical). Otherwise, it is the pointer to the + // real part of the data. void *pr; + + // If using non-interleaved complex storage, this is the pointer to + // the imaginary part of the data. Othrwise is is always nullptr. void *pi; }; @@ -1493,24 +2096,31 @@ { public: - mxArray_sparse (mxClassID id_arg, mwSize m, mwSize n, mwSize nzmax_arg, - mxComplexity flag = mxREAL) - : mxArray_matlab (id_arg, m, n) - { - nzmax = (nzmax_arg > 0 ? nzmax_arg : 1); - pr = mxArray::calloc (nzmax, get_element_size ()); - pi = (flag == mxCOMPLEX ? mxArray::calloc (nzmax, get_element_size ()) - : nullptr); - ir = (static_cast (mxArray::calloc (nzmax, sizeof (mwIndex)))); - jc = (static_cast (mxArray::calloc (n + 1, sizeof (mwIndex)))); - } + mxArray_sparse (bool interleaved, mxClassID id_arg, mwSize m, mwSize n, + mwSize nzmax_arg, mxComplexity flag = mxREAL) + : mxArray_matlab (interleaved, id_arg, m, n), m_complex (flag == mxCOMPLEX), + + nzmax (nzmax_arg > 0 ? nzmax_arg : 1), + pr (mxArray::calloc (nzmax, get_element_size ())), + pi (m_interleaved + ? nullptr + : (m_complex + ? mxArray::calloc (nzmax, get_element_size ()) + : nullptr)), + ir (static_cast (mxArray::calloc (nzmax, sizeof (mwIndex)))), + jc (static_cast (mxArray::calloc (n + 1, sizeof (mwIndex)))) + { } private: mxArray_sparse (const mxArray_sparse& val) : mxArray_matlab (val), nzmax (val.nzmax), pr (mxArray::malloc (nzmax * get_element_size ())), - pi (val.pi ? mxArray::malloc (nzmax * get_element_size ()) : nullptr), + pi (m_interleaved + ? nullptr + : (val.pi + ? mxArray::malloc (nzmax * get_element_size ()) + : nullptr)), ir (static_cast (mxArray::malloc (nzmax * sizeof (mwIndex)))), jc (static_cast (mxArray::malloc (nzmax * sizeof (mwIndex)))) { @@ -1536,7 +2146,10 @@ mxArray_sparse& operator = (const mxArray_sparse&); - mxArray_base * dup (void) const { return new mxArray_sparse (*this); } + mxArray_base * dup (void) const + { + return new mxArray_sparse (*this); + } ~mxArray_sparse (void) { @@ -1546,17 +2159,38 @@ mxFree (jc); } - int is_complex (void) const { return pi != nullptr; } + int is_complex (void) const + { + return m_interleaved ? m_complex : (pi != nullptr); + } int is_sparse (void) const { return 1; } void * get_data (void) const { return pr; } - void * get_imag_data (void) const { return pi; } + void * get_imag_data (void) const + { + if (m_interleaved) + panic_impossible (); + + return pi; + } void set_data (void *pr_arg) { pr = pr_arg; } - void set_imag_data (void *pi_arg) { pi = pi_arg; } + void set_imag_data (void *pi_arg) + { + if (m_interleaved) + panic_impossible (); + + pi = pi_arg; + } + + TYPED_GET_METHOD (mxDouble *, get_doubles) + TYPED_GET_METHOD (mxComplexDouble *, get_complex_doubles) + + TYPED_SET_METHOD (mxDouble *, set_doubles) + TYPED_SET_METHOD (mxComplexDouble *, set_complex_doubles) mwIndex * get_ir (void) const { return ir; } @@ -1584,24 +2218,45 @@ { case mxDOUBLE_CLASS: { - if (pi) + if (is_complex ()) { - double *ppr = static_cast (pr); - double *ppi = static_cast (pi); - - SparseComplexMatrix val (get_m (), get_n (), - static_cast (nzmax)); - - for (mwIndex i = 0; i < nzmax; i++) + if (m_interleaved) { - val.xdata (i) = Complex (ppr[i], ppi[i]); - val.xridx (i) = ir[i]; + Complex *ppr = static_cast (pr); + + SparseComplexMatrix val (get_m (), get_n (), + static_cast (nzmax)); + + for (mwIndex i = 0; i < nzmax; i++) + { + val.xdata (i) = ppr[i]; + val.xridx (i) = ir[i]; + } + + for (mwIndex i = 0; i < get_n () + 1; i++) + val.xcidx (i) = jc[i]; + + retval = val; } - - for (mwIndex i = 0; i < get_n () + 1; i++) - val.xcidx (i) = jc[i]; - - retval = val; + else + { + double *ppr = static_cast (pr); + double *ppi = static_cast (pi); + + SparseComplexMatrix val (get_m (), get_n (), + static_cast (nzmax)); + + for (mwIndex i = 0; i < nzmax; i++) + { + val.xdata (i) = Complex (ppr[i], ppi[i]); + val.xridx (i) = ir[i]; + } + + for (mwIndex i = 0; i < get_n () + 1; i++) + val.xcidx (i) = jc[i]; + + retval = val; + } } else { @@ -1646,7 +2301,6 @@ case mxSINGLE_CLASS: error ("single precision sparse data type not supported"); - break; default: panic_impossible (); @@ -1657,10 +2311,23 @@ private: + // Flag to identify complex object if using interleaved data and PI is + // always nullptr. + bool m_complex; + + // Maximun number of nonzero elements. mwSize nzmax; + // If using interleaved complex storage, this is the pointer to data + // (real, complex, or logical). Otherwise, it is the pointer to the + // real part of the data. void *pr; + + // If using non-interleaved complex storage, this is the pointer to + // the imaginary part of the data. Othrwise is is always nullptr. void *pi; + + // Sparse storage indexing arrays. mwIndex *ir; mwIndex *jc; }; @@ -1671,9 +2338,9 @@ { public: - mxArray_struct (mwSize ndims_arg, const mwSize *dims_arg, int num_keys_arg, - const char **keys) - : mxArray_matlab (mxSTRUCT_CLASS, ndims_arg, dims_arg), + mxArray_struct (bool interleaved, mwSize ndims_arg, const mwSize *dims_arg, + int num_keys_arg, const char **keys) + : mxArray_matlab (interleaved, mxSTRUCT_CLASS, ndims_arg, dims_arg), nfields (num_keys_arg), fields (static_cast (mxArray::calloc (nfields, sizeof (char *)))), @@ -1684,8 +2351,9 @@ init (keys); } - mxArray_struct (const dim_vector& dv, int num_keys_arg, const char **keys) - : mxArray_matlab (mxSTRUCT_CLASS, dv), nfields (num_keys_arg), + mxArray_struct (bool interleaved, const dim_vector& dv, int num_keys_arg, + const char **keys) + : mxArray_matlab (interleaved, mxSTRUCT_CLASS, dv), nfields (num_keys_arg), fields (static_cast (mxArray::calloc (nfields, sizeof (char *)))), data (static_cast (mxArray::calloc (nfields * @@ -1695,8 +2363,10 @@ init (keys); } - mxArray_struct (mwSize m, mwSize n, int num_keys_arg, const char **keys) - : mxArray_matlab (mxSTRUCT_CLASS, m, n), nfields (num_keys_arg), + mxArray_struct (bool interleaved, mwSize m, mwSize n, int num_keys_arg, + const char **keys) + : mxArray_matlab (interleaved, mxSTRUCT_CLASS, m, n), + nfields (num_keys_arg), fields (static_cast (mxArray::calloc (nfields, sizeof (char *)))), data (static_cast (mxArray::calloc (nfields * @@ -1937,18 +2607,18 @@ { public: - mxArray_cell (mwSize ndims_arg, const mwSize *dims_arg) - : mxArray_matlab (mxCELL_CLASS, ndims_arg, dims_arg), + mxArray_cell (bool interleaved, mwSize ndims_arg, const mwSize *dims_arg) + : mxArray_matlab (interleaved, mxCELL_CLASS, ndims_arg, dims_arg), data (static_cast (mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) { } - mxArray_cell (const dim_vector& dv) - : mxArray_matlab (mxCELL_CLASS, dv), + mxArray_cell (bool interleaved, const dim_vector& dv) + : mxArray_matlab (interleaved, mxCELL_CLASS, dv), data (static_cast (mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) { } - mxArray_cell (mwSize m, mwSize n) - : mxArray_matlab (mxCELL_CLASS, m, n), + mxArray_cell (bool interleaved, mwSize m, mwSize n) + : mxArray_matlab (interleaved, mxCELL_CLASS, m, n), data (static_cast (mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) { } @@ -2021,54 +2691,76 @@ // ------------------------------------------------------------------ -mxArray::mxArray (const octave_value& ov) - : rep (new mxArray_octave_value (ov)), name (nullptr) { } - -mxArray::mxArray (mxClassID id, mwSize ndims, const mwSize *dims, - mxComplexity flag, bool init) - : rep (new mxArray_number (id, ndims, dims, flag, init)), name (nullptr) { } - -mxArray::mxArray (mxClassID id, const dim_vector& dv, mxComplexity flag) - : rep (new mxArray_number (id, dv, flag)), name (nullptr) { } - -mxArray::mxArray (mxClassID id, mwSize m, mwSize n, +mxArray::mxArray (bool interleaved, const octave_value& ov) + : rep (create_rep (interleaved, ov)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mxClassID id, mwSize ndims, + const mwSize *dims, mxComplexity flag, bool init) + : rep (create_rep (interleaved, id, ndims, dims, flag, init)), + name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mxClassID id, const dim_vector& dv, + mxComplexity flag) + : rep (create_rep (interleaved, id, dv, flag)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n, mxComplexity flag, bool init) - : rep (new mxArray_number (id, m, n, flag, init)), name (nullptr) { } - -mxArray::mxArray (mxClassID id, double val) - : rep (new mxArray_number (id, val)), name (nullptr) { } - -mxArray::mxArray (mxClassID id, mxLogical val) - : rep (new mxArray_number (id, val)), name (nullptr) { } - -mxArray::mxArray (const char *str) - : rep (new mxArray_number (str)), name (nullptr) { } - -mxArray::mxArray (mwSize m, const char **str) - : rep (new mxArray_number (m, str)), name (nullptr) { } - -mxArray::mxArray (mxClassID id, mwSize m, mwSize n, mwSize nzmax, - mxComplexity flag) - : rep (new mxArray_sparse (id, m, n, nzmax, flag)), name (nullptr) { } - -mxArray::mxArray (mwSize ndims, const mwSize *dims, int num_keys, + : rep (create_rep (interleaved, id, m, n, flag, init)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mxClassID id, double val) + : rep (create_rep (interleaved, id, val)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mxClassID id, mxLogical val) + : rep (create_rep (interleaved, id, val)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, const char *str) + : rep (create_rep (interleaved, str)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mwSize m, const char **str) + : rep (create_rep (interleaved, m, str)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n, + mwSize nzmax, mxComplexity flag) + : rep (create_rep (interleaved, id, m, n, nzmax, flag)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mwSize ndims, const mwSize *dims, + int num_keys, const char **keys) - : rep (new mxArray_struct (ndims, dims, num_keys, keys)), name (nullptr) { } - -mxArray::mxArray (const dim_vector& dv, int num_keys, const char **keys) - : rep (new mxArray_struct (dv, num_keys, keys)), name (nullptr) { } - -mxArray::mxArray (mwSize m, mwSize n, int num_keys, const char **keys) - : rep (new mxArray_struct (m, n, num_keys, keys)), name (nullptr) { } - -mxArray::mxArray (mwSize ndims, const mwSize *dims) - : rep (new mxArray_cell (ndims, dims)), name (nullptr) { } - -mxArray::mxArray (const dim_vector& dv) - : rep (new mxArray_cell (dv)), name (nullptr) { } - -mxArray::mxArray (mwSize m, mwSize n) - : rep (new mxArray_cell (m, n)), name (nullptr) { } + : rep (new mxArray_struct (interleaved, ndims, dims, num_keys, keys)), + name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, const dim_vector& dv, int num_keys, + const char **keys) + : rep (new mxArray_struct (interleaved, dv, num_keys, keys)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mwSize m, mwSize n, int num_keys, + const char **keys) + : rep (new mxArray_struct (interleaved, m, n, num_keys, keys)), + name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mwSize ndims, const mwSize *dims) + : rep (new mxArray_cell (interleaved, ndims, dims)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, const dim_vector& dv) + : rep (new mxArray_cell (interleaved, dv)), name (nullptr) +{ } + +mxArray::mxArray (bool interleaved, mwSize m, mwSize n) + : rep (new mxArray_cell (interleaved, m, n)), name (nullptr) +{ } mxArray::~mxArray (void) { @@ -2100,6 +2792,64 @@ return rep->as_octave_value (); } +mxArray_base * +mxArray::create_rep (bool interleaved, const octave_value& ov) +{ + return new mxArray_octave_value (interleaved, ov); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, mxClassID id, mwSize ndims, + const mwSize *dims, mxComplexity flag, bool init) +{ + return new mxArray_number (interleaved, id, ndims, dims, flag, init); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, mxClassID id, const dim_vector& dv, + mxComplexity flag) +{ + return new mxArray_number (interleaved, id, dv, flag); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n, + mxComplexity flag, bool init) +{ + return new mxArray_number (interleaved, id, m, n, flag, init); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, mxClassID id, double val) +{ + return new mxArray_number (interleaved, id, val); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, mxClassID id, mxLogical val) +{ + return new mxArray_number (interleaved, id, val); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, const char *str) +{ + return new mxArray_number (interleaved, str); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, mwSize m, const char **str) +{ + return new mxArray_number (interleaved, m, str); +} + +mxArray_base * +mxArray::create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n, + mwSize nzmax, mxComplexity flag) +{ + return new mxArray_sparse (interleaved, id, m, n, nzmax, flag); +} + void mxArray::maybe_mutate (void) const { @@ -2130,7 +2880,7 @@ { public: - mex (octave_mex_function *f) + mex (octave_mex_function& f) : curr_mex_fcn (f), memlist (), arraylist (), fname (nullptr) { } // No copying! @@ -2363,7 +3113,9 @@ // freed on exit unless marked as persistent. mxArray * make_value (const octave_value& ov) { - return mark_array (new mxArray (ov)); + bool interleaved = curr_mex_fcn.use_interleaved_complex (); + + return mark_array (new mxArray (interleaved, ov)); } // Free an array and its contents. @@ -2387,7 +3139,7 @@ return inlist; } - octave_mex_function * current_mex_function (void) const + octave_mex_function& current_mex_function (void) const { return curr_mex_fcn; } @@ -2398,7 +3150,7 @@ private: // Pointer to the mex function that corresponds to this mex context. - octave_mex_function *curr_mex_fcn; + octave_mex_function& curr_mex_fcn; // List of memory resources that need to be freed upon exit. std::set memlist; @@ -2438,7 +3190,6 @@ else warning ("%s: value not marked", function_name ()); #endif - } }; @@ -2478,8 +3229,9 @@ return ptr; } -static inline void * -maybe_unmark (void *ptr) +template +static inline T * +maybe_unmark (T *ptr) { if (mex_context) mex_context->unmark (ptr); @@ -2580,116 +3332,235 @@ // Constructors. mxArray * +mxCreateCellArray_interleaved (mwSize ndims, const mwSize *dims) +{ + return maybe_mark_array (new mxArray (true, ndims, dims)); +} + +mxArray * mxCreateCellArray (mwSize ndims, const mwSize *dims) { - return maybe_mark_array (new mxArray (ndims, dims)); + return maybe_mark_array (new mxArray (false, ndims, dims)); +} + +mxArray * +mxCreateCellMatrix_interleaved (mwSize m, mwSize n) +{ + return maybe_mark_array (new mxArray (true, m, n)); } mxArray * mxCreateCellMatrix (mwSize m, mwSize n) { - return maybe_mark_array (new mxArray (m, n)); + return maybe_mark_array (new mxArray (false, m, n)); +} + +mxArray * +mxCreateCharArray_interleaved (mwSize ndims, const mwSize *dims) +{ + return maybe_mark_array (new mxArray (true, mxCHAR_CLASS, ndims, dims)); } mxArray * mxCreateCharArray (mwSize ndims, const mwSize *dims) { - return maybe_mark_array (new mxArray (mxCHAR_CLASS, ndims, dims)); + return maybe_mark_array (new mxArray (false, mxCHAR_CLASS, ndims, dims)); +} + +mxArray * +mxCreateCharMatrixFromStrings_interleaved (mwSize m, const char **str) +{ + return maybe_mark_array (new mxArray (true, m, str)); } mxArray * mxCreateCharMatrixFromStrings (mwSize m, const char **str) { - return maybe_mark_array (new mxArray (m, str)); + return maybe_mark_array (new mxArray (false, m, str)); +} + +mxArray * +mxCreateDoubleMatrix_interleaved (mwSize m, mwSize n, mxComplexity flag) +{ + return maybe_mark_array (new mxArray (true, mxDOUBLE_CLASS, m, n, flag)); } mxArray * mxCreateDoubleMatrix (mwSize m, mwSize n, mxComplexity flag) { - return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, m, n, flag)); + return maybe_mark_array (new mxArray (false, mxDOUBLE_CLASS, m, n, flag)); +} + +mxArray * +mxCreateDoubleScalar_interleaved (double val) +{ + return maybe_mark_array (new mxArray (true, mxDOUBLE_CLASS, val)); } mxArray * mxCreateDoubleScalar (double val) { - return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, val)); + return maybe_mark_array (new mxArray (false, mxDOUBLE_CLASS, val)); +} + +mxArray * +mxCreateLogicalArray_interleaved (mwSize ndims, const mwSize *dims) +{ + return maybe_mark_array (new mxArray (true, mxLOGICAL_CLASS, ndims, dims)); } mxArray * mxCreateLogicalArray (mwSize ndims, const mwSize *dims) { - return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, ndims, dims)); + return maybe_mark_array (new mxArray (false, mxLOGICAL_CLASS, ndims, dims)); +} + +mxArray * +mxCreateLogicalMatrix_interleaved (mwSize m, mwSize n) +{ + return maybe_mark_array (new mxArray (true, mxLOGICAL_CLASS, m, n)); } mxArray * mxCreateLogicalMatrix (mwSize m, mwSize n) { - return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, m, n)); + return maybe_mark_array (new mxArray (false, mxLOGICAL_CLASS, m, n)); +} + +mxArray * +mxCreateLogicalScalar_interleaved (mxLogical val) +{ + return maybe_mark_array (new mxArray (true, mxLOGICAL_CLASS, val)); } mxArray * mxCreateLogicalScalar (mxLogical val) { - return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, val)); + return maybe_mark_array (new mxArray (false, mxLOGICAL_CLASS, val)); +} + +mxArray * +mxCreateNumericArray_interleaved (mwSize ndims, const mwSize *dims, + mxClassID class_id, mxComplexity flag) +{ + return maybe_mark_array (new mxArray (true, class_id, ndims, dims, flag)); } mxArray * -mxCreateNumericArray (mwSize ndims, const mwSize *dims, mxClassID class_id, - mxComplexity flag) -{ - return maybe_mark_array (new mxArray (class_id, ndims, dims, flag)); +mxCreateNumericArray (mwSize ndims, const mwSize *dims, + mxClassID class_id, mxComplexity flag) +{ + return maybe_mark_array (new mxArray (false, class_id, ndims, dims, flag)); +} + +mxArray * +mxCreateNumericMatrix_interleaved (mwSize m, mwSize n, mxClassID class_id, + mxComplexity flag) +{ + return maybe_mark_array (new mxArray (true, class_id, m, n, flag)); } mxArray * mxCreateNumericMatrix (mwSize m, mwSize n, mxClassID class_id, - mxComplexity flag) -{ - return maybe_mark_array (new mxArray (class_id, m, n, flag)); + mxComplexity flag) +{ + return maybe_mark_array (new mxArray (false, class_id, m, n, flag)); +} + +mxArray * +mxCreateUninitNumericArray_interleaved (mwSize ndims, const mwSize *dims, + mxClassID class_id, mxComplexity flag) +{ + return maybe_mark_array (new mxArray (true, class_id, ndims, dims, flag, + false)); } mxArray * mxCreateUninitNumericArray (mwSize ndims, const mwSize *dims, - mxClassID class_id, mxComplexity flag) -{ - return maybe_mark_array (new mxArray (class_id, ndims, dims, flag, false)); + mxClassID class_id, mxComplexity flag) +{ + return maybe_mark_array (new mxArray (false, class_id, ndims, dims, flag, + false)); +} + +mxArray * +mxCreateUninitNumericMatrix_interleaved (mwSize m, mwSize n, + mxClassID class_id, mxComplexity flag) +{ + return maybe_mark_array (new mxArray (true, class_id, m, n, flag, false)); } mxArray * mxCreateUninitNumericMatrix (mwSize m, mwSize n, mxClassID class_id, - mxComplexity flag) -{ - return maybe_mark_array (new mxArray (class_id, m, n, flag, false)); + mxComplexity flag) +{ + return maybe_mark_array (new mxArray (false, class_id, m, n, flag, false)); +} + +mxArray * +mxCreateSparse_interleaved (mwSize m, mwSize n, mwSize nzmax, mxComplexity flag) +{ + return maybe_mark_array (new mxArray (true, mxDOUBLE_CLASS, m, n, nzmax, + flag)); } mxArray * mxCreateSparse (mwSize m, mwSize n, mwSize nzmax, mxComplexity flag) { - return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, m, n, nzmax, flag)); + return maybe_mark_array (new mxArray (false, mxDOUBLE_CLASS, m, n, nzmax, + flag)); +} + +mxArray * +mxCreateSparseLogicalMatrix_interleaved (mwSize m, mwSize n, mwSize nzmax) +{ + return maybe_mark_array (new mxArray (true, mxLOGICAL_CLASS, m, n, nzmax)); } mxArray * mxCreateSparseLogicalMatrix (mwSize m, mwSize n, mwSize nzmax) { - return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, m, n, nzmax)); + return maybe_mark_array (new mxArray (false, mxLOGICAL_CLASS, m, n, nzmax)); +} + +mxArray * +mxCreateString_interleaved (const char *str) +{ + return maybe_mark_array (new mxArray (true, str)); } mxArray * mxCreateString (const char *str) { - return maybe_mark_array (new mxArray (str)); + return maybe_mark_array (new mxArray (false, str)); +} + +mxArray * +mxCreateStructArray_interleaved (mwSize ndims, const mwSize *dims, + int num_keys, const char **keys) +{ + return maybe_mark_array (new mxArray (true, ndims, dims, num_keys, keys)); } mxArray * mxCreateStructArray (mwSize ndims, const mwSize *dims, int num_keys, - const char **keys) -{ - return maybe_mark_array (new mxArray (ndims, dims, num_keys, keys)); + const char **keys) +{ + return maybe_mark_array (new mxArray (false, ndims, dims, num_keys, keys)); } mxArray * -mxCreateStructMatrix (mwSize m, mwSize n, int num_keys, const char **keys) -{ - return maybe_mark_array (new mxArray (m, n, num_keys, keys)); +mxCreateStructMatrix_interleaved (mwSize m, mwSize n, int num_keys, + const char **keys) +{ + return maybe_mark_array (new mxArray (true, m, n, num_keys, keys)); +} + +mxArray * +mxCreateStructMatrix (mwSize m, mwSize n, int num_keys, + const char **keys) +{ + return maybe_mark_array (new mxArray (false, m, n, num_keys, keys)); } // Copy constructor. @@ -2918,12 +3789,6 @@ return static_cast (ptr->get_data ()); } -double * -mxGetPi (const mxArray *ptr) -{ - return static_cast (ptr->get_imag_data ()); -} - double mxGetScalar (const mxArray *ptr) { @@ -2951,12 +3816,121 @@ return ptr->get_data (); } +double * +mxGetPi (const mxArray *ptr) +{ + return static_cast (ptr->get_imag_data ()); +} + void * mxGetImagData (const mxArray *ptr) { return ptr->get_imag_data (); } +mxDouble * mxGetDoubles (const mxArray *ptr) +{ + return ptr->get_doubles (); +} + +mxSingle * mxGetSingles (const mxArray *ptr) +{ + return ptr->get_singles (); +} + +mxInt8 * mxGetInt8s (const mxArray *ptr) +{ + return ptr->get_int8s (); +} + +mxInt16 * mxGetInt16s (const mxArray *ptr) +{ + return ptr->get_int16s (); +} + +mxInt32 * mxGetInt32s (const mxArray *ptr) +{ + return ptr->get_int32s (); +} + +mxInt64 * mxGetInt64s (const mxArray *ptr) +{ + return ptr->get_int64s (); +} + +mxUint8 * mxGetUint8s (const mxArray *ptr) +{ + return ptr->get_uint8s (); +} + +mxUint16 * mxGetUint16s (const mxArray *ptr) +{ + return ptr->get_uint16s (); +} + +mxUint32 * mxGetUint32s (const mxArray *ptr) +{ + return ptr->get_uint32s (); +} + +mxUint64 * mxGetUint64s (const mxArray *ptr) +{ + return ptr->get_uint64s (); +} + +mxComplexDouble * mxGetComplexDoubles (const mxArray *ptr) +{ + return ptr->get_complex_doubles (); +} + +mxComplexSingle * mxGetComplexSingles (const mxArray *ptr) +{ + return ptr->get_complex_singles (); +} + +#if 0 +/* We don't have these yet. */ +mxComplexInt8 * mxGetComplexInt8s (const mxArray *ptr) +{ + return ptr->get_complex_int8s (); +} + +mxComplexInt16 * mxGetComplexInt16s (const mxArray *ptr) +{ + return ptr->get_complex_int16s (); +} + +mxComplexInt32 * mxGetComplexInt32s (const mxArray *ptr) +{ + return ptr->get_complex_int32s (); +} + +mxComplexInt64 * mxGetComplexInt64s (const mxArray *ptr) +{ + return ptr->get_complex_int64s (); +} + +mxComplexUint8 * mxGetComplexUint8s (const mxArray *ptr) +{ + return ptr->get_complex_uint8s (); +} + +mxComplexUint16 * mxGetComplexUint16s (const mxArray *ptr) +{ + return ptr->get_complex_uint16s (); +} + +mxComplexUint32 * mxGetComplexUint32s (const mxArray *ptr) +{ + return ptr->get_complex_uint32s (); +} + +mxComplexUint64 * mxGetComplexUint64s (const mxArray *ptr) +{ + return ptr->get_complex_uint64s (); +} +#endif + // Data setters. void mxSetPr (mxArray *ptr, double *pr) @@ -2965,18 +3939,121 @@ } void +mxSetData (mxArray *ptr, void *pr) +{ + ptr->set_data (maybe_unmark (pr)); +} + +int mxSetDoubles (mxArray *ptr, mxDouble *data) +{ + return ptr->set_doubles (maybe_unmark (data)); +} + +int mxSetSingles (mxArray *ptr, mxSingle *data) +{ + return ptr->set_singles (maybe_unmark (data)); +} + +int mxSetInt8s (mxArray *ptr, mxInt8 *data) +{ + return ptr->set_int8s (maybe_unmark (data)); +} + +int mxSetInt16s (mxArray *ptr, mxInt16 *data) +{ + return ptr->set_int16s (maybe_unmark (data)); +} + +int mxSetInt32s (mxArray *ptr, mxInt32 *data) +{ + return ptr->set_int32s (maybe_unmark (data)); +} + +int mxSetInt64s (mxArray *ptr, mxInt64 *data) +{ + return ptr->set_int64s (maybe_unmark (data)); +} + +int mxSetUint8s (mxArray *ptr, mxUint8 *data) +{ + return ptr->set_uint8s (maybe_unmark (data)); +} + +int mxSetUint16s (mxArray *ptr, mxUint16 *data) +{ + return ptr->set_uint16s (maybe_unmark (data)); +} + +int mxSetUint32s (mxArray *ptr, mxUint32 *data) +{ + return ptr->set_uint32s (maybe_unmark (data)); +} + +int mxSetUint64s (mxArray *ptr, mxUint64 *data) +{ + return ptr->set_uint64s (maybe_unmark (data)); +} + +int mxSetComplexDoubles (mxArray *ptr, mxComplexDouble *data) +{ + return ptr->set_complex_doubles (maybe_unmark (data)); +} + +int mxSetComplexSingles (mxArray *ptr, mxComplexSingle *data) +{ + return ptr->set_complex_singles (maybe_unmark (data)); +} + +#if 0 +/* We don't have these yet. */ +int mxSetComplexInt8s (mxArray *ptr, mxComplexInt8 *data) +{ + return ptr->set_complex_int8s (maybe_unmark (data)); +} + +int mxSetComplexInt16s (mxArray *ptr, mxComplexInt16 *data) +{ + return ptr->set_complex_int16s (maybe_unmark (data)); +} + +int mxSetComplexInt32s (mxArray *ptr, mxComplexInt32 *data) +{ + return ptr->set_complex_int32s (maybe_unmark (data)); +} + +int mxSetComplexInt64s (mxArray *ptr, mxComplexInt64 *data) +{ + return ptr->set_complex_int64s (maybe_unmark (data)); +} + +int mxSetComplexUint8s (mxArray *ptr, mxComplexUint8 *data) +{ + return ptr->set_complex_uint8s (maybe_unmark (data)); +} + +int mxSetComplexUint16s (mxArray *ptr, mxComplexUint16 *data) +{ + return ptr->set_complex_uint16s (maybe_unmark (data)); +} + +int mxSetComplexUint32s (mxArray *ptr, mxComplexUint32 *data) +{ + return ptr->set_complex_uint32s (maybe_unmark (data)); +} + +int mxSetComplexUint64s (mxArray *ptr, mxComplexUint64 *data) +{ + return ptr->set_complex_uint64s (maybe_unmark (data)); +} +#endif + +void mxSetPi (mxArray *ptr, double *pi) { ptr->set_imag_data (maybe_unmark (pi)); } void -mxSetData (mxArray *ptr, void *pr) -{ - ptr->set_data (maybe_unmark (pr)); -} - -void mxSetImagData (mxArray *ptr, void *pi) { ptr->set_imag_data (maybe_unmark (pi)); @@ -3172,12 +4249,10 @@ for (int i = 0; i < nout; i++) argout[i] = nullptr; - octave::unwind_protect_safe frame; - // Save old mex pointer. - frame.protect_var (mex_context); - - mex context (&mex_fcn); + octave::unwind_protect_var restore_var (mex_context); + + mex context (mex_fcn); for (int i = 0; i < nargin; i++) argin[i] = context.make_value (args(i)); @@ -3619,17 +4694,28 @@ { if (mex_context) { - octave_mex_function *curr_mex_fcn = mex_context->current_mex_function (); - - assert (curr_mex_fcn); - - curr_mex_fcn->atexit (f); + octave_mex_function& curr_mex_fcn = mex_context->current_mex_function (); + + curr_mex_fcn.atexit (f); } return 0; } const mxArray * +mexGet_interleaved (double handle, const char *property) +{ + mxArray *m = nullptr; + + octave_value ret = get_property_from_handle (handle, property, "mexGet"); + + if (ret.is_defined ()) + m = ret.as_mxArray (true); + + return m; +} + +const mxArray * mexGet (double handle, const char *property) { mxArray *m = nullptr; @@ -3637,7 +4723,7 @@ octave_value ret = get_property_from_handle (handle, property, "mexGet"); if (ret.is_defined ()) - m = ret.as_mxArray (); + m = ret.as_mxArray (false); return m; } diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mexproto.h --- a/libinterp/corefcn/mexproto.h Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/mexproto.h Thu Nov 19 13:08:00 2020 -0800 @@ -61,10 +61,19 @@ # include #endif +#if ! defined (MX_HAS_INTERLEAVED_COMPLEX) +# define MX_HAS_INTERLEAVED_COMPLEX 0 +#endif + #define MXARRAY_TYPEDEFS_ONLY #include "mxarray.h" #undef MXARRAY_TYPEDEFS_ONLY +/* Prototype for the gateway function. */ + +extern void mexFunction (int nlhs, mxArray *plhs[], + int nrhs, const mxArray *prhs[]); + /* Interface to the interpreter. */ extern OCTINTERP_API const char * mexFunctionName (void); @@ -98,8 +107,12 @@ extern OCTINTERP_API int mexPutVariable (const char *space, const char *name, const mxArray *ptr); +#if MX_HAS_INTERLEAVED_COMPLEX +# define mexGet mexGet_interleaved +#endif extern OCTINTERP_API const mxArray * mexGet (double handle, const char *property); + extern OCTINTERP_API int mexSet (double handle, const char *property, mxArray *val); @@ -131,6 +144,27 @@ extern OCTINTERP_API void mxFree (void *ptr); /* Constructors. */ +#if MX_HAS_INTERLEAVED_COMPLEX +# define mxCreateCellArray mxCreateCellArray_interleaved +# define mxCreateCellMatrix mxCreateCellMatrix_interleaved +# define mxCreateCharArray mxCreateCharArray_interleaved +# define mxCreateCharMatrixFromStrings mxCreateCharMatrixFromStrings_interleaved +# define mxCreateDoubleMatrix mxCreateDoubleMatrix_interleaved +# define mxCreateDoubleScalar mxCreateDoubleScalar_interleaved +# define mxCreateLogicalArray mxCreateLogicalArray_interleaved +# define mxCreateLogicalMatrix mxCreateLogicalMatrix_interleaved +# define mxCreateLogicalScalar mxCreateLogicalScalar_interleaved +# define mxCreateNumericArray mxCreateNumericArray_interleaved +# define mxCreateNumericMatrix mxCreateNumericMatrix_interleaved +# define mxCreateUninitNumericArray mxCreateUninitNumericArray_interleaved +# define mxCreateUninitNumericMatrix mxCreateUninitNumericMatrix_interleaved +# define mxCreateSparse mxCreateSparse_interleaved +# define mxCreateSparseLogicalMatrix mxCreateSparseLogicalMatrix_interleaved +# define mxCreateString mxCreateString_interleaved +# define mxCreateStructArray mxCreateStructArray_interleaved +# define mxCreateStructMatrix mxCreateStructMatrix_interleaved +#endif + extern OCTINTERP_API mxArray * mxCreateCellArray (mwSize ndims, const mwSize *dims); extern OCTINTERP_API mxArray * mxCreateCellMatrix (mwSize m, mwSize n); @@ -227,20 +261,79 @@ extern OCTINTERP_API int mxSetDimensions (mxArray *ptr, const mwSize *dims, mwSize ndims); +#if MX_HAS_INTERLEAVED_COMPLEX +extern OCTINTERP_API int mxMakeArrayReal (mxArray *ptr); +extern OCTINTERP_API int mxMakeArrayComplex (mxArray *ptr); +#endif + /* Data extractors. */ -extern OCTINTERP_API double * mxGetPi (const mxArray *ptr); extern OCTINTERP_API double * mxGetPr (const mxArray *ptr); extern OCTINTERP_API double mxGetScalar (const mxArray *ptr); extern OCTINTERP_API mxChar * mxGetChars (const mxArray *ptr); extern OCTINTERP_API mxLogical * mxGetLogicals (const mxArray *ptr); extern OCTINTERP_API void * mxGetData (const mxArray *ptr); +#if MX_HAS_INTERLEAVED_COMPLEX +extern OCTINTERP_API mxDouble * mxGetDoubles (const mxArray *p); +extern OCTINTERP_API mxSingle * mxGetSingles (const mxArray *p); +extern OCTINTERP_API mxInt8 * mxGetInt8s (const mxArray *p); +extern OCTINTERP_API mxInt16 * mxGetInt16s (const mxArray *p); +extern OCTINTERP_API mxInt32 * mxGetInt32s (const mxArray *p); +extern OCTINTERP_API mxInt64 * mxGetInt64s (const mxArray *p); +extern OCTINTERP_API mxUint8 * mxGetUint8s (const mxArray *p); +extern OCTINTERP_API mxUint16 * mxGetUint16s (const mxArray *p); +extern OCTINTERP_API mxUint32 * mxGetUint32s (const mxArray *p); +extern OCTINTERP_API mxUint64 * mxGetUint64s (const mxArray *p); + +extern OCTINTERP_API mxComplexDouble * mxGetComplexDoubles (const mxArray *p); +extern OCTINTERP_API mxComplexSingle * mxGetComplexSingles (const mxArray *p); +#if 0 +/* We don't have these yet. */ +extern OCTINTERP_API mxComplexInt8 * mxGetComplexInt8s (const mxArray *p); +extern OCTINTERP_API mxComplexInt16 * mxGetComplexInt16s (const mxArray *p); +extern OCTINTERP_API mxComplexInt32 * mxGetComplexInt32s (const mxArray *p); +extern OCTINTERP_API mxComplexInt64 * mxGetComplexInt64s (const mxArray *p); +extern OCTINTERP_API mxComplexUint8 * mxGetComplexUint8s (const mxArray *p); +extern OCTINTERP_API mxComplexUint16 * mxGetComplexUint16s (const mxArray *p); +extern OCTINTERP_API mxComplexUint32 * mxGetComplexUint32s (const mxArray *p); +extern OCTINTERP_API mxComplexUint64 * mxGetComplexUint64s (const mxArray *p); +#endif +#else +extern OCTINTERP_API double * mxGetPi (const mxArray *ptr); extern OCTINTERP_API void * mxGetImagData (const mxArray *ptr); +#endif /* Data setters. */ extern OCTINTERP_API void mxSetPr (mxArray *ptr, double *pr); +extern OCTINTERP_API void mxSetData (mxArray *ptr, void *data); +#if MX_HAS_INTERLEAVED_COMPLEX +extern OCTINTERP_API int mxSetDoubles (mxArray *p, mxDouble *d); +extern OCTINTERP_API int mxSetSingles (mxArray *p, mxSingle *d); +extern OCTINTERP_API int mxSetInt8s (mxArray *p, mxInt8 *d); +extern OCTINTERP_API int mxSetInt16s (mxArray *p, mxInt16 *d); +extern OCTINTERP_API int mxSetInt32s (mxArray *p, mxInt32 *d); +extern OCTINTERP_API int mxSetInt64s (mxArray *p, mxInt64 *d); +extern OCTINTERP_API int mxSetUint8s (mxArray *p, mxUint8 *d); +extern OCTINTERP_API int mxSetUint16s (mxArray *p, mxUint16 *d); +extern OCTINTERP_API int mxSetUint32s (mxArray *p, mxUint32 *d); +extern OCTINTERP_API int mxSetUint64s (mxArray *p, mxUint64 *d); + +extern OCTINTERP_API int mxSetComplexDoubles (mxArray *p, mxComplexDouble *d); +extern OCTINTERP_API int mxSetComplexSingles (mxArray *p, mxComplexSingle *d); +#if 0 +/* We don't have these yet. */ +extern OCTINTERP_API int mxSetComplexInt8s (mxArray *p, mxComplexInt8 *d); +extern OCTINTERP_API int mxSetComplexInt16s (mxArray *p, mxComplexInt16 *d); +extern OCTINTERP_API int mxSetComplexInt32s (mxArray *p, mxComplexInt32 *d); +extern OCTINTERP_API int mxSetComplexInt64s (mxArray *p, mxComplexInt64 *d); +extern OCTINTERP_API int mxSetComplexUint8s (mxArray *p, mxComplexUint8 *d); +extern OCTINTERP_API int mxSetComplexUint16s (mxArray *p, mxComplexUint16 *d); +extern OCTINTERP_API int mxSetComplexUint32s (mxArray *p, mxComplexUint32 *d); +extern OCTINTERP_API int mxSetComplexUint64s (mxArray *p, mxComplexUint64 *d); +#endif +#else extern OCTINTERP_API void mxSetPi (mxArray *ptr, double *pi); -extern OCTINTERP_API void mxSetData (mxArray *ptr, void *data); extern OCTINTERP_API void mxSetImagData (mxArray *ptr, void *pi); +#endif /* Classes. */ extern OCTINTERP_API mxClassID mxGetClassID (const mxArray *ptr); diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mk-mxarray-h.in.sh --- a/libinterp/corefcn/mk-mxarray-h.in.sh Thu Nov 19 13:05:51 2020 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -#! /bin/sh -# -######################################################################## -# -# Copyright (C) 2016-2020 The Octave Project Developers -# -# See the file COPYRIGHT.md in the top-level directory of this -# distribution or . -# -# This file is part of Octave. -# -# Octave is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Octave is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Octave; see the file COPYING. If not, see -# . -# -######################################################################## - -: ${SED=@SED@} - -OCTAVE_IDX_TYPE="@OCTAVE_IDX_TYPE@" - -$SED \ - -e "s|%NO_EDIT_WARNING%|DO NOT EDIT! Generated automatically by mx-mxarray-h.|" \ - -e "s|%OCTAVE_IDX_TYPE%|${OCTAVE_IDX_TYPE}|" diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mk-mxtypes-h.in.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/mk-mxtypes-h.in.sh Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,34 @@ +#! /bin/sh +# +######################################################################## +# +# Copyright (C) 2016-2020 The Octave Project Developers +# +# See the file COPYRIGHT.md in the top-level directory of this +# distribution or . +# +# This file is part of Octave. +# +# Octave is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Octave is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Octave; see the file COPYING. If not, see +# . +# +######################################################################## + +: ${SED=@SED@} + +OCTAVE_IDX_TYPE="@OCTAVE_IDX_TYPE@" + +$SED \ + -e "s|%NO_EDIT_WARNING%|DO NOT EDIT! Generated automatically by mx-mxtypes-h.sh|" \ + -e "s|%OCTAVE_IDX_TYPE%|${OCTAVE_IDX_TYPE}|" diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/module.mk --- a/libinterp/corefcn/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -58,6 +58,8 @@ %reldir%/ls-utils.h \ %reldir%/mex.h \ %reldir%/mexproto.h \ + %reldir%/mx-type-traits.h \ + %reldir%/mxarray.h \ %reldir%/oct-errno.h \ %reldir%/oct-fstrm.h \ %reldir%/oct-handle.h \ @@ -89,7 +91,6 @@ %reldir%/sysdep.h \ %reldir%/text-engine.h \ %reldir%/text-renderer.h \ - %reldir%/txt-eng.h \ %reldir%/url-handle-manager.h \ %reldir%/utils.h \ %reldir%/variables.h \ @@ -185,6 +186,8 @@ %reldir%/interpreter-private.cc \ %reldir%/interpreter.cc \ %reldir%/inv.cc \ + %reldir%/jsondecode.cc \ + %reldir%/jsonencode.cc \ %reldir%/kron.cc \ %reldir%/load-path.cc \ %reldir%/load-save.cc \ @@ -218,6 +221,7 @@ %reldir%/oct-tex-lexer.ll \ %reldir%/oct-tex-parser.h \ %reldir%/oct-tex-parser.yy \ + %reldir%/ordqz.cc \ %reldir%/ordschur.cc \ %reldir%/pager.cc \ %reldir%/pinv.cc \ @@ -298,8 +302,8 @@ fi && \ mv $@-t $@ -%reldir%/mxarray.h: %reldir%/mxarray.in.h %reldir%/mk-mxarray-h.sh | %reldir%/$(octave_dirstamp) - $(AM_V_GEN)$(call simple-filter-rule,%reldir%/mk-mxarray-h.sh) +%reldir%/mxtypes.h: %reldir%/mxtypes.in.h %reldir%/mk-mxtypes-h.sh | %reldir%/$(octave_dirstamp) + $(AM_V_GEN)$(call simple-filter-rule,%reldir%/mk-mxtypes-h.sh) %reldir%/oct-tex-lexer.ll: %reldir%/oct-tex-lexer.in.ll %reldir%/oct-tex-symbols.in | %reldir%/$(octave_dirstamp) $(AM_V_GEN)rm -f $@-t && \ @@ -332,11 +336,11 @@ %reldir%/genprops.awk \ %reldir%/graphics.in.h \ %reldir%/mk-errno-list.sh \ - %reldir%/mk-mxarray-h.in.sh \ - %reldir%/mxarray.in.h \ + %reldir%/mk-mxtypes-h.in.sh \ + %reldir%/mxtypes.in.h \ %reldir%/oct-errno.in.cc \ %reldir%/oct-tex-lexer.in.ll \ %reldir%/oct-tex-symbols.in GEN_CONFIG_SHELL += \ - %reldir%/mk-mxarray-h.sh + %reldir%/mk-mxtypes-h.sh diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mx-type-traits.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/mx-type-traits.h Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,151 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_mx_type_traits_h) +#define octave_mx_type_traits_h 1 + +#include "octave-config.h" + +#include "mxtypes.h" +#include "oct-inttypes.h" + +template +class +mx_type_traits +{ +public: + static const mxClassID mx_class; + typedef T mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxLOGICAL_CLASS; + typedef mxDouble mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxCHAR_CLASS; + typedef mxChar mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxDOUBLE_CLASS; + typedef mxDouble mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxSINGLE_CLASS; + typedef mxSingle mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxINT8_CLASS; + typedef mxInt8 mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxUINT8_CLASS; + typedef mxUint8 mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxINT16_CLASS; + typedef mxInt16 mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxUINT16_CLASS; + typedef mxUint16 mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxINT32_CLASS; + typedef mxInt32 mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxUINT32_CLASS; + typedef mxUint32 mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxINT64_CLASS; + typedef mxInt64 mx_type; +}; + +template <> +class +mx_type_traits +{ +public: + static const mxClassID mx_class = mxUINT64_CLASS; + typedef mxUint64 mx_type; +}; + +#endif diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mxarray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/mxarray.h Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,746 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2001-2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +/* + +Part of this code was originally distributed as part of Octave Forge under +the following terms: + +Author: Paul Kienzle +I grant this code to the public domain. +2001-03-22 + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +*/ + +#if ! defined (octave_mxarray_h) +#define octave_mxarray_h 1 + +#include "octave-config.h" + +#include "mxtypes.h" + +#if ! defined (MXARRAY_TYPEDEFS_ONLY) + +#include +#include "error.h" + +class octave_value; +class dim_vector; + +#define DO_MUTABLE_METHOD(RET_T, METHOD_CALL) \ + RET_T retval = rep->METHOD_CALL; \ + \ + if (rep->mutation_needed ()) \ + { \ + maybe_mutate (); \ + retval = rep->METHOD_CALL; \ + } \ + \ + return retval + +#define DO_VOID_MUTABLE_METHOD(METHOD_CALL) \ + rep->METHOD_CALL; \ + \ + if (rep->mutation_needed ()) \ + { \ + maybe_mutate (); \ + rep->METHOD_CALL; \ + } + +class mxArray; + +// A class to provide the default implementation of some of the +// virtual functions declared in the mxArray class. + +class mxArray_base +{ +protected: + + mxArray_base (bool interleaved); + +public: + + virtual mxArray_base * dup (void) const = 0; + + virtual mxArray * as_mxArray (void) const { return nullptr; } + + virtual ~mxArray_base (void) = default; + + virtual bool is_octave_value (void) const { return false; } + + virtual int iscell (void) const = 0; + + virtual int is_char (void) const = 0; + + virtual int is_class (const char *name_arg) const + { + int retval = 0; + + const char *cname = get_class_name (); + + if (cname && name_arg) + retval = ! strcmp (cname, name_arg); + + return retval; + } + + virtual int is_complex (void) const = 0; + + virtual int is_double (void) const = 0; + + virtual int is_function_handle (void) const = 0; + + virtual int is_int16 (void) const = 0; + + virtual int is_int32 (void) const = 0; + + virtual int is_int64 (void) const = 0; + + virtual int is_int8 (void) const = 0; + + virtual int is_logical (void) const = 0; + + virtual int is_numeric (void) const = 0; + + virtual int is_single (void) const = 0; + + virtual int is_sparse (void) const = 0; + + virtual int is_struct (void) const = 0; + + virtual int is_uint16 (void) const = 0; + + virtual int is_uint32 (void) const = 0; + + virtual int is_uint64 (void) const = 0; + + virtual int is_uint8 (void) const = 0; + + virtual int is_logical_scalar (void) const + { + return is_logical () && get_number_of_elements () == 1; + } + + virtual int is_logical_scalar_true (void) const = 0; + + virtual mwSize get_m (void) const = 0; + + virtual mwSize get_n (void) const = 0; + + virtual mwSize * get_dimensions (void) const = 0; + + virtual mwSize get_number_of_dimensions (void) const = 0; + + virtual void set_m (mwSize m) = 0; + + virtual void set_n (mwSize n) = 0; + + virtual int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) = 0; + + virtual mwSize get_number_of_elements (void) const = 0; + + virtual int isempty (void) const = 0; + + virtual bool is_scalar (void) const = 0; + + virtual mxClassID get_class_id (void) const = 0; + + virtual const char * get_class_name (void) const = 0; + + virtual void set_class_name (const char *name_arg) = 0; + + // The following functions aren't pure virtual because they are only + // valid for one type. Making them pure virtual would mean that they + // have to be implemented for all derived types, and all of those + // would need to throw errors instead of just doing it once here. + + virtual mxArray * + get_property (mwIndex /*idx*/, const char * /*pname*/) const + { + return nullptr; + } + + virtual void set_property (mwIndex /*idx*/, const char * /*pname*/, + const mxArray * /*pval*/) + { + err_invalid_type ("set_property"); + } + + virtual mxArray * get_cell (mwIndex /*idx*/) const + { + err_invalid_type ("get_cell"); + } + + virtual void set_cell (mwIndex idx, mxArray *val) = 0; + + virtual double get_scalar (void) const = 0; + + virtual void * get_data (void) const = 0; + + virtual mxDouble * get_doubles (void) const = 0; + virtual mxSingle * get_singles (void) const = 0; + virtual mxInt8 * get_int8s (void) const = 0; + virtual mxInt16 * get_int16s (void) const = 0; + virtual mxInt32 * get_int32s (void) const = 0; + virtual mxInt64 * get_int64s (void) const = 0; + virtual mxUint8 * get_uint8s (void) const = 0; + virtual mxUint16 * get_uint16s (void) const = 0; + virtual mxUint32 * get_uint32s (void) const = 0; + virtual mxUint64 * get_uint64s (void) const = 0; + + virtual mxComplexDouble * get_complex_doubles (void) const = 0; + virtual mxComplexSingle * get_complex_singles (void) const = 0; +#if 0 + /* We don't have these yet. */ + virtual mxComplexInt8 * get_complex_int8s (void) const = 0; + virtual mxComplexInt16 * get_complex_int16s (void) const = 0; + virtual mxComplexInt32 * get_complex_int32s (void) const = 0; + virtual mxComplexInt64 * get_complex_int64s (void) const = 0; + virtual mxComplexUint8 * get_complex_uint8s (void) const = 0; + virtual mxComplexUint16 * get_complex_uint16s (void) const = 0; + virtual mxComplexUint32 * get_complex_uint32s (void) const = 0; + virtual mxComplexUint64 * get_complex_uint64s (void) const = 0; +#endif + + virtual void * get_imag_data (void) const = 0; + + virtual void set_data (void *pr) = 0; + + virtual int set_doubles (mxDouble *data) = 0; + virtual int set_singles (mxSingle *data) = 0; + virtual int set_int8s (mxInt8 *data) = 0; + virtual int set_int16s (mxInt16 *data) = 0; + virtual int set_int32s (mxInt32 *data) = 0; + virtual int set_int64s (mxInt64 *data) = 0; + virtual int set_uint8s (mxUint8 *data) = 0; + virtual int set_uint16s (mxUint16 *data) = 0; + virtual int set_uint32s (mxUint32 *data) = 0; + virtual int set_uint64s (mxUint64 *data) = 0; + + virtual int set_complex_doubles (mxComplexDouble *data) = 0; + virtual int set_complex_singles (mxComplexSingle *data) = 0; +#if 0 + /* We don't have these yet. */ + virtual int set_complex_int8s (mxComplexInt8 *data) = 0; + virtual int set_complex_int16s (mxComplexInt16 *data) = 0; + virtual int set_complex_int32s (mxComplexInt32 *data) = 0; + virtual int set_complex_int64s (mxComplexInt64 *data) = 0; + virtual int set_complex_uint8s (mxComplexUint8 *data) = 0; + virtual int set_complex_uint16s (mxComplexUint16 *data) = 0; + virtual int set_complex_uint32s (mxComplexUint32 *data) = 0; + virtual int set_complex_uint64s (mxComplexUint64 *data) = 0; +#endif + + virtual void set_imag_data (void *pi) = 0; + + virtual mwIndex * get_ir (void) const = 0; + + virtual mwIndex * get_jc (void) const = 0; + + virtual mwSize get_nzmax (void) const = 0; + + virtual void set_ir (mwIndex *ir) = 0; + + virtual void set_jc (mwIndex *jc) = 0; + + virtual void set_nzmax (mwSize nzmax) = 0; + + virtual int add_field (const char *key) = 0; + + virtual void remove_field (int key_num) = 0; + + virtual mxArray * get_field_by_number (mwIndex index, int key_num) const = 0; + + virtual void + set_field_by_number (mwIndex index, int key_num, mxArray *val) = 0; + + virtual int get_number_of_fields (void) const = 0; + + virtual const char * get_field_name_by_number (int key_num) const = 0; + + virtual int get_field_number (const char *key) const = 0; + + virtual int get_string (char *buf, mwSize buflen) const = 0; + + virtual char * array_to_string (void) const = 0; + + virtual mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const = 0; + + virtual size_t get_element_size (void) const = 0; + + virtual bool mutation_needed (void) const { return false; } + + virtual mxArray * mutate (void) const { return nullptr; } + + virtual octave_value as_octave_value (void) const = 0; + +protected: + + // If TRUE, we are using interleaved storage for complex numeric arrays. + bool m_interleaved; + + mxArray_base (const mxArray_base&) = default; + + size_t get_numeric_element_size (size_t size) const + { + return (m_interleaved + ? is_complex () ? 2 * size : size + : size); + } + + OCTAVE_NORETURN void err_invalid_type (const char *op) const + { + error ("%s: invalid type for mxArray::%s", get_class_name (), op); + } +}; + +// The main interface class. The representation can be based on an +// octave_value object or a separate object that tries to reproduce +// the semantics of mxArray objects in Matlab more directly. + +class mxArray +{ +public: + + mxArray (bool interleaved, const octave_value& ov); + + mxArray (bool interleaved, mxClassID id, mwSize ndims, const mwSize *dims, + mxComplexity flag = mxREAL, bool init = true); + + mxArray (bool interleaved, mxClassID id, const dim_vector& dv, + mxComplexity flag = mxREAL); + + mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n, + mxComplexity flag = mxREAL, bool init = true); + + mxArray (bool interleaved, mxClassID id, double val); + + mxArray (bool interleaved, mxClassID id, mxLogical val); + + mxArray (bool interleaved, const char *str); + + mxArray (bool interleaved, mwSize m, const char **str); + + mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n, mwSize nzmax, + mxComplexity flag = mxREAL); + + mxArray (bool interleaved, mwSize ndims, const mwSize *dims, int num_keys, + const char **keys); + + mxArray (bool interleaved, const dim_vector& dv, int num_keys, + const char **keys); + + mxArray (bool interleaved, mwSize m, mwSize n, int num_keys, + const char **keys); + + mxArray (bool interleaved, mwSize ndims, const mwSize *dims); + + mxArray (bool interleaved, const dim_vector& dv); + + mxArray (bool interleaved, mwSize m, mwSize n); + + mxArray * dup (void) const + { + mxArray *retval = rep->as_mxArray (); + + if (retval) + retval->set_name (name); + else + { + mxArray_base *new_rep = rep->dup (); + + retval = new mxArray (new_rep, name); + } + + return retval; + } + + // No copying! + + mxArray (const mxArray&) = delete; + + mxArray& operator = (const mxArray&) = delete; + + ~mxArray (void); + + bool is_octave_value (void) const { return rep->is_octave_value (); } + + int iscell (void) const { return rep->iscell (); } + + int is_char (void) const { return rep->is_char (); } + + int is_class (const char *name_arg) const { return rep->is_class (name_arg); } + + int is_complex (void) const { return rep->is_complex (); } + + int is_double (void) const { return rep->is_double (); } + + int is_function_handle (void) const { return rep->is_function_handle (); } + + int is_int16 (void) const { return rep->is_int16 (); } + + int is_int32 (void) const { return rep->is_int32 (); } + + int is_int64 (void) const { return rep->is_int64 (); } + + int is_int8 (void) const { return rep->is_int8 (); } + + int is_logical (void) const { return rep->is_logical (); } + + int is_numeric (void) const { return rep->is_numeric (); } + + int is_single (void) const { return rep->is_single (); } + + int is_sparse (void) const { return rep->is_sparse (); } + + int is_struct (void) const { return rep->is_struct (); } + + int is_uint16 (void) const { return rep->is_uint16 (); } + + int is_uint32 (void) const { return rep->is_uint32 (); } + + int is_uint64 (void) const { return rep->is_uint64 (); } + + int is_uint8 (void) const { return rep->is_uint8 (); } + + int is_logical_scalar (void) const { return rep->is_logical_scalar (); } + + int is_logical_scalar_true (void) const + { return rep->is_logical_scalar_true (); } + + mwSize get_m (void) const { return rep->get_m (); } + + mwSize get_n (void) const { return rep->get_n (); } + + mwSize * get_dimensions (void) const { return rep->get_dimensions (); } + + mwSize get_number_of_dimensions (void) const + { return rep->get_number_of_dimensions (); } + + void set_m (mwSize m) { DO_VOID_MUTABLE_METHOD (set_m (m)); } + + void set_n (mwSize n) { DO_VOID_MUTABLE_METHOD (set_n (n)); } + + int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) + { DO_MUTABLE_METHOD (int, set_dimensions (dims_arg, ndims_arg)); } + + mwSize get_number_of_elements (void) const + { return rep->get_number_of_elements (); } + + int isempty (void) const { return get_number_of_elements () == 0; } + + bool is_scalar (void) const { return rep->is_scalar (); } + + const char * get_name (void) const { return name; } + + void set_name (const char *name_arg); + + mxClassID get_class_id (void) const { return rep->get_class_id (); } + + const char * get_class_name (void) const { return rep->get_class_name (); } + + mxArray * get_property (mwIndex idx, const char *pname) const + { return rep->get_property (idx, pname); } + + void set_property (mwIndex idx, const char *pname, const mxArray *pval) + { rep->set_property (idx, pname, pval); } + + void set_class_name (const char *name_arg) + { DO_VOID_MUTABLE_METHOD (set_class_name (name_arg)); } + + mxArray * get_cell (mwIndex idx) const + { DO_MUTABLE_METHOD (mxArray *, get_cell (idx)); } + + void set_cell (mwIndex idx, mxArray *val) + { DO_VOID_MUTABLE_METHOD (set_cell (idx, val)); } + + double get_scalar (void) const { return rep->get_scalar (); } + + void * get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); } + + mxDouble * get_doubles (void) const + { DO_MUTABLE_METHOD (mxDouble *, get_doubles ()); } + + mxSingle * get_singles (void) const + { DO_MUTABLE_METHOD (mxSingle *, get_singles ()); } + + mxInt8 * get_int8s (void) const + { DO_MUTABLE_METHOD (mxInt8 *, get_int8s ()); } + + mxInt16 * get_int16s (void) const + { DO_MUTABLE_METHOD (mxInt16 *, get_int16s ()); } + + mxInt32 * get_int32s (void) const + { DO_MUTABLE_METHOD (mxInt32 *, get_int32s ()); } + + mxInt64 * get_int64s (void) const + { DO_MUTABLE_METHOD (mxInt64 *, get_int64s ()); } + + mxUint8 * get_uint8s (void) const + { DO_MUTABLE_METHOD (mxUint8 *, get_uint8s ()); } + + mxUint16 * get_uint16s (void) const + { DO_MUTABLE_METHOD (mxUint16 *, get_uint16s ()); } + + mxUint32 * get_uint32s (void) const + { DO_MUTABLE_METHOD (mxUint32 *, get_uint32s ()); } + + mxUint64 * get_uint64s (void) const + { DO_MUTABLE_METHOD (mxUint64 *, get_uint64s ()); } + + mxComplexDouble * get_complex_doubles (void) const + { DO_MUTABLE_METHOD (mxComplexDouble *, get_complex_doubles ()); } + + mxComplexSingle * get_complex_singles (void) const + { DO_MUTABLE_METHOD (mxComplexSingle *, get_complex_singles ()); } + +#if 0 + /* We don't have these yet. */ + mxComplexInt8 * get_complex_int8s (void) const + { DO_MUTABLE_METHOD (mxComplexInt8 *, get_complex_int8s ()); } + + mxComplexInt16 * get_complex_int16s (void) const + { DO_MUTABLE_METHOD (mxComplexInt16 *, get_complex_int16s ()); } + + mxComplexInt32 * get_complex_int32s (void) const + { DO_MUTABLE_METHOD (mxComplexInt32 *, get_complex_int32s ()); } + + mxComplexInt64 * get_complex_int64s (void) const + { DO_MUTABLE_METHOD (mxComplexInt64 *, get_complex_int64s ()); } + + mxComplexUint8 * get_complex_uint8s (void) const + { DO_MUTABLE_METHOD (mxComplexUint8 *, get_complex_uint8s ()); } + + mxComplexUint16 * get_complex_uint16s (void) const + { DO_MUTABLE_METHOD (mxComplexUint16 *, get_complex_uint16s ()); } + + mxComplexUint32 * get_complex_uint32s (void) const + { DO_MUTABLE_METHOD (mxComplexUint32 *, get_complex_uint32s ()); } + + mxComplexUint64 * get_complex_uint64s (void) const + { DO_MUTABLE_METHOD (mxComplexUint64 *, get_complex_uint64s ()); } +#endif + + void * get_imag_data (void) const + { DO_MUTABLE_METHOD (void *, get_imag_data ()); } + + void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); } + + int set_doubles (mxDouble *data) + { DO_MUTABLE_METHOD (int, set_doubles (data)); } + + int set_singles (mxSingle *data) + { DO_MUTABLE_METHOD (int, set_singles (data)); } + + int set_int8s (mxInt8 *data) + { DO_MUTABLE_METHOD (int, set_int8s (data)); } + + int set_int16s (mxInt16 *data) + { DO_MUTABLE_METHOD (int, set_int16s (data)); } + + int set_int32s (mxInt32 *data) + { DO_MUTABLE_METHOD (int, set_int32s (data)); } + + int set_int64s (mxInt64 *data) + { DO_MUTABLE_METHOD (int, set_int64s (data)); } + + int set_uint8s (mxUint8 *data) + { DO_MUTABLE_METHOD (int, set_uint8s (data)); } + + int set_uint16s (mxUint16 *data) + { DO_MUTABLE_METHOD (int, set_uint16s (data)); } + + int set_uint32s (mxUint32 *data) + { DO_MUTABLE_METHOD (int, set_uint32s (data)); } + + int set_uint64s (mxUint64 *data) + { DO_MUTABLE_METHOD (int, set_uint64s (data)); } + + int set_complex_doubles (mxComplexDouble *data) + { DO_MUTABLE_METHOD (int, set_complex_doubles (data)); } + + int set_complex_singles (mxComplexSingle *data) + { DO_MUTABLE_METHOD (int, set_complex_singles (data)); } + +#if 0 + /* We don't have these yet. */ + int set_complex_int8s (mxComplexInt8 *data) + { DO_MUTABLE_METHOD (int, set_complex_int8s (data)); } + + int set_complex_int16s (mxComplexInt16 *data) + { DO_MUTABLE_METHOD (int, set_complex_int16s (data)); } + + int set_complex_int32s (mxComplexInt32 *data) + { DO_MUTABLE_METHOD (int, set_complex_int32s (data)); } + + int set_complex_int64s (mxComplexInt64 *data) + { DO_MUTABLE_METHOD (int, set_complex_int64s (data)); } + + int set_complex_uint8s (mxComplexUint8 *data) + { DO_MUTABLE_METHOD (int, set_complex_uint8s (data)); } + + int set_complex_uint16s (mxComplexUint16 *data) + { DO_MUTABLE_METHOD (int, set_complex_uint16s (data)); } + + int set_complex_uint32s (mxComplexUint32 *data) + { DO_MUTABLE_METHOD (int, set_complex_uint32s (data)); } + + int set_complex_uint64s (mxComplexUint64 *data) + { DO_MUTABLE_METHOD (int, set_complex_uint64s (data)); } +#endif + + void set_imag_data (void *pi) { DO_VOID_MUTABLE_METHOD (set_imag_data (pi)); } + + mwIndex * get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); } + + mwIndex * get_jc (void) const { DO_MUTABLE_METHOD (mwIndex *, get_jc ()); } + + mwSize get_nzmax (void) const { return rep->get_nzmax (); } + + void set_ir (mwIndex *ir) { DO_VOID_MUTABLE_METHOD (set_ir (ir)); } + + void set_jc (mwIndex *jc) { DO_VOID_MUTABLE_METHOD (set_jc (jc)); } + + void set_nzmax (mwSize nzmax) { DO_VOID_MUTABLE_METHOD (set_nzmax (nzmax)); } + + int add_field (const char *key) { DO_MUTABLE_METHOD (int, add_field (key)); } + + void remove_field (int key_num) + { DO_VOID_MUTABLE_METHOD (remove_field (key_num)); } + + mxArray * get_field_by_number (mwIndex index, int key_num) const + { DO_MUTABLE_METHOD (mxArray *, get_field_by_number (index, key_num)); } + + void set_field_by_number (mwIndex index, int key_num, mxArray *val) + { DO_VOID_MUTABLE_METHOD (set_field_by_number (index, key_num, val)); } + + int get_number_of_fields (void) const { return rep->get_number_of_fields (); } + + const char * get_field_name_by_number (int key_num) const + { DO_MUTABLE_METHOD (const char*, get_field_name_by_number (key_num)); } + + int get_field_number (const char *key) const + { DO_MUTABLE_METHOD (int, get_field_number (key)); } + + int get_string (char *buf, mwSize buflen) const + { return rep->get_string (buf, buflen); } + + char * array_to_string (void) const { return rep->array_to_string (); } + + mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const + { return rep->calc_single_subscript (nsubs, subs); } + + size_t get_element_size (void) const { return rep->get_element_size (); } + + bool mutation_needed (void) const { return rep->mutation_needed (); } + + mxArray * mutate (void) const { return rep->mutate (); } + + static void * malloc (size_t n); + + static void * calloc (size_t n, size_t t); + + static char * strsave (const char *str) + { + char *retval = nullptr; + + if (str) + { + mwSize sz = sizeof (mxChar) * (strlen (str) + 1); + + retval = static_cast (mxArray::malloc (sz)); + + if (retval) + strcpy (retval, str); + } + + return retval; + } + + static octave_value + as_octave_value (const mxArray *ptr, bool null_is_empty = true); + + octave_value as_octave_value (void) const; + +private: + + mutable mxArray_base *rep; + + char *name; + + mxArray (mxArray_base *r, const char *n) + : rep (r), name (mxArray::strsave (n)) { } + + static mxArray_base * + create_rep (bool interleaved, const octave_value& ov); + + static mxArray_base * + create_rep (bool interleaved, mxClassID id, mwSize ndims, + const mwSize *dims, mxComplexity flag, bool init); + + static mxArray_base * + create_rep (bool interleaved, mxClassID id, const dim_vector& dv, + mxComplexity flag); + + static mxArray_base * + create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n, + mxComplexity flag, bool init); + + static mxArray_base * + create_rep (bool interleaved, mxClassID id, double val); + + static mxArray_base * + create_rep (bool interleaved, mxClassID id, mxLogical val); + + static mxArray_base * + create_rep (bool interleaved, const char *str); + + static mxArray_base * + create_rep (bool interleaved, mwSize m, const char **str); + + static mxArray_base * + create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n, + mwSize nzmax, mxComplexity flag); + + void maybe_mutate (void) const; +}; + +#undef DO_MUTABLE_METHOD +#undef DO_VOID_MUTABLE_METHOD + +#endif +#endif diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mxarray.in.h --- a/libinterp/corefcn/mxarray.in.h Thu Nov 19 13:05:51 2020 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,570 +0,0 @@ -// %NO_EDIT_WARNING% - -//////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2001-2020 The Octave Project Developers -// -// See the file COPYRIGHT.md in the top-level directory of this -// distribution or . -// -// This file is part of Octave. -// -// Octave is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Octave is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Octave; see the file COPYING. If not, see -// . -// -//////////////////////////////////////////////////////////////////////// - -/* - -Part of this code was originally distributed as part of Octave Forge under -the following terms: - -Author: Paul Kienzle -I grant this code to the public domain. -2001-03-22 - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -*/ - -#if ! defined (octave_mxarray_h) -#define octave_mxarray_h 1 - -#include "octave-config.h" - -typedef enum -{ - mxUNKNOWN_CLASS = 0, - mxCELL_CLASS, - mxSTRUCT_CLASS, - mxLOGICAL_CLASS, - mxCHAR_CLASS, - mxVOID_CLASS, - mxDOUBLE_CLASS, - mxSINGLE_CLASS, - mxINT8_CLASS, - mxUINT8_CLASS, - mxINT16_CLASS, - mxUINT16_CLASS, - mxINT32_CLASS, - mxUINT32_CLASS, - mxINT64_CLASS, - mxUINT64_CLASS, - mxFUNCTION_CLASS -} -mxClassID; - -typedef enum -{ - mxREAL = 0, - mxCOMPLEX = 1 -} -mxComplexity; - -/* Matlab uses a wide char (uint16) internally, but Octave uses plain char. */ -/* typedef Uint16 mxChar; */ -typedef char mxChar; - -typedef unsigned char mxLogical; - -/* - * FIXME: Mathworks says mwSize, mwIndex should be int generally. - * But on 64-bit systems, or when mex -largeArrayDims is used, it is size_t. - * mwSignedIndex is supposed to be ptrdiff_t. All of this is confusing. - * Its better to conform to the same indexing as the rest of Octave. - */ -typedef %OCTAVE_IDX_TYPE% mwSize; -typedef %OCTAVE_IDX_TYPE% mwIndex; -typedef %OCTAVE_IDX_TYPE% mwSignedIndex; - -#if ! defined (MXARRAY_TYPEDEFS_ONLY) - -#include -#include "error.h" - -class octave_value; -class dim_vector; - -#define DO_MUTABLE_METHOD(RET_T, METHOD_CALL) \ - RET_T retval = rep->METHOD_CALL; \ - \ - if (rep->mutation_needed ()) \ - { \ - maybe_mutate (); \ - retval = rep->METHOD_CALL; \ - } \ - \ - return retval - -#define DO_VOID_MUTABLE_METHOD(METHOD_CALL) \ - rep->METHOD_CALL; \ - \ - if (rep->mutation_needed ()) \ - { \ - maybe_mutate (); \ - rep->METHOD_CALL; \ - } - -class mxArray; - -// A class to provide the default implementation of some of the -// virtual functions declared in the mxArray class. - -class mxArray_base -{ -protected: - - mxArray_base (void) { } - -public: - - virtual mxArray_base * dup (void) const = 0; - - virtual mxArray * as_mxArray (void) const { return nullptr; } - - virtual ~mxArray_base (void) = default; - - virtual bool is_octave_value (void) const { return false; } - - virtual int iscell (void) const = 0; - - virtual int is_char (void) const = 0; - - virtual int is_class (const char *name_arg) const - { - int retval = 0; - - const char *cname = get_class_name (); - - if (cname && name_arg) - retval = ! strcmp (cname, name_arg); - - return retval; - } - - virtual int is_complex (void) const = 0; - - virtual int is_double (void) const = 0; - - virtual int is_function_handle (void) const = 0; - - virtual int is_int16 (void) const = 0; - - virtual int is_int32 (void) const = 0; - - virtual int is_int64 (void) const = 0; - - virtual int is_int8 (void) const = 0; - - virtual int is_logical (void) const = 0; - - virtual int is_numeric (void) const = 0; - - virtual int is_single (void) const = 0; - - virtual int is_sparse (void) const = 0; - - virtual int is_struct (void) const = 0; - - virtual int is_uint16 (void) const = 0; - - virtual int is_uint32 (void) const = 0; - - virtual int is_uint64 (void) const = 0; - - virtual int is_uint8 (void) const = 0; - - virtual int is_logical_scalar (void) const - { - return is_logical () && get_number_of_elements () == 1; - } - - virtual int is_logical_scalar_true (void) const = 0; - - virtual mwSize get_m (void) const = 0; - - virtual mwSize get_n (void) const = 0; - - virtual mwSize * get_dimensions (void) const = 0; - - virtual mwSize get_number_of_dimensions (void) const = 0; - - virtual void set_m (mwSize m) = 0; - - virtual void set_n (mwSize n) = 0; - - virtual int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) = 0; - - virtual mwSize get_number_of_elements (void) const = 0; - - virtual int isempty (void) const = 0; - - virtual bool is_scalar (void) const = 0; - - virtual mxClassID get_class_id (void) const = 0; - - virtual const char * get_class_name (void) const = 0; - - virtual void set_class_name (const char *name_arg) = 0; - - // The following functions aren't pure virtual because they are only - // valid for one type. Making them pure virtual would mean that they - // have to be implemented for all derived types, and all of those - // would need to throw errors instead of just doing it once here. - - virtual mxArray * - get_property (mwIndex /*idx*/, const char * /*pname*/) const - { - return nullptr; - } - - virtual void set_property (mwIndex /*idx*/, const char * /*pname*/, - const mxArray * /*pval*/) - { - err_invalid_type (); - } - - virtual mxArray * get_cell (mwIndex /*idx*/) const - { - err_invalid_type (); - } - - virtual void set_cell (mwIndex idx, mxArray *val) = 0; - - virtual double get_scalar (void) const = 0; - - virtual void * get_data (void) const = 0; - - virtual void * get_imag_data (void) const = 0; - - virtual void set_data (void *pr) = 0; - - virtual void set_imag_data (void *pi) = 0; - - virtual mwIndex * get_ir (void) const = 0; - - virtual mwIndex * get_jc (void) const = 0; - - virtual mwSize get_nzmax (void) const = 0; - - virtual void set_ir (mwIndex *ir) = 0; - - virtual void set_jc (mwIndex *jc) = 0; - - virtual void set_nzmax (mwSize nzmax) = 0; - - virtual int add_field (const char *key) = 0; - - virtual void remove_field (int key_num) = 0; - - virtual mxArray * get_field_by_number (mwIndex index, int key_num) const = 0; - - virtual void - set_field_by_number (mwIndex index, int key_num, mxArray *val) = 0; - - virtual int get_number_of_fields (void) const = 0; - - virtual const char * get_field_name_by_number (int key_num) const = 0; - - virtual int get_field_number (const char *key) const = 0; - - virtual int get_string (char *buf, mwSize buflen) const = 0; - - virtual char * array_to_string (void) const = 0; - - virtual mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const = 0; - - virtual size_t get_element_size (void) const = 0; - - virtual bool mutation_needed (void) const { return false; } - - virtual mxArray * mutate (void) const { return nullptr; } - - virtual octave_value as_octave_value (void) const = 0; - -protected: - - mxArray_base (const mxArray_base&) { } - - OCTAVE_NORETURN void err_invalid_type (void) const - { - error ("invalid type for operation"); - } -}; - -// The main interface class. The representation can be based on an -// octave_value object or a separate object that tries to reproduce -// the semantics of mxArray objects in Matlab more directly. - -class mxArray -{ -public: - - mxArray (const octave_value& ov); - - mxArray (mxClassID id, mwSize ndims, const mwSize *dims, - mxComplexity flag = mxREAL, bool init = true); - - mxArray (mxClassID id, const dim_vector& dv, mxComplexity flag = mxREAL); - - mxArray (mxClassID id, mwSize m, mwSize n, - mxComplexity flag = mxREAL, bool init = true); - - mxArray (mxClassID id, double val); - - mxArray (mxClassID id, mxLogical val); - - mxArray (const char *str); - - mxArray (mwSize m, const char **str); - - mxArray (mxClassID id, mwSize m, mwSize n, mwSize nzmax, - mxComplexity flag = mxREAL); - - mxArray (mwSize ndims, const mwSize *dims, int num_keys, const char **keys); - - mxArray (const dim_vector& dv, int num_keys, const char **keys); - - mxArray (mwSize m, mwSize n, int num_keys, const char **keys); - - mxArray (mwSize ndims, const mwSize *dims); - - mxArray (const dim_vector& dv); - - mxArray (mwSize m, mwSize n); - - mxArray * dup (void) const - { - mxArray *retval = rep->as_mxArray (); - - if (retval) - retval->set_name (name); - else - { - mxArray_base *new_rep = rep->dup (); - - retval = new mxArray (new_rep, name); - } - - return retval; - } - - // No copying! - - mxArray (const mxArray&) = delete; - - mxArray& operator = (const mxArray&) = delete; - - ~mxArray (void); - - bool is_octave_value (void) const { return rep->is_octave_value (); } - - int iscell (void) const { return rep->iscell (); } - - int is_char (void) const { return rep->is_char (); } - - int is_class (const char *name_arg) const { return rep->is_class (name_arg); } - - int is_complex (void) const { return rep->is_complex (); } - - int is_double (void) const { return rep->is_double (); } - - int is_function_handle (void) const { return rep->is_function_handle (); } - - int is_int16 (void) const { return rep->is_int16 (); } - - int is_int32 (void) const { return rep->is_int32 (); } - - int is_int64 (void) const { return rep->is_int64 (); } - - int is_int8 (void) const { return rep->is_int8 (); } - - int is_logical (void) const { return rep->is_logical (); } - - int is_numeric (void) const { return rep->is_numeric (); } - - int is_single (void) const { return rep->is_single (); } - - int is_sparse (void) const { return rep->is_sparse (); } - - int is_struct (void) const { return rep->is_struct (); } - - int is_uint16 (void) const { return rep->is_uint16 (); } - - int is_uint32 (void) const { return rep->is_uint32 (); } - - int is_uint64 (void) const { return rep->is_uint64 (); } - - int is_uint8 (void) const { return rep->is_uint8 (); } - - int is_logical_scalar (void) const { return rep->is_logical_scalar (); } - - int is_logical_scalar_true (void) const - { return rep->is_logical_scalar_true (); } - - mwSize get_m (void) const { return rep->get_m (); } - - mwSize get_n (void) const { return rep->get_n (); } - - mwSize * get_dimensions (void) const { return rep->get_dimensions (); } - - mwSize get_number_of_dimensions (void) const - { return rep->get_number_of_dimensions (); } - - void set_m (mwSize m) { DO_VOID_MUTABLE_METHOD (set_m (m)); } - - void set_n (mwSize n) { DO_VOID_MUTABLE_METHOD (set_n (n)); } - - int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) - { DO_MUTABLE_METHOD (int, set_dimensions (dims_arg, ndims_arg)); } - - mwSize get_number_of_elements (void) const - { return rep->get_number_of_elements (); } - - int isempty (void) const { return get_number_of_elements () == 0; } - - bool is_scalar (void) const { return rep->is_scalar (); } - - const char * get_name (void) const { return name; } - - void set_name (const char *name_arg); - - mxClassID get_class_id (void) const { return rep->get_class_id (); } - - const char * get_class_name (void) const { return rep->get_class_name (); } - - mxArray * get_property (mwIndex idx, const char *pname) const - { return rep->get_property (idx, pname); } - - void set_property (mwIndex idx, const char *pname, const mxArray *pval) - { rep->set_property (idx, pname, pval); } - - void set_class_name (const char *name_arg) - { DO_VOID_MUTABLE_METHOD (set_class_name (name_arg)); } - - mxArray * get_cell (mwIndex idx) const - { DO_MUTABLE_METHOD (mxArray *, get_cell (idx)); } - - void set_cell (mwIndex idx, mxArray *val) - { DO_VOID_MUTABLE_METHOD (set_cell (idx, val)); } - - double get_scalar (void) const { return rep->get_scalar (); } - - void * get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); } - - void * get_imag_data (void) const - { DO_MUTABLE_METHOD (void *, get_imag_data ()); } - - void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); } - - void set_imag_data (void *pi) { DO_VOID_MUTABLE_METHOD (set_imag_data (pi)); } - - mwIndex * get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); } - - mwIndex * get_jc (void) const { DO_MUTABLE_METHOD (mwIndex *, get_jc ()); } - - mwSize get_nzmax (void) const { return rep->get_nzmax (); } - - void set_ir (mwIndex *ir) { DO_VOID_MUTABLE_METHOD (set_ir (ir)); } - - void set_jc (mwIndex *jc) { DO_VOID_MUTABLE_METHOD (set_jc (jc)); } - - void set_nzmax (mwSize nzmax) { DO_VOID_MUTABLE_METHOD (set_nzmax (nzmax)); } - - int add_field (const char *key) { DO_MUTABLE_METHOD (int, add_field (key)); } - - void remove_field (int key_num) - { DO_VOID_MUTABLE_METHOD (remove_field (key_num)); } - - mxArray * get_field_by_number (mwIndex index, int key_num) const - { DO_MUTABLE_METHOD (mxArray *, get_field_by_number (index, key_num)); } - - void set_field_by_number (mwIndex index, int key_num, mxArray *val) - { DO_VOID_MUTABLE_METHOD (set_field_by_number (index, key_num, val)); } - - int get_number_of_fields (void) const { return rep->get_number_of_fields (); } - - const char * get_field_name_by_number (int key_num) const - { DO_MUTABLE_METHOD (const char*, get_field_name_by_number (key_num)); } - - int get_field_number (const char *key) const - { DO_MUTABLE_METHOD (int, get_field_number (key)); } - - int get_string (char *buf, mwSize buflen) const - { return rep->get_string (buf, buflen); } - - char * array_to_string (void) const { return rep->array_to_string (); } - - mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const - { return rep->calc_single_subscript (nsubs, subs); } - - size_t get_element_size (void) const { return rep->get_element_size (); } - - bool mutation_needed (void) const { return rep->mutation_needed (); } - - mxArray * mutate (void) const { return rep->mutate (); } - - static void * malloc (size_t n); - - static void * calloc (size_t n, size_t t); - - static char * strsave (const char *str) - { - char *retval = nullptr; - - if (str) - { - mwSize sz = sizeof (mxChar) * (strlen (str) + 1); - - retval = static_cast (mxArray::malloc (sz)); - - if (retval) - strcpy (retval, str); - } - - return retval; - } - - static octave_value - as_octave_value (const mxArray *ptr, bool null_is_empty = true); - - octave_value as_octave_value (void) const; - -private: - - mutable mxArray_base *rep; - - char *name; - - mxArray (mxArray_base *r, const char *n) - : rep (r), name (mxArray::strsave (n)) { } - - void maybe_mutate (void) const; -}; - -#undef DO_MUTABLE_METHOD -#undef DO_VOID_MUTABLE_METHOD - -#endif -#endif diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/mxtypes.in.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/mxtypes.in.h Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,128 @@ +// %NO_EDIT_WARNING% + +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2001-2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +/* + +Part of this code was originally distributed as part of Octave Forge under +the following terms: + +Author: Paul Kienzle +I grant this code to the public domain. +2001-03-22 + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +*/ + +#if ! defined (octave_mxtypes_h) +#define octave_mxtypes_h 1 + +#include "octave-config.h" + +typedef enum +{ + mxUNKNOWN_CLASS = 0, + mxCELL_CLASS, + mxSTRUCT_CLASS, + mxLOGICAL_CLASS, + mxCHAR_CLASS, + mxVOID_CLASS, + mxDOUBLE_CLASS, + mxSINGLE_CLASS, + mxINT8_CLASS, + mxUINT8_CLASS, + mxINT16_CLASS, + mxUINT16_CLASS, + mxINT32_CLASS, + mxUINT32_CLASS, + mxINT64_CLASS, + mxUINT64_CLASS, + mxFUNCTION_CLASS +} +mxClassID; + +typedef enum +{ + mxREAL = 0, + mxCOMPLEX = 1 +} +mxComplexity; + +/* Matlab uses a wide char (uint16) internally, but Octave uses plain char. */ +/* typedef Uint16 mxChar; */ +typedef char mxChar; + +typedef unsigned char mxLogical; + +typedef double mxDouble; +typedef float mxSingle; + +typedef int8_t mxInt8; +typedef int16_t mxInt16; +typedef int32_t mxInt32; +typedef int64_t mxInt64; + +typedef uint8_t mxUint8; +typedef uint16_t mxUint16; +typedef uint32_t mxUint32; +typedef uint64_t mxUint64; + +typedef struct { mxDouble real; mxDouble imag; } mxComplexDouble; +typedef struct { mxSingle real; mxSingle imag; } mxComplexSingle; + +/* We don't have these yet but we can define the types. */ +typedef struct { mxInt8 real; mxInt8 imag; } mxComplexInt8; +typedef struct { mxInt16 real; mxInt16 imag; } mxComplexInt16; +typedef struct { mxInt32 real; mxInt32 imag; } mxComplexInt32; +typedef struct { mxInt64 real; mxInt64 imag; } mxComplexInt64; + +typedef struct { mxUint8 real; mxUint8 imag; } mxComplexUint8; +typedef struct { mxUint16 real; mxUint16 imag; } mxComplexUint16; +typedef struct { mxUint32 real; mxUint32 imag; } mxComplexUint32; +typedef struct { mxUint64 real; mxUint64 imag; } mxComplexUint64; + +/* + * FIXME: Mathworks says mwSize, mwIndex should be int generally. + * But on 64-bit systems, or when mex -largeArrayDims is used, it is size_t. + * mwSignedIndex is supposed to be ptrdiff_t. All of this is confusing. + * Its better to conform to the same indexing as the rest of Octave. + */ +typedef %OCTAVE_IDX_TYPE% mwSize; +typedef %OCTAVE_IDX_TYPE% mwIndex; +typedef %OCTAVE_IDX_TYPE% mwSignedIndex; + +#endif diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/oct-hist.cc --- a/libinterp/corefcn/oct-hist.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/oct-hist.cc Thu Nov 19 13:08:00 2020 -0800 @@ -327,12 +327,14 @@ { bool numbered_output = nargout == 0; - unwind_protect frame; + unwind_action restore_history_filename + ([] (const std::string& old_filename) + { + command_history::set_file (old_filename); + }, command_history::file ()); string_vector hlist; - frame.add_fcn (command_history::set_file, command_history::file ()); - int nargin = args.length (); // Number of history lines to show (-1 = all) @@ -545,8 +547,18 @@ file = env_file; if (file.empty ()) - file = sys::file_ops::concat (sys::env::get_home_directory (), - ".octave_hist"); + { + // Default to $DATA/octave/history, where $DATA is the platform- + // dependent location for (roaming) user data files. + + std::string user_data_dir = sys::env::get_user_data_directory (); + + std::string hist_dir = user_data_dir + sys::file_ops::dir_sep_str () + + "octave"; + + file = sys::env::make_absolute ("history", hist_dir); + } + return file; } @@ -819,8 +831,11 @@ All future commands issued during the current Octave session will be written to this new file (if the current setting of @code{history_save} allows for this). -The default value is @file{~/.octave_hist}, but may be overridden by the -environment variable @w{@env{OCTAVE_HISTFILE}}. +The default value is @file{@w{@env{$DATA}}/octave/history}, where +@w{@env{$DATA}} is the platform-specific location for (roaming) user data files +(e.g. @w{@env{$XDG_DATA_HOME}} or, if that is not set, @file{~/.local/share} on +Unix-like operating systems or @w{@env{%APPDATA%}} on Windows). The default +value may be overridden by the environment variable @w{@env{OCTAVE_HISTFILE}}. Programming Notes: diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/oct-map.cc --- a/libinterp/corefcn/oct-map.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/oct-map.cc Thu Nov 19 13:08:00 2020 -0800 @@ -564,8 +564,8 @@ %! reshape (x, 3, 8, 1, 1); %!test <*46385> -%! M = repmat (struct ('a', ones(100), 'b', true), 1, 2); -%! M = repmat(M, 1, 2); +%! M = repmat (struct ('a', ones (100), 'b', true), 1, 2); +%! M = repmat (M, 1, 2); %! assert (size (M), [1, 4]); libinterp/corefcn/oct-map.cc diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/libinterp/corefcn/oct-stream.cc Thu Nov 19 13:08:00 2020 -0800 @@ -97,8 +97,7 @@ } catch (const execution_exception&) { - octave::interpreter& interp - = __get_interpreter__ ("convert_to_valid_int"); + interpreter& interp = __get_interpreter__ ("convert_to_valid_int"); interp.recover_from_exception (); @@ -1914,7 +1913,7 @@ bool match_literal (delimited_stream& isp, const textscan_format_elt& elem); - int skip_whitespace (delimited_stream& is, bool EOLstop = false); + int skip_whitespace (delimited_stream& is, bool EOLstop = true); int skip_delim (delimited_stream& is); @@ -2472,7 +2471,7 @@ while (! ds.eof ()) { bool already_skipped_delim = false; - ts.skip_whitespace (ds); + ts.skip_whitespace (ds, false); ds.progress_benchmark (); ts.scan_complex (ds, *fmt_elts[0], val); if (ds.fail ()) @@ -2714,8 +2713,8 @@ dv = dim_vector (std::max (valid_rows - 1, 0), 1); ra_idx(1) = i; - retval = do_cat_op (retval, octave_value (Cell (col.resize (dv,0))), - ra_idx); + retval = cat_op (retval, octave_value (Cell (col.resize (dv,0))), + ra_idx); i++; } } @@ -2734,8 +2733,7 @@ if (prev_type != -1) { ra_idx(1) = i++; - retval = do_cat_op (retval, octave_value (Cell (cur)), - ra_idx); + retval = cat_op (retval, octave_value (Cell (cur)), ra_idx); } cur = octave_value (col.resize (dv,0)); group_size = 1; @@ -2744,12 +2742,11 @@ else { ra_idx(1) = group_size++; - cur = do_cat_op (cur, octave_value (col.resize (dv,0)), - ra_idx); + cur = cat_op (cur, octave_value (col.resize (dv,0)), ra_idx); } } ra_idx(1) = i; - retval = do_cat_op (retval, octave_value (Cell (cur)), ra_idx); + retval = cat_op (retval, octave_value (Cell (cur)), ra_idx); } return retval; @@ -2960,7 +2957,7 @@ { char *pos = is.tellg (); std::ios::iostate state = is.rdstate (); - //re = octave_read_value (is); + //re = read_value (is); re = read_double (is, fmt); // check for "treat as empty" string @@ -3025,7 +3022,7 @@ pos = is.tellg (); state = is.rdstate (); - //im = octave_read_value (is); + //im = read_value (is); im = read_double (is, fmt); if (is.fail ()) im = 1; @@ -3276,7 +3273,7 @@ else { if (ov.isreal ()) // cat does type conversion - ov = do_cat_op (ov, octave_value (v), row); + ov = cat_op (ov, octave_value (v), row); else ov.internal_rep ()->fast_elem_insert (row(0), v); } @@ -3289,7 +3286,7 @@ else { if (ov.isreal ()) // cat does type conversion - ov = do_cat_op (ov, octave_value (v), row); + ov = cat_op (ov, octave_value (v), row); else ov.internal_rep ()->fast_elem_insert (row(0), FloatComplex (v)); @@ -3374,7 +3371,7 @@ } if (is.fail () & ! fmt.discard) - ov = do_cat_op (ov, empty_value, row); + ov = cat_op (ov, empty_value, row); } else { @@ -3500,11 +3497,12 @@ elem = fmt_list.next (); char *pos = is.tellg (); - // FIXME: these conversions "ignore delimiters". Should they include - // delimiters at the start of the conversion, or can those be skipped? - if (elem->type != textscan_format_elt::literal_conversion - // && elem->type != '[' && elem->type != '^' && elem->type != 'c' - ) + // Skip delimiter before reading the next fmt conversion, + // unless the fmt is a string literal which begins with a delimiter, + // in which case the literal must match everything. Bug #58008 + if (elem->type != textscan_format_elt::literal_conversion) + skip_delim (is); + else if (! is_delim (elem->text[0])) skip_delim (is); if (is.eof ()) @@ -3892,8 +3890,8 @@ int textscan::skip_delim (delimited_stream& is) { - int c1 = skip_whitespace (is, true); // 'true': stop once EOL is read - if (delim_list.numel () == 0) // single character delimiter + int c1 = skip_whitespace (is); // Stop once EOL is read + if (delim_list.numel () == 0) // single character delimiter { if (is_delim (c1) || c1 == eol1 || c1 == eol2) { @@ -3943,7 +3941,7 @@ int prev = -1; // skip multiple delims. // Increment lines for each end-of-line seen; for \r\n, decrement - while (is && ((c1 = skip_whitespace (is, true)) + while (is && ((c1 = skip_whitespace (is)) != std::istream::traits_type::eof ()) && (((c1 == eol1 || c1 == eol2) && ++lines) || -1 != lookahead (is, delim_list, delim_len))) @@ -4369,7 +4367,7 @@ { is.putback (c1); - ref = octave_read_value (is); + ref = read_value (is); } } break; @@ -5715,7 +5713,7 @@ // Easier than dispatching here... octave_value ov_is_ge_zero - = do_binary_op (octave_value::op_ge, val, octave_value (0.0)); + = binary_op (octave_value::op_ge, val, octave_value (0.0)); return ov_is_ge_zero.is_true (); } diff -r dc3ee9616267 -r fa2cdef14442 libinterp/corefcn/ordqz.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/ordqz.cc Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,678 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +// Generalized eigenvalue reordering via LAPACK + +// Originally written by M. Koehler + +#undef DEBUG + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include +#include + +#include "f77-fcn.h" +#include "lo-lapack-proto.h" +#include "qr.h" +#include "quit.h" + +#include "defun.h" +#include "error.h" +#include "errwarn.h" +#include "ovl.h" + + +#if defined (DEBUG) +# include "pager.h" +# include "pr-output.h" +#endif + + +DEFUN (ordqz, args, nargout, + doc: /* -*- texinfo -*- +@deftypefn {} {[@var{AR}, @var{BR}, @var{QR}, @var{ZR}] =} ordqz (@var{AA}, @var{BB}, @var{Q}, @var{Z}, @var{keyword}) +@deftypefnx {} {[@var{AR}, @var{BR}, @var{QR}, @var{ZR}] =} ordqz (@var{AA}, @var{BB}, @var{Q}, @var{Z}, @var{select}) +Reorder the QZ@tie{}decomposition of a generalized eigenvalue problem. + +The generalized eigenvalue problem is defined as + +@tex +$$A x = \lambda B x$$ +@end tex +@ifnottex + +@math{A x = @var{lambda} B x} + +@end ifnottex + +Its generalized Schur decomposition is computed using the @code{qz} algorithm: + +@code{[@var{AA}, @var{BB}, @var{Q}, @var{Z}] = qz (@var{A}, @var{B})} + +where @var{AA}, @var{BB}, @var{Q}, and @var{Z} fulfill +@tex +$$ AA = Q \cdot A \cdot Z, BB = Q \cdot B \cdot Z $$ +@end tex +@ifnottex + +@example +@group + +@var{AA} = @var{Q} * @var{A} * @var{Z}, @var{BB} = @var{Q} * @var{B} * @var{Z} + +@end group +@end example + +@end ifnottex + +The @code{ordqz} function computes a unitary transformation @var{QR} and +@var{ZR} such that the order of the eigenvalue on the diagonal of @var{AA} and +@var{BB} is changed. The resulting reordered matrices @var{AR} and @var{BR} +fulfill: + +@tex +$$ A_R = Q_R \cdot A \cdot Z_R, B_R = Q_R \cdot B \cdot Z_R $$ +@end tex +@ifnottex + +@example +@group + +@var{AR} = @var{QR} * @var{A} * @var{ZR}, @var{BR} = @var{QR} * @var{B} * @var{ZR} + +@end group +@end example + +@end ifnottex + +The function can either be called with the @var{keyword} argument which +selects the eigenvalues in the top left block of @var{AR} and @var{BR} in the +following way: + +@table @asis +@item @qcode{"S"}, @qcode{"udi"} +small: leading block has all +@tex +$|\lambda| < 1$ +@end tex +@ifnottex +|@var{lambda}| < 1 +@end ifnottex + +@item @qcode{"B"}, @qcode{"udo"} +big: leading block has all +@tex +$|\lambda| \geq 1$ +@end tex +@ifnottex +|@var{lambda}| @geq{} 1 +@end ifnottex + +@item @qcode{"-"}, @qcode{"lhp"} +negative real part: leading block has all eigenvalues in the open left +half-plane + +@item @qcode{"+"}, @qcode{"rhp"} +non-negative real part: leading block has all eigenvalues in the closed right +half-plane +@end table + +If a logical vector @var{select} is given instead of a keyword the @code{ordqz} +function reorders all eigenvalues @code{k} to the left block for which +@code{select(k)} is true. + +Note: The keywords are compatible with the ones from @code{qr}. + +@seealso{eig, ordeig, qz, schur, ordschur} +@end deftypefn */) +{ + enum { LHP, RHP, UDI, UDO, VEC, NONE } select_mode = NONE; + + if (args.length () != 5) + print_usage (); + + // Check select argument + if (args(4).is_string()) + { + std::string opts = args(4).string_value (); + std::for_each (opts.begin (), opts.end (), + [] (char & c) { c = std::tolower (c); }); + if (opts == "lhp" || opts == "-") + select_mode = LHP; + else if (opts == "rhp" || opts == "+") + select_mode = RHP; + else if (opts == "udi" || opts == "s") + select_mode = UDI; + else if (opts == "udo" || opts == "b") + select_mode = UDO; + else + error_with_id ("Octave:ordqz:unknown-keyword", + "ordqz: unknown KEYWORD, possible values: " + "lhp, rhp, udi, udo"); + } + else if (args(4).isreal () || args(4).isinteger () || args(4).islogical ()) + { + if (args(4).rows () > 1 && args(4).columns () > 1) + error_with_id ("Octave:ordqz:select-not-vector", + "ordqz: SELECT argument must be a vector"); + select_mode = VEC; + } + else + error_with_id ("Octave:ordqz:unknown-arg", + "ordqz: OPT must be string or a logical vector"); + + if (nargout > 4) + error_with_id ("Octave:ordqz:nargout", + "ordqz: at most four output arguments possible"); + + // Matrix A: check dimensions. + F77_INT nn = octave::to_f77_int (args(0).rows ()); + F77_INT nc = octave::to_f77_int (args(0).columns ()); + + if (args(0).isempty ()) + { + warn_empty_arg ("qz: A"); + return octave_value_list (2, Matrix ()); + } + else if (nc != nn) + err_square_matrix_required ("qz", "A"); + + // Matrix A: get value. + Matrix aa; + ComplexMatrix caa; + + if (args(0).iscomplex ()) + caa = args(0).complex_matrix_value (); + else + aa = args(0).matrix_value (); + + // Extract argument 2 (bb, or cbb if complex). + F77_INT b_nr = octave::to_f77_int (args(1).rows ()); + F77_INT b_nc = octave::to_f77_int (args(1).columns ()); + + if (nn != b_nc || nn != b_nr) + err_nonconformant (); + + Matrix bb; + ComplexMatrix cbb; + + if (args(1).iscomplex ()) + cbb = args(1).complex_matrix_value (); + else + bb = args(1).matrix_value (); + + // Extract argument 3 (qq, or cqq if complex). + F77_INT q_nr = octave::to_f77_int (args(2).rows ()); + F77_INT q_nc = octave::to_f77_int (args(2).columns ()); + + if (nn != q_nc || nn != q_nr) + err_nonconformant (); + + Matrix qq; + ComplexMatrix cqq; + + if (args(2).iscomplex ()) + cqq = args(2).complex_matrix_value ().hermitian (); + else + qq = args(2).matrix_value ().transpose (); + + // Extract argument 4 (zz, or czz if complex). + F77_INT z_nr = octave::to_f77_int (args(3).rows ()); + F77_INT z_nc = octave::to_f77_int (args(3).columns ()); + + if (nn != z_nc || nn != z_nr) + err_nonconformant (); + + Matrix zz; + ComplexMatrix czz; + + if (args(3).iscomplex ()) + czz = args(3).complex_matrix_value (); + else + zz = args(3).matrix_value (); + + bool complex_case = (args(0).iscomplex () || args(1).iscomplex () + || args(2).iscomplex () || args(3).iscomplex ()); + + if (select_mode == VEC && args(4).rows () != nn && args(4).columns () != nn) + error_with_id ("Octave:ordqz:numel_select", + "ordqz: SELECT vector has the wrong number of elements"); + + Array select_array (dim_vector (nn, 1)); + if (select_mode == VEC) + select_array = args(4).vector_value (); + + Array select (dim_vector (nn, 1)); + + if (complex_case) + { + // Complex + if (args(0).isreal ()) + caa = ComplexMatrix (aa); + if (args(1).isreal ()) + cbb = ComplexMatrix (bb); + if (args(2).isreal ()) + cqq = ComplexMatrix (qq); + if (args(3).isreal ()) + czz = ComplexMatrix (zz); + + ComplexRowVector alpha (dim_vector (nn, 1)); + ComplexRowVector beta (dim_vector (nn, 1)); + octave_idx_type k; + + for (k = 0; k < nn-1; k++) + { + if (caa(k+1,k) != 0.0) + error_with_id ("Octave:ordqz:unsupported_AA", + "ordqz: quasi upper triangular matrices are not " + "allowed with complex data"); + } + + for (k = 0; k < nn; k++) + { + alpha(k) = caa(k,k); + beta(k) = cbb(k,k); + } + + for (k = 0; k < nn; k++) + { + switch (select_mode) + { + case LHP: + select(k) = real (alpha(k) * beta(k)) < 0; + break; + case RHP: + select(k) = real (alpha(k) * beta(k)) > 0; + break; + case UDI: + if (beta(k) != 0.0) + select(k) = abs (alpha(k)/beta(k)) < 1.0; + else + select(k) = false; + break; + case UDO: + if (beta(k) != 0.0) + select(k) = abs (alpha(k)/beta(k)) > 1.0; + else + select(k) = true; + break; + case VEC: + if (select_array(k) != 0.0) + select(k) = true; + else + select(k) = false; + break; + default: + // default: case just here to suppress compiler warning. + panic_impossible (); + } + } + + F77_LOGICAL wantq, wantz; + wantq = 1, wantz = 1; + F77_INT ijob, mm, lrwork3, liwork, info; + ijob = 0, lrwork3 = 1, liwork = 1; + F77_DBLE pl, pr; + ComplexRowVector work3 (lrwork3); + Array iwork (dim_vector (liwork, 1)); + + F77_XFCN (ztgsen, ZTGSEN, + (ijob, wantq, wantz, + select.fortran_vec (), nn, + F77_DBLE_CMPLX_ARG (caa.fortran_vec ()), nn, + F77_DBLE_CMPLX_ARG (cbb.fortran_vec ()), nn, + F77_DBLE_CMPLX_ARG (alpha.fortran_vec ()), + F77_DBLE_CMPLX_ARG (beta.fortran_vec ()), + F77_DBLE_CMPLX_ARG (cqq.fortran_vec ()), nn, + F77_DBLE_CMPLX_ARG (czz.fortran_vec ()), nn, + mm, + pl, pr, + nullptr, + F77_DBLE_CMPLX_ARG (work3.fortran_vec ()), lrwork3, + iwork.fortran_vec (), liwork, + info)); + if (info != 0) + error_with_id ("Octave:ordqz:ztgsen_failed", + "ordqz: failed to reorder eigenvalues"); + } + else + { + // Extract eigenvalues + RowVector alphar (dim_vector (nn, 1)); + RowVector alphai (dim_vector (nn, 1)); + RowVector beta (dim_vector (nn, 1)); + + octave_idx_type k; + + k = 0; + while (k < nn) + { +#ifdef DEBUG + octave_stdout << "ordqz: k = " << k << " nn = " << nn << " \n"; +#endif + if ((k < nn-1 && aa(k+1,k) == 0.0) || k == nn-1) + { + alphar(k) = aa(k,k); + alphai(k) = 0.0; + beta(k) = bb(k,k); + k++; + } + else + { + double ar[2], ai[2], b[2], work[4]; + char qz_job = 'E'; + char comp_q = 'N'; + char comp_z = 'N'; + F77_INT nl = 2; + F77_INT ilo = 1; + F77_INT ihi = 2; + F77_INT lwork = 4; + F77_INT info = 0; + double * aa_vec = aa.fortran_vec (); + double * bb_vec = bb.fortran_vec (); + + F77_XFCN (dhgeqz, DHGEQZ, + (F77_CONST_CHAR_ARG2 (&qz_job, 1), + F77_CONST_CHAR_ARG2 (&comp_q, 1), + F77_CONST_CHAR_ARG2 (&comp_z, 1), + nl, ilo, ihi, + &aa_vec[k+k*nn] , nn, + &bb_vec[k+k*nn], nn, + ar, ai, b, + nullptr, nn, + nullptr, nn, work, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + if (info != 0) + error("ordqz: failed to extract eigenvalues"); + + alphar(k) = ar[0]; + alphar(k+1) = ar[1]; + alphai(k) = ai[0]; + alphai(k+1) = ai[1]; + beta(k) = b[0]; + beta(k+1) = b[1]; + + k += 2; + } + + } + + for (k = 0; k < nn; k++) + { + switch (select_mode) + { + case LHP: + select(k) = alphar(k) * beta(k) < 0; + break; + case RHP: + select(k) = alphar(k) * beta(k) > 0; + break; + case UDI: + select(k) = alphar(k)*alphar(k) + + alphai(k)*alphai(k) < beta(k)*beta(k); + break; + case UDO: + select(k) = alphar(k)*alphar(k) + + alphai(k)*alphai(k) > beta(k)*beta(k); + break; + case VEC: + if (select_array(k) != 0.0) + select(k) = true; + else + select(k) = false; + break; + default: + // default: case just here to suppress compiler warning. + panic_impossible(); + } + } + + F77_LOGICAL wantq, wantz; + wantq = 1, wantz = 1; + F77_INT ijob, mm, lrwork3, liwork, info; + ijob = 0, lrwork3 = 4*nn+16, liwork = nn; + F77_DBLE pl, pr; + RowVector rwork3 (lrwork3); + Array iwork (dim_vector (liwork, 1)); + + F77_XFCN (dtgsen, DTGSEN, + (ijob, wantq, wantz, + select.fortran_vec (), nn, + aa.fortran_vec (), nn, + bb.fortran_vec (), nn, + alphar.fortran_vec (), + alphai.fortran_vec (), + beta.fortran_vec (), + qq.fortran_vec (), nn, + zz.fortran_vec (), nn, + mm, + pl, pr, + nullptr, + rwork3.fortran_vec (), lrwork3, + iwork.fortran_vec (), liwork, + info)); + if (info != 0) + error("ordqz: failed to reorder eigenvalues"); + } + + octave_value_list retval (nargout); + switch (nargout) + { + case 4: + if (complex_case) + retval(3) = czz; + else + retval(3) = zz; + OCTAVE_FALLTHROUGH; + case 3: + if (complex_case) + retval(2) = cqq.hermitian(); + else + retval(2) = qq.transpose(); + OCTAVE_FALLTHROUGH; + case 2: + if (complex_case) + retval(1) = cbb; + else + retval(1) = bb; + OCTAVE_FALLTHROUGH; + case 1: + if (complex_case) + retval(0) = caa; + else + retval(0) = aa; + break; + case 0: + if (complex_case) + retval(0) = caa; + else + retval(0) = aa; + break; + } + + return retval; +} + + +/* +%!shared A, B, AA, BB, QQ, ZZ, AC, BC, AAC, BBC, QQC, ZZC, select, selectc +%! A = [ -1.03428 0.24929 0.43205 -0.12860; +%! 1.16228 0.27870 2.12954 0.69250; +%! -0.51524 -0.34939 -0.77820 2.13721; +%! -1.32941 2.11870 0.72005 1.00835 ]; +%! B = [ 1.407302 -0.632956 -0.360628 0.068534; +%! 0.149898 0.298248 0.991777 0.023652; +%! 0.169281 -0.405205 -1.775834 1.511730; +%! 0.717770 1.291390 -1.766607 -0.531352 ]; +%! AC = [ 0.4577 + 0.7199i 0.1476 + 0.6946i 0.6202 + 0.2092i 0.7559 + 0.2759i; +%! 0.5868 + 0.7275i 0.9174 + 0.8781i 0.6741 + 0.1985i 0.4320 + 0.7023i; +%! 0.2408 + 0.6359i 0.2959 + 0.8501i 0.3904 + 0.5613i 0.5000 + 0.1428i; +%! 0.8177 + 0.8581i 0.2583 + 0.8970i 0.7706 + 0.5451i 0.1068 + 0.1650i]; +%! BC = [ 0.089898 + 0.209257i 0.157769 + 0.311387i 0.018926 + 0.622517i 0.058825 + 0.374647i; +%! 0.009367 + 0.098211i 0.736087 + 0.095797i 0.973192 + 0.583765i 0.434018 + 0.461909i; +%! 0.880784 + 0.868215i 0.032839 + 0.569461i 0.873437 + 0.266081i 0.739426 + 0.362017i; +%! 0.121649 + 0.115111i 0.426695 + 0.492222i 0.247670 + 0.034414i 0.771629 + 0.078153i]; +%! [AA, BB, QQ, ZZ] = qz (A, B); +%! [AAC, BBC, QQC, ZZC] = qz (AC, BC); +%! select = [0 0 1 1]; +%! selectc = [0 0 0 1]; + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "rhp"); +%! assert (all (real (eig (AAX(1:3,1:3), BBX(1:3,1:3))) >= 0)); +%! assert (all (real (eig (AAX(4:4,4:4), BBX(4:4,4:4))) < 0)); +%! assert (norm (QQX'*AAX*ZZX' - A, "fro"), 0, 1e-12); +%! assert (norm (QQX'*BBX*ZZX' - B, "fro"), 0, 1e-12); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "+"); +%! assert (all (real (eig (AAX(1:3,1:3), BBX(1:3,1:3))) >= 0)); +%! assert (all (real (eig (AAX(4:4,4:4), BBX(4:4,4:4))) < 0)); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "lhp"); +%! assert (all (real (eig (AAX(2:4,2:4), BBX(2:4,2:4))) >= 0)); +%! assert (all (real (eig (AAX(1:1,1:1), BBX(1:1,1:1))) < 0)); +%! assert (norm (QQX'*AAX*ZZX' - A, "fro"), 0, 1e-12); +%! assert (norm (QQX'*BBX*ZZX' - B, "fro"), 0, 1e-12); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "-"); +%! assert (all (real (eig (AAX(2:4,2:4), BBX(2:4,2:4))) >= 0)); +%! assert (all (real (eig (AAX(1:1,1:1), BBX(1:1,1:1))) < 0)); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "udi"); +%! assert (all (abs (eig (AAX(1:1,1:1), BBX(1:1,1:1))) < 1)); +%! assert (all (abs (eig (AAX(2:4,2:4), BBX(2:4,2:4))) > 1)); +%! assert (norm (QQX'*AAX*ZZX' - A, "fro"), 0, 1e-12); +%! assert (norm (QQX'*BBX*ZZX' - B, "fro"), 0, 1e-12); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "S"); +%! assert (all (abs (eig (AAX(1:1,1:1), BBX(1:1,1:1))) < 1)); +%! assert (all (abs (eig (AAX(2:4,2:4), BBX(2:4,2:4))) > 1)); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "udo"); +%! assert (all (abs (eig (AAX(1:3,1:3), BBX(1:3,1:3))) >= 1)); +%! assert (all (abs (eig (AAX(4:4,4:4), BBX(4:4,4:4))) < 1)); +%! assert (norm (QQX'*AAX*ZZX' - A, "fro"), 0, 1e-12); +%! assert (norm (QQX'*BBX*ZZX' - B, "fro"), 0, 1e-12); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, "B"); +%! assert (all (abs (eig (AAX(1:3,1:3), BBX(1:3,1:3))) >= 1)); +%! assert (all (abs (eig (AAX(4:4,4:4), BBX(4:4,4:4))) < 1)); + +%!test +%! [AAX, BBX, QQX, ZZX] = ordqz (AA, BB, QQ, ZZ, select); +%! assert (all (iscomplex (eig (AAX(1:2,1:2), BBX(1:2,1:2))))); +%! assert (norm (QQX'*AAX*ZZX' - A, "fro"), 0, 1e-12); +%! assert (norm (QQX'*BBX*ZZX' - B, "fro"), 0, 1e-12); + +%!test +%! [AACX, BBCX, QQCX, ZZCX] = ordqz (AAC, BBC, QQC, ZZC, "rhp"); +%! assert (all (real (eig (AACX(1:2,1:2), BBCX(1:2,1:2))) >= 0)); +%! assert (all (real (eig (AACX(3:4,3:4), BBCX(3:4,3:4))) < 0)); +%! assert (norm (QQCX'*AACX*ZZCX' - AC, "fro"), 0, 1e-12); +%! assert (norm (QQCX'*BBCX*ZZCX' - BC, "fro"), 0, 1e-12); + +%!test +%! [AACX, BBCX, QQCX, ZZCX] = ordqz (AAC, BBC, QQC, ZZC, "lhp"); +%! assert (all (real (eig (AACX(1:2,1:2), BBCX(1:2,1:2))) < 0)); +%! assert (all (real (eig (AACX(3:4,3:4), BBCX(3:4,3:4))) >= 0)); +%! assert (norm (QQCX'*AACX*ZZCX' - AC, "fro"), 0, 1e-12); +%! assert (norm (QQCX'*BBCX*ZZCX' - BC, "fro"), 0, 1e-12); + +%!test +%! [AACX, BBCX, QQCX, ZZCX] = ordqz (AAC, BBC, QQC, ZZC, "udi"); +%! assert (all (abs (eig (AACX(1:2,1:2), BBCX(1:2,1:2))) < 1)); +%! assert (all (abs (eig (AACX(3:4,3:4), BBCX(3:4,3:4))) >= 1)); +%! assert (norm (QQCX'*AACX*ZZCX' - AC, "fro"), 0, 1e-12); +%! assert (norm (QQCX'*BBCX*ZZCX' - BC, "fro"), 0, 1e-12); + +%!test +%! [AACX, BBCX, QQCX, ZZCX] = ordqz (AAC, BBC, QQC, ZZC, "udo"); +%! assert (all (abs (eig (AACX(1:2,1:2), BBCX(1:2,1:2))) >= 1)); +%! assert (all (abs (eig (AACX(3:4,3:4), BBCX(3:4,3:4))) < 1)); +%! assert (norm (QQCX'*AACX*ZZCX' - AC, "fro"), 0, 1e-12); +%! assert (norm (QQCX'*BBCX*ZZCX' - BC, "fro"), 0, 1e-12); + +%!test +%! [AACX, BBCX, QQCX, ZZCX] = ordqz (AAC, BBC, QQC, ZZC, selectc); +%! ev = abs (eig (AACX(1:1,1:1), BBCX(1:1,1:1))); +%! assert(ev > 0.6 && ev < 0.7); +%! assert (norm (QQCX'*AACX*ZZCX' - AC, "fro"), 0, 1e-12); +%! assert (norm (QQCX'*BBCX*ZZCX' - BC, "fro"), 0, 1e-12); + +%!test +%! A = toeplitz ([1,2,3,4]); +%! [B, A] = qr (A); +%! B = B'; +%! [AA, BB, Q, Z] = qz (A, B); +%! [AAS, BBS, QS, ZS] = ordqz (AA, BB, Q, Z, "lhp"); +%! E2 = ordeig (AAS, BBS); +%! ECOMP = [-3.414213562373092; -1.099019513592784; +%! -0.5857864376269046; 9.099019513592784]; +%! assert (norm (ECOMP - E2, "Inf"), 0, 1e-8); + +## Test input validation +%!error ordqz () +%!error ordqz (eye (2)) +%!error ordqz (eye (2), eye (2)) +%!error ordqz (eye (2), eye (2), eye (2)) +%!error ordqz (eye (2), eye (2), eye (2), eye (2)) +%!error id=Octave:ordqz:unknown-keyword +%! ordqz (eye (2), eye (2), eye (2), eye (2), "foobar"); +%!error id=Octave:ordqz:select-not-vector +%! ordqz (eye (2), eye (2), eye (2), eye (2), eye (2)); +%!error id=Octave:ordqz:unknown-arg +%! ordqz (eye (2), eye (2), eye (2), eye (2), {"foobar"}); +%!error id=Octave:ordqz:nargout +%! [a,b,c,d,e] = ordqz (eye (2), eye (2), eye (2), eye (2), "udi"); +%!warning ordqz ([], [], [], [], "udi"); +%!error ordqz (ones (1,2), [], [], [], "udi"); +%!error +%! ordqz (eye (3), eye (2), eye (2), eye (2), "udi"); +%!error +%! ordqz (eye (2), eye (3), eye (2), eye (2), "udi"); +%!error +%! ordqz (eye (2), eye (2), eye (3), eye (2), "udi"); +%!error +%! ordqz (eye (2), eye (2), eye (2), eye (3), "udi"); +%!error rng (struct ()) +%!error +%! rng (struct ("Type1",[],"State",[],"Seed",[])); +%!error rng (0, struct ()) +%!error <"philox" is not available in Octave> rng (0, "philox") +%!error rng ("shuffle", struct ()) +%!error rng ("shuffle", "foobar") diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/rot90.m --- a/scripts/general/rot90.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/rot90.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,7 +65,7 @@ function B = rot90 (A, k = 1) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -140,8 +140,7 @@ %! assert (rot90 (a, 3), rot90 (b, 2)); ## Test input validation -%!error rot90 () -%!error rot90 (1, 2, 3) +%!error rot90 () %!error rot90 (1, ones (2)) %!error rot90 (1, 1.5) %!error rot90 (1, 1+i) diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/rotdim.m --- a/scripts/general/rotdim.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/rotdim.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,7 +65,7 @@ function y = rotdim (x, n, plane) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -164,5 +164,4 @@ ## FIXME: We need tests for multidimensional arrays ## and different values of PLANE. -%!error rotdim () -%!error rotdim (1, 2, 3, 4) +%!error rotdim () diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/shift.m --- a/scripts/general/shift.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/shift.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function y = shift (x, b, dim) - if (nargin != 2 && nargin != 3) + if (nargin < 2) print_usage (); endif @@ -91,11 +91,11 @@ %! assert (shift (m, -2), [c; a; b]); ## Test input validation -%!error shift () -%!error shift (1, 2, 3, 4) -%!error shift ([], 1) -%!error shift (ones (2), ones (2)) -%!error shift (ones (2), 1.5) -%!error shift (1, 1, 1.5) -%!error shift (1, 1, 0) -%!error shift (1, 1, 3) +%!error shift () +%!error shift (1) +%!error shift ([], 1) +%!error shift (ones (2), ones (2)) +%!error shift (ones (2), 1.5) +%!error shift (1, 1, 1.5) +%!error shift (1, 1, 0) +%!error shift (1, 1, 3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/shiftdim.m --- a/scripts/general/shiftdim.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/shiftdim.m Thu Nov 19 13:08:00 2020 -0800 @@ -59,7 +59,7 @@ function [y, ns] = shiftdim (x, n) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -104,7 +104,6 @@ %!assert (size (shiftdim (rand (0, 1, 2))), [0 1 2]) ## Test input validation -%!error (shiftdim ()) -%!error (shiftdim (1,2,3)) -%!error (shiftdim (1, ones (2))) -%!error (shiftdim (1, 1.5)) +%!error shiftdim () +%!error shiftdim (1, ones (2)) +%!error shiftdim (1, 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/sortrows.m --- a/scripts/general/sortrows.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/sortrows.m Thu Nov 19 13:08:00 2020 -0800 @@ -53,7 +53,7 @@ function [s, i] = sortrows (A, c) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -159,8 +159,7 @@ %! assert (C2, flipud (C)); ## Test input validation -%!error sortrows () -%!error sortrows (1, 2, 3) +%!error sortrows () %!error sortrows (1, "ascend") %!error sortrows (1, ones (2,2)) %!error sortrows (1, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/sph2cart.m --- a/scripts/general/sph2cart.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/sph2cart.m Thu Nov 19 13:08:00 2020 -0800 @@ -26,22 +26,45 @@ ## -*- texinfo -*- ## @deftypefn {} {[@var{x}, @var{y}, @var{z}] =} sph2cart (@var{theta}, @var{phi}, @var{r}) ## @deftypefnx {} {[@var{x}, @var{y}, @var{z}] =} sph2cart (@var{S}) -## @deftypefnx {} {@var{C} =} sph2cart (@dots{}) ## Transform spherical coordinates to Cartesian coordinates. ## ## The inputs @var{theta}, @var{phi}, and @var{r} must be the same shape, or ## scalar. If called with a single matrix argument then each row of @var{S} -## represents the spherical coordinate (@var{theta}, @var{phi}, @var{r}). +## must represent a spherical coordinate triplet (@var{theta}, @var{phi}, +## @var{r}). ## -## @var{theta} describes the angle relative to the positive x-axis. +## The outputs @var{x}, @var{y}, @var{z} match the shape of the inputs. For a +## matrix input @var{S} the outputs are column vectors with rows corresponding +## to the rows of the input matrix. ## -## @var{phi} is the angle relative to the xy-plane. +## @var{theta} describes the azimuth angle relative to the positive x-axis +## measured in the xy-plane. +## +## @var{phi} is the elevation angle measured relative to the xy-plane. ## ## @var{r} is the distance to the origin @w{(0, 0, 0)}. ## -## If only a single return argument is requested then return a matrix @var{C} -## where each row represents one Cartesian coordinate -## (@var{x}, @var{y}, @var{z}). +## The coordinate transformation is computed using: +## +## @tex +## $$ x = r \cos \phi \cos \theta $$ +## $$ y = r \cos \phi \sin \theta $$ +## $$ z = r \sin \phi $$ +## @end tex +## @ifnottex +## +## @example +## @group +## @var{x} = r * cos (@var{phi}) * cos (@var{theta}) +## @var{y} = r * cos (@var{phi}) * sin (@var{theta}) +## @var{z} = r * sin (@var{phi}) +## @end group +## @end example +## +## @end ifnottex +## @c FIXME: Remove this note in Octave 9.1 (two releases after 7.1). +## Note: For @sc{matlab} compatibility, this function no longer returns a full +## coordinate matrix when called with a single return argument. ## @seealso{cart2sph, pol2cart, cart2pol} ## @end deftypefn @@ -52,19 +75,30 @@ endif if (nargin == 1) - if (! (isnumeric (theta) && ismatrix (theta) && columns (theta) == 3)) - error ("sph2cart: matrix input must have 3 columns [THETA, PHI, R]"); + if (! (isnumeric (theta) && ismatrix (theta))) + error ("sph2cart: matrix input must be a 2-D numeric array"); + endif + if (columns (theta) != 3 && numel (theta) != 3) + error ("sph2cart: matrix input must be a 3-element vector or 3-column array"); endif - r = theta(:,3); - phi = theta(:,2); - theta = theta(:,1); + + if (numel (theta) == 3) + r = theta(3); + phi = theta(2); + theta = theta(1); + else + r = theta(:,3); + phi = theta(:,2); + theta = theta(:,1); + endif + else - if (! isnumeric (theta) || ! isnumeric (phi) || ! isnumeric (r)) - error ("sph2cart: THETA, PHI, R must be numeric arrays of the same size, or scalar"); + if (! (isnumeric (theta) && isnumeric (phi) && isnumeric (r))) + error ("sph2cart: THETA, PHI, R must be numeric arrays or scalars"); endif [err, theta, phi, r] = common_size (theta, phi, r); if (err) - error ("sph2cart: THETA, PHI, R must be numeric arrays of the same size, or scalar"); + error ("sph2cart: THETA, PHI, R must be the same size or scalars"); endif endif @@ -72,10 +106,6 @@ y = r .* cos (phi) .* sin (theta); z = r .* sin (phi); - if (nargout <= 1) - x = [x(:), y(:), z(:)]; - endif - endfunction @@ -89,13 +119,22 @@ %! assert (z, [0, 0, 0]); %!test +%! t = [0; 0; 0]; +%! p = [0; 0; 0]; +%! r = [0; 1; 2]; +%! [x, y, z] = sph2cart (t, p, r); +%! assert (x, [0; 1; 2]); +%! assert (y, [0; 0; 0]); +%! assert (z, [0; 0; 0]); + +%!test %! t = 0; %! p = [0, 0, 0]; %! r = [0, 1, 2]; -%! C = sph2cart (t, p, r); -%! assert (C(:,1), r(:)); -%! assert (C(:,2), [0; 0; 0]); -%! assert (C(:,3), [0; 0; 0]); +%! [x, y, z] = sph2cart (t, p, r); +%! assert (x, [0, 1, 2]); +%! assert (y, [0, 0, 0]); +%! assert (z, [0, 0, 0]); %!test %! t = [0, 0, 0]; @@ -123,31 +162,42 @@ %!test %! S = [ 0, 0, 1; 0.5*pi, 0, 1; pi, 0, 1]; -%! C = [ 1, 0, 0; 0, 1, 0; -1, 0, 0]; -%! assert (sph2cart (S), C, eps); +%! [x, y, z] = sph2cart (S); +%! assert (x, [1; 0; -1], eps); +%! assert (y, [0; 1; 0], eps); +%! assert (z, [0; 0; 0], eps); + +%!test +%! S = [ 0, 0, 1; 0.5*pi, 0, 1; pi, 0, 1; pi, pi, 1]; +%! [x, y, z] = sph2cart (S); +%! assert (x, [1; 0; -1; 1], eps); +%! assert (y, [0; 1; 0; 0], eps); +%! assert (z, [0; 0; 0; 0], eps); + %!test %! [t, p, r] = meshgrid ([0, pi/2], [0, pi/2], [0, 1]); %! [x, y, z] = sph2cart (t, p, r); -%! X = zeros(2, 2, 2); +%! X = zeros (2, 2, 2); %! X(1, 1, 2) = 1; -%! Y = zeros(2, 2, 2); +%! Y = zeros (2, 2, 2); %! Y(1, 2, 2) = 1; -%! Z = zeros(2, 2, 2); +%! Z = zeros (2, 2, 2); %! Z(2, :, 2) = [1 1]; %! assert (x, X, eps); %! assert (y, Y, eps); %! assert (z, Z); ## Test input validation -%!error sph2cart () -%!error sph2cart (1,2) -%!error sph2cart (1,2,3,4) -%!error sph2cart ({1,2,3}) -%!error sph2cart (ones (3,3,2)) -%!error sph2cart ([1,2,3,4]) -%!error sph2cart ({1,2,3}, [1,2,3], [1,2,3]) -%!error sph2cart ([1,2,3], {1,2,3}, [1,2,3]) -%!error sph2cart ([1,2,3], [1,2,3], {1,2,3}) -%!error sph2cart (ones (3,3,3), 1, ones (3,2,3)) -%!error sph2cart (ones (3,3,3), ones (3,2,3), 1) +%!error sph2cart () +%!error sph2cart (1,2) +%!error sph2cart ({1,2,3}) +%!error sph2cart (ones (3,3,2)) +%!error sph2cart ([1,2,3,4]) +%!error sph2cart ([1,2,3,4; 1,2,3,4; 1,2,3,4]) +%!error sph2cart ({1,2,3}, [1,2,3], [1,2,3]) +%!error sph2cart ([1,2,3], {1,2,3}, [1,2,3]) +%!error sph2cart ([1,2,3], [1,2,3], {1,2,3}) +%!error sph2cart ([1,2,3], [1,2,3], [1,2,3]') +%!error sph2cart (ones (3,3,3), 1, ones (3,2,3)) +%!error sph2cart (ones (3,3,3), ones (3,2,3), 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/structfun.m --- a/scripts/general/structfun.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/structfun.m Thu Nov 19 13:08:00 2020 -0800 @@ -70,7 +70,7 @@ ## elements @qcode{"identifier"}, @qcode{"message"} and @qcode{"index"}, ## giving respectively the error identifier, the error message, and the index ## into the input arguments of the element that caused the error. For an -## example on how to use an error handler, @pxref{XREFcellfun,,cellfun}. +## example on how to use an error handler, @pxref{XREFcellfun,,@code{cellfun}}. ## ## @seealso{cellfun, arrayfun, spfun} ## @end deftypefn diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/subsindex.m --- a/scripts/general/subsindex.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/subsindex.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,7 +69,7 @@ function idx = subsindex (obj) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -82,5 +82,4 @@ %!error subsindex (1) ## Test input validation -%!error subsindex () -%!error subsindex (1, 2) +%!error subsindex () diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/trapz.m --- a/scripts/general/trapz.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/trapz.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ function z = trapz (x, y, dim) - if (nargin < 1) || (nargin > 3) + if (nargin < 1) print_usage (); endif @@ -153,8 +153,7 @@ %!assert <*54277> (trapz (ones (3,1), 2), zeros (3,1)) ## Test input validation -%!error trapz () -%!error trapz (1,2,3,4) +%!error trapz () %!error trapz (1, 2, [1 2]) %!error trapz (1, 2, 1.5) %!error trapz (1, 2, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/general/xor.m --- a/scripts/general/xor.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/general/xor.m Thu Nov 19 13:08:00 2020 -0800 @@ -98,6 +98,6 @@ %!assert (xor ([1 0], [1 1], [0 0]), logical ([0 1])) ## Test input validation -%!error xor () -%!error xor (1) +%!error xor () +%!error xor (1) %!error xor (ones (3,2), ones (2,3)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/geometry/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/convhull.m --- a/scripts/geometry/convhull.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/convhull.m Thu Nov 19 13:08:00 2020 -0800 @@ -193,12 +193,12 @@ %! assert (V == 2); ## Input validation tests -%!error convhull () -%!error convhull (1,2,3,4,5) +%!error convhull () +%!error convhull (1,2,3,4,5) %!error convhull (ones (2,4)) -%!error convhull (ones (2,2), struct()) +%!error convhull (ones (2,2), struct ()) %!error convhull (ones (2,4), "") -%!error convhull (ones (2,2), ones (2,2), struct()) -%!error convhull (ones (2,2), ones (2,2), ones (2,2), struct()) +%!error convhull (ones (2,2), ones (2,2), struct ()) +%!error convhull (ones (2,2), ones (2,2), ones (2,2), struct ()) %!error convhull (1, [1 2]) %!error convhull (1, [1 2], [1 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/delaunay.m --- a/scripts/geometry/delaunay.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/delaunay.m Thu Nov 19 13:08:00 2020 -0800 @@ -209,12 +209,12 @@ %! assert (sortrows (sort (delaunay (x, y, z), 2)), [1,2,3,4;1,2,4,5]); ## Input validation tests -%!error delaunay () -%!error delaunay (1,2,3,4,5) +%!error delaunay () +%!error delaunay (1,2,3,4,5) %!error delaunay (ones (2,4)) -%!error delaunay (ones (2,2), struct()) +%!error delaunay (ones (2,2), struct ()) %!error delaunay (ones (2,4), "") -%!error delaunay (ones (2,2), ones (2,2), struct()) -%!error delaunay (ones (2,2), ones (2,2), ones (2,2), struct()) +%!error delaunay (ones (2,2), ones (2,2), struct ()) +%!error delaunay (ones (2,2), ones (2,2), ones (2,2), struct ()) %!error delaunay (1, [1 2]) %!error delaunay (1, [1 2], [1 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/delaunayn.m --- a/scripts/geometry/delaunayn.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/delaunayn.m Thu Nov 19 13:08:00 2020 -0800 @@ -106,8 +106,8 @@ p12 = p1 - p2; p23 = p2 - p3; det = cross (p12, p23, 2); - idx = abs (det(:,3) ./ sqrt (sumsq (p12, 2))) < tol & ... - abs (det(:,3) ./ sqrt (sumsq (p23, 2))) < tol; + idx = abs (det (:,3) ./ sqrt (sumsq (p12, 2))) < tol & ... + abs (det (:,3) ./ sqrt (sumsq (p23, 2))) < tol; else ## FIXME: Vectorize this for loop or convert delaunayn to .oct function idx = []; @@ -135,4 +135,4 @@ ## FIXME: Need tests for delaunayn ## Input validation tests -%!error delaunayn () +%!error delaunayn () diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/dsearch.m --- a/scripts/geometry/dsearch.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/dsearch.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ function idx = dsearch (x, y, tri, xi, yi, s) - if (nargin < 5 || nargin > 6) + if (nargin < 5) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/dsearchn.m --- a/scripts/geometry/dsearchn.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/dsearchn.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,7 +39,7 @@ function [idx, d] = dsearchn (x, tri, xi, outval) - if (nargin < 2 || nargin > 4) + if (nargin < 2) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/griddata.m --- a/scripts/geometry/griddata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/griddata.m Thu Nov 19 13:08:00 2020 -0800 @@ -27,123 +27,232 @@ ## @deftypefn {} {@var{zi} =} griddata (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}) ## @deftypefnx {} {@var{zi} =} griddata (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}, @var{method}) ## @deftypefnx {} {[@var{xi}, @var{yi}, @var{zi}] =} griddata (@dots{}) +## @deftypefnx {} {@var{vi} =} griddata (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}) +## @deftypefnx {} {@var{vi} =} griddata (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}, @var{method}) +## @deftypefnx {} {@var{vi} =} griddata (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}, @var{method}, @var{options}) ## -## Generate a regular mesh from irregular data using interpolation. +## Interpolate irregular 2-D and 3-D source data at specified points. +## +## For 2-D interpolation, the inputs @var{x} and @var{y} define the points +## where the function @code{@var{z} = f (@var{x}, @var{y})} is evaluated. +## The inputs @var{x}, @var{y}, @var{z} are either vectors of the same length, +## or the unequal vectors @var{x}, @var{y} are expanded to a 2-D grid with +## @code{meshgrid} and @var{z} is a 2-D matrix matching the resulting size of +## the X-Y grid. +## +## The interpolation points are (@var{xi}, @var{yi}). If, and only if, +## @var{xi} is a row vector and @var{yi} is a column vector, then +## @code{meshgrid} will be used to create a mesh of interpolation points. ## -## The function is defined by @code{@var{z} = f (@var{x}, @var{y})}. Inputs -## @code{@var{x}, @var{y}, @var{z}} are vectors of the same length or -## @code{@var{x}, @var{y}} are vectors and @code{@var{z}} is matrix. +## For 3-D interpolation, the inputs @var{x}, @var{y}, and @var{z} define the +## points where the function @code{@var{v} = f (@var{x}, @var{y}, @var{z})} +## is evaluated. The inputs @var{x}, @var{y}, @var{z} are either vectors of +## the same length, or if they are of unequal length, then they are expanded to +## a 3-D grid with @code{meshgrid}. The size of the input @var{v} must match +## the size of the original data, either as a vector or a matrix. ## -## The interpolation points are all @code{(@var{xi}, @var{yi})}. If @var{xi}, -## @var{yi} are vectors then they are made into a 2-D mesh. +## The optional input interpolation @var{method} can be @qcode{"nearest"}, +## @qcode{"linear"}, or for 2-D data @qcode{"v4"}. When the method is +## @qcode{"nearest"}, the output @var{vi} will be the closest point in the +## original data (@var{x}, @var{y}, @var{z}) to the query point (@var{xi}, +## @var{yi}, @var{zi}). When the method is @qcode{"linear"}, the output +## @var{vi} will be a linear interpolation between the two closest points in +## the original source data in each dimension. For 2-D cases only, the +## @qcode{"v4"} method is also available which implements a biharmonic spline +## interpolation. If @var{method} is omitted or empty, it defaults to +## @qcode{"linear"}. ## -## The interpolation method can be @qcode{"nearest"}, @qcode{"cubic"} or -## @qcode{"linear"}. If method is omitted it defaults to @qcode{"linear"}. +## For 3-D interpolation, the optional argument @var{options} is passed +## directly to Qhull when computing the Delaunay triangulation used for +## interpolation. For more information on the defaults and how to pass +## different values, @pxref{XREFdelaunayn,,@code{delaunayn}}. +## +## Programming Notes: If the input is complex the real and imaginary parts +## are interpolated separately. Interpolation is normally based on a +## Delaunay triangulation. Any query values outside the convex hull of the +## input points will return @code{NaN}. However, the @qcode{"v4"} method does +## not use the triangulation and will return values outside the original data +## (extrapolation). ## @seealso{griddata3, griddatan, delaunay} ## @end deftypefn -## Algorithm: xi and yi are not "meshgridded" if both are vectors -## of the same size (for compatibility) +function [rx, ry, rz] = griddata (x, y, z, varargin) -function [rx, ry, rz] = griddata (x, y, z, xi, yi, method = "linear") - - if (nargin < 5 || nargin > 7) + if (nargin < 5) print_usage (); endif - if (ischar (method)) - method = tolower (method); - endif - - ## Meshgrid if x and y are vectors but z is matrix - if (isvector (x) && isvector (y) && all ([numel(y), numel(x)] == size (z))) - [x, y] = meshgrid (x, y); - endif - - if (isvector (x) && isvector (y) && isvector (z)) - if (! isequal (length (x), length (y), length (z))) - error ("griddata: X, Y, and Z must be vectors of the same length"); - endif - elseif (! size_equal (x, y, z)) - error ("griddata: lengths of X, Y must match the columns and rows of Z"); - endif - - ## Meshgrid xi and yi if they are a row and column vector. - if (rows (xi) == 1 && columns (yi) == 1) - [xi, yi] = meshgrid (xi, yi); - elseif (isvector (xi) && isvector (yi)) - ## Otherwise, convert to column vectors - xi = xi(:); - yi = yi(:); - endif - - if (! size_equal (xi, yi)) - error ("griddata: XI and YI must be vectors or matrices of same size"); - endif - - x = x(:); - y = y(:); - z = z(:); - - ## Triangulate data. - tri = delaunay (x, y); - zi = NaN (size (xi)); - - if (strcmp (method, "cubic")) - error ("griddata: cubic interpolation not yet implemented"); + if (nargin > 6) + ## Current 2D implementation has nargin max = 6, since no triangulation + ## options are passed to the 2D algorithm. 3D algorithm requires nargin >=7 - elseif (strcmp (method, "nearest")) - ## Search index of nearest point. - idx = dsearch (x, y, tri, xi, yi); - valid = ! isnan (idx); - zi(valid) = z(idx(valid)); - - elseif (strcmp (method, "linear")) - ## Search for every point the enclosing triangle. - tri_list = tsearch (x, y, tri, xi(:), yi(:)); - - ## Only keep the points within triangles. - valid = ! isnan (tri_list); - tri_list = tri_list(valid); - nr_t = rows (tri_list); - - tri = tri(tri_list,:); - - ## Assign x,y,z for each point of triangle. - x1 = x(tri(:,1)); - x2 = x(tri(:,2)); - x3 = x(tri(:,3)); - - y1 = y(tri(:,1)); - y2 = y(tri(:,2)); - y3 = y(tri(:,3)); - - z1 = z(tri(:,1)); - z2 = z(tri(:,2)); - z3 = z(tri(:,3)); - - ## Calculate norm vector. - N = cross ([x2-x1, y2-y1, z2-z1], [x3-x1, y3-y1, z3-z1]); - ## Normalize. - N = diag (norm (N, "rows")) \ N; - - ## Calculate D of plane equation - ## Ax+By+Cz+D = 0; - D = -(N(:,1) .* x1 + N(:,2) .* y1 + N(:,3) .* z1); - - ## Calculate zi by solving plane equation for xi, yi. - zi(valid) = -(N(:,1).*xi(:)(valid) + N(:,2).*yi(:)(valid) + D) ./ N(:,3); + if (nargout > 1) + error ("griddata: only one output argument valid for 3-D interpolation"); + endif + rx = griddata3 (x, y, z, varargin{:}); else - error ("griddata: unknown interpolation METHOD"); - endif + ## for nargin 5 or 6, assign varargin terms to variables for 2D algorithm + xi = varargin{1}; + yi = varargin{2}; + + ## Meshgrid if x and y are vectors but z is matrix + if (isvector (x) && isvector (y) && all ([numel(y), numel(x)] == size (z))) + [x, y] = meshgrid (x, y); + endif + + if (isvector (x) && isvector (y) && isvector (z)) + if (! isequal (length (x), length (y), length (z))) + error ("griddata: X, Y, and Z must be vectors of the same length"); + endif + elseif (! size_equal (x, y, z)) + error ("griddata: lengths of X, Y must match the columns and rows of Z"); + endif + + ## Meshgrid xi and yi if they are a row and column vector, but not + ## if they are simply vectors of the same size (for compatibility). + if (isrow (xi) && iscolumn (yi)) + [xi, yi] = meshgrid (xi, yi); + elseif (isvector (xi) && isvector (yi)) + ## Otherwise, convert to column vectors + xi = xi(:); + yi = yi(:); + endif + + if (! size_equal (xi, yi)) + error ("griddata: XI and YI must be vectors or matrices of same size"); + endif + + if (nargin == 6) + method = varargin{3}; + if (isempty (method)) + method = "linear"; + elseif (! ischar (method)) + error ("griddata: METHOD must be a string"); + else + method = tolower (method); + endif + + if (any (strcmp (method, {"linear", "nearest", "v4"}))) + ## Do nothing, these are implemented methods + elseif (any (strcmp (method, {"cubic", "natural"}))) + ## FIXME: implement missing interpolation methods. + error ('griddata: "%s" interpolation not yet implemented', method); + else + error ('griddata: unknown interpolation METHOD: "%s"', method); + endif + else + method = "linear"; + endif + + x = x(:); + y = y(:); + z = z(:); + + ## Triangulate data. + if (! strcmp (method, "v4")) + tri = delaunay (x, y); + endif + zi = NaN (size (xi)); + + if (strcmp (method, "linear")) + ## Search for every point the enclosing triangle. + tri_list = tsearch (x, y, tri, xi(:), yi(:)); + + ## Only keep the points within triangles. + valid = ! isnan (tri_list); + tri_list = tri_list(valid); + nr_t = rows (tri_list); + + tri = tri(tri_list,:); + + ## Assign x,y,z for each point of triangle. + x1 = x(tri(:,1)); + x2 = x(tri(:,2)); + x3 = x(tri(:,3)); - if (nargout > 1) - rx = xi; - ry = yi; - rz = zi; - else - rx = zi; + y1 = y(tri(:,1)); + y2 = y(tri(:,2)); + y3 = y(tri(:,3)); + + z1 = z(tri(:,1)); + z2 = z(tri(:,2)); + z3 = z(tri(:,3)); + + ## Calculate norm vector. + N = cross ([x2-x1, y2-y1, z2-z1], [x3-x1, y3-y1, z3-z1]); + ## Normalize. + N = diag (norm (N, "rows")) \ N; + + ## Calculate D of plane equation: Ax+By+Cz+D = 0 + D = -(N(:,1) .* x1 + N(:,2) .* y1 + N(:,3) .* z1); + + ## Calculate zi by solving plane equation for xi, yi. + zi(valid) = -(N(:,1).*xi(:)(valid) + N(:,2).*yi(:)(valid) + D) ./ N(:,3); + + elseif (strcmp (method, "nearest")) + ## Search index of nearest point. + idx = dsearch (x, y, tri, xi, yi); + valid = ! isnan (idx); + zi(valid) = z(idx(valid)); + + elseif (strcmp (method, "v4")) + ## Use Biharmonic Spline Interpolation Green's Function method. + ## Compatible with Matlab v4 interpolation method, based on + ## D. Sandwell 1987 and Deng & Tang 2011. + + ## The free space Green Function which solves the two dimensional + ## Biharmonic PDE + ## + ## Delta(Delta(G(X))) = delta(X) + ## + ## for a point source yields + ## + ## G(X) = |X|^2 * (ln|X|-1) / (8 * pi) + ## + ## An N-point Biharmonic Interpolation at the point X is given by + ## + ## z(X) = sum_j_N (alpha_j * G(X-Xj)) + ## = sum_j_N (alpha_j * G(rj)) + ## + ## in which the coefficients alpha_j are the unknowns. rj is the + ## Euclidean distance between X and Xj. + ## From N datapoints {zi, Xi} an equation system can be formed: + ## + ## zi(Xi) = sum_j_N (alpha_j * G(Xi-Xj)) + ## = sum_j_N (alpha_j * G(rij)) + ## + ## Its inverse yields the unknowns alpha_j. + + ## Step1: Solve for weight coefficients alpha_j depending on the + ## Euclidean distances and the training data set {x,y,z} + r = sqrt ((x - x.').^2 + (y - y.').^2); # size N^2 + D = (r.^2) .* (log (r) - 1); + D(isnan (D)) = 0; # Fix Green Function for r=0 + alpha_j = D \ z; + + ## Step2 - Use alphas and Green's functions to get interpolated points. + ## Use dim3 projection for vectorized calculation to avoid loops. + ## Memory usage is proportional to Ni x N. + ## FIXME: if this approach is too memory intensive, revert portion to loop + x = permute (x, [3, 2, 1]); + y = permute (y, [3, 2, 1]); + alpha_j = permute (alpha_j, [3, 2, 1]); + r_i = sqrt ((xi - x).^2 + (yi - y).^2); # size Ni x N + Di = (r_i.^2) .* (log (r_i) - 1); + Di(isnan (Di)) = 0; # Fix Green's Function for r==0 + zi = sum (Di .* alpha_j, 3); + + endif + + if (nargout > 1) + rx = xi; + ry = yi; + rz = zi; + else + rx = zi; + endif + endif endfunction @@ -155,10 +264,10 @@ %! x = 2*rand (100,1) - 1; %! y = 2*rand (size (x)) - 1; %! z = sin (2*(x.^2 + y.^2)); -%! [xx,yy] = meshgrid (linspace (-1,1,32)); +%! [xx,yy] = meshgrid (linspace (-1, 1, 32)); %! zz = griddata (x,y,z,xx,yy); %! mesh (xx, yy, zz); -%! title ("nonuniform grid sampled at 100 points"); +%! title ("non-uniform grid sampled at 100 points"); %!demo %! clf; @@ -166,10 +275,11 @@ %! x = 2*rand (1000,1) - 1; %! y = 2*rand (size (x)) - 1; %! z = sin (2*(x.^2 + y.^2)); -%! [xx,yy] = meshgrid (linspace (-1,1,32)); +%! [xx,yy] = meshgrid (linspace (-1, 1, 32)); %! zz = griddata (x,y,z,xx,yy); %! mesh (xx, yy, zz); -%! title ("nonuniform grid sampled at 1000 points"); +%! title ({"non-uniform grid sampled at 1,000 points", +%! 'method = "linear"'}); %!demo %! clf; @@ -177,34 +287,63 @@ %! x = 2*rand (1000,1) - 1; %! y = 2*rand (size (x)) - 1; %! z = sin (2*(x.^2 + y.^2)); -%! [xx,yy] = meshgrid (linspace (-1,1,32)); +%! [xx,yy] = meshgrid (linspace (-1, 1, 32)); %! zz = griddata (x,y,z,xx,yy,"nearest"); %! mesh (xx, yy, zz); -%! title ("nonuniform grid sampled at 1000 points with nearest neighbor"); +%! title ({"non-uniform grid sampled at 1,000 points", +%! 'method = "nearest neighbor"'}); %!testif HAVE_QHULL -%! [xx,yy] = meshgrid (linspace (-1,1,32)); +%! [xx, yy] = meshgrid (linspace (-1, 1, 32)); %! x = xx(:); %! x = x + 10*(2*round (rand (size (x))) - 1) * eps; %! y = yy(:); %! y = y + 10*(2*round (rand (size (y))) - 1) * eps; %! z = sin (2*(x.^2 + y.^2)); -%! zz = griddata (x,y,z,xx,yy,"linear"); +%! zz = griddata (x,y,z,xx,yy, "linear"); %! zz2 = sin (2*(xx.^2 + yy.^2)); %! zz2(isnan (zz)) = NaN; %! assert (zz, zz2, 100*eps); +%!testif HAVE_QHULL +%! [xx, yy] = meshgrid (linspace (-1, 1, 5)); +%! x = xx(:); +%! x = x + 10*(2*round (rand (size (x))) - 1) * eps; +%! y = yy(:); +%! y = y + 10*(2*round (rand (size (y))) - 1) * eps; +%! z = 2*(x.^2 + y.^2); +%! zz = griddata (x,y,z,xx,yy, "v4"); +%! zz2 = 2*(xx.^2 + yy.^2); +%! zz2(isnan (zz)) = NaN; +%! assert (zz, zz2, 100*eps); + +%!testif HAVE_QHULL +%! [xx, yy] = meshgrid (linspace (-1, 1, 5)); +%! x = xx(:); +%! x = x + 10*(2*round (rand (size (x))) - 1) * eps; +%! y = yy(:); +%! y = y + 10*(2*round (rand (size (y))) - 1) * eps; +%! z = 2*(x.^2 + y.^2); +%! zz = griddata (x,y,z,xx,yy, "nearest"); +%! zz2 = 2*(xx.^2 + yy.^2); +%! zz2(isnan (zz)) = NaN; +%! assert (zz, zz2, 100*eps); + ## Test input validation -%!error griddata () -%!error griddata (1) -%!error griddata (1,2) -%!error griddata (1,2,3) -%!error griddata (1,2,3,4) -%!error griddata (1,2,3,4,5,6,7) +%!error griddata () +%!error griddata (1) +%!error griddata (1,2) +%!error griddata (1,2,3) +%!error griddata (1,2,3,4) +%!error [xi,yi] = griddata (1,2,3,4,5,6,7) +%!error griddata (1:4, 1:3, 1:3, 1:3, 1:3) +%!error griddata (1:3, 1:4, 1:3, 1:3, 1:3) %!error griddata (1:3, 1:3, 1:4, 1:3, 1:3) -%!error griddata (1:3, 1:4, 1:3, 1:3, 1:3) -%!error griddata (1:4, 1:3, 1:3, 1:3, 1:3) %!error griddata (1:4, 1:3, ones (4,4), 1:3, 1:3) %!error griddata (1:4, 1:3, ones (3,5), 1:3, 1:3) -%!error griddata (1:3, 1:3, 1:3, 1:4, 1:3) -%!error griddata (1:3, 1:3, 1:3, 1:3, 1:4) +%!error griddata (1:3, 1:3, 1:3, 1:4, 1:3) +%!error griddata (1:3, 1:3, 1:3, 1:3, 1:4) +%!error griddata (1,2,3,4,5, {"linear"}) +%!error <"cubic" .* not yet implemented> griddata (1,2,3,4,5, "cubic") +%!error <"natural" .* not yet implemented> griddata (1,2,3,4,5, "natural") +%!error griddata (1,2,3,4,5, "foobar") diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/griddata3.m --- a/scripts/geometry/griddata3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/griddata3.m Thu Nov 19 13:08:00 2020 -0800 @@ -28,18 +28,34 @@ ## @deftypefnx {} {@var{vi} =} griddata3 (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}, @var{method}) ## @deftypefnx {} {@var{vi} =} griddata3 (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}, @var{method}, @var{options}) ## -## Generate a regular mesh from irregular data using interpolation. +## Interpolate irregular 3-D source data at specified points. ## -## The function is defined by @code{@var{v} = f (@var{x}, @var{y}, @var{z})}. +## The inputs @var{x}, @var{y}, and @var{z} define the points where the +## function @code{@var{v} = f (@var{x}, @var{y}, @var{z})} is evaluated. The +## inputs @var{x}, @var{y}, @var{z} are either vectors of the same length, or +## if they are of unequal length, then they are expanded to a 3-D grid with +## @code{meshgrid}. The size of the input @var{v} must match the size of the +## original data, either as a vector or a matrix. +## ## The interpolation points are specified by @var{xi}, @var{yi}, @var{zi}. ## -## The interpolation method can be @qcode{"nearest"} or @qcode{"linear"}. -## If method is omitted it defaults to @qcode{"linear"}. +## The optional input interpolation @var{method} can be @qcode{"nearest"} or +## @qcode{"linear"}. When the method is @qcode{"nearest"}, the output @var{vi} +## will be the closest point in the original data (@var{x}, @var{y}, @var{z}) +## to the query point (@var{xi}, @var{yi}, @var{zi}). When the method is +## @qcode{"linear"}, the output @var{vi} will be a linear interpolation between +## the two closest points in the original source data in each dimension. +## If @var{method} is omitted or empty, it defaults to @qcode{"linear"}. ## ## The optional argument @var{options} is passed directly to Qhull when ## computing the Delaunay triangulation used for interpolation. See ## @code{delaunayn} for information on the defaults and how to pass different ## values. +## +## Programming Notes: If the input is complex the real and imaginary parts +## are interpolated separately. Interpolation is based on a Delaunay +## triangulation and any query values outside the convex hull of the input +## points will return @code{NaN}. ## @seealso{griddata, griddatan, delaunayn} ## @end deftypefn @@ -105,3 +121,7 @@ %! vi = griddata3 (x, y, z, v, xi, yi, zi, "nearest"); %! vv = vi - xi.^2 - yi.^2 - zi.^2; %! assert (max (abs (vv(:))), 0.385, 0.1); + +## FIXME: Ideally, there should be BIST tests for input validation. +## However, this function is deprecated in Matlab and it probably isn't worth +## the coding time to work on a function that will be removed soon. diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/griddatan.m --- a/scripts/geometry/griddatan.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/griddatan.m Thu Nov 19 13:08:00 2020 -0800 @@ -28,18 +28,56 @@ ## @deftypefnx {} {@var{yi} =} griddatan (@var{x}, @var{y}, @var{xi}, @var{method}) ## @deftypefnx {} {@var{yi} =} griddatan (@var{x}, @var{y}, @var{xi}, @var{method}, @var{options}) ## -## Generate a regular mesh from irregular data using interpolation. +## Interpolate irregular source data @var{x}, @var{y} at points specified by +## @var{xi}. ## -## The function is defined by @code{@var{y} = f (@var{x})}. -## The interpolation points are all @var{xi}. +## The input @var{x} is an MxN matrix representing M points in an N-dimensional +## space. The input @var{y} is a single-valued column vector (Mx1) +## representing a function evaluated at the points @var{x}, i.e., +## @code{@var{y} = fcn (@var{x})}. The input @var{xi} is a list of points +## for which the function output @var{yi} should be approximated through +## interpolation. @var{xi} must have the same number of columns (@var{N}) +## as @var{x} so that the dimensionality matches. ## -## The interpolation method can be @qcode{"nearest"} or @qcode{"linear"}. -## If method is omitted it defaults to @qcode{"linear"}. +## The optional input interpolation @var{method} can be @qcode{"nearest"} or +## @qcode{"linear"}. When the method is @qcode{"nearest"}, the output @var{yi} +## will be the closest point in the original data @var{x} to the query point +## @var{xi}. When the method is @qcode{"linear"}, the output @var{yi} will +## be a linear interpolation between the two closest points in the original +## source data. If @var{method} is omitted or empty, it defaults to +## @qcode{"linear"}. ## ## The optional argument @var{options} is passed directly to Qhull when ## computing the Delaunay triangulation used for interpolation. See ## @code{delaunayn} for information on the defaults and how to pass different ## values. +## +## Example +## +## @example +## @group +## ## Evaluate sombrero() function at irregular data points +## x = 16*gallery ("uniformdata", [200,1], 1) - 8; +## y = 16*gallery ("uniformdata", [200,1], 11) - 8; +## z = sin (sqrt (x.^2 + y.^2)) ./ sqrt (x.^2 + y.^2); +## ## Create a regular grid and interpolate data +## [xi, yi] = ndgrid (linspace (-8, 8, 50)); +## zi = griddatan ([x, y], z, [xi(:), yi(:)]); +## zi = reshape (zi, size (xi)); +## ## Plot results +## clf (); +## plot3 (x, y, z, "or"); +## hold on +## surf (xi, yi, zi); +## legend ("Original Data", "Interpolated Data"); +## @end group +## @end example +## +## Programming Notes: If the input is complex the real and imaginary parts +## are interpolated separately. Interpolation is based on a Delaunay +## triangulation and any query values outside the convex hull of the input +## points will return @code{NaN}. For 2-D and 3-D data additional +## interpolation methods are available by using the @code{griddata} function. ## @seealso{griddata, griddata3, delaunayn} ## @end deftypefn @@ -49,15 +87,41 @@ print_usage (); endif - if (ischar (method)) - method = tolower (method); - endif - [m, n] = size (x); [mi, ni] = size (xi); - if (n != ni || rows (y) != m || columns (y) != 1) - error ("griddatan: dimensional mismatch"); + if (m < n + 1) + error ("griddatan: number of points in X (rows of X) must be greater than dimensionality of data + 1 (columns of X + 1)"); + endif + if (! iscolumn (y) || rows (y) != m) + error ("griddatan: Y must be a column vector with the same number of points (rows) as X"); + endif + if (n != ni) + error ("griddatan: dimension of query data XI (columns) must match X"); + endif + + if (nargin > 3) + if (isempty (method)) + method = "linear"; + elseif (! ischar (method)) + error ("griddatan: METHOD must be a string"); + else + method = tolower (method); + endif + + if (strcmp (method, "linear") || strcmp (method, "nearest")) + ## Do nothing, these are implemented methods + elseif (strcmp (method, "v4")) + error ('griddatan: "%s" METHOD is available for 2-D inputs by using "griddata"', method); + + elseif (any (strcmp (method, {"cubic", "natural"}))) + ## FIXME: Remove when griddata.m supports these methods. + error ('griddatan: "%s" interpolation METHOD not yet implemented', method); + + else + error ('griddatan: unknown interpolation METHOD: "%s"', method); + endif + endif ## triangulate data @@ -65,13 +129,7 @@ yi = NaN (mi, 1); - if (strcmp (method, "nearest")) - ## search index of nearest point - idx = dsearchn (x, tri, xi); - valid = ! isnan (idx); - yi(valid) = y(idx(valid)); - - elseif (strcmp (method, "linear")) + if (strcmp (method, "linear")) ## search for every point the enclosing triangle [tri_list, bary_list] = tsearchn (x, tri, xi); @@ -90,7 +148,11 @@ endif else - error ("griddatan: unknown interpolation METHOD"); + ## search index of nearest point + idx = dsearchn (x, tri, xi); + valid = ! isnan (idx); + yi(valid) = y(idx(valid)); + endif endfunction @@ -102,8 +164,8 @@ %! x = 2*rand (100,2) - 1; %! x = [x;1,1;1,-1;-1,-1;-1,1]; %! y = sin (2 * sum (x.^2,2)); -%! zz = griddatan (x,y,xi,"linear"); -%! zz2 = griddata (x(:,1),x(:,2),y,xi(:,1),xi(:,2),"linear"); +%! zz = griddatan (x,y,xi, "linear"); +%! zz2 = griddata (x(:,1),x(:,2),y,xi(:,1),xi(:,2), "linear"); %! assert (zz, zz2, 1e-10); %!testif HAVE_QHULL @@ -112,8 +174,8 @@ %! x = 2*rand (100,2) - 1; %! x = [x;1,1;1,-1;-1,-1;-1,1]; %! y = sin (2*sum (x.^2,2)); -%! zz = griddatan (x,y,xi,"nearest"); -%! zz2 = griddata (x(:,1),x(:,2),y,xi(:,1),xi(:,2),"nearest"); +%! zz = griddatan (x,y,xi, "nearest"); +%! zz2 = griddata (x(:,1),x(:,2),y,xi(:,1),xi(:,2), "nearest"); %! assert (zz, zz2, 1e-10); %!testif HAVE_QHULL <*56515> @@ -121,3 +183,17 @@ %! y = [ 1; 2; 3; 4 ]; %! xi = [ .5, .5 ]; %! yi = griddatan (x, y, xi); + +## Test input validation +%!error griddatan () +%!error griddatan (1) +%!error griddatan (1,2) +%!error griddatan (1,2,3) +%!error griddatan ([1;2],[3,4], 1) +%!error griddatan ([1;2],[3;4;5], 1) +%!error griddatan ([1;2],[3;4], [1, 2]) +%!error griddatan ([1;2],[3;4], 1, 5) +%!error <"v4" METHOD is available for 2-D> griddatan ([1;2],[3;4], 1, "v4") +%!error <"cubic" .* not yet implemented> griddatan ([1;2],[3;4], 1, "cubic") +%!error <"natural" .* not yet implemented> griddatan ([1;2],[3;4], 1, "natural") +%!error griddatan ([1;2],[3;4], 1, "foobar") diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/inpolygon.m --- a/scripts/geometry/inpolygon.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/inpolygon.m Thu Nov 19 13:08:00 2020 -0800 @@ -158,10 +158,9 @@ %! assert (on, ON); ## Test input validation -%!error inpolygon () -%!error inpolygon (1, 2) -%!error inpolygon (1, 2, 3) -%!error inpolygon (1, 2, 3, 4, 5) +%!error inpolygon () +%!error inpolygon (1, 2) +%!error inpolygon (1, 2, 3) %!error inpolygon (1i, 1, [3, 4], [5, 6]) %!error inpolygon (1, {1}, [3, 4], [5, 6]) %!error inpolygon (1, [1,2], [3, 4], [5, 6]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/module.mk --- a/scripts/geometry/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/convhull.m \ %reldir%/delaunay.m \ %reldir%/delaunayn.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/rotx.m --- a/scripts/geometry/rotx.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/rotx.m Thu Nov 19 13:08:00 2020 -0800 @@ -27,8 +27,8 @@ ## @deftypefn {} {@var{T} =} rotx (@var{angle}) ## ## @code{rotx} returns the 3x3 transformation matrix corresponding to an active -## rotation of the vector about the x-axis by the specified @var{angle}, given -## in degrees, where a positive angle corresponds to a counterclockwise +## rotation of a vector about the x-axis by the specified @var{angle}, given in +## degrees, where a positive angle corresponds to a counterclockwise ## rotation when viewing the y-z plane from the positive x side. ## ## The form of the transformation matrix is: @@ -51,7 +51,8 @@ ## @end ifnottex ## ## This rotation matrix is intended to be used as a left-multiplying matrix -## when acting on a column vector, using the notation @var{v} = @var{T}@var{u}. +## when acting on a column vector, using the notation +## @code{@var{v} = @var{T}*@var{u}}. ## For example, a vector, @var{u}, pointing along the positive y-axis, rotated ## 90-degrees about the x-axis, will result in a vector pointing along the ## positive z-axis: @@ -81,28 +82,28 @@ ## @seealso{roty, rotz} ## @end deftypefn -function retmat = rotx (angle_in_deg) +function T = rotx (angle) - if ((nargin != 1) || ! isscalar (angle_in_deg)) + if (nargin < 1 || ! isscalar (angle)) print_usage (); endif - angle_in_rad = angle_in_deg * pi / 180; + angle *= pi / 180; - s = sin (angle_in_rad); - c = cos (angle_in_rad); + s = sin (angle); + c = cos (angle); - retmat = [1 0 0; 0 c -s; 0 s c]; + T = [1 0 0; 0 c -s; 0 s c]; endfunction + ## Function output tests -%!assert (rotx (0), [1 0 0; 0 1 0; 0 0 1]); -%!assert (rotx (45), [1, 0, 0; [0; 0],[(sqrt(2)/2).*[1 -1; 1 1]]], 1e-12); -%!assert (rotx (90), [1 0 0; 0 0 -1; 0 1 0], 1e-12); -%!assert (rotx (180), [1 0 0; 0 -1 0; 0 0 -1], 1e-12); +%!assert (rotx (0), [1 0 0; 0 1 0; 0 0 1]) +%!assert (rotx (45), [1, 0, 0; [0; 0],[(sqrt(2)/2).*[1 -1; 1 1]]], 1e-12) +%!assert (rotx (90), [1 0 0; 0 0 -1; 0 1 0], 1e-12) +%!assert (rotx (180), [1 0 0; 0 -1 0; 0 0 -1], 1e-12) ## Test input validation -%!error rotx () -%!error rotx (1, 2) -%!error rotx ([1 2 3]) +%!error rotx () +%!error rotx ([1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/roty.m --- a/scripts/geometry/roty.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/roty.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,8 @@ ## @end ifnottex ## ## This rotation matrix is intended to be used as a left-multiplying matrix -## when acting on a column vector, using the notation @var{v} = @var{T}@var{u}. +## when acting on a column vector, using the notation +## @code{@var{v} = @var{T}*@var{u}}. ## For example, a vector, @var{u}, pointing along the positive z-axis, rotated ## 90-degrees about the y-axis, will result in a vector pointing along the ## positive x-axis: @@ -81,28 +82,28 @@ ## @seealso{rotx, rotz} ## @end deftypefn -function retmat = roty (angle_in_deg) +function T = roty (angle) - if ((nargin != 1) || ! isscalar (angle_in_deg)) + if (nargin < 1 || ! isscalar (angle)) print_usage (); endif - angle_in_rad = angle_in_deg * pi / 180; + angle *= pi / 180; - s = sin (angle_in_rad); - c = cos (angle_in_rad); + s = sin (angle); + c = cos (angle); - retmat = [c 0 s; 0 1 0; -s 0 c]; + T = [c 0 s; 0 1 0; -s 0 c]; endfunction + ## Function output tests -%!assert (roty (0), [1 0 0; 0 1 0; 0 0 1]); -%!assert (roty (45), [sqrt(2) 0 sqrt(2); 0 2 0; -sqrt(2) 0 sqrt(2)]./2, 1e-12); -%!assert (roty (90), [0 0 1; 0 1 0; -1 0 0], 1e-12); -%!assert (roty (180), [-1 0 0; 0 1 0; 0 0 -1], 1e-12); +%!assert (roty (0), [1 0 0; 0 1 0; 0 0 1]) +%!assert (roty (45), [sqrt(2) 0 sqrt(2); 0 2 0; -sqrt(2) 0 sqrt(2)]./2, 1e-12) +%!assert (roty (90), [0 0 1; 0 1 0; -1 0 0], 1e-12) +%!assert (roty (180), [-1 0 0; 0 1 0; 0 0 -1], 1e-12) ## Test input validation -%!error roty () -%!error roty (1, 2) -%!error roty ([1 2 3]) +%!error roty () +%!error roty ([1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/rotz.m --- a/scripts/geometry/rotz.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/rotz.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,8 @@ ## @end ifnottex ## ## This rotation matrix is intended to be used as a left-multiplying matrix -## when acting on a column vector, using the notation @var{v} = @var{T}@var{u}. +## when acting on a column vector, using the notation +## @code{@var{v} = @var{T}*@var{u}}. ## For example, a vector, @var{u}, pointing along the positive x-axis, rotated ## 90-degrees about the z-axis, will result in a vector pointing along the ## positive y-axis: @@ -81,28 +82,28 @@ ## @seealso{rotx, roty} ## @end deftypefn -function retmat = rotz (angle_in_deg) +function T = rotz (angle) - if ((nargin != 1) || ! isscalar (angle_in_deg)) + if (nargin < 1 || ! isscalar (angle)) print_usage (); endif - angle_in_rad = angle_in_deg * pi / 180; + angle = angle * pi / 180; - s = sin (angle_in_rad); - c = cos (angle_in_rad); + s = sin (angle); + c = cos (angle); - retmat = [c -s 0; s c 0; 0 0 1]; + T = [c -s 0; s c 0; 0 0 1]; endfunction + ## Function output tests -%!assert (rotz (0), [1 0 0; 0 1 0; 0 0 1]); -%!assert (rotz (45), [(sqrt(2)/2).*[1 -1; 1 1] ,[0; 0]; 0, 0, 1], 1e-12); -%!assert (rotz (90), [0 -1 0; 1 0 0; 0 0 1], 1e-12); -%!assert (rotz (180), [-1 0 0; 0 -1 0; 0 0 1], 1e-12); +%!assert (rotz (0), [1 0 0; 0 1 0; 0 0 1]) +%!assert (rotz (45), [(sqrt(2)/2).*[1 -1; 1 1] ,[0; 0]; 0, 0, 1], 1e-12) +%!assert (rotz (90), [0 -1 0; 1 0 0; 0 0 1], 1e-12) +%!assert (rotz (180), [-1 0 0; 0 -1 0; 0 0 1], 1e-12) ## Test input validation -%!error rotz () -%!error rotz (1, 2) -%!error rotz ([1 2 3]) +%!error rotz () +%!error rotz ([1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/voronoi.m --- a/scripts/geometry/voronoi.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/voronoi.m Thu Nov 19 13:08:00 2020 -0800 @@ -224,7 +224,7 @@ ## Input validation tests -%!error voronoi () +%!error voronoi () %!error voronoi (ones (3,1)) %!error voronoi (ones (3,1), ones (3,1), "invalid1", "invalid2", "invalid3") %!error voronoi (0, ones (3,1), ones (3,1)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/geometry/voronoin.m --- a/scripts/geometry/voronoin.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/geometry/voronoin.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ function [C, F] = voronoin (pts, options) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -80,6 +80,5 @@ ## FIXME: Need functional tests -%!error voronoin () -%!error voronoin (1,2,3) +%!error voronoin () %!error voronoin ([1 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/errordlg.m --- a/scripts/gui/errordlg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/errordlg.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,7 +39,7 @@ ## ("\n"), or it may be a cellstr array with one element for each line. ## ## The third optional argument @var{opt} controls the behavior of the dialog. -## See @code{msgbox} for details. +## For details, @pxref{XREFmsgbox,,@code{msgbox}}. ## ## The return value @var{h} is a handle to the figure object used for ## building the dialog. diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/getappdata.m --- a/scripts/gui/getappdata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/getappdata.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ function value = getappdata (h, name) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -90,8 +90,7 @@ %! end_unwind_protect ## Test input validation -%!error getappdata () -%!error getappdata (1,2,3) +%!error getappdata () %!error getappdata (-1, "hello") %!error getappdata (0, 1) %!error getappdata ([0 0]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/getpixelposition.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/getpixelposition.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,126 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{pos} =} getpixelposition (@var{h}) +## @deftypefnx {} {@var{pos} =} getpixelposition (@var{h}, @var{rel_to_fig}) +## Return the position of a user interface component in pixel units. +## +## The first argument @var{h} must be a handle to a valid graphics object of +## type uibuttongroup, uicontrol, uipanel, uitable, axes, or figure. For other +## object types, the function returns zeros. +## +## By default, the position is returned relative to the object's parent. +## If the second argument @var{rel_to_fig} is logically true, the position +## is computed relative to the enclosing figure object. +## +## The return value @var{pos} is a 4-element vector with values +## @code{[ lower_left_X, lower_left_Y, width, height ]}. +## +## @seealso{get} +## @end deftypefn + +function pos = getpixelposition (h, rel_to_fig = false) + + if (nargin < 1) + print_usage (); + endif + + if (! isscalar (h) || ! ishghandle (h)) + error ("getpixelposition: H must be a scalar graphics handle"); + endif + + if (! any (strcmp (get (h, "type"), {"uibuttongroup", "uicontrol", ... + "uitable", "uipanel", ... + "axes", "figure"}))) + pos = zeros (1, 4); + return; + endif + + pos = __get_position__ (h, "pixels"); + + if (rel_to_fig) + while (! isfigure (h)) + h = get (h, "parent"); + pos(1:2) += __get_position__ (h, "pixels")(1:2); + endwhile + endif + +endfunction + + +%!demo +%! clf (); +%! hax = axes ("position", [0.25 0.25 0.5 0.5]) +%! pos = getpixelposition (hax); +%! han = annotation ("rectangle"); +%! set (han, "units", "pixels", "position", pos, "color", "r") + +%!demo +%! hf = clf (); +%! hbg = uibuttongroup (hf, "position", [0.2 0.7 0.2 0.2]); +%! hb1 = uicontrol (hbg, "style", "radiobutton", ... +%! "string", "Choice 1", ... +%! "units", "normalized", ... +%! "position", [0.01 0.5 0.98 0.5]); +%! hb2 = uicontrol (hbg, "style", "radiobutton", ... +%! "string", "Choice 2", ... +%! "units", "normalized", ... +%! "position", [0.01 0 0.98 0.5]); +%! pos = getpixelposition (hbg); +%! han = annotation ("rectangle"); +%! set (han, "units", "pixels", "position", pos, "color", "r") + + +%!test +%! pos = [0 0 400 400]; +%! hf = figure ("visible", "off", "menubar", "none", "position", pos); +%! unwind_protect +%! hp = uipanel (hf, "position", [0.5 0.5 0.5 0.5]); +%! hax = axes (hp, "position", [0.5 0.5 0.5 0.5]); +%! assert (getpixelposition (hax), [100 100 100 100], 2); +%! assert (getpixelposition (hax, true), [300 300 100 100], 2); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test +%! ## Compatibility: return zeros for root figure +%! assert (getpixelposition (groot), zeros (1, 4)); + +%!test +%! ## Compatibility: return the same for figures regardless of rel_to_fig +%! hf = figure ("visible", "off"); +%! unwind_protect +%! assert (getpixelposition (hf), getpixelposition (hf, true)); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +## Test input validation +%!error getpixelposition () +%!error getpixelposition ([1, 2]) +%!error getpixelposition (-1) + diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/guidata.m --- a/scripts/gui/guidata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/guidata.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function dataout = guidata (h, data) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -65,7 +65,6 @@ ## Test input validation -%!error guidata () -%!error guidata (1,2,3) +%!error guidata () %!error guidata ({1}) %!error guidata (0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/guihandles.m --- a/scripts/gui/guihandles.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/guihandles.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,10 +42,6 @@ function hdata = guihandles (h) - if (nargin > 2) - print_usage (); - endif - if (nargin == 1) if (! ishghandle (h)) error ("guidata: H must be a valid object handle"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/isappdata.m --- a/scripts/gui/isappdata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/isappdata.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function valid = isappdata (h, name) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -66,7 +66,6 @@ %! end_unwind_protect ## Test input validation -%!error isappdata () -%!error isappdata (1,2,3) +%!error isappdata () %!error isappdata (-1, "hello") %!error isappdata (0, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/listdlg.m --- a/scripts/gui/listdlg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/listdlg.m Thu Nov 19 13:08:00 2020 -0800 @@ -200,7 +200,8 @@ %! endfor ## Test input validation -%!error listdlg () +%!error listdlg () +%!error listdlg (1) %!error listdlg ("SelectionMode") %!error listdlg ("SelectionMode", "multiple", "Name") %!error listdlg ("FooBar", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/listfonts.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/gui/listfonts.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,74 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {fonts =} listfonts () +## @deftypefnx {} {fonts =} listfonts (@var{h}) +## List system fonts. +## +## If a handle to a graphics object @var{h} is provided, also include the +## font from the object's @qcode{"FontName"} property in the list. +## +## Programming Note: On systems that don't use FontConfig natively (all but +## Linux), the font cache is built when Octave is installed. You will need to +## run @code{system ("fc-cache -fv")} manually after installing new fonts. +## +## @seealso{uisetfont, text, axes, uicontrol} +## @end deftypefn + +function fonts = listfonts (h) + + if (nargin == 1 && (! ishghandle (h) || ! isprop (h, "fontname"))) + error (['listfonts: H must be a handle to a graphics object ', ... + 'with a "fontname" property']); + endif + + persistent sysfonts = get_fonts (); + fonts = sysfonts; + + if (nargin == 1 && ! isempty (h)) + font = get (h, "fontname"); + if (! strcmp (font, "*")) + fonts = unique ([fonts font]); + endif + endif + +endfunction + +function fonts = get_fonts () + + fontfiles = __get_system_fonts__ (); + + fonts = unique ({fontfiles.family, "FreeSans"}); + +endfunction + + +## Test input validation +%!error listfonts (0, 0) +%!error +%! s = listfonts (0); +%!error +%! s = listfonts (struct ()); diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/module.mk --- a/scripts/gui/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -14,14 +14,17 @@ %reldir%/private/__uiputfile_fltk__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/dialog.m \ %reldir%/errordlg.m \ %reldir%/getappdata.m \ + %reldir%/getpixelposition.m \ %reldir%/guidata.m \ %reldir%/guihandles.m \ %reldir%/helpdlg.m \ %reldir%/inputdlg.m \ %reldir%/isappdata.m \ + %reldir%/listfonts.m \ %reldir%/listdlg.m \ %reldir%/movegui.m \ %reldir%/msgbox.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/movegui.m --- a/scripts/gui/movegui.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/movegui.m Thu Nov 19 13:08:00 2020 -0800 @@ -185,8 +185,8 @@ if (fpos(2) > y(3)) fpos(2) = y(3) - 30; endif - fpos(1) = max(fpos(1), 30); - fpos(2) = max(fpos(2), 30); + fpos(1) = max (fpos(1), 30); + fpos(2) = max (fpos(2), 30); otherwise error ("movegui: invalid position"); endswitch diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/msgbox.m --- a/scripts/gui/msgbox.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/msgbox.m Thu Nov 19 13:08:00 2020 -0800 @@ -359,7 +359,7 @@ %! "Dialog Title", "custom", cdata, copper (64)); ## Test input validation -%!error msgbox () +%!error msgbox () %!error msgbox (1) %!error %! msgbox ("msg", struct ("WindowStyle", "foobar")) diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/private/__file_filter__.m --- a/scripts/gui/private/__file_filter__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/private/__file_filter__.m Thu Nov 19 13:08:00 2020 -0800 @@ -30,7 +30,6 @@ function [retval, defname, defdir] = __file_filter__ (caller, file_filter) - #keyboard; retval = {}; defname = ""; defdir = ""; diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/private/__ok_cancel_dlg__.m --- a/scripts/gui/private/__ok_cancel_dlg__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/private/__ok_cancel_dlg__.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,14 +24,14 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {[@var{hf}, @var{hok}, @var{hcancel}] =} __ok_cancel_dlg__ (@var{title}) +## @deftypefn {} {[@var{hf}, @var{hok}, @var{hcancel}] =} __ok_cancel_dlg__ (@var{dlg_title}) ## Undocumented internal function. ## @seealso{} ## @end deftypefn -function [hf, hok, hcancel, hpanel] = __ok_cancel_dlg__ (ttl, varargin) +function [hf, hok, hcancel, hpanel] = __ok_cancel_dlg__ (dlg_title, varargin) - hf = dialog ("name", ttl, varargin{:}); + hf = dialog ("name", dlg_title, varargin{:}); setappdata (hf, "__ok_cancel_btn__", "cancel"); hpanel = uipanel (hf, "units", "pixels", "bordertype", "none"); @@ -46,6 +46,7 @@ endfunction function cb_fix_button_position (hf, evt, hcancel, hok, hpanel) + persistent margin = 20; persistent hgt = 30; persistent wd = 70; @@ -62,4 +63,5 @@ unwind_protect_cleanup set (hf, "units", units); end_unwind_protect + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/private/__uiobject_split_args__.m --- a/scripts/gui/private/__uiobject_split_args__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/private/__uiobject_split_args__.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,20 +39,20 @@ parent = in_args{1}; offset = 2; elseif (! ischar (in_args{1}) && ! isstruct (in_args{1})) - error ("%s: invalid parent handle.", who); + error ("%s: invalid parent handle", who); endif args = in_args(offset:end); endif if (! isempty (args)) - i = find (strcmpi (args, "parent"), 1, "first"); - if (! isempty (i) && numel (args) > i) - parent = args{i+1}; + i = find (strcmpi (args(1:2:end), "parent"), 1, "first"); + if (! isempty (i) && numel (args) >= 2*i) + parent = args{2*i}; if (! ishghandle (parent)) - error ("%s: invalid parent handle.", who); + error ("%s: invalid parent handle", who); endif - args(i:i+1) = []; + args((2*i-1):2*i) = []; endif endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/questdlg.m --- a/scripts/gui/questdlg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/questdlg.m Thu Nov 19 13:08:00 2020 -0800 @@ -186,8 +186,8 @@ %! endif ## Test input validation -%!error questdlg () -%!error questdlg (1,2,3,4,5,6,7) +%!error questdlg () +%!error questdlg (1,2,3,4,5,6,7) %!error questdlg (1) %!error questdlg ("msg", 1) %!error <DEFAULT must match one of the button> questdlg ("msg", "title", "ABC") diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/rmappdata.m --- a/scripts/gui/rmappdata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/rmappdata.m Thu Nov 19 13:08:00 2020 -0800 @@ -78,8 +78,8 @@ %! assert (isappdata (0, "%data2%"), false); ## Test input validation -%!error rmappdata () -%!error rmappdata (1) +%!error <Invalid call> rmappdata () +%!error <Invalid call> rmappdata (1) %!error <H must be a scalar .* graphic handle> rmappdata (-1, "hello") %!error <NAME must be a string> rmappdata (0, 1) %!error <appdata 'foobar' is not present> rmappdata (0, "foobar") diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/setappdata.m --- a/scripts/gui/setappdata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/setappdata.m Thu Nov 19 13:08:00 2020 -0800 @@ -127,9 +127,9 @@ %! end_unwind_protect ## Test input validation -%!error setappdata () -%!error setappdata (0) -%!error setappdata (0, "name") +%!error <Invalid call> setappdata () +%!error <Invalid call> setappdata (0) +%!error <Invalid call> setappdata (0, "name") %!error <H must be a scalar .* graphic handle> setappdata (-1, "foo", "bar") %!error <NAME/VALUE arguments must occur in pairs> setappdata (0, "1", 2, "3") %!error <only 3 arguments possible> setappdata (0, {"1"}, 2, "3", 4) diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/uicontrol.m --- a/scripts/gui/uicontrol.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/uicontrol.m Thu Nov 19 13:08:00 2020 -0800 @@ -119,6 +119,16 @@ [h, args] = __uiobject_split_args__ ("uicontrol", varargin, {"figure", "uipanel", "uibuttongroup"}); + + ## Validate style + idx = find (strcmpi (args(1:2:end), "style"), 1, "last"); + if (! isempty (idx) && 2*idx <= numel (args)) + if (strcmpi (args{2*idx}, "frame")) + warning ("Octave:unimplemented-matlab-functionality", + 'uicontrol: "frame" style is not implemented. Use uipanel() or uibuttongroup() instead'); + endif + endif + htmp = __go_uicontrol__ (h, args{:}); if (nargout > 0) @@ -126,3 +136,12 @@ endif endfunction + + +%!warning <"frame" style is not implemented> +%! hf = figure ("visible", "off"); +%! unwind_protect +%! h = uicontrol (hf, "string", "Hello World", "Style", "frame"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/uigetdir.m --- a/scripts/gui/uigetdir.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/uigetdir.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,10 +41,6 @@ function dirname = uigetdir (init_path = pwd, dialog_name = "Select Directory to Open") - if (nargin > 2) - print_usage (); - endif - if (! ischar (init_path) || ! ischar (dialog_name)) error ("uigetdir: INIT_PATH and DIALOG_NAME must be string arguments"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/uisetfont.m --- a/scripts/gui/uisetfont.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/uisetfont.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,14 +38,18 @@ ## @code{FontWeight}, @code{FontAngle}, @code{FontUnits}, and @code{FontSize}, ## indicating the initially selected font. ## -## The title of the dialog window can be changed using the last argument +## The title of the dialog window can be specified by using the last argument ## @var{title}. ## ## If an output argument @var{fontstruct} is requested, the selected font ## structure is returned. Otherwise, the font information is displayed ## onscreen. ## -## @seealso{text, axes, uicontrol} +## Programming Note: On systems that don't use FontConfig natively (all but +## Linux), the font cache is built when Octave is installed. You will need to +## run @code{system ("fc-cache -fv")} manually after installing new fonts. +## +## @seealso{listfonts, text, axes, uicontrol} ## @end deftypefn function varargout = uisetfont (varargin) @@ -71,7 +75,7 @@ typ = get (h, "type"); if (! any (strcmp (typ, {"axes", "text", "uicontrol"}))) error ("Octave:uisetfont:bad-object", - 'uisetfont: unhandled object type "%s"', typ); + "uisetfont: H must be a handle to an axes, text, or uicontrol object"); endif nargin--; varargin(1) = []; @@ -333,7 +337,7 @@ endfunction -function cb_button (h, evt, hlists, role) +function cb_button (h, ~, hlists, role) fontstruct = []; if (strcmp (role, "ok")) @@ -345,7 +349,7 @@ endfunction -function cb_list_value_changed (h, evt, hlists, htext, sysfonts) +function cb_list_value_changed (h, ~, hlists, htext, sysfonts) if (h == hlists(1)) set (hlists(2), "string", getstylestring (sysfonts(get (h, "value"))), @@ -363,7 +367,7 @@ %!testif HAVE_FONTCONFIG %! fail ("uisetfont (110, struct ())", "Invalid call"); %!testif HAVE_FONTCONFIG -%! fail ("uisetfont (groot ())", "unhandled object type"); +%! fail ("uisetfont (groot ())", "H must be a handle to an axes"); %!testif HAVE_FONTCONFIG %! fail ("uisetfont (struct ())", "FONTSTRUCT .* must have fields FontName,.*"); %!testif HAVE_FONTCONFIG diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/waitforbuttonpress.m --- a/scripts/gui/waitforbuttonpress.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/waitforbuttonpress.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,10 +39,6 @@ function b = waitforbuttonpress () - if (nargin != 0 || nargout > 1) - print_usage (); - endif - [x, y, k] = ginput (1); if (nargout == 1) @@ -54,8 +50,3 @@ endif endfunction - - -## Test input validation -%!error waitforbuttonpress (1) -%!error [a,b,c] = waitforbuttonpress () diff -r dc3ee9616267 -r fa2cdef14442 scripts/gui/warndlg.m --- a/scripts/gui/warndlg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/gui/warndlg.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ ## ("\n"), or it may be a cellstr array with one element for each line. ## ## The third optional argument @var{opt} controls the behavior of the dialog. -## See @code{msgbox} for details. +## For details, @pxref{XREFmsgbox,,@code{msgbox}}. ## ## The return value @var{h} is a handle to the figure object used for ## building the dialog. diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/help/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/__gripe_missing_component__.m --- a/scripts/help/__gripe_missing_component__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/__gripe_missing_component__.m Thu Nov 19 13:08:00 2020 -0800 @@ -62,14 +62,13 @@ endfunction -## WARNING: Tests cannot rely on the exact error strings shown above because we -## specifically allow these messages to be overridden by -## missing_component_hook. The prefix is all we can be sure of. +## NOTE: Tests cannot rely on the exact error strings shown above because we +## specifically allow these messages to be overridden by +## missing_component_hook. The prefix is all we can be sure of. %!error <abc: .*> __gripe_missing_component__ ("abc", "info-file") %!error <abc: .*> __gripe_missing_component__ ("abc", "octave") %!error <abc: .*> __gripe_missing_component__ ("abc", "octave-config") %!error <abc: .*> __gripe_missing_component__ ("abc", "xyz") -%!error __gripe_missing_component__ () -%!error __gripe_missing_component__ ("fcn") -%!error __gripe_missing_component__ ("fcn", 1 , 2) +%!error <Invalid call> __gripe_missing_component__ () +%!error <Invalid call> __gripe_missing_component__ ("fcn") diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/__makeinfo__.m --- a/scripts/help/__makeinfo__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/__makeinfo__.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ function [retval, status] = __makeinfo__ (text, output_type = "plain text", fsee_also) ## Check input - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -161,8 +161,8 @@ ## original return value usually more useful if (status_force) status = status_force; - end - end + endif + endif ## Clean up extra newlines generated by makeinfo if (strcmpi (output_type, "plain text")) diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/__unimplemented__.m --- a/scripts/help/__unimplemented__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/__unimplemented__.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,7 +39,7 @@ function txt = __unimplemented__ (fcn) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -561,7 +561,7 @@ txt = sprintf (["'%s' is a method of class '%s'; it must be ", ... "called with a '%s' argument (see 'help @@%s/%s')."], fcn, cls, cls, cls, fcn); - return + return; endif endfor txt = sprintf ("%s but has not yet been implemented.", txt); @@ -736,7 +736,6 @@ "edges", "empty", "enableservice", - "endsWith", "enumeration", "eraseBetween", "eventlisteners", @@ -813,7 +812,6 @@ "getNumOutputs", "getNumRows", "getOpenFiles", - "getpixelposition", "getpoints", "getProfiles", "getqualitydesc", @@ -959,8 +957,6 @@ "javaMethodEDT", "javaObjectEDT", "join", - "jsondecode", - "jsonencode", "juliandate", "labeledge", "labelnode", @@ -975,7 +971,6 @@ "libpointer", "libstruct", "linkdata", - "listfonts", "loadlibrary", "lsqminnorm", "lsqr", @@ -990,15 +985,11 @@ "memmapfile", "memoize", "MemoizedFunction", - "memory", "mergecats", "meta.abstractDetails", - "meta.class.fromName", "meta.DynamicProperty", "meta.EnumeratedValue", "meta.MetaData", - "meta.package.fromName", - "meta.package.getAllPackages", "methodsview", "MException", "milliseconds", @@ -1053,7 +1044,6 @@ "odextend", "openFile", "opengl", - "ordqz", "outdegree", "outerjoin", "pad", @@ -1086,7 +1076,6 @@ "printpreview", "profsave", "propedit", - "properties", "propertyeditor", "PutCharArray", "PutFullMatrix", @@ -1129,10 +1118,8 @@ "replace", "replaceBetween", "resample", - "rescale", "retime", "reverse", - "rgb2gray", "rlim", "rmboundary", "rmedge", @@ -1140,7 +1127,6 @@ "rmmissing", "rmnode", "rmslivers", - "rng", "rowfun", "rtickangle", "rtickformat", @@ -1165,7 +1151,6 @@ "setHCompSmooth", "setinterpmethod", "setpixelposition", - "setstr", "setTileDim", "settimeseriesnames", "setTscale", @@ -1193,13 +1178,11 @@ "ss2tf", "stack", "standardizeMissing", - "startsWith", "stats", "step", "stopasync", "str2mat", "streamparticles", - "streamribbon", "streamslice", "string", "strings", @@ -1336,20 +1319,18 @@ "xmlread", "xmlwrite", "xslt", - "xtickangle", "xtickformat", "year", "years", "ymd", - "ytickangle", "ytickformat", "yyaxis", "yyyymmdd", - "ztickangle", "ztickformat", }; rlist = list; + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/bessel.m --- a/scripts/help/bessel.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/bessel.m Thu Nov 19 13:08:00 2020 -0800 @@ -101,4 +101,4 @@ endfunction -%!error bessel () +%!error <you must use besselj, ...> bessel () diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/doc.m --- a/scripts/help/doc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/doc.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,10 +41,6 @@ function retval = doc (function_name) - if (nargin > 1) - print_usage (); - endif - if (nargin == 1) if (! ischar (function_name)) error ("doc: FUNCTION_NAME must be a string"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/get_first_help_sentence.m --- a/scripts/help/get_first_help_sentence.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/get_first_help_sentence.m Thu Nov 19 13:08:00 2020 -0800 @@ -52,7 +52,7 @@ function [text, status] = get_first_help_sentence (name, max_len = 80) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -109,7 +109,9 @@ text = help_text(1:max_len); endif endif + status = 0; + endfunction ## This function extracts the first sentence from a Texinfo help text. @@ -182,8 +184,7 @@ %! "Return the first sentence...") ## Test input validation -%!error get_first_help_sentence () -%!error get_first_help_sentence (1, 2, 3) +%!error <Invalid call> get_first_help_sentence () %!error <NAME must be a string> get_first_help_sentence (1) %!error <MAX_LEN must be positive integer> get_first_help_sentence ("ls", "a") %!error <MAX_LEN must be positive integer> get_first_help_sentence ("ls", 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/help.m --- a/scripts/help/help.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/help.m Thu Nov 19 13:08:00 2020 -0800 @@ -224,5 +224,5 @@ ## Test input validation %!error <invalid input> help (42) -%!error <invalid input> help ("abc", "def") +%!error <called with too many inputs> help ("abc", "def") %!error <'_! UNLIKELY_FCN! _' not found> help ("_! UNLIKELY_FCN! _") diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/lookfor.m --- a/scripts/help/lookfor.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/lookfor.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,8 @@ ## related functions that are not a part of Octave. ## ## The speed of lookup is greatly enhanced by having a cached documentation -## file. See @code{doc_cache_create} for more information. +## file. For more information, +## @pxref{XREFdoc_cache_create,,@code{doc_cache_create}}. ## @seealso{help, doc, which, path, doc_cache_create} ## @end deftypefn diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/module.mk --- a/scripts/help/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -7,6 +7,7 @@ %reldir%/private/__strip_html_tags__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/__gripe_missing_component__.m \ %reldir%/__makeinfo__.m \ %reldir%/__unimplemented__.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/print_usage.m --- a/scripts/help/print_usage.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/print_usage.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,7 +45,7 @@ error ("Octave:invalid-context", "print_usage: invalid function\n"); endif fullname = evalin ("caller", 'mfilename ("fullpath")'); - if (strcmp (fullname(end-length(name)+1:end), name)) + if (strcmp (fullname(end-length (name)+1:end), name)) fullname = [fullname ".m"]; endif elseif (! ischar (name)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/private/__strip_html_tags__.m --- a/scripts/help/private/__strip_html_tags__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/private/__strip_html_tags__.m Thu Nov 19 13:08:00 2020 -0800 @@ -37,7 +37,7 @@ stop = find (html_text == ">"); if (length (start) == length (stop)) text = html_text; - for n = length(start):-1:1 + for n = length (start):-1:1 text (start (n):stop (n)) = []; endfor text = strip_superfluous_endlines (text); diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/slash.m --- a/scripts/help/slash.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/slash.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,10 +61,10 @@ ## ## For dense matrices, backslash uses the Gaussian Elimination algorithm ## with partial pivoting. For sparse matrices, backslash uses a direct -## method to compute an LU factorization (@pxref{XREFlu,,lu}). The direct -## method tries to minimize ``fill-in'' of zeros but it could nonetheless use a -## lot of memory; if this is a concern, consider an iterative method -## (@pxref{XREFcgs,,cgs} or @pxref{XREFgmres,,gmres}). +## method to compute an LU factorization (@pxref{XREFlu,,@code{lu}}). The +## direct method tries to minimize ``fill-in'' of zeros but it could +## nonetheless use a lot of memory; if this is a concern, consider an iterative +## method (@pxref{XREFcgs,,@code{cgs}} or @pxref{XREFgmres,,@code{gmres}}). ## ## @item @code{/} Matrix Right Division ## The forward slash notation can be used to solve systems of the form diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/type.m --- a/scripts/help/type.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/type.m Thu Nov 19 13:08:00 2020 -0800 @@ -155,5 +155,5 @@ %!assert (type ("+"){1}, "+ is an operator") %!assert (type ("end"){1}, "end is a keyword") -%!error type () +%!error <Invalid call> type () %!error <'__NO_NAME__' undefined> type ('__NO_NAME__') diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/warning_ids.m --- a/scripts/help/warning_ids.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/warning_ids.m Thu Nov 19 13:08:00 2020 -0800 @@ -139,6 +139,13 @@ ## By default, the @code{Octave:built-in-variable-assignment} warning is ## enabled. ## +## @item Octave:charmat-truncated +## If the @code{Octave:charmat-truncated} warning is enabled, a warning is +## printed when a character matrix with multiple rows is converted to a string. +## In this case, the Octave interpreter keeps only the first row and discards +## the others. +## By default, the @code{Octave:charmat-truncated} warning is enabled. +## ## @item Octave:classdef-to-struct ## If the @code{Octave:classdef-to-struct} warning is enabled, a warning ## is issued when a classdef object is forcibly converted into a struct with @@ -230,6 +237,12 @@ ## printed for implicit conversions of complex numbers to real numbers. ## By default, the @code{Octave:imag-to-real} warning is disabled. ## +## @item Octave:infinite-loop +## If the @code{Octave:infinite-loop} warning is enabled, a warning is +## printed when an infinite loop is detected such as @code{for i = 1:Inf} or +## @code{while (1)}. +## By default, the @code{Octave:infinite-loop} warning is enabled. +## ## @item Octave:language-extension ## Print warnings when using features that are unique to the Octave ## language and that may still be missing in @sc{matlab}. @@ -384,6 +397,14 @@ ## the warning message is printed just once per Octave session. ## By default, the @code{Octave:glyph-render} warning is enabled. ## +## @item Octave:unimplemented-matlab-functionality +## If the @code{Octave:unimplemented-matlab-functionality} warning is enabled, +## a warning is printed when a @sc{matlab} code construct is used which the +## Octave interpreter parses as valid, but for which Octave does not yet +## implement the functionality. +## By default, the @code{Octave:unimplemented-matlab-functionality} warning is +## enabled. +## ## @item Octave:variable-switch-label ## If the @code{Octave:variable-switch-label} warning is enabled, Octave ## will print a warning if a switch label is not a constant or constant diff -r dc3ee9616267 -r fa2cdef14442 scripts/help/which.m --- a/scripts/help/which.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/help/which.m Thu Nov 19 13:08:00 2020 -0800 @@ -113,6 +113,6 @@ %! str = which ("fftw"); %! assert (str(end-7:end), "fftw.oct"); -%!error which () -%!error which (1) +%!error <Invalid call> which () +%!error <Invalid call> which (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/image/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/autumn.m --- a/scripts/image/autumn.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/autumn.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = autumn (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("autumn: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/bone.m --- a/scripts/image/bone.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/bone.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = bone (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("bone: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/brighten.m --- a/scripts/image/brighten.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/brighten.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,7 +46,7 @@ function rmap = brighten (arg1, beta) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/cmpermute.m --- a/scripts/image/cmpermute.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/cmpermute.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,7 @@ function [Y, newmap] = cmpermute (X, map, index) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -131,8 +131,8 @@ %! assert (X, max (Y(:)) + 1 - Y); ## Test input validation -%!error cmpermute () -%!error cmpermute (1,2,3,4) +%!error <Invalid call> cmpermute () +%!error <Invalid call> cmpermute (1) %!error <invalid data type 'uint32'> cmpermute (uint32 (magic (16)), jet (256)) %!error <X must be an indexed image> cmpermute (1+i, jet (256)) %!error <X must be an indexed image> cmpermute (sparse (1), jet (256)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/cmunique.m --- a/scripts/image/cmunique.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/cmunique.m Thu Nov 19 13:08:00 2020 -0800 @@ -60,7 +60,7 @@ function [Y, newmap] = cmunique (X, map) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -193,8 +193,7 @@ %! assert (Id, newmap(:,3)(Y+1)); ## Test input validation -%!error cmpermute () -%!error cmpermute (1,2,3) +%!error <Invalid call> cmunique () %!error <X is of invalid data type> cmunique (uint32 (magic (16))) %!error <MAP must be a valid colormap> cmunique (1, "a") %!error <MAP must be a valid colormap> cmunique (1, i) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/colorcube.m --- a/scripts/image/colorcube.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/colorcube.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,12 +42,8 @@ if (nargin == 0) n = rows (colormap); - elseif (nargin == 1) - if (! isscalar (n)) - error ("colorcube: N must be a scalar"); - endif - else - print_usage (); + elseif (! isscalar (n)) + error ("colorcube: N must be a scalar"); endif if (n < 9) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/colormap.m --- a/scripts/image/colormap.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/colormap.m Thu Nov 19 13:08:00 2020 -0800 @@ -177,7 +177,7 @@ %!error colormap (1,2,3) %!error <MAP must be a real-valued N x 3> colormap ({1,2,3}) %!error <MAP must be a real-valued N x 3> colormap ([1 i 1]) -%!error <MAP must be a real-valued N x 3> colormap (ones(3,3,3)) +%!error <MAP must be a real-valued N x 3> colormap (ones (3,3,3)) %!error <MAP must be a real-valued N x 3> colormap ([1 0 1 0]) %!error <all MAP values must be in the range> colormap ([-1 0 0]) %!error <all MAP values must be in the range> colormap ([2 0 0]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/contrast.m --- a/scripts/image/contrast.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/contrast.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,9 +35,7 @@ function cmap = contrast (x, n) - if (nargin > 2) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) hf = get (0, "currentfigure"); if (! isempty (hf)) n = rows (get (hf, "colormap")); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/cool.m --- a/scripts/image/cool.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/cool.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,9 +35,7 @@ function map = cool (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("cool: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/copper.m --- a/scripts/image/copper.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/copper.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = copper (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("copper: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/cubehelix.m --- a/scripts/image/cubehelix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/cubehelix.m Thu Nov 19 13:08:00 2020 -0800 @@ -26,6 +26,7 @@ ## -*- texinfo -*- ## @deftypefn {} {@var{map} =} cubehelix () ## @deftypefnx {} {@var{map} =} cubehelix (@var{n}) +## @deftypefnx {} {@var{map} =} cubehelix (@var{n}, @var{start}, @var{rots}, @var{hue}, @var{gamma}) ## Create cubehelix colormap. ## ## This colormap varies from black to white going though blue, green, and red @@ -50,9 +51,7 @@ function map = cubehelix (n, start = 0.5, rots = -1.5, hue = 1, gamma = 1) - if (nargin > 5) - print_usage (); - elseif (nargin > 0) + if (nargin > 0) if (! isscalar (n)) error ("cubehelix: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/flag.m --- a/scripts/image/flag.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/flag.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = flag (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("flag: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/frame2im.m --- a/scripts/image/frame2im.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/frame2im.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function [x, map] = frame2im (frame) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! all (isfield (frame, {"cdata", "colormap"}))) error ("frame2im: F must be a struct with the fields colormap and cdata"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/gray.m --- a/scripts/image/gray.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/gray.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = gray (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("gray: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/gray2ind.m --- a/scripts/image/gray2ind.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/gray2ind.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,9 +42,9 @@ function [I, map] = gray2ind (I, n = 64) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); - elseif (! isreal (I) || issparse (I) || ! ismatrix(I)) + elseif (! isreal (I) || issparse (I) || ! ismatrix (I)) error ("gray2ind: I must be a grayscale or binary image"); elseif (! isscalar (n) || n < 1 || n > 65536) error ("gray2ind: N must be a positive integer in the range [1, 65536]"); @@ -106,8 +106,7 @@ %! assert (class (gray2ind ([0.0 0.5 1.0], 257)), "uint16"); ## Test input validation -%!error gray2ind () -%!error gray2ind (1,2,3) +%!error <Invalid call> gray2ind () %!error <I must be a grayscale or binary image> gray2ind ({1}) %!error <I must be a grayscale or binary image> gray2ind ([1+i]) %!error <I must be a grayscale or binary image> gray2ind (sparse ([1])) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/hot.m --- a/scripts/image/hot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/hot.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = hot (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("hot: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/hsv.m --- a/scripts/image/hsv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/hsv.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,9 +40,7 @@ function map = hsv (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("hsv: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/hsv2rgb.m --- a/scripts/image/hsv2rgb.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/hsv2rgb.m Thu Nov 19 13:08:00 2020 -0800 @@ -64,7 +64,7 @@ ## where f_x(hue) is a piecewise defined function for ## each color with f_r(hue-2/3) = f_g(hue) = f_b(hue-1/3). - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -136,8 +136,7 @@ %!assert (hsv2rgb (sparse ([1 1 1])), sparse ([1 0 0])) ## Test input validation -%!error hsv2rgb () -%!error hsv2rgb (1,2) +%!error <Invalid call> hsv2rgb () %!error <invalid data type> hsv2rgb ({1}) %!error <HSV must be a colormap or HSV image> hsv2rgb (ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/im2double.m --- a/scripts/image/im2double.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/im2double.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ function img = im2double (img, im_type) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/im2frame.m --- a/scripts/image/im2frame.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/im2frame.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function frame = im2frame (x, map = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (ndims (x) > 4) error ("im2frame: X and RGB must be a single image"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/imfinfo.m --- a/scripts/image/imfinfo.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/imfinfo.m Thu Nov 19 13:08:00 2020 -0800 @@ -188,7 +188,7 @@ %! assert (error_thrown, true); ## Test input validation -%!error imfinfo () -%!error imfinfo (1,2,3) +%!error <Invalid call> imfinfo () +%!error <Invalid call> imfinfo (1,2,3) %!error <FILENAME must be a string> imfinfo (1) %!error <EXT must be a string> imfinfo ("foo", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/imformats.m --- a/scripts/image/imformats.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/imformats.m Thu Nov 19 13:08:00 2020 -0800 @@ -77,11 +77,7 @@ function varargout = imformats (arg1, arg2, arg3) - if (nargin > 3) - print_usage (); - endif - - mlock (); # prevent formats to be removed by "clear all" + mlock (); # prevent formats being removed by "clear all" persistent formats = default_formats (); if (nargin == 0 && nargout == 0) @@ -96,7 +92,7 @@ switch (tolower (arg1)) case "add", if (! isstruct (arg2)) - error ("imformats: FORMAT to %s must be a structure.", arg1); + error ("imformats: FORMAT to %s must be a structure", arg1); endif arrayfun (@is_valid_format, arg2); formats(end + 1: end + numel (arg2)) = arg2; @@ -104,21 +100,21 @@ case {"remove", "update"}, if (! ischar (arg2)) - error ("imformats: EXT to %s must be a string.", arg1); + error ("imformats: EXT to %s must be a string", arg1); endif - ## FIXME: suppose a format with multiple extensions. If one of + ## FIXME: Suppose a format with multiple extensions; if one of ## them is requested to be removed, should we remove the ## whole format, or just that extension from the format? match = find_ext_idx (formats, arg2); if (! any (match)) - error ("imformats: no EXT '%s' found.", arg2); + error ("imformats: no EXT '%s' found", arg2); endif if (strcmpi (arg1, "remove")) formats(match) = []; else ## then it's update if (! isstruct (arg3)) - error ("imformats: FORMAT to update must be a structure."); + error ("imformats: FORMAT to update must be a structure"); endif is_valid_format (arg3); formats(match) = arg3; @@ -130,7 +126,7 @@ otherwise ## then we look for a format with that extension. match = find_ext_idx (formats, arg1); - ## For matlab compatibility, if we don't find any format we must + ## For Matlab compatibility, if we don't find any format we must ## return an empty struct with NO fields. We can't use match as mask if (any (match)) varargout{1} = formats(match); @@ -139,7 +135,7 @@ endif endswitch else - error ("imformats: first argument must be either a structure or string."); + error ("imformats: first argument must be either a structure or string"); endif else varargout{1} = formats; @@ -247,7 +243,7 @@ "XWD", {"xwd"}, false; }; - for fidx = 1: rows(coders) + for fidx = 1:rows (coders) formats(fidx).coder = coders{fidx, 1}; formats(fidx).ext = coders{fidx, 2}; formats(fidx).alpha = coders{fidx, 3}; @@ -268,21 +264,24 @@ endfunction function is_valid_format (format) + ## the minimal list of fields required in the structure. We don't ## require multipage because it doesn't exist in matlab min_fields = {"ext", "read", "isa", "write", "info", "alpha", "description"}; fields_mask = isfield (format, min_fields); if (! all (fields_mask)) - error ("imformats: structure has missing field '%s'.", min_fields(! fields_mask){1}); + error ("imformats: structure has missing field '%s'", min_fields(! fields_mask){1}); endif endfunction function match = find_ext_idx (formats, ext) + ## FIXME: what should we do if there's more than one hit? ## Should this function prevent the addition of ## duplicated extensions? match = cellfun (@(x) any (strcmpi (x, ext)), {formats.ext}); + endfunction function bool = isa_magick (coder, filename) @@ -372,7 +371,7 @@ %! unwind_protect %! fmt = imformats ("jpg"); # take jpg as template %! fmt.ext = "new_fmt"; -%! fmt.read = @() true (); +%! fmt.read = @(~) true (); %! imformats ("add", fmt); %! assert (imread (fname), true); %! unwind_protect_cleanup @@ -391,7 +390,7 @@ %! unwind_protect %! fmt = imformats ("jpg"); # take jpg as template %! fmt.ext = "new_fmt1"; -%! fmt.read = @() true(); +%! fmt.read = @(~) true (); %! fmt(2) = fmt(1); %! fmt(2).ext = "new_fmt2"; %! imformats ("add", fmt); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/imshow.m --- a/scripts/image/imshow.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/imshow.m Thu Nov 19 13:08:00 2020 -0800 @@ -268,7 +268,7 @@ %! title ({"imshow with random 100x100x3 matrix", "RGB values > 1 are clipped"}); ## Test input validation -%!error imshow () +%!error <Invalid call> imshow () %!error <IM must be an image> imshow ({"cell"}) %!error <TrueColor image must be uint8> imshow (ones (3,3,3, "uint32")) %!error <TrueColor image must be uint8> imshow (ones (3,3,3, "int16")) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/imwrite.m --- a/scripts/image/imwrite.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/imwrite.m Thu Nov 19 13:08:00 2020 -0800 @@ -129,8 +129,8 @@ ## Test input validation -%!error imwrite () # Wrong # of args -%!error imwrite (1) # Wrong # of args +%!error <Invalid call> imwrite () # Wrong # of args +%!error <Invalid call> imwrite (1) # Wrong # of args %!error imwrite ({"cell"}, "filename.jpg") # Wrong class for img %!error imwrite (1, [], "filename.jpg") # Empty image map %!error imwrite (1, 2, 3) # No filename specified diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/ind2gray.m --- a/scripts/image/ind2gray.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/ind2gray.m Thu Nov 19 13:08:00 2020 -0800 @@ -77,9 +77,8 @@ %!assert (gray2ind (i2g, 100), uint8 (0:99)) ## Test input validation -%!error ind2gray () -%!error ind2gray (1) -%!error ind2gray (1,2,3) +%!error <Invalid call> ind2gray () +%!error <Invalid call> ind2gray (1) %!error <X must be an indexed image> ind2gray (ones (3,3,3), jet (64)) %!error <X must be an indexed image> ind2gray (1+i, jet (64)) %!error <X must be an indexed image> ind2gray (sparse (1), jet (64)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/ind2rgb.m --- a/scripts/image/ind2rgb.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/ind2rgb.m Thu Nov 19 13:08:00 2020 -0800 @@ -66,7 +66,7 @@ [1 2 4 3]); else ## we should never reach here since ind2x() should filter them out - error ("ind2rgb: an indexed image must have 2 or 4 dimensions."); + error ("ind2rgb: an indexed image must have 2 or 4 dimensions"); endif endif @@ -102,8 +102,8 @@ %! assert (rgb(:,3,:), 1/63 * ones (1,1,3)); ## Test input validation -%!error ind2rgb () -%!error ind2rgb (1,2,3) +%!error <Invalid call> ind2rgb () +%!error <Invalid call> ind2rgb (1) %!error <X must be an indexed image> ind2rgb (ones (3,3,3), jet (64)) %!error <X must be an indexed image> ind2rgb (1+i, jet (64)) %!error <X must be an indexed image> ind2rgb (sparse (1), jet (64)) @@ -127,10 +127,10 @@ %! cmap = repmat (linspace (0, 1, 9)(:), [1 3]); %! ind = [0 3 6; 1 4 7; 2 5 8]; %! rgb = repmat (reshape (linspace (0, 1, 9), [3 3]), [1 1 3]); -%! assert (ind2rgb (uint8 (ind), cmap), rgb) -%! assert (ind2rgb (uint16 (ind), cmap), rgb) -%! assert (ind2rgb (uint32 (ind), cmap), rgb) -%! assert (ind2rgb (uint64 (ind), cmap), rgb) +%! assert (ind2rgb (uint8 (ind), cmap), rgb); +%! assert (ind2rgb (uint16 (ind), cmap), rgb); +%! assert (ind2rgb (uint32 (ind), cmap), rgb); +%! assert (ind2rgb (uint64 (ind), cmap), rgb); %! fail ("ind2rgb (int8 (ind), cmap)", "X must be an indexed image") %! fail ("ind2rgb (int16 (ind), cmap)", "X must be an indexed image") %! fail ("ind2rgb (int32 (ind), cmap)", "X must be an indexed image") @@ -139,5 +139,10 @@ %! cmap(65541,:) = cmap(9,:); # index outside the uint16 range %! cmap(9,:) = 0; %! ind(3,3) = 65540; -%! assert (ind2rgb (uint32 (ind), cmap), rgb) -%! assert (ind2rgb (uint64 (ind), cmap), rgb) +%! assert (ind2rgb (uint32 (ind), cmap), rgb); +%! assert (ind2rgb (uint64 (ind), cmap), rgb); + +%!test <*59242> +%! warning ("off", "Octave:ind2rgb:invalid-idx-img", "local"); +%! assert (ind2rgb (uint64 (intmax ("uint64")), jet (64)), ... +%! reshape ([0.5,0,0], [1,1,3])); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/iscolormap.m --- a/scripts/image/iscolormap.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/iscolormap.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,8 +40,8 @@ function retval = iscolormap (cmap) - if (nargin != 1) - print_usage; + if (nargin < 1) + print_usage (); endif retval = (isnumeric (cmap) && isreal (cmap) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/jet.m --- a/scripts/image/jet.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/jet.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = jet (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("jet: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/lines.m --- a/scripts/image/lines.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/lines.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,9 +38,7 @@ function map = lines (n) hf = get (groot, "currentfigure"); - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("lines: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/module.mk --- a/scripts/image/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -13,6 +13,7 @@ %reldir%/private/ind2x.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/autumn.m \ %reldir%/bone.m \ %reldir%/brighten.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/movie.m --- a/scripts/image/movie.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/movie.m Thu Nov 19 13:08:00 2020 -0800 @@ -244,7 +244,8 @@ %! movie (mov, 3, 25); ## Test input validation -%!error movie () +%!error <Invalid call> movie () +%!error <Invalid call> movie (1,2,3,4,5) %!error <MOV must be a frame struct array> movie ({2}) %!error <MOV must contain at least two frames> %! movie (struct ("cdata", [], "colormap", [])); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/ocean.m --- a/scripts/image/ocean.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/ocean.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = ocean (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("ocean: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/pink.m --- a/scripts/image/pink.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/pink.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,9 +38,7 @@ function map = pink (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("pink: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/prism.m --- a/scripts/image/prism.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/prism.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,7 @@ function map = prism (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("prism: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/private/__imfinfo__.m --- a/scripts/image/private/__imfinfo__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/private/__imfinfo__.m Thu Nov 19 13:08:00 2020 -0800 @@ -30,7 +30,7 @@ function info = __imfinfo__ (filename) - if (nargin != 1) + if (nargin < 1) print_usage ("imfinfo"); elseif (! ischar (filename)) error ("imfinfo: FILENAME must be a string"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/private/ind2x.m --- a/scripts/image/private/ind2x.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/private/ind2x.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,22 +58,28 @@ ## It is possible that an integer storage class may not have enough room ## to make the switch, in which case we convert the data to single. maxidx = max (x(:)); - if (isinteger (x)) + is_int = isinteger (x); + if (is_int) if (maxidx == intmax (x)) x = single (x); endif - x += 1; - maxidx += 1; + x += 1; endif ## When there are more colors in the image, than there are in the map, ## pad the colormap with the last color in the map for Matlab compatibility. num_colors = rows (map); - if (num_colors < maxidx) + if (num_colors - is_int < maxidx) warning (["Octave:" caller ":invalid-idx-img"], [caller ": indexed image contains colors outside of colormap"]); - pad = repmat (map(end,:), maxidx - num_colors, 1); - map(end+1:maxidx, :) = pad; + if (numel (x) > maxidx - num_colors + is_int) + ## The image is large. So extend the map. + pad = repmat (map(end,:), maxidx - num_colors + is_int, 1); + map(end+(1:rows (pad)), :) = pad; + else + ## The map extension would be large. So clip the image. + x(x > rows (map)) = rows (map); + endif endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/rainbow.m --- a/scripts/image/rainbow.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/rainbow.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,9 +39,7 @@ function map = rainbow (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("rainbow: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/rgb2gray.m --- a/scripts/image/rgb2gray.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/rgb2gray.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ function I = rgb2gray (rgb) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -161,7 +161,6 @@ %! assert (rgb2gray (single (rgb_double)), single (expected)); ## Test input validation -%!error rgb2gray () -%!error rgb2gray (1,2) +%!error <Invalid call> rgb2gray () %!error <invalid data type 'cell'> rgb2gray ({1}) %!error <RGB must be a colormap or RGB image> rgb2gray (ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/rgb2hsv.m --- a/scripts/image/rgb2hsv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/rgb2hsv.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,7 @@ function hsv = rgb2hsv (rgb) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -113,8 +113,7 @@ %!assert (rgb2hsv (sparse ([1 1 1])), sparse ([0 0 1])) ## Test input validation -%!error rgb2hsv () -%!error rgb2hsv (1,2) +%!error <Invalid call> rgb2hsv () %!error <invalid data type 'cell'> rgb2hsv ({1}) %!error <RGB must be a colormap or RGB image> rgb2hsv (ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/rgb2ind.m --- a/scripts/image/rgb2ind.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/rgb2ind.m Thu Nov 19 13:08:00 2020 -0800 @@ -103,8 +103,8 @@ ## Test input validation -%!error rgb2ind () -%!error rgb2ind (1,2,3,4,5,6,7) +%!error <Invalid call> rgb2ind () +%!error <Invalid call> rgb2ind (1,2) %!error <RGB> rgb2ind (rand (10, 10, 4)) ## FIXME: the following tests simply make sure that rgb2ind and ind2rgb diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/rgbplot.m --- a/scripts/image/rgbplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/rgbplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -52,7 +52,7 @@ function h = rgbplot (cmap, style = "profile") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -91,8 +91,7 @@ %! rgbplot (ocean, "composite"); ## Test input validation -%!error rgbplot () -%!error rgbplot (1,2) +%!error <Invalid call> rgbplot () %!error <CMAP must be a valid colormap> rgbplot ({0 1 0}) %!error <STYLE must be a string> rgbplot ([0 1 0], 2) %!error <unknown STYLE 'nostyle'> rgbplot ([0 1 0], "nostyle") diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/spinmap.m --- a/scripts/image/spinmap.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/spinmap.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,9 +42,7 @@ function spinmap (t = 5, inc = 2) - if (nargin > 2) - print_usage (); - elseif (ischar (t)) + if (ischar (t)) if (strcmpi (t, "inf")) t = Inf; else @@ -56,8 +54,8 @@ cmap = cmap_orig = get (gcf (), "colormap"); - t0 = clock; - while (etime (clock, t0) < t) + t0 = clock (); + while (etime (clock (), t0) < t) cmap = shift (cmap, inc, 1); set (gcf (), "colormap", cmap); drawnow (); diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/spring.m --- a/scripts/image/spring.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/spring.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,9 +35,7 @@ function map = spring (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("spring: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/summer.m --- a/scripts/image/summer.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/summer.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,9 +35,7 @@ function map = summer (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("summer: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/viridis.m --- a/scripts/image/viridis.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/viridis.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,9 +40,7 @@ function map = viridis (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("viridis: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/white.m --- a/scripts/image/white.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/white.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,9 +35,7 @@ function map = white (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("white: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/image/winter.m --- a/scripts/image/winter.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/image/winter.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,9 +35,7 @@ function map = winter (n) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isscalar (n)) error ("winter: N must be a scalar"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/io/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/beep.m --- a/scripts/io/beep.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/io/beep.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,13 +35,9 @@ function beep () - if (nargin != 0) - print_usage (); - endif - puts ("\a"); endfunction -%!error (beep (1)) +%!error beep (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/csvread.m --- a/scripts/io/csvread.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/io/csvread.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ ## @end example ## ## Any optional arguments are passed directly to @code{dlmread} -## (@pxref{XREFdlmread,,dlmread}). +## (@pxref{XREFdlmread,,@code{dlmread}}). ## @seealso{dlmread, textscan, csvwrite, dlmwrite} ## @end deftypefn diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/csvwrite.m --- a/scripts/io/csvwrite.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/io/csvwrite.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ ## @end example ## ## Any optional arguments are passed directly to @code{dlmwrite} -## (@pxref{XREFdlmwrite,,dlmwrite}). +## (@pxref{XREFdlmwrite,,@code{dlmwrite}}). ## @seealso{csvread, dlmwrite, dlmread} ## @end deftypefn diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/fileread.m --- a/scripts/io/fileread.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/io/fileread.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,7 +31,7 @@ function str = fileread (filename) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -64,6 +64,5 @@ %! assert (str, [cstr{1} "\n" cstr{2} "\n" cstr{3} "\n"]); ## Test input validation -%!error fileread () -%!error fileread (1, 2) +%!error <Invalid call> fileread () %!error <FILENAME argument must be a string> fileread (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/importdata.m --- a/scripts/io/importdata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/io/importdata.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,7 +69,7 @@ function [output, delimiter, header_rows] = importdata (fname, delimiter = "", header_rows = -1) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -82,7 +82,7 @@ if (nargin > 1) if (! ischar (delimiter) || (length (delimiter) > 1 && ! strcmp (delimiter, '\t'))) - error("importdata: DELIMITER must be a single character"); + error ("importdata: DELIMITER must be a single character"); endif if (strcmp (delimiter, '\t')) delimiter = "\t"; @@ -98,7 +98,7 @@ ## Check file format ## Get the extension from the filename. - [~, ~, ext, ~] = fileparts (fname); + [~, ~, ext] = fileparts (fname); ext = lower (ext); switch (ext) @@ -175,8 +175,8 @@ ## If no delimiter determined yet, make a guess. if (isempty (delimiter)) - ## This pattern can be fooled, but mostly does the job just fine. - delim = regexpi (row, '[-+\d.e*ij ]+([^-+\de.ij])[-+\de*.ij ]', + ## Look for number, DELIMITER, DELIMITER*, number + delim = regexpi (row, '[-+]?\d*[.]?\d+(?:[ed][-+]?\d+)?[ij]?([^-+\d.deij])\1*[-+]?\d*[.]?\d+(?:[ed][-+]?\d+)?[ij]?', 'tokens', 'once'); if (! isempty (delim)) delimiter = delim{1}; @@ -200,6 +200,14 @@ row = -1; break; else + ## The number of header rows and header columns is now known. + header_cols = find (! isnan (row_data), 1) - 1; + has_rowheaders = (header_cols == 1); + + ## Set colheaders output from textdata if appropriate + ## NOTE: Octave chooses to be Matlab incompatible and return + ## both 'rowheaders' and 'colheaders' when they are present. + ## Matlab allows only one to be present at a time. if (! isempty (output.textdata)) if (delimiter == " ") output.colheaders = regexp (strtrim (output.textdata{end}), @@ -207,9 +215,22 @@ else output.colheaders = ostrsplit (output.textdata{end}, delimiter); endif + + nc_hdr = numel (output.colheaders); + nc_dat = numel (row_data); + if (! has_rowheaders) + if (nc_hdr != nc_dat) + output = rmfield (output, {"rowheaders", "colheaders"}); + else + output = rmfield (output, "rowheaders"); + endif + else + if (nc_hdr != nc_dat-1) + output = rmfield (output, "colheaders"); + endif + endif endif - header_cols = find (! isnan (row_data), 1) - 1; - ## The number of header rows and header columns is now known. + break; endif @@ -243,19 +264,31 @@ fclose (fid); if (num_header_rows >= 0) - header_rows = num_header_rows; + ## User has defined a number of header rows which disagrees with the + ## auto-detected number. Print a warning. + if (num_header_rows < header_rows) + warning ("Octave:importdata:headerrows_mismatch", + "importdata: detected %d header rows, but HEADER_ROWS input configured %d rows", header_rows, num_header_rows); + endif + else + ## use the automatically detected number of header rows + num_header_rows = header_rows; endif ## Now, let the efficient built-in routine do the bulk of the work. if (delimiter == " ") - output.data = dlmread (fname, "", header_rows, header_cols, + output.data = dlmread (fname, "", num_header_rows, header_cols, "emptyvalue", NA); else - output.data = dlmread (fname, delimiter, header_rows, header_cols, + output.data = dlmread (fname, delimiter, num_header_rows, header_cols, "emptyvalue", NA); endif ## Go back and correct any individual values that did not convert. + ## FIXME: This is only efficient when the number of bad conversions is small. + ## Any file with 'rowheaders' will cause the for loop to execute over + ## *every* line in the file. + na_idx = isna (output.data); if (header_cols > 0) na_idx = [(true (rows (na_idx), header_cols)), na_idx]; @@ -265,8 +298,11 @@ file_content = ostrsplit (fileread (fname), "\r\n", true); na_rows = find (any (na_idx, 2)); + ## Prune text lines in header that were already collected + idx = (na_rows(1:min (header_rows, end)) + num_header_rows) <= header_rows; + na_rows(idx) = []; for ridx = na_rows(:)' - row = file_content{ridx+header_rows}; + row = file_content{ridx+num_header_rows}; if (delimiter == " ") fields = regexp (strtrim (row), ' +', 'split'); else @@ -277,28 +313,45 @@ if (! size_equal (missing_idx, fields)) ## Fields completely missing at end of line. Replace with NA. col = columns (fields); - output.data(ridx, (col+1):end) = NA; + ## FIXME: This code should be redundant because dlmread was called + ## with "emptyval", NA. Delete if there are no problems + ## detected after some time. Commented out: 5/23/2020. + ##output.data(ridx, (col+1):end) = NA; missing_idx = missing_idx(1:col); endif text = fields(missing_idx); text = text(! strcmpi (text, "NA")); # Remove valid "NA" entries + text = text(! strcmpi (text, "")); # Remove empty entries if (! isempty (text)) - output.textdata = [output.textdata; text(:)]; + output.textdata(end+1, 1:columns (text)) = text; endif - if (header_cols) - output.rowheaders(end+1, :) = fields(1:header_cols); + if (has_rowheaders) + output.rowheaders(end+1, 1) = fields(1); endif endfor endif - ## Final cleanup to satisfy output configuration + ## Final cleanup to satisfy Matlab compatibility if (all (cellfun ("isempty", output.textdata))) output = output.data; - elseif (! isempty (output.rowheaders) && ! isempty (output.colheaders)) - output = struct ("data", {output.data}, "textdata", {output.textdata}); + else + ## Text fields should be cell array of strings, rather than just cell. + try + output.textdata = cellstr (output.textdata); + end_try_catch + try + output.rowheaders = cellstr (output.rowheaders); + end_try_catch + try + output.colheaders = cellstr (output.colheaders); + end_try_catch + endif + + if (num_header_rows != header_rows) + header_rows = num_header_rows; endif endfunction @@ -377,7 +430,6 @@ %! A.data = [3.1 -7.2 0; 0.012 6.5 128]; %! A.textdata = {"This is a header row."; ... %! "this row does not contain any data, but the next one does."}; -%! A.colheaders = A.textdata (2); %! fn = tempname (); %! fid = fopen (fn, "w"); %! fprintf (fid, "%s\n", A.textdata{:}); @@ -393,6 +445,7 @@ %! ## Column headers, only last row is returned in colheaders %! A.data = [3.1 -7.2 0; 0.012 6.5 128]; %! A.textdata = {"Label1\tLabel2\tLabel3"; +%! ""; %! "col 1\tcol 2\tcol 3"}; %! A.colheaders = {"col 1", "col 2", "col 3"}; %! fn = tempname (); @@ -404,7 +457,7 @@ %! unlink (fn); %! assert (a, A); %! assert (d, "\t"); -%! assert (h, 2); +%! assert (h, 3); %!test %! ## Row headers @@ -425,9 +478,11 @@ %! ## Row/Column headers and Header Text %! A.data = [3.1 -7.2 0; 0.012 6.5 128]; %! A.textdata = {"This is introductory header text" -%! " col1 col2 col3" +%! "col1\tcol2\tcol3" %! "row1" %! "row2"}; +%! A.rowheaders = A.textdata(3:4); +%! A.colheaders = {"col1", "col2", "col3"}; %! fn = tempname (); %! fid = fopen (fn, "w"); %! fprintf (fid, "%s\n", A.textdata{1:2}); @@ -511,8 +566,7 @@ %!test %! ## Missing values and Text Values %! A.data = [3.1 NA 0; 0.012 NA 128]; -%! A.textdata = {char(zeros(1,0)) -%! "NO DATA"}; +%! A.textdata = {"NO DATA"}; %! fn = tempname (); %! fid = fopen (fn, "w"); %! fputs (fid, "3.1\t\t0\n0.012\tNO DATA\t128"); @@ -585,8 +639,37 @@ %! assert (d, ""); %! assert (h, 3); -%!error importdata () -%!error importdata (1,2,3,4) +%!test <*58294> +%! ## Varying values of header lines field +%! fn = tempname (); +%! fid = fopen (fn, "w"); +%! fputs (fid, "header1\nheader2\n3.1\n4.2"); +%! fclose (fid); +%! warning ("off", "Octave:importdata:headerrows_mismatch", "local"); +%! ## Base import +%! [a, d, h] = importdata (fn, ""); +%! assert (a.data, [3.1; 4.2]); +%! assert (a.textdata, {"header1"; "header2"}); +%! assert (h, 2); +%! ## Import with 0 header lines +%! [a, d, h] = importdata (fn, "", 0); +%! assert (a.data, [NA; NA; 3.1; 4.2]); +%! assert (a.textdata, {"header1"; "header2"}); +%! assert (h, 0); +%! ## Import with 1 header lines +%! [a, d, h] = importdata (fn, "", 1); +%! assert (a.data, [NA; 3.1; 4.2]); +%! assert (a.textdata, {"header1"; "header2"}); +%! assert (h, 1); +%! ## Import with 3 header lines +%! [a, d, h] = importdata (fn, "", 3); +%! assert (a.data, [4.2]); +%! assert (a.textdata, {"header1"; "header2"; "3.1"}); +%! assert (h, 3); +%! unlink (fn); + +## Test input validation +%!error <Invalid call> importdata () %!error <FNAME must be a string> importdata (1) %!error <option -pastespecial not implemented> importdata ("-pastespecial") %!error <DELIMITER must be a single character> importdata ("foo", 1) @@ -594,3 +677,10 @@ %!error <HEADER_ROWS must be an integer> importdata ("foo", " ", "1") %!error <HEADER_ROWS must be an integer> importdata ("foo", " ", 1.5) %!error <not implemented for file format .avi> importdata ("foo.avi") +%!warning <detected 2 header rows, but HEADER_ROWS input configured 1 rows> +%! fn = tempname (); +%! fid = fopen (fn, "w"); +%! fputs (fid, "header1\nheader2\n3.1"); +%! fclose (fid); +%! a = importdata (fn, "", 1); +%! unlink (fn); diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/is_valid_file_id.m --- a/scripts/io/is_valid_file_id.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/io/is_valid_file_id.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,18 +31,18 @@ function retval = is_valid_file_id (fid) + if (nargin < 1) + print_usage (); + endif + retval = false; - if (nargin == 1) - try - if (isscalar (fid)) - [file, mode, arch] = fopen (fid); - retval = ! isempty (file); - endif - end_try_catch - else - print_usage (); - endif + try + if (isscalar (fid)) + [file, mode, arch] = fopen (fid); + retval = ! isempty (file); + endif + end_try_catch endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/io/module.mk --- a/scripts/io/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/io/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/beep.m \ %reldir%/csvread.m \ %reldir%/csvwrite.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/java/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/java/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/java/javachk.m --- a/scripts/java/javachk.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/java/javachk.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,7 +69,7 @@ function msg = javachk (feature, caller = "") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (! ischar (feature)) error ("javachk: FEATURE must be a string"); @@ -133,7 +133,7 @@ endfunction -%!testif ; ! __octave_config_info__().build_features.JAVA +%!testif ; ! __octave_config_info__ ().build_features.JAVA %! msg = javachk ("desktop"); %! assert (msg.message, "javachk: this function is not supported, Octave was not compiled with Java support"); %! assert (msg.identifier, "Octave:javachk:java-not-supported"); @@ -158,7 +158,7 @@ %! assert (javachk ("jvm"), stnul); ## Test input validation -%!error javachk () -%!error javachk (1) +%!error <Invalid call> javachk () +%!error <FEATURE must be a string> javachk (1) %!error javachk ("jvm", 2) %!error javachk ("jvm", "feature", "ok") diff -r dc3ee9616267 -r fa2cdef14442 scripts/java/javaclasspath.m --- a/scripts/java/javaclasspath.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/java/javaclasspath.m Thu Nov 19 13:08:00 2020 -0800 @@ -62,10 +62,6 @@ function [path1, path2] = javaclasspath (what = "") - if (nargin > 1) - print_usage (); - endif - ## dynamic classpath dynamic_path = javaMethod ("getClassPath", "org.octave.ClassHelper"); dynamic_path_list = ostrsplit (dynamic_path, pathsep ()); diff -r dc3ee9616267 -r fa2cdef14442 scripts/java/module.mk --- a/scripts/java/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/java/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/javaArray.m \ %reldir%/java_get.m \ %reldir%/java_set.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/java/usejava.m --- a/scripts/java/usejava.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/java/usejava.m Thu Nov 19 13:08:00 2020 -0800 @@ -54,7 +54,7 @@ function retval = usejava (feature) - if (nargin != 1 || ! ischar (feature)) + if (nargin < 1 || ! ischar (feature)) print_usage (); endif @@ -92,7 +92,6 @@ %! assert (usejava ("jvm"), true); ## Test input validation -%!error usejava () -%!error usejava (1, 2) -%!error usejava (1) +%!error <Invalid call> usejava () +%!error <Invalid call> usejava (1) %!error <unrecognized FEATURE> usejava ("abc") diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/@inline/argnames.m --- a/scripts/legacy/@inline/argnames.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/@inline/argnames.m Thu Nov 19 13:08:00 2020 -0800 @@ -32,7 +32,7 @@ function args = argnames (obj) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/@inline/char.m --- a/scripts/legacy/@inline/char.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/@inline/char.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function expr = char (obj) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/@inline/formula.m --- a/scripts/legacy/@inline/formula.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/@inline/formula.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function expr = formula (obj) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/@inline/vectorize.m --- a/scripts/legacy/@inline/vectorize.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/@inline/vectorize.m Thu Nov 19 13:08:00 2020 -0800 @@ -52,7 +52,7 @@ function fcn = vectorize (obj) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/findstr.m --- a/scripts/legacy/findstr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/findstr.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,7 +61,7 @@ "findstr is obsolete; use strfind instead\n"); endif - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -157,6 +157,6 @@ %!assert (findstr ("aba", "abababa", 0), [1, 5]) ## Test input validation -%!error findstr () -%!error findstr ("foo", "bar", 3, 4) +%!error <Invalid call> findstr () +%!error <Invalid call> findstr ("str1") %!error <must have only one non-singleton dimension> findstr (["AB" ; "CD"], "C") diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/flipdim.m --- a/scripts/legacy/flipdim.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/flipdim.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,4 +40,5 @@ endif y = flip (varargin{:}); + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/genvarname.m --- a/scripts/legacy/genvarname.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/genvarname.m Thu Nov 19 13:08:00 2020 -0800 @@ -114,7 +114,7 @@ "genvarname is obsolete; use matlab.lang.makeValidName or matlab.lang.makeUniqueStrings instead\n"); endif - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -227,8 +227,7 @@ %!assert (genvarname ("x", {"a", "b"; "x", "d"}), "x1") ## Test input validation -%!error genvarname () -%!error genvarname (1,2,3) +%!error <Invalid call> genvarname () %!error <more than one STR is given, it must be a cellstr> genvarname (char ("a", "b", "c")) %!error <STR must be a string or cellstr> genvarname (1) %!error <more than one exclusion is given, it must be a cellstr> genvarname ("x", char ("a", "b", "c")) diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/isdir.m --- a/scripts/legacy/isdir.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/isdir.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,7 @@ "isdir is obsolete; use isfolder or dir_in_loadpath instead\n"); endif - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -69,5 +69,4 @@ %!assert (isdir (pwd ())) %!assert (! isdir (tempname ())) -%!error isdir () -%!error isdir (1, 2) +%!error <Invalid call> isdir () diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/module.mk --- a/scripts/legacy/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/__vectorize__.m \ %reldir%/findstr.m \ %reldir%/flipdim.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/setstr.m --- a/scripts/legacy/setstr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/setstr.m Thu Nov 19 13:08:00 2020 -0800 @@ -7,19 +7,21 @@ ## ## This file is part of Octave. ## -## Octave is free software; you can redistribute it and/or modify it +## Octave is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or (at -## your option) any later version. +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. +## <https://www.gnu.org/licenses/>. +## +######################################################################## ## -*- texinfo -*- ## @deftypefn {} {@var{s} =} setstr (@var{x}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/strmatch.m --- a/scripts/legacy/strmatch.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/strmatch.m Thu Nov 19 13:08:00 2020 -0800 @@ -70,7 +70,7 @@ "strmatch is obsolete; use strncmp or strcmp instead\n"); endif - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -150,7 +150,7 @@ ## Test input validation %!error <Invalid call to strmatch> strmatch () %!error <Invalid call to strmatch> strmatch ("a") -%!error <Invalid call to strmatch> strmatch ("a", "aaa", "exact", 1) +%!error <called with too many inputs> strmatch ("a", "aaa", "exact", 1) %!error <S must contain only one string> strmatch ({"a", "b"}, "aaa") %!error <S must be a string> strmatch (1, "aaa") %!error <S must be a string> strmatch (char ("a", "bb"), "aaa") diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/strread.m --- a/scripts/legacy/strread.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/strread.m Thu Nov 19 13:08:00 2020 -0800 @@ -354,7 +354,7 @@ ## Check for unsupported format specifiers errpat = '(\[.*\]|[cq]|[nfdu]8|[nfdu]16|[nfdu]32|[nfdu]64)'; if (! all (cellfun ("isempty", regexp (fmt_words(idy2), errpat)))) - error ("strread: %q, %c, %[] or bit width format specifiers are not supported yet."); + error ("strread: %q, %c, %[] or bit width format specifiers are not supported yet"); endif ## Format conversion specifiers following literals w/o space/delim diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/textread.m --- a/scripts/legacy/textread.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/textread.m Thu Nov 19 13:08:00 2020 -0800 @@ -346,7 +346,7 @@ ## Read multiple lines using empty format string %!test %! f = tempname (); -%! unlink (f); +%! sts = unlink (f); %! fid = fopen (f, "w"); %! d = rand (1, 4); %! fprintf (fid, " %f %f %f %f ", d); @@ -358,7 +358,7 @@ ## Empty format, corner case = one line w/o EOL %!test %! f = tempname (); -%! unlink (f); +%! sts = unlink (f); %! fid = fopen (f, "w"); %! d = rand (1, 4); %! fprintf (fid, " %f %f %f %f ", d); diff -r dc3ee9616267 -r fa2cdef14442 scripts/legacy/vectorize.m --- a/scripts/legacy/vectorize.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/legacy/vectorize.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,7 +48,7 @@ "vectorize is unreliable; its use is strongly discouraged\n"); endif - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -68,8 +68,10 @@ else error ("vectorize: FUN must be a string or anonymous function handle"); endif + endfunction + %!assert (vectorize ("x.^2 + 1"), "x.^2 + 1") %!test %! fh = @(x) x.^2 + 1; @@ -91,7 +93,5 @@ %! assert (finfo.function, "@(x) 2 .^ x .^ 5"); ## Test input validation -%!error vectorize () -%!error vectorize (1, 2) +%!error <Invalid call> vectorize () %!error <FUN must be a string or anonymous function handle> vectorize (1) - diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/linear-algebra/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/bandwidth.m --- a/scripts/linear-algebra/bandwidth.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/bandwidth.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function [lower, upper] = bandwidth (A, type) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -108,8 +108,7 @@ %! assert ([a,b], [4,4]); ## Test input validation -%!error bandwidth () -%!error bandwidth (1,2,3) +%!error <Invalid call> bandwidth () %!error <A must be a 2-D numeric or logical> bandwidth ("string", "lower") %!error <A must be a 2-D numeric or logical> bandwidth (ones (3,3,3), "lower") %!error <TYPE must be "lower" or "upper"> bandwidth (ones (2), "uper") diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/commutation_matrix.m --- a/scripts/linear-algebra/commutation_matrix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/commutation_matrix.m Thu Nov 19 13:08:00 2020 -0800 @@ -76,7 +76,7 @@ function k = commutation_matrix (m, n) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); else if (! (isscalar (m) && m == fix (m) && m > 0)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/cond.m --- a/scripts/linear-algebra/cond.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/cond.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,8 +39,8 @@ ## ## By default, @code{@var{p} = 2} is used which implies a (relatively slow) ## singular value decomposition. Other possible selections are -## @code{@var{p} = 1, Inf, "fro"} which are generally faster. See @code{norm} -## for a full discussion of possible @var{p} values. +## @code{@var{p} = 1, Inf, "fro"} which are generally faster. For a full +## discussion of possible @var{p} values, @pxref{XREFnorm,,@code{norm}}. ## ## The condition number of a matrix quantifies the sensitivity of the matrix ## inversion operation when small changes are made to matrix elements. Ideally @@ -53,7 +53,7 @@ function retval = cond (A, p = 2) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -95,8 +95,7 @@ %!assert (cond ([1, 2; 2, 1]), 3, sqrt (eps)) %!assert (cond ([1, 2, 3; 4, 5, 6; 7, 8, 9]) > 1.0e+16) -%!error cond () -%!error cond (1, 2, 3) +%!error <Invalid call> cond () %!error <A must be a 2-D matrix> cond (ones (1,3,3)) %!error <A must not contain Inf or NaN value> cond ([1, 2;Inf 4]) %!error <A must not contain Inf or NaN value> cond ([1, 2;NaN 4]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/condeig.m --- a/scripts/linear-algebra/condeig.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/condeig.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ function [v, lambda, c] = condeig (a) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -134,12 +134,11 @@ %! assert (lambda, expected_lambda, 0.001); %! assert (c, expected_c, 0.001); -# Test empty input +## Test empty input %!assert (condeig ([]), []) ## Test input validation -%!error condeig () -%!error condeig (1,2) +%!error <Invalid call> condeig () %!error <A must be a square numeric matrix> condeig ({1}) %!error <A must be a square numeric matrix> condeig (ones (3,2)) %!error <A must be a square numeric matrix> condeig (ones (2,2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/condest.m --- a/scripts/linear-algebra/condest.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/condest.m Thu Nov 19 13:08:00 2020 -0800 @@ -26,8 +26,12 @@ ## -*- texinfo -*- ## @deftypefn {} {@var{cest} =} condest (@var{A}) ## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{t}) -## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{solvefun}, @var{t}, @var{p1}, @var{p2}, @dots{}) -## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{solvefun}, @var{t}, @var{p1}, @var{p2}, @dots{}) +## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{Ainvfcn}) +## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{Ainvfcn}, @var{t}) +## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{Ainvfcn}, @var{t}, @var{p1}, @var{p2}, @dots{}) +## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{Ainvfcn}) +## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{Ainvfcn}, @var{t}) +## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{Ainvfcn}, @var{t}, @var{p1}, @var{p2}, @dots{}) ## @deftypefnx {} {[@var{cest}, @var{v}] =} condest (@dots{}) ## ## Estimate the 1-norm condition number of a square matrix @var{A} using @@ -35,54 +39,56 @@ ## ## The optional input @var{t} specifies the number of test vectors (default 5). ## -## If the matrix is not explicit, e.g., when estimating the condition number of -## @var{A} given an LU@tie{}factorization, @code{condest} uses the following -## functions: +## The input may be a matrix @var{A} (the algorithm is particularly +## appropriate for large, sparse matrices). Alternatively, the behavior of +## the matrix can be defined implicitly by functions. When using an implicit +## definition, @code{condest} requires the following functions: ## ## @itemize @minus -## @item @var{Afcn} which must return +## @item @code{@var{Afcn} (@var{flag}, @var{x})} which must return ## ## @itemize @bullet ## @item -## the dimension @var{n} of @var{a}, if @var{flag} is @qcode{"dim"} +## the dimension @var{n} of @var{A}, if @var{flag} is @qcode{"dim"} ## ## @item -## true if @var{a} is a real operator, if @var{flag} is @qcode{"real"} +## true if @var{A} is a real operator, if @var{flag} is @qcode{"real"} ## ## @item -## the result @code{@var{a} * @var{x}}, if @var{flag} is "notransp" +## the result @code{@var{A} * @var{x}}, if @var{flag} is "notransp" ## ## @item -## the result @code{@var{a}' * @var{x}}, if @var{flag} is "transp" +## the result @code{@var{A}' * @var{x}}, if @var{flag} is "transp" ## @end itemize ## -## @item @var{solvefun} which must return +## @item @code{@var{Ainvfcn} (@var{flag}, @var{x})} which must return ## ## @itemize @bullet ## @item -## the dimension @var{n} of @var{a}, if @var{flag} is @qcode{"dim"} +## the dimension @var{n} of @code{inv (@var{A})}, if @var{flag} is +## @qcode{"dim"} ## ## @item -## true if @var{a} is a real operator, if @var{flag} is @qcode{"real"} +## true if @code{inv (@var{A})} is a real operator, if @var{flag} is +## @qcode{"real"} ## ## @item -## the result @code{@var{a} \ @var{x}}, if @var{flag} is "notransp" +## the result @code{inv (@var{A}) * @var{x}}, if @var{flag} is "notransp" ## ## @item -## the result @code{@var{a}' \ @var{x}}, if @var{flag} is "transp" +## the result @code{inv (@var{A})' * @var{x}}, if @var{flag} is "transp" ## @end itemize ## @end itemize ## -## The parameters @var{p1}, @var{p2}, @dots{} are arguments of +## Any parameters @var{p1}, @var{p2}, @dots{} are additional arguments of ## @code{@var{Afcn} (@var{flag}, @var{x}, @var{p1}, @var{p2}, @dots{})} -## and @code{@var{solvefcn} (@var{flag}, @var{x}, @var{p1}, @var{p2}, -## @dots{})}. +## and @code{@var{Ainvfcn} (@var{flag}, @var{x}, @var{p1}, @var{p2}, @dots{})}. ## ## The principal output is the 1-norm condition number estimate @var{cest}. ## -## The optional second output is an approximate null vector when @var{cest} is -## large; it satisfies the equation -## @code{norm (A*v, 1) == norm (A, 1) * norm (@var{v}, 1) / @var{est}}. +## The optional second output @var{v} is an approximate null vector; it +## satisfies the equation @code{norm (@var{A}*@var{v}, 1) == +## norm (@var{A}, 1) * norm (@var{v}, 1) / @var{cest}}. ## ## Algorithm Note: @code{condest} uses a randomized algorithm to approximate ## the 1-norms. Therefore, if consistent results are required, the @@ -104,7 +110,7 @@ ## Pseudospectra}. @url{https://citeseer.ist.psu.edu/223007.html} ## @end itemize ## -## @seealso{cond, norm, normest1, normest} +## @seealso{cond, rcond, norm, normest1, normest} ## @end deftypefn ## Code originally licensed under: @@ -142,10 +148,6 @@ ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. -## Author: Jason Riedy <ejr@cs.berkeley.edu> -## Keywords: linear-algebra norm estimation -## Version: 0.2 - function [cest, v] = condest (varargin) if (nargin < 1 || nargin > 6) @@ -154,8 +156,8 @@ have_A = false; have_t = false; - have_apply_normest1 = false; - have_solve_normest1 = false; + have_Afcn = false; + have_Ainvfcn = false; if (isnumeric (varargin{1})) A = varargin{1}; @@ -166,8 +168,8 @@ n = rows (A); if (nargin > 1) if (is_function_handle (varargin{2})) - solve = varargin{2}; - have_solve_normest1 = true; + Ainvfcn = varargin{2}; + have_Ainvfcn = true; if (nargin > 2) t = varargin{3}; have_t = true; @@ -175,23 +177,20 @@ else t = varargin{2}; have_t = true; - real_op = isreal (A); endif - else - real_op = isreal (A); endif elseif (is_function_handle (varargin{1})) if (nargin == 1) - error("condest: must provide SOLVEFCN when using AFCN"); + error ("condest: must provide AINVFCN when using AFCN"); endif - apply = varargin{1}; - have_apply_normest1 = true; + Afcn = varargin{1}; + have_Afcn = true; if (! is_function_handle (varargin{2})) - error("condest: SOLVEFCN must be a function handle"); + error ("condest: AINVFCN must be a function handle"); endif - solve = varargin{2}; - have_solve_normest1 = true; - n = apply ("dim", [], varargin{4:end}); + Ainvfcn = varargin{2}; + have_Ainvfcn = true; + n = Afcn ("dim", [], varargin{4:end}); if (nargin > 2) t = varargin{3}; have_t = true; @@ -207,99 +206,131 @@ ## Disable warnings which may be emitted during calculation process. warning ("off", "Octave:nearly-singular-matrix", "local"); - if (! have_solve_normest1) - ## prepare solve in normest1 form + if (! have_Ainvfcn) + ## Prepare Ainvfcn in normest1 form if (issparse (A)) - [L, U, P, Pc] = lu (A); - solve = @(flag, x) solve_sparse (flag, x, n, real_op, L, U, P, Pc); + [L, U, P, Q] = lu (A); + Ainvfcn = @inv_sparse_fcn; else [L, U, P] = lu (A); - solve = @(flag, x) solve_not_sparse (flag, x, n, real_op, L, U, P); + Q = []; + Ainvfcn = @inv_full_fcn; endif - ## Check for singular matrices before continuing + ## Check for singular matrices before continuing (bug #46737) if (any (diag (U) == 0)) cest = Inf; v = []; return; endif + + ## Initialize solver + Ainvfcn ("init", A, L, U, P, Q); + clear L U P Q; endif if (have_A) Anorm = norm (A, 1); else - Anorm = normest1 (apply, t, [], varargin{4:end}); + Anorm = normest1 (Afcn, t, [], varargin{4:end}); endif - [Ainv_norm, v, w] = normest1 (solve, t, [], varargin{4:end}); + [Ainv_norm, v, w] = normest1 (Ainvfcn, t, [], varargin{4:end}); cest = Anorm * Ainv_norm; if (isargout (2)) v = w / norm (w, 1); endif + if (! have_Ainvfcn) + Ainvfcn ("clear"); # clear persistent memory in subfunction + endif + endfunction -function value = solve_sparse (flag, x, n, real_op, L , U , P , Pc) - ## FIXME: Sparse algorithm is less accurate than full matrix version - ## See BIST test for non-orthogonal matrix where relative tolerance +function retval = inv_sparse_fcn (flag, x, varargin) + ## FIXME: Sparse algorithm is less accurate than full matrix version. + ## See BIST test for asymmetric matrix where relative tolerance ## of 1e-12 is used for sparse, but 4e-16 for full matrix. + ## BUT, does it really matter for an "estimate"? + persistent Ainv Ainvt n isreal_op; + switch (flag) case "dim" - value = n; + retval = n; case "real" - value = real_op; + retval = isreal_op; case "notransp" - value = Pc' * (U \ (L \ (P * x))); + retval = Ainv * x; case "transp" - value = P' * (L' \ (U' \ (Pc * x))); + retval = Ainvt * x; + case "init" + n = rows (x); + isreal_op = isreal (x); + [L, U, P, Q] = deal (varargin{1:4}); + Ainv = Q * (U \ (L \ P)); + Ainvt = P' * (L' \ (U' \ Q')); + case "clear" # called to free memory at end of condest function + clear Ainv Ainvt n isreal_op; endswitch + endfunction -function value = solve_not_sparse (flag, x, n, real_op, L, U, P) +function retval = inv_full_fcn (flag, x, varargin) + persistent Ainv Ainvt n isreal_op; + switch (flag) case "dim" - value = n; + retval = n; case "real" - value = real_op; + retval = isreal_op; case "notransp" - value = U \ (L \ (P * x)); + retval = Ainv * x; case "transp" - value = P' * (L' \ (U' \ x)); + retval = Ainvt \ x; + case "init" + n = rows (x); + isreal_op = isreal (x); + [L, U, P] = deal (varargin{1:3}); + Ainv = U \ (L \ P); + Ainvt = P' * (L' \ U'); + case "clear" # called to free memory at end of condest function + clear Ainv Ainvt n isreal_op; endswitch + endfunction ## Note: These test bounds are very loose. There is enough randomization to ## trigger odd cases with hilb(). -%!function value = apply_fun (flag, x, A, m) +%!function retval = __Afcn__ (flag, x, A, m) %! if (nargin == 3) %! m = 1; %! endif %! switch (flag) %! case "dim" -%! value = length (A); +%! retval = length (A); %! case "real" -%! value = isreal (A); +%! retval = isreal (A); %! case "notransp" -%! value = x; for i = 1:m, value = A * value;, endfor +%! retval = x; for i = 1:m, retval = A * retval;, endfor %! case "transp" -%! value = x; for i = 1:m, value = A' * value;, endfor +%! retval = x; for i = 1:m, retval = A' * retval;, endfor %! endswitch %!endfunction -%!function value = solve_fun (flag, x, A, m) +%!function retval = __Ainvfcn__ (flag, x, A, m) %! if (nargin == 3) %! m = 1; %! endif %! switch (flag) %! case "dim" -%! value = length (A); +%! retval = length (A); %! case "real" -%! value = isreal (A); +%! retval = isreal (A); %! case "notransp" -%! value = x; for i = 1:m, value = A \ value;, endfor +%! retval = x; for i = 1:m, retval = A \ retval;, endfor %! case "transp" -%! value = x; for i = 1:m, value = A' \ value;, endfor +%! retval = x; for i = 1:m, retval = A' \ retval;, endfor %! endswitch %!endfunction @@ -320,25 +351,25 @@ %!test %! N = 6; %! A = hilb (N); -%! solve = @(flag, x) solve_fun (flag, x, A); -%! cA = condest (A, solve); +%! Ainvfcn = @(flag, x) __Ainvfcn__ (flag, x, A); +%! cA = condest (A, Ainvfcn); %! cA_test = norm (inv (A), 1) * norm (A, 1); %! assert (cA, cA_test, -2^-6); %!test %! N = 6; %! A = hilb (N); -%! apply = @(flag, x) apply_fun (flag, x, A); -%! solve = @(flag, x) solve_fun (flag, x, A); -%! cA = condest (apply, solve); +%! Afcn = @(flag, x) __Afcn__ (flag, x, A); +%! Ainvfcn = @(flag, x) __Ainvfcn__ (flag, x, A); +%! cA = condest (Afcn, Ainvfcn); %! cA_test = norm (inv (A), 1) * norm (A, 1); %! assert (cA, cA_test, -2^-6); -%!test # parameters for apply and solve functions +%!test # parameters for apply and Ainvfcn functions %! N = 6; %! A = hilb (N); %! m = 2; -%! cA = condest (@apply_fun, @solve_fun, [], A, m); +%! cA = condest (@__Afcn__, @__Ainvfcn__, [], A, m); %! cA_test = norm (inv (A^2), 1) * norm (A^2, 1); %! assert (cA, cA_test, -2^-6); @@ -351,7 +382,7 @@ %! assert (cest, Inf); %! assert (v, []); -## Test non-orthogonal matrices +## Test asymmetric matrices %!test <*57968> %! A = reshape (sqrt (0:15), 4, 4); %! cexp = norm (A, 1) * norm (inv (A), 1); @@ -365,9 +396,9 @@ %! assert (cest, cexp, -1e-12); ## Test input validation -%!error condest () -%!error condest (1,2,3,4,5,6,7) -%!error <A must be square> condest ([1 2]) -%!error <must provide SOLVEFCN when using AFCN> condest (@sin) -%!error <SOLVEFCN must be a function handle> condest (@sin, 1) +%!error <Invalid call> condest () +%!error <Invalid call> condest (1,2,3,4,5,6,7) +%!error <A must be square> condest ([1, 2]) +%!error <must provide AINVFCN when using AFCN> condest (@sin) +%!error <AINVFCN must be a function handle> condest (@sin, 1) %!error <argument must be a square matrix or function handle> condest ({1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/cross.m --- a/scripts/linear-algebra/cross.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/cross.m Thu Nov 19 13:08:00 2020 -0800 @@ -50,7 +50,7 @@ function z = cross (x, y, dim) - if (nargin != 2 && nargin != 3) + if (nargin < 2) print_usage (); endif @@ -119,5 +119,8 @@ %! assert (cross (x, y, 2), r, 2e-8); %! assert (cross (x, y, 1), -r, 2e-8); -%!error cross (0,0) -%!error cross () +## Test input validation +%!error <Invalid call> cross () +%!error <Invalid call> cross (1) +## FIXME: Need tests for other error() conditions and warning() calls. +%!error <must have at least one dimension with 3 elements> cross (0,0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/duplication_matrix.m --- a/scripts/linear-algebra/duplication_matrix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/duplication_matrix.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ function d = duplication_matrix (n) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -118,7 +118,7 @@ %! assert (D * vech (B), vec (B), 1e-6); %! assert (D * vech (C), vec (C), 1e-6); -%!error duplication_matrix () +%!error <Invalid call> duplication_matrix () %!error duplication_matrix (0.5) %!error duplication_matrix (-1) %!error duplication_matrix (ones (1,4)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/expm.m --- a/scripts/linear-algebra/expm.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/expm.m Thu Nov 19 13:08:00 2020 -0800 @@ -81,7 +81,7 @@ function r = expm (A) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -103,7 +103,7 @@ n = rows (A); id = eye (n); ## Trace reduction. - A(A == -Inf) = -realmax; + A(A == -Inf) = -realmax (); trshift = trace (A) / n; if (trshift > 0) A -= trshift * id; @@ -157,7 +157,6 @@ %!assert (full (expm (10*eye (3))), expm (full (10*eye (3))), 8*eps) ## Test input validation -%!error expm () -%!error expm (1, 2) +%!error <Invalid call> expm () %!error <expm: A must be a square matrix> expm ({1}) %!error <expm: A must be a square matrix> expm ([1 0;0 1; 2 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/gls.m --- a/scripts/linear-algebra/gls.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/gls.m Thu Nov 19 13:08:00 2020 -0800 @@ -155,10 +155,9 @@ %! assert (gls (y,x,o), [3; 2], 50*eps); ## Test input validation -%!error gls () -%!error gls (1) -%!error gls (1, 2) -%!error gls (1, 2, 3, 4) +%!error <Invalid call> gls () +%!error <Invalid call> gls (1) +%!error <Invalid call> gls (1, 2) %!error gls ([true, true], [1, 2], ones (2)) %!error gls ([1, 2], [true, true], ones (2)) %!error gls ([1, 2], [1, 2], true (2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/housh.m --- a/scripts/linear-algebra/housh.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/housh.m Thu Nov 19 13:08:00 2020 -0800 @@ -133,5 +133,6 @@ %! assert (r, d, 2e-8); %! assert (z, 0, 2e-8); -%!error housh ([0]) -%!error housh () +%!error <Invalid call> housh () +%!error <Invalid call> housh (1) +%!error <Invalid call> housh (1,2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/isbanded.m --- a/scripts/linear-algebra/isbanded.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/isbanded.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,9 +69,9 @@ %!assert (isbanded ([1, 1],1,1)) %!assert (isbanded ([1; 1],1,1)) -%!assert (isbanded (eye(10),0,0)) -%!assert (isbanded (eye(10),1,1)) -%!assert (isbanded (i*eye(10),1,1)) +%!assert (isbanded (eye (10),0,0)) +%!assert (isbanded (eye (10),1,1)) +%!assert (isbanded (i*eye (10),1,1)) %!assert (isbanded (logical (eye (10)),1,1)) %! A = [2 3 0 0 0; 1 2 3 0 0; 0 1 2 3 0; 0 0 1 2 3; 0 0 0 1 2]; @@ -80,10 +80,9 @@ %! assert (! isbanded (A,1,0)); ## Test input validation -%!error isbanded () -%!error isbanded (1) -%!error isbanded (1,2) -%!error isbanded (1,2,3,4) +%!error <Invalid call> isbanded () +%!error <Invalid call> isbanded (1) +%!error <Invalid call> isbanded (1,2) %!error <LOWER and UPPER must be non-negative> isbanded (1, -1, 1) %!error <LOWER and UPPER must be non-negative> isbanded (1, 1, -1) %!error <LOWER and UPPER must be non-negative> isbanded (1, {1}, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/isdefinite.m --- a/scripts/linear-algebra/isdefinite.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/isdefinite.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ function retval = isdefinite (A, tol) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -103,8 +103,7 @@ %!assert (! isdefinite (magic (3))) -%!error isdefinite () -%!error isdefinite (1,2,3) +%!error <Invalid call> isdefinite () %!error <TOL must be a scalar .= 0> isdefinite (1, {1}) %!error <TOL must be a scalar .= 0> isdefinite (1, [1 1]) %!error <TOL must be a scalar .= 0> isdefinite (1, -1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/isdiag.m --- a/scripts/linear-algebra/isdiag.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/isdiag.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,7 +31,7 @@ function retval = isdiag (A) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -60,5 +60,4 @@ %!assert (isdiag (diag (1:10))) ## Test input validation -%!error isdiag () -%!error isdiag (1,2) +%!error <Invalid call> isdiag () diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/ishermitian.m --- a/scripts/linear-algebra/ishermitian.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/ishermitian.m Thu Nov 19 13:08:00 2020 -0800 @@ -52,7 +52,7 @@ function retval = ishermitian (A, skewopt = "nonskew", tol = 0) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -133,8 +133,7 @@ %! assert (! ishermitian (s)); ## Test input validation -%!error ishermitian () -%!error ishermitian (1,2,3,4) +%!error <Invalid call> ishermitian () %!error <second argument must be> ishermitian (1, {"skew"}) %!error <SKEWOPT must be 'skew' or 'nonskew'> ishermitian (1, "foobar") %!error <SKEWOPT must be 'skew' or 'nonskew'> ishermitian (1, "foobar") diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/issymmetric.m --- a/scripts/linear-algebra/issymmetric.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/issymmetric.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,7 @@ function retval = issymmetric (A, skewopt = "nonskew", tol = 0) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -66,9 +66,8 @@ endif ## Validate inputs - retval = (isnumeric (A) || islogical (A)) && issquare (A); - if (! retval) - return; + if (! (isnumeric (A) || islogical (A) || ischar (A))) + error ("issymmetric: A must be a numeric, logical, or character matrix"); endif if (! (strcmp (skewopt, "skew") || strcmp (skewopt, "nonskew"))) @@ -79,13 +78,18 @@ error ("issymmetric: TOL must be a scalar >= 0"); endif + if (! issquare (A)) + retval = false; + return; + endif + ## Calculate symmetry if (strcmp (skewopt, "nonskew")) if (tol == 0) ## check for exact symmetry retval = full (! any ((A != A.')(:))); else - if (islogical (A)) + if (! isnumeric (A)) ## Hack to allow norm to work. Choose single to minimize memory. A = single (A); endif @@ -97,7 +101,7 @@ if (tol == 0) retval = full (! any ((A != -A.')(:))); else - if (islogical (A)) + if (! isnumeric (A)) ## Hack to allow norm to work. Choose single to minimize memory. A = single (A); endif @@ -116,26 +120,21 @@ %!assert (issymmetric ([1, 2.1; 2, 1.1], 0.2)) %!assert (issymmetric ([1, 2i; 2i, 1])) %!assert (issymmetric (speye (100)), true) # Return full logical value. -%!assert (issymmetric (logical (eye (2)))) -%!assert (! issymmetric (logical ([1 1; 0 1]))) -%!assert (issymmetric (logical ([1 1; 0 1]), 0.5)) +%!assert (! issymmetric ([0, 2; -2, 0], "nonskew")) %!assert (issymmetric ([0, 2; -2, 0], "skew")) %!assert (! issymmetric ([0, 2; -2, eps], "skew")) %!assert (issymmetric ([0, 2; -2, eps], "skew", eps)) - -%!assert (! (issymmetric ("test"))) -%!assert (! (issymmetric ("t"))) -%!assert (! (issymmetric (["te"; "et"]))) -%!assert (! issymmetric ({1})) -%!test -%! s.a = 1; -%! assert (! issymmetric (s)); +%!assert (issymmetric (logical (eye (2)))) +%!assert (! issymmetric (logical ([1 1; 0 1]))) +%!assert (issymmetric (logical ([1 1; 0 1]), 0.5)) +%!assert (! issymmetric ("test")) +%!assert (issymmetric ("t")) +%!assert (issymmetric (["te"; "et"])) ## Test input validation -%!error issymmetric () -%!error issymmetric (1,2,3,4) +%!error <Invalid call> issymmetric () %!error <second argument must be> issymmetric (1, {"skew"}) -%!error <SKEWOPT must be 'skew' or 'nonskew'> issymmetric (1, "foobar") +%!error <A must be a numeric,.* matrix> issymmetric ({1}) %!error <SKEWOPT must be 'skew' or 'nonskew'> issymmetric (1, "foobar") %!error <TOL must be a scalar .= 0> issymmetric (1, "skew", {1}) %!error <TOL must be a scalar .= 0> issymmetric (1, "skew", [1 1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/istril.m --- a/scripts/linear-algebra/istril.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/istril.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function retval = istril (A) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -61,5 +61,4 @@ %!assert (! istril (randn (10))) ## Test input validation -%!error istril () -%!error istril (1,2) +%!error <Invalid call> istril () diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/istriu.m --- a/scripts/linear-algebra/istriu.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/istriu.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function retval = istriu (A) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -61,5 +61,4 @@ %!assert (! istriu (randn (10))) ## Test input validation -%!error istriu () -%!error istriu (1,2) +%!error <Invalid call> istriu () diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/krylov.m --- a/scripts/linear-algebra/krylov.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/krylov.m Thu Nov 19 13:08:00 2020 -0800 @@ -71,7 +71,7 @@ defeps = 1e-12; endif - if (nargin < 3 || nargin > 5) + if (nargin < 3) print_usage (); elseif (nargin < 5) ## Default permutation flag. @@ -187,7 +187,7 @@ if ((columns (V) > na) && (length (alpha) == na)) ## Trim to size. V = V(:,1:na); - elseif (columns(V) > na) + elseif (columns (V) > na) krylov_V = V; krylov_na = na; krylov_length_alpha = length (alpha); @@ -198,7 +198,7 @@ ## Construct next Q and multiply. Q = zeros (size (V)); for kk = 1:columns (Q) - Q(pivot_vec(nu-columns(Q)+kk),kk) = 1; + Q(pivot_vec(nu-columns (Q)+kk),kk) = 1; endfor ## Apply Householder reflections. @@ -218,7 +218,7 @@ hv = U(:,i); av = alpha(i); V -= av*hv*(hv'*V); - H(i,nu-columns(V)+(1:columns(V))) = V(pivot_vec(i),:); + H(i,nu-columns (V)+(1:columns (V))) = V(pivot_vec(i),:); endfor endwhile diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/linsolve.m --- a/scripts/linear-algebra/linsolve.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/linsolve.m Thu Nov 19 13:08:00 2020 -0800 @@ -77,7 +77,7 @@ function [x, R] = linsolve (A, b, opts) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -141,8 +141,8 @@ %! opts.TRANSA = true; %! assert (linsolve (A, b, opts), A' \ b); -%!error linsolve () -%!error linsolve (1) +%!error <Invalid call> linsolve () +%!error <Invalid call> linsolve (1) %!error linsolve (1,2,3) %!error <A and B must be numeric> linsolve ({1},2) %!error <A and B must be numeric> linsolve (1,{2}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/logm.m --- a/scripts/linear-algebra/logm.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/logm.m Thu Nov 19 13:08:00 2020 -0800 @@ -52,7 +52,7 @@ function [s, iters] = logm (A, opt_iters = 100) - if (nargin == 0 || nargin > 2) + if (nargin == 0) print_usage (); endif @@ -95,7 +95,7 @@ j(2) = find (tau / 2 <= theta, 1); if (j(1) - j(2) <= 1 || p == 2) m = j(1); - break + break; endif endif k += 1; @@ -182,6 +182,5 @@ %!assert (logm (expm ([0 1i; -1i 0])), [0 1i; -1i 0], 10 * eps) ## Test input validation -%!error logm () -%!error logm (1, 2, 3) +%!error <Invalid call> logm () %!error <logm: A must be a square matrix> logm ([1 0;0 1; 2 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/lscov.m --- a/scripts/linear-algebra/lscov.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/lscov.m Thu Nov 19 13:08:00 2020 -0800 @@ -60,7 +60,7 @@ function [x, stdx, mse, S] = lscov (A, b, V = [], alg) - if (nargin < 2 || nargin > 4) + if (nargin < 2) print_usage (); endif @@ -167,9 +167,9 @@ %! y = Z(:,1); X = [ones(rows(Z),1), Z(:,2:end)]; %! alpha = 0.05; %! [b, stdb, mse] = lscov (X, y); -%! assert(b, V(:,1), 3e-6); -%! assert(stdb, V(:,2), -1.e-5); -%! assert(sqrt (mse), rsd, -1E-6); +%! assert (b, V(:,1), 3e-6); +%! assert (stdb, V(:,2), -1.e-5); +%! assert (sqrt (mse), rsd, -1E-6); %!test %! ## Adapted from example in Matlab documentation @@ -178,41 +178,41 @@ %! X = [ones(size(x1)) x1 x2]; %! y = [.17 .26 .28 .23 .27 .34]'; %! [b, se_b, mse, S] = lscov(X, y); -%! assert(b, [0.1203 0.3284 -0.1312]', 1E-4); -%! assert(se_b, [0.0643 0.2267 0.1488]', 1E-4); -%! assert(mse, 0.0015, 1E-4); -%! assert(S, [0.0041 -0.0130 0.0075; -0.0130 0.0514 -0.0328; 0.0075 -0.0328 0.0221], 1E-4); +%! assert (b, [0.1203 0.3284 -0.1312]', 1E-4); +%! assert (se_b, [0.0643 0.2267 0.1488]', 1E-4); +%! assert (mse, 0.0015, 1E-4); +%! assert (S, [0.0041 -0.0130 0.0075; -0.0130 0.0514 -0.0328; 0.0075 -0.0328 0.0221], 1E-4); %! w = [1 1 1 1 1 .1]'; %! [bw, sew_b, msew] = lscov (X, y, w); -%! assert(bw, [0.1046 0.4614 -0.2621]', 1E-4); -%! assert(sew_b, [0.0309 0.1152 0.0814]', 1E-4); -%! assert(msew, 3.4741e-004, -1E-4); -%! V = .2*ones(length(x1)) + .8*diag(ones(size(x1))); +%! assert (bw, [0.1046 0.4614 -0.2621]', 1E-4); +%! assert (sew_b, [0.0309 0.1152 0.0814]', 1E-4); +%! assert (msew, 3.4741e-004, -1E-4); +%! V = .2*ones (length (x1)) + .8*diag (ones (size (x1))); %! [bg, sew_b, mseg] = lscov (X, y, V); -%! assert(bg, [0.1203 0.3284 -0.1312]', 1E-4); -%! assert(sew_b, [0.0672 0.2267 0.1488]', 1E-4); -%! assert(mseg, 0.0019, 1E-4); +%! assert (bg, [0.1203 0.3284 -0.1312]', 1E-4); +%! assert (sew_b, [0.0672 0.2267 0.1488]', 1E-4); +%! assert (mseg, 0.0019, 1E-4); %! y2 = [y 2*y]; %! [b2, se_b2, mse2, S2] = lscov (X, y2); -%! assert(b2, [b 2*b], 2*eps); -%! assert(se_b2, [se_b 2*se_b], 2*eps); -%! assert(mse2, [mse 4*mse], eps); -%! assert(S2(:, :, 1), S, eps); -%! assert(S2(:, :, 2), 4*S, eps); +%! assert (b2, [b 2*b], 2*eps); +%! assert (se_b2, [se_b 2*se_b], 2*eps); +%! assert (mse2, [mse 4*mse], eps); +%! assert (S2(:, :, 1), S, eps); +%! assert (S2(:, :, 2), 4*S, eps); %!test %! ## Artificial example with positive semi-definite weight matrix %! x = (0:0.2:2)'; -%! y = round(100*sin(x) + 200*cos(x)); +%! y = round (100*sin (x) + 200*cos (x)); %! X = [ones(size(x)) sin(x) cos(x)]; -%! V = eye(numel(x)); +%! V = eye (numel (x)); %! V(end, end-1) = V(end-1, end) = 1; %! [b, seb, mseb, S] = lscov (X, y, V); -%! assert(b, [0 100 200]', 0.2); +%! assert (b, [0 100 200]', 0.2); -%!error lscov () -%!error lscov (1) -%!error lscov (1,2,3,4,5) +## Test input validation +%!error <Invalid call> lscov () +%!error <Invalid call> lscov (1) %!error <A and B must have the same number of rows> lscov (ones (2,2),1) %!warning <algorithm selection input ALG is not yet implemented> %! lscov (1,1, [], "chol"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/module.mk --- a/scripts/linear-algebra/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/bandwidth.m \ %reldir%/commutation_matrix.m \ %reldir%/cond.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/normest.m --- a/scripts/linear-algebra/normest.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/normest.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,7 @@ function [nest, iter] = normest (A, tol = 1e-6) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -96,8 +96,7 @@ %! assert (normest (A), norm (A), 1e-6); ## Test input validation -%!error normest () -%!error normest (1, 2, 3) +%!error <Invalid call> normest () %!error <A must be a numeric .* matrix> normest ([true true]) %!error <A must be .* 2-D matrix> normest (ones (3,3,3)) %!error <TOL must be a real scalar> normest (1, [1, 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/normest1.m --- a/scripts/linear-algebra/normest1.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/normest1.m Thu Nov 19 13:08:00 2020 -0800 @@ -379,7 +379,7 @@ %! assert (iscolumn (it)); ## Test input validation -%!error normest1 () +%!error <Invalid call> normest1 () %!error <A must be a square matrix or a function handle> normest1 ({1}) %!error <A must be a square matrix> normest1 ([1 2]) %!error <X0 must have 2 columns> normest1 (magic (5), :, [1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/null.m --- a/scripts/linear-algebra/null.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/null.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function retval = null (A, tol) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (nargin == 2 && strcmp (tol, "r")) error ("null: option for rational not yet implemented"); @@ -88,7 +88,7 @@ %!test %! A = [1 0; 0 1]; %! assert (null (A), zeros (2,0)); -%! assert (null (single (A)), zeros (2, 0, "single")) +%! assert (null (single (A)), zeros (2, 0, "single")); %!test %! A = [1 0; 1 0]; @@ -96,8 +96,8 @@ %!test %! A = [1 1; 0 0]; -%! assert (null (A), [-1/sqrt(2) 1/sqrt(2)]', eps) -%! assert (null (single (A)), single ([-1/sqrt(2) 1/sqrt(2)]'), eps) +%! assert (null (A), [-1/sqrt(2) 1/sqrt(2)]', eps); +%! assert (null (single (A)), single ([-1/sqrt(2) 1/sqrt(2)]'), eps); %!test %! tol = 1e-4; diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/ols.m --- a/scripts/linear-algebra/ols.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/ols.m Thu Nov 19 13:08:00 2020 -0800 @@ -183,9 +183,8 @@ %! assert (b, [1.4, 2], 2*eps); ## Test input validation -%!error ols () -%!error ols (1) -%!error ols (1, 2, 3) +%!error <Invalid call> ols () +%!error <Invalid call> ols (1) %!error ols ([true, true], [1, 2]) %!error ols ([1, 2], [true, true]) %!error ols (ones (2,2,2), ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/ordeig.m --- a/scripts/linear-algebra/ordeig.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/ordeig.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,17 +35,17 @@ ## appearance of the matrix @code{@var{A}-@var{lambda}*@var{B}}. The pair ## @var{A}, @var{B} is usually the result of a QZ decomposition. ## -## @seealso{ordschur, eig, schur, qz} +## @seealso{ordschur, ordqz, eig, schur, qz} ## @end deftypefn function lambda = ordeig (A, B) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif if (! isnumeric (A) || ! issquare (A)) - error ("ordeig: A must be a square matrix") + error ("ordeig: A must be a square matrix"); endif n = length (A); @@ -53,7 +53,7 @@ if (nargin == 1) B = eye (n); if (isreal (A)) - if (! isquasitri (A)) + if (! is_quasitri (A)) error ("ordeig: A must be quasi-triangular (i.e., upper block triangular with 1x1 or 2x2 blocks on the diagonal)"); endif else @@ -68,7 +68,7 @@ error ("ordeig: A and B must be the same size"); endif if (isreal (A) && isreal (B)) - if (! isquasitri (A) || ! isquasitri (B)) + if (! is_quasitri (A) || ! is_quasitri (B)) error ("ordeig: A and B must be quasi-triangular (i.e., upper block triangular with 1x1 or 2x2 blocks on the diagonal)"); endif else @@ -106,7 +106,7 @@ endfunction ## Check whether a matrix is quasi-triangular -function retval = isquasitri (A) +function retval = is_quasitri (A) if (length (A) <= 2) retval = true; else @@ -140,8 +140,7 @@ %! assert (lambda, 3); ## Test input validation -%!error ordeig () -%!error ordeig (1,2,3) +%!error <Invalid call> ordeig () %!error <A must be a square matrix> ordeig ('a') %!error <A must be a square matrix> ordeig ([1, 2, 3]) %!error <A must be quasi-triangular> ordeig (magic (3)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/orth.m --- a/scripts/linear-algebra/orth.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/orth.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,45 +40,41 @@ function retval = orth (A, tol) - if (nargin == 1 || nargin == 2) - - if (isempty (A)) - retval = []; - return; - endif - - [U, S, V] = svd (A); + if (nargin < 1) + print_usage (); + endif - [rows, cols] = size (A); - - [S_nr, S_nc] = size (S); + if (isempty (A)) + retval = []; + return; + endif - if (S_nr == 1 || S_nc == 1) - s = S(1); - else - s = diag (S); - endif + [U, S, V] = svd (A); + + [rows, cols] = size (A); + + [S_nr, S_nc] = size (S); - if (nargin == 1) - if (isa (A, "single")) - tol = max (size (A)) * s (1) * eps ("single"); - else - tol = max (size (A)) * s (1) * eps; - endif - endif - - rank = sum (s > tol); + if (S_nr == 1 || S_nc == 1) + s = S(1); + else + s = diag (S); + endif - if (rank > 0) - retval = -U(:, 1:rank); + if (nargin == 1) + if (isa (A, "single")) + tol = max (size (A)) * s (1) * eps ("single"); else - retval = zeros (rows, 0); + tol = max (size (A)) * s (1) * eps; endif + endif - else + rank = sum (s > tol); - print_usage (); - + if (rank > 0) + retval = -U(:, 1:rank); + else + retval = zeros (rows, 0); endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/planerot.m --- a/scripts/linear-algebra/planerot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/planerot.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,7 +65,7 @@ function [G, y] = planerot (x) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! (isvector (x) && numel (x) == 2)) error ("planerot: X must be a 2-element vector"); @@ -83,7 +83,7 @@ %! assert (g, [x(1) x(2); -x(2) x(1)] / sqrt (x(1)^2 + x(2)^2), 2e-8); %! assert (y(2), 0, 2e-8); -%!error planerot () -%!error planerot (1,2) +## Test input validation +%!error <Invalid call> planerot () %!error <X must be a 2-element vector> planerot (ones (2,2)) %!error <X must be a 2-element vector> planerot ([0 0 0]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/qzhess.m --- a/scripts/linear-algebra/qzhess.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/qzhess.m Thu Nov 19 13:08:00 2020 -0800 @@ -153,5 +153,6 @@ %! assert (q * b * z, bb, 2e-8); %! assert (bb .* mask, zeros (5), 2e-8); -%!error qzhess ([0]) -%!error qzhess () +## Test input validation +%!error <Invalid call> qzhess () +%!error <Invalid call> qzhess (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/rank.m --- a/scripts/linear-algebra/rank.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/rank.m Thu Nov 19 13:08:00 2020 -0800 @@ -81,6 +81,10 @@ function retval = rank (A, tol) + if (nargin < 1) + print_usage (); + endif + if (nargin == 1) sigma = svd (A); if (isempty (sigma)) @@ -92,11 +96,9 @@ tolerance = max (size (A)) * sigma (1) * eps; endif endif - elseif (nargin == 2) + else sigma = svd (A); tolerance = tol; - else - print_usage (); endif retval = sum (sigma > tolerance); diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/rref.m --- a/scripts/linear-algebra/rref.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/rref.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function [A, k] = rref (A, tol) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -111,7 +111,7 @@ %! a = [1 3; 4 5; 7 9]; %! [r k] = rref (a); %! assert (rank (a), rank (r), 2e-8); -%! assert (r, eye(3)(:,1:2), 2e-8); +%! assert (r, eye (3)(:,1:2), 2e-8); %! assert (k, [1 2], 2e-8); %!test @@ -130,4 +130,5 @@ %! [r k] = rref (a, tol); %! assert (rank (a, tol), rank (r, tol), 2e-8); -%!error rref () +## Test input validation +%!error <Invalid call> rref () diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/trace.m --- a/scripts/linear-algebra/trace.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/trace.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function y = trace (A) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -58,6 +58,5 @@ %!assert (trace (rand (1,0)), 0) %!assert (trace ([3:10]), 3) -%!error trace () -%!error trace (1, 2) +%!error <Invalid call> trace () %!error <only valid on 2-D objects> trace (reshape (1:9,[1,3,3])) diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/vech.m --- a/scripts/linear-algebra/vech.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/vech.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function v = vech (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -58,5 +58,4 @@ %!assert (vech ([1, 2, 3; 4, 5, 6; 7, 8, 9]), [1; 4; 7; 5; 8; 9]) -%!error vech () -%!error vech (1, 2) +%!error <Invalid call> vech () diff -r dc3ee9616267 -r fa2cdef14442 scripts/linear-algebra/vecnorm.m --- a/scripts/linear-algebra/vecnorm.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/linear-algebra/vecnorm.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,7 @@ function n = vecnorm (A, p = 2, dim) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -111,8 +111,7 @@ %! assert (vecnorm (A), ret, 1e-4); ## Test input validation -%!error vecnorm () -%!error vecnorm (1,2,3,4) +%!error <Invalid call> vecnorm () %!error <P must be positive real scalar> vecnorm (1, [1 2]) %!error <P must be positive real scalar> vecnorm (1, i) %!error <P must be positive real scalar> vecnorm (1, -1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/bunzip2.m --- a/scripts/miscellaneous/bunzip2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/bunzip2.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ function filelist = bunzip2 (bzfile, dir = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/cast.m --- a/scripts/miscellaneous/cast.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/cast.m Thu Nov 19 13:08:00 2020 -0800 @@ -108,8 +108,7 @@ %!assert (cast ([-2.5 1.1 2.5], "uint64"), uint64 ([0 1 3])) ## Test input validation -%!error cast () -%!error cast (1) -%!error cast (1,2,3) +%!error <Invalid call> cast () +%!error <Invalid call> cast (1) %!error <TYPE 'foobar' is not a built-in type> cast (1, "foobar") %!error <TYPE must be a string> cast (1, {"foobar"}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/citation.m --- a/scripts/miscellaneous/citation.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/citation.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,16 +47,13 @@ function citation (package = "octave") - if (nargin > 1) - print_usage (); - else - display_info_file ("citation", package, "CITATION"); - endif + ## function takes care of validating PACKAGE input + display_info_file ("citation", package, "CITATION"); endfunction ## Test input validation -%!error citation (1, 2) %!error <citation: PACKAGE must be a string> citation (1) -%!error <citation: package .* is not installed> citation ("__NOT_A_VALID_PKG_NAME__") +%!error <citation: package .* is not installed> +%! citation ("__NOT_A_VALID_PKG_NAME__"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/compare_versions.m --- a/scripts/miscellaneous/compare_versions.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/compare_versions.m Thu Nov 19 13:08:00 2020 -0800 @@ -223,10 +223,9 @@ %!assert (compare_versions ("0.1", "0.1", "~="), false) ## Test input validation -%!error compare_versions () -%!error compare_versions (1) -%!error compare_versions (1,2) -%!error compare_versions (1,2,3,4) +%!error <Invalid call> compare_versions () +%!error <Invalid call> compare_versions (1) +%!error <Invalid call> compare_versions (1,2) %!error <V1 and V2 must be strings> compare_versions (0.1, "0.1", "==") %!error <V1 and V2 must be strings> compare_versions ("0.1", 0.1, "==") %!error <V1 and V2 must be a single row> compare_versions (["0";".";"1"], "0.1", "==") diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/computer.m --- a/scripts/miscellaneous/computer.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/computer.m Thu Nov 19 13:08:00 2020 -0800 @@ -25,9 +25,9 @@ ## -*- texinfo -*- ## @deftypefn {} {} computer () -## @deftypefnx {} {@var{c} =} computer () -## @deftypefnx {} {[@var{c}, @var{maxsize}] =} computer () -## @deftypefnx {} {[@var{c}, @var{maxsize}, @var{endian}] =} computer () +## @deftypefnx {} {@var{comp} =} computer () +## @deftypefnx {} {[@var{comp}, @var{maxsize}] =} computer () +## @deftypefnx {} {[@var{comp}, @var{maxsize}, @var{endian}] =} computer () ## @deftypefnx {} {@var{arch} =} computer ("arch") ## Print or return a string of the form @var{cpu}-@var{vendor}-@var{os} that ## identifies the type of computer that Octave is running on. @@ -55,36 +55,57 @@ ## ## If the argument @qcode{"arch"} is specified, return a string indicating the ## architecture of the computer on which Octave is running. +## +## Results may be different if Octave was invoked with the --traditional +## option. ## @seealso{isunix, ismac, ispc} ## @end deftypefn -function [c, maxsize, endian] = computer (a) +function [comp, maxsize, endian] = computer (arch) - if (nargin > 1) - print_usage (); - elseif (nargin == 1 && ! strcmpi (a, "arch")) + if (nargin == 1 && ! strcmpi (arch, "arch")) error ('computer: "arch" is only valid argument'); endif + canonical_host_type = __octave_config_info__ ("canonical_host_type"); + traditional = __traditional__ (); + enable_64 = __octave_config_info__ ("ENABLE_64"); + host_parts = ostrsplit (canonical_host_type, "-"); + if (nargin == 0) - msg = __octave_config_info__ ("canonical_host_type"); - if (strcmp (msg, "unknown")) - msg = "Hi Dave, I'm a HAL-9000"; + host = ""; + if (traditional && enable_64) + if (ismac ()) + host = "MACI64"; + elseif (ispc ()) + host = "PCWIN64"; + elseif (strcmp ([host_parts{3} "-" host_parts{1}], "linux-x86_64")) + host = "GLNXA64"; + endif + endif + if (isempty (host)) + host = canonical_host_type; + elseif (strcmp (host, "unknown")) + host = "Hi Dave, I'm a HAL-9000"; endif if (nargout == 0) - disp (msg); + disp (host); else - c = msg; - if (isargout (2)) - if (__octave_config_info__ ("ENABLE_64")) - maxsize = 2^63-1; + comp = host; + if (nargout > 1) + if (enable_64) + if (traditional) + maxsize = 2^48-1; + else + maxsize = 2^63-1; + endif else maxsize = 2^31-1; endif endif - if (isargout (3)) + if (nargout > 2) if (__octave_config_info__ ("words_big_endian")) endian = "B"; elseif (__octave_config_info__ ("words_little_endian")) @@ -94,13 +115,25 @@ endif endif endif + else - ## "arch" argument asked for - tmp = ostrsplit (__octave_config_info__ ("canonical_host_type"), "-"); - if (numel (tmp) == 4) - c = sprintf ("%s-%s-%s", tmp{4}, tmp{3}, tmp{1}); - else - c = sprintf ("%s-%s", tmp{3}, tmp{1}); + + ## "arch" case. + comp = ""; + if (traditional && enable_64) + if (ismac ()) + comp = "maci64"; + elseif (ispc ()) + comp = "win64"; + elseif (strcmp ([host_parts{3} "-" host_parts{1}], "linux-x86_64")) + comp = "glnxa64"; + endif + endif + if (isempty (comp)) + comp = [host_parts{3} "-" host_parts{1}]; + if (numel (host_parts) == 4) + comp = [host_parts{4} "-" comp]; + endif endif endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/copyfile.m --- a/scripts/miscellaneous/copyfile.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/copyfile.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,12 +48,12 @@ function [status, msg, msgid] = copyfile (f1, f2, force) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif max_cmd_line = 1024; - status = true; + sts = 1; msg = ""; msgid = ""; @@ -87,13 +87,27 @@ ## If f1 has more than 1 element then f2 must be a directory isdir = isfolder (f2); if (numel (f1) > 1 && ! isdir) - error ("copyfile: when copying multiple files, F2 must be a directory"); + if (nargout == 0) + error ("copyfile: when copying multiple files, F2 must be a directory"); + else + status = 0; + msg = "when copying multiple files, F2 must be a directory"; + msgid = "copyfile"; + return; + endif endif ## Protect the filename(s). f1 = glob (f1); if (isempty (f1)) - error ("copyfile: no files to move"); + if (nargout == 0) + error ("copyfile: no files to move"); + else + status = 0; + msg = "no files to move"; + msgid = "copyfile"; + return; + endif endif p1 = sprintf ('"%s" ', f1{:}); p2 = tilde_expand (f2); @@ -118,7 +132,7 @@ ## Copy the files. [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); if (err != 0) - status = false; + sts = 0; msgid = "copyfile"; break; endif @@ -133,20 +147,28 @@ ## Copy the files. [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); if (err != 0) - status = false; + sts = 0; msgid = "copyfile"; endif endif + if (nargout == 0) + if (sts == 0) + error ("copyfile: operation failed: %s", msg); + endif + else + status = sts; + endif + endfunction %!test %! unwind_protect -%! f1 = tempname; +%! f1 = tempname (); %! tmp_var = pi; %! save (f1, "tmp_var"); -%! f2 = tempname; +%! f2 = tempname (); %! assert (copyfile (f1, f2)); %! assert (exist (f2, "file")); %! fid = fopen (f1, "rb"); @@ -166,9 +188,9 @@ %! end_unwind_protect ## Test input validation -%!error copyfile () -%!error copyfile (1) -%!error copyfile (1,2,3,4) +%!error <Invalid call> copyfile () +%!error <Invalid call> copyfile (1) %!error <F1 must be a string> copyfile (1, "foobar") %!error <F2 must be a string> copyfile ("foobar", 1) %!error <F2 must be a directory> copyfile ({"a", "b"}, "%_NOT_A_DIR_%") +%!error <no files to move> copyfile ("%_NOT_A_FILENAME1_%", "%_NOT_A_FILENAME2_%") diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/delete.m --- a/scripts/miscellaneous/delete.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/delete.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,13 +49,15 @@ for arg = varargin files = glob (arg{1}); if (isempty (files)) - warning ("delete: no such file: %s", arg{1}); + warning ("Octave:delete:no-such-file", ... + "delete: no such file: %s", arg{1}); endif for i = 1:length (files) file = files{i}; [err, msg] = unlink (file); if (err) - warning ("delete: %s: %s", file, msg); + warning ("Octave:delete:unlink-error", ... + "delete: %s: %s", file, msg); endif endfor endfor @@ -65,7 +67,8 @@ __go_delete__ (varargin{1}); else - error ("delete: first argument must be a filename or graphics handle"); + error ("Octave:delete:unsupported-object", ... + "delete: first argument must be a filename or graphics handle"); endif endfunction @@ -73,14 +76,14 @@ %!test %! unwind_protect -%! file = tempname; +%! file = tempname (); %! tmp_var = pi; %! save (file, "tmp_var"); %! assert (exist (file, "file")); %! delete (file); %! assert (! exist (file, "file")); %! unwind_protect_cleanup -%! unlink (file); +%! sts = unlink (file); %! end_unwind_protect %!test @@ -95,5 +98,5 @@ %! end_unwind_protect ## Test input validation -%!error delete () +%!error <Invalid call> delete () %!error <first argument must be a filename> delete (struct ()) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/dir.m --- a/scripts/miscellaneous/dir.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/dir.m Thu Nov 19 13:08:00 2020 -0800 @@ -75,13 +75,7 @@ ## FIXME: This is quite slow for large directories. ## Perhaps it should be converted to C++? -function retval = dir (directory) - - if (nargin == 0) - directory = "."; - elseif (nargin > 1) - print_usage (); - endif +function retval = dir (directory = ".") if (! ischar (directory)) error ("dir: DIRECTORY argument must be a string"); @@ -97,9 +91,11 @@ if (strcmp (directory, ".")) flst = {"."}; nf = 1; + dir_has_wildcard = false; else flst = __wglob__ (directory); nf = numel (flst); + dir_has_wildcard = any (directory == '*'); # See Bug #58976. endif ## Determine the file list for the case where a single directory is specified. @@ -109,7 +105,7 @@ if (err < 0) warning ("dir: 'stat (%s)' failed: %s", fn, msg); nf = 0; - elseif (S_ISDIR (st.mode)) + elseif (S_ISDIR (st.mode) && ! dir_has_wildcard) flst = readdir (flst{1}); nf = numel (flst); flst = strcat ([fn filesep], flst); @@ -224,7 +220,40 @@ %! chdir (orig_dir); %! confirm_recursive_rmdir (false, "local"); %! if (exist (tmp_dir)) -%! rmdir (tmp_dir, "s"); +%! sts = rmdir (tmp_dir, "s"); +%! endif +%! end_unwind_protect + +%!test <*58976> +%! orig_dir = pwd (); +%! tmp_dir = tempname (); +%! unwind_protect +%! assert (mkdir (tmp_dir)); +%! assert (mkdir (fullfile (tmp_dir, "dir1"))); +%! assert (mkdir (fullfile (tmp_dir, "dir2"))); +%! chdir (fullfile (tmp_dir, "dir1")); +%! fclose (fopen ("f1", "w")); +%! chdir (tmp_dir); +%! +%! ## Wildcard with multiple matches lists directories +%! list = dir (fullfile (tmp_dir, "dir*")); +%! assert (numel (list) == 2); +%! assert ({list.name}, {"dir1", "dir2"}); +%! +%! ## Wildcard with single match lists directories +%! assert (rmdir (fullfile (tmp_dir, "dir2"))); +%! list = dir (fullfile (tmp_dir, "dir*")); +%! assert (numel (list) == 1); +%! assert ({list.name}, {"dir1"}); +%! +%! ## No wildcard returns listing of directory contents +%! list = dir (fullfile (tmp_dir, "dir1")); +%! assert (any (strcmp ({list.name}, "f1"))); +%! unwind_protect_cleanup +%! chdir (orig_dir); +%! confirm_recursive_rmdir (false, "local"); +%! if (exist (tmp_dir)) +%! sts = rmdir (tmp_dir, "s"); %! endif %! end_unwind_protect @@ -238,7 +267,7 @@ %! assert (list(1).folder, canonicalize_file_name (tmp_dir)); %! unwind_protect_cleanup %! if (exist (tmp_dir)) -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! endif %! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/dos.m --- a/scripts/miscellaneous/dos.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/dos.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function [status, text] = dos (command, echo_arg) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -73,5 +73,6 @@ %! assert (output, ""); %! endif -%!error dos () +## Test input validation +%!error <Invalid call> dos () %!error dos (1, 2, 3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/edit.m --- a/scripts/miscellaneous/edit.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/edit.m Thu Nov 19 13:08:00 2020 -0800 @@ -109,7 +109,7 @@ ## (editor is started in the background and Octave continues) or sync mode ## (Octave waits until the editor exits). Set it to @qcode{"sync"} to start ## the editor in sync mode. The default is @qcode{"async"} -## (@pxref{XREFsystem,,system}). +## (@pxref{XREFsystem,,@code{system}}). ## ## @item editinplace ## Determines whether files should be edited in place, without regard to @@ -143,7 +143,7 @@ "MODE", "async", "EDITINPLACE", true); ## Make sure the stateval variables survive "clear functions". - mlock; + mlock (); ## Get default editor every time in case the user has changed it FUNCTION.EDITOR = [EDITOR() " %s"]; @@ -219,7 +219,7 @@ if (iscellstr (varargin)) editfilelist = varargin; else - error ("edit: if supplying more than one input all inputs must be strings containing field names to open."); + error ("edit: if supplying more than one input all inputs must be strings containing field names to open"); endif endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/fieldnames.m --- a/scripts/miscellaneous/fieldnames.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/fieldnames.m Thu Nov 19 13:08:00 2020 -0800 @@ -28,30 +28,35 @@ ## @deftypefnx {} {@var{names} =} fieldnames (@var{obj}) ## @deftypefnx {} {@var{names} =} fieldnames (@var{javaobj}) ## @deftypefnx {} {@var{names} =} fieldnames ("@var{javaclassname}") -## Return a cell array of strings with the names of the fields in the -## specified input. +## Return a cell array of strings with the names of the fields in the specified +## input. ## -## When the input is a structure @var{struct}, the names are the elements of -## the structure. +## When the input is a structure @var{struct}, the @var{names} are the elements +## of the structure. ## -## When the input is an Octave object @var{obj}, the names are the public +## When the input is an Octave object @var{obj}, the @var{names} are the public ## properties of the object. ## ## When the input is a Java object @var{javaobj} or a string containing the -## name of a Java class @var{javaclassname}, the names are the public fields -## (data members) of the object or class. -## @seealso{numfields, isfield, orderfields, struct, methods} +## name of a Java class @var{javaclassname}, the @var{names} are the public +## fields (data members) of the object or class. +## @seealso{numfields, isfield, orderfields, struct, properties} ## @end deftypefn function names = fieldnames (obj) - if (nargin != 1) + if (nargin < 1) print_usage (); endif - if (isstruct (obj) || isobject (obj)) - ## Call internal C++ function for structs or Octave objects + if (isstruct (obj)) names = __fieldnames__ (obj); + elseif (isobject (obj)) + try + names = properties (obj); # classdef object + catch + names = __fieldnames__ (obj); # @class object + end_try_catch elseif (isjava (obj) || ischar (obj)) ## FIXME: Function prototype that accepts java obj exists, but doesn't ## work if obj is java.lang.String. Convert obj to classname. @@ -70,22 +75,34 @@ endfunction -## test preservation of fieldname order +## Test preservation of fieldname order %!test %! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; %! assert (fieldnames (x), {"d"; "a"; "b"; "c"}); -## test empty structure +## Test empty structure %!test %! s = struct (); %! assert (fieldnames (s), cell (0, 1)); -## test Java classname by passing classname +## Test classdef object +%!test +%! m = containers.Map (); +%! f = fieldnames (m); +%! assert (f, {"Count"; "KeyType"; "ValueType"; "map"; "numeric_keys"}); + +## Test old-style @class object +%!test +%! obj = ftp (); +%! f = fieldnames (obj); +%! assert (f, {"host"; "username"; "password"; "curlhandle"}); + +## Test Java classname by passing classname %!testif HAVE_JAVA; usejava ("jvm") %! names = fieldnames ("java.lang.Double"); %! assert (any (strcmp (names, "MAX_VALUE"))); -## test Java classname by passing java object +## Test Java classname by passing java object %!testif HAVE_JAVA; usejava ("jvm") %! names = fieldnames (javaObject ("java.lang.Double", 10)); %! assert (any (strcmp (names, "MAX_VALUE"))); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/fileattrib.m --- a/scripts/miscellaneous/fileattrib.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/fileattrib.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,13 +24,16 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {} fileattrib (@var{file}) -## @deftypefnx {} {} fileattrib () +## @deftypefn {} {} fileattrib () +## @deftypefnx {} {} fileattrib (@var{file}) +## @deftypefnx {} {[@var{status}, @var{attrib}] =} fileattrib (@dots{}) ## @deftypefnx {} {[@var{status}, @var{msg}, @var{msgid}] =} fileattrib (@dots{}) -## Return information about @var{file}. +## Report attribute information about @var{file}. ## -## If successful, @var{status} is 1 and @var{msg} is a structure with the -## following fields: +## If no file or directory is specified, report information about the present +## working directory. +## +## If successful, the output is a structure with the following fields: ## ## @table @code ## @item Name @@ -64,30 +67,29 @@ ## True if the user (group; other users) has execute permission for @var{file}. ## @end table ## -## If an attribute does not apply (i.e., archive on a Unix system) then the +## If an attribute does not apply (e.g., archive on a Unix system) then the ## field is set to NaN. ## -## If @code{attrib} fails, @var{msg} is a non-empty string containing an -## error message and @var{msg_id} is the non-empty string @qcode{"fileattrib"}. +## If @var{file} contains globbing characters, information about all matching +## files is returned in a structure array. ## -## With no input arguments, return information about the current directory. -## -## If @var{file} contains globbing characters, return information about all -## the matching files. -## @seealso{glob} +## If outputs are requested, the first is @var{status} which takes the value 1 +## when the operation was successful, and 0 otherwise. The second output +## contains the structure described above (@var{attrib}) if the operation was +## successful; otherwise, the second output is a system-dependent error message +## (@var{msg}). The third output is an empty string ("") when the operation +## was successful, or a unique message identifier (@var{msgid}) in the case of +## failure. +## @seealso{stat, glob} ## @end deftypefn function [status, msg, msgid] = fileattrib (file = ".") - if (nargin > 1) - print_usage (); - endif - if (! ischar (file)) error ("fileattrib: FILE must be a string"); endif - status = true; + sts = 1; msg = ""; msgid = ""; @@ -108,10 +110,9 @@ r(i).hidden = NaN; else [~, attrib] = dos (sprintf ('attrib "%s"', r(i).Name)); - ## dos never returns error status so have to check it indirectly + ## DOS never returns error status so have to check it indirectly if (! isempty (strfind (attrib, " -"))) - status = false; - msgid = "fileattrib"; + sts = 0; break; endif attrib = regexprep (attrib, '\S+:.*', ""); @@ -142,15 +143,23 @@ r(i).OtherExecute = NaN; endif else - status = false; - msgid = "fileattrib"; + sts = 0; break; endif endfor - if (status) - if (nargout == 0) - status = r; + if (nargout == 0) + if (! sts) + error ("fileattrib: operation failed"); + endif + status = r; + else + status = sts; + if (! sts) + if (isempty (msg)) + msg = "operation failed"; + endif + msgid = "fileattrib"; else msg = r; endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/fileparts.m --- a/scripts/miscellaneous/fileparts.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/fileparts.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function [dir, name, ext] = fileparts (filename) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -111,7 +111,6 @@ %! assert (strcmp (d, "") && strcmp (n, "") && strcmp (e, ".ext")); ## Test input validation -%!error fileparts () -%!error fileparts (1,2) +%!error <Invalid call> fileparts () %!error <FILENAME must be a single string> fileparts (1) %!error <FILENAME must be a single string> fileparts (["a"; "b"]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/fullfile.m --- a/scripts/miscellaneous/fullfile.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/fullfile.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,17 +24,18 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file}) -## @deftypefnx {} {@var{filenames} =} fullfile (@dots{}, @var{files}) +## @deftypefn {} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file}) ## Build complete filename from separate parts. ## -## Joins any number of path components intelligently. The return value is -## the concatenation of each component with exactly one file separator -## between each non empty part and at most one leading and/or trailing file +## The function joins any number of path components intelligently. The return +## value is the concatenation of each component with exactly one file separator +## between each part of the path and at most one leading and/or trailing file ## separator. ## -## If the last component part is a cell array, returns a cell array of -## filepaths, one for each element in the last component, e.g.: +## The input arguments might be strings or cell strings. Any input arguments +## that are cell strings must contain one single string or must be equal in +## size. In that case, the function returns a cell string of filepaths of the +## same dimensions as the input cell strings, e.g.: ## ## @example ## @group @@ -49,7 +50,7 @@ ## @end example ## ## On Windows systems, while forward slash file separators do work, they are -## replaced by backslashes; in addition drive letters are stripped of leading +## replaced by backslashes. In addition, drive letters are stripped of leading ## file separators to obtain a valid file path. ## ## Note: @code{fullfile} does not perform any validation of the resulting full @@ -59,19 +60,58 @@ function filename = fullfile (varargin) - if (nargin && iscell (varargin{end})) - filename = cellfun (@(x) fullfile (varargin{1:end-1}, x), varargin{end}, - "UniformOutput", false); - else - non_empty = cellfun ("isempty", varargin); - unc = 0; - if (ispc && ! isempty (varargin)) - varargin = strrep (varargin, '/', filesep); - unc = strncmp (varargin{1}, '\\', 2); - varargin(1) = regexprep (varargin{1}, '[\\/]*([a-zA-Z]:[\\/]*)', "$1"); - endif - filename = strjoin (varargin(! non_empty), filesep); - filename(unc + strfind (filename(1+unc : end), [filesep filesep])) = ""; + ## remove empty arguments + varargin(cellfun (@isempty, varargin)) = []; + + if (isempty (varargin)) + ## return early for all empty or no input + filename = ""; + return; + endif + + ## check input type + is_cellstr = cellfun (@iscellstr, varargin); + if (! all (is_cellstr | cellfun (@ischar, varargin))) + error ("fullfile: input must either be strings or cell strings"); + endif + + ## convert regular strings to cell strings + varargin(! is_cellstr) = num2cell (varargin(! is_cellstr)); + + ## check if input size matches + if (numel (varargin) > 1 && common_size (varargin{:}) != 0) + error ("fullfile: cell string input must be scalar or of the same size"); + endif + + fs = filesep (); + + if (ispc ()) + ## replace forward slashes with backslashes + varargin = cellfun (@(x) strrep (x, "/", fs), varargin, + "UniformOutput", false); + + ## Strip fileseps preceeding drive letters + varargin{1} = regexprep (varargin{1}, '\\*([a-zA-Z]:\\*)', "$1"); + + unc = strncmp (varargin{1}, '\\', 2); + endif + + ## insert file separator between elements + varargin(2,:) = {fs}; + varargin{end} = ""; + + filename = strcat (varargin{:}); + + ## remove multiplicate file separators + filename = regexprep (filename, [undo_string_escapes(fs), "*"], fs); + + if (ispc ()) + ## prepend removed file separator for UNC paths + filename(unc) = strcat (fs, filename(unc)); + endif + + if (! any (is_cellstr)) + filename = filename{1}; endif endfunction @@ -79,13 +119,14 @@ %!shared fs, fsx, xfs, fsxfs, xfsy, xfsyfs %! fs = filesep (); -%! fsx = [fs "x"]; -%! xfs = ["x" fs]; -%! fsxfs = [fs "x" fs]; -%! xfsy = ["x" fs "y"]; -%! xfsyfs = ["x" fs "y" fs]; +%! fsx = [fs, "x"]; +%! xfs = ["x", fs]; +%! fsxfs = [fs, "x", fs]; +%! xfsy = ["x", fs, "y"]; +%! xfsyfs = ["x", fs, "y", fs]; %!assert (fullfile (""), "") +%!assert (fullfile ("", ""), "") %!assert (fullfile (fs), fs) %!assert (fullfile ("", fs), fs) %!assert (fullfile (fs, ""), fs) @@ -105,32 +146,39 @@ %!assert (fullfile (fs, "x", fs), fsxfs) %!assert (fullfile ("x/", "/", "/", "y", "/", "/"), xfsyfs) -%!assert (fullfile ("/", "x/", "/", "/", "y", "/", "/"), [fs xfsyfs]) -%!assert (fullfile ("/x/", "/", "/", "y", "/", "/"), [fs xfsyfs]) +%!assert (fullfile ("/", "x/", "/", "/", "y", "/", "/"), [fs, xfsyfs]) +%!assert (fullfile ("/x/", "/", "/", "y", "/", "/"), [fs, xfsyfs]) ## different on purpose so that "fullfile (c{:})" works for empty c %!assert (fullfile (), "") -%!assert (fullfile ("x", "y", {"c", "d"}), {[xfsyfs "c"], [xfsyfs "d"]}) +%!assert (fullfile ("x", "y", {"c", "d"}), {[xfsyfs, "c"], [xfsyfs, "d"]}) +%!assert (fullfile ({"folder1", "folder2"}, "sub", {"f1.m", "f2.m"}), ... +%! {["folder1", fs, "sub", fs, "f1.m"], ... +%! ["folder2", fs, "sub", fs, "f2.m"]}); ## Windows specific - drive letters and file sep type -%!test -%! if (ispc) -%! assert (fullfile ('\/\/\//A:/\/\', "x/", "/", "/", "y", "/", "/"), ... -%! ['A:\' xfsyfs]); -%! endif +%!testif ; ispc () +%! assert (fullfile ('\/\/\//A:/\/\', "x/", "/", "/", "y", "/", "/"), ... +%! ['A:\' xfsyfs]); ## *nix specific - double backslash -%!test -%! if (isunix || ismac) -%! assert (fullfile (fs, fs), fs); -%! endif +%!testif ; ! ispc () +%! assert (fullfile (fs, fs), fs); + +## Windows specific - UNC path +%!testif ; ispc () +%! assert (fullfile ({'\/\//server1', 'C:', '\\server2\/'}, ... +%! "x/", "/", "/", "y", "/", "/"), ... +%! {['\\server1\', xfsyfs], ['C:\', xfsyfs], ['\\server2\', xfsyfs]}); ## Windows specific - drive letters and file sep type, cell array -%!test -%! if (ispc) -%! tmp = fullfile ({"\\\/B:\//", "A://c", "\\\C:/g/h/i/j\/"}); -%! assert (tmp{1}, 'B:\'); -%! assert (tmp{2}, 'A:\c'); -%! assert (tmp{3}, 'C:\g\h\i\j\'); -%! endif +%!testif ; ispc () +%! tmp = fullfile ({'\\\/B:\//', 'A://c', '\\\C:/g/h/i/j\/'}); +%! assert (tmp{1}, 'B:\'); +%! assert (tmp{2}, 'A:\c'); +%! assert (tmp{3}, 'C:\g\h\i\j\'); + +%!error <strings or cell strings> fullfile (1) +%!error <strings or cell strings> fullfile ({1}) +%!error <same size> fullfile ({"a", "b"}, {"a", "b", "c"}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/getfield.m --- a/scripts/miscellaneous/getfield.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/getfield.m Thu Nov 19 13:08:00 2020 -0800 @@ -32,8 +32,8 @@ ## If @var{s} is a structure array then @var{sidx} selects an element of the ## structure array, @var{field} specifies the field name of the selected ## element, and @var{fidx} selects which element of the field (in the case of -## an array or cell array). See @code{setfield} for a more complete -## description of the syntax. +## an array or cell array). For a more complete description of the syntax, +## @pxref{XREFsetfield,,@code{setfield}}. ## ## @seealso{setfield, rmfield, orderfields, isfield, fieldnames, isstruct, struct} ## @end deftypefn @@ -65,6 +65,6 @@ %! assert (getfield (ss,{1,2},"fd",{3},"b", {1,4}), 5); ## Test input validation -%!error getfield () -%!error getfield (1) +%!error <Invalid call> getfield () +%!error <Invalid call> getfield (1) %!error <invalid index> getfield (1,2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/grabcode.m --- a/scripts/miscellaneous/grabcode.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/grabcode.m Thu Nov 19 13:08:00 2020 -0800 @@ -59,7 +59,7 @@ function code_str = grabcode (url) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -100,5 +100,4 @@ ## Test input validation -%!error grabcode () -%!error grabcode (1,2) +%!error <Invalid call> grabcode () diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/gunzip.m --- a/scripts/miscellaneous/gunzip.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/gunzip.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function filelist = gunzip (gzfile, dir = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/inputParser.m --- a/scripts/miscellaneous/inputParser.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/inputParser.m Thu Nov 19 13:08:00 2020 -0800 @@ -190,10 +190,11 @@ properties (Access = protected, Constant = true) ## Default validator, always returns scalar true. - def_val = @() true; + def_val = @(~) true; endproperties methods + function set.PartialMatching (this, val) if (val) error ("inputParser: PartialMatching is not yet implemented"); @@ -225,7 +226,7 @@ ## ## @end deftypefn - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); elseif (numel (this.Optional) || numfields (this.Parameter) || numfields (this.Switch)) @@ -264,7 +265,7 @@ ## ## @end deftypefn - if (nargin < 3 || nargin > 4) + if (nargin < 3) print_usage (); elseif (numfields (this.Parameter) || numfields (this.Switch)) error (["inputParser.Optional: can't have Optional arguments " ... @@ -287,7 +288,7 @@ ## ## @end deftypefn - if (nargin < 3 || nargin > 4) + if (nargin < 3) print_usage (); endif this.addParameter (name, def, val); @@ -420,7 +421,7 @@ ## keys. See bug #50752. idx -= 1; vidx -= 1; - break + break; endif try valid_option = opt.val (in); @@ -437,11 +438,11 @@ && isscalar (in))) idx -= 1; vidx -= 1; - break + break; else this.error (sprintf (["failed validation of %s\n", ... "Validation function: %s"], - toupper (opt.name), disp(opt.val))); + toupper (opt.name), disp (opt.val))); endif endif this.Results.(opt.name) = in; @@ -514,9 +515,11 @@ printf ("Defined parameters:\n\n {%s}\n", strjoin (this.Parameters, ", ")); endfunction + endmethods methods (Access = private) + function validate_name (this, type, name) if (! isvarname (name)) error ("inputParser.add%s: NAME is an invalid identifier", method); @@ -572,10 +575,12 @@ endif error ("%s%s", where, msg); endfunction + endmethods endclassdef + %!function p = create_p () %! p = inputParser (); %! p.CaseSensitive = true; @@ -650,7 +655,7 @@ ## check alternative method (obj, ...) API %!function p2 = create_p2 (); -%! p2 = inputParser; +%! p2 = inputParser (); %! addRequired (p2, "req1", @(x) ischar (x)); %! addOptional (p2, "op1", "val", @(x) any (strcmp (x, {"val", "foo"}))); %! addOptional (p2, "op2", 78, @(x) x > 50); @@ -677,13 +682,13 @@ ## We must not perform validation of default values %!test <*45837> -%! p = inputParser; +%! p = inputParser (); %! p.addParameter ("Dir", [], @ischar); %! p.parse (); %! assert (p.Results.Dir, []); %!test -%! p = inputParser; +%! p = inputParser (); %! p.addParameter ("positive", -1, @(x) x > 5); %! p.parse (); %! assert (p.Results.positive, -1); @@ -695,13 +700,12 @@ %! p.addOptional ("err", "foo", @error); %! p.addParameter ("not_err", "bar", @ischar); %! p.parse ("not_err", "qux"); -%! assert (p.Results.err, "foo") -%! assert (p.Results.not_err, "qux") - +%! assert (p.Results.err, "foo"); +%! assert (p.Results.not_err, "qux"); ## With more Parameters to test StructExpand %!function p3 = create_p3 (); -%! p3 = inputParser; +%! p3 = inputParser (); %! addOptional (p3, "op1", "val", @(x) any (strcmp (x, {"val", "foo"}))); %! addOptional (p3, "op2", 78, @(x) x > 50); %! addSwitch (p3, "verbose"); @@ -721,43 +725,43 @@ %!test %! p3 = create_p3 (); %! p3.parse (struct ("line", "circle", "color", "green"), "line", "tree"); -%! assert (p3.Results.line, "tree") +%! assert (p3.Results.line, "tree"); %! p3.parse ("line", "tree", struct ("line", "circle", "color", "green")); -%! assert (p3.Results.line, "circle") +%! assert (p3.Results.line, "circle"); %!test # unmatched parameters with StructExpand %! p3 = create_p3 (); %! p3.KeepUnmatched = true; %! p3.parse (struct ("line", "circle", "color", "green", "bar", "baz")); -%! assert (p3.Unmatched.bar, "baz") +%! assert (p3.Unmatched.bar, "baz"); ## The validation for the second optional argument throws an error with ## a struct so check that we can handle it. %!test %! p3 = create_p3 (); %! p3.parse ("foo", struct ("color", "green"), "line", "tree"); -%! assert (p3.Results.op1, "foo") -%! assert (p3.Results.line, "tree") -%! assert (p3.Results.color, "green") -%! assert (p3.Results.verbose, false) +%! assert (p3.Results.op1, "foo"); +%! assert (p3.Results.line, "tree"); +%! assert (p3.Results.color, "green"); +%! assert (p3.Results.verbose, false); ## Some simple tests for addParamValue since all the other ones use add ## addParameter but they use the same codepath. %!test -%! p = inputParser; +%! p = inputParser (); %! addParameter (p, "line", "tree", @(x) any (strcmp (x, {"tree", "circle"}))); %! addParameter (p, "color", "red", @(x) any (strcmp (x, {"red", "green"}))); %! p.parse ("line", "circle"); -%! assert ({p.Results.line, p.Results.color}, {"circle", "red"}) +%! assert ({p.Results.line, p.Results.color}, {"circle", "red"}); %!test -%! p = inputParser; +%! p = inputParser (); %! p.addParameter ("foo", "bar", @ischar); %! p.parse (); -%! assert (p.Results, struct ("foo", "bar")) +%! assert (p.Results, struct ("foo", "bar")); %! p.parse ("foo", "qux"); -%! assert (p.Results, struct ("foo", "qux")) +%! assert (p.Results, struct ("foo", "qux")); ## This behaviour means that a positional option can never be a string ## that is the name of a parameter key. This is required for Matlab @@ -767,16 +771,16 @@ %! p.addOptional ("op1", "val"); %! p.addParameter ("line", "tree"); %! p.parse ("line", "circle"); -%! assert (p.Results, struct ("op1", "val", "line", "circle")) +%! assert (p.Results, struct ("op1", "val", "line", "circle")); %! %! p = inputParser (); %! p.addOptional ("op1", "val1"); %! p.addOptional ("op2", "val2"); %! p.addParameter ("line", "tree"); %! p.parse ("line", "circle"); -%! assert (p.Results.op1, "val1") -%! assert (p.Results.op2, "val2") -%! assert (p.Results.line, "circle") +%! assert (p.Results.op1, "val1"); +%! assert (p.Results.op2, "val2"); +%! assert (p.Results.line, "circle"); %! %! ## If there's enough arguments to fill the positional options and %! ## param/key, it still skips positional options. @@ -809,18 +813,18 @@ %! p.addOptional ("op1", "val1"); %! p.addParameter ("line", "circle"); %! p.parse ("line"); -%! assert (p.Results, struct ("op1", "line", "line", "circle")) +%! assert (p.Results, struct ("op1", "line", "line", "circle")); %!test <*50752> -%! p = inputParser; +%! p = inputParser (); %! p.addOptional ("op1", "val1"); %! p.addSwitch ("line"); %! p.parse ("line"); -%! assert (p.Results.op1, "val1") -%! assert (p.Results.line, true) +%! assert (p.Results.op1, "val1"); +%! assert (p.Results.line, true); %!test -%! p = inputParser; +%! p = inputParser (); %! p.addParameter ("a", []); %! p.addParameter ("b", []); %! p.parse ("a", 1); @@ -829,7 +833,7 @@ %! assert (p.UsingDefaults, {"a"}); %!test -%! p = inputParser; +%! p = inputParser (); %! p.addParameter ("b", []); %! p.KeepUnmatched = true; %! p.parse ("a", 1); @@ -838,8 +842,8 @@ %! assert (p.Unmatched, struct ()); ## Test for patch #9241 -%!error<failed validation of A with ischar> -%! p = inputParser; +%!error <failed validation of A with ischar> +%! p = inputParser (); %! p.addParameter ("a", [], @ischar); %! p.parse ("a", 1); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/inputname.m --- a/scripts/miscellaneous/inputname.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/inputname.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,76 +31,133 @@ ## @deftypefnx {} {} inputname (@var{n}, @var{ids_only}) ## Return the name of the @var{n}-th argument to the calling function. ## -## If the argument is not a simple variable name, return an empty string. As -## an example, a reference to a field in a structure such as @code{s.field} is -## not a simple name and will return @qcode{""}. +## If the argument is not a simple variable name, return an empty string. +## Examples which will return @qcode{""} are numbers (@code{5.1}), +## expressions (@code{@var{y}/2}), and cell or structure indexing +## (@code{@var{c}@{1@}} or @code{@var{s}.@var{field}}). ## ## @code{inputname} is only useful within a function. When used at the command -## line it always returns an empty string. +## line or within a script it always returns an empty string. +## +## By default, return an empty string if the @var{n}-th argument is not a valid +## variable name. If the optional argument @var{ids_only} is false, return the +## text of the argument even if it is not a valid variable name. This is an +## Octave extension that allows the programmer to view exactly how the function +## was invoked even when the inputs are complex expressions. +## @seealso{nargin, narginchk} +## @end deftypefn + +## FIXME: Actually, it probably *isn't* worth fixing, but there are small +## differences between Octave and Matlab. +## +## 1) When called from the top-level or a script, Matlab throws an error +## +## inputname (1) % at command prompt +## % Octave returns "", Matlab throws an error ## -## By default, return an empty string if the @var{n}-th argument is not -## a valid variable name. If the optional argument @var{ids_only} is -## false, return the text of the argument even if it is not a valid -## variable name. -## @seealso{nargin, nthargout} -## @end deftypefn +## 2) cell or struct indexing causes all further names to be returned as "" +## +## c = {'a', 'b'} +## y = 1; z = 2; +## func (c, y, z) +## % inputname() would return 'c', 'y', 'z' for the inputs. +## func (c{1}, y, z) +## % inputname() would return '', '', '' for the inputs. +## +## 3) If inputname is not called from a function, Matlab walks up the stack +## until it finds some valid code and then works from there. This could +## be relevant for mex files or anonymous functions. +## +## f = @(x) inputname (x); +## a = 1:4; +## arrayfun (fn, a, 'uniformoutput', false) +## % output is {'fn', 'a', '', ''} function name = inputname (n, ids_only = true) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif - name = ""; + if (! isscalar (n) || ! isindex (n)) + error ("inputname: N must be a scalar index"); + endif + try - name = evalin ("caller", sprintf ("__varval__ ('.argn.'){%d}", fix (n))); + name = evalin ("caller", sprintf ("__varval__ ('.argn.'){%d}", n)); catch + name = ""; return; end_try_catch - ## For compatibility with Matlab, - ## return empty string if argument name is not a valid identifier. + ## For compatibility with Matlab, return empty string if argument name is + ## not a valid identifier. if (ids_only && ! isvarname (name)) name = ""; + elseif (ids_only) + ## More complicated checking is required to verify name (bug #59103). + ## NAME may be text, like "Inf", which is an acceptable variable name + ## that passes isvarname(), but that does not mean it is an actual + ## variable name, rather than a function or IEEE number. + try + v = evalin ("caller", + sprintf ("evalin ('caller', '__varval__ (\"%s\")')", name)); + catch + name = ""; + end_try_catch endif endfunction -## Warning: heap big magic in the following tests!!! -## The test function builds a private context for each test, with only the -## specified values shared between them. It does this using the following -## template: -## -## function [<shared>] = testfn (<shared>) -## <test> -## endfunction -## -## To test inputname, I need a function context invoked with known parameter -## names. So define a couple of shared parameters, et voila!, the test is -## trivial. +%!function name = __iname1__ (arg1, arg2, arg3) +%! name = inputname (1); +%!endfunction + +%!function name = __iname1_ID__ (arg1, arg2, arg3) +%! name = inputname (1, false); +%!endfunction + +%!function name = __iname2__ (arg1, arg2, arg3) +%! name = inputname (2); +%!endfunction -%!shared hello, worldly -%!assert (inputname (1), "hello") -%!assert (inputname (2), "worldly") -%!assert (inputname (3), "") +%!function names = __iname3__ (arg1, arg2, arg3) +%! names = cell (1, 3); +%! for i = 1:3 +%! names{i} = inputname (i); +%! endfor +%!endfunction + +%!test +%! assert (__iname1__ ('xvar'), ""); +%! xvar = 1; +%! assert (__iname1__ (xvar), "xvar"); -## Clear parameter list so that testfn is created with zero inputs/outputs -%!shared -%!assert (inputname (-1), "") -%!assert (inputname (1), "") +%!test +%! xvar = 1; yvar = 2; +%! assert (__iname2__ (xvar), ""); +%! assert (__iname2__ (xvar, yvar), "yvar"); + +%!test +%! xvar = 1; yvar = 2; +%! assert (__iname3__ (xvar), {"xvar", "", ""}); +%! assert (__iname3__ (xvar, yvar), {"xvar", "yvar", ""}); +%! assert (__iname3__ (xvar, 3, yvar), {"xvar", "", "yvar"}); -%!function r = __foo1__ (x, y) -%! r = inputname (2); -%!endfunction -%!assert (__foo1__ (pi, e), "e") -%!assert (feval (@__foo1__, pi, e), "e") +## Test numbers, expressions, indexing operations +%!test +%! assert (__iname1__ (1.0), ""); +%! x = 1; +%! assert (__iname1__ (x / 2), ""); +%! assert (__iname1__ (Inf), ""); -%!function r = __foo2__ (x, y) -%! r = inputname (2, false); -%!endfunction -%!assert (__foo2__ (pi+1, 2+2), "2 + 2") -%!assert (feval (@__foo2__, pi, pi/2), "pi / 2") +%!test +%! assert (__iname1_ID__ (1.0), "1.0"); +%! x = 1; +%! assert (__iname1_ID__ (x / 2), "x / 2"); +%! assert (__iname1_ID__ (Inf), "Inf"); -%!error inputname () -%!error inputname (1,2,3) +%!error <Invalid call> inputname () +%!error <N must be a scalar> inputname (ones (2,2)) +%!error <N must be a scalar index> inputname (-1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/isfile.m --- a/scripts/miscellaneous/isfile.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/isfile.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function retval = isfile (f) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -75,6 +75,6 @@ %! end_unwind_protect ## Test input validation -%!error isfile () +%!error <Invalid call> isfile () %!error isfile ("a", "b") %!error <F must be a string> isfile (1.0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/isfolder.m --- a/scripts/miscellaneous/isfolder.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/isfolder.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ function retval = isfolder (f) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -70,11 +70,11 @@ %! addpath (d); %! assert (! isfolder (n)); %! unwind_protect_cleanup -%! try, rmdir (tmp); end_try_catch -%! try, rmpath (d); end_try_catch +%! sts = rmdir (tmp); +%! rmpath (d); %! end_unwind_protect ## Test input validation -%!error isfolder () +%!error <Invalid call> isfolder () %!error isfolder ("a", "b") %!error <F must be a string> isfolder (1.0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/ismac.m --- a/scripts/miscellaneous/ismac.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/ismac.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,15 +31,9 @@ function retval = ismac () - if (nargin == 0) - retval = __octave_config_info__ ("mac"); - else - print_usage (); - endif + retval = __octave_config_info__ ("mac"); endfunction %!assert (islogical (ismac ())) - -%!error ismac (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/ismethod.m --- a/scripts/miscellaneous/ismethod.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/ismethod.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ endif if (! ischar (method)) - error ("ismethod: second argument must be a method name"); + error ("ismethod: METHOD must be a string"); endif method_list = methods (obj); @@ -51,6 +51,7 @@ endfunction + %!testif HAVE_JAVA; usejava ("jvm") %! assert (ismethod (javaObject ("java.lang.String", "Yo"), "hashCode")); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/ispc.m --- a/scripts/miscellaneous/ispc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/ispc.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,15 +31,9 @@ function retval = ispc () - if (nargin == 0) - retval = __octave_config_info__ ("windows"); - else - print_usage (); - endif + retval = __octave_config_info__ ("windows"); endfunction %!assert (islogical (ispc ())) - -%!error ispc (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/isunix.m --- a/scripts/miscellaneous/isunix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/isunix.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,15 +31,9 @@ function retval = isunix () - if (nargin == 0) - retval = __octave_config_info__ ("unix"); - else - print_usage (); - endif + retval = __octave_config_info__ ("unix"); endfunction %!assert (islogical (isunix ())) - -%!error isunix (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/license.m --- a/scripts/miscellaneous/license.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/license.m Thu Nov 19 13:08:00 2020 -0800 @@ -68,12 +68,8 @@ function [retval, errmsg] = license (cmd, feature, toggle) - if (nargin > 3) - print_usage (); - endif - - ## Then only give information about Octave core if (nargin == 0) + ## then only give information about Octave core retval = "GNU General Public License"; return; endif @@ -82,10 +78,6 @@ switch (tolower (cmd)) case "inuse" - if (nargin > 2) - print_usage (); - endif - features = features(loaded); if (nargin > 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/list_primes.m --- a/scripts/miscellaneous/list_primes.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/list_primes.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,9 +34,7 @@ function retval = list_primes (n = 25) - if (nargin > 1) - print_usage (); - elseif (! isreal (n) || ! isscalar (n)) + if (! isreal (n) || ! isscalar (n)) error ("list_primes: N must be a real scalar"); endif @@ -69,6 +67,5 @@ %!assert (list_primes (1), [2]) ## Test input validation -%!error list_primes (1, 2) %!error <N must be a real scalar> list_primes (i) %!error <N must be a real scalar> list_primes ([1 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/memory.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/memory.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,273 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {} memory () +## @deftypefnx {} {[@var{userdata}, @var{systemdata}] =} memory () +## Display or return information about the memory usage of Octave. +## +## If the function is called without output arguments, a table with an overview +## of the current memory consumption is displayed. +## +## The output argument @var{userdata} is a structure with the following fields +## containing data for the Octave process: +## +## @table @code +## @item @var{MaxPossibleArrayBytes} +## Maximum size for an array to be allocated. Be aware that this includes +## @emph{all} physical memory and swap space. Allocating that amount of memory +## might result in system instability, data corruption, and/or file system +## corruption. Note that depending on the platform (32-bit systems), the +## largest contiguous memory block might further limit the maximum possible +## allocatable array. This check is not currently implemented. +## +## @item @var{MemAvailableAllArrays} +## The total size of available memory in bytes. +## +## @item @var{ram_available_all_arrays} +## The maximum size for an array that can be allocated in physical memory +## (excluding swap space). Note that depending on the platform (32-bit +## systems), the largest contiguous memory block might further limit the +## maximum possible allocatable array. This check is not currently +## implemented. +## +## @item @var{MemUsedMATLAB} +## @itemx @var{mem_used_octave} +## The memory (including swap space) currently used by Octave in bytes. +## +## @item @var{ram_used_octave} +## The physical memory (excluding swap space) currently used by Octave in +## bytes. +## +## @end table +## +## The output argument @var{systemdata} is a nested structure with the +## following fields containing information about the system's memory: +## +## @table @code +## @item @var{PhysicalMemory.Available} +## The currently available physical memory in bytes. +## +## @item @var{PhysicalMemory.Total} +## The total physical memory in bytes. +## +## @item @var{SystemMemory.Available} +## The currently available memory (including swap space) in bytes. +## +## @item @var{SystemMemory.Total} +## The total memory (including swap space) in bytes. +## +## @item @var{VirtualAddressSpace.Available} +## The currently available virtual address space in bytes. +## +## @item @var{VirtualAddressSpace.Total} +## The total virtual address space in bytes. +## +## @end table +## +## @example +## @group +## memory () +## @result{} System RAM: 3934008 KiB, swap: 4087804 KiB +## Octave RAM: 170596 KiB, virt: 1347944 KiB +## Free RAM: 1954940 KiB, swap: 4087804 KiB +## Available RAM: 2451948 KiB, total: 6042744 KiB +## @end group +## +## @group +## [userdata, systemdata] = memory () +## @result{} userdata = +## scalar structure containing the fields: +## MaxPossibleArrayBytes = 6.1622e+09 +## MemAvailableAllArrays = 6.1622e+09 +## ram_available_all_arrays = 2.4883e+09 +## MemUsedMATLAB = 1.3825e+09 +## mem_used_octave = 1.3825e+09 +## ram_used_octave = 1.7824e+08 +## +## systemdata = +## scalar structure containing the fields: +## PhysicalMemory = +## scalar structure containing the fields: +## Available = 2.4954e+09 +## Total = 4.0284e+09 +## SystemMemory = +## scalar structure containing the fields: +## Available = 6.6813e+09 +## Total = 8.2143e+09 +## VirtualAddressSpace = +## scalar structure containing the fields: +## Available = 2.8147e+14 +## Total = 2.8147e+14 +## @end group +## @end example +## +## This function is implemented for Linux and Windows only. +## +## @seealso{computer, getpid, getrusage, nproc, uname} +## @end deftypefn + +function [userdata, systemdata] = memory () + + if (! isunix () && ! ispc ()) + if (nargout > 0) + error ("memory: function not yet implemented for this architecture"); + else + warning ("memory: function not yet implemented for this architecture"); + endif + return; + endif + + kiB = 1024; + [architecture, bits] = computer (); + + if (isunix ()) + ## Read values from pseudofiles + [status, meminfo] = lmemory (); + + ## FIXME: Query the actual size of the user address space, + ## e.g., with getrlimit (RLIMIT_AS, rlp) + if (log2 (bits) > 32) + ## 64-bit platform + address_space = 2^48; # 256 TiB + else + ## 32-bit platform + address_space = 3 * 2^30; # 3 GiB + endif + + total_ram = meminfo.MemTotal * kiB; + total_swap = meminfo.SwapTotal * kiB; + free_ram = meminfo.MemFree * kiB; + if (isfield (meminfo, "MemAvailable")) + available_ram = meminfo.MemAvailable * kiB; + else + ## On kernels from before 2014 MemAvailable is not present. + ## This is a rough estimate that can be used instead. + available_ram = (meminfo.MemFree + meminfo.Cached) * kiB; + endif + free_swap = meminfo.SwapFree * kiB; + used_ram = status.VmRSS * kiB; + used_virtual = status.VmSize * kiB; + avail_virtual = address_space - used_virtual; + + elseif (ispc ()) + [proc, sys] = __wmemory__ (); + + total_ram = sys.TotalPhys; + total_swap = sys.TotalPageFile; + available_ram = sys.AvailPhys; + free_swap = sys.AvailPageFile; + used_ram = proc.WorkingSetSize; + used_virtual = proc.WorkingSetSize + proc.PagefileUsage; + avail_virtual = sys.AvailVirtual; + address_space = sys.TotalVirtual; + + endif + + available = min (available_ram + free_swap, avail_virtual); + ram_available = min (available_ram, avail_virtual); + + ## FIXME: On 32-bit systems, the largest possible array is limited by the + ## largest contiguous block in memory. + user.MaxPossibleArrayBytes = available; + user.MemAvailableAllArrays = available; + user.ram_available_all_arrays = ram_available; + user.MemUsedMATLAB = used_virtual; # For compatibility + user.mem_used_octave = used_virtual; + user.ram_used_octave = used_ram; + + syst.PhysicalMemory.Available = available_ram; + syst.PhysicalMemory.Total = total_ram; + syst.SystemMemory.Available = available_ram + free_swap; + syst.SystemMemory.Total = total_ram + total_swap; + syst.VirtualAddressSpace.Available = avail_virtual; + syst.VirtualAddressSpace.Total = address_space; + + if (nargout) + userdata = user; + systemdata = syst; + else + unitsize = kiB; + unitname = 'kiB'; + disp (sprintf ("Octave is running on %s", architecture)) + disp (sprintf ("System RAM: %9.0f %s, swap: %9.0f %s", + round (syst.PhysicalMemory.Total / unitsize), unitname, + round (total_swap / unitsize), unitname )) + disp (sprintf ("Octave RAM: %9.0f %s, virt: %9.0f %s", + round (user.ram_used_octave / unitsize), unitname, + round (user.mem_used_octave / unitsize), unitname)) + if (isunix ()) + ## The concept of free vs. available RAM doesn't seem to exist on Windows + disp (sprintf ("Free RAM: %9.0f %s, swap: %9.0f %s", + round (free_ram / unitsize), unitname, + round (free_swap / unitsize), unitname)) + endif + disp (sprintf ("Available RAM: %9.0f %s, total: %9.0f %s", + round (user.ram_available_all_arrays / unitsize), unitname, + round (user.MemAvailableAllArrays / unitsize), unitname)) + endif + +endfunction + +function [status, meminfo] = lmemory () + ## Read pseudo files to gather memory information on Linux + + ## Read the proc/self/status pseudofile. + ## See https://linuxwiki.de/proc/pid#A.2Fproc.2Fpid.2Fstatus. + ## It contains a variable number of lines with name-value pairs. + + f = fopen ("/proc/self/status"); + buffer = textscan (f, "%s %s", "delimiter", ':\n'); + fclose (f); + for i = 1:rows (buffer{1}) + status.(buffer{1}{i}) = textscan (buffer{2}{i}){1}; + endfor + + ## Read the /proc/meminfo pseudofile + ## see https://linuxwiki.de/proc/meminfo + ## It contains a variable number of lines with name-value pairs. + + f = fopen ("/proc/meminfo"); + buffer = textscan (f, "%s %s", "delimiter", ':\n'); + fclose (f); + for i = 1:rows (buffer{1}) + meminfo.(buffer{1}{i}) = textscan (buffer{2}{i}){1}; + endfor + +endfunction + + +%!testif ; isunix () || ispc () +%! [user, syst] = memory (); +%! assert (user.mem_used_octave > 0); +%! assert (user.ram_used_octave <= user.mem_used_octave); +%! assert (user.mem_used_octave < syst.SystemMemory.Total); +%! assert (user.MemAvailableAllArrays <= syst.SystemMemory.Available); + +%!testif ; ! isunix () && ! ispc () +%! fail ("[user] = memory ()", +%! "function not yet implemented for this architecture"); +%! fail ("memory ()", "warning", +%! "function not yet implemented for this architecture"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/menu.m --- a/scripts/miscellaneous/menu.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/menu.m Thu Nov 19 13:08:00 2020 -0800 @@ -100,8 +100,9 @@ endfunction -%!error menu () -%!error menu ("title") +## Test input validation +%!error <Invalid call> menu () +%!error <Invalid call> menu ("title") %!error <TITLE must be a string> menu (1, "opt1") %!error <All OPTIONS must be strings> menu ("title", "opt1", 1) %!error <OPTIONS must be string or cell array of strings> menu ("title", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/methods.m --- a/scripts/miscellaneous/methods.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/methods.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,7 +46,7 @@ function mtds = methods (obj, opt) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -145,7 +145,7 @@ %! "validate_name"}); ## Test input validation -%!error methods () +%!error <Invalid call> methods () %!error methods ("a", "b", "c") %!error <invalid option> methods ("ftp", "option1") %!error <invalid input argument> methods (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mkdir.m --- a/scripts/miscellaneous/mkdir.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mkdir.m Thu Nov 19 13:08:00 2020 -0800 @@ -50,7 +50,7 @@ function [status, msg, msgid] = mkdir (parent, dirname) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -112,7 +112,7 @@ %! assert (isfolder (dir)); %! unwind_protect_cleanup %! confirm_recursive_rmdir (false, "local"); -%! rmdir (dir1, "s"); +%! sts = rmdir (dir1, "s"); %! end_unwind_protect %!test <*53031> @@ -125,8 +125,8 @@ %! assert (status); %! assert (isfolder (fullfile (tmp_dir, "subdir"))); %! unwind_protect_cleanup -%! rmdir (fullfile (tmp_dir, "subdir")); -%! rmdir (tmp_dir); +%! sts = rmdir (fullfile (tmp_dir, "subdir")); +%! sts = rmdir (tmp_dir); %! if (isempty (HOME)) %! unsetenv ("HOME"); %! else @@ -138,5 +138,4 @@ %! fail ('mkdir ("__%hello%__", "world")', "invalid PARENT"); ## Test input validation -%!error mkdir () -%!error mkdir ("a", "b", "c") +%!error <Invalid call> mkdir () diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/module.mk --- a/scripts/miscellaneous/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -10,6 +10,7 @@ %reldir%/private/tar_is_bsd.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/bug_report.m \ %reldir%/bunzip2.m \ %reldir%/cast.m \ @@ -44,6 +45,7 @@ %reldir%/loadobj.m \ %reldir%/ls.m \ %reldir%/ls_command.m \ + %reldir%/memory.m \ %reldir%/menu.m \ %reldir%/methods.m \ %reldir%/mex.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/movefile.m --- a/scripts/miscellaneous/movefile.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/movefile.m Thu Nov 19 13:08:00 2020 -0800 @@ -54,12 +54,12 @@ function [status, msg, msgid] = movefile (f1, f2, force) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif max_cmd_line = 1024; - status = true; + sts = 1; msg = ""; msgid = ""; @@ -96,13 +96,27 @@ ## If f1 has more than 1 element f2 must be a directory isdir = isfolder (f2); if (numel (f1) > 1 && ! isdir) - error ("movefile: when moving multiple files, F2 must be a directory"); + if (nargout == 0) + error ("movefile: when copying multiple files, F2 must be a directory"); + else + status = 0; + msg = "when copying multiple files, F2 must be a directory"; + msgid = "movefile"; + return; + endif endif ## Protect the filename(s). f1 = glob (f1); if (isempty (f1)) - error ("movefile: no files to move"); + if (nargout == 0) + error ("movefile: no files to move"); + else + status = 0; + msg = "no files to move"; + msgid = "movefile"; + return; + endif endif p1 = sprintf ('"%s" ', f1{:}); p2 = tilde_expand (f2); @@ -129,11 +143,11 @@ ## Move the file(s). [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); if (err != 0) - status = false; + sts = 0; msgid = "movefile"; endif ## Load new file(s) in editor - __event_manager_file_renamed__ (status); + __event_manager_file_renamed__ (sts); endwhile else if (ispc () && ! isunix () @@ -147,11 +161,19 @@ ## Move the file(s). [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); if (err != 0) - status = false; + sts = 0; msgid = "movefile"; endif ## Load new file(s) in editor - __event_manager_file_renamed__ (status); + __event_manager_file_renamed__ (sts); + endif + + if (nargout == 0) + if (sts == 0) + error ("movefile: operation failed: %s", msg); + endif + else + status = sts; endif endfunction @@ -159,14 +181,14 @@ %!test %! unwind_protect -%! f1 = tempname; +%! f1 = tempname (); %! tmp_var = pi; %! save (f1, "tmp_var"); %! fid = fopen (f1, "rb"); %! assert (fid >= 0); %! orig_data = fread (fid); %! fclose (fid); -%! f2 = tempname; +%! f2 = tempname (); %! assert (movefile (f1, f2)); %! assert (! exist (f1, "file")); %! assert (exist (f2, "file")); @@ -182,8 +204,8 @@ %! end_unwind_protect ## Test input validation -%!error movefile () -%!error movefile (1,2,3,4) +%!error <Invalid call> movefile () %!error <F1 must be a string> movefile (1, "foobar") %!error <F2 must be a string> movefile ("foobar", 1) %!error <F2 must be a directory> movefile ({"a", "b"}, "%_NOT_A_DIR_%") +%!error <no files to move> movefile ("%_NOT_A_FILENAME1_%", "%_NOT_A_FILENAME2_%") diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeFinite.m --- a/scripts/miscellaneous/mustBeFinite.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeFinite.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeFinite (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeGreaterThan.m --- a/scripts/miscellaneous/mustBeGreaterThan.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeGreaterThan.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ %!error <Invalid call> mustBeGreaterThan () %!error <Invalid call> mustBeGreaterThan (1) -%!error <Invalid call> mustBeGreaterThan (1,2,3) +%!error <called with too many inputs> mustBeGreaterThan (1, 2, 3) %!error <input must be greater than 42> mustBeGreaterThan (42, 42) %!error <found 1 elements that were not> mustBeGreaterThan (Inf, Inf) %!error <must be greater than 0> mustBeGreaterThan (NaN, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeGreaterThanOrEqual.m --- a/scripts/miscellaneous/mustBeGreaterThanOrEqual.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeGreaterThanOrEqual.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,6 +69,6 @@ %!error <Invalid call> mustBeGreaterThanOrEqual () %!error <Invalid call> mustBeGreaterThanOrEqual (1) -%!error <Invalid call> mustBeGreaterThanOrEqual (1,2,3) +%!error <called with too many inputs> mustBeGreaterThanOrEqual (1, 2, 3) %!error <must be greater than or equal to 2> mustBeGreaterThanOrEqual (1, 2) %!error <must be greater than or equal to 0> mustBeGreaterThanOrEqual (NaN, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeInteger.m --- a/scripts/miscellaneous/mustBeInteger.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeInteger.m Thu Nov 19 13:08:00 2020 -0800 @@ -37,7 +37,7 @@ function mustBeInteger (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -54,7 +54,7 @@ but = "there were non-finite values"; elseif (any (x != fix (x))) but = "it had fractional values in some elements"; - end + endif if (! isempty (but)) label = inputname (1); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeLessThan.m --- a/scripts/miscellaneous/mustBeLessThan.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeLessThan.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,7 +69,7 @@ %!error <Invalid call> mustBeLessThan () %!error <Invalid call> mustBeLessThan (1) -%!error <Invalid call> mustBeLessThan (1,2,3) +%!error <called with too many inputs> mustBeLessThan (1, 2, 3) %!error <must be less than 0> mustBeLessThan (1, 0) %!error <must be less than 1> mustBeLessThan (1, 1) %!error <must be less than Inf> mustBeLessThan (Inf, Inf) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeLessThanOrEqual.m --- a/scripts/miscellaneous/mustBeLessThanOrEqual.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeLessThanOrEqual.m Thu Nov 19 13:08:00 2020 -0800 @@ -72,5 +72,5 @@ %!error <Invalid call> mustBeLessThanOrEqual () %!error <Invalid call> mustBeLessThanOrEqual (1) -%!error <Invalid call> mustBeLessThanOrEqual (1,2,3) +%!error <called with too many inputs> mustBeLessThanOrEqual (1, 2, 3) %!error <must be less than or equal to 0> mustBeLessThanOrEqual (1, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeMember.m --- a/scripts/miscellaneous/mustBeMember.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeMember.m Thu Nov 19 13:08:00 2020 -0800 @@ -53,8 +53,8 @@ label = "input"; endif n_bad = numel (find (tf)); - # FIXME: Fancy inclusion of bad_val & valid values in the error message. - # Probably use mat2str() in a try/catch for that. + ## FIXME: Fancy inclusion of bad_val & valid values in the error message. + ## Probably use mat2str() in a try/catch for that. error ("%s must be one of the specified valid values; found %d elements that were not", ... label, n_bad); endif @@ -70,6 +70,6 @@ %!error <Invalid call> mustBeMember () %!error <Invalid call> mustBeMember (1) -%!error <Invalid call> mustBeMember (1,2,3) +%!error <called with too many inputs> mustBeMember (1, 2, 3) %!error <found 1 elements> mustBeMember ([1, 42], 1:5) %!error <found 1 elements> mustBeMember ("nope", {"foo", "bar", "baz"}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNegative.m --- a/scripts/miscellaneous/mustBeNegative.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNegative.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNegative (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNonNan.m --- a/scripts/miscellaneous/mustBeNonNan.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNonNan.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNonNan (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNonempty.m --- a/scripts/miscellaneous/mustBeNonempty.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNonempty.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNonempty (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNonnegative.m --- a/scripts/miscellaneous/mustBeNonnegative.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNonnegative.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNonnegative (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNonpositive.m --- a/scripts/miscellaneous/mustBeNonpositive.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNonpositive.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNonpositive (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNonsparse.m --- a/scripts/miscellaneous/mustBeNonsparse.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNonsparse.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNonsparse (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNonzero.m --- a/scripts/miscellaneous/mustBeNonzero.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNonzero.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNonzero (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNumeric.m --- a/scripts/miscellaneous/mustBeNumeric.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNumeric.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNumeric (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeNumericOrLogical.m --- a/scripts/miscellaneous/mustBeNumericOrLogical.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeNumericOrLogical.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeNumericOrLogical (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBePositive.m --- a/scripts/miscellaneous/mustBePositive.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBePositive.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBePositive (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/mustBeReal.m --- a/scripts/miscellaneous/mustBeReal.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/mustBeReal.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function mustBeReal (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/namedargs2cell.m --- a/scripts/miscellaneous/namedargs2cell.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/namedargs2cell.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,10 +46,9 @@ function c = namedargs2cell (s) - if (nargin != 1 || nargout > 1) + if (nargin < 1) print_usage (); - endif - if (! isstruct (s) || ! isscalar (s)) + elseif (! isstruct (s) || ! isscalar (s)) error ("namedargs2cell: S must be a scalar structure"); endif @@ -66,6 +65,6 @@ ## Test input validation %!error <Invalid call> namedargs2cell () -%!error <Invalid call> namedargs2cell (1, 2) +%!error <called with too many inputs> namedargs2cell (1, 2) %!error <S must be a scalar structure> namedargs2cell (true) %!error <S must be a scalar structure> namedargs2cell (struct ("name", {1, 2})) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/nargchk.m --- a/scripts/miscellaneous/nargchk.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/nargchk.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function msg = nargchk (minargs, maxargs, nargs, outtype = "string") - if (nargin < 3 || nargin > 4) + if (nargin < 3) print_usage (); elseif (minargs > maxargs) error ("nargchk: MINARGS must be <= MAXARGS"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/narginchk.m --- a/scripts/miscellaneous/narginchk.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/narginchk.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,7 @@ function narginchk (minargs, maxargs) if (nargin != 2) - print_usage; + print_usage (); elseif (! isnumeric (minargs) || ! isscalar (minargs)) error ("narginchk: MINARGS must be a numeric scalar"); elseif (! isnumeric (maxargs) || ! isscalar (maxargs)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/nargoutchk.m --- a/scripts/miscellaneous/nargoutchk.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/nargoutchk.m Thu Nov 19 13:08:00 2020 -0800 @@ -97,13 +97,13 @@ args = evalin ("caller", "nargout;"); if (args < minargs) - error ("nargoutchk: Not enough output arguments."); + error ("nargoutchk: Not enough output arguments"); elseif (args > maxargs) - error ("nargoutchk: Too many output arguments."); + error ("nargoutchk: Too many output arguments"); endif else - print_usage; + print_usage (); endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/news.m --- a/scripts/miscellaneous/news.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/news.m Thu Nov 19 13:08:00 2020 -0800 @@ -37,15 +37,11 @@ function news (package = "octave") - if (nargin > 1) - print_usage (); - else - display_info_file ("news", package, "NEWS"); - endif + ## function takes care of validating PACKAGE input + display_info_file ("news", package, "NEWS"); endfunction -%!error news (1, 2) %!error <news: PACKAGE must be a string> news (1) %!error <news: package .* is not installed> news ("__NOT_A_VALID_PKG_NAME__") diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/open.m --- a/scripts/miscellaneous/open.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/open.m Thu Nov 19 13:08:00 2020 -0800 @@ -73,7 +73,7 @@ function output = open (file) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -131,6 +131,6 @@ ## Test input validation -%!error open () +%!error <Invalid call> open () %!error open ("abc", "def") %!error <FILE must be a string> open (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/orderfields.m --- a/scripts/miscellaneous/orderfields.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/orderfields.m Thu Nov 19 13:08:00 2020 -0800 @@ -104,7 +104,7 @@ function [sout, p] = orderfields (s1, s2) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -213,8 +213,7 @@ %! assert (size_equal (s, s2)); ## Test input validation -%!error orderfields () -%!error orderfields (1,2,3) +%!error <Invalid call> orderfields () %!error <S1 must be a struct> orderfields (1) %!error <S1 and S2 do not have the same fields> %! s1.a = 1; diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/private/display_info_file.m --- a/scripts/miscellaneous/private/display_info_file.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/private/display_info_file.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ names = cellfun (@(x) x.name, installed, "UniformOutput", false); pos = strcmpi (names, package); if (! any (pos)) - error ("%s: package '%s' is not installed.", func, package); + error ("%s: package '%s' is not installed", func, package); endif filepath = fullfile (installed{pos}.dir, "packinfo", file); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/private/tar_is_bsd.m --- a/scripts/miscellaneous/private/tar_is_bsd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/private/tar_is_bsd.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,9 +36,10 @@ ## @end deftypefn function out = tar_is_bsd () + ## BSD tar needs to be handled differently from GNU tar persistent cache - if isempty (cache) + if (isempty (cache)) [status, tar_ver_str] = system ("tar --version"); if (status) error ("tar: Failed executing tar --version (status = %d)", status); @@ -46,4 +47,5 @@ cache = ! isempty (regexp (tar_ver_str, "bsdtar")); endif out = cache; + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/publish.m --- a/scripts/miscellaneous/publish.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/publish.m Thu Nov 19 13:08:00 2020 -0800 @@ -209,7 +209,7 @@ ## Check file to be in Octave's load path [file_path, file_name, file_ext] = fileparts (file); if (isempty (file_path)) - file_path = pwd; + file_path = pwd (); endif if (exist ([file_name, file_ext]) != 2) error (["publish: " file " is not in the load path"]); @@ -611,7 +611,7 @@ ## Extract <html> and <latex> blocks recursively. content_str = strjoin (content, "\n"); tags = {"html", "latex"}; - for i = 1:length(tags) + for i = 1:length (tags) tok = regexp (content_str, ... ['(.*?)(^|\n\n)(<', tags{i}, '>)\n(.*?)\n(<\/', ... tags{i}, '>)($|\n\n)(.*)'], "tokens", "once"); @@ -709,6 +709,7 @@ p_content{end+1}.type = "text"; p_content{end}.content = strjoin (block, "\n"); endfor + endfunction @@ -722,6 +723,7 @@ until (! ischar (m_source{i})) fclose (fid); m_source = m_source(1:end-1); # No EOL + endfunction @@ -770,6 +772,7 @@ endfor endif endif + endfunction @@ -783,6 +786,7 @@ toc_cstr{end+1} = format_text (cstr{i}.content, formatter); endif endfor + endfunction @@ -1067,6 +1071,7 @@ ## Split string by lines and preserve blank lines. cstr = strsplit (strrep (cstr, "\n\n", "\n \n"), "\n"); eval_context ("save"); + endfunction @@ -1088,7 +1093,7 @@ for i = 1:length (var_names) if (! any (strcmp (var_names{i}, forbidden_var_names))) ctext(var_names{i}) = evalin ("caller", var_names{i}); - end + endif endfor case "load" @@ -1107,13 +1112,14 @@ ## Do nothing endswitch + endfunction ## Note: Functional BIST tests are located in the 'test/publish' directory. ## Test input validation -%!error publish () +%!error <Invalid call> publish () %!error publish (1) %!error <FILE does not exist> publish ("%%_non_existent_file_%%.m") %!error <only script files can be published> publish ("publish.m") diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/recycle.m --- a/scripts/miscellaneous/recycle.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/recycle.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,10 +42,6 @@ persistent current_state = "off"; - if (nargin > 1) - print_usage (); - endif - if (nargin == 0 || nargout > 0) val = current_state; endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/run.m --- a/scripts/miscellaneous/run.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/run.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ function run (script) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -114,7 +114,7 @@ %! assert (_5yVNhWVJWJn47RKnzxPsyb_, 1337); %! unwind_protect_cleanup %! unlink (test_script); -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! end_unwind_protect ## Test function file execution @@ -140,11 +140,11 @@ %! assert (tstval2, true); %! unwind_protect_cleanup %! unlink (test_function); -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! path (path_orig); %! end_unwind_protect ## Test input validation -%!error run () +%!error <Invalid call> run () %!error run ("a", "b") %!error <SCRIPT must exist> run ("__A_very_#unlikely#_file_name__") diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/setfield.m --- a/scripts/miscellaneous/setfield.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/setfield.m Thu Nov 19 13:08:00 2020 -0800 @@ -52,7 +52,7 @@ ## the space character. Using arbitrary strings for field names is ## incompatible with @sc{matlab}, and this usage will emit a warning if the ## warning ID @code{Octave:language-extension} is enabled. -## @xref{XREFwarning_ids,,warning_ids}. +## @xref{XREFwarning_ids,,@code{warning_ids}}. ## ## With the second calling form, set a field of a structure array. The ## input @var{sidx} selects an element of the structure array, @var{field} @@ -146,7 +146,7 @@ %! assert (oo(1,2).fd(3).b(1,4), 6); ## Test input validation -%!error setfield () -%!error setfield (1) -%!error setfield (1,2) +%!error <Invalid call> setfield () +%!error <Invalid call> setfield (1) +%!error <Invalid call> setfield (1,2) %!error <invalid index> setfield (1,2,3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/substruct.m --- a/scripts/miscellaneous/substruct.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/substruct.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,7 +69,7 @@ error ("substruct: for TYPE == ., SUBS must be a character string"); endif else - error ('substruct: TYPE must be one of "()", "{}", or "."'); + error ('substruct: TYPE must be one of "()", "{}", or ""'); endif retval = struct ("type", typ, "subs", sub); @@ -87,8 +87,10 @@ %! y = substruct ("()", {1,2,3}, "{}", {":"}, ".", "foo"); %! assert (x,y); -%!error substruct () -%!error substruct (1, 2, 3) +## Test input validation +%!error <Invalid call> substruct () +%!error <Invalid call> substruct (1) +%!error <Invalid call> substruct (1, 2, 3) %!error substruct ("x", 1) %!error substruct ("()", [1,2,3]) %!error substruct (".", {1,2,3}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/swapbytes.m --- a/scripts/miscellaneous/swapbytes.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/swapbytes.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function y = swapbytes (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -74,6 +74,5 @@ %! assert (swapbytes (swapbytes (single (pi))), single (pi)); ## Test input validation -%!error swapbytes () -%!error swapbytes (1, 2) +%!error <Invalid call> swapbytes () %!error <invalid object of class 'cell'> swapbytes ({1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/symvar.m --- a/scripts/miscellaneous/symvar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/symvar.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,6 +48,7 @@ function vars = symvar (str) + warning ("off", "Octave:legacy-function", "local"); # using inline below. vars = argnames (inline (str)); ## Correct for auto-generated 'x' variable when no symvar was found. if (numel (vars) == 1 && strcmp (vars{1}, "x") && ! any (str == "x")) @@ -58,5 +59,5 @@ %!assert (symvar ("3*x + 4*y + 5*cos (z)"), {"x"; "y"; "z"}) -%!assert (symvar ("sin()^2 + cos()^2 == 1"), {}) +%!assert (symvar ("sin ()^2 + cos ()^2 == 1"), {}) %!assert (symvar ("1./x"), {"x"}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/tar.m --- a/scripts/miscellaneous/tar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/tar.m Thu Nov 19 13:08:00 2020 -0800 @@ -44,7 +44,7 @@ function filelist = tar (tarfile, files, rootdir = ".") - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -72,7 +72,7 @@ else cmd = sprintf ("tar cvf %s -C %s %s", tarfile, rootdir, sprintf (" %s", files{:})); - end + endif ## Save and restore the TAR_OPTIONS environment variable used by GNU tar. tar_options_env = getenv ("TAR_OPTIONS"); @@ -133,7 +133,7 @@ %! if (! exist (tarname, "file")) %! error ("tar archive file cannot be found!"); %! endif -%! outdir = tempname; +%! outdir = tempname (); %! untar (tarname, outdir); %! fid = fopen (fullfile (outdir, fname1), "rt"); %! assert (fid >= 0); @@ -149,17 +149,12 @@ %! chdir (orig_dir); %! unlink (tarname); %! confirm_recursive_rmdir (false, "local"); -%! if (exist (dirname)) -%! rmdir (dirname, "s"); -%! endif -%! if (exist (outdir)) -%! rmdir (outdir, "s"); -%! endif +%! sts = rmdir (dirname, "s"); +%! sts = rmdir (outdir, "s"); %! end_unwind_protect ## Test input validation -%!error tar () -%!error tar (1) -%!error tar (1,2,3,4) +%!error <Invalid call> tar () +%!error <Invalid call> tar (1) %!error <TARFILE must be a string> tar (1, "foobar") %!error <FILES must be a character array or cellstr> tar ("foobar", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/tempdir.m --- a/scripts/miscellaneous/tempdir.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/tempdir.m Thu Nov 19 13:08:00 2020 -0800 @@ -37,7 +37,7 @@ dirname = getenv ("TMPDIR"); if (isempty (dirname)) - dirname = P_tmpdir; + dirname = P_tmpdir (); endif if (! strcmp (dirname(end), filesep)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/unix.m --- a/scripts/miscellaneous/unix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/unix.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function [status, text] = unix (command, echo_arg) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -71,5 +71,5 @@ %! assert (output, ""); %! endif -%!error unix () -%!error unix (1, 2, 3) +## Test input validation +%!error <Invalid call> unix () diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/unpack.m --- a/scripts/miscellaneous/unpack.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/unpack.m Thu Nov 19 13:08:00 2020 -0800 @@ -78,7 +78,7 @@ function filelist = unpack (file, dir = [], filetype = "") - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -372,7 +372,7 @@ %! unlink (filename); %! unlink ([filename ".orig"]); %! confirm_recursive_rmdir (false, "local"); -%! rmdir (dirname, "s"); +%! sts = rmdir (dirname, "s"); %! end_unwind_protect %! unwind_protect_cleanup %! ## Restore environment variables TMPDIR, TMP @@ -386,8 +386,7 @@ %! end_unwind_protect ## Test input validation -%!error unpack () -%!error unpack (1,2,3,4) +%!error <Invalid call> unpack () %!error <FILE must be a string or cell array of strings> unpack (1) %!error <FILE "_%NOT_A_FILENAME%_" not found> unpack ("_%NOT_A_FILENAME%_") %!error <FILE "_%NOT_A_FILENAME%_" not found> unpack ({"_%NOT_A_FILENAME%_"}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/untar.m --- a/scripts/miscellaneous/untar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/untar.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ function filelist = untar (tarfile, dir = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/unzip.m --- a/scripts/miscellaneous/unzip.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/unzip.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ function filelist = unzip (zipfile, dir = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/validateattributes.m --- a/scripts/miscellaneous/validateattributes.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/validateattributes.m Thu Nov 19 13:08:00 2020 -0800 @@ -424,7 +424,7 @@ num_pos = strcmpi (cls, name); if (any (num_pos)) cls(num_pos) = []; - cls(end+1:end+numel(group)) = group; + cls(end+1:end+numel (group)) = group; endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/ver.m --- a/scripts/miscellaneous/ver.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/ver.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,10 +58,6 @@ function retval = ver (package = "") - if (nargin > 1) - print_usage (); - endif - if (nargout == 0) hg_id = __octave_config_info__ ("hg_id"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/verLessThan.m --- a/scripts/miscellaneous/verLessThan.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/verLessThan.m Thu Nov 19 13:08:00 2020 -0800 @@ -83,7 +83,7 @@ %!assert (verLessThan ("Octave", "99.9.9")) ## Test input validation -%!error verLessThan () +%!error <Invalid call> verLessThan () %!error verLessThan ("a") %!error verLessThan ("a", "1", "b") %!error <package "no-such-package" is not installed> diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/version.m --- a/scripts/miscellaneous/version.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/version.m Thu Nov 19 13:08:00 2020 -0800 @@ -72,7 +72,7 @@ function [v, d] = version (feature) - if (nargin > 1 || ((nargin != 0) && ((nargout > 1) || ! ischar (feature)))) + if (nargin == 1 && (nargout > 1 || ! ischar (feature))) print_usage (); endif @@ -81,7 +81,7 @@ if (nargout > 1) d = __octave_config_info__ ("release_date"); - end + endif else switch (lower (feature)) case "-date" diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/what.m --- a/scripts/miscellaneous/what.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/what.m Thu Nov 19 13:08:00 2020 -0800 @@ -73,10 +73,6 @@ function retval = what (dir) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) dir = { pwd() }; else @@ -109,7 +105,7 @@ if (numel (dir) == 0) w = __what__ (""); w = resize (w, [0, 1]); # Matlab compatibility, return 0x1 empty array - end + endif if (nargout == 0) for i = 1 : numel (w) diff -r dc3ee9616267 -r fa2cdef14442 scripts/miscellaneous/zip.m --- a/scripts/miscellaneous/zip.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/miscellaneous/zip.m Thu Nov 19 13:08:00 2020 -0800 @@ -44,7 +44,7 @@ function filelist = zip (zipfile, files, rootdir = ".") - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -126,16 +126,15 @@ %! error ("unzipped file not equal to original file!"); %! endif %! unwind_protect_cleanup -%! unlink (filename); -%! unlink ([dirname, filesep, basename, ext]); -%! unlink (zipfile); -%! unlink ([zipfile ".zip"]); -%! rmdir (dirname); +%! sts = unlink (filename); +%! sts = unlink ([dirname, filesep, basename, ext]); +%! sts = unlink (zipfile); +%! sts = unlink ([zipfile ".zip"]); +%! sts = rmdir (dirname); %! end_unwind_protect ## Test input validation -%!error zip () -%!error zip (1) -%!error zip (1,2,3,4) +%!error <Invalid call> zip () +%!error <Invalid call> zip (1) %!error <ZIPFILE must be a string> zip (1, "foobar") %!error <FILES must be a character array or cellstr> zip ("foobar", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/module.mk --- a/scripts/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -6,6 +6,7 @@ include %reldir%/+containers/module.mk include %reldir%/+matlab/+lang/module.mk +include %reldir%/+matlab/+net/module.mk include %reldir%/audio/module.mk include %reldir%/deprecated/module.mk include %reldir%/elfun/module.mk @@ -49,6 +50,9 @@ ######################## include %reldir%/@ftp/module.mk ######################## FCN_FILE_DIRS += %reldir%/@ftp +%canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config + %canon_reldir%_@ftp_FCN_FILES = \ %reldir%/@ftp/ascii.m \ %reldir%/@ftp/binary.m \ @@ -70,7 +74,9 @@ %canon_reldir%_@ftp_DATA = $(%canon_reldir%_@ftp_FCN_FILES) -FCN_FILES += $(%canon_reldir%_@ftp_FCN_FILES) +FCN_FILES += \ + $(%canon_reldir%_FCN_FILES) \ + $(%canon_reldir%_@ftp_FCN_FILES) PKG_ADD_FILES += %reldir%/@ftp/PKG_ADD diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/ode/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/decic.m --- a/scripts/ode/decic.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/decic.m Thu Nov 19 13:08:00 2020 -0800 @@ -97,7 +97,7 @@ y0, fixed_y0, yp0, fixed_yp0, options) - if (nargin < 6 || nargin > 7) + if (nargin < 6) print_usage (); endif @@ -215,13 +215,12 @@ %! assert ([ynew(1:end), ypnew(1:end)], [ref1(1:end), ref2(1:end)], 1e-5); ## Test input validation -%!error decic () -%!error decic (1) -%!error decic (1,2) -%!error decic (1,2,3) -%!error decic (1,2,3,4) -%!error decic (1,2,3,4,5) -%!error decic (1,2,3,4,5,6,7,8) +%!error <Invalid call> decic () +%!error <Invalid call> decic (1) +%!error <Invalid call> decic (1,2) +%!error <Invalid call> decic (1,2,3) +%!error <Invalid call> decic (1,2,3,4) +%!error <Invalid call> decic (1,2,3,4,5) %!error <FUN must be a valid function handle> %! decic (1, 0, [1; 0; 0], [1; 1; 0], [-1e-4; 1; 0], [0; 0; 0]); %!error <T0 must be a numeric scalar> diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/module.mk --- a/scripts/ode/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -17,6 +17,7 @@ %reldir%/private/starting_stepsize.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/decic.m \ %reldir%/ode15i.m \ %reldir%/ode15s.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/ode15i.m --- a/scripts/ode/ode15i.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/ode15i.m Thu Nov 19 13:08:00 2020 -0800 @@ -261,13 +261,13 @@ varargout{1} = t; varargout{2} = y; elseif (nargout == 1) - varargout{1}.x = t; # Time stamps are saved in field x - varargout{1}.y = y; # Results are saved in field y + varargout{1}.x = t.'; # Time stamps saved in field x (row vector) + varargout{1}.y = y.'; # Results are saved in field y (row vector) varargout{1}.solver = solver; if (options.haveeventfunction) - varargout{1}.xe = te; # Time info when an event occurred - varargout{1}.ye = ye; # Results when an event occurred - varargout{1}.ie = ie; # Index info which event occurred + varargout{1}.xe = te.'; # Time info when an event occurred + varargout{1}.ye = ye.'; # Results when an event occurred + varargout{1}.ie = ie.'; # Index info which event occurred endif elseif (nargout > 2) varargout = cell (1,5); @@ -388,11 +388,11 @@ ## With empty options %!testif HAVE_SUNDIALS -%! opt = odeset(); +%! opt = odeset (); %! [t, y] = ode15i (@rob, [0, 1e6, 2e6, 3e6, 4e6], [1; 0; 0], %! [-1e-4; 1e-4; 0], opt); %! assert ([t(end), y(end,:)], fref2, 1e-3); -%! opt = odeset(); +%! opt = odeset (); ## Without options %!testif HAVE_SUNDIALS @@ -504,7 +504,7 @@ %! opt = odeset ("Events", @ff); %! sol = ode15i (@rob, [0, 100], [1; 0; 0], [-1e-4; 1e-4; 0], opt); %! assert (isfield (sol, "ie")); -%! assert (sol.ie, [0;1]); +%! assert (sol.ie, [1, 2]); %! assert (isfield (sol, "xe")); %! assert (isfield (sol, "ye")); %! assert (sol.x(end), 10, 1); @@ -514,20 +514,22 @@ %! opt = odeset ("Events", @ff); %! [t, y, te, ye, ie] = ode15i (@rob, [0, 100], [1; 0; 0], %! [-1e-4; 1e-4; 0], opt); -%! assert ([t(end), te', ie'], [10, 10, 10, 0, 1], [1, 0.2, 0.2, 0, 0]); +%! assert (t(end), 10, 1); +%! assert (te, [10; 10], 0.2); +%! assert (ie, [1; 2]); ## Initial solutions as row vectors %!testif HAVE_SUNDIALS %! A = eye (2); %! [tout, yout] = ode15i (@(t, y, yp) A * y - A * yp, ... %! [0, 1], [1, 1], [1, 1]); -%! assert (size (yout), [20, 2]) +%! assert (size (yout), [20, 2]); %!testif HAVE_SUNDIALS %! A = eye (2); %! [tout, yout] = ode15i (@(t, y, yp) A * y - A * yp, ... %! [0, 1], [1, 1], [1; 1]); -%! assert (size (yout), [20, 2]) +%! assert (size (yout), [20, 2]); ## Jacobian fun wrong dimension %!testif HAVE_SUNDIALS diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/ode15s.m --- a/scripts/ode/ode15s.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/ode15s.m Thu Nov 19 13:08:00 2020 -0800 @@ -270,7 +270,7 @@ options.havetimedep, options.havejacfun); options.havejacfun = true; - else ## All matrices are constant + else # All matrices are constant options.Jacobian = {[- options.Jacobian], [options.Mass]}; endif @@ -322,13 +322,13 @@ varargout{1} = t; varargout{2} = y; elseif (nargout == 1) - varargout{1}.x = t; # Time stamps are saved in field x - varargout{1}.y = y; # Results are saved in field y + varargout{1}.x = t.'; # Time stamps saved in field x (row vector) + varargout{1}.y = y.'; # Results are saved in field y (row vector) varargout{1}.solver = solver; if (options.haveeventfunction) - varargout{1}.xe = te; # Time info when an event occurred - varargout{1}.ye = ye; # Results when an event occurred - varargout{1}.ie = ie; # Index info which event occurred + varargout{1}.xe = te.'; # Time info when an event occurred + varargout{1}.ye = ye.'; # Results when an event occurred + varargout{1}.ie = ie.'; # Index info which event occurred endif elseif (nargout > 2) varargout = cell (1,5); @@ -433,7 +433,7 @@ %! refrob = [100, 0.617234887614937, 0.000006153591397, 0.382758958793666]; %!endfunction %! -%!function [val, isterminal, direction] = feve (t, y) +%!function [val, isterminal, direction] = feve (t, y, ~) %! isterminal = [0, 1]; %! if (t < 1e1) %! val = [-1, -2]; @@ -467,9 +467,9 @@ %!endfunction %! %!function jac = jacfunsparse (t, y) -%! jac = sparse([-0.04, 1e4*y(3), 1e4*y(2); -%! 0.04, -1e4*y(3)-6e7*y(2), -1e4*y(2); -%! 1, 1, 1]); +%! jac = sparse ([-0.04, 1e4*y(3), 1e4*y(2); +%! 0.04, -1e4*y(3)-6e7*y(2), -1e4*y(2); +%! 1, 1, 1]); %!endfunction %!testif HAVE_SUNDIALS @@ -619,77 +619,77 @@ ## Solve in backward direction starting at t=0 %!testif HAVE_SUNDIALS -%! ref = [-1.205364552835178, 0.951542399860817]; +%! ref = [-1.205364552835178; 0.951542399860817]; %! sol = ode15s (@fpol, [0 -2], [2, 0]); -%! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 5e-3); +%! assert ([sol.x(end); sol.y(:,end)], [-2; ref], 5e-3); ## Solve in backward direction starting at t=2 %!testif HAVE_SUNDIALS -%! ref = [-1.205364552835178, 0.951542399860817]; +%! ref = [-1.205364552835178; 0.951542399860817]; %! sol = ode15s (@fpol, [2, 0 -2], fref); -%! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 3e-2); +%! assert ([sol.x(end); sol.y(:,end)], [-2; ref], 3e-2); ## Solve another anonymous function in backward direction %!testif HAVE_SUNDIALS -%! ref = [-1, 0.367879437558975]; +%! ref = [-1; 0.367879437558975]; %! sol = ode15s (@(t,y) y, [0 -1], 1); -%! assert ([sol.x(end), sol.y(end,:)], ref, 1e-2); +%! assert ([sol.x(end); sol.y(:,end)], ref, 1e-2); ## Solve another anonymous function below zero %!testif HAVE_SUNDIALS -%! ref = [0, 14.77810590694212]; +%! ref = [0; 14.77810590694212]; %! sol = ode15s (@(t,y) y, [-2, 0], 2); -%! assert ([sol.x(end), sol.y(end,:)], ref, 5e-2); +%! assert ([sol.x(end); sol.y(:,end)], ref, 5e-2); ## Solve in backward direction starting at t=0 with MaxStep option %!testif HAVE_SUNDIALS -%! ref = [-1.205364552835178, 0.951542399860817]; +%! ref = [-1.205364552835178; 0.951542399860817]; %! opt = odeset ("MaxStep", 1e-3); %! sol = ode15s (@fpol, [0 -2], [2, 0], opt); %! assert (abs (sol.x(8)-sol.x(7)), 1e-3, 1e-3); -%! assert ([sol.x(end), sol.y(end,:)], [-2, ref], 1e-3); +%! assert ([sol.x(end); sol.y(:,end)], [-2; ref], 1e-3); ## AbsTol option %!testif HAVE_SUNDIALS %! opt = odeset ("AbsTol", 1e-5); %! sol = ode15s (@fpol, [0, 2], [2, 0], opt); -%! assert ([sol.x(end), sol.y(end,:)], [2, fref], 4e-3); +%! assert ([sol.x(end); sol.y(:,end)], [2, fref].', 4e-3); ## AbsTol and RelTol option %!testif HAVE_SUNDIALS %! opt = odeset ("AbsTol", 1e-8, "RelTol", 1e-8); %! sol = ode15s (@fpol, [0, 2], [2, 0], opt); -%! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-3); +%! assert ([sol.x(end); sol.y(:,end)], [2, fref].', 1e-3); ## RelTol option -- higher accuracy %!testif HAVE_SUNDIALS %! opt = odeset ("RelTol", 1e-8); %! sol = ode15s (@fpol, [0, 2], [2, 0], opt); -%! assert ([sol.x(end), sol.y(end,:)], [2, fref], 1e-4); +%! assert ([sol.x(end); sol.y(:,end)], [2, fref].', 1e-4); ## Mass option as function %!testif HAVE_SUNDIALS %! opt = odeset ("Mass", @fmas, "MStateDependence", "none"); %! sol = ode15s (@fpol, [0, 2], [2, 0], opt); -%! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3); +%! assert ([sol.x(end); sol.y(:,end)], [2, fref].', 3e-3); ## Mass option as matrix %!testif HAVE_SUNDIALS %! opt = odeset ("Mass", eye (2,2), "MStateDependence", "none"); %! sol = ode15s (@fpol, [0, 2], [2, 0], opt); -%! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3); +%! assert ([sol.x(end); sol.y(:,end)], [2, fref].', 3e-3); ## Mass option as sparse matrix %!testif HAVE_SUNDIALS %! opt = odeset ("Mass", speye (2), "MStateDependence", "none"); %! sol = ode15s (@fpol, [0, 2], [2, 0], opt); -%! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3); +%! assert ([sol.x(end); sol.y(:,end)], [2, fref].', 3e-3); ## Mass option as function and sparse matrix %!testif HAVE_SUNDIALS %! opt = odeset ("Mass", "fmsa", "MStateDependence", "none"); %! sol = ode15s (@fpol, [0, 2], [2, 0], opt); -%! assert ([sol.x(end), sol.y(end,:)], [2, fref], 3e-3); +%! assert ([sol.x(end); sol.y(:,end)], [2, fref].', 3e-3); ## Refine %!testif HAVE_SUNDIALS @@ -715,7 +715,7 @@ %! "MStateDependence", "none"); %! sol = ode15s (@rob, [0, 100], [1; 0; 0], opt); %! assert (isfield (sol, "ie")); -%! assert (sol.ie, [0;1]); +%! assert (sol.ie, [1, 2]); %! assert (isfield (sol, "xe")); %! assert (isfield (sol, "ye")); %! assert (sol.x(end), 10, 1); @@ -725,13 +725,15 @@ %! opt = odeset ("Events", @feve, "Mass", @massdensefunstate, %! "MStateDependence", "none"); %! [t, y, te, ye, ie] = ode15s (@rob, [0, 100], [1; 0; 0], opt); -%! assert ([t(end), te', ie'], [10, 10, 10, 0, 1], [1, 0.5, 0.5, 0, 0]); +%! assert (t(end), 10, 1); +%! assert (te, [10; 10], 0.5); +%! assert (ie, [1; 2]); ## Initial solution as row vector %!testif HAVE_SUNDIALS %! A = zeros (2); %! [tout, yout] = ode15s (@(t, y) A * y, [0, 1], [1, 1]); -%! assert (yout, ones (18, 2)) +%! assert (yout, ones (18, 2)); %!testif HAVE_SUNDIALS %! A = zeros (2); diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/ode23.m --- a/scripts/ode/ode23.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/ode23.m Thu Nov 19 13:08:00 2020 -0800 @@ -326,19 +326,19 @@ ## We are using the Van der Pol equation for all tests. ## Further tests also define a reference solution (computed at high accuracy) -%!function ydot = fpol (t, y) # The Van der Pol ODE +%!function ydot = fpol (t, y, varargin) # The Van der Pol ODE %! ydot = [y(2); (1 - y(1)^2) * y(2) - y(1)]; %!endfunction %!function ref = fref () # The computed reference sol %! ref = [0.32331666704577, -1.83297456798624]; %!endfunction %!function [val, trm, dir] = feve (t, y, varargin) -%! val = fpol (t, y, varargin); # We use the derivatives +%! val = fpol (t, y, varargin{:}); # We use the derivatives %! trm = zeros (2,1); # that's why component 2 %! dir = ones (2,1); # does not seem to be exact %!endfunction %!function [val, trm, dir] = fevn (t, y, varargin) -%! val = fpol (t, y, varargin); # We use the derivatives +%! val = fpol (t, y, varargin{:}); # We use the derivatives %! trm = ones (2,1); # that's why component 2 %! dir = ones (2,1); # does not seem to be exact %!endfunction @@ -378,7 +378,7 @@ %! [t, y] = ode23 (@fpol, [0 2], [2 0], 12, 13, "KL"); %! assert ([t(end), y(end,:)], [2, fref], 1e-3); %!test # empty OdePkg structure *but* extra input arguments -%! opt = odeset; +%! opt = odeset (); %! [t, y] = ode23 (@fpol, [0 2], [2 0], opt, 12, 13, "KL"); %! assert ([t(end), y(end,:)], [2, fref], 1e-2); %!test # Solve another anonymous function below zero @@ -426,7 +426,7 @@ %!test # hermite_cubic_interpolation %! opt = odeset ("RelTol", 1e-8, "NormControl", "on"); %! [t,sol] = ode23(@(t,x)[x(2);x(1)],linspace(0,1),[1;0],opt); -%! assert(max(abs(sol(:,1)-cosh(t))),0,1e-6) +%! assert (max (abs (sol(:,1)-cosh (t))),0,1e-6); %!test # RelTol and NormControl option -- higher accuracy %! opt = odeset ("RelTol", 1e-8, "NormControl", "on"); %! sol = ode23 (@fpol, [0 2], [2 0], opt); @@ -497,14 +497,14 @@ %!test # Check that imaginary part of solution does not get inverted %! sol = ode23 (@(x,y) 1, [0 1], 1i); -%! assert (imag (sol.y), ones (size (sol.y))) +%! assert (imag (sol.y), ones (size (sol.y))); %! [x, y] = ode23 (@(x,y) 1, [0 1], 1i); -%! assert (imag (y), ones (size (y))) +%! assert (imag (y), ones (size (y))); ## Test input validation -%!error ode23 () -%!error ode23 (1) -%!error ode23 (1,2) +%!error <Invalid call> ode23 () +%!error <Invalid call> ode23 (1) +%!error <Invalid call> ode23 (1,2) %!error <TRANGE must be a numeric> ode23 (@fpol, {[0 25]}, [3 15 1]) %!error <TRANGE must be a .* vector> ode23 (@fpol, [0 25; 25 0], [3 15 1]) %!error <TRANGE must contain at least 2 elements> ode23 (@fpol, [1], [3 15 1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/ode23s.m --- a/scripts/ode/ode23s.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/ode23s.m Thu Nov 19 13:08:00 2020 -0800 @@ -283,7 +283,7 @@ %! [vt, vy] = ode23s (fun, [0 20], [2 0]); %! toc () %! ## Plotting the result -%! plot(vt,vy(:,1),'-o'); +%! plot (vt,vy(:,1),'-o'); %!demo %! ## Demo function: stiff Van Der Pol equation @@ -295,7 +295,7 @@ %! [vt, vy] = ode23s (fun, [0 20], [2 0], odeopts); %! toc () %! ## Plotting the result -%! plot(vt,vy(:,1),'-o'); +%! plot (vt,vy(:,1),'-o'); %!demo %! ## Demo function: stiff Van Der Pol equation @@ -306,7 +306,7 @@ %! [vt, vy] = ode23s (fun, [0 200], [2 0]); %! toc () %! ## Plotting the result -%! plot(vt,vy(:,1),'-o'); +%! plot (vt,vy(:,1),'-o'); %!demo %! ## Demo function: stiff Van Der Pol equation @@ -318,7 +318,7 @@ %! [vt, vy] = ode23s (fun, [0 200], [2 0], odeopts); %! toc () %! ## Plotting the result -%! plot(vt,vy(:,1),'-o'); +%! plot (vt,vy(:,1),'-o'); %!demo %! ## Demonstrate convergence order for ode23s @@ -357,7 +357,7 @@ ## We are using the "Van der Pol" implementation for all tests that are done ## for this function. For further tests we also define a reference solution ## (computed at high accuracy). -%!function ydot = fpol (t, y) # The Van der Pol ODE +%!function ydot = fpol (t, y, varargin) # The Van der Pol ODE %! ydot = [y(2); 10 * (1 - y(1)^2) * y(2) - y(1)]; %!endfunction %!function ydot = jac (t, y) # The Van der Pol ODE @@ -367,12 +367,12 @@ %! ref = [1.8610687248524305 -0.0753216319179125]; %!endfunction %!function [val, trm, dir] = feve (t, y, varargin) -%! val = fpol (t, y, varargin); # We use the derivatives +%! val = fpol (t, y, varargin{:}); # We use the derivatives %! trm = zeros (2,1); # that's why component 2 %! dir = ones (2,1); # does not seem to be exact %!endfunction %!function [val, trm, dir] = fevn (t, y, varargin) -%! val = fpol (t, y, varargin); # We use the derivatives +%! val = fpol (t, y, varargin{:}); # We use the derivatives %! trm = ones (2,1); # that's why component 2 %! dir = ones (2,1); # does not seem to be exact %!endfunction @@ -412,7 +412,7 @@ %! [t, y] = ode23s (@fpol, [0 2], [2 0], 12, 13, "KL"); %! assert ([t(end), y(end,:)], [2, fref], 1e-3); %!test # empty OdePkg structure *but* extra input arguments -%! opt = odeset; +%! opt = odeset (); %! [t, y] = ode23s (@fpol, [0 2], [2 0], opt, 12, 13, "KL"); %! assert ([t(end), y(end,:)], [2, fref], 1e-2); %!test # InitialStep option @@ -495,14 +495,14 @@ %!test # Check that imaginary part of solution does not get inverted %! sol = ode23s (@(x,y) 1, [0 1], 1i); -%! assert (imag (sol.y), ones (size (sol.y))) +%! assert (imag (sol.y), ones (size (sol.y))); %! [x, y] = ode23s (@(x,y) 1, [0 1], 1i); -%! assert (imag (y), ones (size (y))) +%! assert (imag (y), ones (size (y))); ## Test input validation -%!error ode23s () -%!error ode23s (1) -%!error ode23s (1,2) +%!error <Invalid call> ode23s () +%!error <Invalid call> ode23s (1) +%!error <Invalid call> ode23s (1,2) %!error <TRANGE must be a numeric> ode23s (@fpol, {[0 25]}, [3 15 1]) %!error <TRANGE must be a .* vector> ode23s (@fpol, [0 25; 25 0], [3 15 1]) %!error <TRANGE must contain at least 2 elements> ode23s (@fpol, [1], [3 15 1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/ode45.m --- a/scripts/ode/ode45.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/ode45.m Thu Nov 19 13:08:00 2020 -0800 @@ -326,19 +326,19 @@ ## We are using the Van der Pol equation for all tests. ## Further tests also define a reference solution (computed at high accuracy) -%!function ydot = fpol (t, y) # The Van der Pol ODE +%!function ydot = fpol (t, y, varargin) # The Van der Pol ODE %! ydot = [y(2); (1 - y(1)^2) * y(2) - y(1)]; %!endfunction %!function ref = fref () # The computed reference solution %! ref = [0.32331666704577, -1.83297456798624]; %!endfunction %!function [val, trm, dir] = feve (t, y, varargin) -%! val = fpol (t, y, varargin); # We use the derivatives +%! val = fpol (t, y, varargin{:}); # We use the derivatives %! trm = zeros (2,1); # that's why component 2 %! dir = ones (2,1); # does not seem to be exact %!endfunction %!function [val, trm, dir] = fevn (t, y, varargin) -%! val = fpol (t, y, varargin); # We use the derivatives +%! val = fpol (t, y, varargin{:}); # We use the derivatives %! trm = ones (2,1); # that's why component 2 %! dir = ones (2,1); # does not seem to be exact %!endfunction @@ -401,7 +401,7 @@ %! assert ([sol.x(5)-sol.x(4)], [1e-3], 1e-3); %!test # Solve with intermediate step %! [t, y] = ode45 (@fpol, [0 1 2], [2 0]); -%! assert (any((t-1) == 0)); +%! assert (any ((t-1) == 0)); %! assert ([t(end), y(end,:)], [2, fref], 1e-3); %!test # Solve in backward direction starting at t=0 %! vref = [-1.205364552835178, 0.951542399860817]; @@ -414,7 +414,7 @@ %!test # Solve in backward direction starting at t=2, with intermediate step %! vref = [-1.205364552835178, 0.951542399860817]; %! [t, y] = ode45 (@fpol, [2 0 -2], fref); -%! idx = find(y < 0, 1, "first") - 1; +%! idx = find (y < 0, 1, "first") - 1; %! assert ([t(idx), y(idx,:)], [0,2,0], 1e-2); %! assert ([t(end), y(end,:)], [-2, vref], 1e-2); %!test # Solve another anonymous function in backward direction @@ -510,13 +510,13 @@ %!test # Check that imaginary part of solution does not get inverted %! sol = ode45 (@(x,y) 1, [0 1], 1i); -%! assert (imag (sol.y), ones (size (sol.y))) +%! assert (imag (sol.y), ones (size (sol.y))); %! [x, y] = ode45 (@(x,y) 1, [0 1], 1i); -%! assert (imag (y), ones (size (y))) +%! assert (imag (y), ones (size (y))); -%!error ode45 () -%!error ode45 (1) -%!error ode45 (1,2) +%!error <Invalid call> ode45 () +%!error <Invalid call> ode45 (1) +%!error <Invalid call> ode45 (1,2) %!error <TRANGE must be a numeric> ode45 (@fpol, {[0 25]}, [3 15 1]) %!error <TRANGE must be a .* vector> ode45 (@fpol, [0 25; 25 0], [3 15 1]) %!error <TRANGE must contain at least 2 elements> ode45 (@fpol, [1], [3 15 1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/odeget.m --- a/scripts/ode/odeget.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/odeget.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,6 +43,10 @@ function val = odeget (ode_opt, field, default = []) + if (nargin < 2) + print_usage (); + endif + validateattributes (ode_opt, {"struct"}, {"nonempty"}); validateattributes (field, {"char"}, {"nonempty"}); @@ -79,9 +83,9 @@ %! warning ("off", "Octave:invalid-input-arg", "local"); %! assert (odeget (odeset ("foo", 42), "foo"), 42); -%!error odeget () -%!error odeget (1) -%!error odeget (1,2,3,4,5) +## Test input validation +%!error <Invalid call> odeget () +%!error <Invalid call> odeget (1) %!error odeget (1, "opt1") %!error odeget (struct ("opt1", 1), 1) %!error odeget (struct ("opt1", 1), "foo") diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/odeplot.m --- a/scripts/ode/odeplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/odeplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -91,7 +91,7 @@ for i = 1:num_lines set (hlines(i), "xdata", told, "ydata", yold(i,:)); endfor - drawnow; + drawnow (); retval = false; diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/odeset.m --- a/scripts/ode/odeset.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/odeset.m Thu Nov 19 13:08:00 2020 -0800 @@ -119,7 +119,7 @@ ## ## @item @code{OutputFcn}: function_handle ## Function to monitor the state during the simulation. For the form of -## the function to use see @code{odeplot}. +## the function to use @pxref{XREFodeplot,,@code{odeplot}}. ## ## @item @code{OutputSel}: scalar | vector ## Indices of elements of the state vector to be passed to the output diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/private/check_default_input.m --- a/scripts/ode/private/check_default_input.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/private/check_default_input.m Thu Nov 19 13:08:00 2020 -0800 @@ -23,7 +23,11 @@ ## ######################################################################## -function [fun] = check_default_input (fun, trange, solver, varargin); +function fun = check_default_input (fun, trange, solver, y0, yp0); + + if (nargin < 4) + print_usage (); + endif ## Check fun validateattributes (fun, {"function_handle", "char"}, {}, solver, "fun"); @@ -57,7 +61,6 @@ endif ## Check y0 and yp0 - y0 = varargin{1}; if (! isnumeric (y0) || ! isvector (y0)) error ("Octave:invalid-input-arg", [solver ": Y0 must be a numeric vector"]); @@ -65,7 +68,6 @@ y0 = y0(:); if (nargin == 5) - yp0 = varargin{2}; if (! isnumeric (yp0) || ! isvector (yp0)) error ("Octave:invalid-input-arg", [solver ": YP0 must be a numeric vector"]); diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/private/odemergeopts.m --- a/scripts/ode/private/odemergeopts.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/private/odemergeopts.m Thu Nov 19 13:08:00 2020 -0800 @@ -23,8 +23,12 @@ ## ######################################################################## +## FIXME: there are some calls to odemergeopts with a "solver" argument +## but we don't use that here. Should the calls be fixed or should we +## do something with the solver argument here? + function options = odemergeopts (caller, useroptions, options, classes, - attributes); + attributes, solver); for [value, key] = options diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/private/runge_kutta_23s.m --- a/scripts/ode/private/runge_kutta_23s.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/private/runge_kutta_23s.m Thu Nov 19 13:08:00 2020 -0800 @@ -128,7 +128,7 @@ endif W = M - dt*d*J; - if issparse (W) + if (issparse (W)) [Lw, Uw, Pw, Qw, Rw] = lu (W); else [Lw, Uw, Pw] = lu (W); @@ -136,13 +136,13 @@ ## compute the slopes F(:,1) = feval (fun, t, x, args{:}); - if issparse (W) + if (issparse (W)) k(:,1) = Qw * (Uw \ (Lw \ (Pw * (Rw \ (F(:,1) + dt*d*T))))); else k(:,1) = Uw \ (Lw \ (Pw * (F(:,1) + dt*d*T))); endif F(:,2) = feval (fun, t+a*dt, x+a*dt*k(:,1), args{:}); - if issparse (W) + if (issparse (W)) k(:,2) = Uw * (Uw \ (Lw \ (Pw * (Rw \ (F(:,2) - M*k(:,1)))))) + k(:,1); else k(:,2) = Uw \ (Lw \ (Pw * (F(:,2) - M*k(:,1)))) + k(:,1); @@ -154,7 +154,7 @@ if (nargout >= 3) ## 3rd order, needed in error formula F(:,3) = feval (fun, t+dt, x_next, args{:}); - if issparse (W) + if (issparse (W)) k(:,3) = Qw * (Uw \ (Lw \ (Pw * (Rw \ (F(:,3) - e32 * (M*k(:,2) - F(:,2)) - 2 * (M*k(:,1) - F(:,1)) + dt*d*T))))); else k(:,3) = Uw \ (Lw \ (Pw * (F(:,3) - e32 * (M*k(:,2) - F(:,2)) - 2 * (M*k(:,1) - F(:,1)) + dt*d*T))); diff -r dc3ee9616267 -r fa2cdef14442 scripts/ode/private/runge_kutta_interpolate.m --- a/scripts/ode/private/runge_kutta_interpolate.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/ode/private/runge_kutta_interpolate.m Thu Nov 19 13:08:00 2020 -0800 @@ -60,12 +60,12 @@ ## at the time t_out using 2nd order Hermite interpolation. function x_out = quadratic_interpolation (t, x, der, t_out) - # coefficients of the parabola + ## coefficients of the parabola a = -(x(:,1) - x(:,2) - der(:).*(t(1)-t(2))) / (t(1) - t(2))^2; b = der(:) - 2*t(1).*a; c = x(:,1) - a*t(1)^2 - b*t(1); - # evaluate in t_out + ## evaluate in t_out x_out = a*t_out.^2 + b*t_out + c; endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/optimization/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/fminbnd.m --- a/scripts/optimization/fminbnd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/fminbnd.m Thu Nov 19 13:08:00 2020 -0800 @@ -97,7 +97,7 @@ return; endif - if (nargin < 2 || nargin > 4) + if (nargin < 2) print_usage (); endif @@ -288,15 +288,15 @@ function print_formatted_table (table) printf ("\n Func-count x f(x) Procedure\n"); for row=table - printf("%5.5s %7.7s %8.8s\t%s\n", - int2str (row.funccount), num2str (row.x,"%.5f"), - num2str (row.fx,"%.6f"), row.procedure); + printf ("%5.5s %7.7s %8.8s\t%s\n", + int2str (row.funccount), num2str (row.x,"%.5f"), + num2str (row.fx,"%.6f"), row.procedure); endfor printf ("\n"); endfunction ## Print either a success termination message or bad news -function print_exit_msg (info, opt=struct()) +function print_exit_msg (info, opt=struct ()) printf (""); switch (info) case 1 diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/fminsearch.m --- a/scripts/optimization/fminsearch.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/fminsearch.m Thu Nov 19 13:08:00 2020 -0800 @@ -55,8 +55,9 @@ ## @code{200 * number_of_variables}, i.e., @code{200 * length (@var{x0})}. ## The value must be a positive integer. ## -## For a description of the other options, see @code{optimset}. To initialize -## an options structure with default values for @code{fminsearch} use +## For a description of the other options, +## @pxref{XREFoptimset,,@code{optimset}}. To initialize an options structure +## with default values for @code{fminsearch} use ## @code{options = optimset ("fminsearch")}. ## ## @code{fminsearch} may also be called with a single structure argument @@ -311,7 +312,7 @@ endfor else ## Right-angled simplex based on co-ordinate axes. - alpha = scale * ones(n+1,1); + alpha = scale * ones (n+1,1); for j = 2:n+1 V(:,j) = x0 + alpha(j)*V(:,j); x(:) = V(:,j); @@ -362,7 +363,7 @@ printf ("Iter. %2.0f,", k); printf (" how = %-11s", [how ","]); printf ("nf = %3.0f, f = %9.4e (%2.1f%%)\n", nf, dirn * fmax, ... - 100*(fmax-fmax_old)/(abs(fmax_old)+eps)); + 100*(fmax-fmax_old)/(abs (fmax_old)+eps)); endif fmax_old = fmax; @@ -578,5 +579,5 @@ %! fminsearch (@(x) (Inf), 0, optimset ("FunValCheck", "on")); ## Test input validation -%!error fminsearch () +%!error <Invalid call> fminsearch () %!error fminsearch (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/fminunc.m --- a/scripts/optimization/fminunc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/fminunc.m Thu Nov 19 13:08:00 2020 -0800 @@ -70,7 +70,8 @@ ## @var{x}, while @qcode{"TolFun"} is a tolerance for the objective function ## value @var{fval}. The default is @code{1e-6} for both options. ## -## For a description of the other options, see @code{optimset}. +## For a description of the other options, +## @pxref{XREFoptimset,,@code{optimset}}. ## ## On return, @var{x} is the location of the minimum and @var{fval} contains ## the value of the objective function at @var{x}. @@ -128,7 +129,7 @@ return; endif - if (nargin < 2 || nargin > 3 || ! isnumeric (x0)) + if (nargin < 2 || ! isnumeric (x0)) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/fsolve.m --- a/scripts/optimization/fsolve.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/fsolve.m Thu Nov 19 13:08:00 2020 -0800 @@ -78,8 +78,9 @@ ## while @qcode{"TolFun"} is a tolerance for equations. Default is @code{1e-6} ## for both @qcode{"TolX"} and @qcode{"TolFun"}. ## -## For a description of the other options, see @code{optimset}. To initialize -## an options structure with default values for @code{fsolve} use +## For a description of the other options, +## @pxref{XREFoptimset,,@code{optimset}}. To initialize an options structure +## with default values for @code{fsolve} use ## @code{options = optimset ("fsolve")}. ## ## The first output @var{x} is the solution while the second output @var{fval} @@ -186,7 +187,7 @@ return; endif - if (nargin < 2 || nargin > 3 || ! isnumeric (x0)) + if (nargin < 2 || ! isnumeric (x0)) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/fzero.m --- a/scripts/optimization/fzero.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/fzero.m Thu Nov 19 13:08:00 2020 -0800 @@ -134,7 +134,7 @@ return; endif - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/glpk.m --- a/scripts/optimization/glpk.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/glpk.m Thu Nov 19 13:08:00 2020 -0800 @@ -485,7 +485,7 @@ function [xopt, fmin, errnum, extra] = glpk (c, A, b, lb, ub, ctype, vartype, sense, param) ## If there is no input output the version and syntax - if (nargin < 3 || nargin > 9) + if (nargin < 3) print_usage (); endif @@ -667,9 +667,9 @@ %! assert (fmin, c' * xmin); %! assert (A * xmin, b); -%!error<C .* finite values> glpk(NaN, 2, 3) -%!error<A must be finite> glpk(1, NaN, 3) -%!error<B must be finite> glpk(1, 2, NaN) -%!error<LB must be a real-valued> glpk(1, 2, 3, NaN) -%!error<UB must be a real-valued> glpk(1, 2, 3, 4, NaN) -%!error<SENSE must be .* integer> glpk(1, 2, 3, 4, 5, "F", "C", NaN) +%!error <C .* finite values> glpk (NaN, 2, 3) +%!error <A must be finite> glpk (1, NaN, 3) +%!error <B must be finite> glpk (1, 2, NaN) +%!error <LB must be a real-valued> glpk (1, 2, 3, NaN) +%!error <UB must be a real-valued> glpk (1, 2, 3, 4, NaN) +%!error <SENSE must be .* integer> glpk (1, 2, 3, 4, 5, "F", "C", NaN) diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/humps.m --- a/scripts/optimization/humps.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/humps.m Thu Nov 19 13:08:00 2020 -0800 @@ -63,10 +63,6 @@ function [x, y] = humps (x = [0:0.05:1]) - if (nargin > 1) - print_usage (); - endif - y = - 4*( 300*x.^4 - 720*x.^3 + 509*x.^2 - 87*x - 22) ./ ... ((10*x.^2 - 6*x + 1).*(20*x.^2 - 36*x + 17)); diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/lsqnonneg.m --- a/scripts/optimization/lsqnonneg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/lsqnonneg.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,8 +41,8 @@ ## @var{x0} is an optional initial guess for the solution @var{x}. ## ## @var{options} is an options structure to change the behavior of the -## algorithm (@pxref{XREFoptimset,,optimset}). @code{lsqnonneg} recognizes -## these options: @qcode{"MaxIter"}, @qcode{"TolX"}. +## algorithm (@pxref{XREFoptimset,,@code{optimset}}). @code{lsqnonneg} +## recognizes these options: @qcode{"MaxIter"}, @qcode{"TolX"}. ## ## Outputs: ## @@ -91,7 +91,7 @@ return; endif - if (nargin < 2 || nargin > 4) + if (nargin < 2) print_usage (); endif @@ -237,10 +237,9 @@ %! xnew = [0;0.6929]; %! assert (lsqnonneg (C, d), xnew, 0.0001); -# Test input validation -%!error lsqnonneg () -%!error lsqnonneg (1) -%!error lsqnonneg (1,2,3,4,5) +## Test input validation +%!error <Invalid call> lsqnonneg () +%!error <Invalid call> lsqnonneg (1) %!error <C .* must be numeric matrices> lsqnonneg ({1},2) %!error <C .* must be numeric matrices> lsqnonneg (ones (2,2,2),2) %!error <D must be numeric matrices> lsqnonneg (1,{2}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/module.mk --- a/scripts/optimization/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -6,6 +6,7 @@ %reldir%/private/__fdjac__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/__all_opts__.m \ %reldir%/fminbnd.m \ %reldir%/fminsearch.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/optimget.m --- a/scripts/optimization/optimget.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/optimget.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function retval = optimget (options, parname, default) - if (nargin < 2 || nargin > 4 || ! isstruct (options) || ! ischar (parname)) + if (nargin < 2 || ! isstruct (options) || ! ischar (parname)) print_usage (); endif @@ -75,9 +75,8 @@ %!assert (optimget (opts, "TolFun", 1e-3), 1e-3) ## Test input validation -%!error optimget () -%!error optimget (1) -%!error optimget (1,2,3,4,5) +%!error <Invalid call> optimget () +%!error <Invalid call> optimget (1) %!error optimget (1, "name") %!error optimget (struct (), 2) %!warning <unrecognized option: foobar> (optimget (opts, "foobar")); diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/optimset.m --- a/scripts/optimization/optimset.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/optimset.m Thu Nov 19 13:08:00 2020 -0800 @@ -199,6 +199,7 @@ endfunction + %!assert (isfield (optimset (), "TolFun")) %!assert (isfield (optimset ("tolFun", 1e-3), "TolFun")) %!assert (optimget (optimset ("tolx", 1e-2), "tOLx"), 1e-2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/pqpnonneg.m --- a/scripts/optimization/pqpnonneg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/pqpnonneg.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,8 +41,8 @@ ## @var{x0} is an optional initial guess for the solution @var{x}. ## ## @var{options} is an options structure to change the behavior of the -## algorithm (@pxref{XREFoptimset,,optimset}). @code{pqpnonneg} recognizes -## one option: @qcode{"MaxIter"}. +## algorithm (@pxref{XREFoptimset,,@code{optimset}}). @code{pqpnonneg} +## recognizes one option: @qcode{"MaxIter"}. ## ## Outputs: ## @@ -93,7 +93,7 @@ return; endif - if (nargin < 2 || nargin > 4) + if (nargin < 2) print_usage (); endif @@ -239,10 +239,9 @@ %! d = rand (20, 1); %! assert (pqpnonneg (C'*C, -C'*d), lsqnonneg (C, d), 100*eps); -# Test input validation -%!error pqpnonneg () -%!error pqpnonneg (1) -%!error pqpnonneg (1,2,3,4,5) +## Test input validation +%!error <Invalid call> pqpnonneg () +%!error <Invalid call> pqpnonneg (1) %!error <C .* must be numeric matrices> pqpnonneg ({1},2) %!error <C .* must be numeric matrices> pqpnonneg (ones (2,2,2),2) %!error <D must be numeric matrices> pqpnonneg (1,{2}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/qp.m --- a/scripts/optimization/qp.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/qp.m Thu Nov 19 13:08:00 2020 -0800 @@ -273,8 +273,8 @@ endif ## Validate inequality constraints. - if (nargs > 7 && isempty (A_in) && ! (isempty(A_lb) || isempty(A_ub))) - warning("qp: empty inequality constraint matrix but non-empty bound vectors"); + if (nargs > 7 && isempty (A_in) && ! (isempty (A_lb) || isempty (A_ub))) + warning ("qp: empty inequality constraint matrix but non-empty bound vectors"); endif if (nargs > 7 && ! isempty (A_in)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/optimization/sqp.m --- a/scripts/optimization/sqp.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/optimization/sqp.m Thu Nov 19 13:08:00 2020 -0800 @@ -29,7 +29,7 @@ ## @deftypefnx {} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}) ## @deftypefnx {} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}, @var{lb}, @var{ub}) ## @deftypefnx {} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}, @var{lb}, @var{ub}, @var{maxiter}) -## @deftypefnx {} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}, @var{lb}, @var{ub}, @var{maxiter}, @var{tol}) +## @deftypefnx {} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}, @var{lb}, @var{ub}, @var{maxiter}, @var{tolerance}) ## Minimize an objective function using sequential quadratic programming (SQP). ## ## Solve the nonlinear program @@ -127,7 +127,7 @@ ## The seventh argument @var{maxiter} specifies the maximum number of ## iterations. The default value is 100. ## -## The eighth argument @var{tol} specifies the tolerance for the stopping +## The eighth argument @var{tolerance} specifies the tolerance for the stopping ## criteria. The default value is @code{sqrt (eps)}. ## ## The value returned in @var{info} may be one of the following: @@ -197,7 +197,7 @@ globals = struct (); # data and handles, needed and changed by subfunctions - if (nargin < 2 || nargin > 8 || nargin == 5) + if (nargin < 2 || nargin == 5) print_usage (); endif @@ -297,7 +297,7 @@ if (isa (x0, "single")) globals.lb = tmp_lb = -realmax ("single"); else - globals.lb = tmp_lb = -realmax; + globals.lb = tmp_lb = -realmax (); endif else error ("sqp: invalid lower bound"); @@ -312,7 +312,7 @@ if (isa (x0, "single")) globals.ub = tmp_ub = realmax ("single"); else - globals.ub = tmp_ub = realmax; + globals.ub = tmp_ub = realmax (); endif else error ("sqp: invalid upper bound"); @@ -390,8 +390,8 @@ info = 0; iter = 0; - # report (); # Called with no arguments to initialize reporting - # report (iter, qp_iter, alpha, __sqp_nfun__, obj); + ## report (); # Called with no arguments to initialize reporting + ## report (iter, qp_iter, alpha, __sqp_nfun__, obj); while (++iter < iter_max) @@ -533,7 +533,7 @@ A = A_new; - # report (iter, qp_iter, alpha, __sqp_nfun__, obj); + ## report (iter, qp_iter, alpha, __sqp_nfun__, obj); endwhile @@ -776,10 +776,9 @@ %! assert (obj, obj_opt, sqrt (eps)); ## Test input validation -%!error sqp () -%!error sqp (1) -%!error sqp (1,2,3,4,5,6,7,8,9) -%!error sqp (1,2,3,4,5) +%!error <Invalid call> sqp () +%!error <Invalid call> sqp (1) +%!error <Invalid call> sqp (1,2,3,4,5) %!error sqp (ones (2,2)) %!error sqp (1, cell (4,1)) %!error sqp (1, cell (3,1), cell (3,1)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/path/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/path/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/path/import.m --- a/scripts/path/import.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/path/import.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,4 +65,4 @@ endfunction -%!error <not yet implemented> import ("foobar"); +%!error <not yet implemented> import ("foobar") diff -r dc3ee9616267 -r fa2cdef14442 scripts/path/matlabroot.m --- a/scripts/path/matlabroot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/path/matlabroot.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function retval = matlabroot () - retval = OCTAVE_HOME; + retval = OCTAVE_HOME (); endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/path/module.mk --- a/scripts/path/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/path/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -6,6 +6,7 @@ %reldir%/private/getsavepath.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/import.m \ %reldir%/matlabroot.m \ %reldir%/pathdef.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/path/pathdef.m --- a/scripts/path/pathdef.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/path/pathdef.m Thu Nov 19 13:08:00 2020 -0800 @@ -44,10 +44,6 @@ function val = pathdef () - if (nargin > 0) - print_usage (); - endif - ## Locate any project-specific .octaverc file. proj_octaverc = fullfile (pwd, ".octaverc"); if (exist (proj_octaverc, "file")) @@ -112,10 +108,10 @@ %! addpath (tmp_dir); %! p1 = path (); %! p2 = pathdef (); -%! assert (! isempty (strfind (p1, tmp_dir))) -%! assert (isempty (strfind (p2, tmp_dir))) +%! assert (! isempty (strfind (p1, tmp_dir))); +%! assert (isempty (strfind (p2, tmp_dir))); %! unwind_protect_cleanup -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! path (path_orig); %! end_unwind_protect @@ -130,9 +126,9 @@ %! path_1 = path (); %! p = pathdef (); %! path_2 = path (); -%! assert (path_1, path_2) +%! assert (path_1, path_2); %! unwind_protect_cleanup -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! path (path_orig); %! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/path/savepath.m --- a/scripts/path/savepath.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/path/savepath.m Thu Nov 19 13:08:00 2020 -0800 @@ -201,7 +201,7 @@ %! endif %! status = savepath (fname); %! assert (status == 0); -%! old_dir = pwd; +%! old_dir = pwd (); %! unwind_protect %! cd (test_dir); %! if (exist (fullfile (pwd, ".octaverc"))) @@ -230,6 +230,6 @@ %! end_unwind_protect %! unwind_protect_cleanup %! confirm_recursive_rmdir (false, "local"); -%! rmdir (test_dir, "s"); +%! sts = rmdir (test_dir, "s"); %! unlink (fname); %! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/pkg/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/module.mk --- a/scripts/pkg/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -28,7 +28,9 @@ %reldir%/private/uninstall.m \ %reldir%/private/unload_packages.m -%canon_reldir%_FCN_FILES = %reldir%/pkg.m +%canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ + %reldir%/pkg.m %canon_reldir%dir = $(fcnfiledir)/pkg diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/pkg.m --- a/scripts/pkg/pkg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/pkg.m Thu Nov 19 13:08:00 2020 -0800 @@ -406,7 +406,7 @@ confirm_recursive_rmdir (false, "local"); - # valid actions in alphabetical order + ## valid actions in alphabetical order available_actions = {"build", "describe", "global_list", "install", ... "list", "load", "local_list", "prefix", "rebuild", ... "test", "uninstall", "unload", "update"}; @@ -569,9 +569,9 @@ global_list, global_install); unwind_protect_cleanup - cellfun ("unlink", local_files); + [~] = cellfun ("unlink", local_files); if (exist (tmp_dir, "file")) - rmdir (tmp_dir, "s"); + [~] = rmdir (tmp_dir, "s"); endif end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/build.m --- a/scripts/pkg/private/build.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/build.m Thu Nov 19 13:08:00 2020 -0800 @@ -91,11 +91,11 @@ tar (tar_path, package_root, builddir); gzip (tar_path, builddir); - rmdir (build_root, "s"); + [~] = rmdir (build_root, "s"); ## Currently does nothing because gzip() removes the original tar ## file but that should change in the future (bug #43431). - unlink (tar_path); + [~] = unlink (tar_path); endfor endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/configure_make.m --- a/scripts/pkg/private/configure_make.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/configure_make.m Thu Nov 19 13:08:00 2020 -0800 @@ -88,9 +88,9 @@ cmd = ["cd '" src "'; " scenv " ./configure " flags]; [status, output] = shell (cmd, verbose); if (status != 0) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); disp (output); - error ("pkg: error running the configure script for %s.", desc.name); + error ("pkg: error running the configure script for %s", desc.name); endif endif @@ -105,9 +105,9 @@ [status, output] = shell (sprintf ("%s make --jobs %i --directory '%s'", scenv, jobs, src), verbose); if (status != 0) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); disp (output); - error ("pkg: error running 'make' for the %s package.", desc.name); + error ("pkg: error running 'make' for the %s package", desc.name); endif endif @@ -169,7 +169,7 @@ if (have_sh) cmd = ['sh.exe -c "' cmd '"']; else - error ("pkg: unable to find the command shell."); + error ("pkg: unable to find the command shell"); endif endif ## if verbose, we want to display the output in real time. To do this, we diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/default_prefix.m --- a/scripts/pkg/private/default_prefix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/default_prefix.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,10 +24,11 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {[@var{prefix}, @var{archprefix} =} default_prefix (@var{global_install}) +## @deftypefn {} {[@var{prefix}, @var{archprefix} =} default_prefix (@var{global_install}, @var{desc}) ## Undocumented internal function. ## @end deftypefn +## FIXME: second input "desc" does not appear to be used. function [prefix, archprefix] = default_prefix (global_install, desc) if (global_install) diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/expand_rel_paths.m --- a/scripts/pkg/private/expand_rel_paths.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/expand_rel_paths.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,18 +5,23 @@ ## See the file COPYRIGHT.md in the top-level directory of this ## distribution or <https://octave.org/copyright/>. ## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program. If not, see <https://www.gnu.org/licenses/>. +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## ## -*- texinfo -*- ## @deftypefn {} {@var{pkg_list} =} expand_rel_paths (@var{pkg_list}) @@ -26,7 +31,7 @@ function pkg_list = expand_rel_paths (pkg_list) ## Prepend location of OCTAVE_HOME to install directories - loc = OCTAVE_HOME; + loc = OCTAVE_HOME (); for i = 1:numel (pkg_list) ## Be sure to only prepend OCTAVE_HOME to pertinent package paths if (strncmpi (pkg_list{i}.dir, "__OH__", 6)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/get_forge_pkg.m --- a/scripts/pkg/private/get_forge_pkg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/get_forge_pkg.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ name)); if (succ) ## Remove blanks for simpler matching. - html(isspace(html)) = []; + html(isspace (html)) = []; ## Good. Let's grep for the version. pat = "<tdclass=""package_table"">PackageVersion:</td><td>([\\d.]*)</td>"; t = regexp (html, pat, "tokens"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/install.m --- a/scripts/pkg/private/install.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/install.m Thu Nov 19 13:08:00 2020 -0800 @@ -145,7 +145,7 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor rethrow (lasterror ()); end_try_catch @@ -199,7 +199,7 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor rethrow (lasterror ()); end_try_catch @@ -218,7 +218,7 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor rethrow (lasterror ()); end_try_catch @@ -237,11 +237,11 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor for i = 1:length (descriptions) - rmdir (descriptions{i}.dir, "s"); - rmdir (getarchdir (descriptions{i}), "s"); + sts = rmdir (descriptions{i}.dir, "s"); + sts = rmdir (getarchdir (descriptions{i}), "s"); endfor rethrow (lasterror ()); end_try_catch @@ -252,8 +252,8 @@ if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) && dirempty (getarchdir (descriptions{i}))) warning ("package %s is empty\n", descriptions{i}.name); - rmdir (descriptions{i}.dir, "s"); - rmdir (getarchdir (descriptions{i}), "s"); + sts = rmdir (descriptions{i}.dir, "s"); + sts = rmdir (getarchdir (descriptions{i}), "s"); descriptions(i) = []; endif endfor @@ -282,10 +282,10 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor for i = 1:length (descriptions) - rmdir (descriptions{i}.dir, "s"); + sts = rmdir (descriptions{i}.dir, "s"); endfor if (global_install) printf ("error: couldn't append to %s\n", global_list); @@ -376,7 +376,7 @@ if (! isfolder (inst_dir)) [status, msg] = mkdir (inst_dir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("the 'inst' directory did not exist and could not be created: %s", msg); endif @@ -389,7 +389,7 @@ src = fullfile (packdir, "src"); if (! isfolder (src)) - return + return; endif ## Copy files to "inst" and "inst/arch" (this is instead of 'make install'). @@ -451,7 +451,7 @@ endif [status, output] = copyfile (archindependent, instdir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("Couldn't copy files from 'src' to 'inst': %s", output); endif endif @@ -466,7 +466,7 @@ endif [status, output] = copyfile (archdependent, archdir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("Couldn't copy files from 'src' to 'inst': %s", output); endif endif @@ -509,7 +509,7 @@ [status, output] = mkdir (desc.dir); if (status != 1) error ("couldn't create installation directory %s : %s", - desc.dir, output); + desc.dir, output); endif endif @@ -520,7 +520,7 @@ if (! dirempty (instdir)) [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't copy files to the installation directory"); endif if (isfolder (fullfile (desc.dir, getarch ())) @@ -535,39 +535,39 @@ if (! isfolder (octm3)) [status, output] = mkdir (octm3); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", octm3, output); endif endif [status, output] = mkdir (octm2); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", octm2, output); endif endif [status, output] = mkdir (octm1); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", octm1, output); endif endif [status, output] = mkdir (octfiledir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", - octfiledir, output); + octfiledir, output); endif endif [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), octfiledir); - rmdir (fullfile (desc.dir, getarch ()), "s"); + sts = rmdir (fullfile (desc.dir, getarch ()), "s"); if (status != 1) - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); error ("couldn't copy files to the installation directory"); endif endif @@ -578,8 +578,8 @@ packinfo = fullfile (desc.dir, "packinfo"); [status, msg] = mkdir (packinfo); if (status != 1) - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); error ("couldn't create packinfo directory: %s", msg); endif @@ -599,8 +599,8 @@ write_index (desc, fullfile (packdir, "inst"), fullfile (packinfo, "INDEX"), global_install); catch - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); rethrow (lasterror ()); end_try_catch endif @@ -632,8 +632,8 @@ else [status, output] = copyfile (filepath, packinfo); if (status != 1) - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); error ("Couldn't copy %s file: %s", filename, output); endif endif @@ -721,8 +721,8 @@ ## part in the main directory. archdir = fullfile (getarchprefix (desc, global_install), [desc.name "-" desc.version], getarch ()); - if (isfolder (getarchdir (desc, global_install))) - archpkg = fullfile (getarchdir (desc, global_install), nm); + if (isfolder (getarchdir (desc))) + archpkg = fullfile (getarchdir (desc), nm); archfid = fopen (archpkg, "at"); else archpkg = instpkg; @@ -804,8 +804,8 @@ cd (wd); catch cd (wd); - rmdir (desc.dir, "s"); - rmdir (getarchdir (desc), "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (getarchdir (desc), "s"); rethrow (lasterror ()); end_try_catch endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/installed_packages.m --- a/scripts/pkg/private/installed_packages.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/installed_packages.m Thu Nov 19 13:08:00 2020 -0800 @@ -134,8 +134,8 @@ header = sprintf ("%s | %s | %s\n", h1, h2, h3); printf (header); tmp = sprintf (repmat ("-", 1, length (header) - 1)); - tmp(length(h1)+2) = "+"; - tmp(length(h1)+length(h2)+5) = "+"; + tmp(length (h1)+2) = "+"; + tmp(length (h1)+length (h2)+5) = "+"; printf ("%s\n", tmp); ## Print the packages. diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/load_packages_and_dependencies.m --- a/scripts/pkg/private/load_packages_and_dependencies.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/load_packages_and_dependencies.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,6 +61,11 @@ EXEC_PATH (execpath); endif + ## Update lexer for autocompletion if necessary + if (isguirunning && (length (idx) > 0)) + __event_manager_update_gui_lexer__; + endif + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/uninstall.m --- a/scripts/pkg/private/uninstall.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/uninstall.m Thu Nov 19 13:08:00 2020 -0800 @@ -32,8 +32,8 @@ global_list, global_install) ## Get the list of installed packages. - [local_packages, global_packages] = installed_packages(local_list, - global_list); + [local_packages, global_packages] = installed_packages (local_list, + global_list); if (global_install) installed_pkgs_lst = {local_packages{:}, global_packages{:}}; else @@ -122,6 +122,11 @@ endif endif if (isfolder (desc.dir)) + ## FIXME: If first call to rmdir fails, then error() will + ## stop further processing of getarchdir & archprefix. + ## If this is, in fact, correct, then calls should + ## just be shortened to rmdir (...) and let rmdir() + ## report failure and reason for failure. [status, msg] = rmdir (desc.dir, "s"); if (status != 1 && isfolder (desc.dir)) error ("couldn't delete directory %s: %s", desc.dir, msg); @@ -131,7 +136,7 @@ error ("couldn't delete directory %s: %s", getarchdir (desc), msg); endif if (dirempty (desc.archprefix)) - rmdir (desc.archprefix, "s"); + sts = rmdir (desc.archprefix, "s"); endif else warning ("directory %s previously lost", desc.dir); @@ -140,8 +145,8 @@ ## Write a new ~/.octave_packages. if (global_install) - if (length (remaining_packages) == 0) - unlink (global_list); + if (numel (remaining_packages) == 0) + [~] = unlink (global_list); else global_packages = save_order (remaining_packages); if (ispc) @@ -152,8 +157,8 @@ save (global_list, "global_packages"); endif else - if (length (remaining_packages) == 0) - unlink (local_list); + if (numel (remaining_packages) == 0) + [~] = unlink (local_list); else local_packages = save_order (remaining_packages); if (ispc) diff -r dc3ee9616267 -r fa2cdef14442 scripts/pkg/private/unload_packages.m --- a/scripts/pkg/private/unload_packages.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/pkg/private/unload_packages.m Thu Nov 19 13:08:00 2020 -0800 @@ -100,6 +100,9 @@ if (any (idx)) rmpath (d); ## FIXME: We should also check if we need to remove items from EXEC_PATH. + if (isguirunning) + __event_manager_update_gui_lexer__; + endif endif endfor diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/appearance/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/annotation.m --- a/scripts/plot/appearance/annotation.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/annotation.m Thu Nov 19 13:08:00 2020 -0800 @@ -217,9 +217,8 @@ ## options opts = varargin; - nopts = numel (opts); if (! isempty (opts)) - if (fix (nopts/2) != nopts/2 || ! all (cellfun (@ischar, opts(1:2:end)))) + if (mod (numel (opts), 2) != 0 || ! all (cellfun (@ischar, opts(1:2:end)))) warning ("annotation: couldn't parse PROP/VAL pairs, skipping"); opts = {}; endif @@ -277,7 +276,7 @@ listener = {@update_figsize_points, hax}; addlistener (hf, "position", listener); - delfcn = @() dellistener (hf, "position", listener); + delfcn = @(~, ~) dellistener (hf, "position", listener); set (hax, "deletefcn", delfcn); endfunction @@ -329,7 +328,7 @@ addlistener (hax, "figsize_points", listener); - delfcn = @() dellistener (hax, "figsize_points", listener); + delfcn = @(~, ~) dellistener (hax, "figsize_points", listener); set (h, "deletefcn", delfcn); addlistener (h, "units", {@update_position, h}); @@ -832,7 +831,10 @@ proptable(1:3:end), proptable(2:3:end), proptable(3:3:end)); endfunction -function addbasemenu (hm, hpar, pname, vals, mainlabel = "") +## FIXME: there are some calls to addbasemenu with option-like arguments +## but we don't do anything with varargin here. What is the right thing +## to do? +function addbasemenu (hm, hpar, pname, vals, mainlabel = "", varargin) if (isempty (mainlabel)) mainlabel = pname; @@ -1131,7 +1133,7 @@ function XY = textcoordinates (hte, pos) ## Get the "tight" extent of the text object in points units - textpos = get(hte, "position"); + textpos = get (hte, "position"); rot = get (hte, "rotation"); units = get (hte, "units"); @@ -1451,8 +1453,8 @@ %! xl = xlim (); %! yl = [-1.2 1.5]; %! ylim (yl); -%! x0 = (x0 - xl(1)) / diff(xl); -%! y0 = (y0 - yl(1)) / diff(yl); +%! x0 = (x0 - xl(1)) / diff (xl); +%! y0 = (y0 - yl(1)) / diff (yl); %! %! pos = get (gca (), "position"); %! x0 = x0*pos(3) + pos(1); @@ -1575,7 +1577,7 @@ %! end_unwind_protect ## Test input validation -%!error annotation () +%!error <Invalid call> annotation () %!error <Invalid call to annotation> annotation ({"line"}, 1:2, 1:2) %!error <X and Y must be 2-element vectors> annotation ("line", {1:2}, 1:2) %!error <X and Y must be 2-element vectors> annotation ("line", 1:2, {1:2}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/axis.m --- a/scripts/plot/appearance/axis.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/axis.m Thu Nov 19 13:08:00 2020 -0800 @@ -54,14 +54,20 @@ ## The following options control the aspect ratio of the axes. ## ## @table @asis +## @item @qcode{"equal"} +## Force x-axis unit distance to equal y-axis (and z-axis) unit distance. +## ## @item @qcode{"square"} ## Force a square axis aspect ratio. ## -## @item @qcode{"equal"} -## Force x-axis unit distance to equal y-axis (and z-axis) unit distance. +## @item @nospell{@qcode{"vis3d"}} +## Set aspect ratio modes (@qcode{"DataAspectRatio"}, +## @qcode{"PlotBoxAspectRatio"}) to @qcode{"manual"} for rotation without +## stretching. ## -## @item @qcode{"normal"} -## Restore default aspect ratio. +## @item @qcode{"normal"} +## @itemx @qcode{"fill"} +## Restore default automatically computed aspect ratios. ## @end table ## ## @noindent @@ -83,8 +89,6 @@ ## @item @qcode{"image"} ## Equivalent to @qcode{"tight"} and @qcode{"equal"}. ## -## @item @nospell{@qcode{"vis3d"}} -## Set aspect ratio modes to @qcode{"manual"} for rotation without stretching. ## @end table ## ## @noindent @@ -250,7 +254,7 @@ ## Fix aspect ratio modes for rotation without stretching. set (ca, "dataaspectratiomode", "manual", "plotboxaspectratiomode", "manual"); - elseif (strcmpi (opt, "normal")) + elseif (strcmpi (opt, "normal") || strcmpi (opt, "fill")) ## Set plotboxaspectratio to something obtuse so that switching ## back to "auto" will force a re-calculation. set (ca, "plotboxaspectratio", [3 2 1]); @@ -369,6 +373,7 @@ endif endfor + endfunction ## Find the limits for axis ("tight"). @@ -583,14 +588,14 @@ %! axis ("autoy"); %! %! subplot (326); -%! plot (t, sin(t), t, -2*sin(t/2)); +%! plot (t, sin (t), t, -2*sin (t/2)); %! axis ("tight"); %! title ("tight"); %!demo %! clf; %! x = 0:0.1:10; -%! plot (x, sin(x)); +%! plot (x, sin (x)); %! axis image; %! title ({"image", 'equivalent to "tight" & "equal"'}); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/camlookat.m --- a/scripts/plot/appearance/camlookat.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/camlookat.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,18 +35,18 @@ ## the bounding box approximately fills the field of view. ## ## This command fixes the camera's viewing direction -## (@code{camtarget() - campos()}), camera up vector (@pxref{XREFcamup,,camup}) -## and viewing angle (@pxref{XREFcamva,,camva}). The camera target -## (@pxref{XREFcamtarget,,camtarget}) and camera position -## (@pxref{XREFcampos,,campos}) are changed. -## +## (@code{camtarget() - campos()}), camera up vector +## (@pxref{XREFcamup,,@code{camup}}) and viewing angle +## (@pxref{XREFcamva,,@code{camva}}). The camera target +## (@pxref{XREFcamtarget,,@code{camtarget}}) and camera position +## (@pxref{XREFcampos,,@code{campos}}) are changed. ## ## If the argument is a list @var{handle_list}, then a single bounding box for ## all the objects is computed and the camera is then adjusted as above. ## ## If the argument is an axis object @var{hax}, then the children of the axis ## are used as @var{handle_list}. When called with no inputs, it uses the -## current axis (@pxref{XREFgca,,gca}). +## current axis (@pxref{XREFgca,,@code{gca}}). ## ## @seealso{camorbit, camzoom, camroll} ## @end deftypefn @@ -54,10 +54,6 @@ function camlookat (hh) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) hax = gca (); hh = get (hax, "children"); @@ -67,26 +63,26 @@ hh = get (hax, "children"); elseif (all (ishghandle (hh))) hax = ancestor (hh, "axes"); - if numel (hax) > 1 + if (numel (hax) > 1) hax = unique ([hax{:}]); endif if (numel (hax) > 1) - error ("camlookat: HANDLE_LIST must be children of the same axes."); + error ("camlookat: HANDLE_LIST must be children of the same axes"); endif endif endif if (isempty (hh)) - return - end + return; + endif x0 = x1 = y0 = y1 = z0 = z1 = []; for i = 1:numel (hh) h = hh(i); if (! ishghandle (h)) - error ("camlookat: Inputs must be handles."); - end + error ("camlookat: Inputs must be handles"); + endif x0_ = min (get (h, "xdata")(:)); x1_ = max (get (h, "xdata")(:)); @@ -206,7 +202,7 @@ %! camlookat (h2); %! dir2 = camtarget () - campos (); %! dir2 /= norm (dir2); -%! assert (dir, dir2, -2*eps) +%! assert (dir, dir2, -2*eps); %! camlookat ([h1 h2]); %! dir2 = camtarget () - campos (); %! dir2 /= norm (dir2); @@ -313,7 +309,7 @@ %! end_unwind_protect ## Test input validation -%!error <Invalid call> camlookat (1, 2) +%!error <called with too many inputs> camlookat (1, 2) %!error <must be handle> camlookat ("a") %!error <children of the same axes> %! hf = figure ("visible", "off"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/camorbit.m --- a/scripts/plot/appearance/camorbit.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/camorbit.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,11 +49,11 @@ ## @end example ## ## These rotations are centered around the camera target -## (@pxref{XREFcamtarget,,camtarget}). +## (@pxref{XREFcamtarget,,@code{camtarget}}). ## First the camera position is pitched up or down by rotating it @var{phi} ## degrees around an axis orthogonal to both the viewing direction ## (specifically @code{camtarget() - campos()}) and the camera ``up vector'' -## (@pxref{XREFcamup,,camup}). +## (@pxref{XREFcamup,,@code{camup}}). ## Example: ## ## @example @@ -81,7 +81,7 @@ ## ## When @var{coorsys} is set to @qcode{"camera"}, the camera is moved left or ## right by rotating it around an axis parallel to the camera up vector -## (@pxref{XREFcamup,,camup}). +## (@pxref{XREFcamup,,@code{camup}}). ## The input @var{dir} should not be specified in this case. ## Example: ## @@ -116,7 +116,7 @@ phi = varargin{2}; if (! (isnumeric (theta) && isscalar (theta) && isnumeric (phi) && isscalar (phi))) - error ("camorbit: THETA and PHI must be numeric scalars") + error ("camorbit: THETA and PHI must be numeric scalars"); endif if (nargin < 3) @@ -124,7 +124,7 @@ else coorsys = varargin{3}; if (! any (strcmpi (coorsys, {"data" "camera"}))) - error ("camorbit: COORSYS must be 'data' or 'camera'") + error ("camorbit: COORSYS must be 'data' or 'camera'"); endif endif @@ -132,13 +132,13 @@ dir = "z"; else if (strcmpi (coorsys, "camera")) - error ("camorbit: DIR must not be used with 'camera' COORSYS."); + error ("camorbit: DIR must not be used with 'camera' COORSYS"); endif dir = varargin{4}; endif if (ischar (dir)) - switch tolower (dir) + switch (tolower (dir)) case "x" dir = [1 0 0]; case "y" @@ -172,7 +172,7 @@ yaw_ax = up; else yaw_ax = dir; - end + endif ## First pitch up then yaw right (order matters) pos = num2cell (campos (hax)); @@ -219,7 +219,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! sphere (); -%! camorbit(20, 30, "camera") +%! camorbit (20, 30, "camera") %! p = campos (); %! u = camup (); %! ## Matlab 2008a diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/campos.m --- a/scripts/plot/appearance/campos.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/campos.m Thu Nov 19 13:08:00 2020 -0800 @@ -145,7 +145,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! sphere(); +%! sphere (); %! p_orig = campos (); %! m = campos ("mode"); %! assert (strcmp (m, "auto")); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/camup.m --- a/scripts/plot/appearance/camup.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/camup.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,8 +57,8 @@ ## @end example ## ## Modifying the up vector does not modify the camera target -## (@pxref{XREFcamtarget,,camtarget}). Thus, the camera up vector might not be -## orthogonal to the direction of the camera's view: +## (@pxref{XREFcamtarget,,@code{camtarget}}). Thus, the camera up vector might +## not be orthogonal to the direction of the camera's view: ## ## @example ## @group diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/camva.m --- a/scripts/plot/appearance/camva.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/camva.m Thu Nov 19 13:08:00 2020 -0800 @@ -135,7 +135,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! sphere(); +%! sphere (); %! a_orig = camva (); %! m = camva ("mode"); %! assert (strcmp (m, "auto")); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/camzoom.m --- a/scripts/plot/appearance/camzoom.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/camzoom.m Thu Nov 19 13:08:00 2020 -0800 @@ -114,14 +114,14 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! sphere(); +%! sphere (); %! x = camva (); %! camzoom (2); %! y = camva (); %! ## Matlab 2016a %! xm = 10.339584907201974; %! ym = 5.1803362845094822; -%! assert (tand (x/2) / tand (y/2), tand (xm/2) / tand (ym/2), 2e-14) +%! assert (tand (x/2) / tand (y/2), tand (xm/2) / tand (ym/2), 2e-14); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect @@ -138,7 +138,7 @@ %! ## Matlab 2014a %! xm = 13.074668029506947; %! ym = 2.6258806698721222; -%! assert (tand (x/2) / tand (y/2), tand (xm/2) / tand (ym/2), 2e-14) +%! assert (tand (x/2) / tand (y/2), tand (xm/2) / tand (ym/2), 2e-14); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect @@ -154,7 +154,7 @@ %! camzoom (hax1, 2) %! x = camva (hax1); %! y = camva (hax2); -%! assert (tand (y/2) / tand (x/2), 2, 2*eps) +%! assert (tand (y/2) / tand (x/2), 2, 2*eps); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/daspect.m --- a/scripts/plot/appearance/daspect.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/daspect.m Thu Nov 19 13:08:00 2020 -0800 @@ -104,7 +104,7 @@ %!demo %! clf; %! x = 0:0.01:4; -%! plot (x,cos(x), x,sin(x)); +%! plot (x,cos (x), x,sin (x)); %! axis square; %! daspect ([1 1 1]); %! title ("square plot box with axis limits [0, 4, -2, 2]"); @@ -120,7 +120,7 @@ %!demo %! clf; %! x = 0:0.01:4; -%! plot (x,cos(x), x,sin(x)); +%! plot (x,cos (x), x,sin (x)); %! daspect ([1 2 1]); %! pbaspect ([2 1 1]); %! title ("2x1 plot box with axis limits [0, 4, -2, 2]"); @@ -128,18 +128,18 @@ %!demo %! clf; %! x = 0:0.01:4; -%! plot (x,cos(x), x, sin(x)); +%! plot (x,cos (x), x, sin (x)); %! axis square; -%! set (gca, "activepositionproperty", "position"); +%! set (gca, "positionconstraint", "innerposition"); %! daspect ([1 1 1]); %! title ("square plot box with axis limits [0, 4, -2, 2]"); %!demo %! clf; %! x = 0:0.01:4; -%! plot (x,cos(x), x,sin(x)); +%! plot (x,cos (x), x,sin (x)); %! axis ([0 4 -1 1]); -%! set (gca, "activepositionproperty", "position"); +%! set (gca, "positionconstraint", "innerposition"); %! daspect ([2 1 1]); %! title ("square plot box with axis limits [0, 4, -1, 1]"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/datetick.m --- a/scripts/plot/appearance/datetick.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/datetick.m Thu Nov 19 13:08:00 2020 -0800 @@ -94,7 +94,7 @@ %! xlabel ("year"); %! ylabel ("average price"); %! title ("datetick() with MM/DD/YY format"); -%! ax = gca; +%! ax = gca (); %! set (ax, "xtick", datenum (1990:5:2005,1,1)); %! datetick ("x", 2, "keepticks"); %! set (ax, "ytick", 12:16); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/hidden.m --- a/scripts/plot/appearance/hidden.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/hidden.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,9 +48,7 @@ function state = hidden (mode = "toggle") - if (nargin > 2) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! ischar (mode)) error ("hidden: MODE must be a string"); elseif (! any (strcmpi (mode, {"on", "off"}))) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/legend.m --- a/scripts/plot/appearance/legend.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/legend.m Thu Nov 19 13:08:00 2020 -0800 @@ -195,7 +195,11 @@ ## Use the old legend code to handle gnuplot toolkit if (strcmp (graphics_toolkit (), "gnuplot")) - [hleg, hleg_obj, hplot, labels] = __gnuplot_legend__ (varargin{:}); + if (nargout > 0) + [hleg, hleg_obj, hplot, labels] = __gnuplot_legend__ (varargin{:}); + else + __gnuplot_legend__ (varargin{:}); + endif return; endif @@ -309,17 +313,17 @@ hf = ancestor (hax, "figure"); add_safe_listener (hl, hf, "colormap", ... - @() set (hl, "colormap", get (hax, "colormap"))); + @(~, ~) set (hl, "colormap", get (hax, "colormap"))); add_safe_listener (hl, hax, "position", {@maybe_update_layout_cb, hl}); add_safe_listener (hl, hax, "tightinset", ... - @(h) update_layout_cb (get (h, "__legend_handle__"))); + @(h, ~) update_layout_cb (get (h, "__legend_handle__"))); add_safe_listener (hl, hax, "clim", ... - @(hax) set (hl, "clim", get (hax, "clim"))); + @(hax, ~) set (hl, "clim", get (hax, "clim"))); add_safe_listener (hl, hax, "colormap", ... - @(hax) set (hl, "colormap", get (hax, "colormap"))); + @(hax, ~) set (hl, "colormap", get (hax, "colormap"))); add_safe_listener (hl, hax, "fontsize", ... - @(hax) set (hl, "fontsize", 0.9*get (hax, "fontsize"))); + @(hax, ~) set (hl, "fontsize", 0.9*get (hax, "fontsize"))); add_safe_listener (hl, hax, "children", {@legend_autoupdate_cb, hl}); ## Listeners to legend properties @@ -345,8 +349,8 @@ addlistener (hl, "string", @update_string_cb); addlistener (hl, "textcolor", ... - @(h) set (findobj (h, "type", "text"), ... - "color", get (hl, "textcolor"))); + @(h, ~) set (findobj (h, "type", "text"), ... + "color", get (hl, "textcolor"))); addlistener (hl, "visible", @update_visible_cb); @@ -378,7 +382,7 @@ endfunction -function update_box_cb (hl) +function update_box_cb (hl, ~) if (strcmp (get (hl, "box"), "on")) if (strcmp (get (hl, "color"), "none")) @@ -404,14 +408,14 @@ endfunction -function update_edgecolor_cb (hl) +function update_edgecolor_cb (hl, ~) ecolor = get (hl, "edgecolor"); set (hl, "xcolor", ecolor, "ycolor", ecolor); endfunction -function update_position_cb (hl) +function update_position_cb (hl, ~) updating = getappdata (hl, "__updating_layout__"); if (isempty (updating) || ! updating) @@ -420,7 +424,7 @@ endfunction -function update_string_cb (hl) +function update_string_cb (hl, ~) ## Check that the number of legend item and the number of labels match ## before calling update_layout_cb. @@ -454,7 +458,7 @@ endfunction -function update_visible_cb (hl) +function update_visible_cb (hl, ~) location = get (hl, "location"); if (strcmp (location(end:-1:end-3), "edis")) @@ -463,7 +467,7 @@ endfunction -function reset_cb (ht, evt, hl, deletelegend = true) +function reset_cb (ht, ~, hl, deletelegend = true) if (ishghandle (hl)) listeners = getappdata (hl, "__listeners__"); @@ -480,7 +484,7 @@ endfunction -function delete_legend_cb (hl) +function delete_legend_cb (hl, ~) reset_cb ([], [], hl, false); @@ -525,7 +529,7 @@ addproperty ("numcolumnsmode", hl, "radio", "{auto}|manual"); - addlistener (hl, "numcolumns", @(h) set (h, "numcolumnsmode", "manual")); + addlistener (hl, "numcolumns", @(h, ~) set (h, "numcolumnsmode", "manual")); addproperty ("autoupdate", hl, "radio", "{on}|off"); @@ -543,7 +547,7 @@ endfunction -function maybe_update_layout_cb (h, d, hl) +function maybe_update_layout_cb (h, ~, hl) persistent updating = false; @@ -569,7 +573,7 @@ endfunction -function update_numchild_cb (hl) +function update_numchild_cb (hl, ~) if (strcmp (get (hl, "autoupdate"), "on")) @@ -587,7 +591,7 @@ endfunction -function legend_autoupdate_cb (hax, d, hl) +function legend_autoupdate_cb (hax, ~, hl) ## Get all current children including eventual peer plotyy axes children try @@ -895,7 +899,7 @@ return; endif - setappdata(hl, "__updating_layout__", true); + setappdata (hl, "__updating_layout__", true); ## Scale limits so that item positions are expressed in points, from ## top to bottom and from left to right or reverse depending on textposition @@ -927,7 +931,7 @@ unwind_protect_cleanup set (hl, "units", units); - setappdata(hl, "__updating_layout__", false); + setappdata (hl, "__updating_layout__", false); end_unwind_protect endfunction @@ -1056,12 +1060,12 @@ safe_property_link (hplt(1), hicon, lprops); safe_property_link (hplt(end), hmarker, mprops); addlistener (hicon, "ydata", ... - @(h) set (hmarker, "ydata", get (h, "markerydata"))); + @(h, ~) set (hmarker, "ydata", get (h, "markerydata"))); addlistener (hicon, "xdata", ... - @(h) set (hmarker, "xdata", get (h, "markerxdata"))); + @(h, ~) set (hmarker, "xdata", get (h, "markerxdata"))); addlistener (hmarker, "markersize", @update_marker_cb); add_safe_listener (hl, hplt(1), "beingdeleted", - @() delete ([hicon hmarker])) + @(~, ~) delete ([hicon hmarker])) if (! strcmp (typ, "__errplot__")) setappdata (hicon, "__creator__", typ); else @@ -1099,11 +1103,11 @@ safe_property_link (hplt(1), hicon, pprops); safe_property_link (hplt(end), htmp, pprops); addlistener (hicon, "ydata", ... - @(h) set (htmp, "ydata", get (h, "innerydata"))); + @(h, ~) set (htmp, "ydata", get (h, "innerydata"))); addlistener (hicon, "xdata", ... - @(h) set (htmp, "xdata", get (h, "innerxdata"))); + @(h, ~) set (htmp, "xdata", get (h, "innerxdata"))); add_safe_listener (hl, hplt(1), "beingdeleted", - @() delete ([hicon htmp])) + @(~, ~) delete ([hicon htmp])) setappdata (hicon, "__creator__", typ); @@ -1119,9 +1123,9 @@ function safe_property_link (h1, h2, props) for ii = 1:numel (props) prop = props{ii}; - lsn = {h1, prop, @(h) set (h2, prop, get (h, prop))}; + lsn = {h1, prop, @(h, ~) set (h2, prop, get (h, prop))}; addlistener (lsn{:}); - addlistener (h2, "beingdeleted", @() dellistener (lsn{:})); + addlistener (h2, "beingdeleted", @(~, ~) dellistener (lsn{:})); endfor endfunction @@ -1143,7 +1147,7 @@ endfunction -function update_marker_cb (h) +function update_marker_cb (h, ~) if (get (h, "markersize") > 8) set (h, "markersize", 8); @@ -1237,7 +1241,7 @@ nrow = ceil (nitem / ncol); - colwidth = arrayfun (@(idx) max(ext(idx:ncol:end, 1)), + colwidth = arrayfun (@(idx) max (ext(idx:ncol:end, 1)), 1:ncol); y = vmargin; for ii = 1:nrow @@ -1347,12 +1351,13 @@ set (hicon, "markerxdata", x0, "markerydata", y0, ... "xdata", xdata, "ydata", ydata); case "__scatter__" - set (hicon, "xdata", mean(xdata), "ydata", mean(ydata)); + set (hicon, "xdata", mean (xdata), "ydata", mean (ydata)); case "__stem__" xdata(2) -= (get (get (hicon, "peer_object"), "markersize") / 2); set (hicon, "markerxdata", xdata(2), "markerydata", mean (ydata), ... "xdata", xdata, "ydata", [mean(ydata), mean(ydata)]); endswitch + endfunction function pos = boxposition (axpos, pba, pbam, dam) @@ -1749,7 +1754,7 @@ %!demo %! clf; %! x = 0:0.1:7; -%! h = plot (x,sin(x), x,cos(x), x,sin(x.^2/10), x,cos(x.^2/10)); +%! h = plot (x,sin (x), x,cos (x), x,sin (x.^2/10), x,cos (x.^2/10)); %! title ("Only the sin() objects have keylabels"); %! legend (h([1, 3]), {"sin (x)", "sin (x^2/10)"}, "location", "southwest"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/lighting.m --- a/scripts/plot/appearance/lighting.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/lighting.m Thu Nov 19 13:08:00 2020 -0800 @@ -184,10 +184,10 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! ha = axes; +%! ha = axes (); %! hm = mesh (sombrero ()); -%! hp = patch; -%! hs = surface; +%! hp = patch (); +%! hs = surface (); %! lighting flat %! assert (get (hp, "facelighting"), "flat"); %! assert (get (hs, "facelighting"), "flat"); @@ -225,7 +225,7 @@ %! close (hf); %! end_unwind_protect -%!error lighting () +%!error <Invalid call> lighting () %!error lighting (1, 2, "flat") %!error <MODE must be a string> lighting (-1) %!error <MODE must be a string> lighting ({}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/material.m --- a/scripts/plot/appearance/material.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/material.m Thu Nov 19 13:08:00 2020 -0800 @@ -227,8 +227,8 @@ %!test %! hf = figure ("Visible", "off"); %! unwind_protect -%! hp = patch; -%! hs = surface; +%! hp = patch (); +%! hs = surface (); %! material dull %! assert (get (hp, "ambientstrength"), 0.3); %! assert (get (hs, "ambientstrength"), 0.3); @@ -296,7 +296,7 @@ %!test %! refl_props = material ("metal"); -%! assert (refl_props, {0.3, 0.3, 1, 25, 0.5}) +%! assert (refl_props, {0.3, 0.3, 1, 25, 0.5}); ## Test input validation %!error <Invalid call to material> material () @@ -305,7 +305,7 @@ %!error <Invalid call to material> a = material (-1, 2) %!error <Invalid call to material> a = material ({}) %!error <Invalid call to material> a = material ([.3 .4 .5]) -%!error <Invalid call to material> [a, b] = material () +%!error <called with too many outputs> [a, b] = material () %!error <first argument must be a list of handles> material (-1, "metal") %!error <unknown material type 'foo'> material foo %!error <incorrect number of elements in material vector> material (-1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/module.mk --- a/scripts/plot/appearance/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -5,9 +5,11 @@ %canon_reldir%_PRIVATE_FCN_FILES = \ %reldir%/private/__axis_label__.m \ %reldir%/private/__axis_limits__.m \ - %reldir%/private/__gnuplot_legend__.m + %reldir%/private/__gnuplot_legend__.m \ + %reldir%/private/__tickangle__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/__clabel__.m \ %reldir%/__getlegenddata__.m \ %reldir%/__rotate_around_axis__.m \ @@ -45,15 +47,18 @@ %reldir%/whitebg.m \ %reldir%/xlabel.m \ %reldir%/xlim.m \ + %reldir%/xtickangle.m \ %reldir%/xticks.m \ %reldir%/xticklabels.m \ %reldir%/ylabel.m \ %reldir%/ylim.m \ %reldir%/yticks.m \ + %reldir%/ytickangle.m \ %reldir%/yticklabels.m \ %reldir%/zlabel.m \ %reldir%/zlim.m \ %reldir%/zticks.m \ + %reldir%/ztickangle.m \ %reldir%/zticklabels.m %canon_reldir%dir = $(fcnfiledir)/plot/appearance diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/pbaspect.m --- a/scripts/plot/appearance/pbaspect.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/pbaspect.m Thu Nov 19 13:08:00 2020 -0800 @@ -105,21 +105,21 @@ %!demo %! clf; %! x = 0:0.01:4; -%! plot (x,cos(x), x,sin(x)); +%! plot (x,cos (x), x,sin (x)); %! pbaspect ([1 1 1]); %! title ("plot box is square"); %!demo %! clf; %! x = 0:0.01:4;; -%! plot (x,cos(x), x,sin(x)); +%! plot (x,cos (x), x,sin (x)); %! pbaspect ([2 1 1]); %! title ("plot box aspect ratio is 2x1"); %!demo %! clf; %! x = 0:0.01:4; -%! plot (x,cos(x), x,sin(x)); +%! plot (x,cos (x), x,sin (x)); %! daspect ([1 1 1]); %! pbaspect ([2 1 1]); %! title ("plot box is 2x1, and axes [0 4 -1 1]"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/private/__gnuplot_legend__.m --- a/scripts/plot/appearance/private/__gnuplot_legend__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/private/__gnuplot_legend__.m Thu Nov 19 13:08:00 2020 -0800 @@ -623,7 +623,7 @@ "box", box, "xtick", [], "ytick", [], "xlim", [0, 1], "ylim", [0, 1], - "activepositionproperty", "position"); + "positionconstraint", "innerposition"); setappdata (hlegend, "__axes_handle__", ud); try addproperty ("__legend_handle__", ud(1), "handle", hlegend); @@ -1063,7 +1063,7 @@ ## This violates strict Matlab compatibility, but reliably ## renders an aesthetic result. set (ca(i), "position", unmodified_axes_position, - "activepositionproperty", "outerposition"); + "positionconstraint", "outerposition"); else ## numel (ca) > 1 for axes overlays (like plotyy) set (ca(i), "position", new_pos); @@ -1182,8 +1182,8 @@ outerposition = get (hleg, "unmodified_axes_outerposition"); units = get (hax, "units"); set (hax, "units", "points"); - switch (get (hax, "activepositionproperty")) - case "position" + switch (get (hax, "positionconstraint")) + case "innerposition" set (hax, "outerposition", outerposition, "position", position); case "outerposition" set (hax, "position", position, "outerposition", outerposition); @@ -1242,11 +1242,11 @@ endfunction ## The legend "location" property has changed. -function cb_legend_location (hleg, d) +function cb_legend_location (hleg, ~) - ## If it isn't "none", which means manual positioning, then rebuild . + ## If it isn't "none", which means manual positioning, then rebuild. if (! strcmp (get (hleg, "location"), "none")) - cb_legend_update (hleg, d); + cb_legend_update (hleg, []); endif endfunction @@ -1557,7 +1557,7 @@ %!demo %! clf; %! x = 0:0.1:7; -%! h = plot (x,sin(x), x,cos(x), x,sin(x.^2/10), x,cos(x.^2/10)); +%! h = plot (x,sin (x), x,cos (x), x,sin (x.^2/10), x,cos (x.^2/10)); %! title ("Only the sin() objects have keylabels"); %! legend (h([1, 3]), {"sin (x)", "sin (x^2/10)"}, "location", "southwest"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/private/__tickangle__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/appearance/private/__tickangle__.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,68 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{retval} =} __tickangle__ (@var{caller}, @var{hax}, @var{angle}) +## Undocumented internal function. +## @seealso{xtickangle, ytickangle, ztickangle} +## @end deftypefn + +function retval = __tickangle__ (caller, hax, angle) + + ax = tolower (caller(1)); + switch (nargin) + case 1 + retval = get (gca (), [ax, "ticklabelrotation"]); + return; + + case 2 + if (isaxes (hax)) + retval = get (hax, [ax, "ticklabelrotation"]); + return; + else + angle = hax; + hax = []; + endif + + case 3 + if (! isaxes (hax)) + error ([caller, ": HAX must be a handle to an axes object"]); + endif + + endswitch + + if (! (isscalar (angle) && isnumeric (angle) && isfinite (angle))) + error ([caller ": ANGLE must be a finite, numeric, scalar value"]); + elseif (nargout > 0) + error ([caller ": function called with output query and input set value"]); + endif + + if (isempty (hax)) + hax = gca (); + endif + + set (hax, [ax, "ticklabelrotation"], angle); + +endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/rticks.m --- a/scripts/plot/appearance/rticks.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/rticks.m Thu Nov 19 13:08:00 2020 -0800 @@ -120,7 +120,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! polar (linspace (0, pi, 20), rand (20,1)); -%! hax = gca; +%! hax = gca (); %! ticks = rticks; %! assert (rticks (hax), ticks); %! rticks (hax, [0 0.25 0.75 1 2]); @@ -135,7 +135,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! polar (linspace (0, pi, 20), 1:20); -%! hax = gca; +%! hax = gca (); %! fail ("rticks (-1, [0 1])", "HAX must be a handle to an axes"); %! fail ("tmp = rticks (hax, [0 1])", "too many output arguments"); %! fail ("tmp = rticks (hax, 'mode')", "MODE is not yet implemented"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/shading.m --- a/scripts/plot/appearance/shading.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/shading.m Thu Nov 19 13:08:00 2020 -0800 @@ -265,10 +265,10 @@ %!test %! hf = figure ("Visible", "off"); %! unwind_protect -%! ha = axes; +%! ha = axes (); %! hm = mesh (sombrero ()); -%! hp = patch; -%! hs = surface; +%! hp = patch (); +%! hs = surface (); %! shading interp; %! assert (get (hp, "facecolor"), "interp"); %! assert (get (hs, "facecolor"), "interp"); @@ -308,7 +308,7 @@ %! close (hf); %! end_unwind_protect -%!error shading () +%!error <Invalid call> shading () %!error shading (1, 2, "flat") %!error <MODE must be a valid string> shading (-1) %!error <MODE must be a valid string> shading ({}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/specular.m --- a/scripts/plot/appearance/specular.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/specular.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function retval = specular (sx, sy, sz, lv, vv, se) - if (nargin < 5 || nargin > 6) + if (nargin < 5) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/thetaticks.m --- a/scripts/plot/appearance/thetaticks.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/thetaticks.m Thu Nov 19 13:08:00 2020 -0800 @@ -124,7 +124,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! polar (linspace (0, pi, 20), rand (20,1)); -%! hax = gca; +%! hax = gca (); %! ticks = thetaticks; %! assert (thetaticks (hax), ticks); %! thetaticks (hax, [0 45 90 135 180]); @@ -139,7 +139,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! polar (linspace (0, pi, 20), 1:20); -%! hax = gca; +%! hax = gca (); %! fail ("thetaticks (-1, [0 1])", "HAX must be a handle to an axes"); %! fail ("tmp = thetaticks (hax, [0 1])", "too many output arguments"); %! fail ("tmp = thetaticks (hax, 'mode')", "MODE is not yet implemented"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/view.m --- a/scripts/plot/appearance/view.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/view.m Thu Nov 19 13:08:00 2020 -0800 @@ -110,13 +110,13 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! plot3 ([0,1], [0,1], [0,1]); -%! [az, el] = view; +%! [az, el] = view (); %! assert ([az, el], [-37.5, 30], eps); %! view (2); -%! [az, el] = view; +%! [az, el] = view (); %! assert ([az, el], [0, 90], eps); %! view ([1 1 0]); -%! [az, el] = view; +%! [az, el] = view (); %! assert ([az, el], [135, 0], eps); %! unwind_protect_cleanup %! close (hf); @@ -125,11 +125,11 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! line; -%! [az, el] = view; +%! line (); +%! [az, el] = view (); %! assert ([az, el], [0, 90], eps); %! view (3); -%! [az, el] = view; +%! [az, el] = view (); %! assert ([az, el], [-37.5, 30], eps); %! unwind_protect_cleanup %! close (hf); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/xtickangle.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/appearance/xtickangle.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,93 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{angle} =} xtickangle () +## @deftypefnx {} {@var{angle} =} xtickangle (@var{hax}) +## @deftypefnx {} {} xtickangle (@var{angle}) +## @deftypefnx {} {} xtickangle (@var{hax}, @var{angle}) +## Query or set the rotation angle of the tick labels on the x-axis of the +## current axes. +## +## When called without an argument, return the rotation angle in degrees of the +## tick labels as specified in the axes property @qcode{"XTickLabelRotation"}. +## When called with a numeric scalar @var{angle}, rotate the tick labels +## counterclockwise to @var{angle} degrees. +## +## If the first argument @var{hax} is an axes handle, then operate on this axes +## rather than the current axes returned by @code{gca}. +## +## Programming Note: Requesting a return value while also setting a specified +## rotation will result in an error. +## +## @seealso{ytickangle, ztickangle, get, set} +## @end deftypefn + +function retval = xtickangle (hax, angle) + + switch (nargin) + case 0 + retval = __tickangle__ (mfilename ()); + + case 1 + if (nargout > 0) + retval = __tickangle__ (mfilename (), hax); + else + __tickangle__ (mfilename (), hax); + endif + + case 2 + if (nargout > 0) + retval = __tickangle__ (mfilename (), hax, angle); + else + __tickangle__ (mfilename (), hax, angle); + endif + + endswitch + +endfunction + + +%!test +%! hf = figure ("visible", "off"); +%! hax = axes (hf); +%! unwind_protect +%! xtickangle (45); +%! assert (xtickangle (), 45); +%! xtickangle (hax, 90); +%! a1 = xtickangle (); +%! a2 = xtickangle (hax); +%! assert (a1, a2); +%! assert (a1, 90); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +## Test input validation +%!error <HAX must be a handle to an axes object> xtickangle (0, 45) +%!error <ANGLE must be .* scalar> xtickangle (eye (2)) +%!error <ANGLE must be .* numeric> xtickangle ({90}) +%!error <ANGLE must be .* finite> xtickangle (Inf) +%!error <called with output query and input set value> ang = xtickangle (45) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/xticklabels.m --- a/scripts/plot/appearance/xticklabels.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/xticklabels.m Thu Nov 19 13:08:00 2020 -0800 @@ -142,7 +142,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "xticklabelmode", "auto"); -%! hax = gca; +%! hax = gca (); %! vals1 = xticklabels; %! assert (xticklabels (hax), vals1); %! mode1 = xticklabels ("mode"); @@ -164,7 +164,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hax = gca; +%! hax = gca (); %! fail ("xticklabels (-1, {})", "HAX must be a handle to an axes"); %! fail ("tmp = xticklabels (hax, {'A','B'})", "too many output arguments"); %! fail ("tmp = xticklabels (hax, [0, 1])", "too many output arguments"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/xticks.m --- a/scripts/plot/appearance/xticks.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/xticks.m Thu Nov 19 13:08:00 2020 -0800 @@ -122,7 +122,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "xtickmode", "auto"); -%! hax = gca; +%! hax = gca (); %! vals1 = xticks; %! assert (xticks (hax), vals1); %! mode1 = xticks ("mode"); @@ -143,7 +143,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hax = gca; +%! hax = gca (); %! fail ("xticks (-1, [0 1])", "HAX must be a handle to an axes"); %! fail ("tmp = xticks (hax, [0 1])", "too many output arguments"); %! fail ("tmp = xticks (hax, 'auto')", "too many .* for arg: auto"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/ytickangle.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/appearance/ytickangle.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,93 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{angle} =} ytickangle () +## @deftypefnx {} {@var{angle} =} ytickangle (@var{hax}) +## @deftypefnx {} {} ytickangle (@var{angle}) +## @deftypefnx {} {} ytickangle (@var{hax}, @var{angle}) +## Query or set the rotation angle of the tick labels on the y-axis of the +## current axes. +## +## When called without an argument, return the rotation angle in degrees of the +## tick labels as specified in the axes property @qcode{"YTickLabelRotation"}. +## When called with a numeric scalar @var{angle}, rotate the tick labels +## counterclockwise to @var{angle} degrees. +## +## If the first argument @var{hax} is an axes handle, then operate on this axes +## rather than the current axes returned by @code{gca}. +## +## Programming Note: Requesting a return value while also setting a specified +## rotation will result in an error. +## +## @seealso{xtickangle, ztickangle, get, set} +## @end deftypefn + +function retval = ytickangle (hax, angle) + + switch (nargin) + case 0 + retval = __tickangle__ (mfilename ()); + + case 1 + if (nargout > 0) + retval = __tickangle__ (mfilename (), hax); + else + __tickangle__ (mfilename (), hax); + endif + + case 2 + if (nargout > 0) + retval = __tickangle__ (mfilename (), hax, angle); + else + __tickangle__ (mfilename (), hax, angle); + endif + + endswitch + +endfunction + + +%!test +%! hf = figure ("visible", "off"); +%! hax = axes (hf); +%! unwind_protect +%! ytickangle (45); +%! assert (ytickangle (), 45); +%! ytickangle (hax, 90); +%! a1 = ytickangle (); +%! a2 = ytickangle (hax); +%! assert (a1, a2); +%! assert (a1, 90); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +## Test input validation +%!error <HAX must be a handle to an axes object> ytickangle (0, 45) +%!error <ANGLE must be .* scalar> ytickangle (eye (2)) +%!error <ANGLE must be .* numeric> ytickangle ({90}) +%!error <ANGLE must be .* finite> ytickangle (Inf) +%!error <called with output query and input set value> ang = ytickangle (45) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/yticklabels.m --- a/scripts/plot/appearance/yticklabels.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/yticklabels.m Thu Nov 19 13:08:00 2020 -0800 @@ -142,7 +142,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "yticklabelmode", "auto"); -%! hax = gca; +%! hax = gca (); %! vals1 = yticklabels; %! assert (yticklabels (hax), vals1); %! mode1 = yticklabels ("mode"); @@ -164,7 +164,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hax = gca; +%! hax = gca (); %! fail ("yticklabels (-1, {})", "HAX must be a handle to an axes"); %! fail ("tmp = yticklabels (hax, {'A','B'})", "too many output arguments"); %! fail ("tmp = yticklabels (hax, [0, 1])", "too many output arguments"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/yticks.m --- a/scripts/plot/appearance/yticks.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/yticks.m Thu Nov 19 13:08:00 2020 -0800 @@ -124,7 +124,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "ytickmode", "auto"); -%! hax = gca; +%! hax = gca (); %! vals1 = yticks; %! assert (yticks (hax), vals1); %! mode1 = yticks ("mode"); @@ -145,7 +145,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hax = gca; +%! hax = gca (); %! fail ("yticks (-1, [0 1])", "HAX must be a handle to an axes"); %! fail ("tmp = yticks (hax, [0 1])", "too many output arguments"); %! fail ("tmp = yticks (hax, 'auto')", "too many .* for arg: auto"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/ztickangle.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/appearance/ztickangle.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,93 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{angle} =} ztickangle () +## @deftypefnx {} {@var{angle} =} ztickangle (@var{hax}) +## @deftypefnx {} {} ztickangle (@var{angle}) +## @deftypefnx {} {} ztickangle (@var{hax}, @var{angle}) +## Query or set the rotation angle of the tick labels on the z-axis of the +## current axes. +## +## When called without an argument, return the rotation angle in degrees of the +## tick labels as specified in the axes property @qcode{"ZTickLabelRotation"}. +## When called with a numeric scalar @var{angle}, rotate the tick labels +## counterclockwise to @var{angle} degrees. +## +## If the first argument @var{hax} is an axes handle, then operate on this axes +## rather than the current axes returned by @code{gca}. +## +## Programming Note: Requesting a return value while also setting a specified +## rotation will result in an error. +## +## @seealso{xtickangle, ytickangle, get, set} +## @end deftypefn + +function retval = ztickangle (hax, angle) + + switch (nargin) + case 0 + retval = __tickangle__ (mfilename ()); + + case 1 + if (nargout > 0) + retval = __tickangle__ (mfilename (), hax); + else + __tickangle__ (mfilename (), hax); + endif + + case 2 + if (nargout > 0) + retval = __tickangle__ (mfilename (), hax, angle); + else + __tickangle__ (mfilename (), hax, angle); + endif + + endswitch + +endfunction + + +%!test +%! hf = figure ("visible", "off"); +%! hax = axes (hf); +%! unwind_protect +%! ztickangle (45); +%! assert (ztickangle (), 45); +%! ztickangle (hax, 90); +%! a1 = ztickangle (); +%! a2 = ztickangle (hax); +%! assert (a1, a2); +%! assert (a1, 90); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +## Test input validation +%!error <HAX must be a handle to an axes object> ztickangle (0, 45) +%!error <ANGLE must be .* scalar> ztickangle (eye (2)) +%!error <ANGLE must be .* numeric> ztickangle ({90}) +%!error <ANGLE must be .* finite> ztickangle (Inf) +%!error <called with output query and input set value> ang = ztickangle (45) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/zticklabels.m --- a/scripts/plot/appearance/zticklabels.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/zticklabels.m Thu Nov 19 13:08:00 2020 -0800 @@ -80,7 +80,7 @@ arg = varargin{2}; otherwise - print_usage; + print_usage (); endswitch @@ -132,7 +132,7 @@ endswitch else - print_usage; + print_usage (); endif endfunction @@ -142,7 +142,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "zticklabelmode", "auto"); -%! hax = gca; +%! hax = gca (); %! vals1 = zticklabels; %! assert (zticklabels (hax), vals1); %! mode1 = zticklabels ("mode"); @@ -164,7 +164,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hax = gca; +%! hax = gca (); %! fail ("zticklabels (-1, {})", "HAX must be a handle to an axes"); %! fail ("tmp = zticklabels (hax, {'A','B'})", "too many output arguments"); %! fail ("tmp = zticklabels (hax, [0, 1])", "too many output arguments"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/appearance/zticks.m --- a/scripts/plot/appearance/zticks.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/appearance/zticks.m Thu Nov 19 13:08:00 2020 -0800 @@ -122,7 +122,7 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "ztickmode", "auto"); -%! hax = gca; +%! hax = gca (); %! vals1 = zticks; %! assert (zticks (hax), vals1); %! mode1 = zticks ("mode"); @@ -143,7 +143,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hax = gca; +%! hax = gca (); %! fail ("zticks (-1, [0 1])", "HAX must be a handle to an axes"); %! fail ("tmp = zticks (hax, [0 1])", "too many output arguments"); %! fail ("tmp = zticks (hax, 'auto')", "too many .* for arg: auto"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/draw/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/area.m --- a/scripts/plot/draw/area.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/area.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ ## the shading under the curve should be defined. The default level is 0. ## ## Additional property/value pairs are passed directly to the underlying patch -## object. The full list of properties is documented at +## object. The full list of properties is documented at ## @ref{Patch Properties}. ## ## If the first argument @var{hax} is an axes handle, then plot into this axes, @@ -207,7 +207,7 @@ set (kids, prop, get (h, prop)); endfunction -function move_baseline (h, d) +function move_baseline (h, ~) persistent recursion = false; ## Don't allow recursion @@ -225,7 +225,7 @@ endif endif endfor - update_data (h, d); + update_data (h, []); unwind_protect_cleanup recursion = false; end_unwind_protect @@ -233,7 +233,7 @@ endfunction -function update_data (h, d) +function update_data (h, ~) hlist = get (h, "areagroup"); bv = get (h, "basevalue"); @@ -288,7 +288,7 @@ %! title ("area() plot of sorted data"); ## Test input validation -%!error area () +%!error <Invalid call> area () %!error area (1,2,3,4) %!error <X and Y must be real vectors or matrices> area ({1}) %!error <X and Y must be real vectors or matrices> area (1+i) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/bar.m --- a/scripts/plot/draw/bar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/bar.m Thu Nov 19 13:08:00 2020 -0800 @@ -124,7 +124,6 @@ [varargout{:}] = __bar__ (true, "bar", varargin{:}); endfunction - %!demo %! clf; %! y = rand (11, 1); @@ -144,3 +143,17 @@ %! clf; %! h = bar (rand (5, 3), "stacked"); %! title ("bar() graph with stacked style"); + +%!demo +%! clf; +%! y = -rand (3) .* eye (3) + rand (3) .* (! eye (3)); +%! h = bar (y, "stacked"); +%! title ("stacked bar() graph including intermingled negative values"); + +%% Test input validation +%!error bar () +%!error <Y must be numeric> bar ("foo") +%!error <X must be a vector> bar ([1 2; 3 4], [1 2 3 4]) +%!error <X vector values must be unique> bar ([1 2 3 3], [1 2 3 4]) +%!error <length of X and Y must be equal> bar ([1 2 3], [1 2 3 4]) +%!error <length of X and Y must be equal> bar ([1 2 3 4], [1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/barh.m --- a/scripts/plot/draw/barh.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/barh.m Thu Nov 19 13:08:00 2020 -0800 @@ -72,7 +72,7 @@ ## ## The optional return value @var{h} is a graphics handle to the created ## bar series hggroup. For a description of the use of the -## bar series, @pxref{XREFbar,,bar}. +## bar series, @pxref{XREFbar,,@code{bar}}. ## @seealso{bar, hist, pie, plot, patch} ## @end deftypefn @@ -95,3 +95,17 @@ %! set (h(2), "facecolor", "g"); %! set (h(3), "facecolor", "b"); %! title ("barh() graph w/multiple bars"); + +%!demo +%! clf; +%! x = -rand (3) .* eye (3) + rand (3) .* (! eye (3)); +%! h = barh (x, "stacked"); +%! title ("stacked barh() graph including intermingled negative values"); + +%% Test input validation +%!error barh () +%!error <Y must be numeric> barh ("foo") +%!error <X must be a vector> barh ([1 2; 3 4], [1 2 3 4]) +%!error <X vector values must be unique> barh ([1 2 3 3], [1 2 3 4]) +%!error <length of X and Y must be equal> barh ([1 2 3], [1 2 3 4]) +%!error <length of X and Y must be equal> barh ([1 2 3 4], [1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/camlight.m --- a/scripts/plot/draw/camlight.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/camlight.m Thu Nov 19 13:08:00 2020 -0800 @@ -80,10 +80,11 @@ ## @end group ## @end example ## -## Here the light is first pitched upwards (@pxref{XREFcamup,,camup}) from the -## camera position (@pxref{XREFcampos,,campos}) by 30 degrees. It is then -## yawed by 45 degrees to the right. Both rotations are centered around the -## camera target (@pxref{XREFcamtarget,,camtarget}). +## Here the light is first pitched upwards (@pxref{XREFcamup,,@code{camup}}) +## from the camera position (@pxref{XREFcampos,,@code{campos}}) by 30 +## degrees. It is then yawed by 45 degrees to the right. Both rotations +## are centered around the camera target +## (@pxref{XREFcamtarget,,@code{camtarget}}). ## ## Return a handle to further manipulate the light object ## diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/colorbar.m --- a/scripts/plot/draw/colorbar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/colorbar.m Thu Nov 19 13:08:00 2020 -0800 @@ -220,7 +220,7 @@ set (hax, "units", orig_props.units, "position", orig_props.position, "outerposition", orig_props.outerposition, - "activepositionproperty", orig_props.activepositionproperty); + "positionconstraint", orig_props.positionconstraint); set (hax, "units", units); endif @@ -252,7 +252,7 @@ ## FIXME: Matlab does not require the "position" property to be active. ## Is there a way to determine the plotbox position for the ## gnuplot graphics toolkit when the outerposition is active? - set (hax, "activepositionproperty", "position"); + set (hax, "positionconstraint", "innerposition"); props = get (hax); props.__axes_handle__ = hax; position = props.position; @@ -277,7 +277,7 @@ ## Create colorbar axes if necessary if (new_colorbar) hcb = axes ("parent", hpar, "tag", "colorbar", - "activepositionproperty", "position", + "positionconstraint", "innerposition", "units", get (hax, "units"), "position", cbpos, "colormap", cmap, "box", "on", "xdir", "normal", "ydir", "normal"); @@ -440,7 +440,7 @@ set (hax, "units", orig_props.units, "position", orig_props.position, "outerposition", orig_props.outerposition, - "activepositionproperty", orig_props.activepositionproperty); + "positionconstraint", orig_props.positionconstraint); set (hax, "units", units); ## Nullify colorbar link (can't delete properties yet) @@ -471,7 +471,7 @@ endfunction ## Update colorbar when changes to axes or figure colormap have occurred. -function cb_colormap (h, d, hax, hcb, hi, init_sz) +function cb_colormap (h, ~, hax, hcb, hi, init_sz) persistent sz = init_sz; if (ishghandle (h)) @@ -536,7 +536,7 @@ scale = [scale, 1]; endif if (strcmp (get (cf, "__graphics_toolkit__"), "gnuplot") - && strcmp (props.activepositionproperty, "outerposition")) + && strcmp (props.positionconstraint, "outerposition")) props.outerposition = props.outerposition .* [1, 1, scale]; off = 0.5 * (props.outerposition (3:4) - __actual_axis_position__ (props)(3:4)); else @@ -859,7 +859,7 @@ %!demo %! clf; %! colormap ("default"); -%! axes; +%! axes (); %! colorbar (); %! hold on; %! contour (peaks ()); @@ -886,7 +886,7 @@ %! shading interp; %! axis ("tight", "square"); %! colorbar (); -#%! axes ("color","none","box","on","activepositionproperty","position"); +#%! axes ("color", "none", "box", "on", "positionconstraint", "innerposition"); %!demo %! clf; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/comet.m --- a/scripts/plot/draw/comet.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/comet.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,9 +46,11 @@ [hax, varargin, nargin] = __plt_get_axis_arg__ ("comet", varargin{:}); - if (nargin == 0) + if (nargin == 0 || nargin > 3) print_usage (); - elseif (nargin == 1) + endif + + if (nargin == 1) y = varargin{1}; x = 1:numel (y); p = 5 / numel (y); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/compass.m --- a/scripts/plot/draw/compass.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/compass.m Thu Nov 19 13:08:00 2020 -0800 @@ -137,8 +137,8 @@ %! title ("compass() example"); ## Test input validation -%!error compass () -%!error compass (1,2,3,4) +%!error <Invalid call> compass () +%!error <Invalid call> compass (1,2,3,4) %!error compass (1, "-r", 2) %!error <invalid linestyle STYLE> compass (1, "abc") %!error <invalid linestyle STYLE> compass (1, {1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/contourc.m --- a/scripts/plot/draw/contourc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/contourc.m Thu Nov 19 13:08:00 2020 -0800 @@ -181,8 +181,8 @@ %! assert (lev_obs, lev_exp, eps); ## Test input validation -%!error contourc () -%!error contourc (1,2,3,4,5) +%!error <Invalid call> contourc () +%!error <Invalid call> contourc (1,2,3,4,5) %!error <X, Y, and Z must be numeric> contourc ({1}) %!error <X, Y, and Z must be numeric> contourc ({1}, 2, 3) %!error <X, Y, and Z must be numeric> contourc (1, {2}, 3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/cylinder.m --- a/scripts/plot/draw/cylinder.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/cylinder.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,17 +61,17 @@ [hax, args, nargs] = __plt_get_axis_arg__ ("cylinder", varargin{:}); - if (nargs == 0) + if (nargs > 2) + print_usage (); + elseif (nargs == 0) r = [1, 1]; n = 20; elseif (nargs == 1) r = args{1}; n = 20; - elseif (nargs == 2) + else r = args{1}; n = args{2}; - else - print_usage (); endif if (length (r) < 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/errorbar.m --- a/scripts/plot/draw/errorbar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/errorbar.m Thu Nov 19 13:08:00 2020 -0800 @@ -247,7 +247,7 @@ ## Invisible figure used for tests %!shared hf, hax %! hf = figure ("visible", "off"); -%! hax = axes; +%! hax = axes (); %!error errorbar () %!error errorbar (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/feather.m --- a/scripts/plot/draw/feather.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/feather.m Thu Nov 19 13:08:00 2020 -0800 @@ -135,8 +135,8 @@ %! title ("feather plot"); ## Test input validation -%!error feather () -%!error feather (1,2,3,4) +%!error <Invalid call> feather () +%!error <Invalid call> feather (1,2,3,4) %!error feather (1, "-r", 2) %!error <invalid linestyle STYLE> feather (1, "abc") %!error <invalid linestyle STYLE> feather (1, {1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/fplot.m --- a/scripts/plot/draw/fplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/fplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -128,6 +128,7 @@ n = 5; tol = 2e-3; fmt = {}; + prop_vals = {}; while (i <= numel (varargin)) arg = varargin{i}; if (ischar (arg)) @@ -138,7 +139,7 @@ if (i == numel (varargin)) error ("fplot: bad input in position %d", i); endif - fmt(end+(1:2)) = varargin([i, i+1]); + prop_vals(end+(1:2)) = varargin([i, i+1]); i++; # Skip PROPERTY. endif elseif (isnumeric (arg) && isscalar (arg) && arg > 0) @@ -225,18 +226,24 @@ if (isempty (hax)) hax = gca (); endif - plot (hax, x, y, fmt{:}); + hl = plot (hax, x, y, fmt{:}); + if (isempty (get (hl(1), "displayname"))) + ## Set displayname for legend if FMT did not contain a name. + if (isvector (y)) + set (hl, "displayname", nam); + else + for i = 1:columns (y) + nams{i} = sprintf ("%s(:,%i)", nam, i); + endfor + set (hl, {"displayname"}, nams(:)); + endif + endif + ## Properties passed as input arguments override other properties. + if (! isempty (prop_vals)) + set (hl, prop_vals{:}); + endif axis (hax, limits); - ## FIXME: If hold is on, then this erases the existing legend rather than - ## adding to it. - if (isvector (y)) - legend (hax, nam); - else - for i = 1:columns (y) - nams{i} = sprintf ("%s(:,%i)", nam, i); - endfor - legend (hax, nams{:}); - endif + legend (hax, "show"); endif endfunction @@ -281,9 +288,31 @@ %! assert (rows (x) == rows (y)); %! assert (y, repmat ([0], size (x))); +%!test <*59274> +%! ## Manual displayname overrides automatic legend entry +%! hf = figure ("visible", "off"); +%! unwind_protect +%! fplot (@sin, [0, 3], "displayname", "mysin"); +%! hl = legend (); +%! assert (get (hl, "string"), {"mysin"}); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test <*59274> +%! ## displayname in format string overrides automatic legend entry +%! hf = figure ("visible", "off"); +%! unwind_protect +%! fplot (@sin, [0, 3], "+;mysin;"); +%! hl = legend (); +%! assert (get (hl, "string"), {"mysin"}); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + ## Test input validation -%!error fplot () -%!error fplot (1,2,3,4,5,6) +%!error <Invalid call> fplot () +%!error <Invalid call> fplot (1,2,3,4,5,6) %!error <FN must be a function handle> fplot (1, [0 1]) %!error <LIMITS must be a real vector> fplot (@cos, [i, 2*i]) %!error <LIMITS must be a real vector with 2 or 4> fplot (@cos, [1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/hist.m --- a/scripts/plot/draw/hist.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/hist.m Thu Nov 19 13:08:00 2020 -0800 @@ -118,14 +118,15 @@ ## Process possible second argument if (nargin == 1 || ischar (varargin{iarg})) n = 10; - ## Use range type to preserve accuracy + ## Use integer range values and perform division last to preserve + ## accuracy. if (min_val != max_val) - x = (0.5:n) * (1/n); - x = (max_val - min_val) * x + min_val; + x = 1:2:2*n; + x = ((max_val - min_val) * x + 2*n*min_val) / (2*n); else x = (-floor ((n-1)/2):ceil ((n-1)/2)) + min_val; endif - x = x.'; # Convert to matrix; + x = x.'; # Convert to matrix else ## Parse bin specification argument x = varargin{iarg++}; @@ -143,14 +144,15 @@ if (n <= 0) error ("hist: number of bins NBINS must be positive"); endif - ## Use range type to preserve accuracy + ## Use integer range values and perform division last to preserve + ## accuracy. if (min_val != max_val) - x = (0.5:n) * (1/n); - x = (max_val - min_val) * x + min_val; + x = 1:2:2*n; + x = ((max_val - min_val) * x + 2*n*min_val) / (2*n); else x = (-floor ((n-1)/2):ceil ((n-1)/2)) + min_val; endif - x = x.'; # Convert to matrix; + x = x.'; # Convert to matrix elseif (isvector (x)) equal_bin_spacing = strcmp (typeinfo (x), "range"); if (! equal_bin_spacing) @@ -198,7 +200,7 @@ ## Lookup is more efficient if y is sorted, but sorting costs. if (! equal_bin_spacing && n > sqrt (rows (y) * 1e4)) y = sort (y); - end + endif nanidx = isnan (y); y(nanidx) = 0; @@ -208,21 +210,21 @@ d = 1; else d = (x(end) - x(1)) / (length (x) - 1); - end + endif cutlen = length (cutoff); for j = 1:y_nc freq(:,j) = accumarray (1 + max (0, min (cutlen, ceil ((double (y(:,j)) - cutoff(1)) / d))), double (! nanidx(:,j)), [n, 1]); - end + endfor else for j = 1:y_nc i = lookup (cutoff, y(:,j)); i = 1 + i - (cutoff(max (i, 1)) == y(:,j)); freq(:,j) = accumarray (i, double (! nanidx(:,j)), [n, 1]); - end - end + endfor + endif endif if (norm) @@ -386,13 +388,13 @@ %! assert (isa (xx, "single")); ## Test input validation -%!error hist () +%!error <Invalid call> hist () %!error <Y must be real-valued> hist (2+i) %!error <bin specification must be a numeric> hist (1, {0,1,2}) %!error <number of bins NBINS must be positive> hist (1, 0) %!test %! hf = figure ("visible", "off"); -%! hax = gca; +%! hax = gca (); %! unwind_protect %! fail ("hist (hax, 1, [2 1 0])", "warning", "bin values X not sorted"); %! unwind_protect_cleanup diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/isocaps.m --- a/scripts/plot/draw/isocaps.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/isocaps.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ ## vectors with lengths corresponding to the dimensions of @var{v}, then the ## volume data is taken at the specified points. If @var{x}, @var{y}, or ## @var{z} are empty, the grid corresponds to the indices (@code{1:n}) in -## the respective direction (@pxref{XREFmeshgrid,,meshgrid}). +## the respective direction (@pxref{XREFmeshgrid,,@code{meshgrid}}). ## ## The optional parameter @var{which_caps} can have one of the following ## string values which defines how the data will be enclosed: @@ -376,7 +376,7 @@ %! [x, y, z] = meshgrid (lin, lin, lin); %! v = abs ((x-0.45).^2 + (y-0.55).^2 + (z-0.8).^2); %! hf = clf; -%! ha = axes; +%! ha = axes (); %! view (3); box off; %! fvc_iso = isosurface (x, y, z, v, isoval); %! cmap = get (hf, "Colormap"); @@ -544,8 +544,8 @@ %! assert (rows (vertices), rows (fvcdata)); ## test for each error -%!error isocaps () -%!error isocaps (1,2,3,4,5,6,7,8,9) +%!error <Invalid call> isocaps () +%!error <Invalid call> isocaps (1,2,3,4,5,6,7,8,9) %!error <parameter 'foo' not supported> isocaps (val, iso, "foo") %!error <incorrect number of input arguments> isocaps (x, val, iso) %!error <incorrect number of input arguments> isocaps (xx, yy, zz, val, iso, 5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/isocolors.m --- a/scripts/plot/draw/isocolors.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/isocolors.m Thu Nov 19 13:08:00 2020 -0800 @@ -185,11 +185,11 @@ %! assert (rows (cdat) == rows (v)); ## Test input validation -%!error isocolors () -%!error isocolors (1) -%!error isocolors (1,2,3) -%!error isocolors (1,2,3,4,5,6) -%!error isocolors (1,2,3,4,5,6,7,8) +%!error <Invalid call> isocolors () +%!error <Invalid call> isocolors (1) +%!error <Invalid call> isocolors (1,2,3) +%!error <Invalid call> isocolors (1,2,3,4,5,6) +%!error <Invalid call> isocolors (1,2,3,4,5,6,7,8) %!error <last argument must be a vertex list> isocolors (1, {1}) %!error <last argument must be a vertex list> isocolors (1, [1 2 3 4]) %!error <last argument must be a .*patch handle> isocolors (1, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/isonormals.m --- a/scripts/plot/draw/isonormals.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/isonormals.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,12 +65,14 @@ narg = nargin; negate = false; - if (ischar (varargin{narg})) - if (strcmpi (varargin{narg}, "negate")) - negate = true; - narg -= 1; - else - error ("isonormals: Unknown option '%s'", varargin{narg}); + if (nargin > 2) + if (ischar (varargin{end})) + if (strcmpi (varargin{end}, "negate")) + negate = true; + narg -= 1; + else + error ("isonormals: Unknown option '%s'", varargin{end}); + endif endif endif @@ -191,11 +193,11 @@ %! assert (all (dirn(isfinite (dirn)) <= 0)); ## Test input validation -%!error isonormals () -%!error isonormals (1) -%!error isonormals (1,2,3) -%!error isonormals (1,2,3,4) -%!error isonormals (1,2,3,4,5,6) +%!error <Invalid call> isonormals () +%!error <Invalid call> isonormals (1) +%!error <Invalid call> isonormals (1,2,3) +%!error <Invalid call> isonormals (1,2,3,4) +%!error <Invalid call> isonormals (1,2,3,4,5,6) %!error <Unknown option 'foo'> isonormals (x, y, z, val, vert, "foo") %!error <must be a list of vertices> isonormals (1, {1}) %!error <must be a list of vertices> isonormals (1, [1 2 3 4]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/isosurface.m --- a/scripts/plot/draw/isosurface.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/isosurface.m Thu Nov 19 13:08:00 2020 -0800 @@ -59,7 +59,7 @@ ## vectors with lengths corresponding to the dimensions of @var{v}, then the ## volume data is taken at the specified points. If @var{x}, @var{y}, or ## @var{z} are empty, the grid corresponds to the indices (@code{1:n}) in -## the respective direction (@pxref{XREFmeshgrid,,meshgrid}). +## the respective direction (@pxref{XREFmeshgrid,,@code{meshgrid}}). ## ## The optional input argument @var{col}, which is a three-dimensional array ## of the same size as @var{v}, specifies coloring of the isosurface. The @@ -168,7 +168,7 @@ warning ("isosurface: triangulation is empty"); endif - # remove faces for which at least one of the vertices is NaN + ## remove faces for which at least one of the vertices is NaN vert_nan = 1:size (fvc.vertices, 1); vert_nan(any (isnan (fvc.vertices), 2)) = NaN; fvc.faces = vert_nan(fvc.faces); @@ -307,7 +307,7 @@ colors = varargin{6}; otherwise - error ("isosurface: incorrect number of input arguments") + error ("isosurface: incorrect number of input arguments"); endswitch @@ -355,19 +355,19 @@ endif if (! isscalar (isoval)) - error ("isosurface: ISOVAL must be a scalar") + error ("isosurface: ISOVAL must be a scalar"); endif ## check colors if (! isempty (colors)) if (! size_equal (v, colors)) - error ("isosurface: COL must match the size of V") + error ("isosurface: COL must match the size of V"); endif if (nout == 2) - warning ("isosurface: colors will be calculated, but no output argument to receive it."); + warning ("isosurface: colors will be calculated, but no output argument to receive it"); endif elseif (nout >= 3) - error ("isosurface: COL must be passed to return C") + error ("isosurface: COL must be passed to return C"); endif endfunction @@ -559,8 +559,8 @@ %! assert (size (fvc.facevertexcdata), [7 1]); ## test for each error and warning -%!error isosurface () -%!error isosurface (1,2,3,4,5,6,7,8,9) +%!error <Invalid call> isosurface () +%!error <Invalid call> isosurface (1,2,3,4,5,6,7,8,9) %!error <parameter 'foobar' not supported> %! fvc = isosurface (val, iso, "foobar"); %!error <incorrect number of input arguments> @@ -592,9 +592,9 @@ %! [xx, yy, zz] = meshgrid (x, y, z); %! fvc = isosurface (xx, yy, zz, val, iso); %!error <ISOVAL must be a scalar> fvc = isosurface (val, [iso iso], yy) -%!error <COL must match the size of V> fvc = isosurface (val, [iso iso]); +%!error <COL must match the size of V> fvc = isosurface (val, [iso iso]) %!error <COL must be passed to return C> [f, v, c] = isosurface (val, iso) -%!warning <colors will be calculated, but no output argument to receive it.> +%!warning <colors will be calculated, but no output argument to receive it> %! [f, v] = isosurface (val, iso, yy); ## test for __calc_isovalue_from_data__ diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/light.m --- a/scripts/plot/draw/light.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/light.m Thu Nov 19 13:08:00 2020 -0800 @@ -163,9 +163,9 @@ %! h_axes1 = axes (); %! surf (X, Y, Z, "LineStyle", "none", "FaceLighting", "none"); %! hold on; -%! surf (X + round(1.2 * size (Z, 2)), Y, Z, "LineStyle", "none", ... +%! surf (X + round (1.2 * size (Z, 2)), Y, Z, "LineStyle", "none", ... %! "FaceLighting", "flat"); -%! surf (X + round(2.4 * size (Z, 2)), Y, Z, "LineStyle", "none", ... +%! surf (X + round (2.4 * size (Z, 2)), Y, Z, "LineStyle", "none", ... %! "FaceLighting", "gouraud"); %! axis tight %! axis equal @@ -592,7 +592,7 @@ %!test %! hf = figure ("visible", "off"); -%! ha = gca; +%! ha = gca (); %! unwind_protect %! h = light (ha, "Position", [1 2 3], "Color", "r"); %! assert (get (h, "Position"), [1 2 3]); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/lightangle.m --- a/scripts/plot/draw/lightangle.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/lightangle.m Thu Nov 19 13:08:00 2020 -0800 @@ -122,7 +122,7 @@ pos -= get (hax, "CameraTarget"); endif - pos = sph2cart (az, el, norm (pos)); + [pos(1), pos(2), pos(3)] = sph2cart (az, el, norm (pos)); if (strcmp (get (hl, "Style"), "local")) pos += get (hax, "CameraTarget"); @@ -165,8 +165,8 @@ ## Test input validation %!error <Invalid call> lightangle () %!error <Invalid call> lightangle (1, 2, 3, 4) +%!error <Invalid call> [a, b, c] = lightangle (45, 30) %!error <Invalid call> [a, b] = lightangle (45, 30) -%!error <Invalid call> [a, b, c] = lightangle (45, 30) %!error <HL must be a handle to a light object> lightangle (0) %!error <H must be a handle to an axes or light object> lightangle (0, 90, 45) %!error <AZ and EL must be numeric scalars> lightangle ([1 2], 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/line.m --- a/scripts/plot/draw/line.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/line.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! h = line; +%! h = line (); %! assert (findobj (hf, "type", "line"), h); %! assert (get (h, "xdata"), [0 1], eps); %! assert (get (h, "ydata"), [0 1], eps); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/loglogerr.m --- a/scripts/plot/draw/loglogerr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/loglogerr.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,8 +46,8 @@ ## @noindent ## which produces a double logarithm plot of @var{y} versus @var{x} ## with errors in the @var{y}-scale defined by @var{ey} and the plot -## format defined by @var{fmt}. @xref{XREFerrorbar,,errorbar}, for available -## formats and additional information. +## format defined by @var{fmt}. @xref{XREFerrorbar,,@code{errorbar}}, for +## available formats and additional information. ## ## If the first argument @var{hax} is an axes handle, then plot into this axes, ## rather than the current axes returned by @code{gca}. diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/module.mk --- a/scripts/plot/draw/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -9,6 +9,7 @@ %reldir%/private/__contour__.m \ %reldir%/private/__errplot__.m \ %reldir%/private/__ezplot__.m \ + %reldir%/private/__gnuplot_scatter__.m \ %reldir%/private/__interp_cube__.m \ %reldir%/private/__line__.m \ %reldir%/private/__marching_cube__.m \ @@ -21,6 +22,7 @@ %reldir%/private/__unite_shared_vertices__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/area.m \ %reldir%/bar.m \ %reldir%/barh.m \ @@ -98,6 +100,7 @@ %reldir%/stream2.m \ %reldir%/stream3.m \ %reldir%/streamline.m \ + %reldir%/streamribbon.m \ %reldir%/streamtube.m \ %reldir%/surf.m \ %reldir%/surface.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/ostreamtube.m --- a/scripts/plot/draw/ostreamtube.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/ostreamtube.m Thu Nov 19 13:08:00 2020 -0800 @@ -71,7 +71,7 @@ ## @end group ## @end example ## -## @seealso{stream3, streamline, streamtube} +## @seealso{stream3, streamline, streamribbon, streamtube} ## @end deftypefn ## References: @@ -97,8 +97,6 @@ options = []; xyz = []; switch (nargin) - case 0 - print_usage (); case 6 [u, v, w, spx, spy, spz] = varargin{:}; [m, n, p] = size (u); @@ -118,7 +116,7 @@ case 10 [x, y, z, u, v, w, spx, spy, spz, options] = varargin{:}; otherwise - error ("ostreamtube: invalid number of inputs"); + print_usage (); endswitch scale = 1; @@ -131,7 +129,7 @@ scale = options(1); num_circum = options(2); otherwise - error ("ostreamtube: invalid number of OPTIONS elements"); + error ("ostreamtube: OPTIONS must be a 1- or 2-element vector"); endswitch if (! isreal (scale) || scale <= 0) @@ -161,7 +159,7 @@ for i = 1 : length (xyz) sl = xyz{i}; if (! isempty (sl)) - slx = sl(:, 1); sly = sl(:, 2); slz = sl(:, 3); + slx = sl(:,1); sly = sl(:,2); slz = sl(:,3); mxx(j) = max (slx); mnx(j) = min (slx); mxy(j) = max (sly); mny(j) = min (sly); mxz(j) = max (slz); mnz(j) = min (slz); @@ -179,12 +177,12 @@ num_vertices = rows (sl); if (! isempty (sl) && num_vertices > 2) - usl = interp3 (x, y, z, u, sl(:, 1), sl(:, 2), sl(:, 3)); - vsl = interp3 (x, y, z, v, sl(:, 1), sl(:, 2), sl(:, 3)); - wsl = interp3 (x, y, z, w, sl(:, 1), sl(:, 2), sl(:, 3)); + usl = interp3 (x, y, z, u, sl(:,1), sl(:,2), sl(:,3)); + vsl = interp3 (x, y, z, v, sl(:,1), sl(:,2), sl(:,3)); + wsl = interp3 (x, y, z, w, sl(:,1), sl(:,2), sl(:,3)); vv = sqrt (usl.*usl + vsl.*vsl + wsl.*wsl); - div_sl = interp3 (x, y, z, div, sl(:, 1), sl(:, 2), sl(:, 3)); + div_sl = interp3 (x, y, z, div, sl(:,1), sl(:,2), sl(:,3)); is_singular_div = find (isnan (div_sl), 1, "first"); if (! isempty (is_singular_div)) @@ -211,61 +209,65 @@ cp = cos (phi); sp = sin (phi); - X0 = sl(1, :); - X1 = sl(2, :); - - ## 1st rotation axis + ## 1st streamline segment + X0 = sl(1,:); + X1 = sl(2,:); R = X1 - X0; RE = R / norm (R); - ## Initial radius - vold = vv(1); - vact = vv(2); - ract = rstart * exp (0.5 * div_sl(2) * norm (R) / vact) * sqrt (vold / vact); - vold = vact; + ## Guide point and its rotation to create a segment + KE = get_normal1 (RE); + K = rstart * KE; + XS0 = rotation (K, RE, cp, sp) + repmat (X0.', 1, num_circum); + + ## End of first segment + ract = rstart * exp (0.5 * div_sl(2) * norm (R) / vv(2)) * ... + sqrt (vv(1) / vv(2)); rold = ract; - - ## Guide point and its rotation to create a segment - N = get_normal1 (R); - K = ract * N; + K = ract * KE; XS = rotation (K, RE, cp, sp) + repmat (X1.', 1, num_circum); - px = zeros (num_circum, max_vertices - 1); - py = zeros (num_circum, max_vertices - 1); - pz = zeros (num_circum, max_vertices - 1); - pc = zeros (num_circum, max_vertices - 1); + px = zeros (num_circum, max_vertices); + py = zeros (num_circum, max_vertices); + pz = zeros (num_circum, max_vertices); + pc = zeros (num_circum, max_vertices); - px(:, 1) = XS(1, :).'; - py(:, 1) = XS(2, :).'; - pz(:, 1) = XS(3, :).'; - pc(:, 1) = vact * ones (num_circum, 1); + px(:,1) = XS0(1,:).'; + py(:,1) = XS0(2,:).'; + pz(:,1) = XS0(3,:).'; + pc(:,1) = vv(1) * ones (num_circum, 1); + + px(:,2) = XS(1,:).'; + py(:,2) = XS(2,:).'; + pz(:,2) = XS(3,:).'; + pc(:,2) = vv(2) * ones (num_circum, 1); for i = 3 : max_vertices - KK = K; + ## Next streamline segment X0 = X1; - X1 = sl(i, :); + X1 = sl(i,:); R = X1 - X0; RE = R / norm (R); ## Tube radius - vact = vv(i); - ract = rold * exp (0.5 * div_sl(i) * norm (R) / vact) * sqrt (vold / vact); - vold = vact; + ract = rold * exp (0.5 * div_sl(i) * norm (R) / vv(i)) * ... + sqrt (vv(i-1) / vv(i)); rold = ract; - ## Project KK onto RE and get the difference in order to calculate the next - ## guiding point - Kp = KK - RE * dot (KK, RE); - K = ract * Kp / norm (Kp); + ## Project KE onto RE and get the difference in order to transport + ## the normal vector KE along the vertex array + Kp = KE - RE * dot (KE, RE); + KE = Kp / norm (Kp); + K = ract * KE; ## Rotate around RE and collect surface patches XS = rotation (K, RE, cp, sp) + repmat (X1.', 1, num_circum); - px(:, i - 1) = XS(1, :).'; - py(:, i - 1) = XS(2, :).'; - pz(:, i - 1) = XS(3, :).'; - pc(:, i - 1) = vact * ones (num_circum, 1); + px(:,i) = XS(1,:).'; + py(:,i) = XS(2,:).'; + pz(:,i) = XS(3,:).'; + pc(:,i) = vv(i) * ones (num_circum, 1); endfor @@ -277,9 +279,9 @@ function N = get_normal1 (X) if ((X(3) == 0) && (X(1) == -X(2))) - N = [- X(2) - X(3), X(1), X(1)]; + N = [(- X(2) - X(3)), X(1), X(1)]; else - N = [X(3), X(3), - X(1) - X(2)]; + N = [X(3), X(3), (- X(1) - X(2))]; endif N /= norm (N); @@ -294,20 +296,21 @@ uy = U(2); uz = U(3); - Y(1, :) = X(1) * (cp + ux * ux * (1 - cp)) + ... - X(2) * (ux * uy * (1 - cp) - uz * sp) + ... - X(3) * (ux * uz * (1 - cp) + uy * sp); + Y(1,:) = X(1) * (cp + ux * ux * (1 - cp)) + ... + X(2) * (ux * uy * (1 - cp) - uz * sp) + ... + X(3) * (ux * uz * (1 - cp) + uy * sp); - Y(2, :) = X(1) * (uy * ux * (1 - cp) + uz * sp) + ... - X(2) * (cp + uy * uy * (1 - cp)) + ... - X(3) * (uy * uz * (1 - cp) - ux * sp); + Y(2,:) = X(1) * (uy * ux * (1 - cp) + uz * sp) + ... + X(2) * (cp + uy * uy * (1 - cp)) + ... + X(3) * (uy * uz * (1 - cp) - ux * sp); - Y(3, :) = X(1) * (uz * ux * (1 - cp) - uy * sp) + ... - X(2) * (uz * uy * (1 - cp) + ux * sp) + ... - X(3) * (cp + uz * uz * (1 - cp)); + Y(3,:) = X(1) * (uz * ux * (1 - cp) - uy * sp) + ... + X(2) * (uz * uy * (1 - cp) + ux * sp) + ... + X(3) * (cp + uz * uz * (1 - cp)); endfunction + %!demo %! clf; %! [x, y, z] = meshgrid (-1:0.1:1, -1:0.1:1, -3.5:0.1:0); @@ -353,14 +356,14 @@ %! title ("Integration Towards Sink"); ## Test input validation -%!error ostreamtube () -%!error <invalid number of inputs> ostreamtube (1) -%!error <invalid number of inputs> ostreamtube (1,2) -%!error <invalid number of inputs> ostreamtube (1,2,3) -%!error <invalid number of inputs> ostreamtube (1,2,3,4) -%!error <invalid number of inputs> ostreamtube (1,2,3,4,5) -%!error <invalid number of OPTIONS> ostreamtube (1,2,3,4,5,6, [1,2,3]) -%!error <SCALE must be a real scalar . 0> ostreamtube (1,2,3,4,5,6, [1i]) -%!error <SCALE must be a real scalar . 0> ostreamtube (1,2,3,4,5,6, [0]) -%!error <N must be greater than 2> ostreamtube (1,2,3,4,5,6, [1, 1i]) -%!error <N must be greater than 2> ostreamtube (1,2,3,4,5,6, [1, 2]) +%!error <Invalid call> ostreamtube () +%!error <Invalid call> ostreamtube (1) +%!error <Invalid call> ostreamtube (1,2) +%!error <Invalid call> ostreamtube (1,2,3) +%!error <Invalid call> ostreamtube (1,2,3,4) +%!error <Invalid call> ostreamtube (1,2,3,4,5) +%!error <OPTIONS must be a 1- or 2-element> ostreamtube (1,2,3,4,5,6,[1,2,3]) +%!error <SCALE must be a real scalar . 0> ostreamtube (1,2,3,4,5,6,[1i]) +%!error <SCALE must be a real scalar . 0> ostreamtube (1,2,3,4,5,6,[0]) +%!error <N must be greater than 2> ostreamtube (1,2,3,4,5,6,[1,1i]) +%!error <N must be greater than 2> ostreamtube (1,2,3,4,5,6,[1,2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/pareto.m --- a/scripts/plot/draw/pareto.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/pareto.m Thu Nov 19 13:08:00 2020 -0800 @@ -72,7 +72,7 @@ [hax, varargin, nargin] = __plt_get_axis_arg__ ("pareto", varargin{:}); - if (nargin != 1 && nargin != 2) + if (nargin < 1 || nargin > 2) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/patch.m --- a/scripts/plot/draw/patch.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/patch.m Thu Nov 19 13:08:00 2020 -0800 @@ -94,16 +94,6 @@ print_usage (); endif - ## FIXME: ishold called this way is very slow. - if (! ishold (hax)) - ## FIXME: This is a hack to get 'layer' command to work for 2D patches - ## Alternative is much more complicated surgery in graphics.cc. - ## of get_children_limits() for 'z' axis and 'patch' object type. - if (isempty (get (htmp, "zdata"))) - set (hax, "zlim", [-1 1]); - endif - endif - if (nargout > 0) h = htmp; endif @@ -259,21 +249,21 @@ %!demo %! clf; -%! vertices = [0 0 0; 0.5 -0.5 0; 1 0 0; 1 1 0; 0 1 1; 1 0 1; 0 -1 0;]+3; +%! vertices = [0 0 0; 0.5 -0.5 0; 1 0 0; 1 1 0; 0 1 1; 1 0 1; 0 -1 0] + 3; %! faces = [1 2 3 4 5 6 7]; %! ha = axes (); -%! hp = patch ('Vertices', vertices, 'Faces', faces, 'FaceColor', 'g'); -%! xlabel('x'), ylabel('y'), zlabel('z') -%! view(3) -%! set (ha, "XTick", [], "YTick", [], "ZTick", []) -%! text (vertices(1,1), vertices(1,2), vertices(1,3), "1") -%! text (vertices(2,1), vertices(2,2), vertices(2,3), "2") -%! text (vertices(3,1), vertices(3,2), vertices(3,3), "3") -%! text (vertices(4,1), vertices(4,2), vertices(4,3), "4") -%! text (vertices(5,1), vertices(5,2), vertices(5,3), "5") -%! text (vertices(6,1), vertices(6,2), vertices(6,3), "6") -%! text (vertices(7,1), vertices(7,2), vertices(7,3), "7") -%! title ("Non-coplanar patch") +%! hp = patch ("Vertices", vertices, "Faces", faces, "FaceColor", "g"); +%! xlabel ("x"), ylabel ("y"), zlabel ("z"); +%! view (3); +%! set (ha, "XTick", [], "YTick", [], "ZTick", []); +%! text (vertices(1,1), vertices(1,2), vertices(1,3), "1"); +%! text (vertices(2,1), vertices(2,2), vertices(2,3), "2"); +%! text (vertices(3,1), vertices(3,2), vertices(3,3), "3"); +%! text (vertices(4,1), vertices(4,2), vertices(4,3), "4"); +%! text (vertices(5,1), vertices(5,2), vertices(5,3), "5"); +%! text (vertices(6,1), vertices(6,2), vertices(6,3), "6"); +%! text (vertices(7,1), vertices(7,2), vertices(7,3), "7"); +%! title ("Non-coplanar patch"); %!test @@ -297,7 +287,7 @@ %! assert (get (h, "linewidth"), get (0, "defaultpatchlinewidth"), eps); %! assert (get (h, "marker"), get (0, "defaultpatchmarker")); %! assert (get (h, "markersize"), get (0, "defaultpatchmarkersize")); -%! hl = light; +%! hl = light (); %! assert (get (h, "facelighting"), "flat"); %! assert (get (h, "facenormals"), [0 0 1], eps); %! assert (get (h, "vertexnormals"), []); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/pie.m --- a/scripts/plot/draw/pie.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/pie.m Thu Nov 19 13:08:00 2020 -0800 @@ -113,6 +113,6 @@ %! title ("pie() with missing slice"); ## Test input validation -%!error pie () +%!error <Invalid call> pie () %!error <all data in X must be finite> pie ([1 2 Inf]) %!error <all data in X must be finite> pie ([1 2 NaN]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/pie3.m --- a/scripts/plot/draw/pie3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/pie3.m Thu Nov 19 13:08:00 2020 -0800 @@ -112,6 +112,6 @@ %! title ("pie3() with missing slice"); ## Test input validation -%!error pie3 () +%!error <Invalid call> pie3 () %!error <all data in X must be finite> pie3 ([1 2 Inf]) %!error <all data in X must be finite> pie3 ([1 2 NaN]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/plotmatrix.m --- a/scripts/plot/draw/plotmatrix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/plotmatrix.m Thu Nov 19 13:08:00 2020 -0800 @@ -78,7 +78,7 @@ [bigax2, varargin, nargin] = __plt_get_axis_arg__ ("plotmatrix", varargin{:}); - if (nargin > 3 || nargin < 1) + if (nargin < 1 || nargin > 3) print_usage (); endif @@ -121,7 +121,7 @@ %! title ("plotmatrix() demo #1"); -function plotmatrixdelete (h, d, ax) +function plotmatrixdelete (h, ~, ax) for i = 1 : numel (ax) hc = ax(i); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/plotyy.m --- a/scripts/plot/draw/plotyy.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/plotyy.m Thu Nov 19 13:08:00 2020 -0800 @@ -93,7 +93,7 @@ hax = get (hax, "__plotyy_axes__"); else hax = [hax; axes("nextplot", get (hax(1), "nextplot"), ... - "parent", get(hax(1), "parent"))]; + "parent", get (hax(1), "parent"))]; endif [axtmp, h1tmp, h2tmp] = __plotyy__ (hax, varargin{:}); @@ -142,9 +142,9 @@ if (strcmp (get (ax(1), "__autopos_tag__"), "subplot")) set (ax(2), "__autopos_tag__", "subplot"); elseif (strcmp (graphics_toolkit (), "gnuplot")) - set (ax, "activepositionproperty", "position"); + set (ax, "positionconstraint", "innerposition"); else - set (ax, "activepositionproperty", "outerposition"); + set (ax, "positionconstraint", "outerposition"); endif ## Don't replace axis which has colororder property already modified @@ -161,7 +161,7 @@ endif set (ax(2), "units", get (ax(1), "units")); - if (strcmp (get(ax(1), "activepositionproperty"), "position")) + if (strcmp (get (ax(1), "positionconstraint"), "innerposition")) set (ax(2), "position", get (ax(1), "position")); else set (ax(2), {"outerposition", "looseinset"}, @@ -241,8 +241,8 @@ val = get (h, prop); if (strcmpi (prop, "position") || strcmpi (prop, "outerposition")) ## Save/restore "positionconstraint" - constraint = get (ax2, "activepositionproperty"); - set (ax2, prop, get (h, prop), "activepositionproperty", constraint); + constraint = get (ax2, "positionconstraint"); + set (ax2, prop, get (h, prop), "positionconstraint", constraint); else set (ax2, prop, get (h, prop)); endif @@ -292,13 +292,13 @@ %! colormap ("default"); %! x = linspace (-1, 1, 201); %! subplot (2,2,1); -%! plotyy (x,sin(pi*x), x,10*cos(pi*x)); +%! plotyy (x,sin (pi*x), x,10*cos (pi*x)); %! title ("plotyy() in subplot"); %! subplot (2,2,2); %! surf (peaks (25)); %! subplot (2,2,3); %! contour (peaks (25)); %! subplot (2,2,4); -%! plotyy (x,10*sin(2*pi*x), x,cos(2*pi*x)); +%! plotyy (x,10*sin (2*pi*x), x,cos (2*pi*x)); %! title ("plotyy() in subplot"); %! axis square; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/polar.m --- a/scripts/plot/draw/polar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/polar.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,8 +34,8 @@ ## ## The input @var{theta} is assumed to be radians and is converted to degrees ## for plotting. If you have degrees then you must convert -## (@pxref{XREFcart2pol,,cart2pol}) to radians before passing the data to this -## function. +## (@pxref{XREFcart2pol,,@code{cart2pol}}) to radians before passing the +## data to this function. ## ## If a single complex input @var{cplx} is given then the real part is used ## for @var{theta} and the imaginary part is used for @var{rho}. @@ -398,6 +398,7 @@ endfunction function resetaxis (~, ~, hax) + if (isaxes (hax)) dellistener (hax, "rtick"); dellistener (hax, "ttick"); @@ -412,6 +413,7 @@ dellistener (hax, "gridlinestyle"); dellistener (hax, "linewidth"); endif + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__bar__.m --- a/scripts/plot/draw/private/__bar__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__bar__.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,6 +38,7 @@ width = 0.8; group = true; + stacked = false; histc = NA; ## BaseValue if (strcmp (get (hax, "yscale"), "log")) @@ -84,6 +85,7 @@ group = true; idx += 1; elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "stacked")) + stacked = true; group = false; idx += 1; elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "histc")) @@ -185,8 +187,22 @@ y0 = zeros (size (y)) + bv; y1 = y; else - y1 = cumsum (y,2); - y0 = [zeros(ngrp,1)+bv, y1(:,1:end-1)]; + if (stacked && any (y(:) < 0)) + ypos = (y >= 0); + yneg = (y < 0); + + y1p = cumsum (y .* ypos, 2); + y1n = cumsum (y .* yneg, 2); + y1 = y1p .* ypos + y1n .* yneg; + + y0p = [zeros(ngrp,1)+bv, y1p(:,1:end-1)]; + y0n = [zeros(ngrp,1)+bv, y1n(:,1:end-1)]; + y0 = y0p .* ypos + y0n .* yneg; + + else + y1 = cumsum (y,2); + y0 = [zeros(ngrp,1)+bv, y1(:,1:end-1)]; + endif endif yb = zeros (4*ngrp, nbars); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__ezplot__.m --- a/scripts/plot/draw/private/__ezplot__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__ezplot__.m Thu Nov 19 13:08:00 2020 -0800 @@ -364,7 +364,7 @@ Y = __eliminate_sing__ (Y); Z = __eliminate_sing__ (Z); endif - else ## non-parametric plots + else # non-parametric plots if (isplot && nargs == 2) Z = feval (fun, X, Y); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__gnuplot_scatter__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/draw/private/__gnuplot_scatter__.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,345 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{hg} =} __gnuplot_scatter__ (@dots{}) +## Undocumented internal function. +## @end deftypefn + +function hg = __gnuplot_scatter__ (hax, fcn, x, y, z, c, s, marker, filled, newargs) + +if (isempty (c)) + c = __next_line_color__ (); +endif + +## Must occur after __next_line_color__ in order to work correctly. +hg = hggroup (hax, "__appdata__", struct ("__creator__", "__scatter__")); +newargs = __add_datasource__ (fcn, hg, {"x", "y", "z", "c", "size"}, + newargs{:}); + +addproperty ("xdata", hg, "data", x); +addproperty ("ydata", hg, "data", y); +addproperty ("zdata", hg, "data", z); +if (ischar (c)) + ## For single explicit color, cdata is unused + addproperty ("cdata", hg, "data", []); +else + addproperty ("cdata", hg, "data", c); +endif +addproperty ("sizedata", hg, "data", s); +addlistener (hg, "xdata", @update_data); +addlistener (hg, "ydata", @update_data); +addlistener (hg, "zdata", @update_data); +addlistener (hg, "cdata", @update_data); +addlistener (hg, "sizedata", @update_data); + +one_explicit_color = ischar (c) || isequal (size (c), [1, 3]); +s = sqrt (s); # size adjustment for visual compatibility w/Matlab + +if (numel (x) <= 100) + + ## For small number of points, we'll construct an object for each point. + + if (numel (s) == 1) + s = repmat (s, numel (x), 1); + endif + + if (one_explicit_color) + for i = 1 : numel (x) + if (filled) + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x(i), "ydata", y(i), "zdata", z(i,:), + "faces", 1, "vertices", [x(i), y(i), z(i,:)], + "marker", marker, "markersize", s(i), + "markeredgecolor", c, "markerfacecolor", c, + "linestyle", "none"); + else + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x(i), "ydata", y(i), "zdata", z(i,:), + "faces", 1, "vertices", [x(i), y(i), z(i,:)], + "marker", marker, "markersize", s(i), + "markeredgecolor", c, "markerfacecolor", "none", + "linestyle", "none"); + endif + endfor + else + if (rows (c) == 1) + c = repmat (c, rows (x), 1); + endif + for i = 1 : numel (x) + if (filled) + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x(i), "ydata", y(i), "zdata", z(i,:), + "faces", 1, "vertices", [x(i), y(i), z(i,:)], + "marker", marker, "markersize", s(i), + "markeredgecolor", "none", + "markerfacecolor", "flat", + "cdata", c(i,:), "facevertexcdata", c(i,:), + "linestyle", "none"); + else + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x(i), "ydata", y(i), "zdata", z(i,:), + "faces", 1, "vertices", [x(i), y(i), z(i,:)], + "marker", marker, "markersize", s(i), + "markeredgecolor", "flat", + "markerfacecolor", "none", + "cdata", c(i,:), "facevertexcdata", c(i,:), + "linestyle", "none"); + endif + endfor + endif + +else + + ## For larger numbers of points, we use one single object. + vert = [x, y, z]; + render_size_color (hg, vert, s, c, marker, filled, true); + +endif + +if (! ischar (c) && rows (c) > 1) + ax = get (hg, "parent"); + clim = get (ax, "clim"); + if (min (c(:)) < clim(1)) + clim(1) = min (c(:)); + set (ax, "clim", clim); + endif + if (max (c(:)) > clim(2)) + set (ax, "clim", [clim(1), max(c(:))]); + endif +endif + +addproperty ("linewidth", hg, "patchlinewidth", 0.5); +addproperty ("marker", hg, "patchmarker", marker); +if (filled) + addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", "none"); + if (one_explicit_color) + addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", c); + else + addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", "flat"); + endif +else + addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", "none"); + if (one_explicit_color) + addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", c); + else + addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", "flat"); + endif +endif +addlistener (hg, "linewidth", @update_props); +addlistener (hg, "marker", @update_props); +addlistener (hg, "markerfacecolor", @update_props); +addlistener (hg, "markeredgecolor", @update_props); + +## Matlab property, although Octave does not implement it. +addproperty ("hittestarea", hg, "radio", "on|{off}", "off"); + +if (! isempty (newargs)) + set (hg, newargs{:}); +endif + +endfunction + +function render_size_color (hg, vert, s, c, marker, filled, isflat) + + if (isempty (c)) + c = __next_line_color__ (); + endif + + if (isscalar (s)) + x = vert(:,1); + y = vert(:,2); + z = vert(:,3:end); + toolkit = get (ancestor (hg, "figure"), "__graphics_toolkit__"); + ## Does gnuplot only support triangles with different vertex colors ? + ## FIXME: Verify gnuplot can only support one color. If RGB triplets + ## can be assigned to each vertex, then fix __gnuplot_draw_axes__.m + gnuplot_hack = (numel (x) > 1 && columns (c) == 3 + && strcmp (toolkit, "gnuplot")); + if (ischar (c) || ! isflat || gnuplot_hack) + if (filled) + ## "facecolor" and "edgecolor" must be set before any other properties + ## to skip co-planarity check (see bug #55751). + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x, "ydata", y, "zdata", z, + "faces", 1:numel (x), "vertices", vert, + "marker", marker, + "markeredgecolor", "none", + "markerfacecolor", c(1,:), + "markersize", s, "linestyle", "none"); + else + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x, "ydata", y, "zdata", z, + "faces", 1:numel (x), "vertices", vert, + "marker", marker, + "markeredgecolor", c(1,:), + "markerfacecolor", "none", + "markersize", s, "linestyle", "none"); + endif + else + if (filled) + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x, "ydata", y, "zdata", z, + "faces", 1:numel (x), "vertices", vert, + "marker", marker, "markersize", s, + "markeredgecolor", "none", + "markerfacecolor", "flat", + "cdata", c, "facevertexcdata", c, + "linestyle", "none"); + else + __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", + "xdata", x, "ydata", y, "zdata", z, + "faces", 1:numel (x), "vertices", vert, + "marker", marker, "markersize", s, + "markeredgecolor", "flat", + "markerfacecolor", "none", + "cdata", c, "facevertexcdata", c, + "linestyle", "none"); + endif + endif + else + ## Round size to one decimal place. + [ss, ~, s_to_ss] = unique (ceil (s*10) / 10); + for i = 1:rows (ss) + idx = (i == s_to_ss); + render_size_color (hg, vert(idx,:), ss(i), c, + marker, filled, isflat); + endfor + endif + +endfunction + +function update_props (h, ~) + + lw = get (h, "linewidth"); + m = get (h, "marker"); + fc = get (h, "markerfacecolor"); + ec = get (h, "markeredgecolor"); + kids = get (h, "children"); + + set (kids, "linewidth", lw, "marker", m, + "markerfacecolor", fc, "markeredgecolor", ec); + +endfunction + +## FIXME: This callback routine doesn't handle the case where N > 100. +function update_data (h, ~) + + x = get (h, "xdata"); + y = get (h, "ydata"); + z = get (h, "zdata"); + if (numel (x) > 100) + error ("scatter: cannot update data with more than 100 points. Call scatter (x, y, ...) with new data instead."); + endif + c = get (h, "cdata"); + one_explicit_color = ischar (c) || isequal (size (c), [1, 3]); + if (! one_explicit_color) + if (rows (c) == 1) + c = repmat (c, numel (x), 1); + endif + endif + filled = ! strcmp (get (h, "markerfacecolor"), "none"); + s = get (h, "sizedata"); + ## Size adjustment for visual compatibility with Matlab. + s = sqrt (s); + if (numel (s) == 1) + s = repmat (s, numel (x), 1); + endif + hlist = get (h, "children"); + + if (one_explicit_color) + if (filled) + if (isempty (z)) + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i)], + "markersize", s(i), + "markeredgecolor", c, "markerfacecolor", c); + + endfor + else + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i), z(i)], + "markersize", s(i), + "markeredgecolor", c, "markerfacecolor", c); + endfor + endif + else + if (isempty (z)) + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i)], + "markersize", s(i), + "markeredgecolor", c, "markerfacecolor", "none"); + + endfor + else + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i), z(i)], + "markersize", s(i), + "markeredgecolor", c, "markerfacecolor", "none"); + endfor + endif + endif + else + if (filled) + if (isempty (z)) + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i)], + "markersize", s(i), + "markeredgecolor", "none", "markerfacecolor", "flat", + "cdata", reshape (c(i,:),[1, size(c)(2:end)]), + "facevertexcdata", c(i,:)); + endfor + else + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i), z(i)], + "markersize", s(i), + "markeredgecolor", "none", "markerfacecolor", "flat", + "cdata", reshape (c(i,:),[1, size(c)(2:end)]), + "facevertexcdata", c(i,:)); + endfor + endif + else + if (isempty (z)) + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i)], + "markersize", s(i), + "markeredgecolor", "flat", "markerfacecolor", "none", + "cdata", reshape (c(i,:),[1, size(c)(2:end)]), + "facevertexcdata", c(i,:)); + endfor + else + for i = 1 : length (hlist) + set (hlist(i), "vertices", [x(i), y(i), z(i)], + "markersize", s(i), + "markeredgecolor", "flat", "markerfacecolor", "none", + "cdata", reshape (c(i,:),[1, size(c)(2:end)]), + "facevertexcdata", c(i,:)); + endfor + endif + endif + endif + +endfunction + diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__line__.m --- a/scripts/plot/draw/private/__line__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__line__.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,8 +24,8 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{h} =} __line__ (@var{parent}, @dots{}) -## Create line object with parent @var{parent}. +## @deftypefn {} {@var{h} =} __line__ (@var{hp}, @dots{}) +## Create line object with parent handle @var{hp}. ## ## Return handle @var{h} to created line objects. ## @end deftypefn diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__marching_cube__.m --- a/scripts/plot/draw/private/__marching_cube__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__marching_cube__.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,18 +24,18 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {[@var{t}, @var{p}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}) -## @deftypefnx {} {[@var{t}, @var{p}, @var{c}] =} __marching_cube__ (@var{x}, @var{y}, @var{z}, @var{val}, @var{iso}, @var{col}) +## @deftypefn {} {[@var{t}, @var{p}] =} __marching_cube__ (@var{xx}, @var{yy}, @var{zz}, @var{val}, @var{iso}) +## @deftypefnx {} {[@var{t}, @var{p}, @var{c}] =} __marching_cube__ (@var{xx}, @var{yy}, @var{zz}, @var{v}, @var{iso}, @var{colors}) ## ## Return the triangulation information @var{t} at points @var{p} for the -## isosurface values resp. the volume data @var{val} and the iso level -## @var{iso}. It is considered that the volume data @var{val} is given at -## the points @var{x}, @var{y} and @var{z} which are of type +## isosurface values resp. the volume data @var{v} and the iso level +## @var{iso}. It is considered that the volume data @var{v} is given at +## the points @var{xx}, @var{yy}, and @var{zz} which are of type ## three-dimensional numeric arrays. The orientation of the triangles is ## chosen such that the normals point from the higher values to the lower ## values. ## -## Optionally the color data @var{col} can be passed to this function +## Optionally the color data @var{colors} can be passed to this function ## whereas computed vertices color data @var{c} is returned as third ## argument. ## @@ -51,10 +51,10 @@ ## @group ## N = 20; ## lin = linspace (0, 2, N); -## [x, y, z] = meshgrid (lin, lin, lin); +## [xx, yy, zz] = meshgrid (lin, lin, lin); ## -## c = (x-.5).^2 + (y-.5).^2 + (z-.5).^2; -## [t, p] = __marching_cube__ (x, y, z, c, .5); +## v = (xx-.5).^2 + (yy-.5).^2 + (zz-.5).^2; +## [t, p] = __marching_cube__ (xx, yy, zz, v, .5); ## ## figure (); ## trimesh (t, p(:,1), p(:,2), p(:,3)); @@ -82,7 +82,7 @@ ## ## @end deftypefn -function [T, p, col] = __marching_cube__ (xx, yy, zz, c, iso, colors) +function [T, p, col] = __marching_cube__ (xx, yy, zz, v, iso, colors) persistent edge_table = []; persistent tri_table = []; @@ -94,19 +94,14 @@ [edge_table, tri_table] = init_mc (); endif - ## FIXME: Do we need all of the following validation on an internal function? - if ((nargin != 5 && nargin != 6) || (nargout != 2 && nargout != 3)) - print_usage (); + if (! isnumeric (xx) || ! isnumeric (yy) || ! isnumeric (zz) + || ! isnumeric (v) || ndims (xx) != 3 || ndims (yy) != 3 + || ndims (zz) != 3 || ndims (v) != 3) + error ("__marching_cube__: XX, YY, ZZ, v must be 3-D matrices"); endif - if (! isnumeric (xx) || ! isnumeric (yy) || ! isnumeric (zz) - || ! isnumeric (c) || ndims (xx) != 3 || ndims (yy) != 3 - || ndims (zz) != 3 || ndims (c) != 3) - error ("__marching_cube__: XX, YY, ZZ, C must be 3-D matrices"); - endif - - if (! size_equal (xx, yy, zz, c)) - error ("__marching_cube__: XX, YY, ZZ, C must be of equal size"); + if (! size_equal (xx, yy, zz, v)) + error ("__marching_cube__: XX, YY, ZZ, v must be of equal size"); endif if (any (size (xx) < [2 2 2])) @@ -118,14 +113,14 @@ endif if (nargin == 6) - if (! isnumeric (colors) || ndims (colors) != 3 || ! size_equal (colors, c)) - error ( "COLORS must be a 3-D matrix with the same size as C" ); + if (! isnumeric (colors) || ndims (colors) != 3 || ! size_equal (colors, v)) + error ( "COLORS must be a 3-D matrix with the same size as v" ); endif calc_cols = true; lindex = 5; endif - n = size (c) - 1; + n = size (v) - 1; ## phase I: assign information to each voxel which edges are intersected by ## the isosurface. @@ -143,7 +138,7 @@ ## calculate which vertices have values higher than iso for ii = 1:8 - idx = c(vertex_idx{ii, :}) > iso; + idx = v(vertex_idx{ii, :}) > iso; cc(idx) = bitset (cc(idx), ii); endfor @@ -157,7 +152,7 @@ ## phase II: calculate the list of intersection points xyz_off = [1, 1, 1; 2, 1, 1; 2, 2, 1; 1, 2, 1; 1, 1, 2; 2, 1, 2; 2, 2, 2; 1, 2, 2]; edges = [1 2; 2 3; 3 4; 4 1; 5 6; 6 7; 7 8; 8 5; 1 5; 2 6; 3 7; 4 8]; - offset = sub2ind (size (c), xyz_off(:, 1), xyz_off(:, 2), xyz_off(:, 3)) - 1; + offset = sub2ind (size (v), xyz_off(:, 1), xyz_off(:, 2), xyz_off(:, 3)) - 1; pp = zeros (length (id), lindex, 12); ccedge = [vec(cedge(id)), id]; ix_offset=0; @@ -165,16 +160,16 @@ id__ = bitget (ccedge(:, 1), jj); id_ = ccedge(id__, 2); [ix iy iz] = ind2sub (size (cc), id_); - id_c = sub2ind (size (c), ix, iy, iz); + id_c = sub2ind (size (v), ix, iy, iz); id1 = id_c + offset(edges(jj, 1)); id2 = id_c + offset(edges(jj, 2)); if (calc_cols) pp(id__, 1:5, jj) = [vertex_interp(iso, xx(id1), yy(id1), zz(id1), ... - xx(id2), yy(id2), zz(id2), c(id1), c(id2), colors(id1), colors(id2)), ... + xx(id2), yy(id2), zz(id2), v(id1), v(id2), colors(id1), colors(id2)), ... (1:rows (id_))' + ix_offset ]; else pp(id__, 1:4, jj) = [vertex_interp(iso, xx(id1), yy(id1), zz(id1), ... - xx(id2), yy(id2), zz(id2), c(id1), c(id2)), ... + xx(id2), yy(id2), zz(id2), v(id1), v(id2)), ... (1:rows (id_))' + ix_offset ]; endif ix_offset += rows (id_); @@ -245,38 +240,38 @@ function [edge_table, tri_table] = init_mc () edge_table = [ - 0x0 , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, ... - 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, ... - 0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, ... - 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, ... - 0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c, ... - 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30, ... - 0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac, ... - 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0, ... - 0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c, ... - 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60, ... - 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc, ... - 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, ... - 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c, ... - 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950, ... - 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc , ... - 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, ... - 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc, ... - 0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0, ... - 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, ... - 0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650, ... - 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, ... - 0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, ... - 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, ... - 0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460, ... - 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, ... - 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0, ... - 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, ... - 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230, ... - 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c, ... - 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190, ... - 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, ... - 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 ]; + 0x0000, 0x0109, 0x0203, 0x030a, 0x0406, 0x050f, 0x0605, 0x070c, ... + 0x080c, 0x0905, 0x0a0f, 0x0b06, 0x0c0a, 0x0d03, 0x0e09, 0x0f00, ... + 0x0190, 0x0099, 0x0393, 0x029a, 0x0596, 0x049f, 0x0795, 0x069c, ... + 0x099c, 0x0895, 0x0b9f, 0x0a96, 0x0d9a, 0x0c93, 0x0f99, 0x0e90, ... + 0x0230, 0x0339, 0x0033, 0x013a, 0x0636, 0x073f, 0x0435, 0x053c, ... + 0x0a3c, 0x0b35, 0x083f, 0x0936, 0x0e3a, 0x0f33, 0x0c39, 0x0d30, ... + 0x03a0, 0x02a9, 0x01a3, 0x00aa, 0x07a6, 0x06af, 0x05a5, 0x04ac, ... + 0x0bac, 0x0aa5, 0x09af, 0x08a6, 0x0faa, 0x0ea3, 0x0da9, 0x0ca0, ... + 0x0460, 0x0569, 0x0663, 0x076a, 0x0066, 0x016f, 0x0265, 0x036c, ... + 0x0c6c, 0x0d65, 0x0e6f, 0x0f66, 0x086a, 0x0963, 0x0a69, 0x0b60, ... + 0x05f0, 0x04f9, 0x07f3, 0x06fa, 0x01f6, 0x00ff, 0x03f5, 0x02fc, ... + 0x0dfc, 0x0cf5, 0x0fff, 0x0ef6, 0x09fa, 0x08f3, 0x0bf9, 0x0af0, ... + 0x0650, 0x0759, 0x0453, 0x055a, 0x0256, 0x035f, 0x0055, 0x015c, ... + 0x0e5c, 0x0f55, 0x0c5f, 0x0d56, 0x0a5a, 0x0b53, 0x0859, 0x0950, ... + 0x07c0, 0x06c9, 0x05c3, 0x04ca, 0x03c6, 0x02cf, 0x01c5, 0x00cc, ... + 0x0fcc, 0x0ec5, 0x0dcf, 0x0cc6, 0x0bca, 0x0ac3, 0x09c9, 0x08c0, ... + 0x08c0, 0x09c9, 0x0ac3, 0x0bca, 0x0cc6, 0x0dcf, 0x0ec5, 0x0fcc, ... + 0x00cc, 0x01c5, 0x02cf, 0x03c6, 0x04ca, 0x05c3, 0x06c9, 0x07c0, ... + 0x0950, 0x0859, 0x0b53, 0x0a5a, 0x0d56, 0x0c5f, 0x0f55, 0x0e5c, ... + 0x015c, 0x0055, 0x035f, 0x0256, 0x055a, 0x0453, 0x0759, 0x0650, ... + 0x0af0, 0x0bf9, 0x08f3, 0x09fa, 0x0ef6, 0x0fff, 0x0cf5, 0x0dfc, ... + 0x02fc, 0x03f5, 0x00ff, 0x01f6, 0x06fa, 0x07f3, 0x04f9, 0x05f0, ... + 0x0b60, 0x0a69, 0x0963, 0x086a, 0x0f66, 0x0e6f, 0x0d65, 0x0c6c, ... + 0x036c, 0x0265, 0x016f, 0x0066, 0x076a, 0x0663, 0x0569, 0x0460, ... + 0x0ca0, 0x0da9, 0x0ea3, 0x0faa, 0x08a6, 0x09af, 0x0aa5, 0x0bac, ... + 0x04ac, 0x05a5, 0x06af, 0x07a6, 0x00aa, 0x01a3, 0x02a9, 0x03a0, ... + 0x0d30, 0x0c39, 0x0f33, 0x0e3a, 0x0936, 0x083f, 0x0b35, 0x0a3c, ... + 0x053c, 0x0435, 0x073f, 0x0636, 0x013a, 0x0033, 0x0339, 0x0230, ... + 0x0e90, 0x0f99, 0x0c93, 0x0d9a, 0x0a96, 0x0b9f, 0x0895, 0x099c, ... + 0x069c, 0x0795, 0x049f, 0x0596, 0x029a, 0x0393, 0x0099, 0x0190, ... + 0x0f00, 0x0e09, 0x0d03, 0x0c0a, 0x0b06, 0x0a0f, 0x0905, 0x080c, ... + 0x070c, 0x0605, 0x050f, 0x0406, 0x030a, 0x0203, 0x0109, 0x0000 ]; tri_table = [ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__pie__.m --- a/scripts/plot/draw/private/__pie__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__pie__.m Thu Nov 19 13:08:00 2020 -0800 @@ -130,7 +130,7 @@ hlist = [hlist; patch(xoff + [0, -sind(xn)], yoff + [0, cosd(xn)], zeros (1, ln + 1), i); - surface(sx, sy, sz, sc); + surface (sx, sy, sz, sc); patch(xoff + [0, -sind(xn)], yoff + [0, cosd(xn)], zlvl * ones (1, ln + 1), i); text(xt, yt, zlvl, labels{i})]; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__plt__.m --- a/scripts/plot/draw/private/__plt__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__plt__.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,7 +24,7 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {} __plt__ (@var{caller}, @var{hparent}, @var{varargin}) +## @deftypefn {} {} __plt__ (@var{caller}, @var{hp}, @var{varargin}) ## Undocumented internal function. ## @end deftypefn @@ -33,125 +33,124 @@ persistent warned_callers = {}; nargs = nargin - 2; - if (nargs > 0) + if (nargs < 1) + error ("__plt__: invalid number of arguments"); + endif - k = 1; + k = 1; - x_set = false; - y_set = false; - property_set = false; - properties = {}; + x_set = false; + y_set = false; + property_set = false; + properties = {}; + + ## Find any legend associated with this axes + try + hlegend = get (hp, "__legend_handle__"); + catch + hlegend = []; + end_try_catch - ## Find any legend associated with this axes - try - hlegend = get (hp, "__legend_handle__"); - catch - hlegend = []; - end_try_catch + setlgnd = false; + if (isempty (hlegend)) + hlgnd = []; + tlgnd = {}; + else + [hlgnd, tlgnd] = __getlegenddata__ (hlegend); + endif + + ## Gather arguments, decode format, gather plot strings, and plot lines. - setlgnd = false; - if (isempty (hlegend)) - hlgnd = []; - tlgnd = {}; + retval = []; + + while (nargs > 0 || x_set) + + if (nargs == 0) + ## Force the last plot when input variables run out. + next_cell = {}; + next_arg = {""}; else - [hlgnd, tlgnd] = __getlegenddata__ (hlegend); + next_cell = varargin(k); + next_arg = varargin{k++}; endif - ## Gather arguments, decode format, gather plot strings, and plot lines. - - retval = []; - - while (nargs > 0 || x_set) - - if (nargs == 0) - ## Force the last plot when input variables run out. - next_cell = {}; - next_arg = {""}; - else - next_cell = varargin(k); - next_arg = varargin{k++}; + if (isnumeric (next_arg) && ndims (next_arg) > 2 + && any (size (next_arg) == 1)) + next_arg = squeeze (next_arg); + if (! any (strcmp (caller, warned_callers)) && ndims (next_arg) < 3) + warning (["%s: N-d inputs have been squeezed to less than " ... + "three dimensions"], caller); + warned_callers(end+1) = caller; endif + endif + if (isnumeric (next_arg) && ndims (next_arg) > 2) + error ("%s: plot arrays must have less than 2 dimensions", caller); + endif - if (isnumeric (next_arg) && ndims (next_arg) > 2 - && any (size (next_arg) == 1)) - next_arg = squeeze (next_arg); - if (! any (strcmp (caller, warned_callers)) && ndims (next_arg) < 3) - warning (["%s: N-d inputs have been squeezed to less than " ... - "three dimensions"], caller); - warned_callers(end+1) = caller; - endif - endif - if (isnumeric (next_arg) && ndims (next_arg) > 2) - error ("%s: plot arrays must have less than 2 dimensions", caller); - endif - - nargs -= 1; + nargs -= 1; - if (ischar (next_arg) || iscellstr (next_arg)) - if (x_set) - [options, valid] = __pltopt__ (caller, next_arg, false); - if (! valid) - if (nargs == 0) - error ("%s: properties must appear followed by a value", caller); - endif - properties = [properties, [next_cell, varargin(k++)]]; - nargs -= 1; - continue; - else - while (nargs > 0 && ischar (varargin{k})) - if (nargs < 2) - error ("%s: properties must appear followed by a value", - caller); - endif - properties = [properties, varargin(k:k+1)]; - k += 2; - nargs -= 2; - endwhile + if (ischar (next_arg) || iscellstr (next_arg)) + if (x_set) + [options, valid] = __pltopt__ (caller, next_arg, false); + if (! valid) + if (nargs == 0) + error ("%s: properties must appear followed by a value", caller); endif - if (y_set) - htmp = __plt2__ (hp, x, y, options, properties); - [hlgnd, tlgnd, setlgnd] = ... - __plt_key__ (htmp, options, hlgnd, tlgnd, setlgnd); - properties = {}; - retval = [retval; htmp]; - else - htmp = __plt1__ (hp, x, options, properties); - [hlgnd, tlgnd, setlgnd] = ... - __plt_key__ (htmp, options, hlgnd, tlgnd, setlgnd); - properties = {}; - retval = [retval; htmp]; - endif - x_set = false; - y_set = false; + properties = [properties, [next_cell, varargin(k++)]]; + nargs -= 1; + continue; else - error ("plot: no data to plot"); + while (nargs > 0 && ischar (varargin{k})) + if (nargs < 2) + error ("%s: properties must appear followed by a value", + caller); + endif + properties = [properties, varargin(k:k+1)]; + k += 2; + nargs -= 2; + endwhile endif - elseif (x_set) if (y_set) - options = __pltopt__ (caller, {""}); htmp = __plt2__ (hp, x, y, options, properties); [hlgnd, tlgnd, setlgnd] = ... __plt_key__ (htmp, options, hlgnd, tlgnd, setlgnd); + properties = {}; retval = [retval; htmp]; - x = next_arg; - y_set = false; - properties = {}; else - y = next_arg; - y_set = true; + htmp = __plt1__ (hp, x, options, properties); + [hlgnd, tlgnd, setlgnd] = ... + __plt_key__ (htmp, options, hlgnd, tlgnd, setlgnd); + properties = {}; + retval = [retval; htmp]; endif + x_set = false; + y_set = false; else + error ("plot: no data to plot"); + endif + elseif (x_set) + if (y_set) + options = __pltopt__ (caller, {""}); + htmp = __plt2__ (hp, x, y, options, properties); + [hlgnd, tlgnd, setlgnd] = ... + __plt_key__ (htmp, options, hlgnd, tlgnd, setlgnd); + retval = [retval; htmp]; x = next_arg; - x_set = true; + y_set = false; + properties = {}; + else + y = next_arg; + y_set = true; endif - - endwhile + else + x = next_arg; + x_set = true; + endif - if (setlgnd) - legend (gca (), hlgnd, tlgnd); - endif - else - error ("__plt__: invalid number of arguments"); + endwhile + + if (setlgnd) + legend (gca (), hlgnd, tlgnd); endif endfunction @@ -365,6 +364,7 @@ retval = __go_line__ (hp, "xdata", x, "ydata", y, "color", color, "linestyle", linestyle, "marker", marker, properties{:}); + endfunction function retval = __plt2sv__ (hp, x, y, options, properties = {}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__scatter__.m --- a/scripts/plot/draw/private/__scatter__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__scatter__.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,13 +24,13 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{hg} =} __scatter__ (@dots{}) +## @deftypefn {} {@var{hs} =} __scatter__ (@dots{}) ## Undocumented internal function. ## @end deftypefn -function hg = __scatter__ (varargin) +function hs = __scatter__ (varargin) - hax = varargin{1}; # We don't do anything with this. Could remove it. + hax = varargin{1}; nd = varargin{2}; fcn = varargin{3}; x = varargin{4}(:); @@ -108,7 +108,7 @@ x(idx) = []; y(idx) = []; if (nd == 2) - z = zeros (length (x), 0); + z = zeros (numel (x), 0); endif if (numel (s) > 1) s(idx) = []; @@ -169,311 +169,58 @@ endif endwhile - if (isempty (c)) - c = __next_line_color__ (); - endif + if (strcmp ("gnuplot", graphics_toolkit ())) + ## Legacy code using patch for gnuplot toolkit + hs = __gnuplot_scatter__ (hax, fcn, x, y, z, c, s, marker, filled, newargs); - ## Must occur after __next_line_color__ in order to work correctly. - hg = hggroup ("__appdata__", struct ("__creator__", "__scatter__")); - newargs = __add_datasource__ (fcn, hg, {"x", "y", "z", "c", "size"}, - newargs{:}); - - addproperty ("xdata", hg, "data", x); - addproperty ("ydata", hg, "data", y); - addproperty ("zdata", hg, "data", z); - if (ischar (c)) - ## For single explicit color, cdata is unused - addproperty ("cdata", hg, "data", []); else - addproperty ("cdata", hg, "data", c); - endif - addproperty ("sizedata", hg, "data", s); - addlistener (hg, "xdata", @update_data); - addlistener (hg, "ydata", @update_data); - addlistener (hg, "zdata", @update_data); - addlistener (hg, "cdata", @update_data); - addlistener (hg, "sizedata", @update_data); - - one_explicit_color = ischar (c) || isequal (size (c), [1, 3]); - s = sqrt (s); # size adjustment for visual compatibility w/Matlab - - if (numel (x) <= 100) - - ## For small number of points, we'll construct an object for each point. - - if (numel (s) == 1) - s = repmat (s, numel (x), 1); + ## Use OpenGL rendering for "qt" and "fltk" graphics toolkits + if (isempty (x)) + c = x; + endif + if (ischar (c)) + c = str2rgb (c); + endif + if (isempty (c)) + cdata_args = {}; + else + cdata_args = {"cdata", c}; + endif + if (filled) + filled_args = {"markeredgecolor", "none", "markerfacecolor", "flat"}; + else + filled_args = {}; endif - if (one_explicit_color) - for i = 1 : numel (x) - if (filled) - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x(i), "ydata", y(i), "zdata", z(i,:), - "faces", 1, "vertices", [x(i), y(i), z(i,:)], - "marker", marker, "markersize", s(i), - "markeredgecolor", c, "markerfacecolor", c, - "linestyle", "none"); - else - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x(i), "ydata", y(i), "zdata", z(i,:), - "faces", 1, "vertices", [x(i), y(i), z(i,:)], - "marker", marker, "markersize", s(i), - "markeredgecolor", c, "markerfacecolor", "none", - "linestyle", "none"); - endif - endfor - else - if (rows (c) == 1) - c = repmat (c, rows (x), 1); - endif - for i = 1 : numel (x) - if (filled) - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x(i), "ydata", y(i), "zdata", z(i,:), - "faces", 1, "vertices", [x(i), y(i), z(i,:)], - "marker", marker, "markersize", s(i), - "markeredgecolor", "none", - "markerfacecolor", "flat", - "cdata", c(i,:), "facevertexcdata", c(i,:), - "linestyle", "none"); - else - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x(i), "ydata", y(i), "zdata", z(i,:), - "faces", 1, "vertices", [x(i), y(i), z(i,:)], - "marker", marker, "markersize", s(i), - "markeredgecolor", "flat", - "markerfacecolor", "none", - "cdata", c(i,:), "facevertexcdata", c(i,:), - "linestyle", "none"); - endif - endfor - endif - - else - - ## For larger numbers of points, we use one single object. - vert = [x, y, z]; - render_size_color (hg, vert, s, c, marker, filled, true); - - endif - - if (! ischar (c) && rows (c) > 1) - ax = get (hg, "parent"); - clim = get (ax, "clim"); - if (min (c(:)) < clim(1)) - clim(1) = min (c(:)); - set (ax, "clim", clim); - endif - if (max (c(:)) > clim(2)) - set (ax, "clim", [clim(1), max(c(:))]); - endif - endif - - addproperty ("linewidth", hg, "patchlinewidth", 0.5); - addproperty ("marker", hg, "patchmarker", marker); - if (filled) - addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", "none"); - if (one_explicit_color) - addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", c); - else - addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", "flat"); - endif - else - addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", "none"); - if (one_explicit_color) - addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", c); - else - addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", "flat"); - endif - endif - addlistener (hg, "linewidth", @update_props); - addlistener (hg, "marker", @update_props); - addlistener (hg, "markerfacecolor", @update_props); - addlistener (hg, "markeredgecolor", @update_props); - - ## Matlab property, although Octave does not implement it. - addproperty ("hittestarea", hg, "radio", "on|{off}", "off"); - - if (! isempty (newargs)) - set (hg, newargs{:}); + hs = __go_scatter__ (hax, "xdata", x(:), "ydata", y(:), "zdata", z(:), + cdata_args{:}, "sizedata", s(:), "marker", marker, + filled_args{:}, newargs{:}); endif endfunction -function render_size_color (hg, vert, s, c, marker, filled, isflat) + +function rgb = str2rgb (str) + ## Convert a color code to the corresponding RGB values + rgb = []; - if (isscalar (s)) - x = vert(:,1); - y = vert(:,2); - z = vert(:,3:end); - toolkit = get (ancestor (hg, "figure"), "__graphics_toolkit__"); - ## Does gnuplot only support triangles with different vertex colors ? - ## FIXME: Verify gnuplot can only support one color. If RGB triplets - ## can be assigned to each vertex, then fix __gnuplot_draw_axes__.m - gnuplot_hack = (numel (x) > 1 && columns (c) == 3 - && strcmp (toolkit, "gnuplot")); - if (ischar (c) || ! isflat || gnuplot_hack) - if (filled) - ## "facecolor" and "edgecolor" must be set before any other properties - ## to skip co-planarity check (see bug #55751). - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x, "ydata", y, "zdata", z, - "faces", 1:numel (x), "vertices", vert, - "marker", marker, - "markeredgecolor", "none", - "markerfacecolor", c(1,:), - "markersize", s, "linestyle", "none"); - else - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x, "ydata", y, "zdata", z, - "faces", 1:numel (x), "vertices", vert, - "marker", marker, - "markeredgecolor", c(1,:), - "markerfacecolor", "none", - "markersize", s, "linestyle", "none"); - endif - else - if (filled) - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x, "ydata", y, "zdata", z, - "faces", 1:numel (x), "vertices", vert, - "marker", marker, "markersize", s, - "markeredgecolor", "none", - "markerfacecolor", "flat", - "cdata", c, "facevertexcdata", c, - "linestyle", "none"); - else - __go_patch__ (hg, "facecolor", "none", "edgecolor", "none", - "xdata", x, "ydata", y, "zdata", z, - "faces", 1:numel (x), "vertices", vert, - "marker", marker, "markersize", s, - "markeredgecolor", "flat", - "markerfacecolor", "none", - "cdata", c, "facevertexcdata", c, - "linestyle", "none"); - endif - endif - else - ## Round size to one decimal place. - [ss, ~, s_to_ss] = unique (ceil (s*10) / 10); - for i = 1:rows (ss) - idx = (i == s_to_ss); - render_size_color (hg, vert(idx,:), ss(i), c, - marker, filled, isflat); - endfor - endif - -endfunction - -function update_props (h, d) - - lw = get (h, "linewidth"); - m = get (h, "marker"); - fc = get (h, "markerfacecolor"); - ec = get (h, "markeredgecolor"); - kids = get (h, "children"); - - set (kids, "linewidth", lw, "marker", m, - "markerfacecolor", fc, "markeredgecolor", ec); + switch (str) + case 'b' + rgb = [0, 0, 1]; + case 'k' + rgb = [0, 0, 0]; + case 'r' + rgb = [1, 0, 0]; + case 'g' + rgb = [0, 1, 0]; + case 'y' + rgb = [1, 1, 0]; + case 'm' + rgb = [1, 0, 1]; + case 'c' + rgb = [0, 1, 1]; + case 'w' + rgb = [1, 1, 1]; +endswitch endfunction - -## FIXME: This callback routine doesn't handle the case where N > 100. -function update_data (h, d) - - x = get (h, "xdata"); - y = get (h, "ydata"); - z = get (h, "zdata"); - if (numel (x) > 100) - error ("scatter: cannot update data with more than 100 points. Call scatter (x, y, ...) with new data instead."); - endif - c = get (h, "cdata"); - one_explicit_color = ischar (c) || isequal (size (c), [1, 3]); - if (! one_explicit_color) - if (rows (c) == 1) - c = repmat (c, numel (x), 1); - endif - endif - filled = ! strcmp (get (h, "markerfacecolor"), "none"); - s = get (h, "sizedata"); - ## Size adjustment for visual compatibility with Matlab. - s = sqrt (s); - if (numel (s) == 1) - s = repmat (s, numel (x), 1); - endif - hlist = get (h, "children"); - - if (one_explicit_color) - if (filled) - if (isempty (z)) - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i)], - "markersize", s(i), - "markeredgecolor", c, "markerfacecolor", c); - - endfor - else - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i), z(i)], - "markersize", s(i), - "markeredgecolor", c, "markerfacecolor", c); - endfor - endif - else - if (isempty (z)) - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i)], - "markersize", s(i), - "markeredgecolor", c, "markerfacecolor", "none"); - - endfor - else - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i), z(i)], - "markersize", s(i), - "markeredgecolor", c, "markerfacecolor", "none"); - endfor - endif - endif - else - if (filled) - if (isempty (z)) - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i)], - "markersize", s(i), - "markeredgecolor", "none", "markerfacecolor", "flat", - "cdata", reshape (c(i,:),[1, size(c)(2:end)]), - "facevertexcdata", c(i,:)); - endfor - else - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i), z(i)], - "markersize", s(i), - "markeredgecolor", "none", "markerfacecolor", "flat", - "cdata", reshape (c(i,:),[1, size(c)(2:end)]), - "facevertexcdata", c(i,:)); - endfor - endif - else - if (isempty (z)) - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i)], - "markersize", s(i), - "markeredgecolor", "flat", "markerfacecolor", "none", - "cdata", reshape (c(i,:),[1, size(c)(2:end)]), - "facevertexcdata", c(i,:)); - endfor - else - for i = 1 : length (hlist) - set (hlist(i), "vertices", [x(i), y(i), z(i)], - "markersize", s(i), - "markeredgecolor", "flat", "markerfacecolor", "none", - "cdata", reshape (c(i,:),[1, size(c)(2:end)]), - "facevertexcdata", c(i,:)); - endfor - endif - endif - endif - -endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/private/__unite_shared_vertices__.m --- a/scripts/plot/draw/private/__unite_shared_vertices__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/private/__unite_shared_vertices__.m Thu Nov 19 13:08:00 2020 -0800 @@ -55,7 +55,7 @@ [J, idx] = sort (J); j(idx) = 1:length (idx); vertices = vertices(idx,:); - if any (nan_vertices) + if (any (nan_vertices)) j(end+1) = length (idx) + 1; vertices(end+1,:) = NaN; lut(nan_vertices) = rows (vertices); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/rectangle.m --- a/scripts/plot/draw/rectangle.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/rectangle.m Thu Nov 19 13:08:00 2020 -0800 @@ -107,7 +107,7 @@ pos = varargin{iarg+1}; varargin(iarg:iarg+1) = []; if (! isvector (pos) || numel (pos) != 4) - error ("rectangle: position must be a 4 element vector"); + error ("rectangle: position must be a 4-element vector"); endif elseif (strcmpi (arg, "curvature")) curv2 = varargin{iarg+1}; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/reducepatch.m --- a/scripts/plot/draw/reducepatch.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/reducepatch.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,7 +39,8 @@ ## The input patch can be represented by a structure @var{fv} with the ## fields @code{faces} and @code{vertices}, by two matrices @var{faces} and ## @var{vertices} (see, e.g., the result of @code{isosurface}), or by a -## handle to a patch object @var{patch_handle} (@pxref{XREFpatch,,patch}). +## handle to a patch object @var{patch_handle} +## (@pxref{XREFpatch,,@code{patch}}). ## ## The number of faces and vertices in the patch is reduced by iteratively ## collapsing the shortest edge of the patch to its midpoint (as discussed, @@ -363,7 +364,7 @@ %! patch (fv, "FaceColor", "g"); %! view (3); axis equal; %! title ("Sphere with all faces"); -%! ax2 = subplot(1, 2, 2); +%! ax2 = subplot (1, 2, 2); %! patch (reducepatch (fv, 72), "FaceColor", "g"); %! view (3); axis equal; %! title ("Sphere with reduced number of faces"); @@ -438,8 +439,8 @@ %! assert (size (vertices_reduced, 2), 3); ## test for each error -%!error reducepatch () -%!error reducepatch (fv, faces, vertices, .5, "f", "v") +%!error <Invalid call> reducepatch () +%!error <Invalid call> reducepatch (fv, faces, vertices, .5, "f", "v") %!error <reducepatch: parameter 'foo' not supported> %! fv_reduced = reducepatch (faces, vertices, .7, "foo"); %!error <struct FV must contain the fields 'vertices' and 'faces'> diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/reducevolume.m --- a/scripts/plot/draw/reducevolume.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/reducevolume.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,8 @@ ## Optionally, @var{x}, @var{y}, and @var{z} can be supplied to represent the ## set of coordinates of @var{v}. They can either be matrices of the same size ## as @var{v} or vectors with sizes according to the dimensions of @var{v}, in -## which case they are expanded to matrices (@pxref{XREFmeshgrid,,meshgrid}). +## which case they are expanded to matrices +## (@pxref{XREFmeshgrid,,@code{meshgrid}}). ## ## If @code{reducevolume} is called with two arguments then @var{x}, @var{y}, ## and @var{z} are assumed to match the respective indices of @var{v}. @@ -263,9 +264,9 @@ ## Test for each error %!test -%!error reducevolume () -%!error reducevolume (1) -%!error reducevolume (1,2,3,4,5,6) +%!error <Invalid call> reducevolume () +%!error <Invalid call> reducevolume (1) +%!error <Invalid call> reducevolume (1,2,3,4,5,6) %!error <incorrect number of arguments> reducevolume (1, 2, 3) %!error <R must be a scalar or a vector of length 3> reducevolume (v, []) %!error <R must be a scalar or a vector of length 3> reducevolume (v, [1 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/ribbon.m --- a/scripts/plot/draw/ribbon.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/ribbon.m Thu Nov 19 13:08:00 2020 -0800 @@ -60,7 +60,7 @@ if (isvector (y)) y = y(:); endif - x = 1:rows(y); + x = 1:rows (y); width = 0.75; elseif (nargin == 2) x = varargin{1}; @@ -122,6 +122,6 @@ %! colormap ("default"); %! [x, y, z] = sombrero (); %! ribbon (y, z); -%! title ("ribbon() plot of sombrero()"); +%! title ("ribbon() plot of sombrero ()"); %!FIXME: Could have some input validation tests here diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/rose.m --- a/scripts/plot/draw/rose.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/rose.m Thu Nov 19 13:08:00 2020 -0800 @@ -72,7 +72,7 @@ [hax, varargin, nargin] = __plt_get_axis_arg__ ("rose", varargin{:}); - if (nargin < 1) + if (nargin < 1 || nargin > 2) print_usage (); endif @@ -166,7 +166,8 @@ %! title ("rose() angular histogram plot with specified bins"); ## Test input validation -%!error rose () +%!error <Invalid call> rose () +%!error <Invalid call> rose (1,2,3) %!warning <bin sizes .= pi will not plot correctly> %! [th, r] = rose ([1 2 2 4 4 4], 2); %!warning <bin 1 and bin 3 are not centered> diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/scatter.m --- a/scripts/plot/draw/scatter.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/scatter.m Thu Nov 19 13:08:00 2020 -0800 @@ -53,10 +53,6 @@ ## If no marker is specified it defaults to @qcode{"o"} or circles. ## If the argument @qcode{"filled"} is given then the markers are filled. ## -## Additional property/value pairs are passed directly to the underlying -## patch object. The full list of properties is documented at -## @ref{Patch Properties}. -## ## If the first argument @var{hax} is an axes handle, then plot into this axes, ## rather than the current axes returned by @code{gca}. ## @@ -73,6 +69,8 @@ ## @end group ## @end example ## +## Programming Note: The full list of properties is documented at +## @ref{Scatter Properties}. ## @seealso{scatter3, patch, plot} ## @end deftypefn @@ -220,3 +218,20 @@ %! title (str); %! endfor %! endfor + + +%!testif ; ! strcmp (graphics_toolkit (), "gnuplot") +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hs = scatter ([], []); +%! assert (get (hs, "type"), "scatter"); +%! assert (isempty (get (hs, "xdata"))); +%! assert (isempty (get (hs, "ydata"))); +%! assert (isempty (get (hs, "zdata"))); +%! assert (get (hs, "cdata"), [0, 0.4470, 0.7410]); +%! assert (get (hs, "cdatamode"), "auto"); +%! assert (get (hs, "sizedata"), 36); +%! assert (get (hs, "linewidth"), 0.5); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/scatter3.m --- a/scripts/plot/draw/scatter3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/scatter3.m Thu Nov 19 13:08:00 2020 -0800 @@ -53,14 +53,10 @@ ## If no marker is specified it defaults to @qcode{"o"} or circles. ## If the argument @qcode{"filled"} is given then the markers are filled. ## -## Additional property/value pairs are passed directly to the underlying -## patch object. The full list of properties is documented at -## @ref{Patch Properties}. -## ## If the first argument @var{hax} is an axes handle, then plot into this axes, ## rather than the current axes returned by @code{gca}. ## -## The optional return value @var{h} is a graphics handle to the hggroup +## The optional return value @var{h} is a graphics handle to the scatter ## object representing the points. ## ## @example @@ -70,6 +66,8 @@ ## @end group ## @end example ## +## Programming Note: The full list of properties is documented at +## @ref{Scatter Properties}. ## @seealso{scatter, patch, plot} ## @end deftypefn diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/semilogx.m --- a/scripts/plot/draw/semilogx.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/semilogx.m Thu Nov 19 13:08:00 2020 -0800 @@ -104,12 +104,12 @@ %! %! subplot (1,2,1); %! semilogx (x, y); -%! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition"); +%! set (gca, "xdir", "reverse", "positionconstraint", "outerposition"); %! title ({"semilogx (x, y)", "xdir = reversed"}); %! %! subplot (1,2,2); %! semilogx (-x, y); -%! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition"); +%! set (gca, "xdir", "reverse", "positionconstraint", "outerposition"); %! title ({"semilogx (-x, y)", "xdir = reversed"}); %!test diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/semilogxerr.m --- a/scripts/plot/draw/semilogxerr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/semilogxerr.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,8 +47,8 @@ ## @noindent ## which produces a semi-logarithmic plot of @var{y} versus @var{x} ## with errors in the @var{y}-scale defined by @var{ey} and the plot -## format defined by @var{fmt}. @xref{XREFerrorbar,,errorbar}, for available -## formats and additional information. +## format defined by @var{fmt}. @xref{XREFerrorbar,,@code{errorbar}}, for +## available formats and additional information. ## ## If the first argument @var{hax} is an axes handle, then plot into this axes, ## rather than the current axes returned by @code{gca}. diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/semilogy.m --- a/scripts/plot/draw/semilogy.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/semilogy.m Thu Nov 19 13:08:00 2020 -0800 @@ -104,12 +104,12 @@ %! %! subplot (2,1,1); %! semilogy (x, y); -%! set (gca, "ydir", "reverse", "activepositionproperty", "outerposition"); +%! set (gca, "ydir", "reverse", "positionconstraint", "outerposition"); %! title ({"semilogy (x, y)", "ydir = reversed"}); %! %! subplot (2,1,2); %! semilogy (x, -y); -%! set (gca, "ydir", "reverse", "activepositionproperty", "outerposition"); +%! set (gca, "ydir", "reverse", "positionconstraint", "outerposition"); %! title ({"semilogy (x, -y)", "ydir = reversed"}); %!test diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/semilogyerr.m --- a/scripts/plot/draw/semilogyerr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/semilogyerr.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,8 +47,8 @@ ## @noindent ## which produces a semi-logarithmic plot of @var{y} versus @var{x} ## with errors in the @var{y}-scale defined by @var{ey} and the plot -## format defined by @var{fmt}. @xref{XREFerrorbar,,errorbar}, for available -## formats and additional information. +## format defined by @var{fmt}. @xref{XREFerrorbar,,@code{errorbar}}, for +## available formats and additional information. ## ## If the first argument @var{hax} is an axes handle, then plot into this axes, ## rather than the current axes returned by @code{gca}. diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/shrinkfaces.m --- a/scripts/plot/draw/shrinkfaces.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/shrinkfaces.m Thu Nov 19 13:08:00 2020 -0800 @@ -73,7 +73,7 @@ function [nf, nv] = shrinkfaces (varargin) - if (nargin < 1 || nargin > 3 || nargout > 2) + if (nargin < 1 || nargin > 3) print_usage (); endif @@ -215,7 +215,7 @@ %! axis auto; # Kludge required for Octave %! axis equal; %! view (115, 30); -%! drawnow; +%! drawnow (); %! shrinkfaces (p, 0.6); %! title ("shrinkfaces() on 3-D complex shapes"); @@ -231,8 +231,8 @@ %!assert (norm (nfv2.vertices - vertices), 0, 2*eps) ## Test input validation -%!error shrinkfaces () -%!error shrinkfaces (1,2,3,4) +%!error <Invalid call> shrinkfaces () +%!error <Invalid call> shrinkfaces (1,2,3,4) %!error [a,b,c] = shrinkfaces (1) %!error <scale factor must be a positive scalar> shrinkfaces (nfv, ones (2)) %!error <scale factor must be a positive scalar> shrinkfaces (nfv, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/smooth3.m --- a/scripts/plot/draw/smooth3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/smooth3.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,7 +65,7 @@ function smoothed_data = smooth3 (data, method = "box", sz = 3, std_dev = 0.65) - if (nargin < 1 || nargin > 4) + if (nargin < 1) print_usage (); endif @@ -257,8 +257,7 @@ %! assert (size_equal (a, b), true); ## Test input validation -%!error smooth3 () -%!error smooth3 (1,2,3,4,5) +%!error <Invalid call> smooth3 () %!error <DATA must be a 3-D numeric matrix> smooth3 (cell (2,2,2)) %!error <DATA must be a 3-D numeric matrix> smooth3 (1) %!error <METHOD must be a string> smooth3 (ones (2,2,2), {3}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/sombrero.m --- a/scripts/plot/draw/sombrero.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/sombrero.m Thu Nov 19 13:08:00 2020 -0800 @@ -56,9 +56,7 @@ function [x, y, z] = sombrero (n = 41) - if (nargin > 2) - print_usage (); - elseif (n <= 1) + if (n <= 1) error ("sombrero: number of grid lines N must be greater than 1"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/stairs.m --- a/scripts/plot/draw/stairs.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/stairs.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ ## of the same format as the @code{plot} command. ## ## Multiple property/value pairs may be specified, but they must appear in -## pairs. The full list of properties is documented at +## pairs. The full list of properties is documented at ## @ref{Line Properties}. ## ## If the first argument @var{hax} is an axes handle, then plot into this axes, @@ -329,9 +329,9 @@ ## Invisible figure used for tests %!shared hf, hax %! hf = figure ("visible", "off"); -%! hax = axes; +%! hax = axes (); -%!error stairs () +%!error <Invalid call> stairs () %!error <Y must be a numeric 2-D vector> stairs (hax, {1}) %!error <Y must be a numeric 2-D vector> stairs (ones (2,2,2)) %!error <X and Y must be numeric 2-D vector> stairs ({1}, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/stem.m --- a/scripts/plot/draw/stem.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/stem.m Thu Nov 19 13:08:00 2020 -0800 @@ -225,7 +225,7 @@ %! end_unwind_protect ## Test input validation -%!error stem () +%!error <Invalid call> stem () %!error <can not define Z for 2-D stem plot> stem (1,2,3) %!error <Y must be a vector or 2-D array> stem (ones (2,2,2)) %!error <X and Y must be numeric> stem ({1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/stem3.m --- a/scripts/plot/draw/stem3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/stem3.m Thu Nov 19 13:08:00 2020 -0800 @@ -90,7 +90,7 @@ %! stem3 (cos (theta), sin (theta), theta); %! title ("stem3() plot"); -%!error stem3 () +%!error <Invalid call> stem3 () %!error <must define X, Y, and Z> stem3 (1,2) %!error <X, Y, and Z must be numeric> stem3 ({1}, 1, 1) %!error <X, Y, and Z must be numeric> stem3 (1, {1}, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/stemleaf.m --- a/scripts/plot/draw/stemleaf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/stemleaf.m Thu Nov 19 13:08:00 2020 -0800 @@ -130,7 +130,7 @@ ## other options for the kinds of plots described by Tukey could be ## provided. This may best be left to users. - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -585,8 +585,7 @@ %! assert (r, rexp); ## Test input validation -%!error stemleaf () -%!error stemleaf (1, 2, 3, 4) +%!error <Invalid call> stemleaf () %!error <X must be a vector> stemleaf (ones (2,2), "") %!warning <X truncated to integer values> tmp = stemleaf ([0 0.5 1],""); %!error <X must be a numeric vector> stemleaf ("Hello World", "data") diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/stream2.m --- a/scripts/plot/draw/stream2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/stream2.m Thu Nov 19 13:08:00 2020 -0800 @@ -82,8 +82,6 @@ options = []; switch (numel (varargin)) - case 0 - print_usage (); case {4,5} if (numel (varargin) == 4) [u, v, spx, spy] = varargin{:}; @@ -97,7 +95,7 @@ case 7 [x, y, u, v, spx, spy, options] = varargin{:}; otherwise - error ("stream2: invalid number of inputs"); + print_usage (); endswitch stepsize = 0.1; @@ -110,7 +108,7 @@ stepsize = options(1); max_vertices = options(2); otherwise - error ("stream2: invalid number of OPTIONS elements"); + error ("stream2: OPTIONS must be a 1- or 2-element vector"); endswitch if (! isreal (stepsize) || stepsize == 0) @@ -207,11 +205,11 @@ %! assert (numel (xy{:}), 10); ## Test input validation -%!error stream2 () -%!error <invalid number of inputs> stream2 (1) -%!error <invalid number of inputs> stream2 (1,2) -%!error <invalid number of inputs> stream2 (1,2,3) -%!error <invalid number of OPTIONS> stream2 (1,2,3,4, [1,2,3]) +%!error <Invalid call> stream2 () +%!error <Invalid call> stream2 (1) +%!error <Invalid call> stream2 (1,2) +%!error <Invalid call> stream2 (1,2,3) +%!error <OPTIONS must be a 1- or 2-element> stream2 (1,2,3,4, [1,2,3]) %!error <STEPSIZE must be a real scalar != 0> stream2 (1,2,3,4, [1i]) %!error <STEPSIZE must be a real scalar != 0> stream2 (1,2,3,4, [0]) %!error <MAX_VERTICES must be an integer> stream2 (1,2,3,4, [1, 1i]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/stream3.m --- a/scripts/plot/draw/stream3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/stream3.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,7 +58,7 @@ ## @end group ## @end example ## -## @seealso{stream2, streamline, streamtube, ostreamtube} +## @seealso{stream2, streamline, streamribbon, streamtube, ostreamtube} ## @end deftypefn ## References: @@ -83,8 +83,6 @@ options = []; switch (numel (varargin)) - case 0 - print_usage (); case {6,7} if (numel (varargin) == 6) [u, v, w, spx, spy, spz] = varargin{:}; @@ -98,7 +96,7 @@ case 10 [x, y, z, u, v, w, spx, spy, spz, options] = varargin{:}; otherwise - error ("stream3: invalid number of inputs"); + print_usage (); endswitch stepsize = 0.1; @@ -111,7 +109,7 @@ stepsize = options(1); max_vertices = options(2); otherwise - error ("stream3: invalid number of OPTIONS elements"); + error ("stream3: OPTIONS must be a 1- or 2-element vector"); endswitch if (! isreal (stepsize) || stepsize == 0) @@ -231,14 +229,14 @@ %! assert (numel (xyz{:}), 15); ## Test input validation -%!error stream3 () -%!error <invalid number of inputs> stream3 (1) -%!error <invalid number of inputs> stream3 (1,2) -%!error <invalid number of inputs> stream3 (1,2,3) -%!error <invalid number of inputs> stream3 (1,2,3,4) -%!error <invalid number of inputs> stream3 (1,2,3,4,5) -%!error <invalid number of inputs> stream3 (1,2,3,4,5,6,7,8) -%!error <invalid number of OPTIONS> stream3 (1,2,3,4,5,6, [1,2,3]) +%!error <Invalid call> stream3 () +%!error <Invalid call> stream3 (1) +%!error <Invalid call> stream3 (1,2) +%!error <Invalid call> stream3 (1,2,3) +%!error <Invalid call> stream3 (1,2,3,4) +%!error <Invalid call> stream3 (1,2,3,4,5) +%!error <Invalid call> stream3 (1,2,3,4,5,6,7,8) +%!error <OPTIONS must be a 1- or 2-element> stream3 (1,2,3,4,5,6, [1,2,3]) %!error <STEPSIZE must be a real scalar != 0> stream3 (1,2,3,4,5,6, [1i]) %!error <STEPSIZE must be a real scalar != 0> stream3 (1,2,3,4,5,6, [0]) %!error <MAX_VERTICES must be an integer> stream3 (1,2,3,4,5,6, [1, 1i]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/streamline.m --- a/scripts/plot/draw/streamline.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/streamline.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,7 +61,7 @@ ## @end group ## @end example ## -## @seealso{stream2, stream3, streamtube, ostreamtube} +## @seealso{stream2, stream3, streamribbon, streamtube, ostreamtube} ## @end deftypefn function h = streamline (varargin) @@ -154,7 +154,7 @@ %! sy = 0.0; %! sz = 0.0; %! plot3 (sx, sy, sz, ".r", "markersize", 15); -%! t = linspace (0, 12 * 2 * pi(), 500); +%! t = linspace (0, 12 * 2 * pi (), 500); %! tx = exp (-a * t).*cos (t); %! ty = exp (-a * t).*sin (t); %! tz = - b * t; @@ -167,7 +167,7 @@ %! axis equal tight; ## Test input validation -%!error streamline () +%!error <Invalid call> streamline () %!error <Invalid call to streamline> %! hf = figure ("visible", "off"); %! unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/streamribbon.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/draw/streamribbon.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,443 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {} streamribbon (@var{x}, @var{y}, @var{z}, @var{u}, @var{v}, @var{w}, @var{sx}, @var{sy}, @var{sz}) +## @deftypefnx {} {} streamribbon (@var{u}, @var{v}, @var{w}, @var{sx}, @var{sy}, @var{sz}) +## @deftypefnx {} {} streamribbon (@var{xyz}, @var{x}, @var{y}, @var{z}, @var{anlr_spd}, @var{lin_spd}) +## @deftypefnx {} {} streamribbon (@var{xyz}, @var{anlr_spd}, @var{lin_spd}) +## @deftypefnx {} {} streamribbon (@var{xyz}, @var{anlr_rot}) +## @deftypefnx {} {} streamribbon (@dots{}, @var{width}) +## @deftypefnx {} {} streamribbon (@var{hax}, @dots{}) +## @deftypefnx {} {@var{h} =} streamribbon (@dots{}) +## Calculate and display streamribbons. +## +## The streamribbon is constructed by rotating a normal vector around a +## streamline according to the angular rotation of the vector field. +## +## The vector field is given by @code{[@var{u}, @var{v}, @var{w}]} and is +## defined over a rectangular grid given by @code{[@var{x}, @var{y}, @var{z}]}. +## The streamribbons start at the seed points +## @code{[@var{sx}, @var{sy}, @var{sz}]}. +## +## @code{streamribbon} can be called with a cell array that contains +## pre-computed streamline data. To do this, @var{xyz} must be created with +## the @code{stream3} function. @var{lin_spd} is the linear speed of the +## vector field and can be calculated from @code{[@var{u}, @var{v}, @var{w}]} +## by the square root of the sum of the squares. The angular speed +## @var{anlr_spd} is the projection of the angular velocity onto the velocity +## of the normalized vector field and can be calculated with the @code{curl} +## command. This option is useful if you need to alter the integrator step +## size or the maximum number of streamline vertices. +## +## Alternatively, ribbons can be created from an array of vertices @var{xyz} of +## a path curve. @var{anlr_rot} contains the angles of rotation around the +## edges between adjacent vertices of the path curve. +## +## The input parameter @var{width} sets the width of the streamribbons. +## +## Streamribbons are colored according to the total angle of rotation along the +## ribbon. +## +## If the first argument @var{hax} is an axes handle, then plot into this axes, +## rather than the current axes returned by @code{gca}. +## +## The optional return value @var{h} is a graphics handle to the plot objects +## created for each streamribbon. +## +## Example: +## +## @example +## @group +## [x, y, z] = meshgrid (0:0.2:4, -1:0.2:1, -1:0.2:1); +## u = - x + 10; +## v = 10 * z.*x; +## w = - 10 * y.*x; +## streamribbon (x, y, z, u, v, w, [0, 0], [0, 0.6], [0, 0]); +## view (3); +## @end group +## @end example +## +## @seealso{streamline, stream3, streamtube, ostreamtube} +## +## @end deftypefn + +## References: +## +## @inproceedings{ +## title = {Feature Detection from Vector Quantities in a Numerically Simulated Hypersonic Flow Field in Combination with Experimental Flow Visualization}, +## author = {Pagendarm, Hans-Georg and Walter, Birgit}, +## year = {1994}, +## publisher = {IEEE Computer Society Press}, +## booktitle = {Proceedings of the Conference on Visualization ’94}, +## pages = {117–123}, +## } +## +## @article{ +## title = {Efficient streamline, streamribbon, and streamtube constructions on unstructured grids}, +## author = {Ueng, Shyh-Kuang and Sikorski, C. and Ma, Kwan-Liu}, +## year = {1996}, +## month = {June}, +## publisher = {IEEE Transactions on Visualization and Computer Graphics}, +## } +## +## @inproceedings{ +## title = {Visualization of 3-D vector fields - Variations on a stream}, +## author = {Dave Darmofal and Robert Haimes}, +## year = {1992} +## } +## +## @techreport{ +## title = {Parallel Transport Approach to Curve Framing}, +## author = {Andrew J. Hanson and Hui Ma}, +## year = {1995} +## } +## +## @article{ +## title = {There is More than One Way to Frame a Curve}, +## author = {Bishop, Richard}, +## year = {1975}, +## month = {03}, +## volume = {82}, +## publisher = {The American Mathematical Monthly} +## } + +function h = streamribbon (varargin) + + [hax, varargin, nargin] = __plt_get_axis_arg__ ("streamribbon", varargin{:}); + + width = []; + xyz = []; + anlr_spd = []; + lin_spd = []; + anlr_rot = []; + switch (nargin) + case 2 + [xyz, anlr_rot] = varargin{:}; + case 3 + if (numel (varargin{3}) == 1) + [xyz, anlr_rot, width] = varargin{:}; + else + [xyz, anlr_spd, lin_spd] = varargin{:}; + [m, n, p] = size (anlr_spd); + [x, y, z] = meshgrid (1:n, 1:m, 1:p); + endif + case 4 + [xyz, anlr_spd, lin_spd, width] = varargin{:}; + [m, n, p] = size (anlr_spd); + [x, y, z] = meshgrid (1:n, 1:m, 1:p); + case 6 + if (iscell (varargin{1})) + [xyz, x, y, z, anlr_spd, lin_spd] = varargin{:}; + else + [u, v, w, spx, spy, spz] = varargin{:}; + [m, n, p] = size (u); + [x, y, z] = meshgrid (1:n, 1:m, 1:p); + endif + case 7 + if (iscell (varargin{1})) + [xyz, x, y, z, anlr_spd, lin_spd, width] = varargin{:}; + else + [u, v, w, spx, spy, spz, width] = varargin{:}; + [m, n, p] = size (u); + [x, y, z] = meshgrid (1:n, 1:m, 1:p); + endif + case 9 + [x, y, z, u, v, w, spx, spy, spz] = varargin{:}; + case 10 + [x, y, z, u, v, w, spx, spy, spz, width] = varargin{:}; + otherwise + print_usage (); + endswitch + + if (isempty (xyz)) + xyz = stream3 (x, y, z, u, v, w, spx, spy, spz); + anlr_spd = curl (x, y, z, u, v, w); + lin_spd = sqrt (u.*u + v.*v + w.*w); + endif + + ## Derive scale factor from the bounding box diagonal + if (isempty (width)) + mxx = mnx = mxy = mny = mxz = mnz = []; + j = 1; + for i = 1 : length (xyz) + sl = xyz{i}; + if (! isempty (sl)) + slx = sl(:,1); sly = sl(:,2); slz = sl(:,3); + mxx(j) = max (slx); mnx(j) = min (slx); + mxy(j) = max (sly); mny(j) = min (sly); + mxz(j) = max (slz); mnz(j) = min (slz); + j += 1; + endif + endfor + dx = max (mxx) - min (mnx); + dy = max (mxy) - min (mny); + dz = max (mxz) - min (mnz); + width = sqrt (dx*dx + dy*dy + dz*dz) / 25; + elseif (! isreal (width) || width <= 0) + error ("streamribbon: WIDTH must be a real scalar > 0"); + endif + + if (! isempty (anlr_rot)) + for i = 1 : length (xyz) + if (rows (anlr_rot{i}) != rows (xyz{i})) + error ("streamribbon: ANLR_ROT must have same length as XYZ"); + endif + endfor + endif + + if (isempty (hax)) + hax = gca (); + else + hax = hax(1); + endif + + ## Angular speed of a paddle wheel spinning around a streamline in a fluid + ## flow "V": + ## dtheta/dt = 0.5 * <curl(V), V/norm(V)> + ## + ## Integration along a streamline segment with the length "h" yields the + ## rotation angle: + ## theta = 0.25 * h * <curl(V), V(0)/norm(V(0))^2) + V(h)/norm(V(h))^2)> + ## + ## Alternative approach using the curl angular speed "c = curl()": + ## theta = 0.5 * h * (c(0)/norm(V(0)) + c(h)/norm(V(h))) + ## + ## Hints: + ## i. ) For integration use trapezoidal rule + ## ii.) "V" can be assumend to be piecewise linear and curl(V) to be + ## piecewise constant because of the used linear interpolation + + h = []; + for i = 1 : length (xyz) + sl = xyz{i}; + num_vertices = rows (sl); + if (! isempty (sl) && num_vertices > 1) + if (isempty (anlr_rot)) + ## Plot from vector field + ## Interpolate onto streamline vertices + [lin_spd_sl, anlr_spd_sl, max_vertices] = ... + interp_sl (x, y, z, lin_spd, anlr_spd, sl); + if (max_vertices > 1) + ## Euclidean distance between two adjacent vertices + stepsize = vecnorm (diff (sl(1:max_vertices, :)), 2, 2); + ## Angular rotation around edges between two adjacent sl-vertices + ## Note: Potential "division by zero" is checked in interp_sl() + anlr_rot_sl = 0.5 * stepsize.*(anlr_spd_sl(1:max_vertices - 1)./ ... + lin_spd_sl(1:max_vertices - 1) + ... + anlr_spd_sl(2:max_vertices)./ ... + lin_spd_sl(2:max_vertices)); + + htmp = plotribbon (hax, sl, anlr_rot_sl, max_vertices, 0.5 * width); + h = [h; htmp]; + endif + else + ## Plot from vertice array + anlr_rot_sl = anlr_rot{i}; + + htmp = plotribbon (hax, sl, anlr_rot_sl, num_vertices, 0.5 * width); + h = [h; htmp]; + endif + endif + endfor + +endfunction + +function h = plotribbon (hax, sl, anlr_rot_sl, max_vertices, width2) + + total_angle = cumsum (anlr_rot_sl); + total_angle = [0; total_angle]; + + ## 1st streamline segment + X0 = sl(1,:); + X1 = sl(2,:); + R = X1 - X0; + RE = R / norm (R); + + ## Initial vector KE which is to be transported along the vertice array + KE = get_normal2 (RE); + XS10 = - width2 * KE + X0; + XS20 = width2 * KE + X0; + + ## Apply angular rotation + cp = cos (anlr_rot_sl(1)); + sp = sin (anlr_rot_sl(1)); + KE = rotation (KE, RE, cp, sp).'; + + XS1 = - width2 * KE + X1; + XS2 = width2 * KE + X1; + + px = zeros (2, max_vertices); + py = zeros (2, max_vertices); + pz = zeros (2, max_vertices); + pc = zeros (2, max_vertices); + + px(:,1) = [XS10(1); XS20(1)]; + py(:,1) = [XS10(2); XS20(2)]; + pz(:,1) = [XS10(3); XS20(3)]; + pc(:,1) = total_angle(1) * [1; 1]; + + px(:,2) = [XS1(1); XS2(1)]; + py(:,2) = [XS1(2); XS2(2)]; + pz(:,2) = [XS1(3); XS2(3)]; + pc(:,2) = total_angle(2) * [1; 1]; + + for i = 3 : max_vertices + + ## Next streamline segment + X0 = X1; + X1 = sl(i,:); + R = X1 - X0; + RE = R / norm (R); + + ## Project KE onto RE and get the difference in order to transport + ## the normal vector KE along the vertex array + Kp = KE - RE * dot (KE, RE); + KE = Kp / norm (Kp); + + ## Apply angular rotation to KE + cp = cos (anlr_rot_sl(i - 1)); + sp = sin (anlr_rot_sl(i - 1)); + KE = rotation (KE, RE, cp, sp).'; + + XS1 = - width2 * KE + X1; + XS2 = width2 * KE + X1; + + px(:,i) = [XS1(1); XS2(1)]; + py(:,i) = [XS1(2); XS2(2)]; + pz(:,i) = [XS1(3); XS2(3)]; + pc(:,i) = total_angle(i) * [1; 1]; + + endfor + + h = surface (hax, px, py, pz, pc); + +endfunction + +## Interpolate speed and divergence onto the streamline vertices and +## return the first chunck of valid samples until a singularity / +## zero is hit or the streamline vertex array "sl" ends +function [lin_spd_sl, anlr_spd_sl, max_vertices] = ... + interp_sl (x, y, z, lin_spd, anlr_spd, sl) + + anlr_spd_sl = interp3 (x, y, z, anlr_spd, sl(:,1), sl(:,2), sl(:,3)); + lin_spd_sl = interp3 (x, y, z, lin_spd, sl(:,1), sl(:,2), sl(:,3)); + + is_singular_anlr_spd = find (isnan (anlr_spd_sl), 1, "first"); + is_zero_lin_spd = find (lin_spd_sl == 0, 1, "first"); + + max_vertices = rows (sl); + if (! isempty (is_singular_anlr_spd)) + max_vertices = min (max_vertices, is_singular_anlr_spd - 1); + endif + if (! isempty (is_zero_lin_spd)) + max_vertices = min (max_vertices, is_zero_lin_spd - 1); + endif + +endfunction + +## N normal to X, so that N is in span ([0 0 1], X) +## If not possible then span ([1 0 0], X) +function N = get_normal2 (X) + + if ((X(1) == 0) && (X(2) == 0)) + A = [1, 0, 0]; + else + A = [0, 0, 1]; + endif + + ## Project A onto X and get the difference + N = A - X * dot (A, X) / (norm (X)^2); + N /= norm (N); + +endfunction + +## Rotate X around U where |U| = 1 +## cp = cos (angle), sp = sin (angle) +function Y = rotation (X, U, cp, sp) + + ux = U(1); + uy = U(2); + uz = U(3); + + Y(1,:) = X(1) * (cp + ux * ux * (1 - cp)) + ... + X(2) * (ux * uy * (1 - cp) - uz * sp) + ... + X(3) * (ux * uz * (1 - cp) + uy * sp); + + Y(2,:) = X(1) * (uy * ux * (1 - cp) + uz * sp) + ... + X(2) * (cp + uy * uy * (1 - cp)) + ... + X(3) * (uy * uz * (1 - cp) - ux * sp); + + Y(3,:) = X(1) * (uz * ux * (1 - cp) - uy * sp) + ... + X(2) * (uz * uy * (1 - cp) + ux * sp) + ... + X(3) * (cp + uz * uz * (1 - cp)); + +endfunction + + +%!demo +%! clf; +%! [x, y, z] = meshgrid (0:0.2:4, -1:0.2:1, -1:0.2:1); +%! u = - x + 10; +%! v = 10 * z.*x; +%! w = - 10 * y.*x; +%! sx = [0, 0]; +%! sy = [0, 0.6]; +%! sz = [0, 0]; +%! streamribbon (x, y, z, u, v, w, sx, sy, sz); +%! hold on; +%! quiver3 (x, y, z, u, v, w); +%! colormap (jet); +%! shading interp; +%! camlight ("headlight"); +%! view (3); +%! axis tight equal off; +%! set (gca, "cameraviewanglemode", "manual"); +%! hcb = colorbar; +%! title (hcb, "Angle"); +%! title ("Streamribbon"); + +%!demo +%! clf; +%! t = (0:pi/50:2*pi).'; +%! xyz{1} = [cos(t), sin(t), 0*t]; +%! twist{1} = ones (numel (t), 1) * pi / (numel (t) - 1); +%! streamribbon (xyz, twist, 0.5); +%! colormap (jet); +%! view (3); +%! camlight ("headlight"); +%! axis tight equal off; +%! title ("Moebius Strip"); + +## Test input validation +%!error <Invalid call> streamribbon () +%!error <Invalid call> streamribbon (1) +%!error <Invalid call> streamribbon (1,2,3,4,5) +%!error <Invalid call> streamribbon (1,2,3,4,5,6,7,8) +%!error <Invalid call> streamribbon (1,2,3,4,5,6,7,8,9,10,11) +%!error <WIDTH must be a real scalar . 0> streamribbon (1,2,3,1i) +%!error <WIDTH must be a real scalar . 0> streamribbon (1,2,3,0) +%!error <WIDTH must be a real scalar . 0> streamribbon (1,2,3,-1) +%!error <ANLR_ROT must have same length as XYZ> streamribbon ({[1,1,1;2,2,2]},{[1,1,1]}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/streamtube.m --- a/scripts/plot/draw/streamtube.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/streamtube.m Thu Nov 19 13:08:00 2020 -0800 @@ -66,7 +66,7 @@ ## The optional return value @var{h} is a graphics handle to the plot objects ## created for each tube. ## -## @seealso{stream3, streamline, ostreamtube} +## @seealso{stream3, streamline, streamribbon, ostreamtube} ## @end deftypefn function h = streamtube (varargin) @@ -78,8 +78,6 @@ div = []; dia = []; switch (nargin) - case 0 - print_usage (); case 2 ## "dia" can be a cell array or a constant if (iscell (varargin{2}) || numel (varargin{2}) == 1) @@ -116,7 +114,7 @@ case 10 [x, y, z, u, v, w, spx, spy, spz, options] = varargin{:}; otherwise - error ("streamtube: invalid number of inputs"); + print_usage (); endswitch scale = 1; @@ -129,7 +127,7 @@ scale = options(1); num_circum = options(2); otherwise - error ("streamtube: invalid number of OPTIONS elements"); + error ("streamtube: OPTIONS must be a 1- or 2-element vector"); endswitch if (! isreal (scale) || scale <= 0) @@ -169,7 +167,7 @@ for i = 1 : length (xyz) sl = xyz{i}; if (! isempty (sl)) - slx = sl(:, 1); sly = sl(:, 2); slz = sl(:, 3); + slx = sl(:,1); sly = sl(:,2); slz = sl(:,3); mxx(j) = max (slx); mnx(j) = min (slx); mxy(j) = max (sly); mny(j) = min (sly); mxz(j) = max (slz); mnz(j) = min (slz); @@ -226,10 +224,9 @@ cp = cos (phi); sp = sin (phi); - X0 = sl(1, :); - X1 = sl(2, :); - - ## 1st rotation axis + ## 1st streamline segment + X0 = sl(1,:); + X1 = sl(2,:); R = X1 - X0; RE = R / norm (R); @@ -244,35 +241,34 @@ py = zeros (num_circum, max_vertices); pz = zeros (num_circum, max_vertices); - px(:, 1) = XS0(1, :).'; - py(:, 1) = XS0(2, :).'; - pz(:, 1) = XS0(3, :).'; + px(:,1) = XS0(1,:).'; + py(:,1) = XS0(2,:).'; + pz(:,1) = XS0(3,:).'; - px(:, 2) = XS(1, :).'; - py(:, 2) = XS(2, :).'; - pz(:, 2) = XS(3, :).'; + px(:,2) = XS(1,:).'; + py(:,2) = XS(2,:).'; + pz(:,2) = XS(3,:).'; for i = 3 : max_vertices - KEold = KE; + ## Next streamline segment X0 = X1; - - X1 = sl(i, :); + X1 = sl(i,:); R = X1 - X0; RE = R / norm (R); - ## Project KE onto RE and get the difference in order to calculate the next - ## guiding point - Kp = KEold - RE * dot (KEold, RE); + ## Project KE onto RE and get the difference in order to transport + ## the normal vector KE along the vertex array + Kp = KE - RE * dot (KE, RE); KE = Kp / norm (Kp); K = radius_sl(i) * KE; ## Rotate around RE and collect surface patches XS = rotation (K, RE, cp, sp) + repmat (X1.', 1, num_circum); - px(:, i) = XS(1, :).'; - py(:, i) = XS(2, :).'; - pz(:, i) = XS(3, :).'; + px(:,i) = XS(1,:).'; + py(:,i) = XS(2,:).'; + pz(:,i) = XS(3,:).'; endfor @@ -285,7 +281,7 @@ ## the streamline vertex array "sl" ends function [div_sl_crop, max_vertices] = interp_sl (x, y, z, div, sl) - div_sl = interp3 (x, y, z, div, sl(:, 1), sl(:, 2), sl(:, 3)); + div_sl = interp3 (x, y, z, div, sl(:,1), sl(:,2), sl(:,3)); is_nan = find (isnan (div_sl), 1, "first"); is_inf = find (isinf (div_sl), 1, "first"); @@ -305,9 +301,9 @@ function N = get_normal1 (X) if ((X(3) == 0) && (X(1) == -X(2))) - N = [- X(2) - X(3), X(1), X(1)]; + N = [(- X(2) - X(3)), X(1), X(1)]; else - N = [X(3), X(3), - X(1) - X(2)]; + N = [X(3), X(3), (- X(1) - X(2))]; endif N /= norm (N); @@ -322,20 +318,21 @@ uy = U(2); uz = U(3); - Y(1, :) = X(1) * (cp + ux * ux * (1 - cp)) + ... - X(2) * (ux * uy * (1 - cp) - uz * sp) + ... - X(3) * (ux * uz * (1 - cp) + uy * sp); + Y(1,:) = X(1) * (cp + ux * ux * (1 - cp)) + ... + X(2) * (ux * uy * (1 - cp) - uz * sp) + ... + X(3) * (ux * uz * (1 - cp) + uy * sp); - Y(2, :) = X(1) * (uy * ux * (1 - cp) + uz * sp) + ... - X(2) * (cp + uy * uy * (1 - cp)) + ... - X(3) * (uy * uz * (1 - cp) - ux * sp); + Y(2,:) = X(1) * (uy * ux * (1 - cp) + uz * sp) + ... + X(2) * (cp + uy * uy * (1 - cp)) + ... + X(3) * (uy * uz * (1 - cp) - ux * sp); - Y(3, :) = X(1) * (uz * ux * (1 - cp) - uy * sp) + ... - X(2) * (uz * uy * (1 - cp) + ux * sp) + ... - X(3) * (cp + uz * uz * (1 - cp)); + Y(3,:) = X(1) * (uz * ux * (1 - cp) - uy * sp) + ... + X(2) * (uz * uy * (1 - cp) + ux * sp) + ... + X(3) * (cp + uz * uz * (1 - cp)); endfunction + %!demo %! clf; %! [x, y, z] = meshgrid (-3:0.15:3, -1:0.1:1, -1:0.1:1); @@ -356,7 +353,7 @@ %!demo %! clf; %! t = 0:.15:15; -%! xyz{1} = [cos(t)' sin(t)' (t/3)']; +%! xyz{1} = [cos(t)', sin(t)', (t/3)']; %! dia{1} = cos(t)'; %! streamtube (xyz, dia); %! grid on; @@ -369,12 +366,12 @@ %! title ("Plot Arbitrary Tube"); ## Test input validation -%!error streamtube () -%!error <invalid number of inputs> streamtube (1) -%!error <invalid number of inputs> streamtube (1,2,3,4) -%!error <invalid number of inputs> streamtube (1,2,3,4,5,6,7,8) -%!error <invalid number of inputs> streamtube (1,2,3,4,5,6,7,8,9,10,11) -%!error <invalid number of OPTIONS elements> streamtube (1,2,[1,2,3]) +%!error <Invalid call> streamtube () +%!error <Invalid call> streamtube (1) +%!error <Invalid call> streamtube (1,2,3,4) +%!error <Invalid call> streamtube (1,2,3,4,5,6,7,8) +%!error <Invalid call> streamtube (1,2,3,4,5,6,7,8,9,10,11) +%!error <OPTIONS must be a 1- or 2-element vector> streamtube (1,2,[1,2,3]) %!error <SCALE must be a real scalar . 0> streamtube (1,2,[1i]) %!error <SCALE must be a real scalar . 0> streamtube (1,2,[0]) %!error <SCALE must be a real scalar . 0> streamtube (1,2,[-1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/surface.m --- a/scripts/plot/draw/surface.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/surface.m Thu Nov 19 13:08:00 2020 -0800 @@ -206,7 +206,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! h = surface; +%! h = surface (); %! assert (findobj (hf, "type", "surface"), h); %! assert (get (h, "xdata"), 1:3, eps); %! assert (get (h, "ydata"), (1:3)', eps); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/surfl.m --- a/scripts/plot/draw/surfl.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/surfl.m Thu Nov 19 13:08:00 2020 -0800 @@ -156,7 +156,7 @@ ## Get view vector (vv). [az, el] = view (); - vv = sph2cart ((az - 90) * pi/180.0, el * pi/180.0, 1.0); + [vv(1), vv(2), vv(3)] = sph2cart ((az - 90) * pi/180.0, el * pi/180.0, 1.0); if (! have_lv) ## Calculate light vector (lv) from view vector. diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/surfnorm.m --- a/scripts/plot/draw/surfnorm.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/surfnorm.m Thu Nov 19 13:08:00 2020 -0800 @@ -203,8 +203,8 @@ %! "sombrero() function with 10 faces"}); ## Test input validation -%!error surfnorm () -%!error surfnorm (1,2) +%!error <Invalid call> surfnorm () +%!error <Invalid call> surfnorm (1,2) %!error <X, Y, and Z must be 2-D real matrices> surfnorm (i) %!error <X, Y, and Z must be 2-D real matrices> surfnorm (i, 1, 1) %!error <X, Y, and Z must be 2-D real matrices> surfnorm (1, i, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/tetramesh.m --- a/scripts/plot/draw/tetramesh.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/tetramesh.m Thu Nov 19 13:08:00 2020 -0800 @@ -59,7 +59,7 @@ [reg, prop] = parseparams (varargin); - if (length (reg) < 2 || length (reg) > 3) + if (numel (reg) < 2 || numel (reg) > 3) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/trimesh.m --- a/scripts/plot/draw/trimesh.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/trimesh.m Thu Nov 19 13:08:00 2020 -0800 @@ -76,7 +76,7 @@ varargin(1) = []; if (isvector (c)) c = c(:); - end + endif if (rows (c) != numel (z) && rows (c) != rows (tri)) error ("trimesh: the numbers of colors specified in C must equal the number of vertices in Z or the number of triangles in TRI"); elseif (columns (c) != 1 && columns (c) != 3) @@ -122,9 +122,9 @@ %! title ("trimesh() plot of sparsely-sampled peaks() function"); ## Test input validation -%!error trimesh () -%!error trimesh (1) -%!error trimesh (1,2) +%!error <Invalid call> trimesh () +%!error <Invalid call> trimesh (1) +%!error <Invalid call> trimesh (1,2) %!error <the numbers of colors> trimesh (1,2,3,4,[5 6]) %!error <the numbers of colors> trimesh (1,2,3,4,[5 6]') %!error <the numbers of colors> trimesh ([1;1],[2;2],[3;3],[4;4], zeros (3,3)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/draw/trisurf.m --- a/scripts/plot/draw/trisurf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/draw/trisurf.m Thu Nov 19 13:08:00 2020 -0800 @@ -71,7 +71,7 @@ varargin(1) = []; if (isvector (c)) c = c(:); - end + endif if (rows (c) != numel (z) && rows (c) != rows (tri)) error ("trisurf: the numbers of colors specified in C must equal the number of vertices in Z or the number of triangles in TRI"); elseif (columns (c) != 1 && columns (c) != 3) @@ -138,7 +138,7 @@ %! z = peaks (x, y); %! tri = delaunay (x(:), y(:)); %! trisurf (tri, x(:), y(:), z(:)); -%! title ("trisurf() of sparsely-sampled triangulation of peaks()"); +%! title ("trisurf () of sparsely-sampled triangulation of peaks ()"); %!demo %! clf; @@ -171,10 +171,10 @@ %! title ({"trisurf() of random data", '"facecolor" = "interp", "edgecolor" = "white"'}); ## Test input validation -%!error trisurf () -%!error trisurf (1) -%!error trisurf (1,2) -%!error trisurf (1,2,3) +%!error <Invalid call> trisurf () +%!error <Invalid call> trisurf (1) +%!error <Invalid call> trisurf (1,2) +%!error <Invalid call> trisurf (1,2,3) %!error <the numbers of colors> trisurf (1,2,3,4,[5 6]) %!error <the numbers of colors> trisurf (1,2,3,4,[5 6]') %!error <the numbers of colors> trisurf ([1;1],[2;2],[3;3],[4;4], zeros (3,3)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/util/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/__actual_axis_position__.m --- a/scripts/plot/util/__actual_axis_position__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/__actual_axis_position__.m Thu Nov 19 13:08:00 2020 -0800 @@ -50,7 +50,7 @@ end_unwind_protect ## Get axes size in pixels if (strcmp (get (axis_obj.parent, "__graphics_toolkit__"), "gnuplot") - && strcmp (axis_obj.activepositionproperty, "outerposition")) + && strcmp (axis_obj.positionconstraint, "outerposition")) pos_in_pixels = axis_obj.outerposition .* fig_position([3, 4, 3, 4]); else pos_in_pixels = axis_obj.position .* fig_position([3, 4, 3, 4]); @@ -82,7 +82,7 @@ endif pos = pos_in_pixels ./ fig_position([3, 4, 3, 4]); elseif (strcmp (get (axis_obj.parent, "__graphics_toolkit__"), "gnuplot") - && strcmp (axis_obj.activepositionproperty, "outerposition")) + && strcmp (axis_obj.positionconstraint, "outerposition")) pos = axis_obj.outerposition; else pos = axis_obj.position; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/__gnuplot_drawnow__.m --- a/scripts/plot/util/__gnuplot_drawnow__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/__gnuplot_drawnow__.m Thu Nov 19 13:08:00 2020 -0800 @@ -30,7 +30,7 @@ function __gnuplot_drawnow__ (h, term, file, debug_file) - if (nargin < 1 || nargin > 4 || nargin == 2) + if (nargin < 1 || nargin == 2) print_usage (); endif @@ -269,7 +269,7 @@ endif ## Set the gnuplot terminal (type, enhanced, title, options & size). - term_str = ["set terminal " term]; + term_str = ["set encoding utf8;\nset terminal " term]; if (__gnuplot_has_feature__ ("needs_color_with_postscript") ... && strcmp (term, "postscript")) term_str = [term_str, " color"]; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/__opengl_info__.m --- a/scripts/plot/util/__opengl_info__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/__opengl_info__.m Thu Nov 19 13:08:00 2020 -0800 @@ -59,10 +59,6 @@ function retval = __opengl_info__ () - if (nargin != 0) - print_usage (); - endif - [info, msg] = gl_info (); if (! isempty (msg)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/__pltopt__.m --- a/scripts/plot/util/__pltopt__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/__pltopt__.m Thu Nov 19 13:08:00 2020 -0800 @@ -30,59 +30,59 @@ ## ## @var{opt} can currently be some combination of the following: ## -## @table @code -## @item "-" +## @table @asis +## @item @qcode{"-"} ## For solid linestyle (default). ## -## @item "--" +## @item @qcode{"--"} ## For dashed line style. ## -## @item "-." +## @item @qcode{"-."} ## For linespoints plot style. ## -## @item ":" +## @item @qcode{":"} ## For dots plot style. ## -## @item "r" +## @item @qcode{"r"} ## Red line color. ## -## @item "g" +## @item @qcode{"g"} ## Green line color. ## -## @item "b" +## @item @qcode{"b"} ## Blue line color. ## -## @item "c" +## @item @qcode{"c"} ## Cyan line color. ## -## @item "m" +## @item @qcode{"m"} ## Magenta line color. ## -## @item "y" +## @item @qcode{"y"} ## Yellow line color. ## -## @item "k" +## @item @qcode{"k"} ## Black line color. ## -## @item "w" +## @item @qcode{"w"} ## White line color. ## -## @item ";title;" +## @item @qcode{";title;"} ## Here @code{"title"} is the label for the key. ## -## @item "+" -## @itemx "o" -## @itemx "*" -## @itemx "." -## @itemx "x" -## @itemx "s" -## @itemx "d" -## @itemx "^" -## @itemx "v" -## @itemx ">" -## @itemx "<" -## @itemx "p" -## @itemx "h" +## @item @qcode{"+"} +## @itemx @qcode{"o"} +## @itemx @qcode{"*"} +## @itemx @qcode{"."} +## @itemx @qcode{"x"} +## @itemx @qcode{"s"} +## @itemx @qcode{"d"} +## @itemx @qcode{"^"} +## @itemx @qcode{"v"} +## @itemx @qcode{">"} +## @itemx @qcode{"<"} +## @itemx @qcode{"p"} +## @itemx @qcode{"h"} ## Used in combination with the points or linespoints styles, set the point ## style. ## @end table diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/allchild.m --- a/scripts/plot/util/allchild.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/allchild.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ function h = allchild (handles) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -57,7 +57,7 @@ %! toolkit = graphics_toolkit ("qt"); %! hf = figure ("visible", "off"); %! unwind_protect -%! l = line; +%! l = line (); %! kids = allchild (hf); %! assert (get (kids, "type"), ... %! {"axes"; "uitoolbar"; "uimenu"; "uimenu"; "uimenu"}); @@ -66,5 +66,4 @@ %! graphics_toolkit (toolkit); %! end_unwind_protect -%!error allchild () -%!error allchild (1, 2) +%!error <Invalid call> allchild () diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/ancestor.m --- a/scripts/plot/util/ancestor.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/ancestor.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function p = ancestor (h, type, toplevel) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -91,7 +91,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hl = line; +%! hl = line (); %! assert (ancestor (hl, "axes"), gca); %! assert (ancestor (hl, "figure"), hf); %! unwind_protect_cleanup @@ -117,7 +117,6 @@ %!assert (ancestor ([], "axes"), []) -%!error ancestor () -%!error ancestor (1,2,3) +%!error <Invalid call> ancestor () %!error <TYPE must be a string> ancestor (1,2) %!error <third argument must be "toplevel"> ancestor (1, "axes", "foo") diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/cla.m --- a/scripts/plot/util/cla.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/cla.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,17 +49,13 @@ function cla (hax, do_reset = false) - if (nargin > 2) - print_usage (); - endif - if (nargin == 0) - hax = gca; + hax = gca (); elseif (nargin == 1) if (isscalar (hax) && isaxes (hax)) ## Normal case : cla (hax) without reset elseif (ischar (hax) && strcmpi (hax, "reset")) - hax = gca; + hax = gca (); do_reset = true; else print_usage (); @@ -98,7 +94,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! hax = gca; +%! hax = gca (); %! plot (hax, 1:10); %! assert (get (hax, "colororderindex"), 2); %! set (hax, "ticklabelinterpreter", "none"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/clf.m --- a/scripts/plot/util/clf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/clf.m Thu Nov 19 13:08:00 2020 -0800 @@ -52,14 +52,14 @@ if (nargin > 2) print_usage (); elseif (nargin == 0) - hfig = gcf; + hfig = gcf (); do_reset = false; elseif (nargin == 1) if (isscalar (varargin{1}) && isfigure (varargin{1})) hfig = varargin{1}; do_reset = false; elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset")) - hfig = gcf; + hfig = gcf (); do_reset = true; else print_usage (); @@ -119,7 +119,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! l = line; +%! l = line (); %! assert (! isempty (get (gcf, "children"))); %! clf; %! assert (isempty (get (gcf, "children"))); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/close.m --- a/scripts/plot/util/close.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/close.m Thu Nov 19 13:08:00 2020 -0800 @@ -63,9 +63,7 @@ figs = []; - if (nargin > 2) - print_usage (); - elseif (nargin == 0) + if (nargin == 0) ## Close current figure. ## Can't use gcf because it opens a new plot window if one does not exist. figs = get (0, "currentfigure"); @@ -181,7 +179,6 @@ %! end_unwind_protect ## Test input validation -%!error close (1,2,3) %!error <first argument must be "all", a figure handle> close ({"all"}) %!error <first argument must be "all", a figure handle> close (-1) %!error <second argument must be "hidden"> close all hid diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/closereq.m --- a/scripts/plot/util/closereq.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/closereq.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,10 +34,6 @@ function closereq () - if (nargin != 0) - print_usage (); - endif - ## Get current figure, but don't use gcf to avoid creating a new figure. cf = get (0, "currentfigure"); if (isfigure (cf)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/colstyle.m --- a/scripts/plot/util/colstyle.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/colstyle.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function [l, c, m, msg] = colstyle (style) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -94,6 +94,6 @@ %! assert (msg, "colstyle: unrecognized format character: '~'"); ## Test input validation -%!error colstyle () +%!error <Invalid call> colstyle () %!error colstyle (1, 2) %!error <STYLE must be a string> colstyle (1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/copyobj.m --- a/scripts/plot/util/copyobj.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/copyobj.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,7 +48,7 @@ othertypes = {"line", "patch", "surface", "image", "text", "uicontrol"}; alltypes = [partypes othertypes]; - if (! ishghandle (horig) || nargin > 2) + if (! ishghandle (horig)) print_usage (); elseif (! ishghandle (hparent)) hparent = figure (fix (hparent)); @@ -79,7 +79,7 @@ endfor if (kididx <= paridx) - error ("copyobj: %s object can't be a child of %s.", + error ("copyobj: %s object can't be a child of %s", alltypes{kididx}, alltypes{paridx}); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/figure.m --- a/scripts/plot/util/figure.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/figure.m Thu Nov 19 13:08:00 2020 -0800 @@ -85,7 +85,7 @@ ## Check to see if we already have a figure on the screen. If we do, ## then update it if it is different from the figure we are creating ## or switching to. - cf = get (0, "currentfigure"); # Can't use gcf () because it calls figure() + cf = get (0, "currentfigure"); # Can't use gcf() because it calls figure() if (! isempty (cf) && cf != 0) if (init_new_figure || cf != f) drawnow (); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/findall.m --- a/scripts/plot/util/findall.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/findall.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ ## ## @code{findall} performs the same search as @code{findobj}, but it ## includes hidden objects (HandleVisibility = @qcode{"off"}). For full -## documentation, @pxref{XREFfindobj,,findobj}. +## documentation, @pxref{XREFfindobj,,@code{findobj}}. ## @seealso{findobj, allchild, get, set} ## @end deftypefn diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/findobj.m --- a/scripts/plot/util/findobj.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/findobj.m Thu Nov 19 13:08:00 2020 -0800 @@ -88,8 +88,9 @@ ## @end example ## ## Implementation Note: The search only includes objects with visible -## handles (@w{HandleVisibility} = @qcode{"on"}). @xref{XREFfindall,,findall}, -## to search for all objects including hidden ones. +## handles (@w{HandleVisibility} = @qcode{"on"}). +## @xref{XREFfindall,,@code{findall}}, to search for all objects including +## hidden ones. ## @seealso{findall, allchild, get, set} ## @end deftypefn @@ -329,7 +330,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! l = line; +%! l = line (); %! obj = findobj (hf, "type", "line"); %! assert (l, obj); %! assert (gca, findobj (hf, "type", "axes")); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/gca.m --- a/scripts/plot/util/gca.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/gca.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,13 +57,9 @@ function h = gca () - if (nargin == 0) - h = get (gcf (), "currentaxes"); - if (isempty (h)) - h = axes (); - endif - else - print_usage (); + h = get (gcf (), "currentaxes"); + if (isempty (h)) + h = axes (); endif endfunction @@ -71,7 +67,7 @@ %!test %! hf = figure ("visible", "off"); -%! ax = axes; +%! ax = axes (); %! unwind_protect %! assert (gca, ax); %! unwind_protect_cleanup diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/gcf.m --- a/scripts/plot/util/gcf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/gcf.m Thu Nov 19 13:08:00 2020 -0800 @@ -60,15 +60,11 @@ function h = gcf () - if (nargin == 0) - h = get (0, "currentfigure"); - if (isempty (h) || h == 0) - ## We only have a root object, so create a new figure object - ## and make it the current figure. - h = figure (); - endif - else - print_usage (); + h = get (0, "currentfigure"); + if (isempty (h) || h == 0) + ## We only have a root object, so create a new figure object + ## and make it the current figure. + h = figure (); endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/ginput.m --- a/scripts/plot/util/ginput.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/ginput.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,10 +46,6 @@ function varargout = ginput (n = -1) - if (nargin > 1) - print_usage (); - endif - ## Create an axis, if necessary. fig = gcf (); ax = gca (); @@ -69,7 +65,7 @@ else [varargout{:}] = feval (toolkit_fcn, fig, n); endif - return + return; endif x = y = button = []; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/graphics_toolkit.m --- a/scripts/plot/util/graphics_toolkit.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/graphics_toolkit.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,10 +45,6 @@ function retval = graphics_toolkit (name, hlist = []) - if (nargin > 2) - print_usage (); - endif - if (nargout > 0 || nargin == 0) retval = get (0, "defaultfigure__graphics_toolkit__"); ## Handle case where graphics_toolkit has been called before any plotting @@ -92,7 +88,7 @@ if (strcmp (name, "gnuplot")) valid_version = __gnuplot_has_feature__ ("minimum_version"); if (valid_version != 1) - error ("graphics_toolkit: gnuplot version too old."); + error ("graphics_toolkit: gnuplot version too old"); endif endif feval (["__init_", name, "__"]); @@ -109,6 +105,7 @@ endfunction + %!testif HAVE_OPENGL, HAVE_QT; have_window_system () && any (strcmp ("qt", available_graphics_toolkits ())) %! unwind_protect %! hf = figure ("visible", "off"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/groot.m --- a/scripts/plot/util/groot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/groot.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,16 +58,9 @@ function h = groot () - if (nargin != 0) - print_usage (); - endif - h = 0; endfunction %!assert (groot (), 0) - -## Test input validation -%!error groot (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/hdl2struct.m --- a/scripts/plot/util/hdl2struct.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/hdl2struct.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ function s = hdl2struct (h) - if (nargin != 1 || ! ishghandle (h)) + if (nargin < 1 || ! ishghandle (h)) print_usage (); endif @@ -139,12 +139,13 @@ persistent excluded; if (isempty (excluded)) - excluded = cell2struct (repmat ({[]}, 1, 15), + excluded = cell2struct (repmat ({[]}, 1, 16), {"beingdeleted", "busyaction", "buttondownfcn", ... - "children", "clipping", "createfcn", ... - "deletefcn", "handlevisibility", "hittest", ... - "interruptible", "parent", "selected" , ... - "selectionhighlight", "type", "uicontextmenu"}, 2); + "children", "clipping", "contextmenu", ... + "createfcn", "deletefcn", "handlevisibility", ... + "hittest", "interruptible", "parent", ... + "selected" , "selectionhighlight", "type", ... + "uicontextmenu"}, 2); endif obj = get (h); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/hggroup.m --- a/scripts/plot/util/hggroup.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/hggroup.m Thu Nov 19 13:08:00 2020 -0800 @@ -68,7 +68,7 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! h = hggroup; +%! h = hggroup (); %! assert (findobj (hf, "type", "hggroup"), h); %! assert (get (h, "type"), "hggroup"); %! unwind_protect_cleanup diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/hgload.m --- a/scripts/plot/util/hgload.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/hgload.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,7 +45,7 @@ function [h, old_prop] = hgload (filename, prop_struct = struct ()) ## Check number of input arguments - if (nargin == 0 || nargin > 2) + if (nargin == 0) print_usage (); endif @@ -133,8 +133,7 @@ %! end_unwind_protect ## Test input validation -%!error hgload () -%!error hgload (1, 2, 3) +%!error <Invalid call> hgload () %!error <PROP_STRUCT must be a struct> hgload (1, {}) %!error <unable to locate file> hgload ("%%_A_REALLY_UNLIKELY_FILENAME_%%") %!error <unable to locate file> hgload ("%%_A_REALLY_UNLIKELY_FILENAME_%%.fig") diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/hgsave.m --- a/scripts/plot/util/hgsave.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/hgsave.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,7 +61,7 @@ function hgsave (h, filename, fmt = "-binary") - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -134,8 +134,7 @@ %! end_unwind_protect ## Test input validation -%!error hgsave () -%!error hgsave (1, 2, 3, 4) +%!error <Invalid call> hgsave () %!error <no current figure to save> %! unwind_protect %! old_fig = get (0, "currentfigure"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/isaxes.m --- a/scripts/plot/util/isaxes.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/isaxes.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function retval = isaxes (h) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -66,5 +66,4 @@ %! close (hf); %! end_unwind_protect -%!error isaxes () -%!error isaxes (1, 2) +%!error <Invalid call> isaxes () diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/isfigure.m --- a/scripts/plot/util/isfigure.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/isfigure.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ function retval = isfigure (h) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -65,5 +65,4 @@ %! close (hf); %! end_unwind_protect -%!error isfigure () -%!error isfigure (1, 2) +%!error <Invalid call> isfigure () diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/isgraphics.m --- a/scripts/plot/util/isgraphics.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/isgraphics.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function retval = isgraphics (h, type = "") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -61,8 +61,8 @@ %! assert (isgraphics (hf, "figure")); %! assert (! isgraphics (-hf)); %! assert (! isgraphics (hf, "foo")); -%! l = line; -%! ax = gca; +%! l = line (); +%! ax = gca (); %! assert (isgraphics (ax)); %! assert (isgraphics (ax, "axes")); %! assert (! isgraphics (-ax)); @@ -71,17 +71,17 @@ %! assert (isgraphics (l, "line")); %! assert (! isgraphics (-l)); %! assert (! isgraphics (l, "foo")); -%! p = patch; +%! p = patch (); %! assert (isgraphics (p)); %! assert (isgraphics (p, "patch")); %! assert (! isgraphics (-p)); %! assert (! isgraphics (p, "foo")); -%! s = surface; +%! s = surface (); %! assert (isgraphics (s)); %! assert (isgraphics (s, "surface")); %! assert (! isgraphics (-s)); %! assert (! isgraphics (s, "foo")); -%! t = text; +%! t = text (); %! assert (isgraphics (t)); %! assert (isgraphics (t, "text")); %! assert (! isgraphics (-t)); @@ -91,7 +91,7 @@ %! assert (isgraphics (i, "image")); %! assert (! isgraphics (-i)); %! assert (! isgraphics (i, "foo")); -%! hg = hggroup; +%! hg = hggroup (); %! assert (isgraphics (hg)); %! assert (isgraphics (hg, "hggroup")); %! assert (! isgraphics (-hg)); @@ -106,7 +106,6 @@ %! assert (isgraphics ([-1 0], "foobar"), [false false]); ## Test input validation -%!error isgraphics () -%!error isgraphics (1, 2, 3) +%!error <Invalid call> isgraphics () %!error <TYPE must be a string> isgraphics (0, 1) %!error <TYPE must be a string> isgraphics (0, {1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/ishandle.m --- a/scripts/plot/util/ishandle.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/ishandle.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function retval = ishandle (h) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -55,8 +55,8 @@ %! unwind_protect %! assert (ishandle (hf)); %! assert (! ishandle (-hf)); -%! ax = gca; -%! l = line; +%! ax = gca (); +%! l = line (); %! assert (ishandle (ax)); %! assert (! ishandle (-ax)); %! assert (ishandle ([l, -1, ax, hf]), logical ([1, 0, 1, 1])); @@ -72,5 +72,4 @@ %! assert (ishandle (jobj)); ## Test input validation -%!error ishandle () -%!error ishandle (1, 2) +%!error <Invalid call> ishandle () diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/ishold.m --- a/scripts/plot/util/ishold.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/ishold.m Thu Nov 19 13:08:00 2020 -0800 @@ -37,10 +37,6 @@ function retval = ishold (h) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) fig = gcf (); ax = get (fig, "currentaxes"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/isprop.m --- a/scripts/plot/util/isprop.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/isprop.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,29 +31,42 @@ ## logical array indicating whether each handle has the property @var{prop}. ## ## For plotting, @var{obj} is a handle to a graphics object. Otherwise, -## @var{obj} should be an instance of a class. -## @seealso{get, set, ismethod, isobject} +## @var{obj} should be an instance of a class. @code{isprop} reports whether +## the class defines a property, but @code{Access} permissions or visibility +## restrictions (@code{Hidden = true}) may prevent use by the programmer. +## @seealso{get, set, properties, ismethod, isobject} ## @end deftypefn function res = isprop (obj, prop) if (nargin != 2) print_usage (); - elseif (! ischar (prop)) + endif + + if (! ischar (prop)) error ("isprop: PROP name must be a string"); endif - warning ("error", "Octave:abbreviated-property-match", "local"); + if (isobject (obj)) + ## Separate code for classdef objects because Octave doesn't handle arrays + ## of objects and so can't use the generic code. + warning ("off", "Octave:classdef-to-struct", "local"); + + all_props = __fieldnames__ (obj); + res = any (strcmp (prop, all_props)); + else + warning ("error", "Octave:abbreviated-property-match", "local"); - res = false (size (obj)); - for i = 1:numel (res) - if (ishghandle (obj(i))) - try - v = get (obj(i), prop); - res(i) = true; - end_try_catch - endif - endfor + res = false (size (obj)); + for i = 1:numel (res) + if (ishghandle (obj(i))) + try + get (obj(i), prop); + res(i) = true; + end_try_catch + endif + endfor + endif endfunction @@ -63,7 +76,11 @@ %!assert (isprop (zeros (2, 3), "visible"), true (2, 3)) %!assert (isprop ([-2, -1, 0], "visible"), [false, false, true]) -%!error isprop () -%!error isprop (1) -%!error isprop (1,2,3) +%!test +%! m = containers.Map (); +%! assert (isprop (m, "KeyType")); +%! assert (! isprop (m, "FooBar")); + +%!error <Invalid call> isprop () +%!error <Invalid call> isprop (1) %!error <PROP name must be a string> isprop (0, {"visible"}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/linkaxes.m --- a/scripts/plot/util/linkaxes.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/linkaxes.m Thu Nov 19 13:08:00 2020 -0800 @@ -59,7 +59,7 @@ function linkaxes (hax, optstr = "xy") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -165,6 +165,5 @@ %! end_unwind_protect ## Test input validation -%!error linkaxes () -%!error linkaxes (1,2,3) +%!error <Invalid call> linkaxes () %!error <HAX must be a vector of axes handles> linkaxes ([pi, e]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/linkprop.m --- a/scripts/plot/util/linkprop.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/linkprop.m Thu Nov 19 13:08:00 2020 -0800 @@ -171,9 +171,8 @@ %! end_unwind_protect ## Test input validation -%!error linkprop () -%!error linkprop (1) -%!error linkprop (1,2,3) +%!error <Invalid call> linkprop () +%!error <Invalid call> linkprop (1) %!error <H must contain at least 2 handles> linkprop (1, "color") %!error <invalid graphic handle in input H> linkprop ([pi, e], "color") %!error <PROP must be a string or cell string array> linkprop ([0, 0], 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/meshgrid.m --- a/scripts/plot/util/meshgrid.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/meshgrid.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ function [xx, yy, zz] = meshgrid (x, y, z) - if (nargin == 0 || nargin > 3) + if (nargin == 0) print_usage (); endif @@ -144,8 +144,7 @@ %! assert (XX(end) * YY(end), x(end) * y(end)); ## Test input validation -%!error meshgrid () -%!error meshgrid (1,2,3,4) +%!error <Invalid call> meshgrid () %!error <X and Y must be vectors> meshgrid (ones (2,2), 1:3) %!error <X and Y must be vectors> meshgrid (1:3, ones (2,2)) %!error <X, Y, and Z must be vectors> [X,Y,Z] = meshgrid (1:3, 1:3, ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/module.mk --- a/scripts/plot/util/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -24,6 +24,7 @@ %reldir%/private/__set_default_mouse_modes__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/__actual_axis_position__.m \ %reldir%/__default_plot_options__.m \ %reldir%/__gnuplot_drawnow__.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/ndgrid.m --- a/scripts/plot/util/ndgrid.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/ndgrid.m Thu Nov 19 13:08:00 2020 -0800 @@ -95,8 +95,8 @@ %! x = 1:3; %! [XX, YY] = ndgrid (x); %! assert (size_equal (XX, YY)); -%! assert (isequal (XX, repmat(x(:), 1, numel(x)))); -%! assert (isequal (YY, repmat(x, numel(x), 1))); +%! assert (isequal (XX, repmat (x(:), 1, numel (x)))); +%! assert (isequal (YY, repmat (x, numel (x), 1))); %!test %! x = 1:2; @@ -124,10 +124,10 @@ %! assert (XX1, XX2.'); %! assert (YY1, YY2.'); -%!assert (ndgrid ([]), zeros(0,1)) +%!assert (ndgrid ([]), zeros (0,1)) %!assert (ndgrid ([], []), zeros(0,0)) ## Test input validation -%!error ndgrid () +%!error <Invalid call> ndgrid () %!error <wrong number of input arguments> [a,b,c] = ndgrid (1:3,1:3) %!error <arguments must be vectors> ndgrid (ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/newplot.m --- a/scripts/plot/util/newplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/newplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -89,10 +89,6 @@ function hax = newplot (hsave = []) - if (nargin > 1) - print_usage (); - endif - cf = []; ca = []; diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/pan.m --- a/scripts/plot/util/pan.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/pan.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,35 +46,31 @@ ## @seealso{rotate3d, zoom} ## @end deftypefn -function pan (varargin) - - hfig = NaN; - - nargs = nargin; +function h = pan (hfig, option) - if (nargs > 2) - print_usage (); - endif - - if (nargin == 1 && nargout > 0 && isfigure (varargin{1})) + ## FIXME: Presumably should implement this for Matlab compatibility. + if (nargin == 1 && nargout > 0 && isfigure (hfig)) error ("pan: syntax 'handle = pan (hfig)' not implemented"); endif - if (nargs == 2) - hfig = varargin{1}; - if (isfigure (hfig)) - varargin(1) = []; - nargs -= 1; + if (nargin == 0) + hfig = gcf (); + else + if (nargin == 1) + option = hfig; + hfig = gcf (); else - error ("pan: invalid figure handle HFIG"); + if (! isfigure (hfig)) + error ("pan: invalid figure handle HFIG"); + endif + endif + + if (! ischar (option)) + error ("pan: OPTION must be a string"); endif endif - if (isnan (hfig)) - hfig = gcf (); - endif - - if (nargs == 0) + if (nargin == 0) pm = get (hfig, "__pan_mode__"); if (strcmp (pm.Enable, "on")) pm.Enable = "off"; @@ -83,31 +79,26 @@ endif set (hfig, "__pan_mode__", pm); update_mouse_mode (hfig, pm.Enable); - elseif (nargs == 1) - arg = varargin{1}; - if (ischar (arg)) - switch (arg) - case {"on", "off", "xon", "yon"} - pm = get (hfig, "__pan_mode__"); - switch (arg) - case {"on", "off"} - pm.Enable = arg; - pm.Motion = "both"; - case "xon" - pm.Enable = "on"; - pm.Motion = "horizontal"; - case "yon" - pm.Enable = "on"; - pm.Motion = "vertical"; - endswitch - set (hfig, "__pan_mode__", pm); - update_mouse_mode (hfig, arg); - otherwise - error ("pan: unrecognized OPTION '%s'", arg); - endswitch - else - error ("pan: wrong type argument '%s'", class (arg)); - endif + else + switch (option) + case {"on", "off", "xon", "yon"} + pm = get (hfig, "__pan_mode__"); + switch (option) + case {"on", "off"} + pm.Enable = option; + pm.Motion = "both"; + case "xon" + pm.Enable = "on"; + pm.Motion = "horizontal"; + case "yon" + pm.Enable = "on"; + pm.Motion = "vertical"; + endswitch + set (hfig, "__pan_mode__", pm); + update_mouse_mode (hfig, option); + otherwise + error ("pan: unrecognized OPTION '%s'", option); + endswitch endif endfunction @@ -119,8 +110,8 @@ else ## FIXME: Is there a better way other than calling these functions ## to set the other mouse mode Enable fields to "off"? - rotate3d ("off"); - zoom ("off"); + rotate3d (hfig, "off"); + zoom (hfig, "off"); set (hfig, "__mouse_mode__", "pan"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/print.m --- a/scripts/plot/util/print.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/print.m Thu Nov 19 13:08:00 2020 -0800 @@ -472,12 +472,21 @@ set (opts.figure, "__printing__", "on"); nfig += 1; - ## print() requires children of axes to have units = "normalized", or "data" - hobj = findall (opts.figure, "-not", "type", "figure", ... - "-not", "type", "axes", "-property", "units", ... + ## print() requires children of axes to have units = "normalized" or "data" + ## FIXME: Bug #59015. The only graphics object type to which this + ## requirement applies seems to be 'text' objects. It is simpler, and + ## clearer, to just select those objects. The old code is left commented + ## out until sufficient testing has been done. + ## Change made: 2020/09/02. + ##hobj = findall (opts.figure, "-not", "type", "figure", ... + ## "-not", "type", "axes", "-not", "type", "hggroup", ... + ## "-property", "units", ... + ## "-not", "units", "normalized", "-not", "units", "data"); + ##hobj(strncmp (get (hobj, "type"), "ui", 2)) = []; + + hobj = findall (opts.figure, "type", "text", "-not", "units", "normalized", "-not", "units", "data"); - hobj(strncmp (get (hobj, "type"), "ui", 2)) = []; - for n = 1:numel(hobj) + for n = 1:numel (hobj) props(end+1).h = hobj(n); props(end).name = "units"; props(end).value = {get(hobj(n), "units")}; @@ -791,6 +800,7 @@ if (isfigure (orig_figure)) set (0, "currentfigure", orig_figure); endif + endfunction function cmd = epstool (opts, filein, fileout) @@ -801,7 +811,7 @@ ## DOS Shell: ## gs.exe [...] -sOutputFile=<filein> - & epstool -bbox -preview-tiff <filein> <fileout> & del <filein> - ## Unix Shell; + ## Unix Shell: ## cat > <filein> ; epstool -bbox -preview-tiff <filein> <fileout> ; rm <filein> dos_shell = (ispc () && ! isunix ()); @@ -1004,13 +1014,10 @@ switch (opts.devopt) case {"pdflatexstandalone"} packages = "\\usepackage{graphicx,color}"; - graphicsfile = [opts.name "-inc.pdf"]; case {"pslatexstandalone"} packages = "\\usepackage{epsfig,color}"; - graphicsfile = [opts.name "-inc.ps"]; otherwise packages = "\\usepackage{epsfig,color}"; - graphicsfile = [opts.name "-inc.eps"]; endswitch packages = {packages "\\usepackage[utf8]{inputenc}"}; @@ -1033,9 +1040,6 @@ error ("Octave:print:errorclosingfile", "print: error closing file '%s'", latexfile); endif - ## FIXME: should this be fixed in GL2PS? - latex = strrep (latex, "\\includegraphics{}", - sprintf ("\\includegraphics{%s}", graphicsfile)); fid = fopen (latexfile, "w"); if (fid >= 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/private/__add_default_menu__.m --- a/scripts/plot/util/private/__add_default_menu__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/private/__add_default_menu__.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,10 +24,14 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {} __add_default_menu__ (@var{hfig}) -## @deftypefnx {} {} __add_default_menu__ (@var{hfig}, @var{hmenu}) +## @deftypefn {} {} __add_default_menu__ (@var{hf}) +## @deftypefnx {} {} __add_default_menu__ (@var{hf}, @var{hmenu}) +## @deftypefnx {} {} __add_default_menu__ (@var{hf}, @var{hmenu}, @var{htb}) ## Add default menu and listeners to figure. ## +## @var{hf} is a figure handle. +## @var{hmenu} is a uimenu handle. +## @var{htb} is a uitoolbar handle. ## ## All uimenu handles have their @qcode{"HandleVisibility"} property set to ## @qcode{"off"}. @@ -37,7 +41,7 @@ ## Gnuplot doesn't handle uimenu and uitoolbar objects if (strcmp (graphics_toolkit (), "gnuplot")) - return + return; endif ## Create @@ -45,11 +49,11 @@ ## File menu hui = uimenu (hf, "label", "&File", "tag", "__default_menu__File", ... "handlevisibility", "off"); - uimenu (hui, "label", "&Open", "callback", @open_cb, ... + uimenu (hui, "label", "&Open...", "callback", @open_cb, ... "accelerator", "o"); uimenu (hui, "label", "&Save", "callback", {@save_cb, "save"}, ... "accelerator", "s"); - uimenu (hui, "label", "Save &As", "callback", {@save_cb, "saveas"}, ... + uimenu (hui, "label", "Save &As...", "callback", {@save_cb, "saveas"}, ... "accelerator", "S"); uimenu (hui, "label", "&Close", "callback", @close_cb, ... "accelerator", "w", "separator", "on"); @@ -173,17 +177,16 @@ set (htb, "visible", toolbar_state); endfunction -function open_cb (h, e) - [filename, filedir] = uigetfile ({"*.ofig", "Octave Figure File"}, ... +function open_cb (~, ~) + [filename, filedir] = uigetfile ({"*.ofig;*.fig", "Figure Files"}, ... "Open Figure"); if (filename != 0) fname = fullfile (filedir, filename); - tmphf = hgload (fname); - set (tmphf, "filename", fname); + openfig (fname); endif endfunction -function save_cb (h, e, action) +function save_cb (h, ~, action) hfig = gcbf (); fname = get (hfig, "filename"); @@ -198,34 +201,54 @@ endif endfunction +function __save_as__ (hf, fname = "") + if (! isempty (fname)) + def = fname; + else + def = fullfile (pwd (), "untitled.ofig"); + endif + filter = {"*.ofig", "Octave Figure"; + "*.eps", "Encapsulated PostScript"; + "*.pdf", "Portable Document Format"; + "*.ps", "PostScript"; + "*.svg", "Scalable Vector Graphics"; + "*.gif", "GIF Image"; + "*.jpg", "JPEG Image"; + "*.png", "Portable Network Graphics Image"; + "*.tiff", "TIFF Image"}; + ## Reorder filters to have current first + [~, ~, ext] = fileparts (def); + idx = strcmp (filter(:,1), ["*" tolower(ext)]); + filter = [filter(idx,:); filter(! idx,:)]; -function __save_as__ (hf, fname = "") - filter = ifelse (! isempty (fname), fname, ... - {"*.ofig", "Octave Figure File"; - "*.eps;*.pdf;*.svg;*.ps", "Vector Image Formats"; - "*.gif;*.jpg;*.png;*.tiff", "Bitmap Image Formats"}); - def = ifelse (! isempty (fname), fname, fullfile (pwd, "untitled.ofig")); - - [filename, filedir] = uiputfile (filter, "Save Figure", def); + [filename, filedir, filteridx] = uiputfile (filter, "Save Figure", def); if (filename != 0) fname = fullfile (filedir, filename); - set (gcbf, "filename", fname); - flen = numel (fname); - if (flen > 5 && strcmp (fname(flen-4:end), ".ofig")) - hgsave (hf, fname); + [~, ~, ext] = fileparts (fname); + if (filteridx > rows (filter)) + ## "All Files" option + if (isempty (ext)) + fmt = ""; + else + fmt = ext(2:end); + endif else - saveas (hf, fname); + fmt = filter{filteridx,1}(3:end); + if (isempty (ext)) + fname = [fname "." fmt]; + endif endif + set (hf, "filename", fname); + saveas (hf, fname, fmt); endif + endfunction - -function close_cb (h, e) - close (gcbf); +function close_cb (~, ~) + close (gcbf ()); endfunction - function [hax, fig] = __get_axes__ (h) ## Get parent figure fig = ancestor (h, "figure"); @@ -234,7 +257,7 @@ hax = findobj (fig, "type", "axes", "-not", "tag", "legend"); endfunction -function autoscale_cb (h, e) +function autoscale_cb (h, ~) hax = __get_axes__ (h); arrayfun (@(h) axis (h, "auto"), hax); drawnow (); @@ -253,7 +276,8 @@ "FigureHandle", hf)); endfunction -function guimode_cb (h, e) +function guimode_cb (h, ~) + [hax, fig] = __get_axes__ (h); id = get (h, "tag"); switch (id) @@ -273,9 +297,10 @@ case "zoom_off" arrayfun (@(h) set (h, "mousewheelzoom", 0.0), hax); endswitch + endfunction -function mouse_tools_cb (h, ev, htools, typ = "") +function mouse_tools_cb (h, ~, htools, typ = "") persistent recursion = false; @@ -290,7 +315,7 @@ mode = get (hf, "__mouse_mode__"); state = "on"; - switch mode + switch (mode) case "zoom" zm = get (hf, "__zoom_mode__"); if (strcmp (zm.Direction, "in")) @@ -318,7 +343,7 @@ ## Update the mouse mode according to the button state state = get (h, "state"); - switch typ + switch (typ) case {"zoomin", "zoomout"} prop = "__zoom_mode__"; val = get (hf, prop); @@ -329,7 +354,7 @@ else val.Direction = "out"; endif - set (hf, "__mouse_mode__" , "zoom"); + set (hf, "__mouse_mode__", "zoom"); endif val.Enable = state; set (hf, prop, val); @@ -338,21 +363,21 @@ prop = ["__", typ, "_mode__"]; val = get (hf, prop); if (strcmp (state, "on")) - set (hf, "__mouse_mode__" , typ); + set (hf, "__mouse_mode__", typ); endif val.Enable = state; set (hf, prop, val); case {"text", "select"} if (strcmp (state, "on")) - set (hf, "__mouse_mode__" , typ); + set (hf, "__mouse_mode__", typ); endif endswitch if (strcmp (state, "on")) set (htools(htools != h), "state", "off"); elseif (! any (strcmp (get (htools, "state"), "on"))) - set (hf, "__mouse_mode__" , "none"); + set (hf, "__mouse_mode__", "none"); endif endif @@ -361,7 +386,7 @@ endfunction -function axes_cb (h) +function axes_cb (h, ~) hax = get (gcbf (), "currentaxes"); if (! isempty (hax)) if (strcmp (get (hax, "visible"), "on")) @@ -372,7 +397,7 @@ endif endfunction -function grid_cb (h) +function grid_cb (h, ~) hax = get (gcbf (), "currentaxes"); if (! isempty (hax)) if (strcmp (get (hax, "xgrid"), "on") && strcmp (get (hax, "ygrid"), "on")) @@ -383,14 +408,15 @@ endif endfunction -function auto_cb (h) +function auto_cb (h, ~) hax = get (gcbf (), "currentaxes"); if (! isempty (hax)) axis (hax, "auto"); endif endfunction -function clipboard_cb (h) +function clipboard_cb (h, ~) + hf = gcbf (); fname = tempname (); props = {"inverthardcopy", "paperposition", "paperpositionmode"}; @@ -402,4 +428,5 @@ unwind_protect_cleanup set (hf, props, values); end_unwind_protect + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/private/__gnuplot_draw_axes__.m --- a/scripts/plot/util/private/__gnuplot_draw_axes__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m Thu Nov 19 13:08:00 2020 -0800 @@ -56,6 +56,10 @@ endif nd = __calc_dimensions__ (h); + if (nd == 2 && (any (get (h, "view") != [0, 90]))) + ## view() only works correctly on 3-D axes in gnuplot (bug #58526). + nd = 3; + endif if (strcmp (axis_obj.dataaspectratiomode, "manual") && strcmp (axis_obj.xlimmode, "manual") @@ -87,7 +91,7 @@ dr = 1; endif - if (strcmp (axis_obj.activepositionproperty, "position")) + if (strcmp (axis_obj.positionconstraint, "innerposition")) if (nd == 2 || all (mod (axis_obj.view, 90) == 0)) x = [1, 1]; else @@ -103,7 +107,7 @@ fprintf (plot_stream, "set rmargin screen %.15g;\n", pos(1)+pos(3)/2+x(1)*pos(3)/2); sz_str = ""; - else ## activepositionproperty == outerposition + else # positionconstraint == outerposition fprintf (plot_stream, "unset tmargin;\n"); fprintf (plot_stream, "unset bmargin;\n"); fprintf (plot_stream, "unset lmargin;\n"); @@ -148,13 +152,13 @@ fputs (plot_stream, "unset title;\n"); else if (nd == 2) - t = get(axis_obj.title); + t = get (axis_obj.title); colorspec = get_text_colorspec (t.color); - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", t.interpreter); + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", ... + t.interpreter, gnuplot_term); fontspec = create_fontspec (f, s, gnuplot_term); fprintf (plot_stream, ['set title "%s" %s %s %s;' "\n"], - undo_string_escapes (tt), fontspec, colorspec, - __do_enhanced_option__ (enhanced, t)); + tt, fontspec, colorspec, __do_enhanced_option__ (enhanced, t)); else ## Change meaning of "normalized", but it at least gives user some control if (! strcmp (get (axis_obj.title, "units"), "normalized")) @@ -164,7 +168,7 @@ unwind_protect_cleanup end_unwind_protect endif - t = get(axis_obj.title); + t = get (axis_obj.title); axispos = axis_obj.position; screenpos = t.position; screenpos(1) = axispos(1)+screenpos(1)*axispos(3); @@ -182,16 +186,15 @@ fprintf (plot_stream, "unset xlabel;\n"); fprintf (plot_stream, "unset x2label;\n"); else - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", t.interpreter); + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", ... + t.interpreter, gnuplot_term); fontspec = create_fontspec (f, s, gnuplot_term); if (strcmp (axis_obj.xaxislocation, "top")) fprintf (plot_stream, 'set x2label "%s" %s %s %s', - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); + tt, colorspec, fontspec, __do_enhanced_option__ (enhanced, t)); else fprintf (plot_stream, 'set xlabel "%s" %s %s %s', - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); + tt, colorspec, fontspec, __do_enhanced_option__ (enhanced, t)); endif fprintf (plot_stream, " rotate by %f;\n", angle); if (strcmp (axis_obj.xaxislocation, "top")) @@ -210,16 +213,15 @@ fprintf (plot_stream, "unset ylabel;\n"); fprintf (plot_stream, "unset y2label;\n"); else - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", t.interpreter); + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", ... + t.interpreter, gnuplot_term); fontspec = create_fontspec (f, s, gnuplot_term); if (strcmp (axis_obj.yaxislocation, "right")) fprintf (plot_stream, 'set y2label "%s" %s %s %s', - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); + tt, colorspec, fontspec, __do_enhanced_option__ (enhanced, t)); else fprintf (plot_stream, 'set ylabel "%s" %s %s %s', - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); + tt, colorspec, fontspec, __do_enhanced_option__ (enhanced, t)); endif fprintf (plot_stream, " rotate by %f;\n", angle); if (strcmp (axis_obj.yaxislocation, "right")) @@ -237,11 +239,11 @@ if (isempty (t.string)) fputs (plot_stream, "unset zlabel;\n"); else - [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", t.interpreter); + [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", ... + t.interpreter, gnuplot_term); fontspec = create_fontspec (f, s, gnuplot_term); fprintf (plot_stream, 'set zlabel "%s" %s %s %s', - undo_string_escapes (tt), colorspec, fontspec, - __do_enhanced_option__ (enhanced, t)); + tt, colorspec, fontspec, __do_enhanced_option__ (enhanced, t)); fprintf (plot_stream, " rotate by %f;\n", angle); endif endif @@ -625,13 +627,12 @@ have_3d_patch(data_idx) = false; tmpdispname = obj.displayname; obj.displayname = get (obj.parent, "displayname"); - tmp = undo_string_escapes ( - __maybe_munge_text__ (enhanced, obj, "displayname", hlgndntrp) - ); + tmp = __maybe_munge_text__ (enhanced, obj, "displayname", ... + hlgndntrp, gnuplot_term); titlespec{data_idx} = ['title "' tmp '"']; obj.displayname = tmpdispname; if (! isempty (findobj (obj.parent, "-property", "format", "-depth", 0))) - # Place phantom errorbar data for legend + ## Place phantom errorbar data for legend data{data_idx} = NaN (4,1); usingclause{data_idx} = sprintf ("record=1 using ($1):($2):($3):($4)"); switch (get (obj.parent, "format")) @@ -646,15 +647,15 @@ otherwise errbars = "xerrorbars"; endswitch - withclause{data_idx} = sprintf ("with %s linestyle %d", + withclause{data_idx} = sprintf ("with %s linestyle %d", ... errbars, sidx(1)); else ## Place phantom stemseries data for legend data{data_idx} = NaN (2,1); usingclause{data_idx} = sprintf ("record=1 using ($1):($2)"); hgobj = get (obj.parent); - [hgstyle, hgsidx] = do_linestyle_command (hgobj, hgobj.color, data_idx, - plot_stream); + [hgstyle, hgsidx] = do_linestyle_command (hgobj, hgobj.color, ... + data_idx, plot_stream); withclause{data_idx} = sprintf ("with %s linestyle %d", hgstyle{1}, hgsidx(1)); endif @@ -675,9 +676,8 @@ if (isempty (obj.displayname)) titlespec{data_idx} = 'title ""'; else - tmp = undo_string_escapes ( - __maybe_munge_text__ (enhanced, obj, "displayname", hlgndntrp) - ); + tmp = __maybe_munge_text__ (enhanced, obj, "displayname", ... + hlgndntrp, gnuplot_term); titlespec{data_idx} = ['title "' tmp '"']; endif usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata)); @@ -798,9 +798,8 @@ if (i > 1 || isempty (obj.displayname)) titlespec{local_idx} = 'title ""'; else - tmp = undo_string_escapes ( - __maybe_munge_text__ (enhanced, obj, "displayname", hlgndntrp) - ); + tmp = __maybe_munge_text__ (enhanced, obj, "displayname", ... + hlgndntrp, gnuplot_term); titlespec{local_idx} = ['title "' tmp '"']; endif if (isfield (obj, "facecolor")) @@ -865,7 +864,7 @@ if (nd == 3 && numel (xcol) == 3) if (isnan (ccdat)) - ccdat = (cmap_sz + rows (addedcmap) + 1) * ones(3, 1); + ccdat = (cmap_sz + rows (addedcmap) + 1) * ones (3, 1); addedcmap = [addedcmap; reshape(color, 1, 3)]; elseif (numel (ccdat) == 1) ccdat = ccdat * ones (size (zcol)); @@ -1001,7 +1000,7 @@ colorspec = "palette"; elseif (columns (ccol) == 3) colorspec = "lc rgb variable"; - ccol = 255*ccol*[0x1; 0x100; 0x10000]; + ccol = 255*ccol*double ([0x00_00_01; 0x00_01_00; 0x01_00_00]); endif else colorspec = sprintf ('lc rgb "#%02x%02x%02x"', @@ -1211,9 +1210,8 @@ parametric(data_idx) = false; have_cdata(data_idx) = false; have_3d_patch(data_idx) = false; - tmp = undo_string_escapes ( - __maybe_munge_text__ (enhanced, obj, "displayname", hlgndntrp) - ); + tmp = __maybe_munge_text__ (enhanced, obj, "displayname", ... + hlgndntrp, gnuplot_term); titlespec{data_idx} = ['title "' tmp '"']; data{data_idx} = NaN (3,1); usingclause{data_idx} = sprintf ("record=1 using ($1):($2):($3)"); @@ -1976,7 +1974,7 @@ endif endif endif - if (! isempty(pt) && isfield (obj, "markeredgecolor") + if (! isempty (pt) && isfield (obj, "markeredgecolor") && ! strcmp (obj.markeredgecolor, "none")) if (facesame && (strcmp (obj.markeredgecolor, "auto") || (isnumeric (obj.markeredgecolor) @@ -2007,7 +2005,7 @@ edgecolor = obj.markeredgecolor; else edgecolor = obj.color; - end + endif fprintf (plot_stream, ' linecolor rgb "#%02x%02x%02x"', round (255*edgecolor)); else @@ -2264,7 +2262,8 @@ endif if (strcmp (interpreter, "tex")) for n = 1 : numel (labels) - labels{n} = __tex2enhanced__ (labels{n}, fontname, false, false); + labels{n} = __tex2enhanced__ (labels{n}, fontname, false, false, ... + gnuplot_term); endfor elseif (strcmp (interpreter, "latex")) if (! warned_latex) @@ -2295,7 +2294,7 @@ fprintf (plot_stream, ['set format %s "%s";' "\n"], ax, fmt); if (strcmp (ticmode, "manual") && isempty (tics)) fprintf (plot_stream, "unset %stics;\nunset m%stics;\n", ax, ax); - return + return; else k = 1; ntics = numel (tics); @@ -2305,7 +2304,7 @@ tickdir, ticklength, axispos, mirror); labels = strrep (labels, "%", "%%"); for i = 1:ntics - fprintf (plot_stream, ' "%s" %.15g', labels{k++}, tics(i)); + fprintf (plot_stream, ' "%s" %.15f', labels{k++}, tics(i)); if (i < ntics) fputs (plot_stream, ", "); endif @@ -2395,7 +2394,8 @@ endfunction -function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld, ntrp) +function [str, f, s] = __maybe_munge_text__ (enhanced, obj, fld, ntrp, ... + gnuplot_term) persistent warned_latex = false; if (strcmp (fld, "string")) @@ -2432,10 +2432,10 @@ if (strcmp (ntrp, "tex")) if (iscellstr (str)) for n = 1:numel (str) - str{n} = __tex2enhanced__ (str{n}, fnt, it, bld); + str{n} = __tex2enhanced__ (str{n}, fnt, it, bld, gnuplot_term); endfor else - str = __tex2enhanced__ (str, fnt, it, bld); + str = __tex2enhanced__ (str, fnt, it, bld, gnuplot_term); endif elseif (strcmp (ntrp, "latex")) if (! warned_latex) @@ -2451,20 +2451,26 @@ endfunction -function str = __tex2enhanced__ (str, fnt, it, bld) +function str = __tex2enhanced__ (str, fnt, it, bld, gnuplot_term) persistent sym = __setup_sym_table__ (); persistent flds = fieldnames (sym); + if (any (strcmp (gnuplot_term, {"postscript", "epscairo"}))) + symtype = 1; + else + symtype = 2; + endif + [s, e, m] = regexp (str, "\\\\([a-zA-Z]+|0)", "start", "end", "matches"); for i = length (s) : -1 : 1 - ## special case for "\0" and replace with empty set "{/Symbol \306}' + ## special case for "\0" and replace with empty set equivalent if (strncmp (m{i}, '\0', 2)) - str = [str(1:s(i) - 1) '{/Symbol \306}' str(s(i) + 2:end)]; + str = [str(1:s(i) - 1) sym.emptyset{symtype} str(s(i) + 2:end)]; else f = m{i}(2:end); if (isfield (sym, f)) - g = getfield (sym, f); + g = sym.(f){symtype}; ## FIXME: The symbol font doesn't seem to support bold or italic ##if (bld) ## if (it) @@ -2528,8 +2534,8 @@ '{}', str(e(i) + b2(1) + 1:end)]; endif elseif (strcmp (f, "fontsize")) - b1 = strfind (str(e(i) + 1:end),'{'); - b2 = strfind (str(e(i) + 1:end),'}'); + b1 = strfind (str(e (i) + 1:end),'{'); + b2 = strfind (str(e (i) + 1:end),'}'); if (isempty (b1) || isempty (b2)) warning ('syntax error in \fontname argument'); else @@ -2541,7 +2547,7 @@ ## like \pix, that should be translated to the symbol Pi and x for j = 1 : length (flds) if (strncmp (flds{j}, f, length (flds{j}))) - g = getfield (sym, flds{j}); + g = sym.(flds{j}){symtype}; ## FIXME: The symbol font doesn't seem to support bold or italic ##if (bld) ## if (it) @@ -2564,7 +2570,7 @@ ## But need to put the shorter of the two arguments first. ## Careful of nested {} and unprinted characters when defining ## shortest.. Don't have to worry about things like ^\theta as they - ## are already converted to ^{/Symbol q}. + ## are already converted. ## FIXME: This is a mess. Is it worth it just for a "@" character? @@ -2653,118 +2659,122 @@ endfunction function sym = __setup_sym_table__ () + ## Setup the translation table for TeX to gnuplot enhanced mode. - sym.forall = '{/Symbol \042}'; - sym.exists = '{/Symbol \044}'; - sym.ni = '{/Symbol \047}'; - sym.cong = '{/Symbol \100}'; - sym.Delta = '{/Symbol D}'; - sym.Phi = '{/Symbol F}'; - sym.Gamma = '{/Symbol G}'; - sym.vartheta = '{/Symbol J}'; - sym.Lambda = '{/Symbol L}'; - sym.Pi = '{/Symbol P}'; - sym.Theta = '{/Symbol Q}'; - sym.Sigma = '{/Symbol S}'; - sym.varsigma = '{/Symbol V}'; - sym.Omega = '{/Symbol W}'; - sym.Xi = '{/Symbol X}'; - sym.Psi = '{/Symbol Y}'; - sym.perp = '{/Symbol \136}'; - sym.alpha = '{/Symbol a}'; - sym.beta = '{/Symbol b}'; - sym.chi = '{/Symbol c}'; - sym.delta = '{/Symbol d}'; - sym.epsilon = '{/Symbol e}'; - sym.phi = '{/Symbol f}'; - sym.gamma = '{/Symbol g}'; - sym.eta = '{/Symbol h}'; - sym.iota = '{/Symbol i}'; - sym.varphi = '{/Symbol j}'; # Not in OpenGL - sym.kappa = '{/Symbol k}'; - sym.lambda = '{/Symbol l}'; - sym.mu = '{/Symbol m}'; - sym.nu = '{/Symbol n}'; - sym.o = '{/Symbol o}'; - sym.pi = '{/Symbol p}'; - sym.theta = '{/Symbol q}'; - sym.rho = '{/Symbol r}'; - sym.sigma = '{/Symbol s}'; - sym.tau = '{/Symbol t}'; - sym.upsilon = '{/Symbol u}'; - sym.varpi = '{/Symbol v}'; - sym.omega = '{/Symbol w}'; - sym.xi = '{/Symbol x}'; - sym.psi = '{/Symbol y}'; - sym.zeta = '{/Symbol z}'; - sym.sim = '{/Symbol \176}'; - sym.Upsilon = '{/Symbol \241}'; - sym.prime = '{/Symbol \242}'; - sym.leq = '{/Symbol \243}'; - sym.infty = '{/Symbol \245}'; - sym.clubsuit = '{/Symbol \247}'; - sym.diamondsuit = '{/Symbol \250}'; - sym.heartsuit = '{/Symbol \251}'; - sym.spadesuit = '{/Symbol \252}'; - sym.leftrightarrow = '{/Symbol \253}'; - sym.leftarrow = '{/Symbol \254}'; - sym.uparrow = '{/Symbol \255}'; - sym.rightarrow = '{/Symbol \256}'; - sym.downarrow = '{/Symbol \257}'; - sym.circ = '{/Symbol \260}'; # degree symbol, not circ as in FLTK - sym.deg = '{/Symbol \260}'; - sym.ast = '{/Symbol *}'; - sym.pm = '{/Symbol \261}'; - sym.geq = '{/Symbol \263}'; - sym.times = '{/Symbol \264}'; - sym.propto = '{/Symbol \265}'; - sym.partial = '{/Symbol \266}'; - sym.bullet = '{/Symbol \267}'; - sym.div = '{/Symbol \270}'; - sym.neq = '{/Symbol \271}'; - sym.equiv = '{/Symbol \272}'; - sym.approx = '{/Symbol \273}'; - sym.ldots = '{/Symbol \274}'; - sym.mid = '{/Symbol \275}'; - sym.aleph = '{/Symbol \300}'; - sym.Im = '{/Symbol \301}'; - sym.Re = '{/Symbol \302}'; - sym.wp = '{/Symbol \303}'; - sym.otimes = '{/Symbol \304}'; - sym.oplus = '{/Symbol \305}'; + sym.forall = {'{/Symbol \042}', '∀'}; + sym.exists = {'{/Symbol \044}', '∃'}; + sym.ni = {'{/Symbol \047}', '∋'}; + sym.cong = {'{/Symbol \100}', '≅'}; + sym.Delta = {'{/Symbol D}', 'Δ'}; + sym.Phi = {'{/Symbol F}', 'Φ'}; + sym.Gamma = {'{/Symbol G}', 'Γ'}; + sym.vartheta = {'{/Symbol J}', 'ϑ'}; + sym.Lambda = {'{/Symbol L}', 'Λ'}; + sym.Pi = {'{/Symbol P}', 'Π'}; + sym.Theta = {'{/Symbol Q}', 'Θ'}; + sym.Sigma = {'{/Symbol S}', 'Σ'}; + sym.varsigma = {'{/Symbol V}', 'ς'}; + sym.Omega = {'{/Symbol W}', 'Ω'}; + sym.Xi = {'{/Symbol X}', 'Ξ'}; + sym.Psi = {'{/Symbol Y}', 'Ψ'}; + sym.perp = {'{/Symbol \136}', '⊥'}; + sym.alpha = {'{/Symbol a}', 'α'}; + sym.beta = {'{/Symbol b}', 'β'}; + sym.chi = {'{/Symbol c}', 'χ'}; + sym.delta = {'{/Symbol d}', 'δ'}; + sym.epsilon = {'{/Symbol e}', 'ε'}; + sym.phi = {'{/Symbol f}', 'ϕ'}; + sym.gamma = {'{/Symbol g}', 'γ'}; + sym.eta = {'{/Symbol h}', 'η'}; + sym.iota = {'{/Symbol i}', 'ι'}; + sym.varphi = {'{/Symbol j}', 'φ'}; # Not in OpenGL + sym.kappa = {'{/Symbol k}', 'κ'}; + sym.lambda = {'{/Symbol l}', 'λ'}; + sym.mu = {'{/Symbol m}', 'μ'}; + sym.nu = {'{/Symbol n}', 'ν'}; + sym.o = {'{/Symbol o}', 'ο'}; + sym.pi = {'{/Symbol p}', 'π'}; + sym.theta = {'{/Symbol q}', 'θ'}; + sym.rho = {'{/Symbol r}', 'ρ'}; + sym.sigma = {'{/Symbol s}', 'σ'}; + sym.tau = {'{/Symbol t}', 'τ'}; + sym.upsilon = {'{/Symbol u}', 'υ'}; + sym.varpi = {'{/Symbol v}', 'ϖ'}; + sym.omega = {'{/Symbol w}', 'ω'}; + sym.xi = {'{/Symbol x}', 'ξ'}; + sym.psi = {'{/Symbol y}', 'ψ'}; + sym.zeta = {'{/Symbol z}', 'ζ'}; + sym.sim = {'{/Symbol \176}', '∼'}; + sym.Upsilon = {'{/Symbol \241}', 'Υ'}; + sym.prime = {'{/Symbol \242}', '′'}; + sym.leq = {'{/Symbol \243}', '≤'}; + sym.infty = {'{/Symbol \245}', '∞'}; + sym.clubsuit = {'{/Symbol \247}', '♣'}; + sym.diamondsuit = {'{/Symbol \250}', '♢'}; + sym.heartsuit = {'{/Symbol \251}', '♡'}; + sym.spadesuit = {'{/Symbol \252}', '♠'}; + sym.leftrightarrow = {'{/Symbol \253}', '↔'}; + sym.leftarrow = {'{/Symbol \254}', '←'}; + sym.uparrow = {'{/Symbol \255}', '↑'}; + sym.rightarrow = {'{/Symbol \256}', '→'}; + sym.downarrow = {'{/Symbol \257}', '↓'}; + sym.circ = {'{/Symbol \260}', '∘'}; + ## degree symbol, not circ as in FLTK + sym.deg = {'{/Symbol \260}', '°'}; + sym.ast = {'{/Symbol *}', '∗'}; + sym.pm = {'{/Symbol \261}', '±'}; + sym.geq = {'{/Symbol \263}', '≥'}; + sym.times = {'{/Symbol \264}', '×'}; + sym.propto = {'{/Symbol \265}', '∝'}; + sym.partial = {'{/Symbol \266}', '∂'}; + sym.bullet = {'{/Symbol \267}', '∙'}; + sym.div = {'{/Symbol \270}', '÷'}; + sym.neq = {'{/Symbol \271}', '≠'}; + sym.equiv = {'{/Symbol \272}', '≡'}; + sym.approx = {'{/Symbol \273}', '≈'}; + sym.ldots = {'{/Symbol \274}', '…'}; + sym.mid = {'{/Symbol \275}', '∣'}; + sym.aleph = {'{/Symbol \300}', 'ℵ'}; + sym.Im = {'{/Symbol \301}', 'ℑ'}; + sym.Re = {'{/Symbol \302}', 'ℜ'}; + sym.wp = {'{/Symbol \303}', '℘'}; + sym.otimes = {'{/Symbol \304}', '⊗'}; + sym.oplus = {'{/Symbol \305}', '⊕'}; ## empty set, not circled slash division operator as in FLTK. - sym.oslash = '{/Symbol \306}'; - sym.cap = '{/Symbol \307}'; - sym.cup = '{/Symbol \310}'; - sym.supset = '{/Symbol \311}'; - sym.supseteq = '{/Symbol \312}'; - sym.subset = '{/Symbol \314}'; - sym.subseteq = '{/Symbol \315}'; - sym.in = '{/Symbol \316}'; - sym.notin = '{/Symbol \317}'; # Not in OpenGL - sym.angle = '{/Symbol \320}'; - sym.bigtriangledown = '{/Symbol \321}'; # Not in OpenGL - sym.langle = '{/Symbol \341}'; - sym.rangle = '{/Symbol \361}'; - sym.nabla = '{/Symbol \321}'; - sym.prod = '{/Symbol \325}'; # Not in OpenGL - sym.surd = '{/Symbol \326}'; - sym.cdot = '{/Symbol \327}'; - sym.neg = '{/Symbol \330}'; - sym.wedge = '{/Symbol \331}'; - sym.vee = '{/Symbol \332}'; - sym.Leftrightarrow = '{/Symbol \333}'; # Not in OpenGL - sym.Leftarrow = '{/Symbol \334}'; - sym.Uparrow = '{/Symbol \335}'; # Not in OpenGL - sym.Rightarrow = '{/Symbol \336}'; - sym.Downarrow = '{/Symbol \337}'; # Not in OpenGL - sym.diamond = '{/Symbol \340}'; # Not in OpenGL - sym.copyright = '{/Symbol \343}'; - sym.lfloor = '{/Symbol \353}'; - sym.lceil = '{/Symbol \351}'; - sym.rfloor = '{/Symbol \373}'; - sym.rceil = '{/Symbol \371}'; - sym.int = '{/Symbol \362}'; + sym.oslash = {'{/Symbol \306}', '⊘'}; + sym.emptyset = {'{/Symbol \306}', '∅'}; + sym.cap = {'{/Symbol \307}', '∩'}; + sym.cup = {'{/Symbol \310}', '∪'}; + sym.supset = {'{/Symbol \311}', '⊃'}; + sym.supseteq = {'{/Symbol \312}', '⊇'}; + sym.subset = {'{/Symbol \314}', '⊂'}; + sym.subseteq = {'{/Symbol \315}', '⊑'}; + sym.in = {'{/Symbol \316}', '∈'}; + sym.notin = {'{/Symbol \317}', '∋'}; # Not in OpenGL + sym.angle = {'{/Symbol \320}', '∠'}; + sym.bigtriangledown = {'{/Symbol \321}', '▽'}; # Not in OpenGL + sym.langle = {'{/Symbol \341}', '〈'}; + sym.rangle = {'{/Symbol \361}', '〉'}; + sym.nabla = {'{/Symbol \321}', '∇'}; + sym.prod = {'{/Symbol \325}', '∏'}; # Not in OpenGL + sym.surd = {'{/Symbol \326}', '√'}; + sym.cdot = {'{/Symbol \327}', '⋅'}; + sym.neg = {'{/Symbol \330}', '¬'}; + sym.wedge = {'{/Symbol \331}', '∧'}; + sym.vee = {'{/Symbol \332}', '∨'}; + sym.Leftrightarrow = {'{/Symbol \333}', '⇔'}; # Not in OpenGL + sym.Leftarrow = {'{/Symbol \334}', '⇐'}; + sym.Uparrow = {'{/Symbol \335}', '⇑'}; # Not in OpenGL + sym.Rightarrow = {'{/Symbol \336}', '⇒'}; + sym.Downarrow = {'{/Symbol \337}', '⇓'}; # Not in OpenGL + sym.diamond = {'{/Symbol \340}', '⋄'}; # Not in OpenGL + sym.copyright = {'{/Symbol \343}', '©'}; + sym.lfloor = {'{/Symbol \353}', '⌊'}; + sym.lceil = {'{/Symbol \351}', '⌈'}; + sym.rfloor = {'{/Symbol \373}', '⌋'}; + sym.rceil = {'{/Symbol \371}', '⌉'}; + sym.int = {'{/Symbol \362}', '∫'}; + endfunction function retval = __do_enhanced_option__ (enhanced, obj) @@ -2782,7 +2792,8 @@ function do_text (stream, gpterm, enhanced, obj, hax, screenpos) - [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string", obj.interpreter); + [label, f, s] = __maybe_munge_text__ (enhanced, obj, "string", ... + obj.interpreter, gpterm); fontspec = create_fontspec (f, s, gpterm); lpos = obj.position; halign = obj.horizontalalignment; @@ -2840,13 +2851,13 @@ endif fprintf (stream, ['set label "%s" at %s %.15e,%.15e%s %s rotate by %f offset character %f,%f %s %s front %s;' "\n"], - undo_string_escapes (label), units, lpos(1), - lpos(2), zstr, halign, angle, dx_and_dy, fontspec, - __do_enhanced_option__ (enhanced, obj), colorspec); + label, units, lpos(1), lpos(2), zstr, halign, angle, dx_and_dy, + fontspec, __do_enhanced_option__ (enhanced, obj), colorspec); endfunction function cdata = mapcdata (cdata, mode, clim, cmap_sz) + if (ndims (cdata) == 3) ## True Color, clamp data to 8-bit clim = double (clim); @@ -2877,4 +2888,5 @@ endif cdata = max (1, min (cdata, cmap_sz)); endif + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/private/__opengl_print__.m --- a/scripts/plot/util/private/__opengl_print__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/private/__opengl_print__.m Thu Nov 19 13:08:00 2020 -0800 @@ -100,7 +100,7 @@ cmd_pstoedit = opts.pstoedit_cmd (opts, "fig", false); [~, ~, ext] = fileparts (opts.name); if (any (strcmpi (ext, {".ps", ".tex", "."}))) - opts.name = opts.name(1:end-numel(ext)); + opts.name = opts.name(1:end-numel (ext)); endif opts.name = [opts.name ".ps"]; cmd = sprintf ('%s | %s > "%s"', cmd_pstoedit, cmd_fig2dev, opts.name); @@ -109,7 +109,7 @@ cmd_fig2dev = opts.fig2dev_cmd (opts, "pstex_t"); gl2ps_device{2} = "eps"; pipeline{2} = sprintf ('%s | %s > "%s"', cmd_pstoedit, - cmd_fig2dev, strrep(opts.name, ".ps", ".tex")); + cmd_fig2dev, strrep (opts.name, ".ps", ".tex")); else ## Using svgconvert tmp = tempname (); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/private/__print_parse_opts__.m --- a/scripts/plot/util/private/__print_parse_opts__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/private/__print_parse_opts__.m Thu Nov 19 13:08:00 2020 -0800 @@ -250,7 +250,11 @@ if (opengl_ok && strcmp (graphics_toolkit (arg_st.figure), "qt")) ## "opengl" renderer only does text rotations of 0°, 90°, 180°, 270°, ... ht = findall (arg_st.figure, "type", "text"); - angles = [get(ht, "rotation"){:}]; + if (isempty (ht)) + angles = []; + else + angles = [get(ht, "rotation"){:}]; + endif if (any (mod (angles, 90))) arg_st.renderer = "painters"; else @@ -424,7 +428,7 @@ if (! (arg_st.send_to_printer || arg_st.formatted_for_printing || strncmp (arg_st.devopt, "pdf", 3) || strncmp (arg_st.devopt, "ps", 2))) - error ("print: the '%s' option is only valid for page formats and printers.", arg_st.resize_flag); + error ("print: the '%s' option is only valid for page formats and printers", arg_st.resize_flag); endif endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/refresh.m --- a/scripts/plot/util/refresh.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/refresh.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,9 +35,7 @@ function refresh (h) - if (nargin > 1) - print_usage (); - elseif (nargin == 1) + if (nargin == 1) if (! isfigure (h)) error ("refresh: H must be a valid figure handle"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/refreshdata.m --- a/scripts/plot/util/refreshdata.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/refreshdata.m Thu Nov 19 13:08:00 2020 -0800 @@ -74,14 +74,12 @@ endif if (nargin == 1) workspace = "base"; - elseif (nargin == 2) + else if (! ischar (workspace) || ! any (strcmpi (workspace, {"base", "caller"}))) error ('refreshdata: WORKSPACE must be "base" or "caller"'); endif workspace = tolower (workspace); - else - print_usage (); endif endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/rotate.m --- a/scripts/plot/util/rotate.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/rotate.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,7 +45,7 @@ ## default origin due to possible differences in the auto-scaling ## algorithm between Octave and Matlab. - if (nargin < 3 || nargin > 4) + if (nargin < 3) print_usage (); endif @@ -65,7 +65,7 @@ endif if (! (isnumeric (direction) && numel (direction) == 3)) - error ("rotate: invalid direction"); + error ("rotate: invalid DIRECTION"); endif if (! (isnumeric (alpha) && isscalar (alpha))) @@ -181,11 +181,12 @@ %! h2 = figure ("visible", "off"); %! o2 = line (); %! o3 = text (0, 0, "foobar"); -%!error rotate () -%!error rotate (o1) -%!error rotate (o1, [0,0,0]) + +%!error <Invalid call> rotate () +%!error <Invalid call> rotate (o1) +%!error <Invalid call> rotate (o1, [0,0,0]) %!error <all handles must be children of the same axes object> rotate ([o1, o2], [0,0,0], 90) -%!error <invalid direction> rotate (o1, "foo", 90) +%!error <invalid DIRECTION> rotate (o1, "foo", 90) %!error <invalid rotation angle> rotate (o1, [0,0,0], "foo") %!error <invalid ORIGIN> rotate (o1, [0,0,0], 90, "foo") %!error rotate (o1, [0,0,0], 90, [0,0,0], 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/rotate3d.m --- a/scripts/plot/util/rotate3d.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/rotate3d.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,35 +41,31 @@ ## @seealso{pan, zoom} ## @end deftypefn -function rotate3d (varargin) - - hfig = NaN; - - nargs = nargin; +function h = rotate3d (hfig, option) - if (nargs > 2) - print_usage (); - endif - - if (nargin == 1 && nargout > 0 && isfigure (varargin{1})) + ## FIXME: Presumably should implement this for Matlab compatibility. + if (nargin == 1 && nargout > 0 && isfigure (hfig)) error ("rotate3d: syntax 'handle = rotate3d (hfig)' not implemented"); endif - if (nargs == 2) - hfig = varargin{1}; - if (isfigure (hfig)) - varargin(1) = []; - nargs -= 1; + if (nargin == 0) + hfig = gcf (); + else + if (nargin == 1) + option = hfig; + hfig = gcf (); else - error ("rotate3d: invalid figure handle HFIG"); + if (! isfigure (hfig)) + error ("rotate3d: invalid figure handle HFIG"); + endif + endif + + if (! ischar (option)) + error ("rotate3d: OPTION must be a string"); endif endif - if (isnan (hfig)) - hfig = gcf (); - endif - - if (nargs == 0) + if (nargin == 0) rm = get (hfig, "__rotate_mode__"); if (strcmp (rm.Enable, "on")) rm.Enable = "off"; @@ -78,25 +74,17 @@ endif set (hfig, "__rotate_mode__", rm); update_mouse_mode (hfig, rm.Enable); - elseif (nargs == 1) - arg = varargin{1}; - if (ischar (arg)) - switch (arg) - case {"on", "off"} - rm = get (hfig, "__rotate_mode__"); - switch (arg) - case {"on", "off"} - rm.Enable = arg; - rm.Motion = "both"; - endswitch - set (hfig, "__rotate_mode__", rm); - update_mouse_mode (hfig, arg); - otherwise - error ("rotate3d: unrecognized OPTION '%s'", arg); - endswitch - else - error ("rotate3d: wrong type argument '%s'", class (arg)); - endif + else + switch (option) + case {"on", "off"} + rm = get (hfig, "__rotate_mode__"); + rm.Enable = option; + rm.Motion = "both"; + set (hfig, "__rotate_mode__", rm); + update_mouse_mode (hfig, option); + otherwise + error ("rotate3d: unrecognized OPTION '%s'", option); + endswitch endif endfunction @@ -106,11 +94,10 @@ if (strcmp (arg, "off")) set (hfig, "__mouse_mode__", "none"); else - ## FIXME: Is there a better way other than calling these - ## functions to set the other mouse mode Enable fields to - ## "off"? - pan ("off"); - zoom ("off"); + ## FIXME: Is there a better way other than calling these functions + ## to set the other mouse mode Enable fields to "off"? + pan (hfig, "off"); + zoom (hfig, "off"); set (hfig, "__mouse_mode__", "rotate"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/saveas.m --- a/scripts/plot/util/saveas.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/saveas.m Thu Nov 19 13:08:00 2020 -0800 @@ -33,6 +33,14 @@ ## are: ## ## @table @code +## +## @item ofig +## Octave figure file format (default) +## +## @item mfig +## Two files: Octave m-file @file{filename.m} containing code +## to open Octave figure file @file{filename.ofig} +## ## @item ps ## PostScript ## @@ -58,7 +66,7 @@ ## ## If @var{fmt} is omitted it is extracted from the extension of ## @var{filename}. The default format when there is no extension is -## @qcode{"pdf"}. +## @qcode{"ofig"}. ## ## @example ## @group @@ -68,12 +76,12 @@ ## @end group ## @end example ## -## @seealso{print, hgsave, orient} +## @seealso{print, savefig, hgsave, orient} ## @end deftypefn function saveas (h, filename, fmt) - if (nargin != 2 && nargin != 3) + if (nargin < 2) print_usage (); endif @@ -90,36 +98,60 @@ fig = ancestor (h, "figure"); endif + default_fmt = "ofig"; + if (nargin == 2) ## Attempt to infer format from filename [~, ~, ext] = fileparts (filename); - if (! isempty (ext)) - fmt = ext(2:end); - else - fmt = "pdf"; + if (isempty (ext)) + ext = ["." default_fmt]; + filename = [filename ext]; endif + fmt = ext(2:end); endif if (nargin == 3) if (! ischar (fmt)) error ("saveas: FMT must be a string"); + elseif (isempty (fmt)) + fmt = default_fmt; endif [~, ~, ext] = fileparts (filename); if (isempty (ext)) - filename = [filename "." fmt]; + ext = ["." fmt]; + filename = [filename ext]; endif endif - prt_opt = ["-d" tolower(fmt)]; + fmt = tolower (fmt); + + if (any (strcmp (fmt, {"ofig", "fig"}))) + savefig (fig, filename); + elseif (any (strcmp (fmt, {"m", "mfig"}))) + [d, n] = fileparts (filename); + mfilename = fullfile (d, [n ".m"]); + figfilename = fullfile (d, [n ".ofig"]); + + savefig (fig, figfilename); - print (fig, filename, prt_opt); + fid = fopen (mfilename, "wt"); + if (fid < 0) + error ("saveas: could not open '%s' for writing", mfilename); + endif + fprintf (fid, ['h = openfig ("' figfilename '");' "\n"]); + fclose (fid); + else + prt_opt = ["-d" fmt]; + + print (fig, filename, prt_opt); + endif endfunction + ## Test input validation -%!error saveas () -%!error saveas (1) -%!error saveas (1,2,3,4) +%!error <Invalid call> saveas () +%!error <Invalid call> saveas (1) %!error <H must be a graphics handle> saveas (Inf, "tst.pdf") %!error <FILENAME must be a string> saveas (0, 1) %!error <FMT must be a string> saveas (0, "tst.pdf", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/struct2hdl.m --- a/scripts/plot/util/struct2hdl.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/struct2hdl.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,12 +45,16 @@ function [h, pout] = struct2hdl (s, p=[], hilev = false) + if (nargin < 1) + print_usage (); + endif + fields = {"handle", "type", "children", "properties", "special"}; partypes = {"root", "figure", "axes", "hggroup"}; - othertypes = {"line", "patch", "surface", "image", "text"}; + othertypes = {"line", "patch", "scatter", "surface", "image", "text"}; alltypes = [partypes othertypes]; - if (nargin > 3 || ! isstruct (s)) + if (! isstruct (s)) print_usage (); elseif (! all (isfield (s, fields))) print_usage (); @@ -108,16 +112,22 @@ ## change the mode to "manual" when the value is "auto". names = fieldnames (s.properties); n = strncmp (cellfun (@fliplr, names, "uniformoutput", false), "edom", 4); - n = (n | strcmp (names, "activepositionproperty")); + n = (n | strcmp (names, "positionconstraint")); names = [names(! n); names(n)]; n_pos = find (strcmp (names, "position") | strcmp (names, "outerposition")); if (strcmp (s.type, "axes") && numel (n_pos) == 2) - if (strcmp (s.properties.activepositionproperty, "position")) + if (isfield (s.properties, "positionconstraint")) + positionconstraint = s.properties.positionconstraint; + else + ## loading old figure file before "positionconstraint" property was added + positionconstraint = s.properties.activepositionproperty; + endif + if (strcmp (positionconstraint, "outerposition")) + names{n_pos(1)} = "position"; + names{n_pos(2)} = "outerposition"; + else names{n_pos(1)} = "outerposition"; names{n_pos(2)} = "position"; - else - names{n_pos(1)} = "position"; - names{n_pos(2)} = "outerposition"; endif endif ## Reorder the properties with the mode properties coming last @@ -128,7 +138,7 @@ ## Translate field names for Matlab .fig files ## FIXME: Is it ok to do this unconditionally? - if isfield (s.properties, "applicationdata") + if (isfield (s.properties, "applicationdata")) s.properties.__appdata__ = s.properties.applicationdata; s.properties = rmfield (s.properties, "applicationdata"); endif @@ -150,21 +160,29 @@ if (strcmp (s.properties.tag, "legend")) s.properties.tag = ""; s.properties.userdata = []; - par = gcf; + par = gcf (); elseif (strcmp (s.properties.tag, "colorbar")) s.properties.tag = ""; s.properties.userdata = []; - par = gcf; + par = gcf (); endif endif - if (isfield (s.properties, "tightinset")) - s.properties = rmfield (s.properties, {"tightinset"}); + ## remove read only properties + ## FIXME: Remove "interactions", "layout", "legend", "toolbar", "xaxis", + ## "yaxis", and "zaxis" from this list once they are implemented. + ro_props = {"interactions", "layout", "legend", "nextseriesindex", ... + "tightinset", "toolbar", "xaxis", "yaxis", "zaxis"}; + has_ro_props = cellfun (@(x) isfield (s.properties, x), ro_props); + if (any (has_ro_props)) + s.properties = rmfield (s.properties, ro_props(has_ro_props)); endif [h, s] = createaxes (s, p, par); elseif (strcmp (s.type, "line")) h = createline (s, par); elseif (strcmp (s.type, "patch")) [h, s] = createpatch (s, par); + elseif (strcmp (s.type, "scatter")) + [h, s] = createscatter (s, par); elseif (strcmp (s.type, "text")) if (isfield (s.properties, "extent")) s.properties = rmfield (s.properties, "extent"); @@ -180,7 +198,8 @@ [h, s, p] = createhg (s, p, par, hilev); elseif (any (strcmp (s.type, {"uimenu", "uicontextmenu",... "uicontrol", "uipanel", "uibuttongroup",... - "uitoolbar", "uipushtool", "uitable"}))) + "uitoolbar", "uipushtool", "uitoggletool"... + "uitable"}))) if (isfield (s.properties, "extent")) s.properties = rmfield (s.properties, "extent"); endif @@ -213,6 +232,7 @@ endfunction function [h, sout] = createfigure (s) + ## Create figure initially invisible to speed up loading. opts = {"visible", "off"}; if (isfield (s.properties, "integerhandle")) # see also bug #53342. @@ -229,6 +249,7 @@ endif addmissingprops (h, s.properties); sout = s; + endfunction function [h, sout] = createaxes (s, p, par) @@ -368,6 +389,24 @@ endfunction +function [h, sout] = createscatter (s, par) + + if (isempty (s.properties.zdata)) + ## 2D scatter + h = scatter (s.properties.xdata, s.properties.ydata); + else + ## 3D scatter + h = scatter3 (s.properties.xdata, s.properties.ydata, s.properties.zdata); + endif + + set (h, "parent", par); + s.properties = rmfield (s.properties, + {"xdata", "ydata", "zdata"}); + addmissingprops (h, s.properties); + sout = s; + +endfunction + function h = createtext (s, par) h = text ("parent", par); addmissingprops (h, s.properties); diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/subplot.m --- a/scripts/plot/util/subplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/subplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -238,7 +238,7 @@ set (cf, "units", "pixels"); ## FIXME: At the moment we force gnuplot to use the aligned mode - ## which will set "activepositionproperty" to "position". + ## which will set "positionconstraint" to "innerposition". ## This can yield to text overlap between labels and titles. ## See bug #31610. if (strcmp (get (cf, "__graphics_toolkit__"), "gnuplot")) @@ -328,7 +328,7 @@ set (hsubplot, varargin{:}); endif else - pval = [{"activepositionproperty", "position", ... + pval = [{"positionconstraint", "innerposition", ... "position", pos, "looseinset", li} varargin]; if (! make_subplot) hsubplot = axes (pval{:}); @@ -434,7 +434,7 @@ endfunction -function subplot_align (h, d, rmupdate = false) +function subplot_align (h, ~, rmupdate = false) persistent updating = false; if (! updating) @@ -445,7 +445,7 @@ rmappdata (h, "__subplotposition__"); rmappdata (h, "__subplotouterposition__"); endif - return + return; endif unwind_protect @@ -460,7 +460,7 @@ do_align = ! cellfun (@isempty, pos); pos = cell2mat (pos(do_align)); else - return + return; endif hsubplots = children(do_align); @@ -475,7 +475,7 @@ hsubplots(! do_align) = []; pos(! do_align,:) = []; else - return + return; endif ## Reset outerpositions to their default value @@ -485,7 +485,7 @@ endif for ii = 1:numel (hsubplots) set (hsubplots(ii), "outerposition", opos(ii,:), ... - "activepositionproperty", "position"); + "positionconstraint", "innerposition"); endfor ## Compare current positions to default and compute the new ones diff -r dc3ee9616267 -r fa2cdef14442 scripts/plot/util/zoom.m --- a/scripts/plot/util/zoom.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/plot/util/zoom.m Thu Nov 19 13:08:00 2020 -0800 @@ -64,33 +64,27 @@ ## Eventually we need to also support these features: ## @deftypefnx {} {zoom_object_handle =} zoom (@var{hfig}) -function zoom (varargin) +function h = zoom (hfig, option) - nargs = nargin; - if (nargs > 2) - print_usage (); - endif - - if (nargs == 1 && nargout > 0 && isfigure (varargin{1})) + ## FIXME: Presumably should implement this for Matlab compatibility. + if (nargin == 1 && nargout > 0 && isfigure (hfig)) error ("zoom: syntax 'handle = zoom (hfig)' not implemented"); endif - hfig = NaN; - if (nargs == 2) - hfig = varargin{1}; - if (isfigure (hfig)) - varargin(1) = []; - nargs -= 1; + if (nargin == 0) + hfig = gcf (); + else + if (nargin == 1) + option = hfig; + hfig = gcf (); else - error ("zoom: invalid figure handle HFIG"); + if (! isfigure (hfig)) + error ("zoom: invalid figure handle HFIG"); + endif endif endif - if (isnan (hfig)) - hfig = gcf (); - endif - - if (nargs == 0) + if (nargin == 0) zm = get (hfig, "__zoom_mode__"); if (strcmp (zm.Enable, "on")) zm.Enable = "off"; @@ -99,10 +93,9 @@ endif set (hfig, "__zoom_mode__", zm); update_mouse_mode (hfig, zm.Enable); - elseif (nargs == 1) - arg = varargin{1}; - if (isnumeric (arg)) - factor = arg; + else + if (isnumeric (option)) + factor = option; switch (numel (factor)) case 2 xfactor = factor(1); @@ -110,10 +103,10 @@ case 1 xfactor = yfactor = factor; otherwise - error ("zoom: invalid FACTOR"); + error ("zoom: FACTOR must be a 1- or 2-element vector"); endswitch - if (xfactor < 0 || yfactor < 0) - error ("zoom: FACTOR must be greater than 1"); + if (xfactor <= 0 || yfactor <= 0) + error ("zoom: FACTOR must be greater than 0"); elseif (xfactor == 1 && yfactor == 1) return; endif @@ -132,13 +125,13 @@ endif __zoom__ (cax, mode, factor); endif - elseif (ischar (arg)) - switch (arg) + elseif (ischar (option)) + switch (option) case {"on", "off", "xon", "yon"} zm = get (hfig, "__zoom_mode__"); - switch (arg) + switch (option) case {"on", "off"} - zm.Enable = arg; + zm.Enable = option; zm.Motion = "both"; case "xon" zm.Enable = "on"; @@ -148,7 +141,7 @@ zm.Motion = "vertical"; endswitch set (hfig, "__zoom_mode__", zm); - update_mouse_mode (hfig, arg); + update_mouse_mode (hfig, option); case "out" cax = get (hfig, "currentaxes"); if (! isempty (cax)) @@ -160,10 +153,10 @@ __zoom__ (cax, "reset"); endif otherwise - error ("zoom: unrecognized OPTION '%s'", arg); + error ("zoom: unrecognized OPTION '%s'", option); endswitch else - error ("zoom: wrong type argument '%s'", class (arg)); + error ("zoom: OPTION must be a number or a string"); endif endif @@ -176,8 +169,8 @@ else ## FIXME: Is there a better way other than calling these functions ## to set the other mouse mode Enable fields to "off"? - pan ("off"); - rotate3d ("off"); + pan (hfig, "off"); + rotate3d (hfig, "off"); set (hfig, "__mouse_mode__", "zoom"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/polynomial/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/compan.m --- a/scripts/polynomial/compan.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/compan.m Thu Nov 19 13:08:00 2020 -0800 @@ -63,7 +63,7 @@ function A = compan (c) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/conv.m --- a/scripts/polynomial/conv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/conv.m Thu Nov 19 13:08:00 2020 -0800 @@ -54,7 +54,7 @@ function y = conv (a, b, shape = "full") - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -128,8 +128,7 @@ ## Test input validation -%!error conv (1) -%!error conv (1,2,3,4) +%!error <Invalid call> conv (1) %!error <A and B must be vectors> conv ([1, 2; 3, 4], 3) %!error <A and B must be vectors> conv (3, [1, 2; 3, 4]) %!error <SHAPE argument must be> conv (2, 3, "INVALID_SHAPE") diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/deconv.m --- a/scripts/polynomial/deconv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/deconv.m Thu Nov 19 13:08:00 2020 -0800 @@ -80,6 +80,7 @@ endfunction + %!test %! [b, r] = deconv ([3, 6, 9, 9], [1, 2, 3]); %! assert (b, [3, 0]); @@ -117,22 +118,22 @@ %! y = (10:-1:1); %! a = (4:-1:1); %! [b, r] = deconv (y, a); -%! assert (conv (a, b) + r, y, eps) +%! assert (conv (a, b) + r, y, eps); %!test <*51221> %! a = [1.92306958582241e+15, 3.20449986572221e+24, 1.34271290136344e+32, ... %! 2.32739765751038e+38]; %! b = [7.33727670161595e+27, 1.05919311870816e+36, 4.56169848520627e+42]; %! [div, rem] = deconv (a, b); -%! assert (rem, [0, 0, -2.89443678763879e+32 -1.58695290534499e+39], -10*eps) +%! assert (rem, [0, 0, -2.89443678763879e+32 -1.58695290534499e+39], -10*eps); %! a(2) = 3.204499865722215e+24; %! [div, rem] = deconv (a, b); -%! assert (rem, [0, 0, -2.89443678763879e+32 -1.58695290534499e+39], -10*eps) +%! assert (rem, [0, 0, -2.89443678763879e+32 -1.58695290534499e+39], -10*eps); %!test %! [b, r] = deconv ([1, 1], 1); -%! assert (r, [0, 0]) +%! assert (r, [0, 0]); %!test %! [b, r] = deconv ([1; 1], 1); -%! assert (r, [0; 0]) +%! assert (r, [0; 0]); diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/mkpp.m --- a/scripts/polynomial/mkpp.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/mkpp.m Thu Nov 19 13:08:00 2020 -0800 @@ -56,30 +56,26 @@ ## @seealso{unmkpp, ppval, spline, pchip, ppder, ppint, ppjumps} ## @end deftypefn -function pp = mkpp (x, P, d) +function pp = mkpp (breaks, coefs, d) - ## check number of arguments - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif - ## check x - if (length (x) < 2) - error ("mkpp: at least one interval is needed"); - endif - - if (! isvector (x)) - error ("mkpp: x must be a vector"); + ## Check BREAKS + if (! isvector (breaks)) + error ("mkpp: BREAKS must be a vector"); + elseif (length (breaks) < 2) + error ("mkpp: BREAKS must have at least one interval"); endif - len = length (x) - 1; - dP = length (size (P)); + len = length (breaks) - 1; pp = struct ("form", "pp", - "breaks", x(:).', + "breaks", breaks(:).', "coefs", [], "pieces", len, - "order", prod (size (P)) / len, + "order", prod (size (coefs)) / len, "dim", 1); if (nargin == 3) @@ -88,7 +84,7 @@ endif dim_vec = [pp.pieces * prod(pp.dim), pp.order]; - pp.coefs = reshape (P, dim_vec); + pp.coefs = reshape (coefs, dim_vec); endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/module.mk --- a/scripts/polynomial/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -6,6 +6,7 @@ %reldir%/private/__splinefit__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/compan.m \ %reldir%/conv.m \ %reldir%/deconv.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/mpoles.m --- a/scripts/polynomial/mpoles.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/mpoles.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ function [multp, indx] = mpoles (p, tol, reorder) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/padecoef.m --- a/scripts/polynomial/padecoef.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/padecoef.m Thu Nov 19 13:08:00 2020 -0800 @@ -91,7 +91,7 @@ function [num, den] = padecoef (T, N = 1) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -163,7 +163,7 @@ %! x = A \ b'; %! k = N : -1 : 0; %! d_exp = [flipud(x(N + 2 : 2 * N + 1)); 1]'; -%! n_exp = flipud(x(1 : N + 1))'; +%! n_exp = flipud (x(1 : N + 1))'; %! n_exp ./= d_exp(1); %! d_exp ./= d_exp(1); %! [n_obs, d_obs] = padecoef (T, N); @@ -173,8 +173,7 @@ ## PadeApproximant[Exp[-x * T], {x, 0, {n, n}}] ## Test input validation -%!error padecoef () -%!error padecoef (1,2,3) +%!error <Invalid call> padecoef () %!error <T must be a non-negative scalar> padecoef ([1,2]) %!error <T must be a non-negative scalar> padecoef ({1}) %!error <T must be a non-negative scalar> padecoef (-1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/pchip.m --- a/scripts/polynomial/pchip.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/pchip.m Thu Nov 19 13:08:00 2020 -0800 @@ -75,7 +75,7 @@ function ret = pchip (x, y, xi) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -177,5 +177,5 @@ %!assert (size (yi2), [3,2,5,4]) %!assert (squeeze (yi2(1,2,3,:)), [1/sqrt(2); 0; -1/sqrt(2);-1], 1e-14) -%!error (pchip (1,2)) -%!error (pchip (1,2,3)) +%!error pchip (1,2) +%!error pchip (1,2,3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/poly.m --- a/scripts/polynomial/poly.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/poly.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ function y = poly (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -112,6 +112,5 @@ %! y = poly (x); %! assert (y, [1 + 0i, -9 - 3i, 25 + 24i, -17 - 57i, -12 + 36i]); -%!error poly () -%!error poly (1,2) +%!error <Invalid call> poly () %!error poly ([1, 2, 3; 4, 5, 6]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polyder.m --- a/scripts/polynomial/polyder.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polyder.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,57 +41,57 @@ function [q, d] = polyder (p, a) - if (nargin == 1 || nargin == 2) - if (! isvector (p)) + if (nargin < 1) + print_usage (); + endif + + if (! isvector (p)) + error ("polyder: argument must be a vector"); + endif + if (nargin == 2) + if (! isvector (a)) error ("polyder: argument must be a vector"); endif - if (nargin == 2) - if (! isvector (a)) - error ("polyder: argument must be a vector"); - endif - if (nargout == 1) - ## derivative of p*a returns a single polynomial - q = polyder (conv (p, a)); + if (nargout == 1) + ## derivative of p*a returns a single polynomial + q = polyder (conv (p, a)); + else + ## derivative of p/a returns numerator and denominator + d = conv (a, a); + if (numel (p) == 1) + q = -p * polyder (a); + elseif (numel (a) == 1) + q = a * polyder (p); else - ## derivative of p/a returns numerator and denominator - d = conv (a, a); - if (numel (p) == 1) - q = -p * polyder (a); - elseif (numel (a) == 1) - q = a * polyder (p); - else - q = conv (polyder (p), a) - conv (p, polyder (a)); - q = polyreduce (q); - endif - - ## remove common factors from numerator and denominator - x = polygcd (q, d); - if (length (x) != 1) - q = deconv (q, x); - d = deconv (d, x); - endif - - ## move all the gain into the numerator - q /= d(1); - d /= d(1); - endif - else - lp = numel (p); - if (lp == 1) - q = 0; - return; - elseif (lp == 0) - q = []; - return; + q = conv (polyder (p), a) - conv (p, polyder (a)); + q = polyreduce (q); endif - ## Force P to be a row vector. - p = p(:).'; + ## remove common factors from numerator and denominator + x = polygcd (q, d); + if (length (x) != 1) + q = deconv (q, x); + d = deconv (d, x); + endif - q = p(1:(lp-1)) .* [(lp-1):-1:1]; + ## move all the gain into the numerator + q /= d(1); + d /= d(1); endif else - print_usage (); + lp = numel (p); + if (lp == 1) + q = 0; + return; + elseif (lp == 0) + q = []; + return; + endif + + ## Force P to be a row vector. + p = p(:).'; + + q = p(1:(lp-1)) .* [(lp-1):-1:1]; endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polyeig.m --- a/scripts/polynomial/polyeig.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polyeig.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ function [z, v] = polyeig (varargin) - if (nargin < 1 || nargout > 2) + if (nargin < 1) print_usage (); endif @@ -105,8 +105,7 @@ %! assert (norm (d), 0.0); ## Test input validation -%!error polyeig () -%!error [a,b,c] = polyeig (1) +%!error <Invalid call> polyeig () %!error <coefficients must be square matrices> polyeig (ones (3,2)) %!error <coefficients must have the same dimensions> %! polyeig (ones (3,3), ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polyfit.m --- a/scripts/polynomial/polyfit.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polyfit.m Thu Nov 19 13:08:00 2020 -0800 @@ -27,25 +27,33 @@ ## @deftypefn {} {@var{p} =} polyfit (@var{x}, @var{y}, @var{n}) ## @deftypefnx {} {[@var{p}, @var{s}] =} polyfit (@var{x}, @var{y}, @var{n}) ## @deftypefnx {} {[@var{p}, @var{s}, @var{mu}] =} polyfit (@var{x}, @var{y}, @var{n}) -## Return the coefficients of a polynomial @var{p}(@var{x}) of degree -## @var{n} that minimizes the least-squares-error of the fit to the points -## @code{[@var{x}, @var{y}]}. +## Return the coefficients of a polynomial @var{p}(@var{x}) of degree @var{n} +## that minimizes the least-squares-error of the fit to the points +## @code{[@var{x}(:), @var{y}(:)]}. ## -## If @var{n} is a logical vector, it is used as a mask to selectively force -## the corresponding polynomial coefficients to be used or ignored. +## @var{n} is typically an integer @geq{} 0 specifying the degree of the +## approximating polynomial. If @var{n} is a logical vector, it is used as a +## mask to selectively force the corresponding polynomial coefficients to be +## used or ignored. ## -## The polynomial coefficients are returned in a row vector. +## The polynomial coefficients are returned in the row vector @var{p}. The +## output @var{p} may be directly used with @code{polyval} to estimate values +## using the fitted polynomial. ## ## The optional output @var{s} is a structure containing the following fields: ## ## @table @samp -## @item R -## Triangular factor R from the QR@tie{}decomposition. +## +## @item yf +## The values of the polynomial for each value of @var{x}. ## ## @item X ## The @nospell{Vandermonde} matrix used to compute the polynomial ## coefficients. ## +## @item R +## Triangular factor R from the QR@tie{}decomposition. +## ## @item C ## The unscaled covariance matrix, formally equal to the inverse of ## @var{x'}*@var{x}, but computed in a way minimizing roundoff error @@ -56,121 +64,158 @@ ## ## @item normr ## The norm of the residuals. -## -## @item yf -## The values of the polynomial for each value of @var{x}. ## @end table ## -## The second output may be used by @code{polyval} to calculate the -## statistical error limits of the predicted values. In particular, the -## standard deviation of @var{p} coefficients is given by +## The second output may be used by @code{polyval} to calculate the statistical +## error limits of the predicted values. In particular, the standard deviation +## of @var{p} coefficients is given by ## -## @code{sqrt (diag (s.C)/s.df)*s.normr}. +## @code{sqrt (diag (@var{s.C})/@var{s.df}) * @var{s.normr}}. ## -## When the third output, @var{mu}, is present the coefficients, @var{p}, are -## associated with a polynomial in +## When the third output, @var{mu}, is present the original data is centered +## and scaled which can improve the numerical stability of the fit. The +## coefficients @var{p} are associated with a polynomial in ## ## @code{@var{xhat} = (@var{x} - @var{mu}(1)) / @var{mu}(2)} @* ## where @var{mu}(1) = mean (@var{x}), and @var{mu}(2) = std (@var{x}). ## -## This linear transformation of @var{x} improves the numerical stability of -## the fit. +## Example 1 : logical @var{n} and integer @var{n} +## +## @example +## @group +## f = @@(x) x.^2 + 5; # data-generating function +## x = 0:5; +## y = f (x); +## ## Fit data to polynomial A*x^3 + B*x^1 +## p = polyfit (x, y, logical ([1, 0, 1, 0])) +## @result{} p = [ 0.0680, 0, 4.2444, 0 ] +## ## Fit data to polynomial using all terms up to x^3 +## p = polyfit (x, y, 3) +## @result{} p = [ -4.9608e-17, 1.0000e+00, -3.3813e-15, 5.0000e+00 ] +## @end group +## @end example +## ## @seealso{polyval, polyaffine, roots, vander, zscore} ## @end deftypefn function [p, s, mu] = polyfit (x, y, n) - if (nargin < 3 || nargin > 4) + if (nargin < 3) print_usage (); endif + y_is_row_vector = isrow (y); + + ## Reshape x & y into column vectors. + x = x(:); + y = y(:); + + nx = numel (x); + ny = numel (y); + if (nx != ny) + error ("polyfit: X and Y must have the same number of points"); + endif + if (nargout > 2) - ## Normalized the x values. + ## Center and scale the x values. mu = [mean(x), std(x)]; x = (x - mu(1)) / mu(2); endif - if (! size_equal (x, y)) - error ("polyfit: X and Y must be vectors of the same size"); - endif - + ## n is the polynomial degree (an input, or deduced from the polymask size) + ## m is the effective number of coefficients. if (islogical (n)) - polymask = n; - ## n is the polynomial degree as given the polymask size; m is the - ## effective number of used coefficients. - n = length (polymask) - 1; m = sum (polymask) - 1; + polymask = n(:).'; # force to row vector + n = numel (polymask) - 1; + m = sum (polymask) - 1; + pad_output = true; else if (! (isscalar (n) && n >= 0 && ! isinf (n) && n == fix (n))) error ("polyfit: N must be a non-negative integer"); endif - polymask = logical (ones (1, n+1)); m = n; + polymask = true (1, n+1); + m = n; + pad_output = false; endif - y_is_row_vector = (rows (y) == 1); - - ## Reshape x & y into column vectors. - l = numel (x); - x = x(:); - y = y(:); + if (m >= nx) + warning ("polyfit: degree of polynomial N is >= number of data points; solution is not unique"); + m = nx; + pad_output = true; + ## Keep the lowest m entries in polymask + idx = find (polymask); + idx((end-m+1):end) = []; + polymask(idx) = false; + endif ## Construct the Vandermonde matrix. - v = vander (x, n+1); + X = vander (x, n+1); + v = X(:, polymask); ## Solve by QR decomposition. - [q, r, k] = qr (v(:, polymask), 0); + [q, r, k] = qr (v, 0); p = r \ (q' * y); p(k) = p; - if (n != m) - q = p; p = zeros (n+1, 1); - p(polymask) = q; - endif - - if (nargout > 1) + if (isargout (2)) yf = v*p; - if (y_is_row_vector) s.yf = yf.'; else s.yf = yf; endif - s.X = v; + + s.X = X; - ## r.'*r is positive definite if X(:, polymask) is of full rank. - ## Invert it by cholinv to avoid taking the square root of squared - ## quantities. If cholinv fails, then X(:, polymask) is rank deficient - ## and not invertible. + ## r.'*r is positive definite if matrix v is of full rank. Invert it by + ## cholinv to avoid taking the square root of squared quantities. + ## If cholinv fails, then v is rank deficient and not invertible. try C = cholinv (r.'*r)(k, k); catch - C = NaN (m+1, m+1); + C = NaN (m, m); end_try_catch - if (n != m) - ## fill matrices if required + if (pad_output) s.X(:, ! polymask) = 0; - s.R = zeros (n+1, n+1); s.R(polymask, polymask) = r; - s.C = zeros (n+1, n+1); s.C(polymask, polymask) = C; + s.R = zeros (rows (r), n+1); s.R(:, polymask) = r; + s.C = zeros (rows (C), n+1); s.C(:, polymask) = C; else s.R = r; s.C = C; endif - s.df = l - m - 1; + + s.df = max (0, nx - m - 1); s.normr = norm (yf - y); endif - ## Return a row vector. - p = p.'; + if (pad_output) + ## Zero pad output + q = p; + p = zeros (n+1, 1); + p(polymask) = q; + endif + p = p.'; # Return a row vector. endfunction %!shared x %! x = [-2, -1, 0, 1, 2]; -%!assert (polyfit (x, x.^2+x+1, 2), [1, 1, 1], sqrt (eps)) -%!assert (polyfit (x, x.^2+x+1, 3), [0, 1, 1, 1], sqrt (eps)) -%!fail ("polyfit (x, x.^2+x+1)") -%!fail ("polyfit (x, x.^2+x+1, [])") + +%!assert (polyfit (x, 3*x.^2 + 2*x + 1, 2), [3, 2, 1], 10*eps) +%!assert (polyfit (x, 3*x.^2 + 2*x + 1, logical ([1 1 1])), [3, 2, 1], 10*eps) +%!assert (polyfit (x, x.^2 + 2*x + 3, 3), [0, 1, 2, 3], 10*eps) +%!assert (polyfit (x, x.^2 + 2*x + 3, logical ([0 1 1 1])), [0 1 2 3], 10*eps) + +## Test logical input N +%!test +%! x = [0:5]; +%! y = 3*x.^3 + 2*x.^2 + 4; +%! [p, s] = polyfit (x, y, logical ([1, 0, 1, 1])); +%! assert (p(2), 0); +%! assert (all (p([1, 3, 4]))); +%! assert (s.df, 3); ## Test difficult case where scaling is really needed. This example ## demonstrates the rather poor result which occurs when the dependent @@ -188,25 +233,29 @@ %! assert (s2.normr < s1.normr); %!test -%! x = 1:4; -%! p0 = [1i, 0, 2i, 4]; -%! y0 = polyval (p0, x); -%! p = polyfit (x, y0, numel (p0) - 1); -%! assert (p, p0, 1000*eps); - -%!test %! warning ("off", "Octave:nearly-singular-matrix", "local"); %! x = 1000 + (-5:5); %! xn = (x - mean (x)) / std (x); %! pn = ones (1,5); %! y = polyval (pn, xn); -%! [p, s, mu] = polyfit (x, y, numel (pn) - 1); -%! [p2, s2] = polyfit (x, y, numel (pn) - 1); +%! n = numel (pn) - 1; +%! [p, s, mu] = polyfit (x, y, n); +%! [p2, s2] = polyfit (x, y, n); %! assert (p, pn, s.normr); %! assert (s.yf, y, s.normr); %! assert (mu, [mean(x), std(x)]); %! assert (s.normr/s2.normr < sqrt (eps)); +## Complex polynomials +%!test +%! x = 1:4; +%! p0 = [1i, 0, 2i, 4]; +%! y = polyval (p0, x); +%! n = numel (p0) - 1; +%! p = polyfit (x, y, n); +%! assert (p, p0, 1000*eps); + +## Matrix input %!test %! x = [1, 2, 3; 4, 5, 6]; %! y = [0, 0, 1; 1, 0, 0]; @@ -214,4 +263,88 @@ %! expected = [0, 1, -14, 65, -112, 60] / 12; %! assert (p, expected, sqrt (eps)); -%!error <vectors of the same size> polyfit ([1, 2; 3, 4], [1, 2, 3, 4], 2) +## Orientation of output +%!test +%! x = 0:5; +%! y = x.^4 + 2*x + 5; +%! [p, s] = polyfit (x, y, 3); +%! assert (isrow (s.yf)); +%! [p, s] = polyfit (x, y.', 3); +%! assert (iscolumn (s.yf)); + +## Insufficient data for fit +%!test +%! x = [1, 2]; +%! y = [3, 4]; +%! ## Disable warnings entirely because there is not a specific ID to disable. +%! wstate = warning (); +%! unwind_protect +%! warning ("off", "all"); +%! p0 = polyfit (x, y, 4); +%! [p1, s, mu] = polyfit (x, y, 4); +%! unwind_protect_cleanup +%! warning (wstate); +%! end_unwind_protect +%! assert (p0, [0, 0, 0, 1, 2], 10*eps); +%! assert (p1, [0, 0, 0, sqrt(2)/2, 3.5], 10*eps); +%! assert (size (s.X), [2, 5]); +%! assert (s.X(:,1:3), zeros (2,3)); +%! assert (size (s.R), [2, 5]); +%! assert (s.R(:,1:3), zeros (2,3)); +%! assert (size (s.C), [2, 5]); +%! assert (s.C(:,1:3), zeros (2,3)); +%! assert (s.df, 0); +%! assert (mu, [1.5, sqrt(2)/2]); + +%!test +%! x = [1, 2, 3]; +%! y = 2*x + 1; +%! ## Disable warnings entirely because there is not a specific ID to disable. +%! wstate = warning (); +%! unwind_protect +%! warning ("off", "all"); +%! p0 = polyfit (x, y, logical ([1, 1, 1, 0 1])); +%! [p1, s, mu] = polyfit (x, y, logical ([1, 1, 1, 0 1])); +%! unwind_protect_cleanup +%! warning (wstate); +%! end_unwind_protect +%! assert (p0, [0, -2/11, 12/11, 0, 23/11], 10*eps); +%! assert (p1, [0, 2, 0, 0, 5], 10*eps); +%! assert (size (s.X), [3, 5]); +%! assert (s.X(:,[1,4]), zeros (3,2)); +%! assert (size (s.R), [3, 5]); +%! assert (s.R(:,[1,4]), zeros (3,2)); +%! assert (size (s.C), [3, 5]); +%! assert (s.C(:,[1,4]), zeros (3,2)); +%! assert (s.df, 0); +%! assert (mu, [2, 1]); + +%!test <*57964> +%! ## Disable warnings entirely because there is not a specific ID to disable. +%! wstate = warning (); +%! unwind_protect +%! warning ("off", "all"); +%! [p, s] = polyfit ([1,2], [3,4], 2); +%! unwind_protect_cleanup +%! warning (wstate); +%! end_unwind_protect +%! assert (size (p), [1, 3]); +%! assert (size (s.X), [2, 3]); +%! assert (s.X(:,1), [0; 0]); +%! assert (size (s.R), [2, 3]); +%! assert (s.R(:,1), [0; 0]); +%! assert (size (s.C), [2, 3]); +%! assert (s.C(:,1), [0; 0]); + +## Test input validation +%!error <Invalid call> polyfit () +%!error <Invalid call> polyfit (1) +%!error <Invalid call> polyfit (1,2) +%!error <X and Y must have the same number of points> polyfit ([1, 2], 1, 1) +%!error <X and Y must have the same number of points> polyfit (1, [1, 2], 1) +%!error <N must be a non-negative integer> polyfit (1, 2, [1,2]) +%!error <N must be a non-negative integer> polyfit (1, 2, -1) +%!error <N must be a non-negative integer> polyfit (1, 2, Inf) +%!error <N must be a non-negative integer> polyfit (1, 2, 1.5) +%!test <*57964> +%! fail ("p = polyfit ([1,2], [3,4], 4)", "warning", "solution is not unique"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polygcd.m --- a/scripts/polynomial/polygcd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polygcd.m Thu Nov 19 13:08:00 2020 -0800 @@ -53,39 +53,42 @@ function x = polygcd (b, a, tol) - if (nargin == 2 || nargin == 3) - if (nargin == 2) - if (isa (a, "single") || isa (b, "single")) - tol = sqrt (eps ("single")); - else - tol = sqrt (eps); - endif + if (nargin < 2) + print_usage (); + endif + + if (nargin == 2) + if (isa (a, "single") || isa (b, "single")) + tol = sqrt (eps ("single")); + else + tol = sqrt (eps); endif - if (length (a) == 1 || length (b) == 1) - if (a == 0) - x = b; - elseif (b == 0) - x = a; - else - x = 1; - endif + endif + ## FIXME: No input validation of tol if it was user-supplied + + + if (length (a) == 1 || length (b) == 1) + if (a == 0) + x = b; + elseif (b == 0) + x = a; else - a /= a(1); - while (1) - [d, r] = deconv (b, a); - nz = find (abs (r) > tol); - if (isempty (nz)) - x = a; - break; - else - r = r(nz(1):length(r)); - endif - b = a; - a = r / r(1); - endwhile + x = 1; endif else - print_usage (); + a /= a(1); + while (1) + [d, r] = deconv (b, a); + nz = find (abs (r) > tol); + if (isempty (nz)) + x = a; + break; + else + r = r(nz(1):length (r)); + endif + b = a; + a = r / r(1); + endwhile endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polyint.m --- a/scripts/polynomial/polyint.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polyint.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function retval = polyint (p, k) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -79,5 +79,5 @@ %! B = [length(A):-1:1]; %! assert (polyint (A), [1./B, 0]); -%!error polyint () +%!error <Invalid call> polyint () %!error polyint (ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polyout.m --- a/scripts/polynomial/polyout.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polyout.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ function y = polyout (c, x) - if (nargin < 1) || (nargin > 2) || (nargout < 0) || (nargout > 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polyreduce.m --- a/scripts/polynomial/polyreduce.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polyreduce.m Thu Nov 19 13:08:00 2020 -0800 @@ -32,7 +32,7 @@ function p = polyreduce (c) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! isvector (c) || isempty (c)) error ("polyreduce: C must be a non-empty vector"); @@ -54,7 +54,6 @@ %!assert (polyreduce ([1, 0, 3]), [1, 0, 3]) %!assert (polyreduce ([0, 0, 0]), 0) -%!error polyreduce () -%!error polyreduce (1, 2) +%!error <Invalid call> polyreduce () %!error <C must be a non-empty vector> polyreduce ([1, 2; 3, 4]) %!error <C must be a non-empty vector> polyreduce ([]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/polyval.m --- a/scripts/polynomial/polyval.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/polyval.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,7 +48,7 @@ function [y, dy] = polyval (p, x, s = [], mu) - if (nargin < 2 || nargin > 4 || (nargout == 2 && nargin < 3)) + if (nargin < 2 || (nargout == 2 && nargin < 3)) print_usage (); endif @@ -175,10 +175,9 @@ %!assert (class (polyval ([], single ([]))), "single") ## Test input validation -%!error polyval () -%!error polyval (1) -%!error polyval (1,2,3,4,5) -%!error [y, dy] = polyval (1, 2) +%!error <Invalid call> polyval () +%!error <Invalid call> polyval (1) +%!error <Invalid call> [y, dy] = polyval (1, 2) %!error <P must be a numeric floating point vector> polyval ({1, 0}, 0:10) %!error <P must be a numeric floating point vector> polyval (int8 ([1]), 0:10) %!error <P must be a numeric floating point vector> polyval ([1,0;0,1], 0:10) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/ppder.m --- a/scripts/polynomial/ppder.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/ppder.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ function ppd = ppder (pp, m = 1) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/ppint.m --- a/scripts/polynomial/ppint.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/ppint.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function ppi = ppint (pp, c) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif if (! (isstruct (pp) && strcmp (pp.form, "pp"))) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/ppjumps.m --- a/scripts/polynomial/ppjumps.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/ppjumps.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function jumps = ppjumps (pp) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/ppval.m --- a/scripts/polynomial/ppval.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/ppval.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,7 +61,7 @@ P = reshape (P, [d, n * k]); P = shiftdim (P, nd); P = reshape (P, [n, k, d]); - Pidx = P(idx(:), :); # 2D matrix size: x = coefs*prod(d), y = prod(sxi) + Pidx = P(idx(:), :); # 2D matrix size: x = coefs*prod (d), y = prod (sxi) if (isvector (xi)) Pidx = reshape (Pidx, [xn, k, d]); @@ -139,9 +139,8 @@ %! assert (ppval (pp, [breaks',breaks']), ret); ## Test input validation -%!error ppval () -%!error ppval (1) -%!error ppval (1,2,3) +%!error <Invalid call> ppval () +%!error <Invalid call> ppval (1) %!error <argument must be a pp-form structure> ppval (1,2) %!error <argument must be a pp-form structure> ppval (struct ("a", 1), 2) %!error <argument must be a pp-form structure> ppval (struct ("form", "ab"), 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/private/__splinefit__.m --- a/scripts/polynomial/private/__splinefit__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/private/__splinefit__.m Thu Nov 19 13:08:00 2020 -0800 @@ -334,7 +334,7 @@ % Return if isempty(constr) - return + return; end % Unpack constraints diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/residue.m --- a/scripts/polynomial/residue.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/residue.m Thu Nov 19 13:08:00 2020 -0800 @@ -297,13 +297,13 @@ pn = 1; for j = 1:n - 1 pn = conv (pn, [1, -p(j)]); - end + endfor for j = n + 1:numel (p) pn = conv (pn, [1, -p(j)]); - end + endfor for j = 1:e(n) - 1 pn = deconv (pn, p1); - end + endfor pn = r(n) * pn; pnum += prepad (pn, N+1, 0, 2); endfor diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/roots.m --- a/scripts/polynomial/roots.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/roots.m Thu Nov 19 13:08:00 2020 -0800 @@ -84,7 +84,7 @@ function r = roots (c) - if (nargin != 1 || (! isvector (c) && ! isempty (c))) + if (nargin < 1 || (! isvector (c) && ! isempty (c))) print_usage (); elseif (any (! isfinite (c))) error ("roots: inputs must not contain Inf or NaN"); @@ -135,8 +135,7 @@ %!assert (roots ([1e-200, -1e200, 1]), 1e-200) %!assert (roots ([1e-200, -1e200 * 1i, 1]), -1e-200 * 1i) -%!error roots () -%!error roots (1,2) +%!error <Invalid call> roots () %!error roots ([1, 2; 3, 4]) %!error <inputs must not contain Inf or NaN> roots ([1 Inf 1]) %!error <inputs must not contain Inf or NaN> roots ([1 NaN 1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/spline.m --- a/scripts/polynomial/spline.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/spline.m Thu Nov 19 13:08:00 2020 -0800 @@ -228,7 +228,7 @@ %! x = 0:10; y = sin (x); %! xspline = 0:0.1:10; yspline = spline (x,y,xspline); %! title ("spline fit to points from sin (x)"); -%! plot (xspline,sin(xspline),"r", xspline,yspline,"g-", x,y,"b+"); +%! plot (xspline,sin (xspline),"r", xspline,yspline,"g-", x,y,"b+"); %! legend ("original", "interpolation", "interpolation points"); %! %-------------------------------------------------------- %! % confirm that interpolated function matches the original diff -r dc3ee9616267 -r fa2cdef14442 scripts/polynomial/unmkpp.m --- a/scripts/polynomial/unmkpp.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/polynomial/unmkpp.m Thu Nov 19 13:08:00 2020 -0800 @@ -29,7 +29,7 @@ ## Extract the components of a piecewise polynomial structure @var{pp}. ## ## This function is the inverse of @code{mkpp}: it extracts the inputs to -## @code{mkpp} needed to create the piecewise polynomial structure @var{PP}. +## @code{mkpp} needed to create the piecewise polynomial structure @var{pp}. ## The code below makes this relation explicit: ## ## @example @@ -74,7 +74,7 @@ function [x, P, n, k, d] = unmkpp (pp) - if (nargin != 1) + if (nargin < 1) print_usage (); endif if (! (isstruct (pp) && isfield (pp, "form") && strcmp (pp.form, "pp"))) @@ -101,8 +101,7 @@ %! assert (d, 1); ## Test input validation -%!error unmkpp () -%!error unmkpp (1,2) +%!error <Invalid call> unmkpp () %!error <piecewise polynomial structure> unmkpp (1) %!error <piecewise polynomial structure> unmkpp (struct ("field1", "pp")) %!error <piecewise polynomial structure> unmkpp (struct ("form", "not_a_pp")) diff -r dc3ee9616267 -r fa2cdef14442 scripts/prefs/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/prefs/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/prefs/addpref.m --- a/scripts/prefs/addpref.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/prefs/addpref.m Thu Nov 19 13:08:00 2020 -0800 @@ -109,9 +109,9 @@ %! endif %! end_unwind_protect -%!error addpref () -%!error addpref (1) -%!error addpref (1,2) -%!error addpref (1,2,3,4) +## Test input validation +%!error <Invalid call> addpref () +%!error <Invalid call> addpref (1) +%!error <Invalid call> addpref (1,2) %!error <GROUP must be a string> addpref (1, "pref1", 2) %!error <PREF must be a string> addpref ("group1", 1, 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/prefs/getpref.m --- a/scripts/prefs/getpref.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/prefs/getpref.m Thu Nov 19 13:08:00 2020 -0800 @@ -55,10 +55,6 @@ function retval = getpref (group, pref, default) - if (nargin > 3) - print_usage (); - endif - if (nargin == 0) retval = loadprefs (); elseif (nargin == 1) @@ -151,9 +147,7 @@ %! %! unwind_protect_cleanup %! unlink (fullfile (tmp_home, ".octave_prefs")); -%! if (isfolder (tmp_home)) -%! rmdir (tmp_home); -%! endif +%! sts = rmdir (tmp_home); %! if (isempty (HOME)) %! unsetenv ("HOME"); %! else @@ -161,6 +155,5 @@ %! endif %! end_unwind_protect -%!error getpref (1,2,3,4) %!error <GROUP must be a string> getpref (1) %!error <PREF must be a string> getpref ("group1", 1, 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/prefs/ispref.m --- a/scripts/prefs/ispref.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/prefs/ispref.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function retval = ispref (group, pref = "") - if (nargin == 0 || nargin > 2) + if (nargin == 0) print_usage (); endif @@ -98,7 +98,6 @@ %! endif %! end_unwind_protect -%!error ispref () -%!error ispref (1,2,3) +%!error <Invalid call> ispref () %!error <GROUP must be a string> ispref (1, "pref1") %!error <PREF must be a string> ispref ("group1", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/prefs/module.mk --- a/scripts/prefs/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/prefs/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -8,6 +8,7 @@ %reldir%/private/saveprefs.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/addpref.m \ %reldir%/getpref.m \ %reldir%/ispref.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/prefs/rmpref.m --- a/scripts/prefs/rmpref.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/prefs/rmpref.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function rmpref (group, pref) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (! ischar (group)) error ("rmpref: GROUP must be a string"); @@ -113,7 +113,6 @@ %! end_unwind_protect ## Test input validation -%!error rmpref () -%!error rmpref (1,2,3) +%!error <Invalid call> rmpref () %!error <GROUP must be a string> rmpref (1) %!error <PREF must be a string> rmpref ("group1", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/prefs/setpref.m --- a/scripts/prefs/setpref.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/prefs/setpref.m Thu Nov 19 13:08:00 2020 -0800 @@ -96,9 +96,7 @@ %! "size mismatch for PREF and VAL"); %! unwind_protect_cleanup %! unlink (fullfile (tmp_home, ".octave_prefs")); -%! if (isfolder (tmp_home)) -%! rmdir (tmp_home); -%! endif +%! sts = rmdir (tmp_home); %! if (isempty (HOME)) %! unsetenv ("HOME"); %! else @@ -106,9 +104,9 @@ %! endif %! end_unwind_protect -%!error setpref () -%!error setpref (1) -%!error setpref (1,2) -%!error setpref (1,2,3,4) +## Test input validation +%!error <Invalid call> setpref () +%!error <Invalid call> setpref (1) +%!error <Invalid call> setpref (1,2) %!error <GROUP must be a string> setpref (1, "pref1", 2) %!error <PREF must be a string> setpref ("group1", 1, 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/profiler/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/profiler/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/profiler/module.mk --- a/scripts/profiler/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/profiler/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/profexplore.m \ %reldir%/profexport.m \ %reldir%/profile.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/profiler/profexplore.m --- a/scripts/profiler/profexplore.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/profiler/profexplore.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ if (nargin == 0) data = profile ("info"); - elseif (nargin != 1) + elseif (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/profiler/profexport.m --- a/scripts/profiler/profexport.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/profiler/profexport.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ ## Built-in profiler. function profexport (dir, name = "", data) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -77,7 +77,7 @@ endif if (! copyfile (__dataFilename ("style.css"), dir)) - error ("profexport: failed to copy data file to directory '%s'", dir) + error ("profexport: failed to copy data file to directory '%s'", dir); endif if (isempty (name)) @@ -207,18 +207,18 @@ template = __readTemplate ("hierarchical.html"); entryTemplate = __readTemplate ("hierarchical_entry.html"); - % Fill in basic data and parent breadcrumbs. + ## Fill in basic data and parent breadcrumbs. res = template; res = strrep (res, "%title", name); parentsStr = __hierarchicalParents (parents); res = strrep (res, "%parents", parentsStr); - % Set this page's counter and update parents struct with it. + ## Set this page's counter and update parents struct with it. mine = cnt++; parents{end}.cnt = mine; file = sprintf ("%s/hierarchy-%d.html", dir, mine); - % Sort children by time. + ## Sort children by time. times = -[ children.TotalTime ]; [~, p] = sort (times); children = children(p); @@ -314,7 +314,7 @@ %! open (fullfile (dir, "index.html")); ## Test input validation -%!error profexport () +%!error <Invalid call> profexport () %!error profexport (1) %!error profexport (1, 2, 3, 4) %!error <DIR must be a string> profexport (5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/profiler/profile.m --- a/scripts/profiler/profile.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/profiler/profile.m Thu Nov 19 13:08:00 2020 -0800 @@ -68,7 +68,7 @@ ## Built-in profiler. function retval = profile (option) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -151,6 +151,6 @@ %! assert (fieldnames (hier), {"Index"; "SelfTime"; "TotalTime"; "NumCalls"; "Children"}); ## Test input validation -%!error profile () +%!error <Invalid call> profile () %!error profile ("on", 2) %!error profile ("INVALID_OPTION") diff -r dc3ee9616267 -r fa2cdef14442 scripts/profiler/profshow.m --- a/scripts/profiler/profshow.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/profiler/profshow.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,10 +46,6 @@ ## Built-in profiler. function profshow (data, n = 20) - if (nargin > 2) - print_usage (); - endif - if (nargin == 0) data = profile ("info"); elseif (nargin == 1 && ! isstruct (data)) @@ -113,7 +109,7 @@ %! profile off; %! profshow (profile ("info"), 5); -%!error profshow (1, 2, 3) +## Test input validation %!error <N must be a positive integer> profshow (struct (), ones (2)) %!error <N must be a positive integer> profshow (struct (), 1+i) %!error <N must be a positive integer> profshow (struct (), -1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/set/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/set/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/set/ismember.m --- a/scripts/set/ismember.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/set/ismember.m Thu Nov 19 13:08:00 2020 -0800 @@ -92,7 +92,7 @@ s_idx = zeros (size (real_argout{2})); s_idx(tf) = min (real_argout{2}(tf), imag_argout{2}(tf)); endif - return + return; endif ## lookup() does not handle logical values @@ -294,7 +294,7 @@ %! assert (s_idx, 2); %! %! tf = ismember ([5, 4-3j, 3+4j], 5); -%! assert (tf, logical ([1, 0, 0])) +%! assert (tf, logical ([1, 0, 0])); %! [~, s_idx] = ismember ([5, 4-3j, 3+4j], 5); %! assert (s_idx, [1, 0, 0]); %! @@ -303,8 +303,8 @@ %! assert (s_idx, 1); ## Test input validation -%!error ismember () -%!error ismember (1) -%!error ismember (1,2,3,4) +%!error <Invalid call> ismember () +%!error <Invalid call> ismember (1) +%!error <Invalid call> ismember (1,2,3,4) %!error <"stable" or "sorted" are not valid options> ismember (1,2, "sorted") %!error <"stable" or "sorted" are not valid options> ismember (1,2, "stable") diff -r dc3ee9616267 -r fa2cdef14442 scripts/set/module.mk --- a/scripts/set/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/set/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -6,6 +6,7 @@ %reldir%/private/validsetargs.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/intersect.m \ %reldir%/ismember.m \ %reldir%/powerset.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/set/powerset.m --- a/scripts/set/powerset.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/set/powerset.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function p = powerset (a, byrows_arg) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -113,8 +113,7 @@ %!assert (powerset([]), {}); # always return a cell array ## Test input validation -%!error powerset () -%!error powerset (1,2,3) +%!error <Invalid call> powerset () %!error <second argument must be "rows"> powerset (1, "cols") %!error <"rows" not valid for cell arrays> powerset ({1}, "rows") %!error <cell arrays can only be used for character> powerset ({1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/set/union.m --- a/scripts/set/union.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/set/union.m Thu Nov 19 13:08:00 2020 -0800 @@ -91,7 +91,7 @@ na = rows (a); else na = numel (a); - end + endif ia = idx(idx <= na); ib = idx(idx > na) - na; endif @@ -195,12 +195,12 @@ %!error <cells not supported with "rows"> union ({"a"}, {"b"}, "rows","legacy") %!error <A and B must be arrays or cell arrays> union (@sin, 1, "rows") %!error <A and B must be arrays or cell arrays> union (@sin,1,"rows","legacy") -%!error <A and B must be 2-dimensional matrices> union (rand(2,2,2), 1, "rows") -%!error <A and B must be 2-dimensional matrices> union (1, rand(2,2,2), "rows") +%!error <A and B must be 2-dimensional matrices> union (rand (2,2,2), 1, "rows") +%!error <A and B must be 2-dimensional matrices> union (1, rand (2,2,2), "rows") %!error <A and B must be 2-dimensional matrices> -%! union (rand(2,2,2), 1, "rows", "legacy"); +%! union (rand (2,2,2), 1, "rows", "legacy"); %!error <A and B must be 2-dimensional matrices> -%! union (1, rand(2,2,2), "rows", "legacy"); +%! union (1, rand (2,2,2), "rows", "legacy"); %!error <number of columns in A and B must match> union ([1 2], 1, "rows") %!error <number of columns in A and B must match> union (1, [1 2], "rows") %!error <number of columns in A and B must match> diff -r dc3ee9616267 -r fa2cdef14442 scripts/set/unique.m --- a/scripts/set/unique.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/set/unique.m Thu Nov 19 13:08:00 2020 -0800 @@ -354,7 +354,7 @@ %! assert (j, [4; 1; 4; 3; 2]); ## Test input validation -%!error unique () +%!error <Invalid call> unique () %!error <X must be an array or cell array of strings> unique ({1}) %!error <options must be strings> unique (1, 2) %!error <cannot specify both "first" and "last"> unique (1, "first", "last") diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/signal/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/__parse_movargs__.m --- a/scripts/signal/__parse_movargs__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/__parse_movargs__.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,10 +24,12 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {@var{args} =} __parse_movargs__ (@var{varargin}) +## @deftypefn {} {@var{args} =} __parse_movargs__ (@var{caller}, @var{varargin}) ## ## Parse arguments for movXXX functions before passing to @code{movfun}. ## +## The input @var{caller} is a string with the name of the calling function +## and is used to personalize any error messages. ## @seealso{movfun} ## @end deftypefn @@ -57,7 +59,6 @@ else error ("Octave:invalid-input-arg", [caller ": invalid input at position %d"], i); - args(end+1) = arg; endif i += 1; # Advance to next element diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/arch_fit.m --- a/scripts/signal/arch_fit.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/arch_fit.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,7 +58,7 @@ function [a, b] = arch_fit (y, x, p, iter, gamma, a0, b0) - if (nargin < 3 || nargin == 6 || nargin > 7) + if (nargin < 3 || nargin == 6) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/arch_rnd.m --- a/scripts/signal/arch_rnd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/arch_rnd.m Thu Nov 19 13:08:00 2020 -0800 @@ -83,13 +83,13 @@ y = zeros (t, 1); h(1) = a(1); - e(1) = sqrt (h(1)) * randn; + e(1) = sqrt (h(1)) * randn (); y(1) = b(1) + e(1); for t = 2:m ta = min ([t, la]); h(t) = a(1) + a(2:ta) * e(t-ta+1:t-1).^2; - e(t) = sqrt (h(t)) * randn; + e(t) = sqrt (h(t)) * randn (); tb = min ([t, lb]); y(t) = b(1) + b(2:tb) * y(t-tb+1:t-1) + e(t); endfor @@ -97,7 +97,7 @@ if (t > m) for t = m+1:t h(t) = a(1) + a(2:la) * e(t-la+1:t-1).^2; - e(t) = sqrt (h(t)) * randn; + e(t) = sqrt (h(t)) * randn (); y(t) = b(1) + b(2:lb) * y(t-tb+1:t-1) + e(t); endfor endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/arma_rnd.m --- a/scripts/signal/arma_rnd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/arma_rnd.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,15 +47,9 @@ ## is omitted, @var{n} = 100 is used. ## @end deftypefn -function x = arma_rnd (a, b, v, t, n) +function x = arma_rnd (a, b, v, t, n = 100) - if (nargin == 4) - n = 100; - elseif (nargin == 5) - if (! isscalar (n)) - error ("arma_rnd: N must be a scalar"); - endif - else + if (nargin < 4) print_usage (); endif @@ -67,6 +61,10 @@ error ("arma_rnd: T must be a scalar"); endif + if (! isscalar (n)) + error ("arma_rnd: N must be a scalar"); + endif + ar = length (a); br = length (b); diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/autoreg_matrix.m --- a/scripts/signal/autoreg_matrix.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/autoreg_matrix.m Thu Nov 19 13:08:00 2020 -0800 @@ -63,6 +63,6 @@ %! B(:,1) = 1; %! assert (autoreg_matrix (A,K), B); -%!error autoreg_matrix () -%!error autoreg_matrix (1) +%!error <Invalid call> autoreg_matrix () +%!error <Invalid call> autoreg_matrix (1) %!error autoreg_matrix (ones (4,1), 5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/bartlett.m --- a/scripts/signal/bartlett.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/bartlett.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ function c = bartlett (m) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -63,7 +63,7 @@ %! A = bartlett (N); %! assert (A(ceil (N/2)), 1); -%!error bartlett () +%!error <Invalid call> bartlett () %!error bartlett (0.5) %!error bartlett (-1) %!error bartlett (ones (1,4)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/blackman.m --- a/scripts/signal/blackman.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/blackman.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function c = blackman (m, opt) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -90,7 +90,7 @@ %! A = blackman (N, "periodic"); %! assert (A(N/2 + 1), 1, 1e-6); -%!error blackman () +%!error <Invalid call> blackman () %!error blackman (0.5) %!error blackman (-1) %!error blackman (ones (1,4)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/detrend.m --- a/scripts/signal/detrend.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/detrend.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function y = detrend (x, p = 1) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -101,8 +101,7 @@ %! assert (abs (y(:)) < 20*eps); ## Test input validation -%!error detrend () -%!error detrend (1, 2, 3) +%!error <Invalid call> detrend () %!error detrend ("a") %!error detrend (true) %!error detrend (1, "invalid") diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/diffpara.m --- a/scripts/signal/diffpara.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/diffpara.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,7 +46,7 @@ function [d, dd] = diffpara (x, a, b) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/fftconv.m --- a/scripts/signal/fftconv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/fftconv.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function c = fftconv (x, y, n) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -102,8 +102,7 @@ %! assert (size (conv (b,a)), [1, numel(a)+numel(b)-1]); ## Test input validation -%!error fftconv (1) -%!error fftconv (1,2,3,4) +%!error <Invalid call> fftconv (1) %!error fftconv ([1, 2; 3, 4], 3) %!error fftconv (2, []) %!error fftconv ([1,1], [2,2] , [3, 4]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/fftfilt.m --- a/scripts/signal/fftfilt.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/fftfilt.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ ## of two larger than N and length(b). This could result in length ## one blocks, but if the user knows better ... - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -187,8 +187,7 @@ %! assert (y0, y, 55*eps); ## Test input validation -%!error fftfilt (1) -%!error fftfilt (1, 2, 3, 4) +%!error <Invalid call> fftfilt (1) %!error fftfilt (ones (2), 1) %!error fftfilt (2, ones (3,3,3)) %!error fftfilt (2, 1, ones (2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/fftshift.m --- a/scripts/signal/fftshift.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/fftshift.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,7 @@ function retval = fftshift (x, dim) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -151,7 +151,6 @@ %! assert (fftshift (y), x); ## Test input validation -%!error fftshift () -%!error fftshift (1, 2, 3) +%!error <Invalid call> fftshift () %!error fftshift (0:3, -1) %!error fftshift (0:3, 0:3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/filter2.m --- a/scripts/signal/filter2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/filter2.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ function y = filter2 (b, x, shape) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif if (nargin < 3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/freqz.m --- a/scripts/signal/freqz.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/freqz.m Thu Nov 19 13:08:00 2020 -0800 @@ -82,7 +82,7 @@ function [h_r, f_r] = freqz (b, a, n, region, Fs) - if (nargin < 1 || nargin > 5) + if (nargin < 1) print_usage (); elseif (nargin == 1) ## Response of an FIR filter. diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/freqz_plot.m --- a/scripts/signal/freqz_plot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/freqz_plot.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function freqz_plot (w, h, freq_norm = false) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/hamming.m --- a/scripts/signal/hamming.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/hamming.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function c = hamming (m, opt) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -87,7 +87,7 @@ %! A = hamming (N, "periodic"); %! assert (A(N/2 + 1), 1); -%!error hamming () +%!error <Invalid call> hamming () %!error hamming (0.5) %!error hamming (-1) %!error hamming (ones (1,4)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/hanning.m --- a/scripts/signal/hanning.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/hanning.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function c = hanning (m, opt) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -87,7 +87,7 @@ %! A = hanning (N, "periodic"); %! assert (A(N/2 + 1), 1); -%!error hanning () +%!error <Invalid call> hanning () %!error hanning (0.5) %!error hanning (-1) %!error hanning (ones (1,4)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/hurst.m --- a/scripts/signal/hurst.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/hurst.m Thu Nov 19 13:08:00 2020 -0800 @@ -33,7 +33,7 @@ function H = hurst (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/ifftshift.m --- a/scripts/signal/ifftshift.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/ifftshift.m Thu Nov 19 13:08:00 2020 -0800 @@ -35,7 +35,7 @@ function retval = ifftshift (x, dim) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -134,7 +134,6 @@ %! assert (ifftshift (y), x); ## Test input validation -%!error ifftshift () -%!error ifftshift (1, 2, 3) +%!error <Invalid call> ifftshift () %!error ifftshift (0:3, -1) %!error ifftshift (0:3, 0:3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/module.mk --- a/scripts/signal/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -9,6 +9,7 @@ %reldir%/private/triangle_sw.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/__parse_movargs__.m \ %reldir%/arch_fit.m \ %reldir%/arch_rnd.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/movfun.m --- a/scripts/signal/movfun.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/movfun.m Thu Nov 19 13:08:00 2020 -0800 @@ -311,6 +311,7 @@ ## Apply "shrink" boundary conditions ## Function is not applied to any window elements outside the original data. function y = shrink_bc (fcn, x, idxp, win, wlen, odim) + N = length (x); idx = idxp + win; tf = (idx > 0) & (idx <= N); # idx inside boundaries @@ -324,11 +325,12 @@ k = idx(tf(:,i),i); y(i,:) = fcn (x(k)); endfor + endfunction ## Apply replacement value boundary conditions ## Window is padded at beginning and end with user-specified value. -function y = replaceval_bc (fcn, x, idxp, win, wlen) +function y = replaceval_bc (fcn, x, idxp, win, wlen, ~) persistent substitute; @@ -359,7 +361,7 @@ ## Apply "same" boundary conditions ## 'y' values outside window are replaced by value of 'x' at the window ## boundary. -function y = same_bc (fcn, x, idxp, win) +function y = same_bc (fcn, x, idxp, win, ~, ~) idx = idxp + win; idx(idx < 1) = 1; N = length (x); @@ -370,7 +372,7 @@ ## Apply "periodic" boundary conditions ## Window wraps around. Window values outside data array are replaced with ## data from the other end of the array. -function y = periodic_bc (fcn, x, idxp, win) +function y = periodic_bc (fcn, x, idxp, win, ~, ~) N = length (x); idx = idxp + win; tf = idx < 1; @@ -600,12 +602,12 @@ %!assert (size( movfun (@(x) [min(x), max(x)], cumsum (ones (10,5),2), 3)), %! [10 5 2]) ## outdim > dim -%!error (movfun (@(x) [min(x), max(x)], (1:10).', 3, "Outdim", 3)) +%!error movfun (@(x) [min(x), max(x)], (1:10).', 3, "Outdim", 3) ## Test input validation -%!error movfun () -%!error movfun (@min) -%!error movfun (@min, 1) +%!error <Invalid call> movfun () +%!error <Invalid call> movfun (@min) +%!error <Invalid call> movfun (@min, 1) %!error <WLEN must be .* array of integers> movfun (@min, 1, {1}) %!error <WLEN must be .* array of integers .= 0> movfun (@min, 1, -1) %!error <WLEN must be .* array of integers> movfun (@min, 1, 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/movslice.m --- a/scripts/signal/movslice.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/movslice.m Thu Nov 19 13:08:00 2020 -0800 @@ -94,9 +94,8 @@ ## FIXME: Need functional BIST tests ## Test input validation -%!error movslice () -%!error movslice (1) -%!error movslice (1,2,3) +%!error <Invalid call> movslice () +%!error <Invalid call> movslice (1) %!error <N must be a positive integer> movslice ([1 2], 1) %!error <N must be a positive integer> movslice (0, 1) %!error <WLEN must be .* array of integers> movslice (1, {1}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/periodogram.m --- a/scripts/signal/periodogram.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/periodogram.m Thu Nov 19 13:08:00 2020 -0800 @@ -210,8 +210,8 @@ ## Test input validation -%!error periodogram () -%!error periodogram (1,2,3,4,5,6) +%!error <Invalid call> periodogram () +%!error <Invalid call> periodogram (1,2,3,4,5,6) %!error <X must be a real or complex vector> periodogram (ones (2,2)) %!error <WIN must be a vector.*same length> periodogram (1:5, ones (2,2)) %!error <WIN must be a vector.*same length> periodogram (1:5, 1:6) diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/sinc.m --- a/scripts/signal/sinc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/sinc.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ function result = sinc (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -58,4 +58,5 @@ %!assert (sinc (1), 0,1e-6) %!assert (sinc (1/2), 2/pi, 1e-6) -%!error sinc() +## Test input validation +%!error <Invalid call> sinc () diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/sinetone.m --- a/scripts/signal/sinetone.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/sinetone.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function retval = sinetone (freq, rate = 8000, sec = 1, ampl = 64) - if (nargin < 1 || nargin > 4) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/sinewave.m --- a/scripts/signal/sinewave.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/sinewave.m Thu Nov 19 13:08:00 2020 -0800 @@ -33,19 +33,21 @@ ## @seealso{sinetone} ## @end deftypefn -function x = sinewave (m, n, d) +function x = sinewave (m, n, d = 0) - if (nargin > 0 && nargin < 4) - if (nargin < 3) - d = 0; - endif - if (nargin < 2) - n = m; - endif - x = sin (((1 : m) + d - 1) * 2 * pi / n); - else + if (nargin < 1) print_usage (); endif + + ## FIXME: No input validation of M, N, or D + if (nargin < 2) + n = m; + endif + if (nargin < 3) + d = 0; + endif + + x = sin (((1 : m) + d - 1) * 2 * pi / n); endfunction @@ -58,4 +60,4 @@ %!assert (sinewave (1), sinewave (1, 1,0)) %!assert (sinewave (3, 4), sinewave (3, 4, 0)) -%!error sinewave () +%!error <Invalid call> sinewave () diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/spectral_adf.m --- a/scripts/signal/spectral_adf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/spectral_adf.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function retval = spectral_adf (c, win, b) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -74,7 +74,6 @@ ## Test input validation -%!error spectral_adf () -%!error spectral_adf (1, 2, 3, 4) -%!error spectral_adf (1, 2) -%!error spectral_adf (1, "invalid") +%!error <Invalid call> spectral_adf () +%!error <WIN must be a string> spectral_adf (1, 2) +%!error <unable to find function for @invalid_lw> spectral_adf (1, "invalid") diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/spectral_xdf.m --- a/scripts/signal/spectral_xdf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/spectral_xdf.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function retval = spectral_xdf (x, win, b) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -76,7 +76,6 @@ ## Test input validation -%!error spectral_xdf () -%!error spectral_xdf (1, 2, 3, 4) -%!error spectral_xdf (1, 2) -%!error spectral_xdf (1, "invalid") +%!error <Invalid call> spectral_xdf () +%!error <WIN must be a string> spectral_xdf (1, 2) +%!error <unable to find function for @invalid_sw> spectral_xdf (1, "invalid") diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/spencer.m --- a/scripts/signal/spencer.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/spencer.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,7 +31,7 @@ function retval = spencer (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/stft.m --- a/scripts/signal/stft.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/stft.m Thu Nov 19 13:08:00 2020 -0800 @@ -66,7 +66,7 @@ function [y, c] = stft (x, win_size = 80, inc = 24, num_coef = 64, win_type = 1) - if (nargin < 1 || nargin > 5) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/unwrap.m --- a/scripts/signal/unwrap.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/unwrap.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,7 +39,7 @@ function retval = unwrap (x, tol, dim) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -152,6 +152,5 @@ %! assert (diff (unwrap (B), 1) < 2*pi, true (1, length (B)-1)); ## Test input validation -%!error unwrap () -%!error unwrap (1,2,3,4) +%!error <Invalid call> unwrap () %!error unwrap ("foo") diff -r dc3ee9616267 -r fa2cdef14442 scripts/signal/yulewalker.m --- a/scripts/signal/yulewalker.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/signal/yulewalker.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function [a, v] = yulewalker (c) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/sparse/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/bicg.m --- a/scripts/sparse/bicg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/bicg.m Thu Nov 19 13:08:00 2020 -0800 @@ -236,7 +236,7 @@ endif norm_b = norm (b, 2); - if (norm_b == 0) # the only (only iff det(A) == 0) solution is x = 0 + if (norm_b == 0) # the only (only iff det (A) == 0) solution is x = 0 if (nargout < 2) printf ("The right hand side vector is all zero so bicg\n") printf ("returned an all zero solution without iterating.\n") @@ -258,7 +258,7 @@ resvec(1) = norm (r0, 2); try - warning ("error", "Octave:singular-matrix", "local") + warning ("error", "Octave:singular-matrix", "local"); prec_r0 = M1fun (r0, "notransp", varargin{:}); # r0 preconditioned prec_s0 = s0; prec_r0 = M2fun (prec_r0, "notransp", varargin{:}); @@ -276,7 +276,7 @@ alpha = (s0' * prec_r0); if (abs (prod_qv) <= eps * abs (alpha)) flag = 4; - break + break; endif alpha ./= prod_qv; x += alpha * p; diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/bicgstab.m --- a/scripts/sparse/bicgstab.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/bicgstab.m Thu Nov 19 13:08:00 2020 -0800 @@ -213,14 +213,14 @@ ## Check consistency and type of A, M1, M2 [Afun, M1fun, M2fun] = __alltohandles__ (A, b, M1, M2, "bicgstab"); - # Check if input tol are empty (set them to default if necessary) + ## Check if input tol are empty (set them to default if necessary) [tol, maxit, x0] = __default__input__ ({1e-06, min(rows(b), 20), ... - zeros(rows(b), 1)}, tol, maxit, x0); + zeros(rows (b), 1)}, tol, maxit, x0); norm_b = norm (b, 2); if (norm_b == 0) if (nargout < 2) - printf("The right hand side vector is all zero so bicgstab \n") + printf ("The right hand side vector is all zero so bicgstab \n") printf ("returned an all zero solution without iterating.\n") endif x_min = zeros (numel (b), 1); @@ -228,7 +228,7 @@ flag = 0; resvec = 0; relres = 0; - return + return; endif ## Double maxit to mind also the "half iterations" @@ -248,7 +248,7 @@ ## To check if the preconditioners are singular or they have some NaN try - warning("error", "Octave:singular-matrix", "local"); + warning ("error", "Octave:singular-matrix", "local"); p_hat = feval (M1fun, p, varargin{:}); p_hat = feval (M2fun, p_hat, varargin{:}); catch @@ -270,7 +270,7 @@ if (resvec (iter + 1) <= real_tol) # reached the tol x_min = x; iter_min = iter; - break + break; elseif (resvec (iter + 1) <= resvec (iter_min + 1)) # Found min residual x_min = x; iter_min = iter; @@ -293,7 +293,7 @@ endif if (norm (x - x_pr) <= norm (x) * eps) flag = 3; - break + break; endif x_pr = x; rho_2 = rho_1; @@ -309,7 +309,7 @@ endwhile resvec = resvec (1:iter+1,1); - relres = resvec (iter_min + 1) / norm_b; ## I set the relative residual + relres = resvec (iter_min + 1) / norm_b; # I set the relative residual iter /= 2; iter_min /= 2; diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/cgs.m --- a/scripts/sparse/cgs.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/cgs.m Thu Nov 19 13:08:00 2020 -0800 @@ -199,12 +199,12 @@ [Afun, M1fun, M2fun] = __alltohandles__ (A, b, M1, M2, "cgs"); [tol, maxit, x0] = __default__input__ ({1e-06, min( rows(b), 20), ... - zeros(size(b))}, tol, maxit, x0); + zeros(size (b))}, tol, maxit, x0); norm_b = norm (b, 2); if (norm_b == 0) if (nargout < 2) - printf("The right hand side vector is all zero so cgs \n") + printf ("The right hand side vector is all zero so cgs \n") printf ("returned an all zero solution without iterating.\n") endif x_min = zeros (numel (b), 1); @@ -212,7 +212,7 @@ flag = 0; resvec = 0; relres = 0; - return + return; endif resvec = zeros (maxit, 1); # Preallocation of resvec @@ -229,7 +229,7 @@ rho_1 = rr' * r0; try - warning ("error","Octave:singular-matrix","local") + warning ("error","Octave:singular-matrix","local"); p_hat = feval (M1fun, p, varargin{:}); p_hat = feval (M2fun, p_hat, varargin {:}); catch @@ -252,7 +252,7 @@ r0 -= alpha* feval (Afun, u_hat, varargin{:}); iter += 1; resvec (iter + 1) = norm (r0, 2); - if (norm (x - x_pr, 2) <= norm(x, 2) * eps) # Stagnation + if (norm (x - x_pr, 2) <= norm (x, 2) * eps) # Stagnation flag = 3; break; endif @@ -379,7 +379,7 @@ %! M1_fun = @(z) M1 \ z; %! M2_fun = @(z) M2 \ z; %! [x, flag] = cgs (A,b); -%! assert(flag, 0); +%! assert (flag, 0); %! [x, flag] = cgs (A, b, [], maxit, M1, M2); %! assert (flag, 0); %! [x, flag] = cgs (A, b, [], maxit, M1_fun, M2_fun); diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/colperm.m --- a/scripts/sparse/colperm.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/colperm.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function p = colperm (s) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/eigs.m --- a/scripts/sparse/eigs.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/eigs.m Thu Nov 19 13:08:00 2020 -0800 @@ -787,7 +787,7 @@ %! B = toeplitz (sparse ([1, 1], [1, 2], [2, 1], 1, 10)); %! [v, d] = eigs (A, B, 4, "lm"); %! for i = 1:4 -%! assert (A * v(:,i), d(i, i) * B * v(:,i), 1e-12) +%! assert (A * v(:,i), d(i, i) * B * v(:,i), 1e-12); %! endfor %! ddiag = diag (d); %! [ddiag, idx] = sort (ddiag); @@ -887,7 +887,7 @@ %! opts.cholB = true; %! [v, d] = eigs (A, R, 4, "lm", opts); %! for i = 1:4 -%! assert (A * v(:,i), d(i, i) * B * v(:,i), 1e-12) +%! assert (A * v(:,i), d(i, i) * B * v(:,i), 1e-12); %! endfor %!testif HAVE_ARPACK, HAVE_UMFPACK %! A = toeplitz (sparse (1:10)); @@ -897,7 +897,7 @@ %! opts.permB = permB; %! [v, d] = eigs (A, R, 4, "lm", opts); %! for i = 1:4 -%! assert (A * v(:,i), d(i, i) * B * v(:,i), 1e-12) +%! assert (A * v(:,i), d(i, i) * B * v(:,i), 1e-12); %! endfor @@ -1292,7 +1292,7 @@ %! A(1, 1) = 0; %! A(1, 9) = 1; %! [V, L] = eigs (A, 4, -1); -%! assert (!any (isnan (diag (L)))); +%! assert (! any (isnan (diag (L)))); %! assert (any (abs (diag (L)) <= 2 * eps)); %!testif HAVE_ARPACK %! A = diag (ones (9, 1), 1); @@ -1488,11 +1488,11 @@ %! i_A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; %! j_A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; %! v_A = [1, 2i, 3, 4i, 5, 6i, 7, 8, 9, 10i]; -%! A = sparse(i_A, j_A, v_A); +%! A = sparse (i_A, j_A, v_A); %! i_B = [1,2, 3, 4, 5, 6, 7, 8, 9, 10]; %! j_B = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; %! v_B = [3, 10i, 1, 8i, 7, 6i, 5, 4i, 9, 7i]; -%! B = sparse(i_B, j_B, v_B); # not SPD +%! B = sparse (i_B, j_B, v_B); # not SPD %! [Evectors, Evalues] = eigs(A, B, 5, "SM"); # call_eig is true %! ResidualVectors = A * Evectors - B * Evectors * Evalues; %! RelativeErrors = norm (ResidualVectors, "columns") ./ ... diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/etreeplot.m --- a/scripts/sparse/etreeplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/etreeplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,10 +36,15 @@ function etreeplot (A, varargin) - if (nargin < 1) + if (nargin < 1 || nargin > 3) print_usage (); endif treeplot (etree (A+A'), varargin{:}); endfunction + + +## Test input validation +%!error <Invalid call> etreeplot () +%!error <Invalid call> etreeplot (1,2,3,4) diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/gmres.m --- a/scripts/sparse/gmres.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/gmres.m Thu Nov 19 13:08:00 2020 -0800 @@ -258,9 +258,9 @@ size_b = rows (b); if (tol >= 1) - warning("Input tol is bigger than 1. \n Try to use a smaller tolerance."); + warning ("Input tol is bigger than 1. \n Try to use a smaller tolerance."); elseif (tol <= eps / 2) - warning("Input tol may not be achievable by gmres. \n Try to use a bigger tolerance."); + warning ("Input tol may not be achievable by gmres. \n Try to use a bigger tolerance."); endif ## This big "if block" is to set maxit and restart in the proper way @@ -270,7 +270,7 @@ maxit = 1; max_iter_number = min (size_b, 10); elseif (restart <= 0) || (maxit <= 0) - error ("gmres: MAXIT and RESTART must be positive integers") + error ("gmres: MAXIT and RESTART must be positive integers"); elseif (restart < size_b) && (empty_maxit) maxit = min (size_b / restart, 10); max_iter_number = maxit * restart; @@ -278,7 +278,7 @@ maxit = 1; max_iter_number = min (size_b, 10); elseif (restart > size_b) && (empty_maxit) - warning ("RESTART is %d but it should be bounded by SIZE(A,2).\n Setting restart to %d. \n", restart, size_b) + warning ("RESTART is %d but it should be bounded by SIZE(A,2).\n Setting restart to %d. \n", restart, size_b); restart = size_b; maxit = 1; max_iter_number = restart; @@ -290,8 +290,8 @@ restart = size_b; maxit = size_b; max_iter_number = size_b; - elseif (restart > size_b) && (!empty_maxit) - warning ("RESTART is %d but it should be bounded by SIZE(A,2).\n Setting restart to %d. \n", restart, size_b) + elseif (restart > size_b) && (! empty_maxit) + warning ("RESTART is %d but it should be bounded by SIZE(A,2).\n Setting restart to %d. \n", restart, size_b); restart = size_b; max_iter_number = restart * maxit; elseif (restart == size_b) && (maxit <= size_b) @@ -303,14 +303,14 @@ prec_b_norm = norm (b, 2); if (prec_b_norm == 0) if (nargout < 2) - printf("The right hand side vector is all zero so gmres\nreturned an all zero solution without iterating.\n") + printf ("The right hand side vector is all zero so gmres\nreturned an all zero solution without iterating.\n") endif x_min = b; flag = 0; relres = 0; resvec = 0; it = [0, 0]; - return + return; endif ## gmres: function handle case @@ -324,14 +324,14 @@ iter_min = 0; # iteration with minimum residual outer_it = 1; # number of outer iterations restart_it = 1; # number of inner iterations - it = zeros(1, 2); + it = zeros (1, 2); resvec = zeros (max_iter_number + 1, 1); flag = 1; # Default flag is maximum # of iterations exceeded ## begin loop u = feval (Afun, x_old, varargin{:}); try - warning("error", "Octave:singular-matrix", "local") + warning ("error", "Octave:singular-matrix", "local"); prec_res = feval (M1fun, b - u, varargin{:}); # M1*(b-u) prec_res = feval (M2fun, prec_res, varargin{:}); presn = norm (prec_res, 2); @@ -401,22 +401,22 @@ if ((nargout < 2) && (restart != size_b)) # restart applied switch (flag) case {0} # gmres converged - printf ("gmres(%d) converged at outer iteration %d (inner iteration %d) ",restart, it (1), it (2)); + printf ("gmres (%d) converged at outer iteration %d (inner iteration %d) ",restart, it (1), it (2)); printf ("to a solution with relative residual %d \n", relres); case {1} # max number of iteration reached - printf ("gmres(%d) stopped at outer iteration %d (inner iteration %d) ", restart, outer_it, restart_it-1); + printf ("gmres (%d) stopped at outer iteration %d (inner iteration %d) ", restart, outer_it, restart_it-1); printf ("without converging to the desired tolerance %d ", tol); printf ("because the maximum number of iterations was reached \n"); printf ("The iterated returned (number %d(%d)) ", it(1), it(2)); printf ("has relative residual %d \n", relres); case {2} # preconditioner singular - printf ("gmres(%d) stopped at outer iteration %d (inner iteration %d) ",restart, outer_it, restart_it-1); + printf ("gmres (%d) stopped at outer iteration %d (inner iteration %d) ",restart, outer_it, restart_it-1); printf ("without converging to the desired tolerance %d ", tol); printf ("because the preconditioner matrix is singular \n"); printf ("The iterated returned (number %d(%d)) ", it(1), it(2)); printf ("has relative residual %d \n", relres); case {3} # stagnation - printf ("gmres(%d) stopped at outer iteration %d (inner iteration %d) ", restart, outer_it, restart_it - 1); + printf ("gmres (%d) stopped at outer iteration %d (inner iteration %d) ", restart, outer_it, restart_it - 1); printf ("without converging to the desired tolerance %d", tol); printf ("because it stagnates. \n"); printf ("The iterated returned (number %d(%d)) ", it(1), it(2)); @@ -447,8 +447,10 @@ printf ("has relative residual %d \n", relres); endswitch endif + endfunction + %!demo %! dim = 20; %! A = spdiags ([-ones(dim,1) 2*ones(dim,1) ones(dim,1)], [-1:1], dim, dim); @@ -539,7 +541,7 @@ %! [x, flag] = gmres (A, b, 10, 1e-10, dim, @(x) x ./ diag (A), [], b); %! assert (x, A\b, 1e-9*norm (x, Inf)); %! [x, flag] = gmres (A, b, dim, 1e-10, 1e4, @(x) diag (diag (A)) \ x, [], b); -%! assert(x, A\b, 1e-7*norm (x, Inf)); +%! assert (x, A\b, 1e-7*norm (x, Inf)); %!test %! dim = 100; @@ -564,14 +566,14 @@ %! b = sum (A, 2); %! [x, flag] = gmres(A, b, [], [], 5); %! assert (flag, 0); -%! assert (x, ones (5, 1), -1e-06) +%! assert (x, ones (5, 1), -1e-06); %!test %! ## Maximum number of iteration reached %! A = hilb (100); %! b = sum (A, 2); %! [x, flag, relres, iter] = gmres (A, b, [], 1e-14); -%! assert(flag, 1); +%! assert (flag, 1); %!test %! ## gmres recognizes that the preconditioner matrix is singular @@ -580,56 +582,56 @@ %! I = eye (3); %! M = [1 0 0; 0 1 0; 0 0 0]; # the last row is zero %! [x, flag] = gmres(@(y) AA * y, bb, [], [], [], @(y) M \ y, @(y) y); -%! assert (flag, 2) +%! assert (flag, 2); %!test %! A = rand (4); %! A = A' * A; %! [x, flag] = gmres (A, zeros (4, 1), [], [], [], [], [], ones (4, 1)); -%! assert (x, zeros (4, 1)) +%! assert (x, zeros (4, 1)); %!test %! A = rand (4); %! b = zeros (4, 1); %! [x, flag, relres, iter] = gmres (A, b); -%! assert (relres, 0) +%! assert (relres, 0); %!test %! A = toeplitz (sparse ([2, 1, 0, 0, 0]), sparse ([2, -1, 0, 0, 0])); %! b = A * ones (5, 1); %! [x, flag, relres, iter] = gmres (A, b, [], [], [], [], [], ... %! ones (5, 1) + 1e-8); -%! assert (iter, [0, 0]) +%! assert (iter, [0, 0]); %!test %! A = rand (20); %! b = A * ones (20, 1); %! [x, flag, relres, iter, resvec] = gmres (A, b, [], [], 1); -%! assert (iter, [1, 1]) +%! assert (iter, [1, 1]); %!test %! A = hilb (20); %! b = A * ones (20, 1); %! [x, flag, relres, iter, resvec] = gmres (A, b ,5, 1e-14); -%! assert (iter, [4, 5]) +%! assert (iter, [4, 5]); %!test %! A = single (1); %! b = 1; %! [x, flag] = gmres (A, b); -%! assert (class (x), "single") +%! assert (class (x), "single"); %!test %! A = 1; %! b = single (1); %! [x, flag] = gmres (A, b); -%! assert (class (x), "single") +%! assert (class (x), "single"); %!test %! A = single (1); %! b = single (1); %! [x, flag] = gmres (A, b); -%! assert (class (x), "single") +%! assert (class (x), "single"); %!test %!function y = Afun (x) @@ -637,11 +639,11 @@ %! y = A * x; %!endfunction %! [x, flag] = gmres ("Afun", [1; 2; 2; 3]); -%! assert (x, ones(4, 1), 1e-6) +%! assert (x, ones (4, 1), 1e-6); %!test # preconditioned residual %! A = toeplitz (sparse ([2, 1, 0, 0, 0]), sparse ([2, -1, 0, 0, 0])); %! b = sum (A, 2); %! M = magic (5); %! [x, flag, relres] = gmres (A, b, [], [], 2, M); -%! assert (relres, norm (M \ (b - A * x)) / norm (M \ b), 8 * eps) +%! assert (relres, norm (M \ (b - A * x)) / norm (M \ b), 8 * eps); diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/gplot.m --- a/scripts/sparse/gplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/gplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function [x, y] = gplot (A, xy, line_style) - if (nargin < 2 || nargin > 3 || nargout > 2) + if (nargin < 2) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/ichol.m --- a/scripts/sparse/ichol.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/ichol.m Thu Nov 19 13:08:00 2020 -0800 @@ -160,7 +160,7 @@ function L = ichol (A, opts = struct ()) - if (nargin < 1 || nargin > 2 || nargout > 1) + if (nargin < 1) print_usage (); endif @@ -169,7 +169,7 @@ endif if (! isstruct (opts)) - error ("ichol: OPTS must be a structure."); + error ("ichol: OPTS must be a structure"); endif ## If A is empty then return empty L for Matlab compatibility diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/ilu.m --- a/scripts/sparse/ilu.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/ilu.m Thu Nov 19 13:08:00 2020 -0800 @@ -168,7 +168,7 @@ function [L, U, P] = ilu (A, opts = struct ()) - if (nargin < 1 || nargin > 2 || (nargout > 3)) + if (nargin < 1) print_usage (); endif @@ -177,7 +177,7 @@ endif if (! isstruct (opts)) - error ("ilu: OPTS must be a structure."); + error ("ilu: OPTS must be a structure"); endif ## If A is empty then return empty L, U and P for Matlab compatibility @@ -507,7 +507,7 @@ %! A = sparse (magic (4)); %! opts.type = "ilutp"; %! [L, U] = ilu (A, opts); -%! assert (L * U, A, eps) +%! assert (L * U, A, eps); ## Tests for input validation %!shared A_tiny, opts diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/module.mk --- a/scripts/sparse/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -8,6 +8,7 @@ %reldir%/private/__sprand__.m %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/bicg.m \ %reldir%/bicgstab.m \ %reldir%/cgs.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/nonzeros.m --- a/scripts/sparse/nonzeros.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/nonzeros.m Thu Nov 19 13:08:00 2020 -0800 @@ -31,7 +31,7 @@ function v = nonzeros (A) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -52,5 +52,4 @@ %!assert (nonzeros (sparse ([1,2,3,0])), [1;2;3]) ## Test input validation -%!error nonzeros () -%!error nonzeros (1, 2) +%!error <Invalid call> nonzeros () diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/pcg.m --- a/scripts/sparse/pcg.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/pcg.m Thu Nov 19 13:08:00 2020 -0800 @@ -284,7 +284,7 @@ b_norm = norm (b); if (b_norm == 0) if (n_arg_out < 2) - printf("The right hand side vector is all zero so pcg \n"); + printf ("The right hand side vector is all zero so pcg \n"); printf ("returned an all zero solution without iterating.\n"); endif x_min = b; @@ -293,7 +293,7 @@ resvec = 0; iter_min = 0; eigest = [NaN, NaN]; - return + return; endif x = x_pr = x_min = x0; @@ -319,7 +319,7 @@ while (resvec(iter-1,1) > tol * b_norm && iter < maxit) if (iter == 2) # Check whether M1 or M2 are singular try - warning ("error","Octave:singular-matrix","local") + warning ("error","Octave:singular-matrix","local"); z = feval (M1fun, r, varargin{:}); z = feval (M2fun, z, varargin{:}); catch @@ -395,7 +395,7 @@ endif else eigest = [NaN, NaN]; - warning ('pcg: eigenvalue estimate failed: matrix not positive definite?') + warning ('pcg: eigenvalue estimate failed: matrix not positive definite?'); endif resvec(iter - 1, 2) = sqrt (r' * z); resvec = resvec (1:(iter-1), :); @@ -454,6 +454,7 @@ printf ("has relative residual %d \n", relres); endswitch endif + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/pcr.m --- a/scripts/sparse/pcr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/pcr.m Thu Nov 19 13:08:00 2020 -0800 @@ -334,7 +334,7 @@ %! printf ("The solution relative error is %g\n", norm (x-X) / norm (X)); %! clf; %! title ("Convergence history"); -%! xlabel ("Iteration"); ylabel ("log(||b-Ax||/||b||)"); +%! xlabel ("Iteration"); ylabel ("log (||b-Ax||/||b||)"); %! semilogy ([0:iter], resvec/resvec(1), "o-g;relative residual;"); %!demo @@ -354,13 +354,13 @@ %! endif %! clf; %! title ("Convergence history"); -%! xlabel ("Iteration"); ylabel ("log(||b-Ax||)"); +%! xlabel ("Iteration"); ylabel ("log (||b-Ax||)"); %! semilogy ([0:iter], resvec, "o-g;absolute residual;"); %!demo %! ## Full output from PCR %! ## We use an indefinite matrix based on the 1-D Laplacian matrix for A, -%! ## and here we have cond(A) = O(N^2) +%! ## and here we have cond (A) = O(N^2) %! ## That's the reason we need some preconditioner; here we take %! ## a very simple and not powerful Jacobi preconditioner, %! ## which is the diagonal of A. @@ -383,7 +383,7 @@ %! [x, flag, relres, iter, resvec] = pcr (A,b,[],maxit); %! clf; %! title ("Convergence history"); -%! xlabel ("Iteration"); ylabel ("log(||b-Ax||)"); +%! xlabel ("Iteration"); ylabel ("log (||b-Ax||)"); %! semilogy ([0:iter], resvec, "o-g;NO preconditioning: absolute residual;"); %! %! pause (1); @@ -445,7 +445,7 @@ %! b = ones (N,1); %! X = A \ b; # X is the true solution %! [x, flag, relres, iter] = pcr (A,b,[],[],A,b); -%! assert (norm (x-X) / norm(X) < 1e-6); +%! assert (norm (x-X) / norm (X) < 1e-6); %! assert (relres < 1e-6); %! assert (flag, 0); %! assert (iter, 1); # should converge in one iteration diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/private/__alltohandles__.m --- a/scripts/sparse/private/__alltohandles__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/private/__alltohandles__.m Thu Nov 19 13:08:00 2020 -0800 @@ -64,47 +64,65 @@ Afun = A; elseif (ischar (A)) Afun = str2func (A); - elseif (!isnumeric (A) || !issquare (A)) - error([solver_name, ": A must be a square matrix or a function handle"]) + elseif (! isnumeric (A) || ! issquare (A)) + error ([solver_name, ": A must be a square matrix or a function handle"]); else A_is_numeric = true; if (size (A, 2) != size (b, 1)) - error ("__alltohandles__: dimension of b is not consistent with A") + error ("__alltohandles__: dimension of B is not consistent with A"); endif endif ## Check M1 and sets its type if (isempty (M1)) # M1 empty, set to identity function - M1fun = @(x) x; + switch (solver_name) + case {"pcg", "gmres", "bicgstab", "cgs", "tfqmr"} + ## methods which do not require the transpose + M1fun = @(x) x; + case {"bicg"} + ## methods which do require the transpose + M1fun = @(x, ~) x; + otherwise + error (["__alltohandles__: unknown method: ", solver_name]); + endswitch else # M1 not empty if (is_function_handle (M1)) M1fun = M1; elseif (ischar (M1)) M1fun = str2func (M1); - elseif (!isnumeric (M1) || !issquare (M1)) - error([solver_name, ": M1 must be a square matrix or a function handle"]) + elseif (! isnumeric (M1) || ! issquare (M1)) + error ([solver_name, ": M1 must be a square matrix or a function handle"]); else M1_is_numeric = true; endif endif if (isempty (M2)) # M2 empty, then I set is to the identity function - M2fun = @(x) x; + switch (solver_name) + case {"pcg", "gmres", "bicgstab", "cgs", "tfqmr"} + ## methods which do not require the transpose + M2fun = @(x) x; + case {"bicg"} + ## methods which do require the transpose + M2fun = @(x, ~) x; + otherwise + error (["__alltohandles__: unknown method: ", solver_name]); + endswitch else # M2 not empty if (is_function_handle (M2)) M2fun = M2; elseif (ischar (M2)) M2fun = str2func (M2); - elseif (!isnumeric (M2) || !issquare (M2)) - error([solver_name, ": M2 must be a square matrix or a function handle"]) + elseif (! isnumeric (M2) || ! issquare (M2)) + error ([solver_name, ": M2 must be a square matrix or a function handle"]); else M2_is_numeric = true; endif endif - switch solver_name + switch (solver_name) case {"pcg", "gmres", "bicgstab", "cgs", "tfqmr"} - # methods which do not require the transpose + ## methods which do not require the transpose if (A_is_numeric) Afun = @(x) A * x; endif @@ -115,7 +133,7 @@ M2fun = @(x) M2 \ x; endif case {"bicg"} - # methods which do require the transpose + ## methods which do require the transpose if (A_is_numeric) Afun = @(x, trans) A_sub (A, x, trans); endif @@ -128,6 +146,7 @@ otherwise error (["__alltohandles__: unknown method: ", solver_name]); endswitch + endfunction function y = A_sub (A, x, trans) diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/private/__default__input__.m --- a/scripts/sparse/private/__default__input__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/private/__default__input__.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,31 +34,39 @@ ## @item @var{def_val} is a cell array that contains the values to use ## as default. ## -## @item @var{varargin} are the input arguments +## @item @var{varargin} are the input arguments. ## @end itemize ## ## The output arguments are: ## ## @itemize @minus -## @item @var{varargout} all input arguments completed with default -## values for empty or omitted parameters. +## @item @var{varargout} are the input arguments where any empty or omitted +## parameters have been replaced with default values. ## ## @end itemize ## ## @end deftypefn - -function [varargout] = __default__input__ (def_val, varargin) +function varargout = __default__input__ (def_val, varargin) - m = length (def_val); - n = length (varargin); + m = numel (def_val); + n = numel (varargin); + count = min (m, n); - for i = 1:m - if (n < i || isempty (varargin{i})) + ## Check for missing values in input and replace with default value. + for i = 1:count + if (isempty (varargin{i})) varargout{i} = def_val{i}; else varargout{i} = varargin{i}; endif endfor + ## Copy any remaining items to output + if (n < m) + varargout(n+1:m) = def_val(n+1:m); + elseif (m < n) + varargout(m+1:n) = varargin(m+1:n); + endif + endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/private/__sprand__.m --- a/scripts/sparse/private/__sprand__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/private/__sprand__.m Thu Nov 19 13:08:00 2020 -0800 @@ -117,7 +117,7 @@ else ## Only the min (m, n) greater singular values from rc vector are used. if (length (rc) > min (m,n)) - rc = rc(1:min(m, n)); + rc = rc(1:min (m, n)); endif S = sparse (diag (sort (rc, "descend"), m, n)); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/qmr.m --- a/scripts/sparse/qmr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/qmr.m Thu Nov 19 13:08:00 2020 -0800 @@ -206,13 +206,13 @@ vt = pt - beta1 * v; y = M1m1x (vt); - rho1 = norm(y); + rho1 = norm (y); wt = Atx (q) - beta1 * w; z = M2tm1x (wt); - xi1 = norm(z); - theta1 = rho1 / (gamma0 * abs(beta1)); - gamma1 = 1 / sqrt(1 + theta1^2); # If gamma1 == 0, method fails. + xi1 = norm (z); + theta1 = rho1 / (gamma0 * abs (beta1)); + gamma1 = 1 / sqrt (1 + theta1^2); # If gamma1 == 0, method fails. eta1 = -eta0 * rho0 * gamma1^2 / (beta1 * gamma0^2); if (iter == 1) @@ -267,7 +267,7 @@ printf ("to a solution with relative residual %e\n", res1); endif else - print_usage(); + print_usage (); endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/spconvert.m --- a/scripts/sparse/spconvert.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/spconvert.m Thu Nov 19 13:08:00 2020 -0800 @@ -37,7 +37,7 @@ function s = spconvert (m) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -73,8 +73,7 @@ %! assert (size (spconvert ([1, 1, 3; 5, 15, 0])), [5, 15]); ## Test input validation -%!error spconvert () -%!error spconvert (1, 2) +%!error <Invalid call> spconvert () %!error spconvert ({[1 2 3]}) %!error spconvert ([1 2]) %!error spconvert ([1 2 3i]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/spdiags.m --- a/scripts/sparse/spdiags.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/spdiags.m Thu Nov 19 13:08:00 2020 -0800 @@ -64,7 +64,7 @@ function [B, d] = spdiags (v, d, m, n) - if (nargin < 1 || nargin > 4) + if (nargin < 1) print_usage (); endif @@ -178,5 +178,4 @@ %!assert (spdiags ([0.5 -1 0.5], 0:2, 1, 1), sparse (0.5)) ## Test input validation -%!error spdiags () -%!error spdiags (1,2,3,4,5) +%!error <Invalid call> spdiags () diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/spones.m --- a/scripts/sparse/spones.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/spones.m Thu Nov 19 13:08:00 2020 -0800 @@ -33,7 +33,7 @@ function r = spones (S) - if (nargin != 1) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/sprand.m --- a/scripts/sparse/sprand.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/sprand.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,9 +49,9 @@ function s = sprand (m, n, d, rc) - if (nargin == 1 ) + if (nargin == 1) s = __sprand__ (m, @rand); - elseif ( nargin == 3) + elseif (nargin == 3) s = __sprand__ (m, n, d, "sprand", @rand); elseif (nargin == 4) s = __sprand__ (m, n, d, rc, "sprand", @rand); @@ -99,9 +99,8 @@ %!assert (size (sprand (3, 0, 0.5)), [3, 0]) ## Test input validation -%!error sprand () -%!error sprand (1, 2) -%!error sprand (1, 2, 3, 4) +%!error <Invalid call> sprand () +%!error <Invalid call> sprand (1, 2) %!error <M must be a non-negative integer> sprand (-1, -1, 0.5) %!error <M must be a non-negative integer> sprand (ones (3), 3, 0.5) %!error <M must be a non-negative integer> sprand (3.5, 3, 0.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/sprandn.m --- a/scripts/sparse/sprandn.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/sprandn.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,9 +49,9 @@ function s = sprandn (m, n, d, rc) - if (nargin == 1 ) + if (nargin == 1) s = __sprand__ (m, @randn); - elseif ( nargin == 3) + elseif (nargin == 3) s = __sprand__ (m, n, d, "sprandn", @randn); elseif (nargin == 4) s = __sprand__ (m, n, d, rc, "sprandn", @randn); @@ -98,9 +98,8 @@ %!assert (size (sprandn (3, 0, 0.5)), [3, 0]) ## Test input validation -%!error sprandn () -%!error sprandn (1, 2) -%!error sprandn (1, 2, 3, 4) +%!error <Invalid call> sprandn () +%!error <Invalid call> sprandn (1, 2) %!error <M must be a non-negative integer> sprand (-1, -1, 0.5) %!error <M must be a non-negative integer> sprandn (ones (3), 3, 0.5) %!error <M must be a non-negative integer> sprandn (3.5, 3, 0.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/sprandsym.m --- a/scripts/sparse/sprandsym.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/sprandsym.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,7 +39,7 @@ function S = sprandsym (n, d) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -181,8 +181,7 @@ %!assert (size (sprandsym (0, 0.5)), [0, 0]) ## Test input validation -%!error sprandsym () -%!error sprandsym (1, 2, 3) +%!error <Invalid call> sprandsym () %!error sprandsym (ones (3), 0.5) %!error sprandsym (3.5, 0.5) %!error sprandsym (-1, 0.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/spstats.m --- a/scripts/sparse/spstats.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/spstats.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function [count, mean, var] = spstats (S, j) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/spy.m --- a/scripts/sparse/spy.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/spy.m Thu Nov 19 13:08:00 2020 -0800 @@ -29,17 +29,17 @@ ## @deftypefnx {} {} spy (@dots{}, @var{line_spec}) ## Plot the sparsity pattern of the sparse matrix @var{x}. ## -## If the argument @var{markersize} is given as a scalar value, it is used to -## determine the point size in the plot. +## If the optional numeric argument @var{markersize} is given, it determines +## the size of the markers used in the plot. ## -## If the string @var{line_spec} is given it is passed to @code{plot} and -## determines the appearance of the plot. +## If the optional string @var{line_spec} is given it is passed to @code{plot} +## and determines the appearance of the plot. ## @seealso{plot, gplot} ## @end deftypefn function spy (x, varargin) - if (nargin < 1) + if (nargin < 1 || nargin > 3) print_usage (); endif @@ -49,21 +49,22 @@ else line_spec = "."; endif - for i = 1:length (varargin) - if (ischar (varargin{i})) - if (length (varargin{i}) == 1) - line_spec = [line_spec, varargin{i}]; + for arg = varargin + arg = arg{1}; + if (ischar (arg)) + if (numel (arg) == 1) + line_spec = [line_spec, arg]; else - line_spec = varargin{i}; + line_spec = arg; endif - elseif (isscalar (varargin{i})) - markersize = varargin{i}; + elseif (isreal (arg) && isscalar (arg)) + markersize = arg; else error ("spy: expected markersize or linespec"); endif endfor - [i, j, s] = find (x); + [i, j] = find (x); [m, n] = size (x); if (isnan (markersize)) @@ -73,6 +74,7 @@ endif axis ([0, n+1, 0, m+1], "ij"); + xlabel (sprintf ("nnz = %d", nnz (x))); endfunction @@ -81,5 +83,6 @@ %! clf; %! spy (sprand (10,10, 0.2)); -## Mark graphical function as tested by demo block -%!assert (1) +## Test input validation +%!error <Invalid call> spy () +%!error <Invalid call> spy (1,2,3,4) diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/svds.m --- a/scripts/sparse/svds.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/svds.m Thu Nov 19 13:08:00 2020 -0800 @@ -102,7 +102,7 @@ persistent root2 = sqrt (2); - if (nargin < 1 || nargin > 4) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/tfqmr.m --- a/scripts/sparse/tfqmr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/tfqmr.m Thu Nov 19 13:08:00 2020 -0800 @@ -217,7 +217,7 @@ norm_b = norm (b, 2); if (norm_b == 0) if (nargout < 2) - printf("The right hand side vector is all zero so tfqmr \n") + printf ("The right hand side vector is all zero so tfqmr \n") printf ("returned an all zero solution without iterating.\n") endif x_min = zeros (numel (b), 1); @@ -225,7 +225,7 @@ flag = 0; resvec = 0; relres = 0; - return + return; endif x = x_pr = x_min = x0; @@ -242,7 +242,7 @@ it = 1; try - warning("error", "Octave:singular-matrix", "local"); + warning ("error", "Octave:singular-matrix", "local"); u_hat = feval (M1fun, u, varargin{:}); u_hat = feval (M2fun, u_hat, varargin{:}); v = feval (Afun, u_hat, varargin{:}); @@ -257,7 +257,7 @@ ## Essentially the next iteration doesn't change x, ## and the iter after this will have a division by zero flag = 4; - break + break; endif alpha = rho_1 / v_r; u_1 = u - alpha * v; # u at the after iteration @@ -279,7 +279,7 @@ ## Essentially the next iteration doesn't change x, ## and the iter after this will have a division by zero flag = 4; - break + break; endif beta = rho_1 / rho_2; u_1 = w + beta * u; # u at the after iteration @@ -298,7 +298,7 @@ endif if (norm (x_pr - x) <= norm (x) * eps) flag = 3; # Stagnation - break + break; endif x_pr = x; it = -it; @@ -306,8 +306,8 @@ resvec = resvec (1: (iter + 1)); relres = resvec (iter_min + 1) / norm (b); - iter_min = floor(iter_min / 2); # compatibility, since it - # makes two times the effective iterations + iter_min = floor (iter_min / 2); # compatibility, since it + # makes two times the effective iterations if (relres <= tol) flag = 0; @@ -344,7 +344,10 @@ printf ("has relative residual %e\n", relres); endswitch endif + endfunction + + %!test %! ## Check that all type of inputs work %! A = toeplitz (sparse ([2, 1, 0, 0, 0]), sparse ([2, -1, 0, 0, 0])); @@ -428,46 +431,46 @@ %! A (1,50) = 10000; %! b = ones (50,1); %! [x, flag, relres, iter, resvec] = tfqmr (A, b, [], 100); -%! assert (flag, 0) -%! assert (x, A \ b, 1e-05) +%! assert (flag, 0); +%! assert (x, A \ b, 1e-05); %! ## Detects a singular preconditioner %! M = ones (50); %! M(1, 1) = 0; %! [x, flag] = tfqmr (A, b, [], 100, M); -%! assert (flag, 2) +%! assert (flag, 2); %!test %! A = single (1); %! b = 1; %! [x, flag] = tfqmr (A, b); -%! assert (class (x), "single") +%! assert (class (x), "single"); %!test %! A = 1; %! b = single (1); %! [x, flag] = tfqmr (A, b); -%! assert (class (x), "single") +%! assert (class (x), "single"); %!test %! A = single (1); %! b = single (1); %! [x, flag] = tfqmr (A, b); -%! assert (class (x), "single") +%! assert (class (x), "single"); %!test %!function y = Afun (x) -%! A = toeplitz ([2, 1, 0, 0], [2, -1, 0, 0]); -%! y = A * x; +%! A = toeplitz ([2, 1, 0, 0], [2, -1, 0, 0]); +%! y = A * x; %!endfunction %! [x, flag] = tfqmr ("Afun", [1; 2; 2; 3]); -%! assert (x, ones(4, 1), 1e-6) +%! assert (x, ones (4, 1), 1e-6); %!test # unpreconditioned residual %! A = toeplitz (sparse ([2, 1, 0, 0, 0]), sparse ([2, -1, 0, 0, 0])); %! b = sum (A, 2); %! M = magic (5); %! [x, flag, relres] = tfqmr (A, b, [], 3, M); -%! assert (relres, norm (b - A * x) / norm (b), 8 * eps) +%! assert (relres, norm (b - A * x) / norm (b), 8 * eps); %!demo # simplest use %! n = 20; diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/treelayout.m --- a/scripts/sparse/treelayout.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/treelayout.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function [x_coordinate, y_coordinate, height, s] = ... treelayout (tree, permutation) - if (nargin < 1 || nargin > 2 || nargout > 4) + if (nargin < 1) print_usage (); elseif (! isvector (tree) || rows (tree) != 1 || ! isnumeric (tree) || any (tree > length (tree)) || any (tree < 0)) @@ -72,7 +72,7 @@ if (hare < i) ## This part of graph was checked before. - break + break; endif tortoise = tree(tortoise); diff -r dc3ee9616267 -r fa2cdef14442 scripts/sparse/treeplot.m --- a/scripts/sparse/treeplot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/sparse/treeplot.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,7 +40,7 @@ function treeplot (tree, node_style = "ko", edge_style = "r") - if (nargin < 1 || nargin > 3 || nargout > 0) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/specfun/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/beta.m --- a/scripts/specfun/beta.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/beta.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,8 +43,8 @@ ## ## The Beta function can grow quite large and it is often more useful to work ## with the logarithm of the output rather than the function directly. -## @xref{XREFbetaln,,betaln}, for computing the logarithm of the Beta function -## in an efficient manner. +## @xref{XREFbetaln,,@code{betaln}}, for computing the logarithm of the Beta +## function in an efficient manner. ## @seealso{betaln, betainc, betaincinv} ## @end deftypefn @@ -88,9 +88,8 @@ %! assert (zeros (size (a)), beta (a, -a), tol); %! assert (zeros (size (a)), beta (-a, a), tol); -%!error beta () -%!error beta (1) -%!error beta (1,2,3) +%!error <Invalid call> beta () +%!error <Invalid call> beta (1) %!error <A and B must be real> beta (1i, 2) %!error <A and B must be real> beta (2, 1i) %!error <A and B must have consistent sizes> beta ([1 2], [1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/betainc.m --- a/scripts/specfun/betainc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/betainc.m Thu Nov 19 13:08:00 2020 -0800 @@ -9,7 +9,7 @@ ## ## Octave is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or +## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but @@ -74,7 +74,7 @@ function y = betainc (x, a, b, tail = "lower") - if (nargin < 3 || nargin > 4) + if (nargin < 3) print_usage (); endif @@ -205,12 +205,12 @@ %! y_ex = [0.999999999999989; 0.999999999999992; 0.999999999999995]; %! assert (y, y_ex, -1e-14); -%!assert (betainc (0.001, 20, 30), 2.750687665855991e-47, -3e-14); -%!assert (betainc (0.0001, 20, 30), 2.819953178893307e-67, -7e-14); -%!assert <*54383> (betainc (0.99, 20, 30, "upper"), 1.5671643161872703e-47, -7e-14); -%!assert (betainc (0.999, 20, 30, "upper"), 1.850806276141535e-77, -7e-14); -%!assert (betainc (0.5, 200, 300), 0.9999964565197356, -1e-15); -%!assert (betainc (0.5, 200, 300, "upper"), 3.54348026439253e-06, -3e-13); +%!assert (betainc (0.001, 20, 30), 2.750687665855991e-47, -3e-14) +%!assert (betainc (0.0001, 20, 30), 2.819953178893307e-67, -7e-14) +%!assert <*54383> (betainc (0.99, 20, 30, "upper"), 1.5671643161872703e-47, -7e-14) +%!assert (betainc (0.999, 20, 30, "upper"), 1.850806276141535e-77, -7e-14) +%!assert (betainc (0.5, 200, 300), 0.9999964565197356, -1e-15) +%!assert (betainc (0.5, 200, 300, "upper"), 3.54348026439253e-06, -3e-13) ## Test trivial values %!test @@ -223,10 +223,9 @@ %! assert (betainc (0.5, 1, Inf), NaN); ## Test input validation -%!error betainc () -%!error betainc (1) -%!error betainc (1,2) -%!error betainc (1,2,3,4,5) +%!error <Invalid call> betainc () +%!error <Invalid call> betainc (1) +%!error <Invalid call> betainc (1,2) %!error <must be of common size or scalars> betainc (ones (2,2), ones (1,2), 1) %!error <all inputs must be real> betainc (0.5i, 1, 2) %!error <all inputs must be real> betainc (0, 1i, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/betaincinv.m --- a/scripts/specfun/betaincinv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/betaincinv.m Thu Nov 19 13:08:00 2020 -0800 @@ -84,7 +84,7 @@ function x = betaincinv (y, a, b, tail = "lower") - if (nargin < 3 || nargin > 4) + if (nargin < 3) print_usage (); endif @@ -155,7 +155,7 @@ x(y == 0) = 1; x(y == 1) = 0; else - error ("betaincinv: invalid value for TAIL") + error ("betaincinv: invalid value for TAIL"); endif ## Special values have been already computed. @@ -207,6 +207,7 @@ ## subfunctions: Bisection and Newton Methods function xc = bisection_method (F, xl, xr, a, b, y, maxit) + F_l = F (xl, a, b, y); F_r = F (xr, a, b, y); for it = 1:maxit @@ -222,12 +223,14 @@ F_r(flag_r) = F_c(flag_r); F_l(flag_c) = F_r(flag_c) = 0; endfor + endfunction function x = newton_method (F, JF, x0, a, b, y, tol, maxit); + l = numel (y); res = -F (x0, a, b, y) ./ JF (x0, a, b); - todo = (abs(res) >= tol * abs (x0)); + todo = (abs (res) >= tol * abs (x0)); x = x0; it = 0; while (any (todo) && (it < maxit)) @@ -235,9 +238,10 @@ x(todo) += res(todo); res(todo) = -F(x(todo), a(todo), b(todo), y(todo)) ... ./ JF (x(todo), a(todo), b(todo)); - todo = (abs(res) >= tol * abs (x)); + todo = (abs (res) >= tol * abs (x)); endwhile x += res; + endfunction @@ -279,10 +283,9 @@ %!assert (class (betaincinv (single (0.5), int8 (1), 1)), "single") ## Test input validation -%!error betaincinv () -%!error betaincinv (1) -%!error betaincinv (1,2) -%!error betaincinv (1,2,3,4,5) +%!error <Invalid call> betaincinv () +%!error <Invalid call> betaincinv (1) +%!error <Invalid call> betaincinv (1,2) %!error <must be of common size or scalars> %! betaincinv (ones (2,2), ones (1,2), 1); %!error <all inputs must be real> betaincinv (0.5i, 1, 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/betaln.m --- a/scripts/specfun/betaln.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/betaln.m Thu Nov 19 13:08:00 2020 -0800 @@ -68,9 +68,8 @@ %!assert (betaln (3,4), log (beta (3,4)), eps) ## Test input validation -%!error betaln () -%!error betaln (1) -%!error betaln (1,2,3) +%!error <Invalid call> betaln () +%!error <Invalid call> betaln (1) %!error <A and B must be real> betaln (1i, 2) %!error <A and B must be real> betaln (2, 1i) %!error <A and B must have consistent sizes> betaln ([1 2], [1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/cosint.m --- a/scripts/specfun/cosint.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/cosint.m Thu Nov 19 13:08:00 2020 -0800 @@ -76,7 +76,7 @@ function y = cosint (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -96,7 +96,7 @@ x = complex (real (x)(:), imag (x)(:)); else x = x(:); - end + endif ## Initialize the result y = zeros (size (x), class (x)); @@ -106,7 +106,7 @@ ## Special values y(x == Inf) = 0; - y((x == -Inf) & !signbit (imag (x))) = 1i * pi; + y((x == -Inf) & ! signbit (imag (x))) = 1i * pi; y((x == -Inf) & signbit (imag (x))) = -1i * pi; todo(isinf (x)) = false; @@ -136,11 +136,11 @@ xx = complex (real (x)(todo), imag (x)(todo)); else xx = x(todo); - end + endif ssum = - xx .^ 2 / 4; # First term of the series expansion ## FIXME: This is way more precision than a double value can hold. gma = 0.57721566490153286060651209008; # Euler gamma constant - yy = gma + log (complex (xx)) + ssum; # log(complex(...) handles signed zero + yy = gma + log (complex (xx)) + ssum; # log (complex (...) handles signed zero flag_sum = true (nnz (todo), 1); it = 0; maxit = 300; @@ -161,7 +161,7 @@ endfunction -%!assert (cosint (1.1), 0.38487337742465081550, 2 * eps); +%!assert (cosint (1.1), 0.38487337742465081550, 2 * eps) %!test %! x = [2, 3, pi; exp(1), 5, 6]; @@ -267,6 +267,5 @@ %#!test <*52953> ## Test input validation -%!error cosint () -%!error cosint (1,2) +%!error <Invalid call> cosint () %!error <X must be numeric> cosint ("1") diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/ellipke.m --- a/scripts/specfun/ellipke.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/ellipke.m Thu Nov 19 13:08:00 2020 -0800 @@ -90,7 +90,7 @@ function [k, e] = ellipke (m, tol = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -219,8 +219,7 @@ %! assert (e, e_exp, 8*eps (e_exp)); ## Test input validation -%!error ellipke () -%!error ellipke (1,2,3) +%!error <Invalid call> ellipke () %!error <M must be real> ellipke (1i) %!error <M must be .= 1> ellipke (2) %!error <TOL must be a real scalar . 0> ellipke (1, i) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/expint.m --- a/scripts/specfun/expint.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/expint.m Thu Nov 19 13:08:00 2020 -0800 @@ -96,7 +96,7 @@ function E1 = expint (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -273,6 +273,5 @@ %!assert (! isreal (expint (-1))) ## Test input validation -%!error expint () -%!error expint (1,2) +%!error <Invalid call> expint () %!error <X must be numeric> expint ("1") diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/factor.m --- a/scripts/specfun/factor.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/factor.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,7 @@ function [pf, n] = factor (q) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -120,8 +120,7 @@ %! assert (n, double (3)); ## Test input validation -%!error factor () -%!error factor (1,2) +%!error <Invalid call> factor () %!error <Q must be a real non-negative integer> factor (6i) %!error <Q must be a real non-negative integer> factor ([1,2]) %!error <Q must be a real non-negative integer> factor (1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/factorial.m --- a/scripts/specfun/factorial.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/factorial.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function x = factorial (n) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! isreal (n) || any (n(:) < 0 | n(:) != fix (n(:)))) error ("factorial: all N must be real non-negative integers"); @@ -53,9 +53,9 @@ ## This doesn't seem particularly worth copying--for example uint8 would ## saturate for n > 5. If desired, however, the following code could be ## uncommented. - # if (! isfloat (x)) - # x = cast (x, class (n)); - # endif + ## if (! isfloat (x)) + ## x = cast (x, class (n)); + ## endif endfunction @@ -65,8 +65,7 @@ %!assert (factorial (70), exp (sum (log (1:70))), -128*eps) %!assert (factorial (0), 1) -%!error factorial () -%!error factorial (1,2) +%!error <Invalid call> factorial () %!error <must be real non-negative integers> factorial (2i) %!error <must be real non-negative integers> factorial (-3) %!error <must be real non-negative integers> factorial (5.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/gammainc.m --- a/scripts/specfun/gammainc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/gammainc.m Thu Nov 19 13:08:00 2020 -0800 @@ -9,7 +9,7 @@ ## ## Octave is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or +## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but @@ -95,7 +95,7 @@ function y = gammainc (x, a, tail = "lower") - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -299,6 +299,7 @@ ## a == 1. function y = gammainc_a1 (x, tail) + if (strcmp (tail, "lower")) if (abs (x) < 1/2) y = - expm1 (-x); @@ -316,12 +317,14 @@ else y = 1 ./ x; endif + endfunction ## positive integer a; exp (x) and a! both under 1/eps ## uses closed-form expressions for nonnegative integer a ## -- http://mathworld.wolfram.com/IncompleteGammaFunction.html. function y = gammainc_an (x, a, tail) + y = t = ones (size (x), class (x)); i = 1; while (any (a(:) > i)) @@ -339,12 +342,14 @@ elseif (strcmp (tail, "scaledupper")) y .*= exp (-x) ./ D(x, a); endif + endfunction ## x + 0.25 < a | x < 0 | abs(x) < 1. ## Numerical Recipes in Fortran 77 (6.2.5) ## series function y = gammainc_s (x, a, tail) + if (strcmp (tail, "scaledlower") || strcmp (tail, "scaledupper")) y = ones (size (x), class (x)); term = x ./ (a + 1); @@ -367,6 +372,7 @@ elseif (strcmp (tail, "scaledupper")) y = 1 ./ D (x,a) - y; endif + endfunction ## x positive and large relative to a @@ -375,6 +381,7 @@ ## Lentz's algorithm ## __gammainc__ in libinterp/corefcn/__gammainc__.cc function y = gammainc_l (x, a, tail) + y = __gammainc__ (x, a); if (strcmp (tail, "lower")) y = 1 - y .* D (x, a); @@ -383,6 +390,7 @@ elseif (strcmp (tail, "scaledlower")) y = 1 ./ D (x, a) - y; endif + endfunction ## Compute exp(-x)*x^a/Gamma(a+1) in a stable way for x and a large. @@ -391,6 +399,7 @@ ## SIAM J. Sci. Stat. Comput., 7(3), 1986 ## which quotes Section 5, Abramowitz&Stegun 6.1.40, 6.1.41. function y = D (x, a) + athresh = 10; # FIXME: can this be better tuned? y = zeros (size (x), class (x)); @@ -430,7 +439,7 @@ endif ii = (x < 0) & (a == fix (a)); - if (any(ii)) # remove spurious imaginary part. + if (any (ii)) # remove spurious imaginary part. y(ii) = real (y(ii)); endif @@ -478,9 +487,9 @@ %! -2.9582761911890713293e7-1i * 9.612022339061679758e6, -30*eps) %!assert (gammainc (-10, 10, "upper"), -3.112658165341493126871616e7, ... %! -2*eps) -%!assert (gammainc (-10, 10, "scaledlower"), 0.5128019364747265, -1e-14); -%!assert (gammainc (-10, 10, "scaledupper"), -0.5128019200000000, -1e-14); -%!assert (gammainc (200, 201, "upper"), 0.518794309678684497, -2 * eps); +%!assert (gammainc (-10, 10, "scaledlower"), 0.5128019364747265, -1e-14) +%!assert (gammainc (-10, 10, "scaledupper"), -0.5128019200000000, -1e-14) +%!assert (gammainc (200, 201, "upper"), 0.518794309678684497, -2 * eps) %!assert (gammainc (200, 201, "scaledupper"), %! 18.4904360746560462660798514, -eps) ## Here we are very good (no D (x,a)) involved @@ -566,9 +575,8 @@ %!assert (class (gammainc (1, int8 (0.5))) == "double") ## Test input validation -%!error gammainc () -%!error gammainc (1) -%!error gammainc (1,2,3,4) +%!error <Invalid call> gammainc () +%!error <Invalid call> gammainc (1) %!error <must be of common size or scalars> gammainc ([0, 0],[0; 0]) %!error <must be of common size or scalars> gammainc ([1 2 3], [1 2]) %!error <all inputs must be real> gammainc (2+i, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/gammaincinv.m --- a/scripts/specfun/gammaincinv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/gammaincinv.m Thu Nov 19 13:08:00 2020 -0800 @@ -9,7 +9,7 @@ ## ## Octave is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or +## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but @@ -87,7 +87,7 @@ function x = gammaincinv (y, a, tail = "lower") - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -148,7 +148,7 @@ q = y; p = 1 - q; else - error ("gammaincinv: invalid value for TAIL") + error ("gammaincinv: invalid value for TAIL"); endif todo = (a != 1) & (y != 0) & (y != 1); @@ -256,6 +256,7 @@ ## subfunction: Newton's Method function x = newton_method (F, JF, y, a, x0, tol, maxit); + l = numel (y); res = -F (y, a, x0) ./ JF (a, x0); todo = (abs (res) >= tol * abs (x0)); @@ -267,6 +268,7 @@ todo = (abs (res) >= tol * abs (x)); endwhile x += res; + endfunction @@ -312,9 +314,8 @@ %!assert (class (gammaincinv (single (0.5), int8 (1))), "single") ## Test input validation -%!error gammaincinv () -%!error gammaincinv (1) -%!error gammaincinv (1, 2, 3, 4) +%!error <Invalid call> gammaincinv () +%!error <Invalid call> gammaincinv (1) %!error <must be of common size or scalars> %! gammaincinv (ones (2,2), ones (1,2), 1); %!error <all inputs must be real> gammaincinv (0.5i, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/isprime.m --- a/scripts/specfun/isprime.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/isprime.m Thu Nov 19 13:08:00 2020 -0800 @@ -69,7 +69,7 @@ function t = isprime (x) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (any (fix (x) != x)) error ("isprime: X contains non-integer entries"); @@ -173,7 +173,6 @@ %!assert (isprime (magic (3)), logical ([0, 0, 0; 1, 1, 1; 0, 0, 1])) ## Test input validation -%!error isprime () -%!error isprime (1, 2) +%!error <Invalid call> isprime () %!error <X contains non-integer entries> isprime (0.5i) %!error <X contains non-integer entries> isprime (0.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/lcm.m --- a/scripts/specfun/lcm.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/lcm.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,7 +58,8 @@ %!assert (lcm (3, 5, 7, 15), 105) -%!error lcm () -%!error lcm (1) +## Test input validation +%!error <Invalid call> lcm () +%!error <Invalid call> lcm (1) %!error <same size or scalar> lcm ([1 2], [1 2 3]) %!error <arguments must be numeric> lcm ([1 2], {1 2}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/legendre.m --- a/scripts/specfun/legendre.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/legendre.m Thu Nov 19 13:08:00 2020 -0800 @@ -167,7 +167,7 @@ persistent warned_overflow = false; - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -311,9 +311,8 @@ %! assert (result, expected); ## Test input validation -%!error legendre () -%!error legendre (1) -%!error legendre (1,2,3,4) +%!error <Invalid call> legendre () +%!error <Invalid call> legendre (1) %!error <must be a real non-negative integer> legendre (i, [-1, 0, 1]) %!error <must be a real non-negative integer> legendre ([1, 2], [-1, 0, 1]) %!error <must be a real non-negative integer> legendre (-1, [-1, 0, 1]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/module.mk --- a/scripts/specfun/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/beta.m \ %reldir%/betainc.m \ %reldir%/betaincinv.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/nchoosek.m --- a/scripts/specfun/nchoosek.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/nchoosek.m Thu Nov 19 13:08:00 2020 -0800 @@ -149,9 +149,8 @@ %!assert (size (nchoosek (1:5,0)), [1 0]) ## Test input validation -%!error nchoosek () -%!error nchoosek (1) -%!error nchoosek (1,2,3) +%!error <Invalid call> nchoosek () +%!error <Invalid call> nchoosek (1) %!error nchoosek (100, 2i) %!error nchoosek (100, [2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/nthroot.m --- a/scripts/specfun/nthroot.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/nthroot.m Thu Nov 19 13:08:00 2020 -0800 @@ -106,9 +106,8 @@ %! assert (lastwarn (), warnmsg); ## Test input validation -%!error nthroot () -%!error nthroot (1) -%!error nthroot (1,2,3) +%!error <Invalid call> nthroot () +%!error <Invalid call> nthroot (1) %!error <X must not contain complex values> nthroot (1+j, 2) %!error <N must be a real nonzero scalar> nthroot (1, i) %!error <N must be a real nonzero scalar> nthroot (1, [1 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/perms.m --- a/scripts/specfun/perms.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/perms.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,7 +58,7 @@ function A = perms (v) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -123,8 +123,7 @@ %!assert (unique (perms (1:5)(:))', 1:5) %!assert (perms (int8 (1:4)), int8 (perms (1:4))) -%!error perms () -%!error perms (1, 2) +%!error <Invalid call> perms () ## Should work for any array type, such as cells and structs, and not ## only for numeric data. @@ -161,5 +160,5 @@ %!test <*52432> %! s = struct (); %! s(1) = []; -%! assert (perms (reshape (s, 0, 0)), reshape (s, 1, 0)) -%! assert (perms (reshape (s, 0, 1)), reshape (s, 1, 0)) +%! assert (perms (reshape (s, 0, 0)), reshape (s, 1, 0)); +%! assert (perms (reshape (s, 0, 1)), reshape (s, 1, 0)); diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/pow2.m --- a/scripts/specfun/pow2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/pow2.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,12 +47,14 @@ function y = pow2 (f, e) + if (nargin < 1) + print_usage (); + endif + if (nargin == 1) y = 2 .^ f; - elseif (nargin == 2) + else y = f .* (2 .^ e); - else - print_usage (); endif endfunction @@ -69,5 +71,4 @@ %! z = x .* (2 .^ y); %! assert (pow2 (x,y), z, sqrt (eps)); -%!error pow2 () -%!error pow2 (1,2,3) +%!error <Invalid call> pow2 () diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/primes.m --- a/scripts/specfun/primes.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/primes.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ function p = primes (n) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -108,7 +108,6 @@ %!assert (class (primes (single (10))), "single") %!assert (class (primes (uint8 (10))), "uint8") -%!error primes () -%!error primes (1, 2) +%!error <Invalid call> primes () %!error <N must be a numeric scalar> primes ("1") %!error <N must be a numeric scalar> primes (ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/reallog.m --- a/scripts/specfun/reallog.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/reallog.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function y = reallog (x) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (iscomplex (x) || any (x(:) < 0)) error ("reallog: produced complex result"); @@ -50,7 +50,6 @@ %! x = rand (10, 10); %! assert (reallog (x), log (x)); -%!error reallog () -%!error reallog (1,2) +%!error <Invalid call> reallog () %!error <produced complex result> reallog (2i) %!error <produced complex result> reallog (-1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/realpow.m --- a/scripts/specfun/realpow.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/realpow.m Thu Nov 19 13:08:00 2020 -0800 @@ -54,7 +54,6 @@ %! assert (x.^y, realpow (x,y)); %!assert <47775> (realpow (1i,2), -1) -%!error realpow () -%!error realpow (1) -%!error realpow (1,2,3) +%!error <Invalid call> realpow () +%!error <Invalid call> realpow (1) %!error <produced complex result> realpow (-1, 1/2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/realsqrt.m --- a/scripts/specfun/realsqrt.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/realsqrt.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function y = realsqrt (x) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (iscomplex (x) || any (x(:) < 0)) error ("realsqrt: produced complex result"); @@ -50,6 +50,5 @@ %! x = rand (10, 10); %! assert (realsqrt (x), sqrt (x)); -%!error realsqrt () -%!error realsqrt (1,2) +%!error <Invalid call> realsqrt () %!error <produced complex result> realsqrt (-1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/specfun/sinint.m --- a/scripts/specfun/sinint.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/specfun/sinint.m Thu Nov 19 13:08:00 2020 -0800 @@ -54,7 +54,7 @@ function y = sinint (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -75,7 +75,7 @@ x = complex (real (x)(:), imag (x)(:)); else x = x(:); - end + endif ## Initialize the result y = zeros (size (x), class (x)); @@ -202,14 +202,13 @@ %! -0.000099999999944461111128 + 0.99999999833338888972e-6*1i %! -1.5386156269726011209 - 0.053969388020443786229*1i ]; %! B = sinint (x); -%! assert (A, B, -3*eps) +%! assert (A, B, -3*eps); %! B = sinint (single (x)); -%! assert (A, B, -3*eps ("single")) +%! assert (A, B, -3*eps ("single")); ## FIXME: Need a test for bug #52953 %#!test <*52953> ## Test input validation -%!error sinint () -%!error sinint (1,2) +%!error <Invalid call> sinint () %!error <X must be numeric> sinint ("1") diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/special-matrix/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/gallery.m --- a/scripts/special-matrix/gallery.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/gallery.m Thu Nov 19 13:08:00 2020 -0800 @@ -413,12 +413,12 @@ ## uniformdata) by Nicholas J. Higham <Nicholas.J.Higham@manchester.ac.uk> ## Adapted for Octave and into single gallery function by Carnë Draug -function [varargout] = gallery (name, varargin) +function varargout = gallery (name, varargin) if (nargin < 1) print_usage (); elseif (! ischar (name)) - error ("gallery: NAME must be a string."); + error ("gallery: NAME must be a string"); endif ## NOTE: there isn't a lot of input check in the individual functions @@ -439,7 +439,7 @@ switch (tolower (name)) case "binomial" - error ("gallery: matrix %s not implemented.", name); + error ("gallery: matrix %s not implemented", name); case "cauchy" , [varargout{1:n_out}] = cauchy (varargin{:}); case "chebspec" , [varargout{1:n_out}] = chebspec (varargin{:}); case "chebvand" , [varargout{1:n_out}] = chebvand (varargin{:}); @@ -470,7 +470,7 @@ case "lauchli" , [varargout{1:n_out}] = lauchli (varargin{:}); case "lehmer" , [varargout{1:n_out}] = lehmer (varargin{:}); case "leslie" - error ("gallery: matrix %s not implemented.", name); + error ("gallery: matrix %s not implemented", name); case "lesp" , [varargout{1:n_out}] = lesp (varargin{:}); case "lotkin" , [varargout{1:n_out}] = lotkin (varargin{:}); case "minij" , [varargout{1:n_out}] = minij (varargin{:}); @@ -483,19 +483,19 @@ case "poisson" , [varargout{1:n_out}] = poisson (varargin{:}); case "prolate" , [varargout{1:n_out}] = prolate (varargin{:}); case "randcolu" - error ("gallery: matrix %s not implemented.", name); + error ("gallery: matrix %s not implemented", name); case "randcorr" - error ("gallery: matrix %s not implemented.", name); + error ("gallery: matrix %s not implemented", name); case "randhess" , [varargout{1:n_out}] = randhess (varargin{:}); case "randjorth" - error ("gallery: matrix %s not implemented.", name); + error ("gallery: matrix %s not implemented", name); case "rando" , [varargout{1:n_out}] = rando (varargin{:}); case "randsvd" , [varargout{1:n_out}] = randsvd (varargin{:}); case "redheff" , [varargout{1:n_out}] = redheff (varargin{:}); case "riemann" , [varargout{1:n_out}] = riemann (varargin{:}); case "ris" , [varargout{1:n_out}] = ris (varargin{:}); case "sampling" - error ("gallery: matrix %s not implemented.", name); + error ("gallery: matrix %s not implemented", name); case "smoke" , [varargout{1:n_out}] = smoke (varargin{:}); case "toeppd" , [varargout{1:n_out}] = toeppd (varargin{:}); case "toeppen" , [varargout{1:n_out}] = toeppen (varargin{:}); @@ -534,11 +534,11 @@ ## pp. 279-313, 1962. (States the totally positive property on p. 295.) if (nargin < 1 || nargin > 2) - error ("gallery: 1 or 2 arguments are required for cauchy matrix."); + error ("gallery: 1 or 2 arguments are required for cauchy matrix"); elseif (! isnumeric (x)) - error ("gallery: X must be numeric for cauchy matrix."); + error ("gallery: X must be numeric for cauchy matrix"); elseif (nargin == 2 && ! isnumeric (y)) - error ("gallery: Y must be numeric for cauchy matrix."); + error ("gallery: Y must be numeric for cauchy matrix"); endif n = numel (x); @@ -548,7 +548,7 @@ elseif (n > 1 && isvector (x)) ## do nothing else - error ("gallery: X be an integer or a vector for cauchy matrix."); + error ("gallery: X be an integer or a vector for cauchy matrix"); endif if (nargin == 1) @@ -559,7 +559,7 @@ x = x(:); y = y(:); if (numel (x) != numel (y)) - error ("gallery: X and Y must be vectors of same length for cauchy matrix."); + error ("gallery: X and Y must be vectors of same length for cauchy matrix"); endif C = 1 ./ (x .+ y.'); @@ -586,11 +586,11 @@ ## derivative, SIAM J. Sci. Stat. Comput., 9 (1988), pp. 1050-1057. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for chebspec matrix."); + error ("gallery: 1 to 2 arguments are required for chebspec matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for chebspec matrix."); + error ("gallery: N must be an integer for chebspec matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a scalar for chebspec matrix."); + error ("gallery: K must be a scalar for chebspec matrix"); endif ## k = 1 case obtained from k = 0 case with one bigger n. @@ -598,7 +598,7 @@ case (0), # do nothing case (1), n = n + 1; otherwise - error ("gallery: K should be either 0 or 1 for chebspec matrix."); + error ("gallery: K should be either 0 or 1 for chebspec matrix"); endswitch n -= 1; @@ -648,7 +648,7 @@ ## pp. 23-41. if (nargin < 1 || nargin > 2) - error ("gallery: 1 or 2 arguments are required for chebvand matrix."); + error ("gallery: 1 or 2 arguments are required for chebvand matrix"); endif ## because the order of the arguments changes if nargin is 1 or 2 ... @@ -659,7 +659,7 @@ n = numel (p); if (! isnumeric (p)) - error ("gallery: P must be numeric for chebvand matrix."); + error ("gallery: P must be numeric for chebvand matrix"); elseif (isscalar (p) && fix (p) == p) n = p; p = linspace (0, 1, n); @@ -671,7 +671,7 @@ if (nargin == 1) m = n; elseif (! isnumeric (m) || ! isscalar (m)) - error ("gallery: M must be a scalar for chebvand matrix."); + error ("gallery: M must be a scalar for chebvand matrix"); endif C = ones (m, n); @@ -699,13 +699,13 @@ ## Hessenberg matrices, SIAM Review, 13 (1971), pp. 220-221. if (nargin < 1 || nargin > 3) - error ("gallery: 1 to 3 arguments are required for chow matrix."); + error ("gallery: 1 to 3 arguments are required for chow matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for chow matrix."); + error ("gallery: N must be an integer for chow matrix"); elseif (! isnumeric (alpha) || ! isscalar (alpha)) - error ("gallery: ALPHA must be a scalar for chow matrix."); + error ("gallery: ALPHA must be a scalar for chow matrix"); elseif (! isnumeric (delta) || ! isscalar (delta)) - error ("gallery: DELTA must be a scalar for chow matrix."); + error ("gallery: DELTA must be a scalar for chow matrix"); endif A = toeplitz (alpha.^(1:n), [alpha 1 zeros(1, n-2)]) + delta * eye (n); @@ -727,9 +727,9 @@ ## P.J. Davis, Circulant Matrices, John Wiley, 1977. if (nargin != 1) - error ("gallery: 1 argument is required for circul matrix."); + error ("gallery: 1 argument is required for circul matrix"); elseif (! isnumeric (v)) - error ("gallery: V must be numeric for circul matrix."); + error ("gallery: V must be numeric for circul matrix"); endif n = numel (v); @@ -739,7 +739,7 @@ elseif (n > 1 && isvector (v)) ## do nothing else - error ("gallery: X must be a scalar or a vector for circul matrix."); + error ("gallery: X must be a scalar or a vector for circul matrix"); endif v = v(:).'; # Make sure v is a row vector @@ -772,11 +772,11 @@ ## Linear Algebra and Appl., 150 (1991), pp. 341-360. if (nargin < 1 || nargin > 2) - error ("gallery: 1 or 2 arguments are required for clement matrix."); + error ("gallery: 1 or 2 arguments are required for clement matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for clement matrix."); + error ("gallery: N must be an integer for clement matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for clement matrix."); + error ("gallery: K must be a numeric scalar for clement matrix"); endif n -= 1; @@ -789,7 +789,7 @@ y = sqrt (x.*z); A = diag (y, -1) + diag (y, 1); else - error ("gallery: K must have a value of 0 or 1 for clement matrix."); + error ("gallery: K must have a value of 0 or 1 for clement matrix"); endif endfunction @@ -808,11 +808,11 @@ ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. if (nargin < 1 || nargin > 2) - error ("gallery: 1 or 2 arguments are required for compar matrix."); + error ("gallery: 1 or 2 arguments are required for compar matrix"); elseif (! isnumeric (A) || ndims (A) != 2) - error ("gallery: A must be a 2-D matrix for compar matrix."); + error ("gallery: A must be a 2-D matrix for compar matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for compar matrix."); + error ("gallery: K must be a numeric scalar for compar matrix"); endif [m, n] = size (A); @@ -840,7 +840,7 @@ if (all (A == triu (A))), C = triu (C); endif else - error ("gallery: K must have a value of 0 or 1 for compar matrix."); + error ("gallery: K must have a value of 0 or 1 for compar matrix"); endif endfunction @@ -869,13 +869,13 @@ ## (Algorithm 674), ACM Trans. Math. Soft., 14 (1988), pp. 381-396. if (nargin < 1 || nargin > 3) - error ("gallery: 1 to 3 arguments are required for condex matrix."); + error ("gallery: 1 to 3 arguments are required for condex matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for condex matrix."); + error ("gallery: N must be an integer for condex matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for condex matrix."); + error ("gallery: K must be a numeric scalar for condex matrix"); elseif (! isnumeric (theta) || ! isscalar (theta)) - error ("gallery: THETA must be a numeric scalar for condex matrix."); + error ("gallery: THETA must be a numeric scalar for condex matrix"); endif if (k == 1) # Cline and Rew (1983), Example B. @@ -905,7 +905,7 @@ A = eye (n) + theta*P; else - error ("gallery: unknown estimator K '%d' for condex matrix.", k); + error ("gallery: unknown estimator K '%d' for condex matrix", k); endif ## Pad out with identity as necessary. @@ -929,11 +929,11 @@ ## elimination: see NA Digest Volume 89, Issue 3 (January 22, 1989). if (nargin < 1 || nargin > 2) - error ("gallery: 1 or 2 arguments are required for cycol matrix."); + error ("gallery: 1 or 2 arguments are required for cycol matrix"); elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) - error ("gallery: N must be a 1 or 2 element integer for cycol matrix."); + error ("gallery: N must be a 1 or 2 element integer for cycol matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a scalar for cycol matrix."); + error ("gallery: K must be a scalar for cycol matrix"); endif ## Parameter n specifies dimension: m-by-n @@ -964,11 +964,11 @@ ## pp. 271-283. if (nargin < 1 || nargin > 2) - error ("gallery: 1 or 2 arguments are required for dorr matrix."); + error ("gallery: 1 or 2 arguments are required for dorr matrix"); elseif (! isscalar (n) || ! isnumeric (n) || fix (n) != n) - error ("gallery: N must be an integer for dorr matrix."); + error ("gallery: N must be an integer for dorr matrix"); elseif (! isscalar (theta) || ! isnumeric (theta)) - error ("gallery: THETA must be a numeric scalar for dorr matrix."); + error ("gallery: THETA must be a numeric scalar for dorr matrix"); endif c = zeros (n, 1); @@ -1023,11 +1023,11 @@ ## (0,1) matrix, Linear Algebra and Appl., 183 (1993), pp. 147-153. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for dramadah matrix."); + error ("gallery: 1 to 2 arguments are required for dramadah matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for dramadah matrix."); + error ("gallery: N must be an integer for dramadah matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for dramadah matrix."); + error ("gallery: K must be a numeric scalar for dramadah matrix"); endif switch (k) @@ -1061,7 +1061,7 @@ A = toeplitz (c, [1 1 zeros(1,n-2)]); otherwise - error ("gallery: unknown K '%d' for dramadah matrix.", k); + error ("gallery: unknown K '%d' for dramadah matrix", k); endswitch endfunction @@ -1087,9 +1087,9 @@ ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 159. if (nargin != 1) - error ("gallery: 1 argument is required for fiedler matrix."); + error ("gallery: 1 argument is required for fiedler matrix"); elseif (! isnumeric (c)) - error ("gallery: C must be numeric for fiedler matrix."); + error ("gallery: C must be numeric for fiedler matrix"); endif n = numel (c); @@ -1099,7 +1099,7 @@ elseif (n > 1 && isvector (c)) ## do nothing else - error ("gallery: C must be an integer or a vector for fiedler matrix."); + error ("gallery: C must be an integer or a vector for fiedler matrix"); endif c = c(:).'; # Ensure c is a row vector. @@ -1115,13 +1115,13 @@ ## ALPHA defaults to SQRT(EPS) and LAMBDA to 0. if (nargin < 1 || nargin > 3) - error ("gallery: 1 to 3 arguments are required for forsythe matrix."); + error ("gallery: 1 to 3 arguments are required for forsythe matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for forsythe matrix."); + error ("gallery: N must be an integer for forsythe matrix"); elseif (! isnumeric (alpha) || ! isscalar (alpha)) - error ("gallery: ALPHA must be a numeric scalar for forsythe matrix."); + error ("gallery: ALPHA must be a numeric scalar for forsythe matrix"); elseif (! isnumeric (lambda) || ! isscalar (lambda)) - error ("gallery: LAMBDA must be a numeric scalar for forsythe matrix."); + error ("gallery: LAMBDA must be a numeric scalar for forsythe matrix"); endif A = jordbloc (n, lambda); @@ -1167,11 +1167,11 @@ ## Comput., 7 (1986), pp. 835-839. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for frank matrix."); + error ("gallery: 1 to 2 arguments are required for frank matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for frank matrix."); + error ("gallery: N must be an integer for frank matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for frank matrix."); + error ("gallery: K must be a numeric scalar for frank matrix"); endif p = n:-1:1; @@ -1181,15 +1181,15 @@ case (0), # do nothing case (1), F = F(p,p)'; otherwise - error ("gallery: K must have a value of 0 or 1 for frank matrix."); + error ("gallery: K must have a value of 0 or 1 for frank matrix"); endswitch endfunction function c = gcdmat (n) if (nargin != 1) - error ("gallery: 1 argument is required for gcdmat matrix."); + error ("gallery: 1 argument is required for gcdmat matrix"); elseif (! isscalar (n) || ! isnumeric (n) || fix (n) != n) - error ("gallery: N must be an integer for gcdmat matrix."); + error ("gallery: N must be an integer for gcdmat matrix"); endif c = gcd (repmat ((1:n)', [1 n]), repmat (1:n, [n 1])); endfunction @@ -1213,13 +1213,13 @@ ## Math. Comp., 23 (1969), pp. 119-125. if (nargin < 1 || nargin > 3) - error ("gallery: 1 to 3 arguments are required for gearmat matrix."); + error ("gallery: 1 to 3 arguments are required for gearmat matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for gearmat matrix."); + error ("gallery: N must be an integer for gearmat matrix"); elseif (! isnumeric (i) || ! isscalar (i) || i == 0 || abs (i) > n) - error ("gallery: I must be a nonzero scalar, and abs (I) <= N for gearmat matrix."); + error ("gallery: I must be a nonzero scalar, and abs (I) <= N for gearmat matrix"); elseif (! isnumeric (j) || ! isscalar (j) || i == 0 || abs (j) > n) - error ("gallery: J must be a nonzero scalar, and abs (J) <= N for gearmat matrix."); + error ("gallery: J must be a nonzero scalar, and abs (J) <= N for gearmat matrix"); endif A = diag (ones (n-1, 1), -1) + diag (ones (n-1, 1), 1); @@ -1243,11 +1243,11 @@ ## Appl., 13 (1992), pp. 796-825. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for grcar matrix."); + error ("gallery: 1 to 2 arguments are required for grcar matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for grcar matrix."); + error ("gallery: N must be an integer for grcar matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for grcar matrix."); + error ("gallery: K must be a numeric scalar for grcar matrix"); endif G = tril (triu (ones (n)), k) - diag (ones (n-1, 1), -1); @@ -1267,13 +1267,13 @@ ## Berlin, 1987. (pp. 86-87) if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for hanowa matrix."); + error ("gallery: 1 to 2 arguments are required for hanowa matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for hanowa matrix."); + error ("gallery: N must be an integer for hanowa matrix"); elseif (rem (n, 2) != 0) - error ("gallery: N must be even for hanowa matrix."); + error ("gallery: N must be even for hanowa matrix"); elseif (! isnumeric (d) || ! isscalar (d)) - error ("gallery: D must be a numeric scalar for hanowa matrix."); + error ("gallery: D must be a numeric scalar for hanowa matrix"); endif m = n/2; @@ -1307,9 +1307,9 @@ ## Press, 1965. if (nargin != 1) - error ("gallery: 1 argument is required for house matrix."); + error ("gallery: 1 argument is required for house matrix"); elseif (! isnumeric (x) || ! isvector (x)) - error ("gallery: X must be a vector for house matrix."); + error ("gallery: X must be a vector for house matrix"); endif ## must be a column vector @@ -1331,7 +1331,7 @@ function A = integerdata (varargin) if (nargin < 3) - error ("gallery: At least 3 arguments required for integerdata matrix."); + error ("gallery: At least 3 arguments required for integerdata matrix"); endif if (isnumeric (varargin{end})) @@ -1394,9 +1394,9 @@ ## Operator Theory, 10 (1987), pp. 82-95. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for invhess matrix."); + error ("gallery: 1 to 2 arguments are required for invhess matrix"); elseif (! isnumeric (x)) - error ("gallery: X must be numeric for invhess matrix."); + error ("gallery: X must be numeric for invhess matrix"); endif if (isscalar (x) && fix (x) == x) @@ -1405,13 +1405,13 @@ elseif (! isscalar (x) && isvector (x)) n = numel (x); else - error ("gallery: X must be an integer scalar, or a vector for invhess matrix."); + error ("gallery: X must be an integer scalar, or a vector for invhess matrix"); endif if (nargin < 2) y = -x(1:end-1); elseif (! isvector (y) || numel (y) != numel (x) -1) - error ("gallery: Y must be a vector of length -1 than X for invhess matrix."); + error ("gallery: Y must be a vector of length -1 than X for invhess matrix"); endif x = x(:); @@ -1436,10 +1436,10 @@ ## of involutory and of idempotent matrices, Numer. Math. 5 (1963), ## pp. 234-237. - if (nargin != 1) - error ("gallery: 1 argument is required for invol matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for invol matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for invol matrix."); + error ("gallery: N must be an integer for invol matrix"); endif A = hilb (n); @@ -1470,11 +1470,11 @@ ## Dept. of Mathematics, University of Bradford, 1993. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for ipjfact matrix."); + error ("gallery: 1 to 2 arguments are required for ipjfact matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for ipjfact matrix."); + error ("gallery: N must be an integer for ipjfact matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for ipjfact matrix."); + error ("gallery: K must be a numeric scalar for ipjfact matrix"); endif c = cumprod (2:n+1); @@ -1486,7 +1486,7 @@ case (0), # do nothing case (1), A = ones (n) ./ A; otherwise - error ("gallery: K must have a value of 0 or 1 for ipjfact matrix."); + error ("gallery: K must have a value of 0 or 1 for ipjfact matrix"); endswitch if (nargout == 2) @@ -1507,7 +1507,7 @@ endif else - error ("gallery: K must have a value of 0 or 1 for ipjfact matrix."); + error ("gallery: K must have a value of 0 or 1 for ipjfact matrix"); endif detA = d; @@ -1520,11 +1520,11 @@ ## LAMBDA. LAMBDA = 1 is the default. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for jordbloc matrix."); + error ("gallery: 1 to 2 arguments are required for jordbloc matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for jordbloc matrix."); + error ("gallery: N must be an integer for jordbloc matrix"); elseif (! isnumeric (lambda) || ! isscalar (lambda)) - error ("gallery: LAMBDA must be a numeric scalar for jordbloc matrix."); + error ("gallery: LAMBDA must be a numeric scalar for jordbloc matrix"); endif J = lambda * eye (n) + diag (ones (n-1, 1), 1); @@ -1558,13 +1558,13 @@ ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. if (nargin < 1 || nargin > 3) - error ("gallery: 1 to 3 arguments are required for kahan matrix."); + error ("gallery: 1 to 3 arguments are required for kahan matrix"); elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) - error ("gallery: N must be a 1 or 2 element integer for kahan matrix."); + error ("gallery: N must be a 1 or 2 element integer for kahan matrix"); elseif (! isnumeric (theta) || ! isscalar (theta)) - error ("gallery: THETA must be a numeric scalar for kahan matrix."); + error ("gallery: THETA must be a numeric scalar for kahan matrix"); elseif (! isnumeric (pert) || ! isscalar (pert)) - error ("gallery: PERT must be a numeric scalar for kahan matrix."); + error ("gallery: PERT must be a numeric scalar for kahan matrix"); endif ## Parameter n specifies dimension: r-by-n @@ -1603,11 +1603,11 @@ ## 10 (1989), pp. 135-146 (and see the references therein). if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for lauchli matrix."); + error ("gallery: 1 to 2 arguments are required for lauchli matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for lauchli matrix."); + error ("gallery: N must be an integer for lauchli matrix"); elseif (! isscalar (rho)) - error ("gallery: RHO must be a scalar for lauchli matrix."); + error ("gallery: RHO must be a scalar for lauchli matrix"); endif A = (1:n)'*ones (1,n); @@ -1631,9 +1631,9 @@ ## Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369. if (nargin < 1 || nargin > 3) - error ("gallery: 1 to 3 arguments are required for krylov matrix."); + error ("gallery: 1 to 3 arguments are required for krylov matrix"); elseif (! isnumeric (A) || ! issquare (A) || ndims (A) != 2) - error ("gallery: A must be a square 2-D matrix for krylov matrix."); + error ("gallery: A must be a square 2-D matrix for krylov matrix"); endif n = length (A); @@ -1645,13 +1645,13 @@ if (nargin < 2) x = ones (n, 1); elseif (! isvector (x) || numel (x) != n) - error ("gallery: X must be a vector of length equal to A for krylov matrix."); + error ("gallery: X must be a vector of length equal to A for krylov matrix"); endif if (nargin < 3) j = n; elseif (! isnumeric (j) || ! isscalar (j) || fix (j) != j) - error ("gallery: J must be an integer for krylov matrix."); + error ("gallery: J must be an integer for krylov matrix"); endif B = ones (n, j); @@ -1673,11 +1673,11 @@ ## kleinsten Quadraten, Numer. Math, 3 (1961), pp. 226-240. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for lauchli matrix."); + error ("gallery: 1 to 2 arguments are required for lauchli matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for lauchli matrix."); + error ("gallery: N must be an integer for lauchli matrix"); elseif (! isscalar (mu)) - error ("gallery: MU must be a scalar for lauchli matrix."); + error ("gallery: MU must be a scalar for lauchli matrix"); endif A = [ones(1, n) @@ -1700,10 +1700,10 @@ ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 154. - if (nargin != 1) - error ("gallery: 1 argument is required for lehmer matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for lehmer matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for lehmer matrix."); + error ("gallery: N must be an integer for lehmer matrix"); endif A = ones (n, 1) * (1:n); @@ -1731,10 +1731,10 @@ ## Mathematics, volume 260, Longman Scientific and Technical, Essex, ## UK, 1992, pp. 234-266. - if (nargin != 1) - error ("gallery: 1 argument is required for lesp matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for lesp matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for lesp matrix."); + error ("gallery: N must be an integer for lesp matrix"); endif x = 2:n; @@ -1751,10 +1751,10 @@ ## Reference: ## M. Lotkin, A set of test matrices, MTAC, 9 (1955), pp. 153-161. - if (nargin != 1) - error ("gallery: 1 argument is required for lotkin matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for lotkin matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for lotkin matrix."); + error ("gallery: N must be an integer for lotkin matrix"); endif A = hilb (n); @@ -1779,10 +1779,10 @@ ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241. ## (For the eigenvalues of Givens' matrix.) - if (nargin != 1) - error ("gallery: 1 argument is required for minij matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for minij matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for minij matrix."); + error ("gallery: N must be an integer for minij matrix"); endif A = bsxfun (@min, 1:n, (1:n)'); @@ -1803,11 +1803,11 @@ ## Bristol, 1990 (Appendix 1). if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for moler matrix."); + error ("gallery: 1 to 2 arguments are required for moler matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for moler matrix."); + error ("gallery: N must be an integer for moler matrix"); elseif (! isscalar (alpha)) - error ("gallery: ALPHA must be a scalar for moler matrix."); + error ("gallery: ALPHA must be a scalar for moler matrix"); endif A = triw (n, alpha)' * triw (n, alpha); @@ -1826,16 +1826,16 @@ ## R.J. Plemmons, Regular splittings and the discrete Neumann ## problem, Numer. Math., 25 (1976), pp. 153-161. - if (nargin != 1) - error ("gallery: 1 argument is required for neumann matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for neumann matrix"); elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) - error ("gallery: N must be a 1 or 2 element integer for neumann matrix."); + error ("gallery: N must be a 1 or 2 element integer for neumann matrix"); endif if (isscalar (n)) m = sqrt (n); if (m^2 != n) - error ("gallery: N must be a perfect square for neumann matrix."); + error ("gallery: N must be a perfect square for neumann matrix"); endif n(1) = m; n(2) = m; @@ -1851,7 +1851,7 @@ function A = normaldata (varargin) if (nargin < 2) - error ("gallery: At least 2 arguments required for normaldata matrix."); + error ("gallery: At least 2 arguments required for normaldata matrix"); endif if (isnumeric (varargin{end})) jidx = varargin{end}; @@ -1924,11 +1924,11 @@ ## pp. 500-507. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for orthog matrix."); + error ("gallery: 1 to 2 arguments are required for orthog matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for orthog matrix."); + error ("gallery: N must be an integer for orthog matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for orthog matrix."); + error ("gallery: K must be a numeric scalar for orthog matrix"); endif switch (k) @@ -1971,7 +1971,7 @@ Q = cos (m); otherwise - error ("gallery: unknown K '%d' for orthog matrix.", k); + error ("gallery: unknown K '%d' for orthog matrix", k); endswitch endfunction @@ -1992,10 +1992,10 @@ ## E.E. Tyrtyshnikov, Cauchy-Toeplitz matrices and some applications, ## Linear Algebra and Appl., 149 (1991), pp. 1-18. - if (nargin != 1) - error ("gallery: 1 argument is required for parter matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for parter matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for parter matrix."); + error ("gallery: N must be an integer for parter matrix"); endif A = cauchy ((1:n) + 0.5, -(1:n)); @@ -2013,11 +2013,11 @@ ## Comm. ACM, 5 (1962), p. 508. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for pei matrix."); + error ("gallery: 1 to 2 arguments are required for pei matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for pei matrix."); + error ("gallery: N must be an integer for pei matrix"); elseif (! isnumeric (alpha) || ! isscalar (alpha)) - error ("gallery: ALPHA must be a scalar for pei matrix."); + error ("gallery: ALPHA must be a scalar for pei matrix"); endif P = alpha * eye (n) + ones (n); @@ -2034,10 +2034,10 @@ ## Johns Hopkins University Press, Baltimore, Maryland, 1989 ## (Section 4.5.4). - if (nargin != 1) - error ("gallery: 1 argument is required for poisson matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for poisson matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for poisson matrix."); + error ("gallery: N must be an integer for poisson matrix"); endif S = tridiag (n, -1, 2, -1); @@ -2060,11 +2060,11 @@ ## 187:269--278, 1993. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for prolate matrix."); + error ("gallery: 1 to 2 arguments are required for prolate matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for prolate matrix."); + error ("gallery: N must be an integer for prolate matrix"); elseif (! isnumeric (w) || ! isscalar (w)) - error ("gallery: W must be a scalar for prolate matrix."); + error ("gallery: W must be a scalar for prolate matrix"); endif a = zeros (n, 1); @@ -2095,10 +2095,10 @@ ## W.B. Gragg, The QR algorithm for unitary Hessenberg matrices, ## J. Comp. Appl. Math., 16 (1986), pp. 1-8. - if (nargin != 1) - error ("gallery: 1 argument is required for randhess matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for randhess matrix"); elseif (! isnumeric (x) || ! isreal (x)) - error ("gallery: N or X must be numeric real values for randhess matrix."); + error ("gallery: N or X must be numeric real values for randhess matrix"); endif if (isscalar (x)) @@ -2111,7 +2111,7 @@ H = eye (n); H(n,n) = sign (x(n)) + (x(n) == 0); # Second term ensures H(n,n) nonzero. else - error ("gallery: N or X must be a scalar or a vector for randhess matrix."); + error ("gallery: N or X must be a scalar or a vector for randhess matrix"); endif for i = n:-1:2 @@ -2134,11 +2134,11 @@ ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2). if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for rando matrix."); + error ("gallery: 1 to 2 arguments are required for rando matrix"); elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) - error ("gallery: N must be an integer for rando matrix."); + error ("gallery: N must be an integer for rando matrix"); elseif (! isnumeric (k) || ! isscalar (k)) - error ("gallery: K must be a numeric scalar for smoke matrix."); + error ("gallery: K must be a numeric scalar for smoke matrix"); endif ## Parameter n specifies dimension: m-by-n. @@ -2150,7 +2150,7 @@ case (2), A = 2*floor ( rand(m, n) + 0.5) -1; # {-1, 1} case (3), A = round (3*rand(m, n) - 1.5); # {-1, 0, 1} otherwise - error ("gallery: unknown K '%d' for smoke matrix.", k); + error ("gallery: unknown K '%d' for smoke matrix", k); endswitch endfunction @@ -2191,19 +2191,19 @@ ## New York, 1989. if (nargin < 1 || nargin > 5) - error ("gallery: 1 to 5 arguments are required for randsvd matrix."); + error ("gallery: 1 to 5 arguments are required for randsvd matrix"); elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) - error ("gallery: N must be a 1 or 2 element integer vector for randsvd matrix."); + error ("gallery: N must be a 1 or 2 element integer vector for randsvd matrix"); elseif (! isnumeric (kappa) || ! isscalar (kappa)) - error ("gallery: KAPPA must be a numeric scalar for randsvd matrix."); + error ("gallery: KAPPA must be a numeric scalar for randsvd matrix"); elseif (abs (kappa) < 1) - error ("gallery: KAPPA must larger than or equal to 1 for randsvd matrix."); + error ("gallery: KAPPA must larger than or equal to 1 for randsvd matrix"); elseif (! isnumeric (mode) || ! isscalar (mode)) - error ("gallery: MODE must be a numeric scalar for randsvd matrix."); + error ("gallery: MODE must be a numeric scalar for randsvd matrix"); elseif (! isnumeric (kl) || ! isscalar (kl)) - error ("gallery: KL must be a numeric scalar for randsvd matrix."); + error ("gallery: KL must be a numeric scalar for randsvd matrix"); elseif (! isnumeric (ku) || ! isscalar (ku)) - error ("gallery: KU must be a numeric scalar for randsvd matrix."); + error ("gallery: KU must be a numeric scalar for randsvd matrix"); endif posdef = 0; @@ -2242,7 +2242,7 @@ rand ("uniform"); sigma = exp (-rand (p, 1) * log (kappa)); otherwise - error ("gallery: unknown MODE '%d' for randsvd matrix.", mode); + error ("gallery: unknown MODE '%d' for randsvd matrix", mode); endswitch ## Convert to diagonal matrix of singular values. @@ -2305,10 +2305,10 @@ ## Spectral Properties of a Matrix of Redheffer, ## Linear Algebra and Appl., 162 (1992), pp. 673-683. - if (nargin != 1) - error ("gallery: 1 argument is required for redheff matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for redheff matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for redheff matrix."); + error ("gallery: N must be an integer for redheff matrix"); endif i = (1:n)' * ones (1, n); @@ -2335,10 +2335,10 @@ ## F. Roesler, Riemann's hypothesis as an eigenvalue problem, ## Linear Algebra and Appl., 81 (1986), pp. 153-198. - if (nargin != 1) - error ("gallery: 1 argument is required for riemann matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for riemann matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for riemann matrix."); + error ("gallery: N must be an integer for riemann matrix"); endif n += 1; @@ -2361,10 +2361,10 @@ ## Algebra and Function Minimisation, second edition, Adam Hilger, ## Bristol, 1990 (Appendix 1). - if (nargin != 1) - error ("gallery: 1 argument is required for ris matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for ris matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for ris matrix."); + error ("gallery: N must be an integer for ris matrix"); endif p = -2*(1:n) + (n+1.5); @@ -2389,11 +2389,11 @@ ## Toeplitz matrices, Linear Algebra and Appl., 162-164:153-185, 1992. if (nargin < 1 || nargin > 2) - error ("gallery: 1 to 2 arguments are required for smoke matrix."); + error ("gallery: 1 to 2 arguments are required for smoke matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be an integer for smoke matrix."); + error ("gallery: N must be an integer for smoke matrix"); elseif (! isnumeric (n) || ! isscalar (n)) - error ("gallery: K must be a numeric scalar for smoke matrix."); + error ("gallery: K must be a numeric scalar for smoke matrix"); endif w = exp (2*pi*i/n); @@ -2403,7 +2403,7 @@ case (0), A(n,1) = 1; case (1), # do nothing otherwise, - error ("gallery: K must have a value of 0 or 1 for smoke matrix."); + error ("gallery: K must have a value of 0 or 1 for smoke matrix"); endswitch endfunction @@ -2424,13 +2424,13 @@ ## Comput., 7 (1986), pp. 123-131. if (nargin < 1 || nargin > 4) - error ("gallery: 1 to 4 arguments are required for toeppd matrix."); + error ("gallery: 1 to 4 arguments are required for toeppd matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be a numeric integer for toeppd matrix."); + error ("gallery: N must be a numeric integer for toeppd matrix"); elseif (! isnumeric (m) || ! isscalar (m) || fix (m) != m) - error ("gallery: M must be a numeric integer for toeppd matrix."); + error ("gallery: M must be a numeric integer for toeppd matrix"); elseif (numel (w) != m || numel (theta) != m) - error ("gallery: W and THETA must be vectors of length M for toeppd matrix."); + error ("gallery: W and THETA must be vectors of length M for toeppd matrix"); endif T = zeros (n); @@ -2465,11 +2465,11 @@ ## 1966, pp. 349-365. if (nargin < 1 || nargin > 6) - error ("gallery: 1 to 6 arguments are required for toeppen matrix."); + error ("gallery: 1 to 6 arguments are required for toeppen matrix"); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) - error ("gallery: N must be a numeric integer for toeppen matrix."); + error ("gallery: N must be a numeric integer for toeppen matrix"); elseif (any (! cellfun ("isnumeric", {a b c d e})) || any (cellfun ("numel", {a b c d e}) != 1)) - error ("gallery: A, B, C, D and E must be numeric scalars for toeppen matrix."); + error ("gallery: A, B, C, D and E must be numeric scalars for toeppen matrix"); endif P = spdiags ([a*ones(n,1) b*ones(n,1) c*ones(n,1) d*ones(n,1) e*ones(n,1)], @@ -2497,7 +2497,7 @@ ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241. if (nargin != 1 && nargin != 3 && nargin != 4) - error ("gallery: 1, 3, or 4 arguments are required for tridiag matrix."); + error ("gallery: 1, 3, or 4 arguments are required for tridiag matrix"); elseif (nargin == 3) z = y; y = x; @@ -2514,9 +2514,9 @@ z *= ones (n-1, 1); y *= ones (n, 1); elseif (numel (y) != numel (x) + 1) - error ("gallery: X must have one element less than Y for tridiag matrix."); + error ("gallery: X must have one element less than Y for tridiag matrix"); elseif (numel (y) != numel (z) + 1) - error ("gallery: Z must have one element less than Y for tridiag matrix."); + error ("gallery: Z must have one element less than Y for tridiag matrix"); endif ## T = diag (x, -1) + diag (y) + diag (z, 1); # For non-sparse matrix. @@ -2555,13 +2555,13 @@ ## Academic Press, London, 1978, pp. 109-135. if (nargin < 1 || nargin > 3) - error ("gallery: 1 to 3 arguments are required for triw matrix."); + error ("gallery: 1 to 3 arguments are required for triw matrix"); elseif (! isnumeric (n) || all (numel (n) != [1 2])) - error ("gallery: N must be a 1 or 2 elements vector for triw matrix."); + error ("gallery: N must be a 1 or 2 elements vector for triw matrix"); elseif (! isscalar (alpha)) - error ("gallery: ALPHA must be a scalar for triw matrix."); + error ("gallery: ALPHA must be a scalar for triw matrix"); elseif (! isscalar (k) || ! isnumeric (k) || fix (k) != k || k < 0) - error ("gallery: K must be a numeric integer >= 0 for triw matrix."); + error ("gallery: K must be a numeric integer >= 0 for triw matrix"); endif m = n(1); # Parameter n specifies dimension: m-by-n. @@ -2573,7 +2573,7 @@ function A = uniformdata (varargin) if (nargin < 2) - error ("gallery: At least 2 arguments required for uniformdata matrix."); + error ("gallery: At least 2 arguments required for uniformdata matrix"); endif if (isnumeric (varargin{end})) jidx = varargin{end}; @@ -2687,13 +2687,13 @@ ## format. if (nargin < 2 || nargin > 3) - error ("gallery: 2 or 3 arguments are required for wathen matrix."); + error ("gallery: 2 or 3 arguments are required for wathen matrix"); elseif (! isnumeric (nx) || ! isscalar (nx) || nx < 1) - error ("gallery: NX must be a positive scalar for wathen matrix."); + error ("gallery: NX must be a positive scalar for wathen matrix"); elseif (! isnumeric (ny) || ! isscalar (ny) || ny < 1) - error ("gallery: NY must be a positive scalar for wathen matrix."); + error ("gallery: NY must be a positive scalar for wathen matrix"); elseif (! isscalar (k)) - error ("gallery: K must be a scalar for wathen matrix."); + error ("gallery: K must be a scalar for wathen matrix"); endif e1 = [ 6 -6 2 -8 @@ -2762,10 +2762,10 @@ ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University ## Press, 1965. - if (nargin != 1) - error ("gallery: 1 argument is required for wilk matrix."); + if (nargin < 1) + error ("gallery: 1 argument is required for wilk matrix"); elseif (! isnumeric (n) || ! isscalar (n)) - error ("gallery: N must be a numeric scalar for wilk matrix."); + error ("gallery: N must be a numeric scalar for wilk matrix"); endif if (n == 3) @@ -2802,7 +2802,7 @@ A = diag (abs (-m:m)) + E + E'; else - error ("gallery: unknown N '%d' for wilk matrix.", n); + error ("gallery: unknown N '%d' for wilk matrix", n); endif endfunction @@ -2912,7 +2912,7 @@ %!assert (gallery ("invhess", 2), [1 -1; 1 2]) ## Test input validation of main dispatch function only -%!error gallery () +%!error <Invalid call> gallery () %!error <NAME must be a string> gallery (123) %!error <matrix binomial not implemented> gallery ("binomial") %!error <unknown matrix with NAME foobar> gallery ("foobar") @@ -2930,9 +2930,9 @@ %! 4 5 6 7 8 %! 5 6 7 8 9 %! 6 7 8 9 10]; -%! assert (gallery ("cauchy", 5), exp) -%! assert (gallery ("cauchy", 1:5), exp) -%! assert (gallery ("cauchy", 1:5, 1:5), exp) +%! assert (gallery ("cauchy", 5), exp); +%! assert (gallery ("cauchy", 1:5), exp); +%! assert (gallery ("cauchy", 1:5, 1:5), exp); %! %! exp = 1 ./ [ %! 1 2 3 4 5 @@ -2940,9 +2940,9 @@ %! 3 4 5 6 7 %! 4 5 6 7 8 %! 5 6 7 8 9]; -%! assert (gallery ("cauchy", 0:4, 1:5), exp) -%! assert (gallery ("cauchy", 1:5, 0:4), exp) -%! assert (gallery ("cauchy", 1:5, 4:-1:0), fliplr (exp)) +%! assert (gallery ("cauchy", 0:4, 1:5), exp); +%! assert (gallery ("cauchy", 1:5, 0:4), exp); +%! assert (gallery ("cauchy", 1:5, 4:-1:0), fliplr (exp)); %! %! exp = 1 ./ [ %! -1 0 1 2 3 @@ -2950,16 +2950,16 @@ %! 1 2 3 4 5 %! 2 3 4 5 6 %! 3 4 5 6 7]; -%! assert (gallery ("cauchy", 1:5, -2:2), exp) +%! assert (gallery ("cauchy", 1:5, -2:2), exp); %! %! exp = 1 ./ [ %! 8 18 -4 2 %! 13 23 1 7 %! 9 19 -3 3 %! 15 25 3 9]; -%! assert (gallery ("cauchy", [-2 3 -1 5], [10 20 -2 4]), exp) -%! assert (gallery ("cauchy", [-2 3 -1 5], [10 20 -2 4]'), exp) -%! assert (gallery ("cauchy", [-2 3 -1 5]', [10 20 -2 4]), exp) +%! assert (gallery ("cauchy", [-2 3 -1 5], [10 20 -2 4]), exp); +%! assert (gallery ("cauchy", [-2 3 -1 5], [10 20 -2 4]'), exp); +%! assert (gallery ("cauchy", [-2 3 -1 5]', [10 20 -2 4]), exp); %!assert (size (gallery ("chebspec", 5)), [5 5]) %!assert (size (gallery ("chebspec", 5, 1)), [5 5]) @@ -3006,10 +3006,10 @@ %! 2 1 0 1 2 %! 3 2 1 0 1 %! 4 3 2 1 0]; -%! assert (gallery ("fiedler", 5), exp) -%! assert (gallery ("fiedler", 1:5), exp) -%! assert (gallery ("fiedler", -2:2), exp) -%! assert (gallery ("fiedler", 2:5), exp(1:4,1:4)) +%! assert (gallery ("fiedler", 5), exp); +%! assert (gallery ("fiedler", 1:5), exp); +%! assert (gallery ("fiedler", -2:2), exp); +%! assert (gallery ("fiedler", 2:5), exp(1:4,1:4)); %!assert (size (gallery ("forsythe", 5)), [5 5]) %!assert (size (gallery ("forsythe", 5, 1, 0.5)), [5 5]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/hadamard.m --- a/scripts/special-matrix/hadamard.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/hadamard.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ function h = hadamard (n) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -176,6 +176,6 @@ %! assert (norm (h*h' - n*eye (n)), 0); %! endfor -%!error hadamard () +%!error <Invalid call> hadamard () %!error hadamard (1,2) %!error <N must be 2\^k\*p> hadamard (5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/hankel.m --- a/scripts/special-matrix/hankel.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/hankel.m Thu Nov 19 13:08:00 2020 -0800 @@ -56,7 +56,7 @@ function retval = hankel (c, r) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -99,7 +99,6 @@ %!warning <column wins anti-diagonal conflict> %! assert (hankel (1:3,4:6), [1,2,3;2,3,5;3,5,6]); -%!error hankel () -%!error hankel (1, 2, 3) +%!error <Invalid call> hankel () %!error <C must be a vector> hankel ([1, 2; 3, 4]) %!error <C and R must be vectors> hankel (1:4, [1, 2; 3, 4]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/hilb.m --- a/scripts/special-matrix/hilb.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/hilb.m Thu Nov 19 13:08:00 2020 -0800 @@ -60,7 +60,7 @@ function retval = hilb (n) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! isscalar (n)) error ("hilb: N must be a scalar integer"); @@ -77,6 +77,5 @@ %!assert (hilb (2), [1, 1/2; 1/2, 1/3]) %!assert (hilb (3), [1, 1/2, 1/3; 1/2, 1/3, 1/4; 1/3, 1/4, 1/5]) -%!error hilb () -%!error hilb (1, 2) +%!error <Invalid call> hilb () %!error <N must be a scalar integer> hilb (ones (2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/invhilb.m --- a/scripts/special-matrix/invhilb.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/invhilb.m Thu Nov 19 13:08:00 2020 -0800 @@ -81,7 +81,7 @@ function retval = invhilb (n) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! isscalar (n)) error ("invhilb: N must be a scalar integer"); @@ -128,6 +128,5 @@ %! assert (invhilb (4), result4); %!assert (invhilb (7) * hilb (7), eye (7), sqrt (eps)) -%!error invhilb () -%!error invhilb (1, 2) +%!error <Invalid call> invhilb () %!error <N must be a scalar integer> invhilb ([1, 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/magic.m --- a/scripts/special-matrix/magic.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/magic.m Thu Nov 19 13:08:00 2020 -0800 @@ -38,7 +38,7 @@ function A = magic (n) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -105,6 +105,5 @@ %!assert (magic (1.5), 1) ## Test input validation -%!error magic () -%!error magic (1, 2) +%!error <Invalid call> magic () %!error <N must be non-negative> magic (-5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/module.mk --- a/scripts/special-matrix/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/gallery.m \ %reldir%/hadamard.m \ %reldir%/hankel.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/pascal.m --- a/scripts/special-matrix/pascal.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/pascal.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ function retval = pascal (n, t = 0) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (! (isscalar (n) && isscalar (t))) error ("pascal: N and T must be scalars"); @@ -90,8 +90,7 @@ %!assert (pascal (0,2), []) ## Test input validation -%!error pascal () -%!error pascal (1,2,3) +%!error <Invalid call> pascal () %!error <N and T must be scalars> pascal ([1 2]) %!error <N and T must be scalars> pascal (1, [1 2]) %!error <T must be -1> pascal (3,-2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/rosser.m --- a/scripts/special-matrix/rosser.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/rosser.m Thu Nov 19 13:08:00 2020 -0800 @@ -33,10 +33,6 @@ function retval = rosser () - if (nargin != 0) - print_usage (); - endif - retval = [611, 196, -192, 407, -8, -52, -49, 29; 196, 899, 113, -192, -71, -43, -8, -44; -192, 113, 899, 196, 61, 49, 8, 52; @@ -52,4 +48,4 @@ %!assert (size (rosser ()), [8,8]) %!assert (rosser ()([1, end]), [611, 99]) -%!error (rosser (1)) +%!error rosser (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/toeplitz.m --- a/scripts/special-matrix/toeplitz.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/toeplitz.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,7 +65,7 @@ function retval = toeplitz (c, r) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -133,8 +133,7 @@ %!assert (toeplitz ([1, 2, 3], [1; -3i; -5i]), [1, -3i, -5i; 2, 1, -3i; 3, 2, 1]) ## Test input validation -%!error toeplitz () -%!error toeplitz (1, 2, 3) +%!error <Invalid call> toeplitz () %!error <C must be a vector> toeplitz ([1, 2; 3, 4]) %!error <C and R must be vectors> toeplitz ([1, 2; 3, 4], 1) %!error <C and R must be vectors> toeplitz (1, [1, 2; 3, 4]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/vander.m --- a/scripts/special-matrix/vander.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/vander.m Thu Nov 19 13:08:00 2020 -0800 @@ -95,6 +95,5 @@ %!assert (vander (2, 3), [4, 2, 1]) %!assert (vander ([2, 3], 3), [4, 2, 1; 9, 3, 1]) -%!error vander () -%!error vander (1, 2, 3) +%!error <Invalid call> vander () %!error <polynomial C must be a vector> vander ([1, 2; 3, 4]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/special-matrix/wilkinson.m --- a/scripts/special-matrix/wilkinson.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/special-matrix/wilkinson.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function retval = wilkinson (n) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -58,8 +58,7 @@ %!assert (wilkinson (4), [1.5,1,0,0;1,0.5,1,0;0,1,0.5,1;0,0,1,1.5]) ## Test input validation -%!error wilkinson () -%!error wilkinson (1,2) +%!error <Invalid call> wilkinson () %!error <N must be a non-negative integer> wilkinson (ones (2)) %!error <N must be a non-negative integer> wilkinson (-1) %!error <N must be a non-negative integer> wilkinson (1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/statistics/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/bounds.m --- a/scripts/statistics/bounds.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/bounds.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,7 +48,7 @@ function [s, l] = bounds (x, dim, nanflag = false) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -119,8 +119,7 @@ %! assert (l, x(:,:,3)); ## Test input validation -%!error bounds () -%!error bounds (1, 2, 3, 4) +%!error <Invalid call> bounds () %!error <X must be a numeric> bounds (['A'; 'B']) %!error <DIM must be an integer> bounds (1, ones (2,2)) %!error <DIM must be an integer> bounds (1, 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/center.m --- a/scripts/statistics/center.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/center.m Thu Nov 19 13:08:00 2020 -0800 @@ -44,7 +44,7 @@ function retval = center (x, dim) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -92,8 +92,7 @@ %!assert (center (1, 3), 0) ## Test input validation -%!error center () -%!error center (1, 2, 3) +%!error <Invalid call> center () %!error <DIM must be an integer> center (1, ones (2,2)) %!error <DIM must be an integer> center (1, 1.5) %!error <DIM must be .* a valid dimension> center (1, 0) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/corr.m --- a/scripts/statistics/corr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/corr.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,7 @@ function retval = corr (x, y = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -107,8 +107,7 @@ %!assert (corr (single (5)), single (1)) ## Test input validation -%!error corr () -%!error corr (1, 2, 3) +%!error <Invalid call> corr () %!error corr ([1; 2], ["A", "B"]) %!error corr (ones (2,2,2)) %!error corr (ones (2,2), ones (2,2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/corrcoef.m --- a/scripts/statistics/corrcoef.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/corrcoef.m Thu Nov 19 13:08:00 2020 -0800 @@ -284,7 +284,7 @@ %! r = corrcoef (x, y); %! assert (r, [1, NaN; NaN, 1]); -%!error corrcoef () +%!error <Invalid call> corrcoef () %!error <parameter 1 must be a string> corrcoef (1, 2, 3) %!error <parameter "alpha" missing value> corrcoef (1, 2, "alpha") %!error <"alpha" must be a scalar> corrcoef (1,2, "alpha", "1") diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/cov.m --- a/scripts/statistics/cov.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/cov.m Thu Nov 19 13:08:00 2020 -0800 @@ -79,7 +79,7 @@ function c = cov (x, y = [], opt = 0) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -171,10 +171,9 @@ %! assert (c, 2); ## Test input validation -%!error cov () -%!error cov (1, 2, 3, 4) +%!error <Invalid call> cov () %!error cov ([1; 2], ["A", "B"]) %!error cov (ones (2,2,2)) %!error cov (ones (2,2), ones (2,2,2)) -%!error cov (1, 3) +%!error <normalization OPT must be 0 or 1> cov (1, 3) %!error cov (ones (2,2), ones (3,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/discrete_cdf.m --- a/scripts/statistics/discrete_cdf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/discrete_cdf.m Thu Nov 19 13:08:00 2020 -0800 @@ -64,7 +64,7 @@ %!shared x,v,p,y %! x = [-1 0.1 1.1 1.9 3]; %! v = 0.1:0.2:1.9; -%! p = 1/length(v) * ones (1, length(v)); +%! p = 1/length (v) * ones (1, length (v)); %! y = [0 0.1 0.6 1 1]; %!assert (discrete_cdf ([x, NaN], v, p), [y, NaN], eps) @@ -74,10 +74,9 @@ %!assert (discrete_cdf ([x, NaN], v, single (p)), single ([y, NaN]), 2*eps ("single")) ## Test input validation -%!error discrete_cdf () -%!error discrete_cdf (1) -%!error discrete_cdf (1,2) -%!error discrete_cdf (1,2,3,4) +%!error <Invalid call> discrete_cdf () +%!error <Invalid call> discrete_cdf (1) +%!error <Invalid call> discrete_cdf (1,2) %!error discrete_cdf (1, ones (2), ones (2,1)) %!error discrete_cdf (1, [1 ; NaN], ones (2,1)) %!error discrete_cdf (1, ones (2,1), ones (1,1)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/discrete_inv.m --- a/scripts/statistics/discrete_inv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/discrete_inv.m Thu Nov 19 13:08:00 2020 -0800 @@ -76,7 +76,7 @@ %!shared x,v,p,y %! x = [-1 0 0.1 0.5 1 2]; %! v = 0.1:0.2:1.9; -%! p = 1/length(v) * ones (1, length(v)); +%! p = 1/length (v) * ones (1, length (v)); %! y = [NaN v(1) v(1) v(end/2) v(end) NaN]; %!assert (discrete_inv ([x, NaN], v, p), [y, NaN], eps) @@ -86,10 +86,9 @@ %!assert (discrete_inv ([x, NaN], v, single (p)), single ([y, NaN]), eps ("single")) ## Test input validation -%!error discrete_inv () -%!error discrete_inv (1) -%!error discrete_inv (1,2) -%!error discrete_inv (1,2,3,4) +%!error <Invalid call> discrete_inv () +%!error <Invalid call> discrete_inv (1) +%!error <Invalid call> discrete_inv (1,2) %!error discrete_inv (1, ones (2), ones (2,1)) %!error discrete_inv (1, ones (2,1), ones (1,1)) %!error discrete_inv (1, ones (2,1), [1 NaN]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/discrete_pdf.m --- a/scripts/statistics/discrete_pdf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/discrete_pdf.m Thu Nov 19 13:08:00 2020 -0800 @@ -75,10 +75,9 @@ %!assert (discrete_pdf ([x, NaN], v, single (p)), single ([y, NaN]), 5*eps ("single")) ## Test input validation -%!error discrete_pdf () -%!error discrete_pdf (1) -%!error discrete_pdf (1,2) -%!error discrete_pdf (1,2,3,4) +%!error <Invalid call> discrete_pdf () +%!error <Invalid call> discrete_pdf (1) +%!error <Invalid call> discrete_pdf (1,2) %!error discrete_pdf (1, ones (2), ones (2,1)) %!error discrete_pdf (1, [1 ; NaN], ones (2,1)) %!error discrete_pdf (1, ones (2,1), ones (1,1)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/discrete_rnd.m --- a/scripts/statistics/discrete_rnd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/discrete_rnd.m Thu Nov 19 13:08:00 2020 -0800 @@ -88,11 +88,11 @@ %!assert (class (discrete_rnd (1:2, 1:2)), "double") %!assert (class (discrete_rnd (single (1:2), 1:2)), "single") ## FIXME: Maybe this should work, maybe it shouldn't. -#%!assert(class (discrete_rnd (1:2, single(1:2))), "single") +#%!assert (class (discrete_rnd (1:2, single(1:2))), "single") ## Test input validation -%!error discrete_rnd () -%!error discrete_rnd (1) +%!error <Invalid call> discrete_rnd () +%!error <Invalid call> discrete_rnd (1) %!error discrete_rnd (1:2,1:2, -1) %!error discrete_rnd (1:2,1:2, ones (2)) %!error discrete_rnd (1:2,1:2, [2 -1 2]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/empirical_cdf.m --- a/scripts/statistics/empirical_cdf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/empirical_cdf.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,7 +58,6 @@ %!assert (empirical_cdf ([x, NaN], single (v)), single ([y, NaN]), eps) ## Test input validation -%!error empirical_cdf () -%!error empirical_cdf (1) -%!error empirical_cdf (1,2,3) +%!error <Invalid call> empirical_cdf () +%!error <Invalid call> empirical_cdf (1) %!error empirical_cdf (1, ones (2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/empirical_inv.m --- a/scripts/statistics/empirical_inv.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/empirical_inv.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,6 @@ %!assert (empirical_inv ([x, NaN], single (v)), single ([y, NaN]), eps) ## Test input validation -%!error empirical_inv () -%!error empirical_inv (1) -%!error empirical_inv (1,2,3) +%!error <Invalid call> empirical_inv () +%!error <Invalid call> empirical_inv (1) %!error empirical_inv (1, ones (2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/empirical_pdf.m --- a/scripts/statistics/empirical_pdf.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/empirical_pdf.m Thu Nov 19 13:08:00 2020 -0800 @@ -68,7 +68,6 @@ %!assert (empirical_pdf (2, [1 2 3 2]), 0.5) ## Test input validation -%!error empirical_pdf () -%!error empirical_pdf (1) -%!error empirical_pdf (1,2,3) +%!error <Invalid call> empirical_pdf () +%!error <Invalid call> empirical_pdf (1) %!error empirical_inv (1, ones (2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/empirical_rnd.m --- a/scripts/statistics/empirical_rnd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/empirical_rnd.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,6 +65,6 @@ %!assert (class (empirical_rnd (single (1:2), 1)), "single") ## Test input validation -%!error empirical_rnd () +%!error <Invalid call> empirical_rnd () %!error empirical_rnd (ones (2), 1) %!error empirical_rnd (ones (2), 1, 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/histc.m --- a/scripts/statistics/histc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/histc.m Thu Nov 19 13:08:00 2020 -0800 @@ -62,7 +62,7 @@ function [n, idx] = histc (x, edges, dim) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -188,9 +188,9 @@ %! n = histc (x, 0:10, 2); %! assert (n, repmat ([repmat(100, 1, 10), 1], [2, 1, 3])); -%!error histc () -%!error histc (1) -%!error histc (1, 2, 3, 4) +## Test input validation +%!error <Invalid call> histc () +%!error <Invalid call> histc (1) %!error histc ([1:10 1+i], 2) %!warning <empty EDGES specified> histc (1:10, []); %!error histc (1, 1, 3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/iqr.m --- a/scripts/statistics/iqr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/iqr.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function y = iqr (x, dim) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -97,8 +97,7 @@ %! assert (iqr (x, 1), 50); %! assert (iqr (x', 2), 50); -%!error iqr () -%!error iqr (1, 2, 3) +%!error <Invalid call> iqr () %!error iqr (1) %!error iqr (['A'; 'B']) %!error iqr (1:10, 3) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/kendall.m --- a/scripts/statistics/kendall.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/kendall.m Thu Nov 19 13:08:00 2020 -0800 @@ -93,7 +93,7 @@ function tau = kendall (x, y = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -148,8 +148,7 @@ %!assert (kendall (single (1)), single (1)) ## Test input validation -%!error kendall () -%!error kendall (1, 2, 3) +%!error <Invalid call> kendall () %!error kendall (['A'; 'B']) %!error kendall (ones (2,1), ['A'; 'B']) %!error kendall (ones (2,2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/kurtosis.m --- a/scripts/statistics/kurtosis.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/kurtosis.m Thu Nov 19 13:08:00 2020 -0800 @@ -88,7 +88,7 @@ function y = kurtosis (x, flag, dim) - if (nargin < 1) || (nargin > 3) + if (nargin < 1) print_usage (); endif @@ -162,8 +162,7 @@ %! assert (lastwarn (), ""); ## Test input validation -%!error kurtosis () -%!error kurtosis (1, 2, 3) +%!error <Invalid call> kurtosis () %!error <X must be a numeric vector or matrix> kurtosis (['A'; 'B']) %!error <FLAG must be 0 or 1> kurtosis (1, 2) %!error <FLAG must be 0 or 1> kurtosis (1, [1 0]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/mad.m --- a/scripts/statistics/mad.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/mad.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,7 +58,7 @@ function retval = mad (x, opt = 0, dim) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -105,8 +105,7 @@ %!assert (mad (magic (4), 1, 2), [5.5; 1.5; 1.5; 5.5]) ## Test input validation -%!error mad () -%!error mad (1, 2, 3, 4) +%!error <Invalid call> mad () %!error <X must be a numeric> mad (['A'; 'B']) %!error <OPT must be 0 or 1> mad (1, 2) %!error <DIM must be an integer> mad (1, [], ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/mean.m --- a/scripts/statistics/mean.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/mean.m Thu Nov 19 13:08:00 2020 -0800 @@ -179,6 +179,7 @@ ## this should have been filtered out during input check, but... error ("mean: OUTTYPE '%s' not recognized", out_type); endswitch + endfunction @@ -217,25 +218,25 @@ %!test %! in = [1 2 3]; %! out = 2; -%! assert (mean (in, "default"), mean (in)) -%! assert (mean (in, "default"), out) +%! assert (mean (in, "default"), mean (in)); +%! assert (mean (in, "default"), out); %! %! in = single ([1 2 3]); %! out = 2; -%! assert (mean (in, "default"), mean (in)) -%! assert (mean (in, "default"), single (out)) -%! assert (mean (in, "double"), out) -%! assert (mean (in, "native"), single (out)) +%! assert (mean (in, "default"), mean (in)); +%! assert (mean (in, "default"), single (out)); +%! assert (mean (in, "double"), out); +%! assert (mean (in, "native"), single (out)); %! %! in = uint8 ([1 2 3]); %! out = 2; -%! assert (mean (in, "default"), mean (in)) -%! assert (mean (in, "default"), out) -%! assert (mean (in, "double"), out) -%! assert (mean (in, "native"), uint8 (out)) +%! assert (mean (in, "default"), mean (in)); +%! assert (mean (in, "default"), out); +%! assert (mean (in, "double"), out); +%! assert (mean (in, "native"), uint8 (out)); %! %! in = logical ([1 0 1]); %! out = 2/3; -%! assert (mean (in, "default"), mean (in)) -%! assert (mean (in, "default"), out) -%! assert (mean (in, "native"), out) # logical ignores native option +%! assert (mean (in, "default"), mean (in)); +%! assert (mean (in, "default"), out); +%! assert (mean (in, "native"), out); # logical ignores native option diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/meansq.m --- a/scripts/statistics/meansq.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/meansq.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ function y = meansq (x, dim) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -88,8 +88,7 @@ %!assert (meansq ([1 2], 3), [1 4]) ## Test input validation -%!error meansq () -%!error meansq (1, 2, 3) +%!error <Invalid call> meansq () %!error <X must be a numeric> meansq (['A'; 'B']) %!error <DIM must be an integer> meansq (1, ones (2,2)) %!error <DIM must be an integer> meansq (1, 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/median.m --- a/scripts/statistics/median.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/median.m Thu Nov 19 13:08:00 2020 -0800 @@ -62,7 +62,7 @@ function retval = median (x, dim) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -138,8 +138,7 @@ %!assert (median (single ([1, 3, NaN])), single (NaN)) ## Test input validation -%!error median () -%!error median (1, 2, 3) +%!error <Invalid call> median () %!error <X must be a numeric> median ({1:5}) %!error <X cannot be an empty matrix> median ([]) %!error <DIM must be an integer> median (1, ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/mode.m --- a/scripts/statistics/mode.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/mode.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,7 +45,7 @@ function [m, f, c] = mode (x, dim) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -182,8 +182,7 @@ %! assert (c{3}, [1; 2; 3]); ## Test input validation -%!error mode () -%!error mode (1, 2, 3) +%!error <Invalid call> mode () %!error <X must be a numeric> mode ({1 2 3}) %!error <DIM must be an integer> mode (1, ones (2,2)) %!error <DIM must be an integer> mode (1, 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/module.mk --- a/scripts/statistics/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/bounds.m \ %reldir%/center.m \ %reldir%/corr.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/moment.m --- a/scripts/statistics/moment.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/moment.m Thu Nov 19 13:08:00 2020 -0800 @@ -130,7 +130,7 @@ function m = moment (x, p, opt1, opt2) - if (nargin < 2 || nargin > 4) + if (nargin < 2) print_usage (); endif @@ -206,9 +206,8 @@ %!assert (moment (1, 2, 4), 0) ## Test input validation -%!error moment () -%!error moment (1) -%!error moment (1, 2, 3, 4, 5) +%!error <Invalid call> moment () +%!error <Invalid call> moment (1) %!error <X must be a non-empty numeric matrix> moment (['A'; 'B'], 2) %!error <X must be a non-empty numeric matrix> moment (ones (2,0,3), 2) %!error <P must be a numeric scalar> moment (1, true) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movmad.m --- a/scripts/statistics/movmad.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movmad.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmax, movmean, movmedian, movmin, movprod, movstd, movsum, movvar} ## @end deftypefn @@ -140,10 +140,9 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([0.5; repmat(2/3,8,1); 0.5], movmad ((1:10).', 3)) - ## Test input validation -%!error movmad () -%!error movmad (1) +%!error <Invalid call> movmad () +%!error <Invalid call> movmad (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movmax.m --- a/scripts/statistics/movmax.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movmax.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmean, movmedian, movmin, movprod, movstd, movsum, movvar} ## @end deftypefn @@ -141,9 +141,9 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([(2:10).'; 10], movmax ((1:10).', 3)) ## Test input validation -%!error movmax () -%!error movmax (1) +%!error <Invalid call> movmax () +%!error <Invalid call> movmax (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movmean.m --- a/scripts/statistics/movmean.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movmean.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmax, movmedian, movmin, movprod, movstd, movsum, movvar} ## @end deftypefn @@ -140,9 +140,9 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([1.5; (2:9).'; 9.5], movmean ((1:10).', 3)) ## Test input validation -%!error movmean () -%!error movmean (1) +%!error <Invalid call> movmean () +%!error <Invalid call> movmean (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movmedian.m --- a/scripts/statistics/movmedian.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movmedian.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmax, movmean, movmin, movprod, movstd, movsum, movvar} ## @end deftypefn @@ -140,9 +140,9 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([1.5; (2:9).'; 9.5], movmedian ((1:10).', 3)) ## Test input validation -%!error movmedian () -%!error movmedian (1) +%!error <Invalid call> movmedian () +%!error <Invalid call> movmedian (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movmin.m --- a/scripts/statistics/movmin.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movmin.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmax, movmean, movmedian, movprod, movstd, movsum, movvar} ## @end deftypefn @@ -141,9 +141,9 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([1; (1:9).'], movmin ((1:10).', 3)) ## Test input validation -%!error movmin () -%!error movmin (1) +%!error <Invalid call> movmin () +%!error <Invalid call> movmin (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movprod.m --- a/scripts/statistics/movprod.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movprod.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmax, movmean, movmedian, movmin, movstd, movsum, movvar} ## @end deftypefn @@ -141,9 +141,9 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([2; 6; 24; 60; 120; 210; 336; 504; 720; 90], movprod ((1:10).', 3)) ## Test input validation -%!error movprod () -%!error movprod (1) +%!error <Invalid call> movprod () +%!error <Invalid call> movprod (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movstd.m --- a/scripts/statistics/movstd.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movstd.m Thu Nov 19 13:08:00 2020 -0800 @@ -138,7 +138,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmax, movmean, movmedian, movmin, movprod, movsum, movvar} ## @end deftypefn @@ -167,7 +167,7 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([1/sqrt(2); ones(8,1); 1/sqrt(2)], movstd ((1:10).', 3), 1e-8) %!test <*56765> @@ -179,5 +179,5 @@ %! assert (y1(1:3), sqrt ([1/4, 2/3, 5/4])); ## Test input validation -%!error movstd () -%!error movstd (1) +%!error <Invalid call> movstd () +%!error <Invalid call> movstd (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movsum.m --- a/scripts/statistics/movsum.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movsum.m Thu Nov 19 13:08:00 2020 -0800 @@ -123,7 +123,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmax, movmean, movmedian, movmin, movprod, movstd, movvar} ## @end deftypefn @@ -141,9 +141,9 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([(3:3:27).'; 19], movsum ((1:10).', 3)) ## Test input validation -%!error movsum () -%!error movsum (1) +%!error <Invalid call> movsum () +%!error <Invalid call> movsum (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/movvar.m --- a/scripts/statistics/movvar.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/movvar.m Thu Nov 19 13:08:00 2020 -0800 @@ -137,7 +137,7 @@ ## @end table ## ## Programming Note: This function is a wrapper which calls @code{movfun}. -## For additional options and documentation, @pxref{XREFmovfun,,movfun}. +## For additional options and documentation, @pxref{XREFmovfun,,@code{movfun}}. ## ## @seealso{movfun, movslice, movmad, movmax, movmean, movmedian, movmin, movprod, movstd, movsum} ## @end deftypefn @@ -166,7 +166,7 @@ ## FIXME: Need functional BIST tests -# test for bug #55241 +## test for bug #55241 %!assert ([0.5; ones(8,1); 0.5], movvar ((1:10).', 3)) %!test <*56765> @@ -178,5 +178,5 @@ %! assert (y1(1:3), [1/4, 2/3, 5/4]); ## Test input validation -%!error movvar () -%!error movvar (1) +%!error <Invalid call> movvar () +%!error <Invalid call> movvar (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/prctile.m --- a/scripts/statistics/prctile.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/prctile.m Thu Nov 19 13:08:00 2020 -0800 @@ -46,7 +46,7 @@ function q = prctile (x, p = [], dim) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -180,8 +180,7 @@ %! assert (q, qa, tol); ## Test input validation -%!error prctile () -%!error prctile (1, 2, 3, 4) +%!error <Invalid call> prctile () %!error prctile (['A'; 'B'], 10) %!error prctile (1:10, [true, false]) %!error prctile (1:10, ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/quantile.m --- a/scripts/statistics/quantile.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/quantile.m Thu Nov 19 13:08:00 2020 -0800 @@ -156,7 +156,7 @@ function q = quantile (x, p = [], dim, method = 5) - if (nargin < 1 || nargin > 4) + if (nargin < 1) print_usage (); endif @@ -384,8 +384,7 @@ %!assert <*54421> (quantile ([1:10], [0.25, 0.75]'), [3; 8]) ## Test input validation -%!error quantile () -%!error quantile (1, 2, 3, 4, 5) +%!error <Invalid call> quantile () %!error quantile (['A'; 'B'], 10) %!error quantile (1:10, [true, false]) %!error quantile (1:10, ones (2,2)) @@ -405,7 +404,7 @@ ## Description: Quantile function of empirical samples function inv = __quantile__ (x, p, method = 5) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage ("quantile"); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/range.m --- a/scripts/statistics/range.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/range.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function y = range (x, dim) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -62,5 +62,4 @@ %!assert (range (2), 0) ## Test input validation -%!error range () -%!error range (1, 2, 3) +%!error <Invalid call> range () diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/ranks.m --- a/scripts/statistics/ranks.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/ranks.m Thu Nov 19 13:08:00 2020 -0800 @@ -53,7 +53,7 @@ function y = ranks (x, dim, rtype = 0) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -105,7 +105,7 @@ otherwise if (! ischar (rtype)) rtype = num2str (rtype); - end + endif error ("ranks: unknown RTYPE '%s'", rtype); endswitch @@ -164,8 +164,7 @@ %!assert (ranks ([1, 2, 2, 4], [], "dense"), [1, 2, 2, 3]) ## Test input validation -%!error ranks () -%!error ranks (1, 2, 3, 4) +%!error <Invalid call> ranks () %!error <X must be a numeric vector or matrix> ranks ({1, 2}) %!error <X must be a numeric vector or matrix> ranks (['A'; 'B']) %!error <DIM must be an integer> ranks (1, 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/run_count.m --- a/scripts/statistics/run_count.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/run_count.m Thu Nov 19 13:08:00 2020 -0800 @@ -36,7 +36,7 @@ function retval = run_count (x, n, dim) - if (nargin != 2 && nargin != 3) + if (nargin < 2) print_usage (); endif @@ -103,9 +103,8 @@ %!assert (run_count (ones (3), 4), [0,0,0;0,0,0;1,1,1;0,0,0]) ## Test input validation -%!error run_count () -%!error run_count (1) -%!error run_count (1, 2, 3, 4) +%!error <Invalid call> run_count () +%!error <Invalid call> run_count (1) %!error run_count ({1, 2}, 3) %!error run_count (['A'; 'A'; 'B'], 3) %!error run_count (1:5, ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/runlength.m --- a/scripts/statistics/runlength.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/runlength.m Thu Nov 19 13:08:00 2020 -0800 @@ -44,7 +44,7 @@ function [count, value] = runlength (x) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -73,7 +73,6 @@ %! assert (v, [2 0 4 0 1]); ## Test input validation -%!error runlength () -%!error runlength (1, 2) +%!error <Invalid call> runlength () %!error runlength (['A'; 'B']) %!error runlength (ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/skewness.m --- a/scripts/statistics/skewness.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/skewness.m Thu Nov 19 13:08:00 2020 -0800 @@ -87,7 +87,7 @@ function y = skewness (x, flag, dim) - if (nargin < 1) || (nargin > 3) + if (nargin < 1) print_usage (); endif @@ -161,8 +161,7 @@ %! assert (lastwarn (), ""); ## Test input validation -%!error skewness () -%!error skewness (1, 2, 3) +%!error <Invalid call> skewness () %!error <X must be a numeric vector or matrix> skewness (['A'; 'B']) %!error <FLAG must be 0 or 1> skewness (1, 2) %!error <FLAG must be 0 or 1> skewness (1, [1 0]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/spearman.m --- a/scripts/statistics/spearman.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/spearman.m Thu Nov 19 13:08:00 2020 -0800 @@ -68,7 +68,7 @@ function rho = spearman (x, y = []) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -114,8 +114,7 @@ %!assert (spearman ([1 2 3], [-1 1 -2]), -0.5, 5*eps) ## Test input validation -%!error spearman () -%!error spearman (1, 2, 3) +%!error <Invalid call> spearman () %!error spearman (['A'; 'B']) %!error spearman (ones (1,2), {1, 2}) %!error spearman (ones (2,2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/statistics.m --- a/scripts/statistics/statistics.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/statistics.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,7 +39,7 @@ function stats = statistics (x, dim) - if (nargin != 1 && nargin != 2) + if (nargin < 1) print_usage (); endif @@ -93,8 +93,7 @@ %! assert (kurtosis (x, [], 2), s(:,9), eps); ## Test input validation -%!error statistics () -%!error statistics (1, 2, 3) +%!error <Invalid call> statistics () %!error statistics (['A'; 'B']) %!error statistics (1, ones (2,2)) %!error statistics (1, 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/std.m --- a/scripts/statistics/std.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/std.m Thu Nov 19 13:08:00 2020 -0800 @@ -70,7 +70,7 @@ function retval = std (x, opt = 0, dim) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -126,8 +126,7 @@ %!assert (std ([1 2 3], [], 3), [0 0 0]) ## Test input validation -%!error std () -%!error std (1, 2, 3, 4) +%!error <Invalid call> std () %!error <X must be a numeric> std (['A'; 'B']) %!error <OPT must be 0 or 1> std (1, 2) %!error <DIM must be an integer> std (1, [], ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/var.m --- a/scripts/statistics/var.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/var.m Thu Nov 19 13:08:00 2020 -0800 @@ -74,7 +74,7 @@ function retval = var (x, opt = 0, dim) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -123,8 +123,7 @@ %!assert (var ([1,2,3], [], 3), [0,0,0]) ## Test input validation -%!error var () -%!error var (1,2,3,4) +%!error <Invalid call> var () %!error <X must be a numeric> var (['A'; 'B']) %!error <OPT must be 0 or 1> var (1, -1) %!error <FLAG must be 0 or 1> skewness (1, 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/statistics/zscore.m --- a/scripts/statistics/zscore.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/statistics/zscore.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ function [z, mu, sigma] = zscore (x, opt = 0, dim) - if (nargin < 1 || nargin > 3 ) + if (nargin < 1) print_usage (); endif @@ -102,7 +102,7 @@ %!assert <*54531> (zscore ([1,2,3], [], 2), [-1,0,1]) ## Test input validation -%!error zscore () +%!error <Invalid call> zscore () %!error zscore (1, 2, 3) %!error <X must be a numeric> zscore (['A'; 'B']) %!error <OPT must be empty, 0, or 1> zscore (1, ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/strings/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/base2dec.m --- a/scripts/strings/base2dec.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/base2dec.m Thu Nov 19 13:08:00 2020 -0800 @@ -115,7 +115,7 @@ ## Multiply the resulting digits by the appropriate power ## and sum the rows. - out = s * (base .^ (columns(s)-1 : -1 : 0)'); + out = s * (base .^ (columns (s)-1 : -1 : 0)'); endfunction @@ -128,7 +128,7 @@ %!assert <*35621> (base2dec (["0"; "1"], 2), [0; 1]) ## Test input validation -%!error base2dec () +%!error <Invalid call> base2dec () %!error base2dec ("11120") %!error base2dec ("11120", 3, 4) %!error <symbols .* must be unique> base2dec ("11120", "1231") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/bin2dec.m --- a/scripts/strings/bin2dec.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/bin2dec.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ function d = bin2dec (s) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -74,6 +74,5 @@ %!assert (bin2dec (char ("1 0 1", " 1111")), [5; 15]) ## Test input validation -%!error bin2dec () -%!error bin2dec (1) -%!error bin2dec ("1", 2) +%!error <Invalid call> bin2dec () +%!error <S must be a string> bin2dec (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/blanks.m --- a/scripts/strings/blanks.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/blanks.m Thu Nov 19 13:08:00 2020 -0800 @@ -44,7 +44,7 @@ function s = blanks (n) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! (isscalar (n) && n == fix (n) && n >= 0)) error ("blanks: N must be a non-negative integer"); @@ -63,8 +63,7 @@ %!assert (blanks (10), " ") ## Test input validation -%!error blanks () -%!error blanks (1, 2) +%!error <Invalid call> blanks () %!error blanks (ones (2)) %!error blanks (2.1) %!error blanks (-2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/deblank.m --- a/scripts/strings/deblank.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/deblank.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ function s = deblank (s) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -102,5 +102,5 @@ %!assert (deblank ({" abc ", {" def "}}), {" abc", {" def"}}) %!error <Invalid call to deblank> deblank () -%!error <Invalid call to deblank> deblank ("foo", "bar") +%!error <called with too many inputs> deblank ("foo", "bar") %!error <argument must be a string> deblank (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/dec2base.m --- a/scripts/strings/dec2base.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/dec2base.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,7 +58,7 @@ function retval = dec2base (d, base, len) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -163,9 +163,8 @@ %!assert <*56005> (dec2base ([0, 0], 16), ["0"; "0"]) ## Test input validation -%!error dec2base () -%!error dec2base (1) -%!error dec2base (1, 2, 3, 4) +%!error <Invalid call> dec2base () +%!error <Invalid call> dec2base (1) %!error dec2base ("A") %!error dec2base (2i) %!error dec2base (-1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/dec2bin.m --- a/scripts/strings/dec2bin.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/dec2bin.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,45 +24,111 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {} dec2bin (@var{d}, @var{len}) -## Return a binary number corresponding to the non-negative integer @var{d}, -## as a string of ones and zeros. +## @deftypefn {} {} dec2bin (@var{d}) +## @deftypefnx {} {} dec2bin (@var{d}, @var{len}) +## Return a string of ones and zeros representing the conversion of the integer +## @var{d} to a binary number. ## -## For example: +## If @var{d} is negative, return the two's complement binary value of @var{d}. +## If @var{d} is a matrix or cell array, return a string matrix with one row +## for each element in @var{d}, padded with leading zeros to the width of the +## largest value. +## +## The optional second argument, @var{len}, specifies the minimum number of +## digits in the result. +## +## Examples: ## ## @example ## @group ## dec2bin (14) ## @result{} "1110" +## +## dec2bin (-14) +## @result{} "11110010" ## @end group ## @end example ## -## If @var{d} is a matrix or cell array, return a string matrix with one row -## per element in @var{d}, padded with leading zeros to the width of the -## largest value. +## Programming Notes: The largest negative value that can be converted in to +## two's complement is @code{- (flintmax () / 2)}. ## -## The optional second argument, @var{len}, specifies the minimum number of -## digits in the result. ## @seealso{bin2dec, dec2base, dec2hex} ## @end deftypefn function b = dec2bin (d, len) + if (nargin == 0) + print_usage (); + endif + + if (iscell (d)) + d = cell2mat (d); + endif + ## Create column vector for algorithm (output is always col. vector anyways) + d = d(:); + + lt_zero_idx = (d < 0); + if (any (lt_zero_idx)) + ## FIXME: Need an algorithm that works with larger values such as int64. + if (any (d(lt_zero_idx) < -2^52)) + error ("dec2bin: negative inputs cannot be less than -flintmax () / 2"); + elseif (any (d(lt_zero_idx) < intmin ("int32"))) + d(lt_zero_idx) += flintmax (); + elseif (any (d < intmin ("int16"))) + d(lt_zero_idx) += double (intmax ("uint32")) + 1; + elseif (any (d < intmin ("int8"))) + d(lt_zero_idx) += double (intmax ("uint16"))+ 1; + else + d(lt_zero_idx) += double (intmax ("uint8")) + 1; + endif + endif + if (nargin == 1) b = dec2base (d, 2); - elseif (nargin == 2) + else b = dec2base (d, 2, len); - else - print_usage (); endif endfunction +%!assert (dec2bin (3), "11") %!assert (dec2bin (14), "1110") %!assert (dec2bin (14, 6), "001110") +%!assert (dec2bin ([1, 2; 3, 4]), ["001"; "011"; "010"; "100"]) %!assert (dec2bin ({1, 2; 3, 4}), ["001"; "011"; "010"; "100"]) +%!assert (dec2bin ({1, 2; 3, 4}, 4), ["0001"; "0011"; "0010"; "0100"]) + +## Test negative inputs +%!assert (dec2bin (-3), "11111101") +%!assert (dec2bin (-3, 3), "11111101") +%!assert (dec2bin (-3, 9), "011111101") +%!assert (dec2bin (-2^7 -1), "1111111101111111") +%!assert (dec2bin (-2^15 -1), "11111111111111110111111111111111") +## FIXME: Matlab generates a string that is 64 characters long +%!assert (dec2bin (-2^31 -1), +%! "11111111111111111111101111111111111111111111111111111") +%!assert (dec2bin (-2^52), +%! "10000000000000000000000000000000000000000000000000000") +## FIXME: Uncomment when support for int64 is added +%!#assert (dec2bin (-2^63), +%! "1000000000000000000000000000000000000000000000000000000000000000") +%!#test +%! assert (dec2bin (int64 (-2^63)), +%! "1000000000000000000000000000000000000000000000000000000000000000"); +%!#test +%! assert (dec2bin (int64 (-2^63) -1), +%! "1000000000000000000000000000000000000000000000000000000000000000"); +%!#test +%! assert (dec2bin (int64 (-2^63) +1), +%! "1000000000000000000000000000000000000000000000000000000000000001"); +%!assert (dec2bin ([-1, -2; -3, -4]), +%! ["11111111"; "11111101"; "11111110"; "11111100"]) +%!assert (dec2bin ([1, 2; 3, -4]), +%! ["00000001"; "00000011"; "00000010"; "11111100"]) +%!assert (dec2bin ({1, 2; 3, -4}), +%! ["00000001"; "00000011"; "00000010"; "11111100"]) ## Test input validation -%!error dec2bin () -%!error dec2bin (1, 2, 3) +%!error <Invalid call> dec2bin () +%!error <negative inputs cannot be less than> dec2bin (- flintmax ()) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/dec2hex.m --- a/scripts/strings/dec2hex.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/dec2hex.m Thu Nov 19 13:08:00 2020 -0800 @@ -24,36 +24,66 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {} dec2hex (@var{d}, @var{len}) -## Return the hexadecimal string corresponding to the non-negative integer -## @var{d}. +## @deftypefn {} {} dec2hex (@var{d}) +## @deftypefnx {} {} dec2hex (@var{d}, @var{len}) +## Return a string representing the conversion of the integer @var{d} to a +## hexadecimal (base16) number. ## -## For example: +## If @var{d} is negative, return the two's complement binary value of @var{d}. +## If @var{d} is a matrix or cell array, return a string matrix with one row +## for each element in @var{d}, padded with leading zeros to the width of the +## largest value. +## +## The optional second argument, @var{len}, specifies the minimum number of +## digits in the result. +## +## Examples: ## ## @example ## @group ## dec2hex (2748) ## @result{} "ABC" +## +## dec2hex (-2) +## @result{} "FE" ## @end group ## @end example ## -## If @var{d} is a matrix or cell array, return a string matrix with one row -## per element in @var{d}, padded with leading zeros to the width of the -## largest value. -## -## The optional second argument, @var{len}, specifies the minimum number of -## digits in the result. ## @seealso{hex2dec, dec2base, dec2bin} ## @end deftypefn function h = dec2hex (d, len) + if (nargin == 0) + print_usage (); + endif + + if (iscell (d)) + d = cell2mat (d); + endif + ## Create column vector for algorithm (output is always col. vector anyways) + d = d(:); + + lt_zero_idx = (d < 0); + if (any (lt_zero_idx)) + ## FIXME: Need an algorithm that works with larger values such as int64. + if (any (d(lt_zero_idx) < -2^52)) + error ("dec2hex: negative inputs cannot be less than -flintmax () / 2"); + elseif (any (d(lt_zero_idx) < intmin ("int32"))) + d(lt_zero_idx) += flintmax (); + elseif (any (d < intmin ("int16"))) + d(lt_zero_idx) += double (intmax ("uint32")) + 1; + elseif (any (d < intmin ("int8"))) + d(lt_zero_idx) += double (intmax ("uint16"))+ 1; + else + d(lt_zero_idx) += double (intmax ("uint8")) + 1; + endif + endif + if (nargin == 1) h = dec2base (d, 16); - elseif (nargin == 2) + else h = dec2base (d, 16, len); - else - print_usage (); endif endfunction @@ -61,8 +91,36 @@ %!assert (dec2hex (2748), "ABC") %!assert (dec2hex (2748, 5), "00ABC") +%!assert (dec2hex ([2748, 2746]), ["ABC"; "ABA"]) %!assert (dec2hex ({2748, 2746}), ["ABC"; "ABA"]) +%!assert (dec2hex ({2748, 2746}, 4), ["0ABC"; "0ABA"]) + +## Test negative inputs +%!assert (dec2hex (-3), "FD") +%!assert (dec2hex (-3, 1), "FD") +%!assert (dec2hex (-3, 3), "0FD") +%!assert (dec2hex (-2^7 -1), "FF7F") +%!assert (dec2hex (-2^15 -1), "FFFF7FFF") +## FIXME: Matlab returns longer string that begins with 'F' +%!assert (dec2hex (-2^31 -1), "1FFFFF7FFFFFFF") +## FIXME: Matlab returns longer string that begins with 'FFF' +%!assert (dec2hex (-2^52), "10000000000000") +## FIXME: Uncomment when support for int64 is added +%!#assert (dec2hex (-2^63), +%! "1000000000000000000000000000000000000000000000000000000000000000") +%!#test +%! assert (dec2hex (int64 (-2^63)), +%! "1000000000000000000000000000000000000000000000000000000000000000"); +%!#test +%! assert (dec2hex (int64 (-2^63) -1), +%! "1000000000000000000000000000000000000000000000000000000000000000"); +%!#test +%! assert (dec2hex (int64 (-2^63) +1), +%! "1000000000000000000000000000000000000000000000000000000000000001"); +%!assert (dec2hex ([-1, -2; -3, -4]), ["FF"; "FD"; "FE"; "FC"]) +%!assert (dec2hex ([1, 2; 3, -4]), ["01"; "03"; "02"; "FC"]) +%!assert (dec2hex ({1, 2; 3, -4}), ["01"; "03"; "02"; "FC"]) ## Test input validation -%!error dec2hex () -%!error dec2hex (1, 2, 3) +%!error <Invalid call> dec2hex () +%!error <negative inputs cannot be less than> dec2hex (- flintmax ()) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/endsWith.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/strings/endsWith.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,173 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{retval} =} endsWith (@var{str}, @var{pattern}) +## @deftypefnx {} {@var{retval} =} endsWith (@var{str}, @var{pattern}, "IgnoreCase", @var{ignore_case}) +## Check whether string(s) end with pattern(s). +## +## Return an array of logical values that indicates which string(s) in the +## input @var{str} (a single string or cell array of strings) end with +## the input @var{pattern} (a single string or cell array of strings). +## +## If the value of the parameter @qcode{"IgnoreCase"} is true, then the +## function will ignore the letter case of @var{str} and @var{pattern}. By +## default, the comparison is case sensitive. +## +## Examples: +## +## @example +## @group +## ## one string and one pattern while considering case +## endsWith ("hello", "lo") +## @result{} 1 +## @end group +## +## @group +## ## one string and one pattern while ignoring case +## endsWith ("hello", "LO", "IgnoreCase", true) +## @result{} 1 +## @end group +## +## @group +## ## multiple strings and multiple patterns while considering case +## endsWith (@{"tests.txt", "mydoc.odt", "myFunc.m", "results.pptx"@}, +## @{".docx", ".odt", ".txt"@}) +## @result{} 1 1 0 0 +## @end group +## +## @group +## ## multiple strings and one pattern while considering case +## endsWith (@{"TESTS.TXT", "mydoc.odt", "result.txt", "myFunc.m"@}, +## ".txt", "IgnoreCase", false) +## @result{} 0 0 1 0 +## @end group +## +## @group +## ## multiple strings and one pattern while ignoring case +## endsWith (@{"TESTS.TXT", "mydoc.odt", "result.txt", "myFunc.m"@}, +## ".txt", "IgnoreCase", true) +## @result{} 1 0 1 0 +## @end group +## @end example +## +## @seealso{startsWith, regexp, strncmp, strncmpi} +## @end deftypefn + +function retval = endsWith (str, pattern, IgnoreCase, ignore_case) + + if (nargin != 2 && nargin != 4) + print_usage (); + endif + + ## Validate input str and pattern + if (! (iscellstr (str) || ischar (str))) + error ("endsWith: STR must be a string or cell array of strings"); + endif + if (! (iscellstr (pattern) || ischar (pattern))) + error ("endsWith: PATTERN must be a string or cell array of strings"); + endif + + ## reverse str and pattern + str = cellfun (@flip, cellstr (str), "UniformOutput", false); + pattern = cellfun (@flip, cellstr (pattern), "UniformOutput", false); + + if (nargin == 2) + ignore_case = false; + else + ## For Matlab compatibility accept any abbreviation of 3rd argument + if (! ischar (IgnoreCase) || isempty (IgnoreCase) + || ! strncmpi (IgnoreCase, "IgnoreCase", length (IgnoreCase))) + error ('endsWith: third input must be "IgnoreCase"'); + endif + + if (! isscalar (ignore_case) || ! isreal (ignore_case)) + error ('endsWith: "IgnoreCase" value must be a logical scalar'); + endif + ignore_case = logical (ignore_case); + endif + + retval = false (size (str)); + if (ignore_case) + for j = 1:numel (pattern) + retval |= strncmpi (str, pattern{j}, length (pattern{j})); + endfor + else + for j = 1:numel (pattern) + retval |= strncmp (str, pattern{j}, length (pattern{j})); + endfor + endif + +endfunction + + +## Test simple use with one string and one pattern +%!assert (endsWith ("hello", "lo")) +%!assert (! endsWith ("hello", "LO")) +%!assert (endsWith ("hello", "LO", "i", 5)) +%!assert (! endsWith ("hello", "no")) + +## Test multiple strings with a single pattern +%!test +%! str = {"myFile.odt", "results.ppt", "myCode.m"; ... +%! "data-analysis.ppt", "foundations.txt", "data.odt"}; +%! pattern = ".odt"; +%! expected = [true, false, false; false, false, true]; +%! assert (endsWith (str, pattern), expected); + +## Test multiple strings with multiple patterns +%!test +%! str = {"tests.txt", "mydoc.odt", "myFunc.m", "results.pptx"}; +%! pattern = {".docx", ".odt", ".txt"}; +%! expected = [true, true, false, false]; +%! assert (endsWith (str, pattern), expected); + +## Test IgnoreCase +%!test +%! str = {"TESTS.TXT", "mydoc.odt", "result.txt", "myFunc.m"}; +%! pattern = ".txt"; +%! expected_ignore = [true, false, true, false]; +%! expected_wo_ignore = [false, false, true, false]; +%! assert (endsWith (str, pattern, "IgnoreCase", true), expected_ignore); +%! assert (endsWith (str, pattern, "IgnoreCase", false), expected_wo_ignore); +%! assert (endsWith (str, pattern, "I", 500), expected_ignore); +%! assert (endsWith (str, pattern, "iG", 0), expected_wo_ignore); + +## Test input validation +%!error <Invalid call> endsWith () +%!error endsWith ("A") +%!error endsWith ("A", "B", "C") +%!error endsWith ("A", "B", "C", "D", "E") +%!error <STR must be a string> endsWith (152, "hi") +%!error <STR must be a .* cell array of strings> endsWith ({152}, "hi") +%!error <PATTERN must be a string> endsWith ("hi", 152) +%!error <PATTERN must be a .* cell array of strings> endsWith ("hi", {152}) +%!error <third input must be "IgnoreCase"> endsWith ("hello", "lo", 1, 1) +%!error <third input must be "IgnoreCase"> endsWith ("hello", "lo", "", 1) +%!error <third input must be "IgnoreCase"> endsWith ("hello", "lo", "foo", 1) +%!error <"IgnoreCase" value must be a logical scalar> +%! endsWith ("hello", "hi", "i", "true"); +%!error <"IgnoreCase" value must be a logical scalar> +%! endsWith ("hello", "hi", "i", {true}); diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/erase.m --- a/scripts/strings/erase.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/erase.m Thu Nov 19 13:08:00 2020 -0800 @@ -64,7 +64,7 @@ ## @end group ## @end example ## -## See @code{strrep} for processing overlaps. +## For processing overlaps, @pxref{XREFstrrep,,@code{strrep}}. ## ## @seealso{strrep, regexprep} ## @end deftypefn @@ -143,7 +143,7 @@ %!assert (erase ({'Hello World t '}, {'ld '; 'o '}), {'HellWort '}) ## Test input validation -%!error erase () +%!error <Invalid call> erase () %!error erase ("a") %!error erase ("a", "b", "c") %!error <STR must be a string> erase ([1], "foo") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/hex2dec.m --- a/scripts/strings/hex2dec.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/hex2dec.m Thu Nov 19 13:08:00 2020 -0800 @@ -50,7 +50,7 @@ function d = hex2dec (s) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -65,6 +65,5 @@ %!assert (hex2dec ({"A1", "1A"}), [161; 26]) ## Test input validation -%!error hex2dec () -%!error hex2dec (1) -%!error hex2dec ("1", 2) +%!error <Invalid call> hex2dec () +%!error <S must be a string> hex2dec (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/index.m --- a/scripts/strings/index.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/index.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,7 +48,7 @@ function n = index (s, t, direction = "first") - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -113,7 +113,7 @@ %! assert (index (str, "o", "last"), [5; 2; 3; 2]); ## Test input validation -%!error index () +%!error <Invalid call> index () %!error index ("a") %!error index ("a", "b", "first", "d") %!error index (1, "bar") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/isletter.m --- a/scripts/strings/isletter.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/isletter.m Thu Nov 19 13:08:00 2020 -0800 @@ -34,7 +34,7 @@ function retval = isletter (s) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -43,5 +43,5 @@ endfunction -%!error isletter () +%!error <Invalid call> isletter () %!error isletter ("a", "b") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/isstring.m --- a/scripts/strings/isstring.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/isstring.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,7 +42,7 @@ function retval = isstring (s) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -59,5 +59,5 @@ %!assert (isstring ({'a'}), false) %!assert (isstring ({"b"}), false) -%!error isstring () +%!error <Invalid call> isstring () %!error isstring ("a", "b") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/isstrprop.m --- a/scripts/strings/isstrprop.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/isstrprop.m Thu Nov 19 13:08:00 2020 -0800 @@ -137,7 +137,7 @@ %!assert (isstrprop ({"AbC", "123"}, "lower"), {logical([0 1 0]), logical([0 0 0])}) ## Test input validation -%!error isstrprop () +%!error <Invalid call> isstrprop () %!error isstrprop ("abc123") %!error isstrprop ("abc123", "alpha", "alpha") %!error <invalid string property> isstrprop ("abc123", "foo") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/mat2str.m --- a/scripts/strings/mat2str.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/mat2str.m Thu Nov 19 13:08:00 2020 -0800 @@ -65,7 +65,7 @@ function s = mat2str (x, n = 15, cls = "") - if (nargin < 1 || nargin > 3 || ! (isnumeric (x) || islogical (x))) + if (nargin < 1 || ! (isnumeric (x) || islogical (x))) print_usage (); elseif (ndims (x) > 2) error ("mat2str: X must be two dimensional"); @@ -151,8 +151,7 @@ %!assert (mat2str (logical ([0 1; 0 0])), "[false true;false false]") ## Test input validation -%!error mat2str () -%!error mat2str (1,2,3,4) +%!error <Invalid call> mat2str () %!error mat2str (["Hello"]) %!error <X must be two dimensional> mat2str (ones (3,3,2)) %!error <N must have only 1 or 2 elements> mat2str (ones (3,3), [1 2 3]) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/module.mk --- a/scripts/strings/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/base2dec.m \ %reldir%/bin2dec.m \ %reldir%/blanks.m \ @@ -9,6 +10,7 @@ %reldir%/dec2base.m \ %reldir%/dec2bin.m \ %reldir%/dec2hex.m \ + %reldir%/endsWith.m \ %reldir%/erase.m \ %reldir%/hex2dec.m \ %reldir%/index.m \ @@ -20,6 +22,7 @@ %reldir%/ostrsplit.m \ %reldir%/regexptranslate.m \ %reldir%/rindex.m \ + %reldir%/startsWith.m \ %reldir%/str2num.m \ %reldir%/strcat.m \ %reldir%/strchr.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/native2unicode.m --- a/scripts/strings/native2unicode.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/native2unicode.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,7 +45,7 @@ function utf8_str = native2unicode (native_bytes, codepage = "") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -59,7 +59,7 @@ endif if (! ischar (codepage)) - error ("native2unicode: CODEPAGE must be a string") + error ("native2unicode: CODEPAGE must be a string"); endif ## FIXME: Would it be better to do this by converting to uint8? Or to @@ -88,12 +88,12 @@ %! assert (double (native2unicode ([164:166 0 167:170], 'ISO-8859-5')), %! [208 132 208 133 208 134 0 208 135 208 136 208 137 208 138]); -%!assert (native2unicode ("foobar"), "foobar"); +%!assert (native2unicode ("foobar"), "foobar") %!assert <*54384> (double (native2unicode ([0 0 120.3 0 0 122.6 0 0])), -%! [0 0 120 0 0 123 0 0]); +%! [0 0 120 0 0 123 0 0]) %!error <Invalid call> native2unicode () -%!error <Invalid call> native2unicode (1, 'ISO-8859-1', 'test') +%!error <called with too many inputs> native2unicode (1, 'ISO-8859-1', 'test') %!error <NATIVE_BYTES must be a numeric vector> native2unicode ([1 2; 3 4]) %!error <NATIVE_BYTES must be a numeric vector> native2unicode ({1 2 3 4}) %!error <CODEPAGE must be a string> native2unicode (164:170, 123) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/ostrsplit.m --- a/scripts/strings/ostrsplit.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/ostrsplit.m Thu Nov 19 13:08:00 2020 -0800 @@ -62,7 +62,7 @@ function cstr = ostrsplit (s, sep, strip_empty = false) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); elseif (! ischar (s) || ! ischar (sep)) error ("ostrsplit: S and SEP must be string values"); @@ -119,7 +119,7 @@ %!assert (ostrsplit (char ("a,bc", ",de"), ", ", true), {"a", "bc", "de"}) ## Test input validation -%!error ostrsplit () +%!error <Invalid call> ostrsplit () %!error ostrsplit ("abc") %!error ostrsplit ("abc", "b", true, 4) %!error <S and SEP must be string values> ostrsplit (123, "b") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/regexptranslate.m --- a/scripts/strings/regexptranslate.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/regexptranslate.m Thu Nov 19 13:08:00 2020 -0800 @@ -89,6 +89,6 @@ ## Test input validation %!error <Invalid call to regexptranslate> regexptranslate () %!error <Invalid call to regexptranslate> regexptranslate ("wildcard") -%!error <Invalid call to regexptranslate> regexptranslate ("a", "b", "c") +%!error <called with too many inputs> regexptranslate ("a", "b", "c") %!error <invalid operation> regexptranslate ("foo", "abc") %!error <operation OP must be a string> regexptranslate (10, "abc") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/rindex.m --- a/scripts/strings/rindex.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/rindex.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,6 +67,6 @@ %! assert (rindex (str, "o"), [5; 2; 3; 2]); ## Test input validation -%!error rindex () +%!error <Invalid call> rindex () %!error rindex ("foo") %!error rindex ("foo", "bar", "last") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/startsWith.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/strings/startsWith.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,172 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{retval} =} startsWith (@var{str}, @var{pattern}) +## @deftypefnx {} {@var{retval} =} startsWith (@var{str}, @var{pattern}, "IgnoreCase", @var{ignore_case}) +## Check whether string(s) start with pattern(s). +## +## Return an array of logical values that indicates which string(s) in the +## input @var{str} (a single string or cell array of strings) begin with +## the input @var{pattern} (a single string or cell array of strings). +## +## If the value of the parameter @qcode{"IgnoreCase"} is true, then the +## function will ignore the letter case of @var{str} and @var{pattern}. By +## default, the comparison is case sensitive. +## +## Examples: +## +## @example +## @group +## ## one string and one pattern while considering case +## startsWith ("hello", "he") +## @result{} 1 +## @end group +## +## @group +## ## one string and one pattern while ignoring case +## startsWith ("hello", "HE", "IgnoreCase", true) +## @result{} 1 +## @end group +## +## @group +## ## multiple strings and multiple patterns while considering case +## startsWith (@{"lab work.pptx", "data.txt", "foundations.ppt"@}, +## @{"lab", "data"@}) +## @result{} 1 1 0 +## @end group +## +## @group +## ## multiple strings and one pattern while considering case +## startsWith (@{"DATASHEET.ods", "data.txt", "foundations.ppt"@}, +## "data", "IgnoreCase", false) +## @result{} 0 1 0 +## @end group +## +## @group +## ## multiple strings and one pattern while ignoring case +## startsWith (@{"DATASHEET.ods", "data.txt", "foundations.ppt"@}, +## "data", "IgnoreCase", true) +## @result{} 1 1 0 +## @end group +## @end example +## +## @seealso{endsWith, regexp, strncmp, strncmpi} +## @end deftypefn + +function retval = startsWith (str, pattern, IgnoreCase, ignore_case) + + if (nargin != 2 && nargin != 4) + print_usage (); + endif + + ## Validate input str and pattern + if (! (iscellstr (str) || ischar (str))) + error ("startsWith: STR must be a string or cell array of strings"); + endif + if (! (iscellstr (pattern) || ischar (pattern))) + error ("startsWith: PATTERN must be a string or cell array of strings"); + endif + + str = cellstr (str); + pattern = cellstr (pattern); + + if (nargin == 2) + ignore_case = false; + else + ## For Matlab compatibility accept any abbreviation of 3rd argument + if (! ischar (IgnoreCase) || isempty (IgnoreCase) + || ! strncmpi (IgnoreCase, "IgnoreCase", length (IgnoreCase))) + error ('startsWith: third input must be "IgnoreCase"'); + endif + + if (! isscalar (ignore_case) || ! isreal (ignore_case)) + error ('startsWith: "IgnoreCase" value must be a logical scalar'); + endif + ignore_case = logical (ignore_case); + endif + + retval = false (size (str)); + if (ignore_case) + for j = 1:numel (pattern) + retval |= strncmpi (str, pattern{j}, length (pattern{j})); + endfor + else + for j = 1:numel (pattern) + retval |= strncmp (str, pattern{j}, length (pattern{j})); + endfor + endif + +endfunction + + +## Test simple use with one string and one pattern +%!assert (startsWith ("hello", "he")) +%!assert (! startsWith ("hello", "HE")) +%!assert (startsWith ("hello", "HE", "i", 5)) +%!assert (! startsWith ("hello", "no")) + +## Test multiple strings with a single pattern +%!test +%! str = {"data science", "dataSheet.ods", "myFunc.m"; "foundations.ppt", ... +%! "results.txt", "myFile.odt"}; +%! pattern = "data"; +%! expected = [true, true, false; false, false, false]; +%! assert (startsWith (str, pattern), expected); + +## Test multiple strings with multiple patterns +%!test +%! str = {"lab work.pptx", "myFile.odt", "data.txt", "foundations.ppt"}; +%! pattern = {"lab", "data"}; +%! expected = [true, false, true, false]; +%! assert (startsWith (str, pattern), expected); + +## Test IgnoreCase +%!test +%! str = {"DATASHEET.ods", "myFile.odt", "data.txt", "foundations.ppt"}; +%! pattern = "data"; +%! expected_ignore = [true, false, true, false]; +%! expected_wo_ignore = [false, false, true, false]; +%! assert (startsWith (str, pattern, "IgnoreCase", true), expected_ignore); +%! assert (startsWith (str, pattern, "IgnoreCase", false), expected_wo_ignore); +%! assert (startsWith (str, pattern, "I", 500), expected_ignore); +%! assert (startsWith (str, pattern, "iG", 0), expected_wo_ignore); + +## Test input validation +%!error <Invalid call> startsWith () +%!error startsWith ("A") +%!error startsWith ("A", "B", "C") +%!error startsWith ("A", "B", "C", "D", "E") +%!error <STR must be a string> startsWith (152, "hi") +%!error <STR must be a .* cell array of strings> startsWith ({152}, "hi") +%!error <PATTERN must be a string> startsWith ("hi", 152) +%!error <PATTERN must be a .* cell array of strings> startsWith ("hi", {152}) +%!error <third input must be "IgnoreCase"> startsWith ("hello", "he", 1, 1) +%!error <third input must be "IgnoreCase"> startsWith ("hello", "he", "", 1) +%!error <third input must be "IgnoreCase"> startsWith ("hello", "he", "foo", 1) +%!error <"IgnoreCase" value must be a logical scalar> +%! startsWith ("hello", "hi", "i", "true"); +%!error <"IgnoreCase" value must be a logical scalar> +%! startsWith ("hello", "hi", "i", {true}); diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/str2num.m --- a/scripts/strings/str2num.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/str2num.m Thu Nov 19 13:08:00 2020 -0800 @@ -55,7 +55,7 @@ function [m, state] = str2num (s) - if (nargin != 1) + if (nargin < 1) print_usage (); elseif (! ischar (s)) error ("str2num: S must be a string or string array"); @@ -90,6 +90,5 @@ %! assert (! state); ## Test input validation -%!error str2num () -%!error str2num ("string", 1) +%!error <Invalid call> str2num () %!error <S must be a string> str2num ({"string"}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/strchr.m --- a/scripts/strings/strchr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/strchr.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ function varargout = strchr (str, chars, varargin) - if (nargin < 2) + if (nargin < 2 || nargin > 4) print_usage (); elseif (! ischar (str)) error ("strchr: STR argument must be a string or string array"); @@ -82,7 +82,8 @@ %!assert (strchr ("Octave is the best software", "software"), [3, 4, 6, 9, 11, 13, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27]) ## Test input validation -%!error strchr () -%!error strchr (1) +%!error <Invalid call> strchr () +%!error <Invalid call> strchr (1) +%!error <Invalid call> strchr ("s", "a", 1, "last", 5) %!error <STR argument must be a string> strchr (1, "aeiou") %!error <CHARS argument must be a string> strchr ("aeiou", 1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/strjoin.m --- a/scripts/strings/strjoin.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/strjoin.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,11 +49,9 @@ ## @seealso{strsplit} ## @end deftypefn -function rval = strjoin (cstr, delimiter) +function rval = strjoin (cstr, delimiter = " ") - if (nargin == 1) - delimiter = " "; - elseif (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (! (iscellstr (cstr) && (ischar (delimiter) || iscellstr (delimiter)))) print_usage (); diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/strjust.m --- a/scripts/strings/strjust.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/strjust.m Thu Nov 19 13:08:00 2020 -0800 @@ -51,7 +51,7 @@ function y = strjust (s, pos = "right") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (! ischar (s) || ndims (s) > 2) error ("strjust: S must be a string or 2-D character matrix"); @@ -113,6 +113,6 @@ ## Test input validation %!error <Invalid call to strjust> strjust () -%!error <Invalid call to strjust> strjust (["a";"ab"], "center", 1) +%!error <called with too many inputs> strjust (["a";"ab"], "center", 1) %!error <S must be a string> strjust (ones (3,3)) %!error <S must be a string> strjust (char (ones (3,3,3))) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/strsplit.m --- a/scripts/strings/strsplit.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/strsplit.m Thu Nov 19 13:08:00 2020 -0800 @@ -187,7 +187,7 @@ if (! ischar (str) || (! ischar (del) && ! iscellstr (del))) error ("strsplit: S and DEL must be string values"); elseif (! isempty (str) && ! isrow (str)) - error ("strsplit: S must be a char row vector") + error ("strsplit: S must be a char row vector"); elseif (! isscalar (args.collapsedelimiters)) error ("strsplit: COLLAPSEDELIMITERS must be a scalar value"); endif @@ -314,7 +314,7 @@ %!assert <*47403> (strsplit ('xxx+yyy', '+'), {"xxx", "yyy"}) ## Test input validation -%!error strsplit () +%!error <Invalid call> strsplit () %!error strsplit ("abc", "b", true, 4) %!error <invalid parameter name, 'foo'> strsplit ("abc", "b", "foo", "true") %!error <S and DEL must be string values> strsplit (123, "b") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/strtok.m --- a/scripts/strings/strtok.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/strtok.m Thu Nov 19 13:08:00 2020 -0800 @@ -58,12 +58,12 @@ function [tok, rem] = strtok (str, delim) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); elseif (! (ischar (str) || iscellstr (str))) - error ("strtok: STR must be a string or cell array of strings."); + error ("strtok: STR must be a string or cell array of strings"); elseif (ischar (str) && ! isvector (str) &&! isempty (str)) - error ("strtok: STR cannot be a 2-D character array."); + error ("strtok: STR cannot be a 2-D character array"); endif if (nargin < 2 || isempty (delim)) @@ -137,7 +137,7 @@ if (isargout (2)) rem = cell (size (str)); rem(eidx) = {""}; - rem(midx) = tmp(2:2:end); + rem (midx) = tmp(2:2:end); endif endif @@ -229,7 +229,6 @@ %! endfor ## Test input validation -%!error strtok () -%!error strtok ("a", "b", "c") +%!error <Invalid call> strtok () %!error <STR must be a string> strtok (1, "b") %!error <STR cannot be a 2-D> strtok (char ("hello", "world"), "l") diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/strtrim.m --- a/scripts/strings/strtrim.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/strtrim.m Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ function s = strtrim (s) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -90,6 +90,6 @@ %!assert (strtrim ({" abc ", {" def "}}), {"abc", {"def"}}) %!error <Invalid call to strtrim> strtrim () -%!error <Invalid call to strtrim> strtrim ("abc", "def") +%!error <called with too many inputs> strtrim ("abc", "def") %!error <argument must be a string> strtrim (1) %!error <argument must be a string> strtrim ({[]}) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/strtrunc.m --- a/scripts/strings/strtrunc.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/strtrunc.m Thu Nov 19 13:08:00 2020 -0800 @@ -78,7 +78,7 @@ %! assert (y{2}, repmat ("line", 2, 1)); ## Test input validation -%!error strtrunc () +%!error <Invalid call> strtrunc () %!error strtrunc ("abcd") %!error strtrunc ("abcd", 4, 5) %!error <N must be a positive integer> strtrunc ("abcd", ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/substr.m --- a/scripts/strings/substr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/substr.m Thu Nov 19 13:08:00 2020 -0800 @@ -54,7 +54,7 @@ function t = substr (s, offset, len) - if (nargin < 2 || nargin > 3) + if (nargin < 2) print_usage (); endif @@ -104,7 +104,7 @@ %!assert (isempty (substr ("This is a test string", 1, 0))) ## Test input validation -%!error substr () +%!error <Invalid call> substr () %!error substr ("foo", 2, 3, 4) %!error substr (ones (5, 1), 1, 1) %!error substr ("foo", ones (2,2)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/unicode2native.m --- a/scripts/strings/unicode2native.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/unicode2native.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,7 +45,7 @@ function native_bytes = unicode2native (utf8_str, codepage = "") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -73,7 +73,7 @@ %! uint8 ([164:166 0 167:170])); %!error <Invalid call> unicode2native () -%!error <Invalid call> unicode2native ('a', 'ISO-8859-1', 'test') +%!error <called with too many inputs> unicode2native ('a', 'ISO-8859-1', 'test') %!error <UTF8_STR must be a character vector> unicode2native (['ab'; 'cd']) %!error <UTF8_STR must be a character vector> unicode2native ({1 2 3 4}) %!error <CODEPAGE must be a string> unicode2native ('ЄЅІЇЈЉЊ', 123) diff -r dc3ee9616267 -r fa2cdef14442 scripts/strings/untabify.m --- a/scripts/strings/untabify.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/strings/untabify.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ function s = untabify (t, tw = 8, deblank_arg = false) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); elseif (! (ischar (t) || iscellstr (t))) error ("untabify: T must be a string or cellstring"); @@ -122,6 +122,6 @@ %! s = char (randi ([97 97+25], 3, 3)); %! assert (untabify (s), char (untabify (cellstr (s)))); -%!error untabify () -%!error untabify (1,2,3,4) +## Test input validation +%!error <Invalid call> untabify () %!error <must be a string> untabify (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/__debug_octave__.m --- a/scripts/testfun/__debug_octave__.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/__debug_octave__.m Thu Nov 19 13:08:00 2020 -0800 @@ -45,10 +45,6 @@ function __debug_octave__ (command_string) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) if (ismac ()) status = system ("lldb --version"); diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/assert.m --- a/scripts/testfun/assert.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/assert.m Thu Nov 19 13:08:00 2020 -0800 @@ -682,8 +682,8 @@ %! end_try_catch ## test input validation -%!error assert () -%!error assert (1,2,3,4) +%!error <Invalid call> assert () +%!error <Invalid call> assert (1,2,3,4) ## Convert all error indices into tuple format diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/demo.m --- a/scripts/testfun/demo.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/demo.m Thu Nov 19 13:08:00 2020 -0800 @@ -103,7 +103,7 @@ function demo (name, n = 0) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -186,8 +186,7 @@ %! #------------------------------------------------- %! # the figure window shows one cycle of a sine wave -%!error demo () -%!error demo (1, 2, 3) +%!error <Invalid call> demo () %!error <N must be a scalar integer> demo ("demo", {1}) %!error <N must be a scalar integer> demo ("demo", ones (2,2)) %!error <N must be a scalar integer> demo ("demo", 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/example.m --- a/scripts/testfun/example.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/example.m Thu Nov 19 13:08:00 2020 -0800 @@ -39,13 +39,13 @@ ## a string @var{s}, with @var{idx} indicating the ending position of the ## various examples. ## -## See @code{demo} for a complete explanation. +## For a complete explanation @pxref{XREFdemo,,@code{demo}}. ## @seealso{demo, test} ## @end deftypefn function [ex_code, ex_idx] = example (name, n = 0) - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif @@ -119,8 +119,7 @@ %! assert (idx, [1, 23, 73]); ## Test input validation -%!error example () -%!error example ("example", 3, 5) +%!error <Invalid call> example () %!error <N must be a scalar integer> example ("example", {1}) %!error <N must be a scalar integer> example ("example", ones (2,2)) %!error <N must be a scalar integer> example ("example", 1.5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/fail.m --- a/scripts/testfun/fail.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/fail.m Thu Nov 19 13:08:00 2020 -0800 @@ -67,7 +67,7 @@ function retval = fail (code, pattern, warning_pattern) - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -157,6 +157,5 @@ %!error <warning failure> fail ("warning ('warning failure')", "warning", "success") ## Test input validation -%!error fail () -%!error fail (1,2,3,4) +%!error <Invalid call> fail () %!error fail (1, "nowarning", "foo") diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/module.mk --- a/scripts/testfun/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -9,6 +9,7 @@ %reldir%/private/html_plot_demos_template.html %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/__debug_octave__.m \ %reldir%/__have_feature__.m \ %reldir%/__printf_assert__.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/oruntests.m --- a/scripts/testfun/oruntests.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/oruntests.m Thu Nov 19 13:08:00 2020 -0800 @@ -41,7 +41,7 @@ if (nargin == 0) dirs = ostrsplit (path (), pathsep ()); do_class_dirs = true; - elseif (nargin == 1) + else dirs = {canonicalize_file_name(directory)}; if (isempty (dirs{1}) || ! isfolder (dirs{1})) ## Search for directory name in path @@ -55,8 +55,6 @@ dirs = {fullname}; endif do_class_dirs = false; - else - print_usage (); endif for i = 1:numel (dirs) diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/private/compare_plot_demos.m --- a/scripts/testfun/private/compare_plot_demos.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/private/compare_plot_demos.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,7 +57,7 @@ arg.fcn_file = "dump_plot_demos.m"; arg.replace_images = false; - for n = 1:2:numel(varargin) + for n = 1:2:numel (varargin) if (! ischar (varargin{n})) print_usage (); else @@ -68,17 +68,17 @@ if (ischar (arg.toolkits)) arg.toolkits = {arg.toolkits}; elseif (! iscellstr (arg.toolkits)) - error ('compare_plot_demos: Invalid value for "toolkits"') + error ('compare_plot_demos: Invalid value for "toolkits"'); endif if (ischar (arg.directories)) arg.directories = {arg.directories}; elseif (! iscellstr (arg.directories)) - error ('compare_plot_demos: Invalid value for "directory"') + error ('compare_plot_demos: Invalid value for "directory"'); endif if (! ischar (arg.fmt)) - error ('compare_plot_demos: Invalid value for "fmt"') + error ('compare_plot_demos: Invalid value for "fmt"'); endif ## Generate arg.fcn_file for rendering/saving the plot demo images diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/private/dump_demos.m --- a/scripts/testfun/private/dump_demos.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/private/dump_demos.m Thu Nov 19 13:08:00 2020 -0800 @@ -57,10 +57,6 @@ function dump_demos (dirs={"plot/appearance", "plot/draw", "plot/util", "image"}, mfile="dump_plot_demos.m", fmt="png") - if (nargin > 3) - print_usage (); - endif - if (ischar (dirs)) dirs = {dirs}; elseif (! iscellstr (dirs)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/private/html_compare_plot_demos.m --- a/scripts/testfun/private/html_compare_plot_demos.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/private/html_compare_plot_demos.m Thu Nov 19 13:08:00 2020 -0800 @@ -70,12 +70,12 @@ in.plots_per_page = 50; ## Parse inputs - for n = 1:2:numel(varargin) + for n = 1:2:numel (varargin) in.(lower(varargin{n})) = varargin{n+1}; endfor ## Compile a list of all files for all toolkits - for t = 1:numel(toolkits) + for t = 1:numel (toolkits) filter = sprintf ("%s/*.%s", toolkits{t}, in.fmt); in.figfiles = union (in.figfiles, {dir(filter).name}); endfor @@ -87,7 +87,7 @@ anchor = "<!-- ##ADD TABLE HERE## -->"; n = strfind (template, anchor); header = strtrim (template(1:n-1)); - trailer = strtrim (template(n+numel(anchor):end)); + trailer = strtrim (template(n+numel (anchor):end)); page = 1; do @@ -123,7 +123,7 @@ ## Create table header fprintf (fid, "<table>\n<tr>\n"); - for t = 1:numel(toolkits) + for t = 1:numel (toolkits) ## set default column_header = upper (toolkits{t}); if (isfield (in, toolkits{t})) @@ -147,7 +147,7 @@ else err_fn = strrep (ffn, ".png", ".err"); if (! exist (err_fn, "file")) - warning("File %s doesn't exist...", err_fn); + warning ("File %s doesn't exist...", err_fn); else err_fid = fopen (err_fn); msg = char (fread (err_fid))'; diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/speed.m --- a/scripts/testfun/speed.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/speed.m Thu Nov 19 13:08:00 2020 -0800 @@ -159,7 +159,7 @@ ## FIXME: consider two dimensional speedup surfaces for functions like kron. function [__order, __test_n, __tnew, __torig] = speed (__f1, __init, __max_n = 100, __f2 = "", __tol = eps) - if (nargin < 1 || nargin > 6) + if (nargin < 1) print_usage (); endif @@ -243,7 +243,7 @@ __t = min ([__t, __t2, __t3]); endif __torig(k) = __t; - if (! isinf(__tol)) + if (! isinf (__tol)) assert (__v1, __v2, __tol); endif endif @@ -276,7 +276,7 @@ endif if (do_display) - figure; + figure (); ## Strip semicolon added to code fragments before displaying __init(end) = ""; __f1(end) = ""; @@ -403,7 +403,7 @@ %! fstr_build = cstrcat ( %! "function x = build (n)\n", %! " idx = [1:100]';\n", -%! " x = idx(:,ones(1,n));\n", +%! " x = idx(:,ones (1,n));\n", %! " x = reshape (x, 1, n*100);\n", %! "endfunction"); %! @@ -453,5 +453,4 @@ %! assert (length (T_f2) > 10); ## Test input validation -%!error speed () -%!error speed (1, 2, 3, 4, 5, 6, 7) +%!error <Invalid call> speed () diff -r dc3ee9616267 -r fa2cdef14442 scripts/testfun/test.m --- a/scripts/testfun/test.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/testfun/test.m Thu Nov 19 13:08:00 2020 -0800 @@ -115,7 +115,7 @@ ## any built-in demo blocks are extracted but not executed. The text for all ## code blocks is concatenated and returned as @var{code} with @var{idx} being ## a vector of positions of the ends of each demo block. For an easier way to -## extract demo blocks from files, @xref{XREFexample,,example}. +## extract demo blocks from files, @xref{XREFexample,,@code{example}}. ## ## If the second argument is @qcode{"explain"} then @var{name} is ignored and ## an explanation of the line markers used in @code{test} output reports is @@ -137,7 +137,7 @@ persistent __signal_file = ">>>>> "; persistent __signal_skip = "----- "; - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); elseif (! isempty (__name) && ! ischar (__name)) error ("test: NAME must be a string"); @@ -670,7 +670,7 @@ endif ## evaluate code for test, shared, and assert. - if (! isempty(__code)) + if (! isempty (__code)) try eval (sprintf ("function %s__test__(%s)\n%s\nendfunction", __shared_r, __shared, __code)); @@ -727,7 +727,7 @@ && ! strcmp (__type, "xtest") && ! all (__shared == " ")) fputs (__fid, "shared variables "); - eval (sprintf ("fdisp(__fid,var2struct(%s));", __shared)); + eval (sprintf ("fdisp (__fid,var2struct(%s));", __shared)); endif fflush (__fid); endif @@ -915,7 +915,7 @@ function msg = trimerr (msg, prefix) idx = index (msg, [prefix ":"]); if (idx > 0) - msg(1:idx+length(prefix)) = []; + msg(1:idx+length (prefix)) = []; endif msg = strtrim (msg); endfunction @@ -950,7 +950,7 @@ %!fail ("toeplitz ([1,2],[1,2;3,4])", msg2) %!fail ("toeplitz ([1,2;3,4],[1,2])", msg2) %!test fail ("toeplitz", "Invalid call to toeplitz") -%!fail ("toeplitz (1, 2, 3)", "Invalid call to toeplitz") +%!fail ("toeplitz (1, 2, 3)", "called with too many inputs") %!test assert (toeplitz ([1,2,3], [1,4]), [1,4; 2,1; 3,2]) %!assert (toeplitz ([1,2,3], [1,4]), [1,4; 2,1; 3,2]) %!demo toeplitz ([1,2,3,4],[1,5,6]) @@ -984,15 +984,14 @@ ## Test 'fail' keyword %!fail ("test", "Invalid call to test") # no args, generates usage() -%!fail ("test (1,2,3,4)", "usage.*test") # too many args, generates usage() +%!fail ("test (1,2,3,4)", "called with too many inputs") # too many args %!fail ('test ("test", "invalid")', "unknown flag") # incorrect args %!fail ('garbage','garbage.*undefined') # usage on nonexistent function should be ## Test 'error' keyword -%!error test # no args, generates usage() -%!error test (1,2,3,4) # too many args, generates usage() +%!error <Invalid call> test # no args, generates usage() %!error <unknown flag> test ("test", "invalid"); # incorrect args -%!error test ("test", "invalid"); # test without pattern +%!error test ("test", "invalid"); # test without pattern %!error <'garbage' undefined> garbage; # usage on nonexistent function is error ## Test 'warning' keyword @@ -1081,15 +1080,15 @@ ## All of the following tests should fail. These tests should ## be disabled unless you are developing test() since users don't ## like to be presented with known failures. -## %!test error("---------Failure tests. Use test('test','verbose',1)"); -## %!test assert([a,b,c],[1,3,6]); # variables have wrong values +## %!test error ("---------Failure tests. Use test('test','verbose',1)"); +## %!test assert ([a,b,c],[1,3,6]); # variables have wrong values ## %!invalid # unknown block type -## %!error toeplitz([1,2,3]); # correct usage +## %!error toeplitz ([1,2,3]); # correct usage ## %!test syntax errors) # syntax errors fail properly ## %!shared garbage in # variables must be comma separated ## %!error syntax++error # error test fails on syntax errors ## %!error "succeeds."; # error test fails if code succeeds -## %!error <wrong pattern> error("message") # error pattern must match +## %!error <wrong pattern> error ("message") # error pattern must match ## %!demo with syntax error # syntax errors in demo fail properly ## %!shared a,b,c ## %!demo # shared variables not available in demo diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/time/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/addtodate.m --- a/scripts/time/addtodate.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/addtodate.m Thu Nov 19 13:08:00 2020 -0800 @@ -121,10 +121,9 @@ %!assert (addtodate ([d d+1], 1, "month"), [d+31 d+1+31]) ## Test input validation -%!error addtodate () -%!error addtodate (1) -%!error addtodate (1,2) -%!error addtodate (1,2,3,4) +%!error <Invalid call> addtodate () +%!error <Invalid call> addtodate (1) +%!error <Invalid call> addtodate (1,2) %!error <F must be a single character string> addtodate (1,2,3) %!error <F must be a single character string> addtodate (1,2,"month"') %!error <Invalid time unit> addtodate (1,2,"abc") diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/asctime.m --- a/scripts/time/asctime.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/asctime.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,7 @@ function retval = asctime (tm_struct) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -58,5 +58,4 @@ %!assert (asctime (localtime (time ()))(end), "\n") -%!error asctime () -%!error asctime (1, 2) +%!error <Invalid call> asctime () diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/clock.m --- a/scripts/time/clock.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/clock.m Thu Nov 19 13:08:00 2020 -0800 @@ -62,6 +62,6 @@ %!test -%! t1 = clock; +%! t1 = clock (); %! t2 = str2num (strftime ("[%Y, %m, %d, %H, %M, %S]", localtime (time ()))); %! assert (etime (t1, t2) < 1); diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/ctime.m --- a/scripts/time/ctime.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/ctime.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,7 +43,7 @@ function retval = ctime (t) - if (nargin != 1) + if (nargin < 1) print_usage (); endif @@ -58,5 +58,4 @@ %!assert (ctime (time ())(end), "\n") -%!error ctime () -%!error ctime (1, 2) +%!error <Invalid call> ctime () diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/date.m --- a/scripts/time/date.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/date.m Thu Nov 19 13:08:00 2020 -0800 @@ -40,16 +40,9 @@ function retval = date () - if (nargin != 0) - print_usage (); - endif - retval = strftime ("%d-%b-%Y", localtime (time ())); endfunction %!assert (strcmp (date (), strftime ("%d-%b-%Y", localtime (time ())))) - -## Test input validation -%!error date (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/datenum.m --- a/scripts/time/datenum.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/datenum.m Thu Nov 19 13:08:00 2020 -0800 @@ -42,16 +42,17 @@ ## The fractional part, @code{rem (@var{days}, 1)} corresponds to the time ## on the given day. ## -## The input may be a date vector (see @code{datevec}), -## datestr (see @code{datestr}), or directly specified as input. +## The input may be a date vector (@pxref{XREFdatevec,,@code{datevec}}), +## date string (@pxref{XREFdatestr,,@code{datestr}}), or directly specified +## as input. ## ## When processing input datestrings, @var{f} is the format string used to -## interpret date strings (see @code{datestr}). If no format @var{f} is -## specified, then a relatively slow search is performed through various -## formats. It is always preferable to specify the format string @var{f} if -## it is known. Formats which do not specify a particular time component -## will have the value set to zero. Formats which do not specify a date -## will default to January 1st of the current year. +## interpret date strings (@pxref{XREFdatestr,,@code{datestr}}). If no +## format @var{f} is specified, then a relatively slow search is performed +## through various formats. It is always preferable to specify the format +## string @var{f} if it is known. Formats which do not specify a particular +## time component will have the value set to zero. Formats which do not +## specify a date will default to January 1st of the current year. ## ## @var{p} is the year at the start of the century to which two-digit years ## will be referenced. If not specified, it defaults to the current year @@ -109,8 +110,7 @@ persistent monthstart = [306; 337; 0; 31; 61; 92; 122; 153; 184; 214; 245; 275]; persistent monthlength = [31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31]; - if (nargin == 0 || nargin > 6 - || (nargin > 2 && (ischar (year) || iscellstr (year)))) + if (nargin == 0 || (nargin > 2 && (ischar (year) || iscellstr (year)))) print_usage (); endif @@ -251,8 +251,7 @@ %!assert (datenum ("5-19, 2001", "mm-dd, yyyy"), 730990) ## Test input validation -%!error datenum () -%!error datenum (1,2,3,4,5,6,7) +%!error <Invalid call> datenum () %!error <expected date vector containing> datenum ([1, 2]) %!error <expected date vector containing> datenum ([1,2,3,4,5,6,7]) %!error <all inputs must be of class double> datenum (int32 (2000), int32 (1), int32 (1)) diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/datestr.m --- a/scripts/time/datestr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/datestr.m Thu Nov 19 13:08:00 2020 -0800 @@ -30,9 +30,10 @@ ## Format the given date/time according to the format @var{f} and return ## the result in @var{str}. ## -## @var{date} is a serial date number (see @code{datenum}), a date vector (see -## @code{datevec}), or a string or cell array of strings. In the latter case, -## it is passed to @code{datevec} to guess the input date format. +## @var{date} is a serial date number (@pxref{XREFdatenum,,@code{datenum}}), a +## date vector (@pxref{XREFdatevec,,@code{datevec}}), or a string or cell array +## of strings. In the latter case, it is passed to @code{datevec} to guess the +## input date format. ## ## @var{f} can be an integer which corresponds to one of the codes in the table ## below, or a date format string. @@ -175,7 +176,7 @@ names_d = {"S", "M", "T", "W", "T", "F", "S"}; endif - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -368,5 +369,4 @@ %! "00:05:00.000") ## Test input validation -%!error datestr () -%!error datestr (1, 2, 3, 4) +%!error <Invalid call> datestr () diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/datevec.m --- a/scripts/time/datevec.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/datevec.m Thu Nov 19 13:08:00 2020 -0800 @@ -29,19 +29,19 @@ ## @deftypefnx {} {@var{v} =} datevec (@var{date}, @var{p}) ## @deftypefnx {} {@var{v} =} datevec (@var{date}, @var{f}, @var{p}) ## @deftypefnx {} {[@var{y}, @var{m}, @var{d}, @var{h}, @var{mi}, @var{s}] =} datevec (@dots{}) -## Convert a serial date number (see @code{datenum}) or date string (see -## @code{datestr}) into a date vector. +## Convert a serial date number (@pxref{XREFdatenum,,@code{datenum}}) or date +## string (@pxref{XREFdatestr,,@code{datestr}}) into a date vector. ## ## A date vector is a row vector with six members, representing the year, ## month, day, hour, minute, and seconds respectively. ## ## @var{f} is the format string used to interpret date strings -## (see @code{datestr}). If @var{date} is a string, but no format is -## specified, then a relatively slow search is performed through various -## formats. It is always preferable to specify the format string @var{f} if it -## is known. Formats which do not specify a particular time component will -## have the value set to zero. Formats which do not specify a date will -## default to January 1st of the current year. +## (@pxref{XREFdatestr,,@code{datestr}}). If @var{date} is a string, but no +## format is specified, then a relatively slow search is performed through +## various formats. It is always preferable to specify the format string +## @var{f} if it is known. Formats which do not specify a particular time +## component will have the value set to zero. Formats which do not specify a +## date will default to January 1st of the current year. ## ## @var{p} is the year at the start of the century to which two-digit years ## will be referenced. If not specified, it defaults to the current year minus @@ -94,7 +94,7 @@ std_formats{++nfmt} = "mm/dd/yyyy HH:MM"; endif - if (nargin < 1 || nargin > 3) + if (nargin < 1) print_usage (); endif @@ -423,7 +423,6 @@ %! end_unwind_protect ## Test input validation -%!error datevec () -%!error datevec (1,2,3,4) +%!error <Invalid call> datevec () %!error <none of the standard formats match> datevec ("foobar") %!error <DATE not parsed correctly with given format> datevec ("foobar", "%d") diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/eomday.m --- a/scripts/time/eomday.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/eomday.m Thu Nov 19 13:08:00 2020 -0800 @@ -61,6 +61,5 @@ %!assert (eomday ([2004;2005], [2;2]), [29;28]) ## Test input validation -%!error eomday () -%!error eomday (1) -%!error eomday (1,2,3) +%!error <Invalid call> eomday () +%!error <Invalid call> eomday (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/etime.m --- a/scripts/time/etime.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/etime.m Thu Nov 19 13:08:00 2020 -0800 @@ -80,6 +80,5 @@ %! assert (etime (t5, t1), 13); ## Test input validation -%!error etime () -%!error etime (1) -%!error etime (1, 2, 3) +%!error <Invalid call> etime () +%!error <Invalid call> etime (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/is_leap_year.m --- a/scripts/time/is_leap_year.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/is_leap_year.m Thu Nov 19 13:08:00 2020 -0800 @@ -43,10 +43,6 @@ function retval = is_leap_year (year) - if (nargin > 1) - print_usage (); - endif - if (nargin == 0) t = clock (); year = t(1); @@ -63,4 +59,3 @@ %!assert (is_leap_year (1800), false) %!assert (is_leap_year (1600), true) -%!error is_leap_year (1, 2) diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/module.mk --- a/scripts/time/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/addtodate.m \ %reldir%/asctime.m \ %reldir%/calendar.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/now.m --- a/scripts/time/now.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/now.m Thu Nov 19 13:08:00 2020 -0800 @@ -26,7 +26,7 @@ ## -*- texinfo -*- ## @deftypefn {} {t =} now () ## Return the current local date/time as a serial day number -## (see @code{datenum}). +## (@pxref{XREFdatenum,,@code{datenum}}). ## ## The integral part, @code{floor (now)} corresponds to the number of days ## between today and Jan 1, 0000. @@ -37,10 +37,6 @@ function t = now () - if (nargin != 0) - print_usage (); - endif - t = datenum (clock ()); ## The following doesn't work (e.g., one hour off on 2005-10-04): @@ -59,5 +55,3 @@ %!assert (isnumeric (now ())) %!assert (now () > 0) %!assert (now () <= now ()) - -%!error now (1) diff -r dc3ee9616267 -r fa2cdef14442 scripts/time/weekday.m --- a/scripts/time/weekday.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/time/weekday.m Thu Nov 19 13:08:00 2020 -0800 @@ -55,7 +55,7 @@ function [d, s] = weekday (d, format = "short") - if (nargin < 1 || nargin > 2) + if (nargin < 1) print_usage (); endif diff -r dc3ee9616267 -r fa2cdef14442 scripts/web/.oct-config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/web/.oct-config Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,1 @@ +encoding=utf-8 diff -r dc3ee9616267 -r fa2cdef14442 scripts/web/module.mk --- a/scripts/web/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/web/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,7 @@ FCN_FILE_DIRS += %reldir% %canon_reldir%_FCN_FILES = \ + %reldir%/.oct-config \ %reldir%/web.m \ %reldir%/weboptions.m \ %reldir%/webread.m \ diff -r dc3ee9616267 -r fa2cdef14442 scripts/web/weboptions.m --- a/scripts/web/weboptions.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/web/weboptions.m Thu Nov 19 13:08:00 2020 -0800 @@ -160,6 +160,7 @@ endproperties methods + function f = weboptions (varargin) if (rem (numel (varargin), 2) != 0) error ("weboptions: invalid number of arguments"); @@ -244,6 +245,7 @@ error (["weboptions: Undefined field " field]); endif endif + endfunction function f = set.CharacterEncoding (f, value) @@ -264,7 +266,7 @@ function f = set.Timeout (f, value) if (! isreal (value) || ! isscalar (value) - || floor(value) != value || value < 0) + || floor (value) != value || value < 0) error ("weboptions: invalid Timeout value"); else f.Timeout = value; @@ -355,6 +357,7 @@ endfunction function display (f) + Timeout = int2str (f.Timeout); Password = repmat ("*", 1, numel (num2str (f.Password))); @@ -393,6 +396,7 @@ "\n HeaderFields: " , HeaderFields,... "\n CertificateFilename: '", f.CertificateFilename, "'\n"]; disp (output); + endfunction endmethods diff -r dc3ee9616267 -r fa2cdef14442 scripts/web/webread.m --- a/scripts/web/webread.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/web/webread.m Thu Nov 19 13:08:00 2020 -0800 @@ -48,7 +48,7 @@ function response = webread (url, varargin) if (nargin == 0) - print_usage(); + print_usage (); endif if (! (ischar (url) && isrow (url))) @@ -105,7 +105,7 @@ ## Test input validation -%!error webread () +%!error <Invalid call> webread () %!error <URL must be a string> webread (1) %!error <URL must be a string> webread (["a";"b"]) %!error <KEYS and VALUES must be strings> webread ("URL", "NAME1", 5) diff -r dc3ee9616267 -r fa2cdef14442 scripts/web/webwrite.m --- a/scripts/web/webwrite.m Thu Nov 19 13:05:51 2020 -0800 +++ b/scripts/web/webwrite.m Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ function response = webwrite (url, varargin) if (nargin < 2) - print_usage(); + print_usage (); endif if (! (ischar (url) && isrow (url))) @@ -94,7 +94,7 @@ if (ischar (varargin{1}) && isrow (varargin{1})) param = strsplit (varargin{1}, {"=", "&"}); response = __restful_service__ (url, param, options); - elseif (! iscellstr (varargin)) + elseif (! iscellstr (varargin)) error ("webwrite: DATA must be a string"); else response = __restful_service__ (url, varargin, options); @@ -113,8 +113,8 @@ ## Test input validation -%!error webwrite () -%!error webwrite ("abc") +%!error <Invalid call> webwrite () +%!error <Invalid call> webwrite ("abc") %!error <URL must be a string> webwrite (1, "NAME1", "VALUE1") %!error <URL must be a string> webwrite (["a";"b"], "NAME1", "VALUE1") %!error <DATA must be a string> webwrite ("URL", 1, weboptions ()) diff -r dc3ee9616267 -r fa2cdef14442 src/mkoctfile.in.cc --- a/src/mkoctfile.in.cc Thu Nov 19 13:05:51 2020 -0800 +++ b/src/mkoctfile.in.cc Thu Nov 19 13:08:00 2020 -0800 @@ -66,8 +66,6 @@ # include "wait-wrappers.h" #endif -static std::map<std::string, std::string> vars; - #if ! defined (OCTAVE_VERSION) # define OCTAVE_VERSION %OCTAVE_CONF_VERSION% #endif @@ -170,11 +168,13 @@ return s; } -static void -initialize (void) +static std::map<std::string, std::string> +make_vars_map (bool link_stand_alone, bool verbose, bool debug) { set_octave_home (); + std::map<std::string, std::string> vars; + vars["OCTAVE_HOME"] = Voctave_home; vars["OCTAVE_EXEC_HOME"] = Voctave_exec_home; @@ -227,14 +227,14 @@ = get_variable ("OCTLIBDIR", prepend_octave_exec_home (%OCTAVE_CONF_OCTLIBDIR%)); + std::string DEFAULT_INCFLAGS; + #if defined (OCTAVE_USE_WINDOWS_API) - std::string DEFAULT_INCFLAGS - = "-I" + quote_path (vars["OCTINCLUDEDIR"] + R"(\..)") - + " -I" + quote_path (vars["OCTINCLUDEDIR"]); + DEFAULT_INCFLAGS = "-I" + quote_path (vars["OCTINCLUDEDIR"] + R"(\..)") + + " -I" + quote_path (vars["OCTINCLUDEDIR"]); #else - std::string DEFAULT_INCFLAGS - = "-I" + quote_path (vars["OCTINCLUDEDIR"] + "/..") - + " -I" + quote_path (vars["OCTINCLUDEDIR"]); + DEFAULT_INCFLAGS = "-I" + quote_path (vars["OCTINCLUDEDIR"] + "/..") + + " -I" + quote_path (vars["OCTINCLUDEDIR"]); #endif if (vars["INCLUDEDIR"] != "/usr/include") @@ -264,16 +264,22 @@ vars["FPICFLAG"] = get_variable ("FPICFLAG", %OCTAVE_CONF_FPICFLAG%); vars["CC"] = get_variable ("CC", %OCTAVE_CONF_MKOCTFILE_CC%); + if (verbose && vars["CC"] == "cc-msvc") + vars["CC"] += " -d"; vars["CFLAGS"] = get_variable ("CFLAGS", %OCTAVE_CONF_CFLAGS%); vars["CPICFLAG"] = get_variable ("CPICFLAG", %OCTAVE_CONF_CPICFLAG%); vars["CXX"] = get_variable ("CXX", %OCTAVE_CONF_MKOCTFILE_CXX%); + if (verbose && vars["CXX"] == "cc-msvc") + vars["CXX"] += " -d"; vars["CXXFLAGS"] = get_variable ("CXXFLAGS", %OCTAVE_CONF_CXXFLAGS%); vars["CXXLD"] = get_variable ("CXXLD", vars["CXX"]); + if (verbose && vars["CXXLD"] == "cc-msvc") + vars["CXXLD"] += " -d"; vars["CXXPICFLAG"] = get_variable ("CXXPICFLAG", %OCTAVE_CONF_CXXPICFLAG%); @@ -296,6 +302,9 @@ vars["DL_LDFLAGS"] = get_variable ("DL_LDFLAGS", %OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%); + if (! link_stand_alone) + DEFAULT_LDFLAGS += ' ' + vars["DL_LDFLAGS"]; + vars["RDYNAMIC_FLAG"] = get_variable ("RDYNAMIC_FLAG", %OCTAVE_CONF_RDYNAMIC_FLAG%); @@ -339,8 +348,7 @@ = get_variable ("OCT_LINK_OPTS", replace_prefix (%OCTAVE_CONF_OCT_LINK_OPTS%)); - vars["LDFLAGS"] = get_variable ("LDFLAGS", - replace_prefix (%OCTAVE_CONF_LDFLAGS%)); + vars["LDFLAGS"] = get_variable ("LDFLAGS", DEFAULT_LDFLAGS); vars["LD_STATIC_FLAG"] = get_variable ("LD_STATIC_FLAG", %OCTAVE_CONF_LD_STATIC_FLAG%); @@ -348,17 +356,23 @@ // FIXME: Remove LFLAGS in Octave 8.0 vars["LFLAGS"] = get_variable ("LFLAGS", DEFAULT_LDFLAGS); if (vars["LFLAGS"] != DEFAULT_LDFLAGS) - std::cerr << "warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead" << std::endl; + std::cerr << "mkoctfile: warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead" << std::endl; vars["F77_INTEGER8_FLAG"] = get_variable ("F77_INTEGER8_FLAG", %OCTAVE_CONF_F77_INTEGER_8_FLAG%); vars["ALL_FFLAGS"] = vars["FFLAGS"] + ' ' + vars["F77_INTEGER8_FLAG"]; + if (debug) + vars["ALL_FFLAGS"] += " -g"; vars["ALL_CFLAGS"] = vars["INCFLAGS"] + ' ' + vars["XTRA_CFLAGS"] + ' ' + vars["CFLAGS"]; + if (debug) + vars["ALL_CFLAGS"] += " -g"; vars["ALL_CXXFLAGS"] = vars["INCFLAGS"] + ' ' + vars["XTRA_CXXFLAGS"] + ' ' + vars["CXXFLAGS"]; + if (debug) + vars["ALL_CXXFLAGS"] += " -g"; vars["ALL_LDFLAGS"] = vars["LD_STATIC_FLAG"] + ' ' + vars["CPICFLAG"] + ' ' + vars["LDFLAGS"]; @@ -369,14 +383,14 @@ vars["FFTW_LIBS"] = vars["FFTW3_LDFLAGS"] + ' ' + vars["FFTW3_LIBS"] + ' ' + vars["FFTW3F_LDFLAGS"] + ' ' + vars["FFTW3F_LIBS"]; + + return vars; } static std::string usage_msg = "usage: mkoctfile [options] file ..."; static std::string version_msg = "mkoctfile, version " OCTAVE_VERSION; -static bool debug = false; - static std::string help_msg = "\n" "Options:\n" @@ -564,7 +578,7 @@ } static int -run_command (const std::string& cmd, bool printonly = false) +run_command (const std::string& cmd, bool verbose, bool printonly = false) { if (printonly) { @@ -572,7 +586,7 @@ return 0; } - if (debug) + if (verbose) std::cout << cmd << std::endl; int result = system (cmd.c_str ()); @@ -630,6 +644,32 @@ } static std::string +create_interleaved_complex_file (void) +{ + std::string tmpl = get_temp_directory () + "/oct-XXXXXX.c"; + + char *ctmpl = new char [tmpl.length () + 1]; + + ctmpl = strcpy (ctmpl, tmpl.c_str ()); + + // mkostemps will open the file and return a file descriptor. We + // won't worry about closing it because we will need the file until we + // are done and then the file will be closed when mkoctfile exits. + int fd = octave_mkostemps_wrapper (ctmpl, 2); + + // Make C++ string from filled-in template. + std::string retval (ctmpl); + delete [] ctmpl; + + // Write symbol definition to file. + FILE *fid = fdopen (fd, "w"); + fputs ("const int __mx_has_interleaved_complex__ = 1;\n", fid); + fclose (fid); + + return retval; +} + +static std::string tmp_objfile_name (void) { std::string tmpl = get_temp_directory () + "/oct-XXXXXX.o"; @@ -659,8 +699,6 @@ int main (int argc, char **argv) { - initialize (); - if (argc == 1) { std::cout << usage_msg << std::endl; @@ -679,6 +717,9 @@ std::string output_ext = ".oct"; std::string objfiles, libfiles, octfile, outputfile; std::string incflags, defs, ldflags, pass_on_options; + std::string var_to_print; + bool debug = false; + bool verbose = false; bool strip = false; bool no_oct_file_strip_on_this_platform = is_true ("%NO_OCT_FILE_STRIP%"); bool compile_only = false; @@ -686,6 +727,11 @@ bool depend = false; bool printonly = false; bool output_file_option = false; + bool creating_mex_file = false; + bool r2017b_option = false; + bool r2018a_option = false; + // The default for this may change in the future. + bool mx_has_interleaved_complex = false; for (int i = 1; i < argc; i++) { @@ -725,13 +771,7 @@ else if (arg == "-d" || arg == "-debug" || arg == "--debug" || arg == "-v" || arg == "-verbose" || arg == "--verbose") { - debug = true; - if (vars["CC"] == "cc-msvc") - vars["CC"] += " -d"; - if (vars["CXX"] == "cc-msvc") - vars["CXX"] += " -d"; - if (vars["CXXLD"] == "cc-msvc") - vars["CXXLD"] += " -d"; + verbose = true; } else if (arg == "-silent" || arg == "--silent") { @@ -764,7 +804,28 @@ } else if (arg == "-largeArrayDims" || arg == "-compatibleArrayDims") { - std::cerr << "warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl; + std::cerr << "mkoctfile: warning: -largeArrayDims and -compatibleArrayDims are accepted for compatibility, but ignored" << std::endl; + } + else if (arg == "-R2017b") + { + if (r2018a_option) + { + std::cerr << "mkoctfile: only one of -R2017b and -R2018a may be used" << std::endl; + return 1; + } + + r2017b_option = true; + } + else if (arg == "-R2018a") + { + if (r2017b_option) + { + std::cerr << "mkoctfile: only one of -R2017b and -R2018a may be used" << std::endl; + return 1; + } + + r2018a_option = true; + mx_has_interleaved_complex = true; } else if (starts_with (arg, "-Wl,") || starts_with (arg, "-l") || starts_with (arg, "-L") || starts_with (arg, "-R")) @@ -801,13 +862,17 @@ { if (i < argc-1) { - arg = argv[++i]; + ++i; + // FIXME: Remove LFLAGS checking in Octave 7.0 - if (arg == "LFLAGS") - std::cerr << "warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead" << std::endl; + if (! strcmp (argv[i], "LFLAGS")) + std::cerr << "mkoctfile: warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead" << std::endl; - std::cout << vars[arg] << std::endl; - return 0; + if (! var_to_print.empty ()) + std::cerr << "mkoctfile: warning: only one '" << arg + << "' option will be processed" << std::endl; + else + var_to_print = argv[i]; } else std::cerr << "mkoctfile: --print requires argument" << std::endl; @@ -826,9 +891,7 @@ } else if (arg == "-g") { - vars["ALL_CFLAGS"] += " -g"; - vars["ALL_CXXFLAGS"] += " -g"; - vars["ALL_FFLAGS"] += " -g"; + debug = true; } else if (arg == "-link-stand-alone" || arg == "--link-stand-alone") { @@ -836,6 +899,8 @@ } else if (arg == "-mex" || arg == "--mex") { + creating_mex_file = true; + incflags += " -I."; #if defined (_MSC_VER) ldflags += " -Wl,-export:mexFunction"; @@ -876,10 +941,54 @@ octfile = file; } - if (output_ext == ".mex" - && vars["ALL_CFLAGS"].find ("-g") != std::string::npos) + std::map<std::string, std::string> vars + = make_vars_map (link_stand_alone, verbose, debug); + + if (! var_to_print.empty ()) + { + if (vars.find (var_to_print) == vars.end ()) + { + std::cerr << "mkoctfile: unknown variable '" << var_to_print << "'" + << std::endl; + return 1; + } + + std::cout << vars[var_to_print] << std::endl; + + return 0; + } + + if (creating_mex_file) { - defs += " -DMEX_DEBUG"; + if (vars["ALL_CFLAGS"].find ("-g") != std::string::npos) + defs += " -DMEX_DEBUG"; + + if (mx_has_interleaved_complex) + { + defs += " -DMX_HAS_INTERLEAVED_COMPLEX=1"; + + if (! compile_only) + { + // Create tmp C source file that defines an extern symbol + // that can be checked when loading the mex file to + // determine that the file was compiled expecting + // interleaved complex values. + + std::string tmp_file = create_interleaved_complex_file (); + + cfiles.push_back (tmp_file); + } + } + } + else + { + if (r2017b_option) + std::cerr << "mkoctfile: warning: -R2017b option ignored unless creating mex file" + << std::endl; + + if (r2018a_option) + std::cerr << "mkoctfile: warning: -R2018a option ignored unless creating mex file" + << std::endl; } if (compile_only && output_file_option @@ -1064,7 +1173,7 @@ + vars["ALL_FFLAGS"] + ' ' + incflags + ' ' + defs + ' ' + pass_on_options + ' ' + f + " -o " + o); - int status = run_command (cmd, printonly); + int status = run_command (cmd, verbose, printonly); if (status) return status; @@ -1104,7 +1213,7 @@ + pass_on_options + ' ' + incflags + ' ' + defs + ' ' + quote_path (f) + " -o " + quote_path (o)); - int status = run_command (cmd, printonly); + int status = run_command (cmd, verbose, printonly); if (status) return status; @@ -1144,7 +1253,7 @@ + pass_on_options + ' ' + incflags + ' ' + defs + ' ' + quote_path (f) + " -o " + quote_path (o)); - int status = run_command (cmd, printonly); + int status = run_command (cmd, verbose, printonly); if (status) return status; @@ -1185,7 +1294,7 @@ + vars["LFLAGS"] + ' ' + octave_libs + ' ' + vars["OCTAVE_LINK_OPTS"] + ' ' + vars["OCTAVE_LINK_DEPS"]); - int status = run_command (cmd, printonly); + int status = run_command (cmd, verbose, printonly); clean_up_tmp_files (tmp_objfiles); @@ -1219,7 +1328,7 @@ cmd += ' ' + vars["FLIBS"]; #endif - int status = run_command (cmd, printonly); + int status = run_command (cmd, verbose, printonly); clean_up_tmp_files (tmp_objfiles); @@ -1231,7 +1340,7 @@ { std::string cmd = "strip " + octfile; - int status = run_command (cmd, printonly); + int status = run_command (cmd, verbose, printonly); if (status) return status; diff -r dc3ee9616267 -r fa2cdef14442 test/args.tst --- a/test/args.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/args.tst Thu Nov 19 13:08:00 2020 -0800 @@ -219,7 +219,7 @@ %! f() ## struct -%!function f (x = struct("a", 3)) +%!function f (x = struct ("a", 3)) %! assert (x, struct ("a", 3)); %!endfunction %!test diff -r dc3ee9616267 -r fa2cdef14442 test/bug-35448/fA.m --- a/test/bug-35448/fA.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-35448/fA.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,7 +1,7 @@ -# fA.m +## fA.m function y = fA (x, f) global gfun - if nargin < 2 + if (nargin < 2) y = fA (x, gfun); else w = feval (f, x); diff -r dc3ee9616267 -r fa2cdef14442 test/bug-35448/fB.m --- a/test/bug-35448/fB.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-35448/fB.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# fB.m +## fB.m function y = fB (x) y = x; endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/bug-35448/fC.m --- a/test/bug-35448/fC.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-35448/fC.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# fC.m +## fC.m function y = fC (x) y = x; endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/bug-36025/@testclass/one.m --- a/test/bug-36025/@testclass/one.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-36025/@testclass/one.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -% function ONE return item "X" +%% function ONE return item "X" function a = one (m) a = m.x; diff -r dc3ee9616267 -r fa2cdef14442 test/bug-36025/@testclass/two.m --- a/test/bug-36025/@testclass/two.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-36025/@testclass/two.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -% function TWO returns item "Y" +%% function TWO returns item "Y" function a = one (m) a = m.y; diff -r dc3ee9616267 -r fa2cdef14442 test/bug-38236/df_vr.m --- a/test/bug-38236/df_vr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-38236/df_vr.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,2 +1,2 @@ -# df_vr.m +## df_vr.m vr = 7; diff -r dc3ee9616267 -r fa2cdef14442 test/bug-38236/u_vr.m --- a/test/bug-38236/u_vr.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-38236/u_vr.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# u_vr.m +## u_vr.m ## define and exectute "__demo__" once eval ("function __demo__ (); df_vr; v = vr * 2; endfunction"); diff -r dc3ee9616267 -r fa2cdef14442 test/bug-40117.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-40117.tst Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,76 @@ +######################################################################## +## +## Copyright (C) 2020 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +%!function __mktestfun_40117__ (file, varargin) +%! unwind_protect +%! fid = fopen (file, "w"); +%! fprintf (fid, "%s\n", varargin{:}); +%! unwind_protect_cleanup +%! if (fid > 0) +%! fclose (fid); +%! endif +%! end_unwind_protect +%!endfunction + +%!test <40117> +%! unwind_protect +%! tmp_dir = tempname (); +%! mkdir (tmp_dir); +%! a_dir = fullfile (tmp_dir, "a"); +%! a_private_dir = fullfile (a_dir, "private"); +%! mkdir (a_dir); +%! mkdir (a_private_dir); +%! __mktestfun_40117__ (fullfile (a_dir, "main_40117.m"), +%! "function r = main_40117 ()", +%! " r = p1_40117 ();", +%! "endfunction"); +%! __mktestfun_40117__ (fullfile (a_private_dir, "p1_40117.m"), +%! "function r = p1_40117 ()", +%! " r = p2_40117 ();", +%! "endfunction"); +%! __mktestfun_40117__ (fullfile (a_private_dir, "p2_40117.m"), +%! "function r = p2_40117 ()", +%! " r = 'a_p2_40117';", +%! "endfunction"); +%! addpath (a_dir); +%! assert (main_40117 (), "a_p2_40117"); +%! +%! ## Update the secondary private function, attempting to avoid +%! ## filesystem timestamp resolution problems. +%! pause (1); +%! __mktestfun_40117__ (fullfile (a_private_dir, "p2_40117.m"), +%! "function r = p2_40117 ()", +%! " r = 'new function!';", +%! "endfunction"); +%! +%! ## Force new functions to be found. +%! rehash (); +%! +%! assert (main_40117 (), "new function!"); +%! unwind_protect_cleanup +%! rmpath (a_dir); +%! confirm_recursive_rmdir (false, "local"); +%! rmdir (tmp_dir, "s"); +%! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 test/bug-47680/super_bug47680.m --- a/test/bug-47680/super_bug47680.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-47680/super_bug47680.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,7 +1,7 @@ classdef super_bug47680 properties tag; - end + endproperties methods function obj = super_bug47680 (x) obj.tag = x; diff -r dc3ee9616267 -r fa2cdef14442 test/bug-50014/bug-50014.tst --- a/test/bug-50014/bug-50014.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-50014/bug-50014.tst Thu Nov 19 13:08:00 2020 -0800 @@ -26,7 +26,7 @@ %!error <duplicate subfunction or nested function name> %! duplicate_nested_function () -%!assert (duplicate_nested_in_subfunction_ok (), 3); +%!assert (duplicate_nested_in_subfunction_ok (), 3) %!error <duplicate subfunction or nested function name> %! duplicate_nested_parent_function () @@ -52,4 +52,4 @@ %!error <duplicate subfunction or nested function name> %! duplicate_subfunction_old_syntax () -%!assert (duplicate_subfunction_separate_scope_ok (), 3); +%!assert (duplicate_subfunction_separate_scope_ok (), 3) diff -r dc3ee9616267 -r fa2cdef14442 test/bug-50014/duplicate_parent_nested2.m --- a/test/bug-50014/duplicate_parent_nested2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-50014/duplicate_parent_nested2.m Thu Nov 19 13:08:00 2020 -0800 @@ -4,8 +4,8 @@ function bug () endfunction endfunction - function bug () ## no error here - function bug () ## error here (duplicates parent name) + function bug () # no error here + function bug () # error here (duplicates parent name) endfunction endfunction endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/bug-51532/+package_bug51532/foo.m --- a/test/bug-51532/+package_bug51532/foo.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-51532/+package_bug51532/foo.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,3 +1,3 @@ function retval = foo (val) retval = val; -end +endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/bug-54995/@testclass54995/testclass54995.m --- a/test/bug-54995/@testclass54995/testclass54995.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-54995/@testclass54995/testclass54995.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ function obj = testclass54995 () obj = struct ("x", eye (4)); - obj = class(obj, "testclass54995"); + obj = class (obj, "testclass54995"); endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/bug-55321.tst --- a/test/bug-55321.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-55321.tst Thu Nov 19 13:08:00 2020 -0800 @@ -23,7 +23,7 @@ ## ######################################################################## -%!function cb_children (hg) +%!function cb_children (hg, ~) %! hl = get (hg, "children"); %! color = get (hl, "color"); %! set (hl, "userdata", isequal (color, [1 0 0])); diff -r dc3ee9616267 -r fa2cdef14442 test/bug-58593/myclass2.m --- a/test/bug-58593/myclass2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/bug-58593/myclass2.m Thu Nov 19 13:08:00 2020 -0800 @@ -13,16 +13,16 @@ case '.' switch (S(1).subs) case 'data' - % Transform: obj.data --> obj.data_ + %% Transform: obj.data --> obj.data_ r = obj.data_; if (length (S) > 1) r = subsref (r, S(2:end)); end case 'alldata' - % Transform: obj.data --> obj.data_(1:end) - % This statement should trigger *builtin* subsref *twice* (one - % for the evaluation of 'end', and the other for the whole rvalue). - % 'end' here is also builtin 'end' + %% Transform: obj.data --> obj.data_(1:end) + %% This statement should trigger *builtin* subsref *twice* (one + %% for the evaluation of 'end', and the other for the whole rvalue). + %% 'end' here is also builtin 'end' r = obj.data_(1:end); if (length (S) > 1) @@ -32,7 +32,7 @@ error ('Incorrect usage'); end case '()' - % Transform: obj(index) --> obj.data_(index) + %% Transform: obj(index) --> obj.data_(index) r = subsref (obj.data_, S); otherwise error ('Incorrect usage'); @@ -44,25 +44,25 @@ case '.' switch (S(1).subs) case 'data' - % Transform: obj.data --> obj.data_ - if length(S)>1 + %% Transform: obj.data --> obj.data_ + if (length (S)>1) B = subsasgn (obj.data_, S(2:end), B); end obj.data_ = B; case 'alldata' - % Transform: obj.data --> obj.data_(1:end) - if length(S)>1 + %% Transform: obj.data --> obj.data_(1:end) + if (length (S)>1) B = subsasgn (obj.data_(1:end), S(2:end), B); end - % This statement should trigger *builtin* subsref to evaluate 'end', - % then *builtin* subsasgn for the whole assignment expression - % 'end' here is also builtin 'end' + %% This statement should trigger *builtin* subsref to evaluate 'end', + %% then *builtin* subsasgn for the whole assignment expression + %% 'end' here is also builtin 'end' obj.data_(1:end) = B; otherwise - error('Incorrect usage'); + error ('Incorrect usage'); end case '()' - % Transform: obj(index) --> obj.data_(index) + %% Transform: obj(index) --> obj.data_(index) obj.data_ = subsasgn (obj.data_, S, B); otherwise error ('Incorrect usage'); @@ -70,7 +70,7 @@ end function r = end (obj, k, n) - % We subtract 1 from the "real" end of obj.data_ + %% We subtract 1 from the "real" end of obj.data_ r = builtin ('end', obj.data_, k, n) - 1; end end diff -r dc3ee9616267 -r fa2cdef14442 test/classdef/foo_subsref_subsasgn.m --- a/test/classdef/foo_subsref_subsasgn.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classdef/foo_subsref_subsasgn.m Thu Nov 19 13:08:00 2020 -0800 @@ -18,7 +18,7 @@ function ind = end (obj, k, n) sz = size (obj.x); - if k < n + if (k < n) ind = sz(k); else ind = prod (sz(k:end)); @@ -31,7 +31,7 @@ if (S(1).type == "()") varargout = {obj.x(S(1).subs{1})}; elseif (S(1).type == "{}") - % Note in ML R2018b "x{1:3}" expects "nargout == 3". + %% Note in ML R2018b "x{1:3}" expects "nargout == 3". varargout = num2cell (obj.x(S(1).subs{1})); elseif (S(1).type == "." && S(1).subs == 'x') varargout = {obj.x}; @@ -40,7 +40,7 @@ 'foo_subsref_subsasgn: Invalid syntax'); end case 2 - % Note in ML R2018b "x(1)(1)" is not allowed. + %% Note in ML R2018b "x(1)(1)" is not allowed. if (S(1).type == "{}" && (S(2).type == "{}" || S(2).type == "()")) varargout = {obj.x(S(1).subs{1}, S(2).subs{1})}; elseif (S(1).type == "." && S(1).subs == 'x' ... @@ -68,7 +68,7 @@ 'foo_subsref_subsasgn: Invalid syntax'); end case 2 - % Note in ML R2018b "x(1)(1)" is not allowed. + %% Note in ML R2018b "x(1)(1)" is not allowed. if (S(1).type == "{}" && (S(2).type == "{}" || S(2).type == "()")) obj.x(S(1).subs{1}, S(2).subs{1}) = varargin{1}; elseif (S(1).type == "." && S(1).subs == 'x' ... diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Blork/Blork.m --- a/test/classes/@Blork/Blork.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Blork/Blork.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function s = Blork (bleek) -% Test class. +%% Test class. if (nargin == 1 && isa (bleek, 'Blork')) s = bleek; diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Blork/get.m --- a/test/classes/@Blork/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Blork/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,6 @@ function v = get (s, propName) - switch propName + switch (propName) case 'bleek' v = s.bleek; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Blork/set.m --- a/test/classes/@Blork/set.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Blork/set.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,7 +5,7 @@ propName = propArgs{1}; propValue = propArgs{2}; propArgs = propArgs(3:end); - switch propName + switch (propName) case 'bleek' s.bleek = propValue; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@CPrecedenceTester1/CPrecedenceTester1.m --- a/test/classes/@CPrecedenceTester1/CPrecedenceTester1.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@CPrecedenceTester1/CPrecedenceTester1.m Thu Nov 19 13:08:00 2020 -0800 @@ -3,6 +3,6 @@ x = struct ('useless_data', pi); x = class (x, 'CPrecedenceTester1'); - % don't change anything as far as precedence is concerned + %% don't change anything as far as precedence is concerned end diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@CPrecedenceTester2/CPrecedenceTester2.m --- a/test/classes/@CPrecedenceTester2/CPrecedenceTester2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@CPrecedenceTester2/CPrecedenceTester2.m Thu Nov 19 13:08:00 2020 -0800 @@ -3,7 +3,7 @@ x = struct ('useless_data', pi^2); x = class (x, 'CPrecedenceTester2'); - switch flag + switch (flag) case 1 % CPrecedencetester2 > Snork superiorto ('Snork'); case 2 % CPrecedencetester2 < Snork diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@CPrecedenceTester3/CPrecedenceTester3.m --- a/test/classes/@CPrecedenceTester3/CPrecedenceTester3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@CPrecedenceTester3/CPrecedenceTester3.m Thu Nov 19 13:08:00 2020 -0800 @@ -3,7 +3,7 @@ x = struct ('useless_data', pi^3); x = class (x, 'CPrecedenceTester3'); - switch flag + switch (flag) case 1 % CPrecedencetester3 > Snork superiorto ('Snork'); case 2 % CPrecedencetester3 < Snork diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Cork/Cork.m --- a/test/classes/@Cork/Cork.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Cork/Cork.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function s = Cork (click) -% Test class. +%% Test class. if (nargin == 1 && isa (click, 'Cork')) s = click; diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Cork/get.m --- a/test/classes/@Cork/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Cork/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,6 @@ function v = get (s, propName) - switch propName + switch (propName) case 'click' v = s.click; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Cork/set.m --- a/test/classes/@Cork/set.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Cork/set.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,7 +5,7 @@ propName = propArgs{1}; propValue = propArgs{2}; propArgs = propArgs(3:end); - switch propName + switch (propName) case 'click' s.click = propValue; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Dork/display.m --- a/test/classes/@Dork/display.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Dork/display.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function display (s) -% Display the critical info for an amplifier +%% Display the critical info for an amplifier gick = get (s, 'gick'); disp ([inputname(1),'.gick = ']); diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Dork/get.m --- a/test/classes/@Dork/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Dork/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,6 @@ function v = get (s, propName) - switch propName + switch (propName) case 'gack' v = s.gack; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Dork/set.m --- a/test/classes/@Dork/set.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Dork/set.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,7 +5,7 @@ propName = propArgs{1}; propValue = propArgs{2}; propArgs = propArgs(3:end); - switch propName + switch (propName) case 'gack' s.gack = propValue; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Gork/display.m --- a/test/classes/@Gork/display.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Gork/display.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function display (s) -% Display the critical info for a Gork. +%% Display the critical info for a Gork. dork_base = s.Dork %pork_base = s.Pork diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Gork/get.m --- a/test/classes/@Gork/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Gork/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,13 +1,13 @@ function v = get (s, propName) - switch propName + switch (propName) case 'cork' v = s.Cork; case 'gark' v = s.gark; otherwise - % Note that get/set for multiple parents is hard. We only do one - % branch of the parent tree just to test this stuff out. + %% Note that get/set for multiple parents is hard. We only do one + %% branch of the parent tree just to test this stuff out. v = get (s.Dork,propName); end diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Gork/set.m --- a/test/classes/@Gork/set.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Gork/set.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,7 +5,7 @@ propName = propArgs{1}; propValue = propArgs{2}; propArgs = propArgs(3:end); - switch propName + switch (propName) case 'cork' if (isa (propValue, 'Cork')) s.Cork = propValue; @@ -15,8 +15,8 @@ case 'gark' s.gark = propValue; otherwise - % Note that get/set for multiple parents is hard. We only do one - % branch of the parent tree just to test this stuff out. + %% Note that get/set for multiple parents is hard. We only do one + %% branch of the parent tree just to test this stuff out. s.Dork = set (s.Dork, propName, propValue); end end diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Gork/subsasgn.m --- a/test/classes/@Gork/subsasgn.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Gork/subsasgn.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,8 +1,8 @@ function g = subsasgn (g, s, x) - switch s.type + switch (s.type) case '.' - switch s.subs + switch (s.subs) case 'gyrk' g.gyrk = x; end diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Gork/subsref.m --- a/test/classes/@Gork/subsref.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Gork/subsref.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,8 +1,8 @@ function x = subsref (g, s) - switch s.type + switch (s.type) case '.' - switch s.subs + switch (s.subs) case 'gyrk' x = g.gyrk; end diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Pork/display.m --- a/test/classes/@Pork/display.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Pork/display.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function display (s) -% Display the critical info for an amplifier +%% Display the critical info for an amplifier geek = get (s, 'geek'); disp ([inputname(1),'.geek = ']); diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Pork/get.m --- a/test/classes/@Pork/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Pork/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,6 @@ function v = get (s, propName) - switch propName + switch (propName) case 'gurk' v = s.gurk; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Pork/set.m --- a/test/classes/@Pork/set.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Pork/set.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,7 +5,7 @@ propName = propArgs{1}; propValue = propArgs{2}; propArgs = propArgs(3:end); - switch propName + switch (propName) case 'gurk' s.gurk = propValue; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Sneetch/Sneetch.m --- a/test/classes/@Sneetch/Sneetch.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Sneetch/Sneetch.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function s = Sneetch (mcbean) -% Test class: should produce error. +%% Test class: should produce error. if (nargin == 1 && isa (mcbean, 'Sneetch')) s = mcbean; diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Snork/Snork.m --- a/test/classes/@Snork/Snork.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Snork/Snork.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function s = Snork (gick) -% Test class. +%% Test class. if (nargin == 1 && isa (gick, 'Snork')) s = gick; diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Snork/end.m --- a/test/classes/@Snork/end.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Snork/end.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,7 +1,7 @@ function r = end (snk, index_pos, num_indices) if (num_indices ~= 1) - error ('Snork object may only have one index') + error ('Snork object may only have one index'); end r = length (snk.cack); diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Snork/get.m --- a/test/classes/@Snork/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Snork/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,6 @@ function v = get (s, propName) - switch propName + switch (propName) case 'gick' v = s.gick; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Snork/set.m --- a/test/classes/@Snork/set.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Snork/set.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,7 +5,7 @@ propName = propArgs{1}; propValue = propArgs{2}; propArgs = propArgs(3:end); - switch propName + switch (propName) case 'gick' s.gick = propValue; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Spork/Spork.m --- a/test/classes/@Spork/Spork.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Spork/Spork.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,5 +1,5 @@ function s = Spork (geek) -% Test class. +%% Test class. if (nargin == 1 && isa (geek, 'Spork')) s = geek; diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Spork/get.m --- a/test/classes/@Spork/get.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Spork/get.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,6 +1,6 @@ function v = get (s, propName) - switch propName + switch (propName) case 'geek' v = s.geek; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/@Spork/set.m --- a/test/classes/@Spork/set.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/@Spork/set.m Thu Nov 19 13:08:00 2020 -0800 @@ -5,7 +5,7 @@ propName = propArgs{1}; propValue = propArgs{2}; propArgs = propArgs(3:end); - switch propName + switch (propName) case 'geek' s.geek = propValue; otherwise diff -r dc3ee9616267 -r fa2cdef14442 test/classes/classes.tst --- a/test/classes/classes.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/classes/classes.tst Thu Nov 19 13:08:00 2020 -0800 @@ -65,9 +65,9 @@ %! assert (isobject (snk)); %! assert (isequal (class (snk), 'Snork')); %! assert (isa (snk, 'Snork')); -%! assert (!isa (snk, 'Sneetch')); +%! assert (! isa (snk, 'Sneetch')); %! assert (ismethod (snk, 'gick')); -%! assert (!ismethod (snk, 'bletch')); +%! assert (! ismethod (snk, 'bletch')); %! assert (exist ('snk') == 1); %! assert (exist ('blink') == 0); %!test snk1 = Snork (snk); diff -r dc3ee9616267 -r fa2cdef14442 test/colon-op/@legacy_colon_op/colon.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/colon-op/@legacy_colon_op/colon.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,7 @@ +function r = colon (a, b, c) + if (nargin == 2) + r = sprintf ("%s:%s", class (a), class (b)); + else + r = sprintf ("%s:%s:%s", class (a), class (b), class (c)); + endif +endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/colon-op/@legacy_colon_op/legacy_colon_op.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/colon-op/@legacy_colon_op/legacy_colon_op.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,3 @@ +function obj = legacy_colon_op () + obj = class (struct (), "legacy_colon_op"); +endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/colon-op/colon-op.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/colon-op/colon-op.tst Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,25 @@ +%!test +%! x = colon_op (); +%! assert (x:2:3, "colon_op:double:double"); +%! assert (1:x:3, "double:colon_op:double"); +%! assert (1:2:x, "double:double:colon_op"); +%! assert (x:x:3, "colon_op:colon_op:double"); +%! assert (1:x:x, "double:colon_op:colon_op"); +%! assert (x:2:x, "colon_op:double:colon_op"); +%! assert (x:x:x, "colon_op:colon_op:colon_op"); +%! assert (x:2, "colon_op:double"); +%! assert (1:x, "double:colon_op"); +%! assert (x:x, "colon_op:colon_op"); + +%!test +%! x = legacy_colon_op (); +%! assert (x:2:3, "legacy_colon_op:double:double"); +%! assert (1:x:3, "double:legacy_colon_op:double"); +%! assert (1:2:x, "double:double:legacy_colon_op"); +%! assert (x:x:3, "legacy_colon_op:legacy_colon_op:double"); +%! assert (1:x:x, "double:legacy_colon_op:legacy_colon_op"); +%! assert (x:2:x, "legacy_colon_op:double:legacy_colon_op"); +%! assert (x:x:x, "legacy_colon_op:legacy_colon_op:legacy_colon_op"); +%! assert (x:2, "legacy_colon_op:double"); +%! assert (1:x, "double:legacy_colon_op"); +%! assert (x:x, "legacy_colon_op:legacy_colon_op"); diff -r dc3ee9616267 -r fa2cdef14442 test/colon-op/colon_op.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/colon-op/colon_op.m Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,11 @@ +classdef colon_op + methods + function r = colon (a, b, c) + if (nargin == 2) + r = sprintf ("%s:%s", class (a), class (b)); + else + r = sprintf ("%s:%s:%s", class (a), class (b), class (c)); + endif + endfunction + endmethods +endclassdef diff -r dc3ee9616267 -r fa2cdef14442 test/colon-op/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/colon-op/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,7 @@ +colon_op_TEST_FILES = \ + %reldir%/@legacy_colon_op/colon.m \ + %reldir%/@legacy_colon_op/legacy_colon_op.m \ + %reldir%/colon-op.tst \ + %reldir%/colon_op.m + +TEST_FILES += $(colon_op_TEST_FILES) diff -r dc3ee9616267 -r fa2cdef14442 test/command.tst --- a/test/command.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/command.tst Thu Nov 19 13:08:00 2020 -0800 @@ -174,5 +174,5 @@ %! command_test w(m,1) % edge weights %! assert (cmd_out, '|w(m,1)|'); %!test -%! command_test x2( size( x ) ) -%! assert (cmd_out, '|x2( size( x ) )|'); +%! command_test x2( size ( x ) ) +%! assert (cmd_out, '|x2( size ( x ) )|'); diff -r dc3ee9616267 -r fa2cdef14442 test/complex.tst --- a/test/complex.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/complex.tst Thu Nov 19 13:08:00 2020 -0800 @@ -43,9 +43,9 @@ ## bug #43313, -1 is both '>' and '==' to (-1 - 0i) %!test -%! assert (complex(-1,0) == complex(-1,-0), true); -%! assert (complex(-1,0) > complex(-1,-0), false); -%! assert (complex(-1,0) < complex(-1,-0), false); +%! assert (complex (-1,0) == complex (-1,-0), true); +%! assert (complex (-1,0) > complex (-1,-0), false); +%! assert (complex (-1,0) < complex (-1,-0), false); ## Test that sort and issorted both agree on boundary case %!test diff -r dc3ee9616267 -r fa2cdef14442 test/ctor-vs-method/@parent/parent.m --- a/test/ctor-vs-method/@parent/parent.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/ctor-vs-method/@parent/parent.m Thu Nov 19 13:08:00 2020 -0800 @@ -3,12 +3,12 @@ if (nargin == 0) rot = class (struct (), 'parent'); else - switch class (a) + switch (class (a)) case 'parent' %% copy constructor rot = a; otherwise - error ('type mismatch in parent constructor') + error ('type mismatch in parent constructor'); end end __trace__ ('end parent/parent'); diff -r dc3ee9616267 -r fa2cdef14442 test/deprecate-props.tst --- a/test/deprecate-props.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/deprecate-props.tst Thu Nov 19 13:08:00 2020 -0800 @@ -37,25 +37,3 @@ %! endif %! endif %!endfunction - -## text/uicontrol/uipanel/uibuttongroup/uitable "oblique" value for -## "fontangle" property was deprecated in 5.0, remove from version 7: -## * remove "oblique" options in graphics.in.h, QtHandlesUtils.cc, -## and ft-text-renderer.cc -## * remove warnings from update_fontangle in graphics.in.h -%!test -%! hf = figure ("visible", "off"); -%! unwind_protect -%! ht = text (); -%! testprop (ht, "fontangle", "7.0", "oblique"); -%! hui = uicontrol (); -%! testprop (hui, "fontangle", "7.0", "oblique"); -%! hui = uipanel (); -%! testprop (hui, "fontangle", "7.0", "oblique"); -%! hui = uibuttongroup (); -%! testprop (hui, "fontangle", "7.0", "oblique"); -%! hui = uitable (); -%! testprop (hui, "fontangle", "7.0", "oblique"); -%! unwind_protect_cleanup -%! close (hf); -%! end_unwind_protect diff -r dc3ee9616267 -r fa2cdef14442 test/diag-perm.tst --- a/test/diag-perm.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/diag-perm.tst Thu Nov 19 13:08:00 2020 -0800 @@ -178,6 +178,8 @@ %! assert (diag (D1D2), d1 .* d2); ## slicing +## preserving diagonal matrix type is not possible if indices are +## general matrix objects. %!test %! m = 13; %! n = 6; @@ -185,7 +187,11 @@ %! d = rand (mn, 1); %! D = diag (d, m, n); %! Dslice = D (1:(m-3), 1:(n-2)); -%! assert (typeinfo (Dslice), "diagonal matrix"); +%! if (disable_range ()) +%! assert (typeinfo (Dslice), "matrix"); +%! else +%! assert (typeinfo (Dslice), "diagonal matrix"); +%! endif ## preserve dense matrix structure when scaling %!assert (typeinfo (rand (8) * (3 * eye (8))), "matrix") @@ -226,7 +232,7 @@ %! A = sprand (n, n, .5); %! scalefact = rand (n-2, 1); %! Dr = diag (scalefact, n, n-2); -%! assert (full (Dr \ A), Dr \ full(A)); +%! assert (full (Dr \ A), Dr \ full (A)); ## sparse inverse column scaling with a zero factor %!test @@ -236,15 +242,15 @@ %! Dc = diag (scalefact); %! scalefact(n-1) = Inf; %! Dc(n-1, n-1) = 0; -%! assert (full (A / Dc), full(A) / Dc); +%! assert (full (A / Dc), full (A) / Dc); ## short sparse inverse column scaling %!test %! n = 7; %! A = sprand (n, n, .5); -%! scalefact = rand (1, n-2) + I () * rand(1, n-2); +%! scalefact = rand (1, n-2) + I () * rand (1, n-2); %! Dc = diag (scalefact, n-2, n); -%! assert (full (A / Dc), full(A) / Dc); +%! assert (full (A / Dc), full (A) / Dc); ## adding sparse and diagonal stays sparse %!test diff -r dc3ee9616267 -r fa2cdef14442 test/eval-catch.tst --- a/test/eval-catch.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/eval-catch.tst Thu Nov 19 13:08:00 2020 -0800 @@ -35,12 +35,12 @@ %!test %! eval ("clear a; a; str = '';", "str=lasterr;"); -%! assert (lasterr()(1:13), "'a' undefined"); +%! assert (lasterr ()(1:13), "'a' undefined"); %! assert (str(1:13), "'a' undefined"); %!test %! eval ("error ('user-defined error'); str = '';", "str = lasterr;"); -%! assert (lasterr()(1:18), "user-defined error"); +%! assert (lasterr ()(1:18), "user-defined error"); %! assert (str(1:18), "user-defined error"); %!function ms = mangle (s) diff -r dc3ee9616267 -r fa2cdef14442 test/fcn-handle/package-function.tst --- a/test/fcn-handle/package-function.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/fcn-handle/package-function.tst Thu Nov 19 13:08:00 2020 -0800 @@ -33,4 +33,4 @@ ## Also test without function handle. %!assert <*55975> (pkga.pkgb.f1 (), "pkg f1"); -%!assert (pkga.pkgb.f2 (), "pkg f2"); +%!assert (pkga.pkgb.f2 (), "pkg f2") diff -r dc3ee9616267 -r fa2cdef14442 test/fcn-handle/static-method.tst --- a/test/fcn-handle/static-method.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/fcn-handle/static-method.tst Thu Nov 19 13:08:00 2020 -0800 @@ -33,4 +33,4 @@ ## Also test without function handle. %!assert <*55975> (pkga.pkgb.bug51709_a.smeth (), "pkg bug51709_a"); -%!assert (pkga.pkgb.bug51709_b.smeth (), "pkg bug51709_b"); +%!assert (pkga.pkgb.bug51709_b.smeth (), "pkg bug51709_b") diff -r dc3ee9616267 -r fa2cdef14442 test/for.tst --- a/test/for.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/for.tst Thu Nov 19 13:08:00 2020 -0800 @@ -161,3 +161,45 @@ %! endfor %! assert (cnt, 0); %! assert (k, cell (0,3)); + +%!test <*45143> +%! warning ("on", "Octave:infinite-loop", "local"); +%! fail ("for i = 0:inf; break; end", "warning", +%! "FOR loop limit is infinite"); +%! +%! fail ("for i = 0:-1:-inf; break; end", "warning", +%! "FOR loop limit is infinite"); + +%!test <*45143> +%! warning ("on", "Octave:infinite-loop", "local"); +%! k = 0; +%! for i = 1:Inf +%! if (++k > 10) +%! break; +%! endif +%! endfor +%! assert (i, 11); +%! +%! k = 0; +%! for i = -1:-1:-Inf +%! if (++k > 10) +%! break; +%! endif +%! endfor +%! assert (i, -11); +%! +%! k = 0; +%! for i = 1:-Inf +%! if (++k > 10) +%! break; +%! endif +%! endfor +%! assert (i, zeros (1,0)); +%! +%! k = 0; +%! for i = 0:-1:Inf +%! if (++k > 10) +%! break; +%! endif +%! endfor +%! assert (i, zeros (1,0)); diff -r dc3ee9616267 -r fa2cdef14442 test/func.tst --- a/test/func.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/func.tst Thu Nov 19 13:08:00 2020 -0800 @@ -81,8 +81,8 @@ %! %! y = feval (fn, m, varargin{:}); %! y2 = feval (fn, reshape (mn, size (m)), varargin{:}); -%! if (!strcmp (class (y), class (m)) || -%! issparse (y) != issparse (m) || !size_equal (y, y2)) +%! if (! strcmp (class (y), class (m)) || +%! issparse (y) != issparse (m) || ! size_equal (y, y2)) %! error ("failed for type %s\n", typ{i}); %! endif %! if (!(strcmp (typ{i}, "cell") || strcmp (typ{i}, "struct")) && @@ -211,5 +211,14 @@ %! retval = in1; %!endfunction -%!error <can't make function parameter retval persistent> __fnpersist1__ (1); -%!error <can't make function parameter in1 persistent> __fnpersist2__ (1); +%!error <can't make function parameter retval persistent> __fnpersist1__ (1) +%!error <can't make function parameter in1 persistent> __fnpersist2__ (1) + +## Check nargin, nargout validation by interpreter +%!function __fn_nargout0__ (in1) +%!endfunction +%!function [out1] = __fn_nargin2__ (in1, in2) +%!endfunction + +%!error <function called with too many outputs> r = __fn_nargout0__ () +%!error <function called with too many inputs> r = __fn_nargin2__ (1,2,3) diff -r dc3ee9616267 -r fa2cdef14442 test/if.tst --- a/test/if.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/if.tst Thu Nov 19 13:08:00 2020 -0800 @@ -107,15 +107,15 @@ %! assert (x, 13); ## test "is_true" of different data types -%!error diag (NaN) || 0; +%!error diag (NaN) || 0 %!test %! d1 = diag ([]) || 0; %! d2 = diag (1) || 0; %! d3 = diag ([1 2]) || 0; %! assert ([d1 d2 d3], [false true false]); -%!error sparse (NaN) || 0; -%!error sparse ([1 1 ; 1 NaN]) || 0; +%!error sparse (NaN) || 0 +%!error sparse ([1 1 ; 1 NaN]) || 0 %!test %! s1 = sparse ([]) || 0; %! s2 = sparse (1) || 0; @@ -133,5 +133,5 @@ %! c1 = [2i 4i] || 0; %! c2 = [22 4i] || 0; %! c3 = i || 0; -%! c4 = complex(0) || 0; +%! c4 = complex (0) || 0; %! assert ([c1 c2 c3 c4], [true true true false]); diff -r dc3ee9616267 -r fa2cdef14442 test/index.tst --- a/test/index.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/index.tst Thu Nov 19 13:08:00 2020 -0800 @@ -513,8 +513,8 @@ %!error <index \(2\): out of bound 1> 1(2) %!error <index \(1\): out of bound 0> [](1) %!error <index \(-1\): subscripts> 1(1)(-1)(1) -%!error <index \(_,1\): out of bound 0 \(dimensions are 5x0\)> zeros(5,0)(3,1) -%!error <index \(3,_\): out of bound 0 \(dimensions are 0x5\)> zeros(0,5)(3,1) +%!error <index \(_,1\): out of bound 0 \(dimensions are 5x0\)> zeros (5,0)(3,1) +%!error <index \(3,_\): out of bound 0 \(dimensions are 0x5\)> zeros (0,5)(3,1) %! %!shared abc %! abc = [1, 2]; @@ -539,8 +539,8 @@ %!error <=: nonconformant arguments \(op1 is 1x1, op2 is 1x5\)> abc(3,5) = 1:5 ## Test diagonal matrices, and access of function results -%!error <index \(_,_,5\): out of bound 1 \(dimensions are 3x3\)> eye(3)(2,3,5) -%!error <index \(-2,_\): subscripts> eye(4)(-2,3) +%!error <index \(_,_,5\): out of bound 1 \(dimensions are 3x3\)> eye (3)(2,3,5) +%!error <index \(-2,_\): subscripts> eye (4)(-2,3) ## Test cells %!shared abc @@ -558,7 +558,7 @@ ## Test sparse matrices %!shared abc -%! abc = sparse(3,3); +%! abc = sparse (3,3); %!error <abc\(-1\): subscripts> abc(-1) %!error <abc\(-1\): subscripts> abc(-1) = 1 %!error <abc\(-1,_\): subscripts> abc(-1,1) @@ -578,7 +578,7 @@ %! abc = [1 2]; %!error <abc\(0\+1i\): subscripts must be real> abc(i) %! abc = [1 2; 3 4]; -%!error <abc\(1\+0i\): subscripts must be real> abc(complex(1)) +%!error <abc\(1\+0i\): subscripts must be real> abc(complex (1)) %!error <abc\(1\+0.5i,_\): subscripts must be real> abc(1+0.5*i,3) %!error <abc\(_,0-2i\): subscripts must be real> abc(2,0-2*i) @@ -587,6 +587,6 @@ %! a(1,1,1).b(1) = 3; %!test <*39789> -%! c = cell(1,1,1); +%! c = cell (1,1,1); %! c{1,1,1} = zeros(5, 2); %! c{1,1,1}(:, 1) = 1; diff -r dc3ee9616267 -r fa2cdef14442 test/inline-fcn.tst --- a/test/inline-fcn.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/inline-fcn.tst Thu Nov 19 13:08:00 2020 -0800 @@ -6,7 +6,7 @@ %!assert (fn (6), 37) %!assert (feval (inline ("sum (x(:))"), [1 2; 3 4]), 10) %!assert (feval (inline ("sqrt (x^2 + y^2)", "x", "y"), 3, 4), 5) -%!assert (feval (inline ("exp (P1*x) + P2", 3), 3, 4, 5), exp(3*4) + 5) +%!assert (feval (inline ("exp (P1*x) + P2", 3), 3, 4, 5), exp (3*4) + 5) ## Test input validation %!error inline () diff -r dc3ee9616267 -r fa2cdef14442 test/integer.tst --- a/test/integer.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/integer.tst Thu Nov 19 13:08:00 2020 -0800 @@ -50,3 +50,111 @@ %! xdiv = clsmax / 0.5; %! assert (xdiv, clsmax); %! endfor + +## Tests for binary constants +%!assert (0b1, uint8 (2^0)) +%!assert (0b10000000, uint8 (2^7)) +%!assert (0b11111111, intmax ("uint8")) +%!assert (0b100000000, uint16 (2^8)) +%!assert (0b1000000000000000, uint16 (2^15)) +%!assert (0b1111111111111111, intmax ("uint16")) +%!assert (0b10000000000000000, uint32 (2^16)) +%!assert (0b10000000000000000000000000000000, uint32 (2^31)) +%!assert (0b11111111111111111111111111111111, intmax ("uint32")) +%!assert (0b100000000000000000000000000000000, uint64 (2^32)) +%!assert (0b1000000000000000000000000000000000000000000000000000000000000000, uint64 (2^63)) +%!assert (0b1111111111111111111111111111111111111111111111111111111111111111, intmax ("uint64")) +%!error <too many digits for binary constant> eval ("0b11111111111111111111111111111111111111111111111111111111111111111") + +%!assert (0b1u16, uint16 (2^0)) +%!assert (0b10000000u16, uint16 (2^7)) + +%!assert (0b1u32, uint32 (2^0)) +%!assert (0b10000000u32, uint32 (2^7)) +%!assert (0b1000000000000000u32, uint32 (2^15)) + +%!assert (0b1u64, uint64 (2^0)) +%!assert (0b10000000u64, uint64 (2^7)) +%!assert (0b1000000000000000u64, uint64 (2^15)) +%!assert (0b10000000000000000000000000000000u64, uint64 (2^31)) + +%!assert (0b1s16, int16 (2^0)) +%!assert (0b10000000s16, int16 (2^7)) + +%!assert (0b1s32, int32 (2^0)) +%!assert (0b10000000s32, int32 (2^7)) +%!assert (0b1000000000000000s32, int32 (2^15)) + +%!assert (0b1s64, int64 (2^0)) +%!assert (0b10000000s64, int64 (2^7)) +%!assert (0b1000000000000000s64, int64 (2^15)) +%!assert (0b10000000000000000000000000000000s64, int64 (2^31)) + +## Tests for hexadecimal constants +%!assert (0x1, uint8 (2^0)) +%!assert (0x80, uint8 (2^7)) +%!assert (0xff, intmax ("uint8")) +%!assert (0x100, uint16 (2^8)) +%!assert (0x8000, uint16 (2^15)) +%!assert (0xffff, intmax ("uint16")) +%!assert (0x10000, uint32 (2^16)) +%!assert (0x80000000, uint32 (2^31)) +%!assert (0xffffffff, intmax ("uint32")) +%!assert (0x100000000, uint64 (2^32)) +%!assert (0x8000000000000000, uint64 (2^63)) +%!assert (0xffffffffffffffff, intmax ("uint64")) +%!error <too many digits for hexadecimal constant> eval ("0xfffffffffffffffff") + +%!assert (0x1u16, uint16 (2^0)) +%!assert (0x80u16, uint16 (2^7)) + +%!assert (0x1u32, uint32 (2^0)) +%!assert (0x80u32, uint32 (2^7)) +%!assert (0x8000u32, uint32 (2^15)) + +%!assert (0x1u64, uint64 (2^0)) +%!assert (0x80u64, uint64 (2^7)) +%!assert (0x8000u64, uint64 (2^15)) +%!assert (0x80000000u64, uint64 (2^31)) + +%!assert (0x1s16, int16 (2^0)) +%!assert (0x80s16, int16 (2^7)) + +%!assert (0x1s32, int32 (2^0)) +%!assert (0x80s32, int32 (2^7)) +%!assert (0x8000s32, int32 (2^15)) + +%!assert (0x1s64, int64 (2^0)) +%!assert (0x80s64, int64 (2^7)) +%!assert (0x8000s64, int64 (2^15)) +%!assert (0x80000000s64, int64 (2^31)) + +## Tests for decimal constants with extreme values + +%!assert (uint64 (9007199254740992), uint64 (flintmax ())) +%!assert (int64 (9007199254740992), int64 (flintmax ())) +%!assert (uint64 (-9007199254740992), uint64 (-flintmax ())) +%!assert (int64 (-9007199254740992), int64 (-flintmax ())) + +%!assert (uint64 (9007199254740993), uint64 (flintmax ())+1) +%!assert (int64 (9007199254740993), int64 (flintmax ())+1) +%!assert (uint64 (-9007199254740993), uint64 (-flintmax ())-1) +%!assert (int64 (-9007199254740993), int64 (-flintmax ())-1) + +%!assert (uint64 (18446744073709551615), intmax ("uint64")) + +%!assert (int64 (9223372036854775807), intmax ("int64")) +%!assert (int64 (-9223372036854775808), intmin ("int64")) + +%!test +%! a = int64 ([9223372036854775803; 9223372036854775804; 9223372036854775805; 9223372036854775806; 9223372036854775807]); +%! bval = int64 (9223372036854775807); +%! b = [bval; bval; bval; bval; bval]; +%! assert (a, b); + +%!test +%! a = int64 ([int64(9223372036854775803); 9223372036854775804; 9223372036854775805; 9223372036854775806; 9223372036854775807]); +%! b0val = int64 (9223372036854775803); +%! bval = int64 (9223372036854775807); +%! b = [b0val; bval; bval; bval; bval]; +%! assert (a, b); diff -r dc3ee9616267 -r fa2cdef14442 test/io.tst --- a/test/io.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/io.tst Thu Nov 19 13:08:00 2020 -0800 @@ -196,7 +196,7 @@ %! [load_status, load_files] = testls (1); %! %! for f = [save_files, load_files] -%! unlink (f{1}); +%! sts = unlink (f{1}); %! endfor %! %! assert (save_status && load_status); @@ -228,7 +228,7 @@ %! assert (s64, s64t); %! assert (u64, u64t); %! unwind_protect_cleanup -%! unlink (h5file); +%! sts = unlink (h5file); %! end_unwind_protect %!test @@ -256,7 +256,7 @@ %! "-struct", "STR", "matrix_fld", "str*_fld"); %! STR = load (struct_dat); %! -%! assert (!isfield (STR,"scalar_fld") && ... +%! assert (! isfield (STR,"scalar_fld") && ... %! STR.matrix_fld == [1.1,2;3,4] && ... %! STR.string_fld == "Octave" && ... %! STR.struct_fld.x == 0 && ... @@ -407,11 +407,11 @@ %% Note use fprintf so output not sent to stdout %!test %! nm = tempname (); -%! fid1 = fopen (nm,"w"); +%! fid1 = fopen (nm, "w"); %! x = fprintf (fid1, "%s: %d\n", "test", 1); %! fclose (fid1); -%! fid2 = fopen (nm,"r"); -%! str = fscanf (fid2,"%s"); +%! fid2 = fopen (nm, "r"); +%! str = fscanf (fid2, "%s"); %! fclose (fid2); %! unlink (nm); %! assert (x, 8); diff -r dc3ee9616267 -r fa2cdef14442 test/jit.tst --- a/test/jit.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/jit.tst Thu Nov 19 13:08:00 2020 -0800 @@ -192,17 +192,17 @@ %! assert (abs (result - 1/9) < 1e-5); %! assert (jit_failcnt, 0); -# %!testif HAVE_LLVM -# %! jit_failcnt (0); -# %! temp = 1+1i; -# %! nan = NaN; -# %! while (1) -# %! temp = temp - 1i; -# %! temp = temp * nan; -# %! break; -# %! endwhile -# %! assert (imag (temp), 0); -# %! assert (jit_failcnt, 0); +## %!testif HAVE_LLVM +## %! jit_failcnt (0); +## %! temp = 1+1i; +## %! nan = NaN; +## %! while (1) +## %! temp = temp - 1i; +## %! temp = temp * nan; +## %! break; +## %! endwhile +## %! assert (imag (temp), 0); +## %! assert (jit_failcnt, 0); %!testif HAVE_LLVM %! jit_failcnt (0); @@ -217,15 +217,15 @@ %! assert (imag (temp), 0); %! assert (jit_failcnt, 0); -# %!testif HAVE_LLVM -# %! jit_failcnt (0); -# %! temp = 1+1i; -# %! while (1) -# %! temp = temp * 5; -# %! break; -# %! endwhile -# %! assert (temp, 5+5i); -# %! assert (jit_failcnt, 0); +## %!testif HAVE_LLVM +## %! jit_failcnt (0); +## %! temp = 1+1i; +## %! while (1) +## %! temp = temp * 5; +## %! break; +## %! endwhile +## %! assert (temp, 5+5i); +## %! assert (jit_failcnt, 0); %!testif HAVE_LLVM %! jit_failcnt (0); @@ -249,22 +249,22 @@ %! assert (sum (mat) == total); %! assert (jit_failcnt, 0); -# %!testif HAVE_LLVM -# %! jit_failcnt (0); -# %! nr = 1001; -# %! mat = [3 1 5]; -# %! try -# %! for i = 1:nr -# %! if (i > 500) -# %! result = mat(100); -# %! else -# %! result = i; -# %! endif -# %! endfor -# %! catch -# %! end_try_catch -# %! assert (result == 500); -# %! assert (jit_failcnt, 0); +## %!testif HAVE_LLVM +## %! jit_failcnt (0); +## %! nr = 1001; +## %! mat = [3 1 5]; +## %! try +## %! for i = 1:nr +## %! if (i > 500) +## %! result = mat(100); +## %! else +## %! result = i; +## %! endif +## %! endfor +## %! catch +## %! end_try_catch +## %! assert (result == 500); +## %! assert (jit_failcnt, 0); %!function result = gen_test (n) %! result = double (rand (1, n) > .01); @@ -388,14 +388,14 @@ %! endfor %!endfunction -# %!testif HAVE_LLVM -# %! jit_failcnt (0); -# %! lasterr (""); -# %! try -# %! test_divide (); -# %! end_try_catch -# %! assert (strcmp (lasterr (), "division by zero")); -# %! assert (jit_failcnt, 0); +## %!testif HAVE_LLVM +## %! jit_failcnt (0); +## %! lasterr (""); +## %! try +## %! test_divide (); +## %! end_try_catch +## %! assert (strcmp (lasterr (), "division by zero")); +## %! assert (jit_failcnt, 0); %!testif HAVE_LLVM %! jit_failcnt (0); @@ -459,17 +459,17 @@ %! assert (a == 9); %! assert (jit_failcnt, 0); -# %!testif HAVE_LLVM -# %! jit_failcnt (0); -# %! num = 2; -# %! a = zeros (1, num); -# %! i = 1; -# %! while i <= num -# %! a(i) = norm (eye (i)); -# %! ++i; -# %! endwhile -# %! assert (a, ones (1, num)); -# %! assert (jit_failcnt, 0); +## %!testif HAVE_LLVM +## %! jit_failcnt (0); +## %! num = 2; +## %! a = zeros (1, num); +## %! i = 1; +## %! while i <= num +## %! a(i) = norm (eye (i)); +## %! ++i; +## %! endwhile +## %! assert (a, ones (1, num)); +## %! assert (jit_failcnt, 0); %!function test_compute_idom () %! while (li <= length (l1) && si <= length (s1)) @@ -583,14 +583,14 @@ %! assert (id (1, 2), 1); %! assert (jit_failcnt, 0); -# %!testif HAVE_LLVM -# %! jit_failcnt (0); -# %! lasterr (""); -# %! try -# %! id (); -# %! end_try_catch -# %! assert (strncmp (lasterr (), "'x' undefined near", 18)); -# %! assert (jit_failcnt, 0); +## %!testif HAVE_LLVM +## %! jit_failcnt (0); +## %! lasterr (""); +## %! try +## %! id (); +## %! end_try_catch +## %! assert (strncmp (lasterr (), "'x' undefined near", 18)); +## %! assert (jit_failcnt, 0); ## Restore JIT settings %!testif HAVE_LLVM diff -r dc3ee9616267 -r fa2cdef14442 test/json/jsondecode_BIST.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/json/jsondecode_BIST.tst Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,556 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Unit tests for jsondecode() +%% +%% Code in libinterp/corefcn/jsondecode.cc +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Note: This script is intended to also run under Matlab to verify +%% compatibility. Preserve Matlab-formatting when making changes. + +%%% Test 1: decode null values + +%% null, in non-numeric arrays -> Empty double [] +%!testif HAVE_RAPIDJSON +%! json = '["str", 5, null, true]'; +%! exp = {'str'; 5; []; true}; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% null, in numeric arrays to NaN (extracted from JSONio) +%!testif HAVE_RAPIDJSON +%! json = '[1, 2, null, 3]'; +%! exp = [1; 2; NaN; 3]; +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%% corner case: array of null values +%!testif HAVE_RAPIDJSON +%! json = '[null, null, null]'; +%! exp = [NaN; NaN; NaN]; +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%%% Test 2: Decode scalar Boolean, Number, and String values + +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsondecode ('true'), logical (1))); +%! assert (isa (jsondecode ('true'), 'logical')); +%! assert (isequal (jsondecode ('false'), logical (0))); +%! assert (isa (jsondecode ('false'), 'logical')); +%! assert (isequal (jsondecode ('123.45'), 123.45)); +%! assert (isequal (jsondecode ('"hello there"'), 'hello there')); + +%%% Test 3: Decode Array of Booleans, Numbers, and Strings values + +%% vectors are always rendered as column vectors +%!testif HAVE_RAPIDJSON +%! json = '[true, true, false, true]'; +%! exp = logical ([1; 1; 0; 1]); +%! obs = jsondecode (json); +%! assert (isa (obs, 'logical')); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON <59135> +%! json = '[[true, true], [false, true]]'; +%! exp = logical ([1, 1; 0, 1]); +%! obs = jsondecode (json); +%! assert (isa (obs, 'logical')); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! json = '["true", "true", "false", "true"]'; +%! exp = {'true'; 'true'; 'false'; 'true'}; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! json = '["foo", "bar", ["foo", "bar"]]'; +%! exp = {'foo'; 'bar'; {'foo'; 'bar'}}; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% vectors are always rendered as column vectors +%!testif HAVE_RAPIDJSON +%! json = '[15000, 5, 12.25, 1502302.3012]'; +%! exp = [15000; 5; 12.25; 1502302.3012]; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% row vectors are preserved by adding one level of hierarchy +%% extracted from JSONio +%!testif HAVE_RAPIDJSON +%! json = '[[1,2]]'; +%! exp = [1, 2]; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% If same dimensions -> transform to an array (extracted from JSONio) +%!testif HAVE_RAPIDJSON +%! json = '[[1, 2], [3, 4]]'; +%! exp = [1, 2; 3, 4]; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% extracted from JSONio +%!testif HAVE_RAPIDJSON +%! json = '[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]'; +%! exp = cat (3, [1, 3; 5, 7], [2, 4; 6, 8]); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% try different dimensions for the array +%!testif HAVE_RAPIDJSON +%! json = '[[[1, 2, -1], [3, 4, null]], [[5, 6, Inf], [7, 8, -Inf]]]'; +%! exp = cat (3, [1, 3; 5, 7], [2, 4; 6, 8], [-1, NaN; Inf, -Inf]); +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%% try different dimensions for the array +%!testif HAVE_RAPIDJSON +%! json = '[[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]'; +%! exp = cat (3, [1, 3; 5, 7; 9, 11], [2, 4; 6, 8; 10, 12]); +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%% try higher dimensions for the array +%!testif HAVE_RAPIDJSON +%! json = ['[[[[1,-1], [2,-2]],[[3,-3],[4,-4]]],[[[5,-5],[6,-6]],[[7,-7],', ... +%! '[8,-8]]],[[[9,-9], [10,-10]],[[11,-11],[12,-12]]],', ... +%! '[[[13,-13],[14,-14]],[[15,-15],[16,-16]]]]']; +%! var1 = cat (3, [1, 3; 5, 7; 9, 11; 13, 15], [2, 4; 6, 8; 10, 12; 14, 16]); +%! var2 = cat (3, [-1, -3; -5, -7; -9, -11; -13, -15], ... +%! [-2, -4; -6, -8; -10, -12; -14, -16]); +%! exp = cat (4, var1, var2); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! json = '[[true, false], [true, false], [true, false]]'; +%! exp = logical ([1 0; 1 0; 1 0]); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% If different dimensions -> transform to a cell array (extracted from JSONio) +%!testif HAVE_RAPIDJSON +%! json = '[[1, 2], [3, 4, 5]]'; +%! exp = {[1; 2]; [3; 4; 5]}; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% extracted from JSONio +%%!testif HAVE_RAPIDJSON +%! json = '[1, 2, [3, 4]]'; +%! exp = {1; 2; [3; 4]}; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! json = '[true, false, [true, false, false]]'; +%! exp = {true; false; logical([1; 0; 0])}; +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); +%! assert (isa (obs{1}, 'logical')); +%! assert (isa (obs{2}, 'logical')); +%! assert (isa (obs{3}, 'logical')); + +%%% Test 4: decode JSON Objects + +%% Check decoding of Boolean, Number, and String values inside an Object +%!testif HAVE_RAPIDJSON +%! json = '{"number": 3.14, "string": "foobar", "boolean": false}'; +%! exp = struct ('number', 3.14, 'string', 'foobar', 'boolean', false); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); +%! assert (isa (obs.boolean, 'logical')); + +%% Check decoding of null values and arrays inside an object & makeValidName +%!testif HAVE_RAPIDJSON +%! json = [ '{"nonnumeric array": ["str", 5, null],' ... +%! '"numeric array": [1, 2, null]}' ]; +%! exp = struct ('nonnumericArray', {{'str'; 5; []}}, ... +%! 'numericArray', {[1; 2; NaN]}); +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%% Check decoding of objects inside an object & makeValidName (from JSONio) +%!testif HAVE_RAPIDJSON +%! json = '{"object": {" field 1 ": 1, "field- 2": 2, "3field": 3, "": 1}}'; +%! exp = struct ('object', ... +%! struct ('field1', 1, 'field_2', 2, 'x3field', 3, 'x', 1)); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% Check decoding of empty objects, empty arrays, and Inf inside an object +%!testif HAVE_RAPIDJSON +%! json = '{"a": Inf, "b": [], "c": {}}'; +%! exp = struct ('a', Inf, 'b', [], 'c', struct ()); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% Check decoding of string arrays inside an object & makeValidName +%% extracted from JSONio +%!testif HAVE_RAPIDJSON +%! json = '{"%string.array": ["Statistical","Parametric","Mapping"]}'; +%! exp = struct ('x_string_array', ... +%! {{'Statistical'; 'Parametric'; 'Mapping'}}); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% extracted from jsonlab +%!testif HAVE_RAPIDJSON +%! json = ['{' , ... +%! '"glossary": { ', ... +%! '"title": "example glossary",', ... +%! '"GlossDiv": {', ... +%! '"title": "S",', ... +%! '"GlossList": {', ... +%! '"GlossEntry": {', ... +%! '"ID": "SGML",', ... +%! '"SortAs": "SGML",', ... +%! '"GlossTerm": "Standard Generalized Markup Language",', ... +%! '"Acronym": "SGML",', ... +%! '"Abbrev": "ISO 8879:1986",', ... +%! '"GlossDef": {', ... +%! '"para": "A meta-markup language, ', ... +%! 'used to create markup languages such as DocBook.",', ... +%! '"GlossSeeAlso": ["GML", "XML"]', ... +%! '},', ... +%! '"GlossSee": "markup"', ... +%! '}', ... +%! '}', ... +%! '}', ... +%! '}', ... +%! '}']; +%! var1 = struct ('para', ['A meta-markup language, used to create ' ... +%! 'markup languages such as DocBook.'], ... +%! 'GlossSeeAlso', {{'GML'; 'XML'}}); +%! var2 = struct ('ID', 'SGML', 'SortAs', 'SGML', ... +%! 'GlossTerm', 'Standard Generalized Markup Language', ... +%! 'Acronym', 'SGML', 'Abbrev', 'ISO 8879:1986', ... +%! 'GlossDef', var1, 'GlossSee', 'markup'); +%! exp = struct ('glossary', ... +%! struct ('title', 'example glossary', ... +%! 'GlossDiv', struct ('title', 'S', ... +%! 'GlossList', ... +%! struct ('GlossEntry', var2)))); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%%% Test 5: decode Array of JSON objects + +%% Arrays with the same field names in the same order (extracted from JSONio) +%!testif HAVE_RAPIDJSON +%! json = '{"structarray": [{"a":1,"b":2},{"a":3,"b":4}]}'; +%! exp = struct ('structarray', struct ('a', {1; 3}, 'b', {2; 4})); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% Different field names before calling makeValidName, BUT the same after +%% calling it, resulting in structarray. +%! json = [ '[', ... +%! '{', ... +%! '"i*d": 0,', ... +%! '"12name": "Osborn"', ... +%! '},', ... +%! '{', ... +%! '"i/d": 1,', ... +%! '"12name": "Mcdowell"', ... +%! '},', ... +%! '{', ... +%! '"i+d": 2,', ... +%! '"12name": "Jewel"', ... +%! '}', ... +%! ']']; +%! exp = struct ('i_d', {0; 1; 2}, ... +%! 'x12name', {'Osborn'; 'Mcdowell'; 'Jewel'}); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% Arrays with the same field names in the same order. +%% JSON text is generated from json-generator.com +%!testif HAVE_RAPIDJSON +%! json = ['[', ... +%! '{', ... +%! '"x_id": "5ee28980fc9ab3",', ... +%! '"index": 0,', ... +%! '"guid": "b229d1de-f94a",', ... +%! '"latitude": -17.124067,', ... +%! '"longitude": -61.161831,', ... +%! '"friends": [', ... +%! '{', ... +%! '"id": 0,', ... +%! '"name": "Collins"', ... +%! '},', ... +%! '{', ... +%! '"id": 1,', ... +%! '"name": "Hays"', ... +%! '},', ... +%! '{', ... +%! '"id": 2,', ... +%! '"name": "Griffin"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{', ... +%! '"x_id": "5ee28980dd7250",', ... +%! '"index": 1,', ... +%! '"guid": "39cee338-01fb",', ... +%! '"latitude": 13.205994,', ... +%! '"longitude": -37.276231,', ... +%! '"friends": [', ... +%! '{', ... +%! '"id": 0,', ... +%! '"name": "Osborn"', ... +%! '},', ... +%! '{', ... +%! '"id": 1,', ... +%! '"name": "Mcdowell"', ... +%! '},', ... +%! '{', ... +%! '"id": 2,', ... +%! '"name": "Jewel"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{', ... +%! '"x_id": "5ee289802422ac",', ... +%! '"index": 2,', ... +%! '"guid": "3db8d55a-663e",', ... +%! '"latitude": -35.453456,', ... +%! '"longitude": 14.080287,', ... +%! '"friends": [', ... +%! '{', ... +%! '"id": 0,', ... +%! '"name": "Socorro"', ... +%! '},', ... +%! '{', ... +%! '"id": 1,', ... +%! '"name": "Darla"', ... +%! '},', ... +%! '{', ... +%! '"id": 2,', ... +%! '"name": "Leanne"', ... +%! '}', ... +%! ']', ... +%! '}', ... +%! ']']; +%! var1 = struct ('id', {0; 1; 2}, 'name', {'Collins'; 'Hays'; 'Griffin'}); +%! var2 = struct ('id', {0; 1; 2}, 'name', {'Osborn'; 'Mcdowell'; 'Jewel'}); +%! var3 = struct ('id', {0; 1; 2}, 'name', {'Socorro'; 'Darla'; 'Leanne'}); +%! exp = struct (... +%! 'x_id', {'5ee28980fc9ab3'; '5ee28980dd7250'; '5ee289802422ac'}, ... +%! 'index', {0; 1; 2}, ... +%! 'guid', {'b229d1de-f94a'; '39cee338-01fb'; '3db8d55a-663e'}, ... +%! 'latitude', {-17.124067; 13.205994; -35.453456}, ... +%! 'longitude', {-61.161831; -37.276231; 14.080287}, ... +%! 'friends', {var1; var2; var3}); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% Arrays with the same field names in different order (extracted from JSONio) +%% Results in cell array, rather than struct array +%!testif HAVE_RAPIDJSON +%! json = '{"cellarray": [{"a":1,"b":2},{"b":3,"a":4}]}'; +%! exp = struct ('cellarray', {{struct('a', 1, 'b', 2); ... +%! struct('b', 3, 'a', 4)}}); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% Arrays with different field names (extracted from JSONio) +%!testif HAVE_RAPIDJSON +%! json = '{"cellarray": [{"a":1,"b":2},{"a":3,"c":4}]}'; +%! exp = struct ('cellarray', {{struct('a', 1, 'b', 2); ... +%! struct('a', 3, 'c', 4)}}); +%! obs = jsondecode (json); +%! assert (isequal (obs, exp)); + +%% Arrays with different field names and a big test +%!testif HAVE_RAPIDJSON +%! json = ['[', ... +%! '{', ... +%! '"x_id": "5ee28980fc9ab3",', ... +%! '"index": 0,', ... +%! '"guid": "b229d1de-f94a",', ... +%! '"latitude": -17.124067,', ... +%! '"longitude": -61.161831,', ... +%! '"friends": [', ... +%! '{', ... +%! '"id": 0,', ... +%! '"name": "Collins"', ... +%! '},', ... +%! '{', ... +%! '"id": 1,', ... +%! '"name": "Hays"', ... +%! '},', ... +%! '{', ... +%! '"id": 2,', ... +%! '"name": "Griffin"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{"numeric array": ["str", 5, null], "nonnumeric array": [1, 2, null]},', ... +%! '{', ... +%! '"firstName": "John",', ... +%! '"lastName": "Smith",', ... +%! '"age": 25,', ... +%! '"address":', ... +%! '{', ... +%! '"streetAddress": "21 2nd Street",', ... +%! '"city": "New York",', ... +%! '"state": "NY"', ... +%! '},', ... +%! '"phoneNumber":', ... +%! '{', ... +%! '"type": "home",', ... +%! '"number": "212 555-1234"', ... +%! '}', ... +%! '}]']; +%! var1 = struct ('x_id', '5ee28980fc9ab3', 'index', 0, ... +%! 'guid', 'b229d1de-f94a', 'latitude', -17.124067, ... +%! 'longitude', -61.161831, ... +%! 'friends', ... +%! struct ('id', {0; 1; 2}, ... +%! 'name', {'Collins'; 'Hays'; 'Griffin'})); +%! var2 = struct ('numericArray', {{'str'; 5; []}}, ... +%! 'nonnumericArray', {[1; 2; NaN]}); +%! var3 = struct ('firstName', 'John', 'lastName', 'Smith', 'age', 25, ... +%! 'address', ... +%! struct ('streetAddress', '21 2nd Street', ... +%! 'city', 'New York', 'state', 'NY'), ... +%! 'phoneNumber', ... +%! struct ('type', 'home', 'number', '212 555-1234')); +%! exp = {var1; var2; var3}; +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%%% Test 6: decode Array of different JSON data types + +%!testif HAVE_RAPIDJSON +%! json = ['[null, true, Inf, 2531.023, "hello there", ', ... +%! '{', ... +%! '"x_id": "5ee28980dd7250",', ... +%! '"index": 1,', ... +%! '"guid": "39cee338-01fb",', ... +%! '"latitude": 13.205994,', ... +%! '"longitude": -37.276231,', ... +%! '"friends": [', ... +%! '{', ... +%! '"id": 0,', ... +%! '"name": "Osborn"', ... +%! '},', ... +%! '{', ... +%! '"id": 1,', ... +%! '"name": "Mcdowell"', ... +%! '},', ... +%! '{', ... +%! '"id": 2,', ... +%! '"name": "Jewel"', ... +%! '}', ... +%! ']', ... +%! '}]']; +%! var = struct ('x_id', '5ee28980dd7250', 'index', 1, ... +%! 'guid', '39cee338-01fb', 'latitude', 13.205994, ... +%! 'longitude', -37.276231, +%! 'friends', struct ('id', {0; 1; 2}, ... +%! 'name', {'Osborn'; 'Mcdowell'; 'Jewel'})); +%! exp = {[]; 1; Inf; 2531.023; 'hello there'; var}; +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%% Array of arrays +%!testif HAVE_RAPIDJSON +%! json = ['[["str", Inf, null], [1, 2, null], ["foo", "bar", ["foo", "bar"]],', ... +%! '[[[1, 2], [3, 4]], [[5, 6], [7, 8]]],' , ... +%! '[', ... +%! '{', ... +%! '"x_id": "5ee28980fc9ab3",', ... +%! '"index": 0,', ... +%! '"guid": "b229d1de-f94a",', ... +%! '"latitude": -17.124067,', ... +%! '"longitude": -61.161831,', ... +%! '"friends": [', ... +%! '{', ... +%! '"id": 0,', ... +%! '"name": "Collins"', ... +%! '},', ... +%! '{', ... +%! '"id": 1,', ... +%! '"name": "Hays"', ... +%! '},', ... +%! '{', ... +%! '"id": 2,', ... +%! '"name": "Griffin"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{"numeric array": ["str", 5, null], "nonnumeric array": [1, 2, null]},', ... +%! '{', ... +%! '"firstName": "John",', ... +%! '"lastName": "Smith",', ... +%! '"age": 25,', ... +%! '"address":', ... +%! '{', ... +%! '"streetAddress": "21 2nd Street",', ... +%! '"city": "New York",', ... +%! '"state": "NY"', ... +%! '},', ... +%! '"phoneNumber":', ... +%! '{', ... +%! '"type": "home",', ... +%! '"number": "212 555-1234"', ... +%! '}', ... +%! '}]]']; +%! var1 = struct ('x_id', '5ee28980fc9ab3', 'index', 0, ... +%! 'guid', 'b229d1de-f94a', 'latitude', -17.124067, ... +%! 'longitude', -61.161831, ... +%! 'friends', struct ('id', {0; 1; 2}, ... +%! 'name', {'Collins'; 'Hays'; 'Griffin'})); +%! var2 = struct ('numericArray', {{'str'; 5; []}}, ... +%! 'nonnumericArray', {[1; 2; NaN]}); +%! var3 = struct ('firstName', 'John', 'lastName', 'Smith', 'age', 25, ... +%! 'address', ... +%! struct ('streetAddress', '21 2nd Street', ... +%! 'city', 'New York', 'state', 'NY'), ... +%! 'phoneNumber', ... +%! struct ('type', 'home', 'number', '212 555-1234')); +%! exp = {{'str'; Inf; []}; [1; 2; NaN]; {'foo'; 'bar'; {'foo'; 'bar'}}; +%! cat(3, [1, 3; 5, 7], [2, 4; 6, 8]); {var1; var2 ;var3}}; +%! obs = jsondecode (json); +%! assert (isequaln (obs, exp)); + +%%% Test 7: Check "ReplacementStyle" and "Prefix" options + +%!testif HAVE_RAPIDJSON +%! json = '{"1a": {"1*a": {"1+*/-a": {"1#a": {}}}}}'; +%! exp = struct ('n1a', ... +%! struct ('n1a', struct ('n1a', struct ('n1a', struct ())))); +%! obs = jsondecode (json, "ReplacementStyle", "delete", ... +%! "Prefix", "_", "Prefix", "n"); +%! assert (isequal (obs, exp)); + +%% Check forwarding of "ReplacementStyle" and "Prefix" options inside arrays +%!testif HAVE_RAPIDJSON +%! json = [ '[', ... +%! '{', ... +%! '"i*d": 0,', ... +%! '"12name": "Osborn"', ... +%! '},', ... +%! '{', ... +%! '"i*d": 1,', ... +%! '"12name": "Mcdowell"', ... +%! '},', ... +%! '{', ... +%! '"i*d": 2,', ... +%! '"12name": "Jewel"', ... +%! '}', ... +%! ']']; +%! exp = struct ('i0x2Ad', {0; 1; 2}, ... +%! 'm_12name', {'Osborn'; 'Mcdowell'; 'Jewel'}); +%! obs = jsondecode (json, "ReplacementStyle", "hex", "Prefix", "m_"); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! json = '{"cell*array": [{"1a":1,"b*1":2},{"1a":3,"b/2":4}]}'; +%! exp = struct ('cell_array', {{struct('x_1a', 1, 'b_1', 2); ... +%! struct('x_1a', 3, 'b_2', 4)}}); +%! obs = jsondecode (json, "ReplacementStyle", "underscore", "Prefix", "x_"); +%! assert (isequal (obs, exp)); diff -r dc3ee9616267 -r fa2cdef14442 test/json/jsonencode_BIST.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/json/jsonencode_BIST.tst Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,658 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Unit tests for jsonencode() +%% +%% Code in libinterp/corefcn/jsonencode.cc +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Note: This script is intended to also run under Matlab to verify +%% compatibility. Preserve Matlab-formatting when making changes. + +%% Some tests here are just the reverse of tests in jsondecode with +%% some modifications. + +%%% Test 1: Encode logical and numeric scalars, NaN, NA, and Inf + +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode (logical (1)), 'true')); +%! assert (isequal (jsonencode (logical (0)), 'false')); +%! assert (isequal (jsonencode (50.025), '50.025')); +%! assert (isequal (jsonencode (NaN), 'null')); +%! assert (isequal (jsonencode (NA), 'null')); % Octave-only test +%! assert (isequal (jsonencode (Inf), 'null')); +%! assert (isequal (jsonencode (-Inf), 'null')); + +%% Customized encoding of Nan, NA, Inf, -Inf +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode (NaN, 'ConvertInfAndNaN', true), 'null')); +%! % Octave-only test for NA +%! assert (isequal (jsonencode (NA, 'ConvertInfAndNaN', true), 'null')); +%! assert (isequal (jsonencode (Inf, 'ConvertInfAndNaN', true), 'null')); +%! assert (isequal (jsonencode (-Inf, 'ConvertInfAndNaN', true), 'null')); + +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode (NaN, 'ConvertInfAndNaN', false), 'NaN')); +%! % Octave-only test for NA +%! assert (isequal (jsonencode (NA, 'ConvertInfAndNaN', false), 'NaN')); +%! assert (isequal (jsonencode (Inf, 'ConvertInfAndNaN', false), 'Infinity')); +%! assert (isequal (jsonencode (-Inf, 'ConvertInfAndNaN', false), '-Infinity')); + +%%% Test 2: encode character vectors and arrays + +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode (''), '""')); +%! assert (isequal (jsonencode ('hello there'), '"hello there"')); +%! assert (isequal (jsonencode (['foo'; 'bar']), '["foo","bar"]')); +%! assert (isequal (jsonencode (['foo', 'bar'; 'foo', 'bar']), ... +%! '["foobar","foobar"]')); + +%% Escape characters inside single-quoted and double-quoted strings +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode ('\0\a\b\t\n\v\f\r'), ... +%! '"\\0\\a\\b\\t\\n\\v\\f\\r"')); +%! % FIXME: Matlab produces a double-escaped string as above. +%! assert (isequal (jsonencode ("\a\b\t\n\v\f\r"), ... +%! '"\u0007\b\t\n\u000B\f\r"')); + +%!testif HAVE_RAPIDJSON +%! data = [[['foo'; 'bar']; ['foo'; 'bar']], [['foo'; 'bar']; ['foo'; 'bar']]]; +%! exp = '["foofoo","barbar","foofoo","barbar"]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = cat (3, ['a', 'b'; 'c', 'd'], ['e', 'f'; 'g', 'h']); +%! exp = '[["ab","ef"],["cd","gh"]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Try different dimensions for the array +%!testif HAVE_RAPIDJSON +%! data = cat (3, ['a', 'b'; 'c', 'd'; '1', '2'], ... +%! ['e', 'f'; 'g', 'h'; '3', '4']); +%! exp = '[["ab","ef"],["cd","gh"],["12","34"]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Try higher dimensions for the array +%!testif HAVE_RAPIDJSON +%! charmat1 = cat (3, ['1', '3'; '5', '7'; '9', 'e'; 'f', 'g'], ... +%! ['2', '4'; '6', '8'; 'a', 'b'; 'c', 'd']); +%! charmat2 = cat (3, ['1', '3'; '5', '7'; '9', 'e'; 'f', 'g'], ... +%! ['2', '4'; '6', '8'; 'a', 'b'; 'c', 'd']); +%! data = cat (4, charmat1, charmat2); +%! exp = [ '[[["13","13"],["24","24"]],[["57","57"],["68","68"]],', ... +%! '[["9e","9e"],["ab","ab"]],[["fg","fg"],["cd","cd"]]]' ]; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Try different dimensions for an array with one of its dimensions equals one +%!testif HAVE_RAPIDJSON +%! data = cat (4, ['a'; 'b'], ['c'; 'd']); +%! exp = '[[["a","c"]],[["b","d"]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% High dimension, but still a vector, is reduced to a vector +%!testif HAVE_RAPIDJSON +%! data = cat (8, ['a'], ['c']); +%! exp = '"ac"'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = cat (8, ['a'; 'b'; '1'], ['c'; 'd'; '2']); +%! exp = '[[[[[[["a","c"]]]]]],[[[[[["b","d"]]]]]],[[[[[["1","2"]]]]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%%% Test 3: encode numeric and logical arrays (with NaN and Inf) + +%% Test simple vectors +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode ([]), '[]')); +%! assert (isequal (jsonencode ([1, 2, 3, 4]), '[1,2,3,4]')); +%! assert (isequal (jsonencode ([true; false; true]), '[true,false,true]')); + +%% Test arrays +%!testif HAVE_RAPIDJSON +%! data = [1, NaN; 3, 4]; +%! exp = '[[1,null],[3,4]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = cat (3, [NaN, 3; 5, Inf], [2, 4; -Inf, 8]); +%! exp = '[[[null,2],[3,4]],[[5,null],[null,8]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Customized encoding of Nan, Inf, -Inf +%!testif HAVE_RAPIDJSON +%! data = cat (3, [1, NaN; 5, 7], [2, Inf; 6, -Inf]); +%! exp = '[[[1,2],[NaN,Infinity]],[[5,6],[7,-Infinity]]]'; +%! obs = jsonencode (data, 'ConvertInfAndNaN', false); +%! assert (isequal (obs, exp)); + +%% Try different dimensions for the array +%!testif HAVE_RAPIDJSON +%! data = cat (3, [1, 3; 5, 7], [2, 4; 6, 8], [-1, NaN; Inf, -Inf]); +%! exp = '[[[1,2,-1],[3,4,NaN]],[[5,6,Infinity],[7,8,-Infinity]]]'; +%! obs = jsonencode (data, 'ConvertInfAndNaN', false); +%! assert (isequal (obs, exp)); + +%% Try different dimensions for the array with one of its dimensions equals one +%!testif HAVE_RAPIDJSON +%! data = cat (3, [1; 7; 11], [4; 8; 12]); +%! exp = '[[[1,4]],[[7,8]],[[11,12]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! array1 = cat (3, [5, 7], [2, 4]); +%! array2 = cat (3, [-1, -3], [-2, -4]); +%! data = cat (4, array1, array2); +%! exp = '[[[[5,-1],[2,-2]],[[7,-3],[4,-4]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = cat (4, [1, 3; 5, 7], [-1, -3; -5, -7]); +%! exp = '[[[[1,-1]],[[3,-3]]],[[[5,-5]],[[7,-7]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% High-dimension vector is reduced to just a vector +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 1, 1, 1, 1, 6]); +%! exp = '[1,1,1,1,1,1]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 2, 2, 2, 2]); +%! exp = '[[[[[1,1],[1,1]],[[1,1],[1,1]]],[[[1,1],[1,1]],[[1,1],[1,1]]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 2, 2, 1, 2]); +%! exp = '[[[[[1,1]],[[1,1]]],[[[1,1]],[[1,1]]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 2, 1, 2, 1, 2]); +%! exp = '[[[[[[1,1]],[[1,1]]]],[[[[1,1]],[[1,1]]]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 1, 2, 1, 2, 1, 2]); +%! exp = '[[[[[[[1,1]],[[1,1]]]],[[[[1,1]],[[1,1]]]]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 2, 2, 1, 1, 2]); +%! exp = '[[[[[[1,1]]],[[[1,1]]]],[[[[1,1]]],[[[1,1]]]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 2, 1, 3, 1, 1, 1, 2]); +%! exp = ['[[[[[[[[1,1]]]],[[[[1,1]]]],[[[[1,1]]]]]],[[[[[[1,1]]]],', ... +%! '[[[[1,1]]]],[[[[1,1]]]]]]]]']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 1, 1, 1, 2, 1, 1, 1, 2]); +%! exp = '[[[[[[[[[1,1]]]],[[[[1,1]]]]]]]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 3, 2, 1, 1, 2, 1, 2, 2]); +%! exp = ['[[[[[[[[[1,1],[1,1]]],[[[1,1],[1,1]]]]]],[[[[[[1,1],', ... +%! '[1,1]]],[[[1,1],[1,1]]]]]]],[[[[[[[1,1],[1,1]]],[[[1,', ... +%! '1],[1,1]]]]]],[[[[[[1,1],[1,1]]],[[[1,1],[1,1]]]]]]],', ... +%! '[[[[[[[1,1],[1,1]]],[[[1,1],[1,1]]]]]],[[[[[[1,1],[1,', ... +%! '1]]],[[[1,1],[1,1]]]]]]]]]']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = ones ([1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 3, 1, 1, 1, 1, 1, 1, 1, 2]); +%! exp = ['[[[[[[[[[[[[[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]],', ... +%! '[[[[[[[[1,1]]]]]]]]],[[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]]]]', ... +%! ']]],[[[[[[[[1,1]]]]]]]]]],[[[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]', ... +%! ']]]]]]],[[[[[[[[1,1]]]]]]]]],[[[[[[[[[1,1]]]]]]]],[[[[[[', ... +%! '[[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]]]]]]],[[[[[[[[[[[[[1,1]', ... +%! ']]]]]]],[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]]],[[[[[[[[', ... +%! '[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]]]],[[[', ... +%! '[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]]],', ... +%! '[[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]]]]]]],[[[[[[[[1,1]]', ... +%! ']]]]]]]]]]]]]]]]]]']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Try higher dimensions for the array +%!testif HAVE_RAPIDJSON +%! var1 = cat (3, [1, 3; 5, 7; 9, 11; 13, 15], [2, 4; 6, 8; 10, 12; 14, 16]); +%! var2 = cat (3, [-1, -3; -5, -7; -9, -11; -13, -15], ... +%! [-2, -4; -6, -8; -10, -12; -14, -16]); +%! data = cat (4, var1, var2); +%! exp = ['[[[[1,-1],[2,-2]],[[3,-3],[4,-4]]],[[[5,-5],[6,-6]],[[7,-7],', ... +%! '[8,-8]]],[[[9,-9],[10,-10]],[[11,-11],[12,-12]]],', ... +%! '[[[13,-13],[14,-14]],[[15,-15],[16,-16]]]]']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Try logical array (tests above were all with numeric data) + +%% 2-D logical array +%!testif HAVE_RAPIDJSON +%! data = [true, false; true, false; true, false]; +%! exp = '[[true,false],[true,false],[true,false]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% N-D logical array +%!testif HAVE_RAPIDJSON <59198> +%! data = true (2,2,2); +%! data(1,1,2) = false; +%! exp = '[[[true,false],[true,true]],[[true,true],[true,true]]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%%% Test 4: encode containers.Map + +%% KeyType must be char to encode objects of containers.Map +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode (containers.Map ('1', [1, 2, 3])), ... +%! '{"1":[1,2,3]}')); + +%!testif HAVE_RAPIDJSON +%! data = containers.Map ({'foo'; 'bar'; 'baz'}, [1, 2, 3]); +%! exp = '{"bar":2,"baz":3,"foo":1}'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON +%! data = containers.Map ({'foo'; 'bar'; 'baz'}, ... +%! {{1, 'hello', NaN}, true, [2, 3, 4]}); +%! exp = '{"bar":true,"baz":[2,3,4],"foo":[1,"hello",NaN]}'; +%! obs = jsonencode (data, 'ConvertInfAndNaN', false); +%! assert (isequal (obs, exp)); + +%%% Test 5: encode scalar structs + +%% Check the encoding of Boolean, Number, and String values inside a struct +%!testif HAVE_RAPIDJSON +%! data = struct ('number', 3.14, 'string', 'foobar', 'boolean', false); +%! exp = '{"number":3.14,"string":"foobar","boolean":false}'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Check the encoding of NaN, NA, Inf, and -Inf values inside a struct +%!testif HAVE_RAPIDJSON +%! % Octave-only test because of NA value +%! data = struct ('numericArray', [7, NaN, NA, Inf, -Inf]); +%! exp = '{"numericArray":[7,null,null,null,null]}'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Customized encoding of Nan, NA, Inf, -Inf +%!testif HAVE_RAPIDJSON +%! data = struct ('numericArray', [7, NaN, NA, Inf, -Inf]); +%! exp = '{"numericArray":[7,NaN,NaN,Infinity,-Infinity]}'; +%! obs = jsonencode (data, 'ConvertInfAndNaN', false); +%! assert (isequal (obs, exp)); + +%% Check the encoding of structs inside a struct +%!testif HAVE_RAPIDJSON +%! data = struct ('object', struct ('field1', 1, 'field2', 2, 'field3', 3)); +%! exp = '{"object":{"field1":1,"field2":2,"field3":3}}'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Check the encoding of empty structs and empty arrays inside a struct +%!testif HAVE_RAPIDJSON +%! data = struct ('a', Inf, 'b', [], 'c', struct ()); +%! exp = '{"a":null,"b":[],"c":{}}'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% a big test +%!testif HAVE_RAPIDJSON +%! var1 = struct ('para', ['A meta-markup language, used to create ' ... +%! 'markup languages such as DocBook.'], ... +%! 'GlossSeeAlso', {{'GML'; 'XML'}}); +%! var2 = struct ('ID', 'SGML', 'SortAs', 'SGML', ... +%! 'GlossTerm', 'Standard Generalized Markup Language', ... +%! 'Acronym', 'SGML', 'Abbrev', 'ISO 8879:1986', ... +%! 'GlossDef', var1, 'GlossSee', 'markup'); +%! data = struct ('glossary', ... +%! struct ('title', 'example glossary', ... +%! 'GlossDiv', struct ('title', 'S', ... +%! 'GlossList', ... +%! struct ('GlossEntry', var2)))); +%! exp = ['{' , ... +%! '"glossary":{', ... +%! '"title":"example glossary",', ... +%! '"GlossDiv":{', ... +%! '"title":"S",', ... +%! '"GlossList":{', ... +%! '"GlossEntry":{', ... +%! '"ID":"SGML",', ... +%! '"SortAs":"SGML",', ... +%! '"GlossTerm":"Standard Generalized Markup Language",', ... +%! '"Acronym":"SGML",', ... +%! '"Abbrev":"ISO 8879:1986",', ... +%! '"GlossDef":{', ... +%! '"para":"A meta-markup language, ', ... +%! 'used to create markup languages such as DocBook.",', ... +%! '"GlossSeeAlso":["GML","XML"]', ... +%! '},', ... +%! '"GlossSee":"markup"', ... +%! '}', ... +%! '}', ... +%! '}', ... +%! '}', ... +%! '}']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%%% Test 6: Encode struct arrays + +%!testif HAVE_RAPIDJSON +%! data = struct ('structarray', struct ('a', {1; 3}, 'b', {2; 4})); +%! exp = '{"structarray":[{"a":1,"b":2},{"a":3,"b":4}]}'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% another big Test +%!testif HAVE_RAPIDJSON +%! var1 = struct ('id', {0; 1; 2}, 'name', {'Collins'; 'Hays'; 'Griffin'}); +%! var2 = struct ('id', {0; 1; 2}, 'name', {'Osborn'; 'Mcdowell'; 'Jewel'}); +%! var3 = struct ('id', {0; 1; 2}, 'name', {'Socorro'; 'Darla'; 'Leanne'}); +%! data = struct (... +%! 'x_id', {'5ee28980fc9ab3'; '5ee28980dd7250'; '5ee289802422ac'}, ... +%! 'index', {0; 1; 2}, ... +%! 'guid', {'b229d1de-f94a'; '39cee338-01fb'; '3db8d55a-663e'}, ... +%! 'latitude', {-17.124067; 13.205994; -35.453456}, ... +%! 'longitude', {-61.161831; -37.276231; 14.080287}, ... +%! 'friends', {var1; var2; var3}); +%! exp = ['[', ... +%! '{', ... +%! '"x_id":"5ee28980fc9ab3",', ... +%! '"index":0,', ... +%! '"guid":"b229d1de-f94a",', ... +%! '"latitude":-17.124067,', ... +%! '"longitude":-61.161831,', ... +%! '"friends":[', ... +%! '{', ... +%! '"id":0,', ... +%! '"name":"Collins"', ... +%! '},', ... +%! '{', ... +%! '"id":1,', ... +%! '"name":"Hays"', ... +%! '},', ... +%! '{', ... +%! '"id":2,', ... +%! '"name":"Griffin"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{', ... +%! '"x_id":"5ee28980dd7250",', ... +%! '"index":1,', ... +%! '"guid":"39cee338-01fb",', ... +%! '"latitude":13.205994,', ... +%! '"longitude":-37.276231,', ... +%! '"friends":[', ... +%! '{', ... +%! '"id":0,', ... +%! '"name":"Osborn"', ... +%! '},', ... +%! '{', ... +%! '"id":1,', ... +%! '"name":"Mcdowell"', ... +%! '},', ... +%! '{', ... +%! '"id":2,', ... +%! '"name":"Jewel"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{', ... +%! '"x_id":"5ee289802422ac",', ... +%! '"index":2,', ... +%! '"guid":"3db8d55a-663e",', ... +%! '"latitude":-35.453456,', ... +%! '"longitude":14.080287,', ... +%! '"friends":[', ... +%! '{', ... +%! '"id":0,', ... +%! '"name":"Socorro"', ... +%! '},', ... +%! '{', ... +%! '"id":1,', ... +%! '"name":"Darla"', ... +%! '},', ... +%! '{', ... +%! '"id":2,', ... +%! '"name":"Leanne"', ... +%! '}', ... +%! ']', ... +%! '}', ... +%! ']']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%%% Test 7: encode cell arrays + +%!testif HAVE_RAPIDJSON +%! assert (isequal (jsonencode ({}), '[]')); +%! assert (isequal (jsonencode ({5}), '[5]')); +%! assert (isequal (jsonencode ({'hello there'}), '["hello there"]')); + +%% Logical cell arrays +%!testif HAVE_RAPIDJSON +%! data = {'true', 'true'; 'false', 'true'}; +%! exp = '["true","false","true","true"]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Cell array of character vectors +%!testif HAVE_RAPIDJSON +%! data = {'foo'; 'bar'; {'foo'; 'bar'}}; +%! exp = '["foo","bar",["foo","bar"]]'; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% cell array of structs & a big test +%!testif HAVE_RAPIDJSON +%! var1 = struct ('x_id', '5ee28980fc9ab3', 'index', 0, ... +%! 'guid', 'b229d1de-f94a', 'latitude', -17.124067, ... +%! 'longitude', -61.161831, ... +%! 'friends', struct ('id', {0; 1; 2}, ... +%! 'name', {'Collins'; 'Hays'; 'Griffin'})); +%! var2 = struct ('numericArray', {{'str'; 5; []}}, ... +%! 'nonnumericArray', {[1; 2; NaN]}); +%! var3 = struct ('firstName', 'John', 'lastName', 'Smith', 'age', 25, ... +%! 'address', ... +%! struct ('streetAddress', '21 2nd Street', ... +%! 'city', 'New York', 'state', 'NY'), ... +%! 'phoneNumber', ... +%! struct ('type', 'home', 'number', '212 555-1234')); +%! data = {var1; var2; var3}; +%! exp = ['[', ... +%! '{', ... +%! '"x_id":"5ee28980fc9ab3",', ... +%! '"index":0,', ... +%! '"guid":"b229d1de-f94a",', ... +%! '"latitude":-17.124067,', ... +%! '"longitude":-61.161831,', ... +%! '"friends":[', ... +%! '{', ... +%! '"id":0,', ... +%! '"name":"Collins"', ... +%! '},', ... +%! '{', ... +%! '"id":1,', ... +%! '"name":"Hays"', ... +%! '},', ... +%! '{', ... +%! '"id":2,', ... +%! '"name":"Griffin"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{"numericArray":["str",5,[]],"nonnumericArray":[1,2,null]},', ... +%! '{', ... +%! '"firstName":"John",', ... +%! '"lastName":"Smith",', ... +%! '"age":25,', ... +%! '"address":', ... +%! '{', ... +%! '"streetAddress":"21 2nd Street",', ... +%! '"city":"New York",', ... +%! '"state":"NY"', ... +%! '},', ... +%! '"phoneNumber":', ... +%! '{', ... +%! '"type":"home",', ... +%! '"number":"212 555-1234"', ... +%! '}', ... +%! '}]']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% cell array of diferrent types & Customized encoding of Nan, Inf, -Inf +%!testif HAVE_RAPIDJSON +%! var = struct ('x_id', '5ee28980dd7250', 'index', 1, ... +%! 'guid', '39cee338-01fb', 'latitude', 13.205994, ... +%! 'longitude', -37.276231, +%! 'friends', struct ('id', {0; 1; 2}, ... +%! 'name', {'Osborn'; 'Mcdowell'; 'Jewel'})); +%! data = {NaN; true; Inf; 2531.023; 'hello there'; var}; +%! exp = ['[NaN,true,Infinity,2531.023,"hello there",', ... +%! '{', ... +%! '"x_id":"5ee28980dd7250",', ... +%! '"index":1,', ... +%! '"guid":"39cee338-01fb",', ... +%! '"latitude":13.205994,', ... +%! '"longitude":-37.276231,', ... +%! '"friends":[', ... +%! '{', ... +%! '"id":0,', ... +%! '"name":"Osborn"', ... +%! '},', ... +%! '{', ... +%! '"id":1,', ... +%! '"name":"Mcdowell"', ... +%! '},', ... +%! '{', ... +%! '"id":2,', ... +%! '"name":"Jewel"', ... +%! '}', ... +%! ']', ... +%! '}]']; +%! obs = jsonencode (data, 'ConvertInfAndNaN', false); +%! assert (isequal (obs, exp)); + +%% a big example +%!testif HAVE_RAPIDJSON +%! var1 = struct ('x_id', '5ee28980fc9ab3', 'index', 0, ... +%! 'guid', 'b229d1de-f94a', 'latitude', -17.124067, ... +%! 'longitude', -61.161831, ... +%! 'friends', struct ('id', {0; 1; 2}, ... +%! 'name', {'Collins'; 'Hays'; 'Griffin'})); +%! var2 = struct ('numericArray', {{'str'; 5; -Inf}}, ... +%! 'nonnumericArray', {[1; 2; NaN]}); +%! var3 = struct ('firstName', 'John', 'lastName', 'Smith', 'age', 25, ... +%! 'address', ... +%! struct ('streetAddress', '21 2nd Street', ... +%! 'city', 'New York', 'state', 'NY'), ... +%! 'phoneNumber', ... +%! struct ('type', 'home', 'number', '212 555-1234')); +%! data = {{'str'; Inf; {}}; [1; 2; NaN]; {'foo'; 'bar'; {'foo'; 'bar'}}; +%! cat(3, [1, 3; 5, 7], [2, 4; 6, 8]); {var1; var2 ;var3}}; +%! exp = ['[["str",null,[]],[1,2,null],["foo","bar",["foo","bar"]],', ... +%! '[[[1,2],[3,4]],[[5,6],[7,8]]],' , ... +%! '[', ... +%! '{', ... +%! '"x_id":"5ee28980fc9ab3",', ... +%! '"index":0,', ... +%! '"guid":"b229d1de-f94a",', ... +%! '"latitude":-17.124067,', ... +%! '"longitude":-61.161831,', ... +%! '"friends":[', ... +%! '{', ... +%! '"id":0,', ... +%! '"name":"Collins"', ... +%! '},', ... +%! '{', ... +%! '"id":1,', ... +%! '"name":"Hays"', ... +%! '},', ... +%! '{', ... +%! '"id":2,', ... +%! '"name":"Griffin"', ... +%! '}', ... +%! ']', ... +%! '},', ... +%! '{"numericArray":["str",5,null],"nonnumericArray":[1,2,null]},', ... +%! '{', ... +%! '"firstName":"John",', ... +%! '"lastName":"Smith",', ... +%! '"age":25,', ... +%! '"address":', ... +%! '{', ... +%! '"streetAddress":"21 2nd Street",', ... +%! '"city":"New York",', ... +%! '"state":"NY"', ... +%! '},', ... +%! '"phoneNumber":', ... +%! '{', ... +%! '"type":"home",', ... +%! '"number":"212 555-1234"', ... +%! '}', ... +%! '}]]']; +%! obs = jsonencode (data); +%! assert (isequal (obs, exp)); + +%% Just basic tests to ensure option "PrettyWriter" is functional. +%!testif HAVE_RAPIDJSON_PRETTYWRITER +%! data = {'Hello'; 'World!'}; +%! exp = do_string_escapes ([ '[\n', ... +%! ' "Hello",\n', ... +%! ' "World!"\n', ... +%! ']' ]); +%! obs = jsonencode (data, 'PrettyWriter', true); +%! assert (isequal (obs, exp)); +%! +%! exp = '["Hello","World!"]'; +%! obs = jsonencode (data, 'PrettyWriter', false); +%! assert (isequal (obs, exp)); + +%!testif HAVE_RAPIDJSON_PRETTYWRITER +%! data = [1, 2; 3, 4]; +%! exp = do_string_escapes ([ ... +%! '[\n' ... +%! ' [\n' ... +%! ' 1,\n' ... +%! ' 2\n' ... +%! ' ],\n' ... +%! ' [\n' ... +%! ' 3,\n' ... +%! ' 4\n' ... +%! ' ]\n' ... +%! ']' ]); +%! obs = jsonencode (data, 'PrettyWriter', true); +%! assert (isequal (obs, exp)); +%! +%! exp = '[[1,2],[3,4]]'; +%! obs = jsonencode (data, 'PrettyWriter', false); +%! assert (isequal (obs, exp)); diff -r dc3ee9616267 -r fa2cdef14442 test/json/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/json/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,5 @@ +json_TEST_FILES = \ + %reldir%/jsondecode_BIST.tst \ + %reldir%/jsonencode_BIST.tst + +TEST_FILES += $(json_TEST_FILES) diff -r dc3ee9616267 -r fa2cdef14442 test/line-continue.tst --- a/test/line-continue.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/line-continue.tst Thu Nov 19 13:08:00 2020 -0800 @@ -61,7 +61,7 @@ %! %!assert (f (), 1) -# String continuation using '\' +## String continuation using '\' %!assert (["abc\ %! def"], "abc def") diff -r dc3ee9616267 -r fa2cdef14442 test/mex/bug-51725.tst --- a/test/mex/bug-51725.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/mex/bug-51725.tst Thu Nov 19 13:08:00 2020 -0800 @@ -24,4 +24,5 @@ ######################################################################## %!assert (bug_51725 (), []) +## Note: ';' is required to suppress output %!error <element number 2 undefined in return list> [x,y,z] = bug_51725 (); diff -r dc3ee9616267 -r fa2cdef14442 test/mex/mexnumtst.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/mex/mexnumtst.c Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,91 @@ +#include "mex.h" + +// To be called with +// +// single array +// complex single array +// double array +// complex double array +// +// Will return arrays of the same type, but created internally to test +// the mxArray -> octave_value conversion + +void +mexFunction (int nlhs, mxArray *plhs[], + int nrhs, const mxArray *prhs[]) +{ + if (nrhs != 4 || nlhs != 4) + mexErrMsgTxt ("invalid arguments"); + + const mxArray *sngl_ra = prhs[0]; + const mxArray *cplx_sngl_ra = prhs[1]; + const mxArray *dble_ra = prhs[2]; + const mxArray *cplx_dble_ra = prhs[3]; + +#if MX_HAS_INTERLEAVED_COMPLEX + + mxSingle *sngl_data = mxGetSingles (sngl_ra); + size_t sngl_data_nr = mxGetM (sngl_ra); + size_t sngl_data_nc = mxGetN (sngl_ra); + + plhs[0] = mxCreateNumericMatrix (sngl_data_nr, sngl_data_nc, mxSINGLE_CLASS, mxREAL); + mxSetSingles (plhs[0], sngl_data); + + mxComplexSingle *cplx_sngl_data = mxGetComplexSingles (cplx_sngl_ra); + size_t cplx_sngl_data_nr = mxGetM (cplx_sngl_ra); + size_t cplx_sngl_data_nc = mxGetN (cplx_sngl_ra); + + plhs[1] = mxCreateNumericMatrix (cplx_sngl_data_nr, cplx_sngl_data_nc, mxSINGLE_CLASS, mxCOMPLEX); + mxSetComplexSingles (plhs[1], cplx_sngl_data); + + mxDouble *dble_data = mxGetDoubles (dble_ra); + size_t dble_data_nr = mxGetM (dble_ra); + size_t dble_data_nc = mxGetN (dble_ra); + + plhs[2] = mxCreateNumericMatrix (dble_data_nr, dble_data_nc, mxDOUBLE_CLASS, mxREAL); + mxSetDoubles (plhs[2], dble_data); + + mxComplexDouble *cplx_dble_data = mxGetComplexDoubles (cplx_dble_ra); + size_t cplx_dble_data_nr = mxGetM (cplx_dble_ra); + size_t cplx_dble_data_nc = mxGetN (cplx_dble_ra); + + plhs[3] = mxCreateNumericMatrix (cplx_dble_data_nr, cplx_dble_data_nc, mxDOUBLE_CLASS, mxCOMPLEX); + mxSetComplexDoubles (plhs[3], cplx_dble_data); + +#else + + mxSingle *sngl_data = (mxSingle *) mxGetData (sngl_ra); + size_t sngl_data_nr = mxGetM (sngl_ra); + size_t sngl_data_nc = mxGetN (sngl_ra); + + mxSingle *cplx_sngl_data_real = (mxSingle *) mxGetData (cplx_sngl_ra); + mxSingle *cplx_sngl_data_imag = (mxSingle *) mxGetImagData (cplx_sngl_ra); + size_t cplx_sngl_data_nr = mxGetM (cplx_sngl_ra); + size_t cplx_sngl_data_nc = mxGetN (cplx_sngl_ra); + + mxDouble *dble_data = (mxDouble *) mxGetData (dble_ra); + size_t dble_data_nr = mxGetM (dble_ra); + size_t dble_data_nc = mxGetN (dble_ra); + + mxDouble *cplx_dble_data_real = (mxDouble *) mxGetData (cplx_dble_ra); + mxDouble *cplx_dble_data_imag = (mxDouble *) mxGetImagData (cplx_dble_ra); + size_t cplx_dble_data_nr = mxGetM (cplx_dble_ra); + size_t cplx_dble_data_nc = mxGetN (cplx_dble_ra); + + plhs[0] = mxCreateNumericMatrix (sngl_data_nr, sngl_data_nc, mxSINGLE_CLASS, mxREAL); + mxSetData (plhs[0], sngl_data); + + plhs[1] = mxCreateNumericMatrix (cplx_sngl_data_nr, cplx_sngl_data_nc, mxSINGLE_CLASS, mxCOMPLEX); + mxSetData (plhs[1], cplx_sngl_data_real); + mxSetImagData (plhs[1], cplx_sngl_data_imag); + + plhs[2] = mxCreateNumericMatrix (dble_data_nr, dble_data_nc, mxDOUBLE_CLASS, mxREAL); + mxSetData (plhs[2], dble_data); + + plhs[3] = mxCreateNumericMatrix (cplx_dble_data_nr, cplx_dble_data_nc, mxDOUBLE_CLASS, mxCOMPLEX); + mxSetData (plhs[3], cplx_dble_data_real); + mxSetImagData (plhs[3], cplx_dble_data_imag); + +#endif + +} diff -r dc3ee9616267 -r fa2cdef14442 test/mex/mexnumtst.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/mex/mexnumtst.tst Thu Nov 19 13:08:00 2020 -0800 @@ -0,0 +1,11 @@ +%!test +%! s = rand (3, 4, "single"); +%! sc = s + i * rand (3, 4, "single"); +%! d = rand (3, 4, "double"); +%! dc = d + i * rand (3, 4, "double"); +%! +%! [sx, scx, dx, dcx] = mexnumtst (s, sc, d, dc); +%! assert (s, sx) +%! assert (sc, scx) +%! assert (d, dx) +%! assert (dc, dcx) diff -r dc3ee9616267 -r fa2cdef14442 test/mex/module.mk --- a/test/mex/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/test/mex/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -1,11 +1,13 @@ mex_TEST_FILES = \ %reldir%/bug-54096.tst \ %reldir%/bug-51725.tst \ + %reldir%/mexnumtst.tst \ $(MEX_TEST_SRC) MEX_TEST_SRC = \ %reldir%/bug_54096.c \ - %reldir%/bug_51725.c + %reldir%/bug_51725.c \ + %reldir%/mexnumtst.c MEX_TEST_FUNCTIONS = $(MEX_TEST_SRC:%.c=%.mex) diff -r dc3ee9616267 -r fa2cdef14442 test/mk-conv-tst.sh --- a/test/mk-conv-tst.sh Thu Nov 19 13:05:51 2020 -0800 +++ b/test/mk-conv-tst.sh Thu Nov 19 13:08:00 2020 -0800 @@ -28,7 +28,7 @@ cat <<EOF ## !!! DO NOT EDIT !!! ## THIS IS AN AUTOMATICALLY GENERATED FILE -## modify build-conv-tests.sh to generate the tests you need. +## modify mk-conv-tst.sh to generate the tests you need. %!shared r,dq,sq,b,bm,dm,cdm,fdm,fcdm,pm,sm,sbm,scm,s,m,cs,cm,fs,fm,fcs,fcm,i8s,i16s,i32s,i64s,i8m,i16m,i32m,i64m,ui8s,ui16s,ui32s,ui64s,ui8m,ui16m,ui32m,ui64m @@ -71,7 +71,12 @@ %! ui32m = uint32 (rand (5) * 10); %! ui64m = uint64 (rand (5) * 10); %! -%!assert (typeinfo (r), "range") +%!test +%! if (disable_range ()) +%! assert (typeinfo (r), "matrix") +%! else +%! assert (typeinfo (r), "range") +%! endif %!assert (typeinfo (dq), "string") %!assert (typeinfo (sq), "sq_string") %!assert (typeinfo (b), "bool") diff -r dc3ee9616267 -r fa2cdef14442 test/mk-sparse-tst.sh --- a/test/mk-sparse-tst.sh Thu Nov 19 13:05:51 2020 -0800 +++ b/test/mk-sparse-tst.sh Thu Nov 19 13:08:00 2020 -0800 @@ -216,7 +216,7 @@ %!assert (nnz (sparse (1,1,0)), 0) %!assert (nnz (sparse (eye (3))*0), 0) %!assert (nnz (sparse (eye (3))-sparse (eye (3))), 0) -%!assert (full (sparse (eye (3))/0), full (eye (3)/0)); +%!assert (full (sparse (eye (3))/0), full (eye (3)/0)) EOF } @@ -576,8 +576,8 @@ %!assert (as', sparse (af')) %!assert (-as, sparse (-af)) %!assert (!as, sparse (!af)) -%!error [i,j] = size (af);as(i-1,j+1); -%!error [i,j] = size (af);as(i+1,j-1); +%!error [i,j] = size (af);as(i-1,j+1) +%!error [i,j] = size (af);as(i+1,j-1) %!test %! [Is,Js,Vs] = find (as); %! [If,Jf,Vf] = find (af); diff -r dc3ee9616267 -r fa2cdef14442 test/mk_bc_overloads_expected.m --- a/test/mk_bc_overloads_expected.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/mk_bc_overloads_expected.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,9 +1,9 @@ -% this script is intended to be Matlab compatible -% first, run the script +%% this script is intended to be Matlab compatible +%% first, run the script % -% ./build_bc_overloads_tests.sh overloads_only +%% ./build_bc_overloads_tests.sh overloads_only % -% to generate the overloaded functions. +%% to generate the overloaded functions. % ex.double = 1; ex.single = single (1); diff -r dc3ee9616267 -r fa2cdef14442 test/module.mk --- a/test/module.mk Thu Nov 19 13:05:51 2020 -0800 +++ b/test/module.mk Thu Nov 19 13:08:00 2020 -0800 @@ -8,6 +8,7 @@ %reldir%/fntests.m \ %reldir%/args.tst \ %reldir%/bug-31371.tst \ + %reldir%/bug-40117.tst \ %reldir%/bug-45969.tst \ %reldir%/bug-45972.tst \ %reldir%/bug-46330.tst \ @@ -90,8 +91,10 @@ include %reldir%/classdef/module.mk include %reldir%/classdef-multiple-inheritance/module.mk include %reldir%/classes/module.mk +include %reldir%/colon-op/module.mk include %reldir%/ctor-vs-method/module.mk include %reldir%/fcn-handle/module.mk +include %reldir%/json/module.mk include %reldir%/local-functions/module.mk include %reldir%/mex/module.mk include %reldir%/nest/module.mk diff -r dc3ee9616267 -r fa2cdef14442 test/nest/arg_nest.m --- a/test/nest/arg_nest.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/arg_nest.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# arg_nest.m +## arg_nest.m function x = arg_nest x = 1; A (x); diff -r dc3ee9616267 -r fa2cdef14442 test/nest/nest.tst --- a/test/nest/nest.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/nest.tst Thu Nov 19 13:08:00 2020 -0800 @@ -156,5 +156,5 @@ %! assert (observed, [1, 2, 1, 3, 2]); ## Test visibility of nested function from script called from parent. -%!assert (script_nest_2 (42), 84); +%!assert (script_nest_2 (42), 84) %!error script_nest_2 (0) diff -r dc3ee9616267 -r fa2cdef14442 test/nest/no_closure.m --- a/test/nest/no_closure.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/no_closure.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# no_closure.m +## no_closure.m function r = no_closure (n) if (ischar (n)) r = nested (n); diff -r dc3ee9616267 -r fa2cdef14442 test/nest/persistent_nest.m --- a/test/nest/persistent_nest.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/persistent_nest.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# persistent_nest +## persistent_nest function y = persistent_nest () persistent x = 0; g; diff -r dc3ee9616267 -r fa2cdef14442 test/nest/recursive_nest.m --- a/test/nest/recursive_nest.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/recursive_nest.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,11 +1,11 @@ -# recursive_nest.m +## recursive_nest.m function x = recursive_nest () global recursive_nest_inc = 1 x = 5; f (20); function f (n) - if n > 0 + if (n > 0) x = x + recursive_nest_inc; f (n - 1); end diff -r dc3ee9616267 -r fa2cdef14442 test/nest/recursive_nest2.m --- a/test/nest/recursive_nest2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/recursive_nest2.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# recursive_nest2.m +## recursive_nest2.m function x = recursive_nest2 () x = B (20); function v = B (n) @@ -7,7 +7,7 @@ C; v = Y; function BB (m) - if m > 0 + if (m > 0) Y = Y + 1; BB(m - 1); C; diff -r dc3ee9616267 -r fa2cdef14442 test/nest/scope0.m --- a/test/nest/scope0.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/scope0.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# scope0.m +## scope0.m function scope0 C; function A diff -r dc3ee9616267 -r fa2cdef14442 test/nest/scope1.m --- a/test/nest/scope1.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/scope1.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,7 +1,7 @@ -# scope1.m +## scope1.m function scope1 (n) value = n; - if value + if (value) C; end function A diff -r dc3ee9616267 -r fa2cdef14442 test/nest/scope2.m --- a/test/nest/scope2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/scope2.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# scope2.m +## scope2.m function scope2 C; function A diff -r dc3ee9616267 -r fa2cdef14442 test/nest/scope3.m --- a/test/nest/scope3.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/scope3.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# scope3.m +## scope3.m function scope3 C; function A diff -r dc3ee9616267 -r fa2cdef14442 test/nest/script_nest.m --- a/test/nest/script_nest.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/script_nest.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,8 +1,8 @@ -# script_nest.m +## script_nest.m function x = script_nest A (5) function A (n) - if n <= 0 + if (n <= 0) script_nest_script; else A (n - 1); diff -r dc3ee9616267 -r fa2cdef14442 test/nest/script_nest_2.m --- a/test/nest/script_nest_2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/script_nest_2.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# script_nest.m +## script_nest.m function r = script_nest_2 (x) function r = nest_fun () r = 13; diff -r dc3ee9616267 -r fa2cdef14442 test/nest/script_nest_script.m --- a/test/nest/script_nest_script.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/script_nest_script.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,2 +1,2 @@ -# script_nest_script.m +## script_nest_script.m x = 5; diff -r dc3ee9616267 -r fa2cdef14442 test/nest/script_nest_script_2.m --- a/test/nest/script_nest_script_2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/script_nest_script_2.m Thu Nov 19 13:08:00 2020 -0800 @@ -1,4 +1,4 @@ -# script_nest_script.m +## script_nest_script.m if (x > 0) r = x * 2; else diff -r dc3ee9616267 -r fa2cdef14442 test/nest/varg_nest2.m --- a/test/nest/varg_nest2.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/nest/varg_nest2.m Thu Nov 19 13:08:00 2020 -0800 @@ -2,12 +2,12 @@ [a, b] = f; x = a; - if nargout == 1 + if (nargout == 1) x = a; endif function [a, b] = f - if nargout == 2 + if (nargout == 2) a = b = 5; endif endfunction diff -r dc3ee9616267 -r fa2cdef14442 test/parser.tst --- a/test/parser.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/parser.tst Thu Nov 19 13:08:00 2020 -0800 @@ -104,7 +104,7 @@ %! assert (2 ^++a, 8); %! assert (a, 3); %! assert (a' ^2, 9); -%! assert (2 ^sin(0), 1); +%! assert (2 ^sin (0), 1); %! assert (-2 ^2, -4);; %! assert (2 ^+1 ^3, 8); %! assert (2 ^-1 ^3, 0.125); @@ -214,7 +214,7 @@ ## Level 13 (parentheses and indexing) %!test %! a.b1 = 2; -%! assert (a.(strcat('b','1'))++, 2); +%! assert (a.(strcat ('b','1'))++, 2); %! assert (a.b1, 3); %! b = {1 2 3 4 5}; %! assert (b{(a. b1 + 1)}, 4); @@ -286,19 +286,19 @@ %!assert (123_456, 123456) %!assert (.123_456, .123456) %!assert (123_456.123_456, 123456.123456) -%!assert (0xAB_CD, 43981) +%!assert (0xAB_CD, uint16 (43981)) %!assert (2e0_1, 20) ## Test binary constants -%!assert (0b101, 5) +%!assert (0b101, uint8 (5)) %!assert (0B1100_0001, 0xC1) -%!assert (class (0b1), "double") +%!assert (class (0b1), "uint8") ## Test range of large binary and hexadecimal literals -%!assert (0x8000_0000_0000_0000, 2^63) -%!assert (0xFFFF_FFFF_FFFF_FFFF, 2^64) -%!assert (0b10000000_0000000_000000000_00000000_00000000_00000000_00000000_00000000, 2^63) -%!assert (0b11111111_1111111_111111111_11111111_11111111_11111111_11111111_11111111, 2^64) +%!assert (0x8000_0000_0000_0000, uint64 (2^63)) +%!assert (0xFFFF_FFFF_FFFF_FFFF, uint64 (2^64)) +%!assert (0b10000000_0000000_000000000_00000000_00000000_00000000_00000000_00000000, uint64 (2^63)) +%!assert (0b11111111_1111111_111111111_11111111_11111111_11111111_11111111_11111111, uint64 (2^64)) ## Test creation of anonymous functions @@ -335,7 +335,7 @@ #!error <vertical dimensions mismatch \(1x2 vs 1x1\)> z = [1, 2; 3] %!test -%! f = @(s,t=toeplitz(s),u=t(x=2:end-1,x)=32)t; +%! f = @(s,t=toeplitz (s),u=t(x=2:end-1,x)=32)t; %! assert (f (1), 1); %! assert (f (1, 2), 2); diff -r dc3ee9616267 -r fa2cdef14442 test/pkg/pkg.tst --- a/test/pkg/pkg.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/pkg/pkg.tst Thu Nov 19 13:08:00 2020 -0800 @@ -31,6 +31,11 @@ %!shared old_prefix, old_archprefix, old_local_list, old_global_list, prefix, restorecfg, restorecache, restoreglobalcache, rmtmpdir, mfile_pkg_name, mfile_pkg_tgz +%!function test_cleanup (prefix) +%! confirm_recursive_rmdir (0, "local"); +%! sts = rmdir (prefix, "s"); +%!endfunction + %!testif HAVE_Z %! ## Do all tests in a temporary directory %! [old_prefix, old_archprefix] = pkg ("prefix"); @@ -48,7 +53,7 @@ %! pkg ("prefix", prefix, prefix); %! pkg ("local_list", fullfile (prefix, "octave_packages")); %! pkg ("global_list", fullfile (prefix, "octave_packages")); -%! rmtmpdir = @onCleanup (@() confirm_recursive_rmdir (0, "local") && rmdir (prefix, "s")); +%! rmtmpdir = @onCleanup (@() test_cleanup (prefix)); %! %! ## Create tar.gz file packages of testing directories in prefix directory %! mfile_pkg_name = {"mfile_basic_test", "mfile_minimal_test"}; @@ -74,7 +79,7 @@ %! %!error pkg ("install", "nonexistent.zip") -# -local +## -local %!testif HAVE_Z %! for i = 1:numel (mfile_pkg_name) %! silent_pkg_install ("-local", mfile_pkg_tgz{i}); @@ -82,18 +87,18 @@ %! pkg ("uninstall", mfile_pkg_name{i}); %! endfor -# -forge (need check for options?) +## -forge (need check for options?) ## FIXME: Need test -# We do not test this yet ... fails if no internet connection -# use dataframe which is an mfile only package +## We do not test this yet ... fails if no internet connection +## use dataframe which is an mfile only package #%!test #%! silent_pkg_install ("-forge", "dataframe"); #%! pkg ("uninstall", "dataframe"); -# -nodeps +## -nodeps ## FIXME: Need test -# -verbose +## -verbose ## FIXME: Need test ## Action load/unload (within install/uninstall) @@ -111,19 +116,19 @@ %! end_unwind_protect %! endfor %! -%!error <package foobar is not installed> pkg ("load", "foobar"); +%!error <package foobar is not installed> pkg ("load", "foobar") -# -nodeps +## -nodeps ## FIXME: Need test -# -verbose +## -verbose ## FIXME: Need test ## Action list %!test %! [user_packages, system_packages] = pkg ("list"); -# -forge +## -forge #%!test #%! oct_forge_pkgs = pkg ("list", "-forge"); @@ -136,7 +141,7 @@ %! system (["chmod -Rf u+w '" prefix "'"]); ## FIXME: Work around bug #53578 %! pkg ("uninstall", mfile_pkg_name{1}); -# -verbose +## -verbose ## FIXME: Need test ## Action prefix @@ -151,11 +156,11 @@ ## Action build ## FIXME: Need test -# pkg build -verbose /tmp image-* +## pkg build -verbose /tmp image-* ## Action rebuild ## FIXME: Need test -# pkg rebuild signal +## pkg rebuild signal ## Future commands %!error pkg ("whereis", "myfunc.m") diff -r dc3ee9616267 -r fa2cdef14442 test/publish/publish.tst --- a/test/publish/publish.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/publish/publish.tst Thu Nov 19 13:08:00 2020 -0800 @@ -49,7 +49,7 @@ %! publish (fname{1}, opts); %! endfor %! confirm_recursive_rmdir (false, "local"); -%! rmdir (tmpDir, "s"); +%! sts = rmdir (tmpDir, "s"); %! unwind_protect_cleanup %! set (0, "defaultfigurevisible", visibility); %! graphics_toolkit (toolkit); @@ -81,7 +81,7 @@ %! str1 = fileread ("test_script.m"); %! str2 = grabcode (fullfile (tmpDir, "test_script.html")); %! confirm_recursive_rmdir (false, "local"); -%! rmdir (tmpDir, "s"); +%! sts = rmdir (tmpDir, "s"); %! ## Canonicalize strings %! str1 = strjoin (deblank (strsplit (str1, "\n")), "\n"); %! str2 = strjoin (deblank (strsplit (str2, "\n")), "\n"); diff -r dc3ee9616267 -r fa2cdef14442 test/publish/test_script.m --- a/test/publish/test_script.m Thu Nov 19 13:05:51 2020 -0800 +++ b/test/publish/test_script.m Thu Nov 19 13:08:00 2020 -0800 @@ -32,7 +32,7 @@ i = 0:2*pi # some real comment -y = sin(i) +y = sin (i) %% % @@ -43,16 +43,16 @@ x = 0:2*pi # some real comment and split code block -y = sin(x) +y = sin (x) %% % % reusing old values -y = cos(i) +y = cos (i) # some real comment and split code block -y = cos(x) +y = cos (x) %% Text formatting % PLAIN TEXT _ITALIC TEXT_ *BOLD TEXT* |MONOSPACED TEXT| diff -r dc3ee9616267 -r fa2cdef14442 test/struct.tst --- a/test/struct.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/struct.tst Thu Nov 19 13:08:00 2020 -0800 @@ -37,7 +37,7 @@ %!test %! s.a = 1; -%! fail ("fieldnames (s, 1)", "Invalid call to fieldnames"); +%! fail ("fieldnames (s, 1)", "called with too many inputs"); %!error fieldnames (1) diff -r dc3ee9616267 -r fa2cdef14442 test/system.tst --- a/test/system.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/system.tst Thu Nov 19 13:08:00 2020 -0800 @@ -98,13 +98,13 @@ %! assert ((e1 && strcmp (s2.modestr(1), "d") && e3 && e4 < 0)); %!error <Invalid call to mkdir> mkdir () -%!error <Invalid call to mkdir> mkdir ("foo", 1, 2) +%!error <called with too many inputs> mkdir ("foo", 1, 2) %!error <Invalid call to rmdir> rmdir () %!test %! crr = confirm_recursive_rmdir (); %! confirm_recursive_rmdir (0); -%! assert (!rmdir ("foo", "s")); +%! assert (! rmdir ("foo", "s")); %! confirm_recursive_rmdir (crr); %!test diff -r dc3ee9616267 -r fa2cdef14442 test/try.tst --- a/test/try.tst Thu Nov 19 13:05:51 2020 -0800 +++ b/test/try.tst Thu Nov 19 13:08:00 2020 -0800 @@ -47,7 +47,7 @@ %! catch %! end_try_catch %! a = 2; -%! assert (!exist ('x')); +%! assert (! exist ('x')); %! assert (a,2); %!test @@ -65,9 +65,9 @@ %! a; %! error ("Shouldn't get here"); %! catch -%! assert (lasterr()(1:13), "'a' undefined"); +%! assert (lasterr ()(1:13), "'a' undefined"); %! end_try_catch -%! assert (lasterr()(1:13), "'a' undefined"); +%! assert (lasterr ()(1:13), "'a' undefined"); %!test %! try @@ -96,13 +96,13 @@ %! a; %! error ("Shouldn't get here"); %! catch -%! assert (lasterr()(1:13), "'a' undefined"); +%! assert (lasterr ()(1:13), "'a' undefined"); %! end_try_catch %! clear b; %! b; %! error ("Shouldn't get here"); %! catch -%! assert (lasterr()(1:13), "'b' undefined"); +%! assert (lasterr ()(1:13), "'b' undefined"); %! end_try_catch %!test @@ -112,12 +112,12 @@ %! error ("Shouldn't get here"); %! catch %! try -%! assert (lasterr()(1:13), "'a' undefined"); +%! assert (lasterr ()(1:13), "'a' undefined"); %! clear b; %! b; %! error ("Shouldn't get here"); %! catch -%! assert (lasterr()(1:13), "'b' undefined"); +%! assert (lasterr ()(1:13), "'b' undefined"); %! end_try_catch %! end_try_catch @@ -131,7 +131,7 @@ %! error (["rethrow: " lasterr]); %! end_try_catch %! catch -%! assert (lasterr()(1:22), "rethrow: 'a' undefined"); +%! assert (lasterr ()(1:22), "rethrow: 'a' undefined"); %! end_try_catch %!test