# HG changeset patch # User Rik # Date 1572883777 28800 # Node ID 2890a931e64734c70e8b0201ba504d70f0377791 # Parent ef31cf01917fcb5c51776b153cbb4a80e78abfa1 Deprecated sizemax function (bug #47469). * scripts/deprecated/sizemax.m: New m-file to produce a warning and provide sizemax() behavior for the next two Octave releases. * scripts/deprecated/module.mk: Add sizemax.m to build system. * bitfcns.cc (Fsizemax): Remove function. * dim-vector.h (dim_max): Add OCTAVE_DEPRECATED macro to function. * dim-vector.cc (safe_numel): Call std::numeric_limits::max rather than dim_max(). * __sprand__.m: Replace sizemax() invocation with new code. * numbers.txi: Remove DOCSTRING entry for sizemax and add text explaining actual size limitation imposed by size of index pointers when Octave was compiled. diff -r ef31cf01917f -r 2890a931e647 doc/interpreter/numbers.txi --- a/doc/interpreter/numbers.txi Mon Nov 04 16:21:14 2019 +0100 +++ b/doc/interpreter/numbers.txi Mon Nov 04 08:09:37 2019 -0800 @@ -277,11 +277,10 @@ separate matrix elements and rows. The maximum number of elements in a matrix is fixed when Octave is compiled. -The allowable number can be queried with the function @code{sizemax}. Note -that other factors, such as the amount of memory available on your machine, -may limit the maximum size of matrices to something smaller. - -@DOCSTRING(sizemax) +If compiled with 64-bit index pointers the limit is @code{intmax ("int64")}, +otherwise it is @code{intmax ("int32")}. Note that other factors, such as the +amount of memory available on your machine, may limit the maximum size of +matrices to something smaller. When you type a matrix or the name of a variable whose value is a matrix, Octave responds by printing the matrix in with neatly aligned diff -r ef31cf01917f -r 2890a931e647 libinterp/corefcn/bitfcns.cc --- a/libinterp/corefcn/bitfcns.cc Mon Nov 04 16:21:14 2019 +0100 +++ b/libinterp/corefcn/bitfcns.cc Mon Nov 04 08:09:37 2019 -0800 @@ -946,27 +946,3 @@ %!error intmin ("double") %!error intmin ("char") */ - -DEFUN (sizemax, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} sizemax () -Return the largest value allowed for the size of an array. - -If Octave is compiled with 64-bit indexing, the result is of class int64, -otherwise it is of class int32. The maximum array size is slightly -smaller than the maximum value allowable for the relevant class as reported -by @code{intmax}. -@seealso{intmax} -@end deftypefn */) -{ - if (args.length () != 0) - print_usage (); - - return octave_value (octave_int (dim_vector::dim_max ())); -} - -/* -%!assert (sizemax () >= (intmax ("int32") - 1)) - -%!error sizemax (0) -*/ diff -r ef31cf01917f -r 2890a931e647 liboctave/array/dim-vector.cc --- a/liboctave/array/dim-vector.cc Mon Nov 04 16:21:14 2019 +0100 +++ b/liboctave/array/dim-vector.cc Mon Nov 04 08:09:37 2019 -0800 @@ -39,6 +39,7 @@ return zv.rep; } +// FIXME: DEPRECATED, remove in version 8. // The maximum allowed value for a dimension extent. This will normally be a // tiny bit off the maximum value of octave_idx_type. // Currently 1 is subtracted to allow safe conversion of any 2D Array into @@ -102,7 +103,7 @@ octave_idx_type dim_vector::safe_numel (void) const { - octave_idx_type idx_max = dim_max (); + octave_idx_type idx_max = std::numeric_limits::max (); octave_idx_type n = 1; int n_dims = ndims (); diff -r ef31cf01917f -r 2890a931e647 liboctave/array/dim-vector.h --- a/liboctave/array/dim-vector.h Mon Nov 04 16:21:14 2019 +0100 +++ b/liboctave/array/dim-vector.h Mon Nov 04 08:09:37 2019 -0800 @@ -261,6 +261,7 @@ public: + OCTAVE_DEPRECATED (6, "dim_vector::dim_max () is deprecated; any uses should be removed") static octave_idx_type dim_max (void); explicit dim_vector (void) : rep (nil_rep ()) diff -r ef31cf01917f -r 2890a931e647 scripts/deprecated/module.mk --- a/scripts/deprecated/module.mk Mon Nov 04 16:21:14 2019 +0100 +++ b/scripts/deprecated/module.mk Mon Nov 04 08:09:37 2019 -0800 @@ -2,7 +2,8 @@ %canon_reldir%_FCN_FILES = \ %reldir%/output_max_field_width.m \ - %reldir%/runtests.m + %reldir%/runtests.m \ + %reldir%/sizemax.m %canon_reldir%dir = $(fcnfiledir)/deprecated diff -r ef31cf01917f -r 2890a931e647 scripts/deprecated/sizemax.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/sizemax.m Mon Nov 04 08:09:37 2019 -0800 @@ -0,0 +1,58 @@ +## Copyright (C) 2019 Rik Wehbring +## +## 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 {} {} sizemax () +## +## @code{sizemax} is deprecated and will be removed in Octave version 8. +## +## Return the largest value allowed for the size of an array. +## +## If Octave is compiled with 64-bit indexing, the result is of class int64, +## otherwise it is of class int32. The maximum array size is slightly smaller +## than the maximum value allowable for the relevant class as reported by +## @code{intmax}. +## @seealso{intmax} +## @end deftypefn + +## FIXME: DEPRECATED: Remove in version 8. + +function retval = sizemax (varargin) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "sizemax is obsolete and will be removed from a future version of Octave\n"); + endif + + if (nargin != 0) + print_usage (); + endif + + if (__have_feature__ ("ENABLE_64")) + retval = intmax ("int64") - 1; + else + retval = intmax ("int32") - 1; + endif + +endfunction + + +%!assert (sizemax () >= (intmax ("int32") - 1)) +%!error sizemax (0) diff -r ef31cf01917f -r 2890a931e647 scripts/sparse/private/__sprand__.m --- a/scripts/sparse/private/__sprand__.m Mon Nov 04 16:21:14 2019 +0100 +++ b/scripts/sparse/private/__sprand__.m Mon Nov 04 08:09:37 2019 -0800 @@ -56,7 +56,13 @@ if (nargin == 5) mn = m*n; k = round (d*mn); - if (mn > sizemax ()) + ## FIXME: randperm() should be fixed to handle large values + if (__have_feature__ ("ENABLE_64")) + max_numel = intmax ("int64"); + else + max_numel = intmax ("int32"); + endif + if (mn > max_numel) ## randperm will overflow, so use alternative methods idx = unique (fix (rand (1.01*k, 1) * mn)) + 1;