changeset 31460:0f968958d7d5

eliminate Range class functions that are no longer needed The Range class was deprecated in Octave 7 and should now be removed from any public interfaces but we need it (or some replacement) to allow legacy range objects to be loaded from files created by old versions of Octave. This change is a start at doing this job. In a future change, we might move the Range class from Range.h to ov-legacy-range.cc, which is the only place where it is used, and eliminate the Range data member from the octave_legacy_range class. * ov.h, ov.cc (octave_value::make_range_rep_deprecated): Delete unnecessary functions. * ov.cc: Don't include Range.h. * xpow.h: Delete forward declaration of Range. * Range.h, Range.cc (Range::nnz, Range::checkelem, Range::elem, Range::index, Range::sort_internal, Range::diag, Range::sort, Range::issorted, Range::set_base, Range::set_limit, Range::set_inc, Range::inc, Range::final_value, Range::dims, Range::rows, Range::cols, Range::columns, Range::isempty, Range::operator ()): Delete. (operator << (std::ostream&, const Range&), operator >> (std::istream&, Range&)): Delete. (operator - (const Range&), operator + (double, const Range&), operator + (const Range&, double), operator - (double, const Range&) operator - (const Range&, double), operator * (double, const Range&) operator * (const Range&, double)): Delete functions and friend decls. * doc/liboctave/range.texi: Delete docs for Range class.
author John W. Eaton <jwe@octave.org>
date Wed, 16 Nov 2022 14:05:18 -0500
parents ccb28d9a1a62
children 7dcd8e3a705d
files doc/liboctave/range.texi libinterp/corefcn/xpow.h libinterp/octave-value/ov.cc libinterp/octave-value/ov.h liboctave/array/Range.cc liboctave/array/Range.h
diffstat 6 files changed, 1 insertions(+), 461 deletions(-) [+]
line wrap: on
line diff
--- a/doc/liboctave/range.texi	Wed Nov 16 19:24:48 2022 +0100
+++ b/doc/liboctave/range.texi	Wed Nov 16 14:05:18 2022 -0500
@@ -20,35 +20,6 @@
 @chapter Ranges
 @cindex ranges
 
-@deftypefn  {} {} Range (void)
-@deftypefnx  {} {} Range (const Range &@var{r})
-@deftypefnx  {} {} Range (double @var{b}, double @var{l})
-@deftypefnx  {} {} Range (double @var{b}, double @var{l}, double @var{i})
-@end deftypefn
-
-@deftypefn {} double base (void) const
-@deftypefnx {} double limit (void) const
-@deftypefnx {} double inc (void) const
-@end deftypefn
-
-@deftypefn {} void set_base (double @var{b})
-@deftypefnx {} void set_limit (double @var{l})
-@deftypefnx {} void set_inc (double @var{i})
-@end deftypefn
+FIXME: The @code{Range} class is obsolete.
 
-@deftypefn {} int nelem (void) const
 @end deftypefn
-
-@deftypefn {} double min (void) const
-@deftypefnx {} double max (void) const
-@end deftypefn
-
-@deftypefn {} void sort (void)
-@end deftypefn
-
-@deftypefn {} {ostream&} {operator <<} (ostream &@var{os}, const Range &@var{r})
-@deftypefnx {} {istream&} {operator >>} (istream &@var{is}, Range &@var{r})
-@end deftypefn
-
-@deftypefn {} void print_range (void)
-@end deftypefn
--- a/libinterp/corefcn/xpow.h	Wed Nov 16 19:24:48 2022 +0100
+++ b/libinterp/corefcn/xpow.h	Wed Nov 16 14:05:18 2022 -0500
@@ -44,7 +44,6 @@
 class ComplexNDArray;
 class FloatComplexNDArray;
 class octave_value;
-class Range;
 
 OCTAVE_NAMESPACE_BEGIN
 
--- a/libinterp/octave-value/ov.cc	Wed Nov 16 19:24:48 2022 +0100
+++ b/libinterp/octave-value/ov.cc	Wed Nov 16 14:05:18 2022 -0500
@@ -1073,36 +1073,6 @@
   maybe_mutate ();
 }
 
-// Remove when public constructor that uses this function is removed.
-octave_base_value *
-octave_value::make_range_rep_deprecated (double base, double inc, double limit)
-{
-#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
-#  pragma GCC diagnostic push
-#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
-
-  return dynamic_cast<octave_base_value *>
-    (new octave_legacy_range (Range (base, inc, limit)));
-
-#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
-#  pragma GCC diagnostic pop
-#endif
-}
-
-// Remove when public constructor that uses this function is removed.
-octave_base_value *
-octave_value::make_range_rep_deprecated (const Range& r, bool force_range)
-{
-  if (! force_range && ! r.ok ())
-    error ("invalid range");
-
-  if ((force_range || Voptimize_range))
-    return dynamic_cast<octave_base_value *> (new octave_legacy_range (r));
-  else
-    return dynamic_cast<octave_base_value *> (new octave_matrix (r.matrix_value ()));
-}
-
 octave_value::octave_value (const octave::range<double>& r, bool force_range)
   : m_rep (force_range || Voptimize_range
            ? dynamic_cast<octave_base_value *> (new ov_range<double> (r))
--- a/libinterp/octave-value/ov.h	Wed Nov 16 19:24:48 2022 +0100
+++ b/libinterp/octave-value/ov.h	Wed Nov 16 14:05:18 2022 -0500
@@ -36,7 +36,6 @@
 #include <memory>
 #include <map>
 
-#include "Range.h"
 #include "data-conv.h"
 #include "idx-vector.h"
 #include "mach-info.h"
@@ -288,18 +287,6 @@
   OCTINTERP_API octave_value (const Array<std::string>& cellstr);
   OCTINTERP_API octave_value (const octave::idx_vector& idx, bool lazy = true);
 
-private:
-
-  // Remove when public constructors that use this function are removed.
-  static OCTINTERP_API octave_base_value *
-  make_range_rep_deprecated (double base, double inc, double limit);
-
-  // Remove when public constructors that use this function are removed.
-  static OCTINTERP_API octave_base_value *
-  make_range_rep_deprecated (const Range& r, bool force_range);
-
-public:
-
   OCTINTERP_API octave_value (const octave::range<double>& r,
                               bool force_range = false);
 
--- a/liboctave/array/Range.cc	Wed Nov 16 19:24:48 2022 +0100
+++ b/liboctave/array/Range.cc	Wed Nov 16 14:05:18 2022 -0500
@@ -465,41 +465,6 @@
           && (octave::math::nint_big (m_inc) == m_inc || m_numel <= 1));
 }
 
-octave_idx_type
-Range::nnz (void) const
-{
-  octave_idx_type retval = 0;
-
-  if (! isempty ())
-    {
-      if ((m_base > 0.0 && m_limit > 0.0) || (m_base < 0.0 && m_limit < 0.0))
-        {
-          // All elements have the same sign, hence there are no zeros.
-          retval = m_numel;
-        }
-      else if (m_inc != 0.0)
-        {
-          if (m_base == 0.0 || m_limit == 0.0)
-            // Exactly one zero at beginning or end of range.
-            retval = m_numel - 1;
-          else if ((m_base / m_inc) != std::floor (m_base / m_inc))
-            // Range crosses negative/positive without hitting zero.
-            retval = m_numel;
-          else
-            // Range crosses negative/positive and hits zero.
-            retval = m_numel - 1;
-        }
-      else
-        {
-          // All elements are equal (m_inc = 0) but not positive or negative,
-          // therefore all elements are zero.
-          retval = 0;
-        }
-    }
-
-  return retval;
-}
-
 Matrix
 Range::matrix_value (void) const
 {
@@ -522,85 +487,6 @@
   return retval;
 }
 
-double
-Range::checkelem (octave_idx_type i) const
-{
-  if (i < 0 || i >= m_numel)
-    octave::err_index_out_of_range (2, 2, i+1, m_numel, dims ());
-
-  if (i == 0)
-    return m_base;
-  else if (i < m_numel - 1)
-    return m_base + i * m_inc;
-  else
-    return m_limit;
-}
-
-double
-Range::checkelem (octave_idx_type i, octave_idx_type j) const
-{
-  // Ranges are *always* row vectors.
-  if (i != 0)
-    octave::err_index_out_of_range (1, 1, i+1, m_numel, dims ());
-
-  return checkelem (j);
-}
-
-double
-Range::elem (octave_idx_type i) const
-{
-  if (i == 0)
-    return m_base;
-  else if (i < m_numel - 1)
-    return m_base + i * m_inc;
-  else
-    return m_limit;
-}
-
-Array<double>
-Range::index (const octave::idx_vector& idx) const
-{
-  Array<double> retval;
-
-  octave_idx_type n = m_numel;
-
-  if (idx.is_colon ())
-    {
-      retval = matrix_value ().reshape (dim_vector (m_numel, 1));
-    }
-  else
-    {
-      if (idx.extent (n) != n)
-        octave::err_index_out_of_range (1, 1, idx.extent (n), n, dims ()); // throws
-
-      dim_vector idx_dims = idx.orig_dimensions ();
-      octave_idx_type idx_len = idx.length (n);
-
-      // taken from Array.cc.
-      if (n != 1 && idx_dims.isvector ())
-        idx_dims = dim_vector (1, idx_len);
-
-      retval.clear (idx_dims);
-
-      // Loop over all values in IDX, executing the lambda expression
-      // for each index value.
-
-      double *array = retval.fortran_vec ();
-
-      idx.loop (n, [=, &array] (idx_vector i)
-      {
-        if (i == 0)
-          *array++ = m_base;
-        else if (i < m_numel - 1)
-          *array++ = m_base + i * m_inc;
-        else
-          *array++ = m_limit;
-      });
-    }
-
-  return retval;
-}
-
 // NOTE: max and min only return useful values if numel > 0.
 //       do_minmax_body() in max.cc avoids calling Range::min/max if numel == 0.
 
@@ -651,214 +537,6 @@
   return retval;
 }
 
-void
-Range::sort_internal (bool ascending)
-{
-  if ((ascending && m_base > m_limit && m_inc < 0.0)
-      || (! ascending && m_base < m_limit && m_inc > 0.0))
-    {
-      std::swap (m_base, m_limit);
-      m_inc = -m_inc;
-    }
-}
-
-void
-Range::sort_internal (Array<octave_idx_type>& sidx, bool ascending)
-{
-  octave_idx_type nel = numel ();
-
-  sidx.resize (dim_vector (1, nel));
-
-  octave_idx_type *psidx = sidx.fortran_vec ();
-
-  bool reverse = false;
-
-  if ((ascending && m_base > m_limit && m_inc < 0.0)
-      || (! ascending && m_base < m_limit && m_inc > 0.0))
-    {
-      std::swap (m_base, m_limit);
-      m_inc = -m_inc;
-      reverse = true;
-    }
-
-  octave_idx_type tmp = (reverse ? nel - 1 : 0);
-  octave_idx_type stp = (reverse ? -1 : 1);
-
-  for (octave_idx_type i = 0; i < nel; i++, tmp += stp)
-    psidx[i] = tmp;
-}
-
-Matrix
-Range::diag (octave_idx_type k) const
-{
-  return matrix_value ().diag (k);
-}
-
-Range
-Range::sort (octave_idx_type dim, sortmode mode) const
-{
-  Range retval = *this;
-
-  if (dim == 1)
-    {
-      if (mode == ASCENDING)
-        retval.sort_internal (true);
-      else if (mode == DESCENDING)
-        retval.sort_internal (false);
-    }
-  else if (dim != 0)
-    (*current_liboctave_error_handler) ("Range::sort: invalid dimension");
-
-  return retval;
-}
-
-Range
-Range::sort (Array<octave_idx_type>& sidx, octave_idx_type dim,
-             sortmode mode) const
-{
-  Range retval = *this;
-
-  if (dim == 1)
-    {
-      if (mode == ASCENDING)
-        retval.sort_internal (sidx, true);
-      else if (mode == DESCENDING)
-        retval.sort_internal (sidx, false);
-    }
-  else if (dim != 0)
-    (*current_liboctave_error_handler) ("Range::sort: invalid dimension");
-
-  return retval;
-}
-
-sortmode
-Range::issorted (sortmode mode) const
-{
-  if (m_numel > 1 && m_inc > 0)
-    mode = (mode == DESCENDING) ? UNSORTED : ASCENDING;
-  else if (m_numel > 1 && m_inc < 0)
-    mode = (mode == ASCENDING) ? UNSORTED : DESCENDING;
-  else
-    mode = (mode == UNSORTED) ? ASCENDING : mode;
-
-  return mode;
-}
-
-void
-Range::set_base (double b)
-{
-  if (m_base != b)
-    {
-      m_base = b;
-
-      init ();
-    }
-}
-
-void
-Range::set_limit (double l)
-{
-  if (m_limit != l)
-    {
-      m_limit = l;
-
-      init ();
-    }
-}
-
-void
-Range::set_inc (double i)
-{
-  if (m_inc != i)
-    {
-      m_inc = i;
-
-      init ();
-    }
-}
-
-std::ostream&
-operator << (std::ostream& os, const Range& a)
-{
-  double b = a.base ();
-  double increment = a.increment ();
-  octave_idx_type nel = a.numel ();
-
-  if (nel > 1)
-    {
-      // First element must be the base *exactly* (e.g., -0).
-      os << b << ' ';
-      for (octave_idx_type i = 1; i < nel-1; i++)
-        os << b + i * increment << ' ';
-    }
-
-  // Print out the last element exactly, rather than a calculated last element.
-  os << a.m_limit << "\n";
-
-  return os;
-}
-
-std::istream&
-operator >> (std::istream& is, Range& a)
-{
-  is >> a.m_base;
-  if (is)
-    {
-      double tmp_limit;
-      is >> tmp_limit;
-
-      if (is)
-        is >> a.m_inc;
-
-      // Clip the m_limit to the true limit, rebuild numel, clear cache
-      a.set_limit (tmp_limit);
-    }
-
-  return is;
-}
-
-// DEPRECATED in Octave 7.
-Range operator - (const Range& r)
-{
-  return Range (-r.base (), -r.limit (), -r.increment (), r.numel ());
-}
-
-// DEPRECATED in Octave 7.
-Range operator + (double x, const Range& r)
-{
-  return Range (x + r.base (), x + r.limit (), r.increment (), r.numel ());
-}
-
-// DEPRECATED in Octave 7.
-Range operator + (const Range& r, double x)
-{
-  return Range (r.base () + x, r.limit () + x, r.increment (), r.numel ());
-}
-
-// DEPRECATED in Octave 7.
-Range operator - (double x, const Range& r)
-{
-  return Range (x - r.base (), x - r.limit (), -r.increment (), r.numel ());
-}
-
-// DEPRECATED in Octave 7.
-Range operator - (const Range& r, double x)
-{
-  return Range (r.base () - x, r.limit () - x, r.increment (), r.numel ());
-}
-
-// DEPRECATED in Octave 7.
-Range operator * (double x, const Range& r)
-{
-  return Range (x * r.base (), x * r.limit (), x * r.increment (), r.numel ());
-}
-
-// DEPRECATED in Octave 7.
-Range operator * (const Range& r, double x)
-{
-  return Range (r.base () * x, r.limit () * x, r.increment () * x, r.numel ());
-}
-
 // C  See Knuth, Art Of Computer Programming, Vol. 1, Problem 1.2.4-5.
 // C
 // C===Tolerant FLOOR function.
--- a/liboctave/array/Range.h	Wed Nov 16 19:24:48 2022 +0100
+++ b/liboctave/array/Range.h	Wed Nov 16 14:05:18 2022 -0500
@@ -461,29 +461,10 @@
 
   double base (void) const { return m_base; }
   double limit (void) const { return m_limit; }
-  double inc (void) const { return m_inc; }
   double increment (void) const { return m_inc; }
 
-  // We adjust the limit to be the final value, so return that.  We
-  // could introduce a new variable to store the final value separately,
-  // but it seems like that would just add confusion.  If we changed
-  // the meaning of the limit function, we would change the behavior of
-  // programs that expect limit to be the final value instead of the
-  // value of the limit when the range was created.  This problem will
-  // be fixed with the new template range class.
-  double final_value (void) const { return m_limit; }
-
   octave_idx_type numel (void) const { return m_numel; }
 
-  dim_vector dims (void) const { return dim_vector (1, m_numel); }
-
-  octave_idx_type rows (void) const { return 1; }
-
-  octave_idx_type cols (void) const { return numel (); }
-  octave_idx_type columns (void) const { return numel (); }
-
-  bool isempty (void) const { return numel () == 0; }
-
   OCTAVE_API bool all_elements_are_ints (void) const;
 
   OCTAVE_API Matrix matrix_value (void) const;
@@ -491,52 +472,6 @@
   OCTAVE_API double min (void) const;
   OCTAVE_API double max (void) const;
 
-  OCTAVE_API void sort_internal (bool ascending = true);
-  OCTAVE_API void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true);
-
-  OCTAVE_API Matrix diag (octave_idx_type k = 0) const;
-
-  OCTAVE_API Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
-  OCTAVE_API Range sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
-              sortmode mode = ASCENDING) const;
-
-  OCTAVE_API sortmode issorted (sortmode mode = ASCENDING) const;
-
-  OCTAVE_API octave_idx_type nnz (void) const;
-
-  // Support for single-index subscripting, without generating matrix cache.
-
-  OCTAVE_API double checkelem (octave_idx_type i) const;
-  OCTAVE_API double checkelem (octave_idx_type i, octave_idx_type j) const;
-
-  OCTAVE_API double elem (octave_idx_type i) const;
-  double elem (octave_idx_type /* i */, octave_idx_type j) const
-  { return elem (j); }
-
-  double operator () (octave_idx_type i) const { return elem (i); }
-  double operator () (octave_idx_type i, octave_idx_type j) const
-  { return elem (i, j); }
-
-  OCTAVE_API Array<double> index (const octave::idx_vector& i) const;
-
-  OCTAVE_API void set_base (double b);
-
-  OCTAVE_API void set_limit (double l);
-
-  OCTAVE_API void set_inc (double i);
-
-  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
-                                               const Range& r);
-  friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r);
-
-  friend OCTAVE_API Range operator - (const Range& r);
-  friend OCTAVE_API Range operator + (double x, const Range& r);
-  friend OCTAVE_API Range operator + (const Range& r, double x);
-  friend OCTAVE_API Range operator - (double x, const Range& r);
-  friend OCTAVE_API Range operator - (const Range& r, double x);
-  friend OCTAVE_API Range operator * (double x, const Range& r);
-  friend OCTAVE_API Range operator * (const Range& r, double x);
-
 private:
 
   double m_base;