annotate libinterp/octave-value/ov-legacy-range.cc @ 31608:23664317f0d3

maint: merge stable to default
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 20:05:44 -0800
parents fb77a0b4a00a aac27ad79be6
children 5f11de0e7440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ////////////////////////////////////////////////////////////////////////
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 // distribution or <https://octave.org/copyright/>.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 // This file is part of Octave.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 // under the terms of the GNU General Public License as published by
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 // (at your option) any later version.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 // GNU General Public License for more details.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 // along with Octave; see the file COPYING. If not, see
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 // <https://www.gnu.org/licenses/>.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ////////////////////////////////////////////////////////////////////////
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <istream>
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <ostream>
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <sstream>
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
34 #include "Range.h"
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "lo-ieee.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "lo-utils.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "variables.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "error.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "ovl.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "oct-hdf5.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "ov-legacy-range.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "ov-range.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "ov-re-mat.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "ov-scalar.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "pr-output.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "byte-swap.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "ls-ascii-helper.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "ls-hdf5.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "ls-utils.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
31469
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
53 class
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
54 Range
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
55 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
56 public:
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
57
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
58 Range (void)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
59 : m_base (0), m_limit (0), m_inc (0), m_numel (0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
60 { }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
61
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
62 // Assume range is already properly constructed, so just copy internal
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
63 // values. However, we set LIMIT to the computed final value because
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
64 // that mimics the behavior of the other Range class constructors that
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
65 // reset limit to the computed final value.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
66
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
67 Range (const octave::range<double>& r)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
68 : m_base (r.base ()), m_limit (r.final_value ()), m_inc (r.increment ()),
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
69 m_numel (r.numel ())
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
70 { }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
71
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
72 Range (const Range& r) = default;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
73
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
74 Range& operator = (const Range& r) = default;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
75
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
76 ~Range (void) = default;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
77
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
78 Range (double b, double l)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
79 : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ())
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
80 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
81 if (! octave::math::isinf (m_limit))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
82 m_limit = limit_internal ();
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
83 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
84
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
85 Range (double b, double l, double i)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
86 : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ())
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
87 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
88 if (! octave::math::isinf (m_limit))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
89 m_limit = limit_internal ();
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
90 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
91
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
92 // The range has a finite number of elements.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
93 bool ok (void) const
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
94 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
95 return (octave::math::isfinite (m_limit)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
96 && (m_numel >= 0 || m_numel == -2));
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
97 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
98
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
99 double base (void) const { return m_base; }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
100 double limit (void) const { return m_limit; }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
101 double increment (void) const { return m_inc; }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
102
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
103 octave_idx_type numel (void) const { return m_numel; }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
104
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
105 bool all_elements_are_ints (void) const;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
106
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
107 Matrix matrix_value (void) const;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
108
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
109 double min (void) const;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
110 double max (void) const;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
111
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
112 private:
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
113
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
114 double m_base;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
115 double m_limit;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
116 double m_inc;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
117
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
118 octave_idx_type m_numel;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
119
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
120 octave_idx_type numel_internal (void) const;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
121
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
122 double limit_internal (void) const;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
123
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
124 void init (void);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
125 };
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
126
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
127 bool
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
128 Range::all_elements_are_ints (void) const
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
129 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
130 // If the base and increment are ints, the final value in the range will also
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
131 // be an integer, even if the limit is not. If there is one or fewer
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
132 // elements only the base needs to be an integer.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
133
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
134 return (! (octave::math::isnan (m_base) || octave::math::isnan (m_inc))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
135 && (octave::math::nint_big (m_base) == m_base || m_numel < 1)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
136 && (octave::math::nint_big (m_inc) == m_inc || m_numel <= 1));
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
137 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
138
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
139 Matrix
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
140 Range::matrix_value (void) const
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
141 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
142 Matrix retval (1, m_numel);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
143
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
144 if (m_numel > 0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
145 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
146 // The first element must always be *exactly* the base.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
147 // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment).
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
148 retval(0) = m_base;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
149
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
150 double b = m_base;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
151 double increment = m_inc;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
152 for (octave_idx_type i = 1; i < m_numel - 1; i++)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
153 retval.xelem (i) = b + i * increment;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
154
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
155 retval.xelem (m_numel - 1) = m_limit;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
156 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
157
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
158 return retval;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
159 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
160
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
161 // NOTE: max and min only return useful values if numel > 0.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
162 // do_minmax_body() in max.cc avoids calling Range::min/max if numel == 0.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
163
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
164 double
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
165 Range::min (void) const
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
166 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
167 double retval = 0.0;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
168 if (m_numel > 0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
169 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
170 if (m_inc > 0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
171 retval = m_base;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
172 else
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
173 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
174 retval = m_base + (m_numel - 1) * m_inc;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
175
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
176 // Require '<=' test. See note in max ().
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
177 if (retval <= m_limit)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
178 retval = m_limit;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
179 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
180
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
181 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
182 return retval;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
183 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
184
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
185 double
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
186 Range::max (void) const
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
187 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
188 double retval = 0.0;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
189 if (m_numel > 0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
190 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
191 if (m_inc > 0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
192 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
193 retval = m_base + (m_numel - 1) * m_inc;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
194
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
195 // On some machines (x86 with extended precision floating point
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
196 // arithmetic, for example) it is possible that we can overshoot the
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
197 // limit by approximately the machine precision even though we were
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
198 // very careful in our calculation of the number of elements.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
199 // Therefore, we clip the result to the limit if it overshoots.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
200 // The test also includes equality (>= m_limit) to have expressions
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
201 // such as -5:1:-0 result in a -0 endpoint.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
202 if (retval >= m_limit)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
203 retval = m_limit;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
204 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
205 else
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
206 retval = m_base;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
207 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
208 return retval;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
209 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
210
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
211 // C See Knuth, Art Of Computer Programming, Vol. 1, Problem 1.2.4-5.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
212 // C
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
213 // C===Tolerant FLOOR function.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
214 // C
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
215 // C X - is given as a Double Precision argument to be operated on.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
216 // C It is assumed that X is represented with M mantissa bits.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
217 // C CT - is given as a Comparison Tolerance such that
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
218 // C 0.LT.CT.LE.3-SQRT(5)/2. If the relative difference between
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
219 // C X and A whole number is less than CT, then TFLOOR is
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
220 // C returned as this whole number. By treating the
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
221 // C floating-point numbers as a finite ordered set note that
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
222 // C the heuristic EPS=2.**(-(M-1)) and CT=3*EPS causes
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
223 // C arguments of TFLOOR/TCEIL to be treated as whole numbers
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
224 // C if they are exactly whole numbers or are immediately
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
225 // C adjacent to whole number representations. Since EPS, the
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
226 // C "distance" between floating-point numbers on the unit
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
227 // C interval, and M, the number of bits in X'S mantissa, exist
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
228 // C on every floating-point computer, TFLOOR/TCEIL are
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
229 // C consistently definable on every floating-point computer.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
230 // C
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
231 // C For more information see the following references:
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
232 // C (1) P. E. Hagerty, "More On Fuzzy Floor And Ceiling," APL QUOTE
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
233 // C QUAD 8(4):20-24, June 1978. Note that TFLOOR=FL5.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
234 // C (2) L. M. Breed, "Definitions For Fuzzy Floor And Ceiling", APL
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
235 // C QUOTE QUAD 8(3):16-23, March 1978. This paper cites FL1 through
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
236 // C FL5, the history of five years of evolutionary development of
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
237 // C FL5 - the seven lines of code below - by open collaboration
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
238 // C and corroboration of the mathematical-computing community.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
239 // C
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
240 // C Penn State University Center for Academic Computing
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
241 // C H. D. Knoble - August, 1978.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
242
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
243 static inline double
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
244 tfloor (double x, double ct)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
245 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
246 // C---------FLOOR(X) is the largest integer algebraically less than
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
247 // C or equal to X; that is, the unfuzzy FLOOR function.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
248
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
249 // DINT (X) = X - DMOD (X, 1.0);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
250 // FLOOR (X) = DINT (X) - DMOD (2.0 + DSIGN (1.0, X), 3.0);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
251
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
252 // C---------Hagerty's FL5 function follows...
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
253
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
254 double q = 1.0;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
255
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
256 if (x < 0.0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
257 q = 1.0 - ct;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
258
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
259 double rmax = q / (2.0 - ct);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
260
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
261 double t1 = 1.0 + std::floor (x);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
262 t1 = (ct / q) * (t1 < 0.0 ? -t1 : t1);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
263 t1 = (rmax < t1 ? rmax : t1);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
264 t1 = (ct > t1 ? ct : t1);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
265 t1 = std::floor (x + t1);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
266
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
267 if (x <= 0.0 || (t1 - x) < rmax)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
268 return t1;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
269 else
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
270 return t1 - 1.0;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
271 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
272
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
273 static inline bool
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
274 teq (double u, double v,
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
275 double ct = 3.0 * std::numeric_limits<double>::epsilon ())
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
276 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
277 double tu = std::abs (u);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
278 double tv = std::abs (v);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
279
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
280 return std::abs (u - v) < ((tu > tv ? tu : tv) * ct);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
281 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
282
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
283 octave_idx_type
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
284 Range::numel_internal (void) const
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
285 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
286 octave_idx_type retval = -1;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
287
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
288 if (! octave::math::isfinite (m_base) || ! octave::math::isfinite (m_inc)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
289 || octave::math::isnan (m_limit))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
290 retval = -2;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
291 else if (octave::math::isinf (m_limit)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
292 && ((m_inc > 0 && m_limit > 0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
293 || (m_inc < 0 && m_limit < 0)))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
294 retval = std::numeric_limits<octave_idx_type>::max () - 1;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
295 else if (m_inc == 0
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
296 || (m_limit > m_base && m_inc < 0)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
297 || (m_limit < m_base && m_inc > 0))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
298 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
299 retval = 0;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
300 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
301 else
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
302 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
303 double ct = 3.0 * std::numeric_limits<double>::epsilon ();
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
304
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
305 double tmp = tfloor ((m_limit - m_base + m_inc) / m_inc, ct);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
306
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
307 octave_idx_type n_elt = (tmp > 0.0
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
308 ? static_cast<octave_idx_type> (tmp) : 0);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
309
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
310 // If the final element that we would compute for the range is equal to
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
311 // the limit of the range, or is an adjacent floating point number,
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
312 // accept it. Otherwise, try a range with one fewer element. If that
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
313 // fails, try again with one more element.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
314 //
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
315 // I'm not sure this is very good, but it seems to work better than just
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
316 // using tfloor as above. For example, without it, the expression
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
317 // 1.8:0.05:1.9 fails to produce the expected result of [1.8, 1.85, 1.9].
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
318
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
319 if (! teq (m_base + (n_elt - 1) * m_inc, m_limit))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
320 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
321 if (teq (m_base + (n_elt - 2) * m_inc, m_limit))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
322 n_elt--;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
323 else if (teq (m_base + n_elt * m_inc, m_limit))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
324 n_elt++;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
325 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
326
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
327 retval = ((n_elt < std::numeric_limits<octave_idx_type>::max ())
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
328 ? n_elt : -1);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
329 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
330
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
331 return retval;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
332 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
333
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
334 double
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
335 Range::limit_internal (void) const
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
336 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
337 double new_limit = m_inc > 0 ? max () : min ();
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
338
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
339 // If result must be an integer then force the new_limit to be one.
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
340 if (all_elements_are_ints ())
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
341 new_limit = std::round (new_limit);
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
342
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
343 return new_limit;
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
344 }
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
345
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
346 void
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
347 Range::init (void)
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
348 {
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
349 m_numel = numel_internal ();
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
350
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
351 if (! octave::math::isinf (m_limit))
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
352 m_limit = limit_internal ();
fb77a0b4a00a move declaration and definition of legacy Range class to ov-legacy-range.cc
John W. Eaton <jwe@octave.org>
parents: 31468
diff changeset
353 }
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_legacy_range, "range", "double");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 octave_legacy_range::octave_legacy_range (void)
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
358 : octave_base_value (), m_range (new Range ()) { }
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
359
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 octave_legacy_range::octave_legacy_range (const Range& r)
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
361 : octave_base_value (), m_range (new Range (r))
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362 {
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
363 if (m_range->numel () < 0 && m_range->numel () != -2)
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 error ("invalid range");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
367 octave_legacy_range::octave_legacy_range (const octave_legacy_range& r)
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
368 : octave_base_value (r), m_range ()
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
369 {
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
370 m_range.reset (new Range (*(r.m_range)));
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
371 }
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
372
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373 static octave_base_value *
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374 default_numeric_conversion_function (const octave_base_value& a)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
375 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
376 const octave_legacy_range& v = dynamic_cast<const octave_legacy_range&> (a);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
378 return new octave_matrix (v.matrix_value ());
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
380
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381 octave_base_value::type_conv_info
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382 octave_legacy_range::numeric_conversion_function (void) const
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384 return octave_base_value::type_conv_info (default_numeric_conversion_function,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 octave_matrix::static_type_id ());
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
386 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
387
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 octave_base_value *
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
389 octave_legacy_range::try_narrowing_conversion (void)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
390 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391 octave_base_value *retval = nullptr;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
392
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
393 switch (m_range->numel ())
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
394 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395 case 1:
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
396 retval = new octave_scalar (m_range->base ());
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399 case 0:
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
400 retval = new octave_matrix (Matrix (1, 0));
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 case -2:
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
404 retval = new octave_matrix (m_range->matrix_value ());
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407 default:
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 {
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
409 if (m_range->increment () == 0)
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
410 retval = new octave_matrix (m_range->matrix_value ());
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412 retval = new octave_range
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
413 (octave::range<double> (m_range->base (), m_range->increment (),
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
414 m_range->limit (), m_range->numel ()));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419 return retval;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422 // Skip white space and comments on stream IS.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424 static void
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
425 skip_comments (std::istream& is)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
426 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 char c = '\0';
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428 while (is.get (c))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
429 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 if (c == ' ' || c == '\t' || c == '\n')
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 ; // Skip whitespace on way to beginning of next line.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436 octave::skip_until_newline (is, false);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
439 bool
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440 octave_legacy_range::load_ascii (std::istream& is)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442 // # base, limit, range comment added by save ().
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
443 skip_comments (is);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
444
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445 double base, limit, inc;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
446 is >> base >> limit >> inc;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
447
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
448 if (! is)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
449 error ("load: failed to load range constant");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
450
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451 if (inc != 0)
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
452 m_range.reset (new Range (base, limit, inc));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
453 else
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
454 m_range.reset (new Range (base, inc, static_cast<octave_idx_type> (limit)));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
455
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
456 return true;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
457 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
458
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459 bool
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
460 octave_legacy_range::load_binary (std::istream& is, bool swap,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
461 octave::mach_info::float_format /* fmt */)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
462 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
463 char tmp;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
464 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
465 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
466 double bas, lim, inc;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
467 if (! is.read (reinterpret_cast<char *> (&bas), 8))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
468 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469 if (swap)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
470 swap_bytes<8> (&bas);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
471 if (! is.read (reinterpret_cast<char *> (&lim), 8))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
472 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
473 if (swap)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
474 swap_bytes<8> (&lim);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
475 if (! is.read (reinterpret_cast<char *> (&inc), 8))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
476 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
477 if (swap)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
478 swap_bytes<8> (&inc);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
479 if (inc != 0)
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
480 m_range.reset (new Range (bas, lim, inc));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
481 else
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
482 m_range.reset (new Range (bas, inc, static_cast<octave_idx_type> (lim)));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
483
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
484 return true;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
485 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
486
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
487 #if defined (HAVE_HDF5)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
489 // The following subroutines creates an HDF5 representation of the way
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
490 // we will store Octave range types (triplets of floating-point numbers).
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
491 // NUM_TYPE is the HDF5 numeric type to use for storage (e.g.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
492 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493 // conversions are handled automatically by HDF5.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
494
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
495 static hid_t
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
496 hdf5_make_range_type (hid_t num_type)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
497 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
498 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 3);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
499
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
500 H5Tinsert (type_id, "base", 0 * sizeof (double), num_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
501 H5Tinsert (type_id, "limit", 1 * sizeof (double), num_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
502 H5Tinsert (type_id, "increment", 2 * sizeof (double), num_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
503
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504 return type_id;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
505 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
506
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
507 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
508
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
509 bool
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
510 octave_legacy_range::load_hdf5 (octave_hdf5_id loc_id, const char *name)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
511 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
512 bool retval = false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
513
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
514 #if defined (HAVE_HDF5)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
515
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
516 #if defined (HAVE_HDF5_18)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
517 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
518 #else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
519 hid_t data_hid = H5Dopen (loc_id, name);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
520 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
521 hid_t type_hid = H5Dget_type (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
522
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
523 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
524
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525 if (! hdf5_types_compatible (type_hid, range_type))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
526 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
527 H5Tclose (range_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
528 H5Dclose (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
529 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
530 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
531
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
532 hid_t space_hid = H5Dget_space (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
533 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
535 if (rank != 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
537 H5Tclose (range_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
538 H5Sclose (space_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539 H5Dclose (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
540 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
541 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
543 double rangevals[3];
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
544 if (H5Dread (data_hid, range_type, octave_H5S_ALL, octave_H5S_ALL,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
545 octave_H5P_DEFAULT, rangevals)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
546 >= 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
547 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
548 retval = true;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
549 octave_idx_type nel;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
550 if (hdf5_get_scalar_attr (data_hid, H5T_NATIVE_IDX,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551 "OCTAVE_RANGE_NELEM", &nel))
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
552 m_range.reset (new Range (rangevals[0], rangevals[2], nel));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
553 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
554 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
555 if (rangevals[2] != 0)
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
556 m_range.reset (new Range (rangevals[0], rangevals[1], rangevals[2]));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
557 else
31468
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
558 m_range.reset (new Range (rangevals[0], rangevals[2],
777a42ebe45b use opaque pointer for octave_legacy_range data member
John W. Eaton <jwe@octave.org>
parents: 31467
diff changeset
559 static_cast<octave_idx_type> (rangevals[1])));
30852
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
560 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
561 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
562
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
563 H5Tclose (range_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
564 H5Sclose (space_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
565 H5Dclose (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
566
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
567 #else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
568 octave_unused_parameter (loc_id);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
569 octave_unused_parameter (name);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
570
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
571 warn_load ("hdf5");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
572 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
573
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
574 return retval;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
575 }