Mercurial > octave
annotate liboctave/array/Range.h @ 28637:fb37f50d5ba8
new Range::final_value function
* Range.h (Range::final_value): New function.
* pr-output.cc (octave_print_internal (std::ostream&, const Range&,
bool, int)): Use Range::final_value instead of computing it here.
* xpow.cc (elem_expow (double, const Range&)): Likewise.
(elem_expow (const Complex&, const Range&)): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 06 Aug 2020 15:36:30 -0400 |
parents | a3db48e66ef8 |
children | 98192ec1621f |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1993-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20513
diff
changeset
|
26 #if ! defined (octave_Range_h) |
382 | 27 #define octave_Range_h 1 |
28 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21221
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21221
diff
changeset
|
30 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
31 #include <iosfwd> |
7458 | 32 |
4810 | 33 #include "dMatrix.h" |
28004
403df0b32204
update out_of_range error messages
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
34 #include "dim-vector.h" |
28635
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
35 #include "lo-error.h" |
7458 | 36 #include "oct-sort.h" |
3 | 37 |
28635
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
38 template <typename T> class Array; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
39 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
40 namespace octave |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
41 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
42 // Helper class used solely for idx_vector.loop () function call |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
43 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
44 template <typename T> |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
45 class rangeidx_helper |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
46 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
47 public: |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
48 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
49 rangeidx_helper (T *a, T b, T i, T l, octave_idx_type n) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
50 : array (a), base (b), inc (i), limit (l), nmax (n-1) { } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
51 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
52 void operator () (octave_idx_type i) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
53 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
54 if (i == 0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
55 *array++ = base; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
56 else if (i < nmax) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
57 *array++ = base + T (i) * inc; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
58 else |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
59 *array++ = limit; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
60 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
61 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
62 private: |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
63 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
64 T *array, base, inc, limit; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
65 octave_idx_type nmax; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
66 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
67 }; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
68 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
69 template <typename T> |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
70 class range |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
71 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
72 public: |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
73 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
74 range (void) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
75 : m_base (0), m_increment (0), m_limit (0), m_final (0), m_numel (0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
76 { } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
77 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
78 // LIMIT is an upper limit and may be outside the range of actual |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
79 // values. For floating point ranges, we perform a tolerant check |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
80 // to attempt to capture limit in the set of values if it is "close" |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
81 // to the value of base + a multiple of the increment. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
82 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
83 range (const T& base, const T& increment, const T& limit) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
84 : m_base (base), m_increment (increment), m_limit (limit), |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
85 m_final (), m_numel () |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
86 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
87 init (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
88 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
89 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
90 range (const T& base, const T& limit) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
91 : m_base (base), m_increment (1), m_limit (limit), m_final (), m_numel () |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
92 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
93 init (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
94 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
95 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
96 // Allow conversion from (presumably) properly constructed Range |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
97 // objects and to create constant ranges (see the static |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
98 // make_constant method). The values of base, limit, increment, |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
99 // and numel must be consistent. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
100 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
101 // FIXME: Actually check that base, limit, increment, and numel are |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
102 // consistent. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
103 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
104 // FIXME: Is there a way to limit this to T == double? |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
105 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
106 range (const T& base, const T& increment, const T& limit, |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
107 octave_idx_type numel) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
108 : m_base (base), m_increment (increment), m_limit (limit), |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
109 m_final (limit), m_numel (numel) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
110 { } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
111 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
112 // We don't use a constructor for this because it will conflict with |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
113 // range<T> (base, limit) when T is octave_idx_type. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
114 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
115 static range<T> make_constant (const T& base, octave_idx_type numel) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
116 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
117 // We could just make this constructor public, but it allows |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
118 // inconsistent ranges to be constructed. And it is probably much |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
119 // clearer to see "make_constant" instead of puzzling over the |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
120 // purpose of this strange constructor form. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
121 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
122 return range<T> (base, T (), base, numel); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
123 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
124 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
125 // We don't use a constructor for this because it will conflict with |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
126 // range<T> (base, limit, increment) when T is octave_idx_type. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
127 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
128 static range<T> make_n_element_range (const T& base, const T& increment, |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
129 octave_idx_type numel) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
130 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
131 // We could just make this constructor public, but it allows |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
132 // inconsistent ranges to be constructed. And it is probably much |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
133 // clearer to see "make_constant" instead of puzzling over the |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
134 // purpose of this strange constructor form. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
135 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
136 T final_val = base + double (numel - 1) * increment; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
137 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
138 return range<T> (base, increment, final_val, numel); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
139 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
140 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
141 range (const range<T>&) = default; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
142 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
143 range<T>& operator = (const range<T>&) = default; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
144 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
145 ~range (void) = default; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
146 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
147 T base (void) const { return m_base; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
148 T increment (void) const { return m_increment; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
149 T limit (void) const { return m_limit; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
150 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
151 T final_value (void) const { return m_final; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
152 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
153 T min (void) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
154 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
155 return (m_numel > 0 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
156 ? m_increment > T (0) ? base () : final_value () |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
157 : T (0)); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
158 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
159 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
160 T max (void) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
161 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
162 return (m_numel > 0 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
163 ? m_increment > T (0) ? final_value () : base () |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
164 : T (0)); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
165 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
166 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
167 octave_idx_type numel (void) const { return m_numel; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
168 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
169 dim_vector dims (void) const { return dim_vector (1, m_numel); } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
170 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
171 octave_idx_type rows (void) const { return 1; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
172 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
173 octave_idx_type cols (void) const { return numel (); } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
174 octave_idx_type columns (void) const { return numel (); } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
175 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
176 bool isempty (void) const { return numel () == 0; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
177 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
178 bool all_elements_are_ints (void) const { return true; } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
179 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
180 sortmode issorted (sortmode mode = ASCENDING) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
181 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
182 if (m_numel > 1 && m_increment > T (0)) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
183 mode = (mode == DESCENDING) ? UNSORTED : ASCENDING; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
184 else if (m_numel > 1 && m_increment < T (0)) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
185 mode = (mode == ASCENDING) ? UNSORTED : DESCENDING; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
186 else |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
187 mode = (mode == UNSORTED) ? ASCENDING : mode; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
188 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
189 return mode; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
190 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
191 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
192 octave_idx_type nnz (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
193 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
194 // Support for single-index subscripting, without generating matrix cache. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
195 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
196 T checkelem (octave_idx_type i) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
197 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
198 if (i < 0 || i >= m_numel) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
199 octave::err_index_out_of_range (2, 2, i+1, m_numel, dims ()); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
200 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
201 if (i == 0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
202 return m_base; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
203 else if (i < m_numel - 1) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
204 return m_base + T (i) * m_increment; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
205 else |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
206 return final_value (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
207 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
208 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
209 T checkelem (octave_idx_type i, octave_idx_type j) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
210 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
211 // Ranges are *always* row vectors. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
212 if (i != 0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
213 octave::err_index_out_of_range (1, 1, i+1, m_numel, dims ()); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
214 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
215 return checkelem (j); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
216 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
217 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
218 T elem (octave_idx_type i) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
219 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
220 if (i == 0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
221 return m_base; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
222 else if (i < m_numel - 1) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
223 return m_base + T (i) * m_increment; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
224 else |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
225 return final_value (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
226 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
227 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
228 T elem (octave_idx_type /* i */, octave_idx_type j) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
229 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
230 return elem (j); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
231 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
232 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
233 T operator () (octave_idx_type i) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
234 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
235 return elem (i); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
236 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
237 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
238 T operator () (octave_idx_type i, octave_idx_type j) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
239 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
240 return elem (i, j); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
241 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
242 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
243 Array<T> index (const idx_vector& i) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
244 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
245 Array<T> retval; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
246 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
247 octave_idx_type n = m_numel; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
248 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
249 if (i.is_colon ()) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
250 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
251 retval = array_value ().reshape (dim_vector (m_numel, 1)); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
252 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
253 else |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
254 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
255 if (i.extent (n) != n) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
256 octave::err_index_out_of_range (1, 1, i.extent (n), n, dims ()); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
257 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
258 dim_vector rd = i.orig_dimensions (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
259 octave_idx_type il = i.length (n); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
260 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
261 // taken from Array.cc. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
262 if (n != 1 && rd.isvector ()) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
263 rd = dim_vector (1, il); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
264 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
265 retval.clear (rd); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
266 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
267 // idx_vector loop across all values in i, |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
268 // executing __rangeidx_helper (i) for each i |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
269 i.loop (n, rangeidx_helper<T> (retval.fortran_vec (), |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
270 m_base, m_increment, final_value (), |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
271 m_numel)); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
272 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
273 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
274 return retval; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
275 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
276 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
277 Array<T> diag (octave_idx_type k) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
278 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
279 return array_value ().diag (k); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
280 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
281 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
282 Array<T> array_value (void) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
283 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
284 octave_idx_type nel = numel (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
285 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
286 Array<T> retval (dim_vector (1, nel)); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
287 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
288 if (nel > 0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
289 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
290 // The first element must always be *exactly* the base. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
291 // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment). |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
292 retval(0) = m_base; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
293 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
294 for (octave_idx_type i = 1; i < nel - 1; i++) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
295 retval.xelem (i) = m_base + double (i) * m_increment; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
296 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
297 retval.xelem (nel - 1) = final_value (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
298 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
299 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
300 return retval; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
301 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
302 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
303 private: |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
304 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
305 T m_base; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
306 T m_increment; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
307 T m_limit; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
308 T m_final; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
309 octave_idx_type m_numel; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
310 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
311 void init (void) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
312 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
313 m_numel = get_numel (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
314 m_final = get_final_value (); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
315 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
316 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
317 // Setting the number of elements to zero when the increment is zero |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
318 // is intentional and matches the behavior of Matlab's colon |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
319 // operator. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
320 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
321 octave_idx_type get_numel (void) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
322 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
323 return ((m_increment == T (0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
324 || (m_limit > m_base && m_increment < T (0)) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
325 || (m_limit < m_base && m_increment > T (0))) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
326 ? T (0) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
327 : (m_limit - m_base + m_increment) / m_increment); |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
328 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
329 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
330 // This calculation is appropriate for integer ranges. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
331 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
332 T get_final_value (void) const |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
333 { |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
334 return m_base + double (m_numel - 1) * m_increment; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
335 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
336 }; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
337 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
338 // Specializations defined externally. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
339 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
340 template <> bool range<double>::all_elements_are_ints (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
341 template <> bool range<float>::all_elements_are_ints (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
342 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
343 template <> octave_idx_type range<double>::get_numel (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
344 template <> octave_idx_type range<float>::get_numel (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
345 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
346 template <> double range<double>::get_final_value (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
347 template <> float range<float>::get_final_value (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
348 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
349 template <> octave_idx_type range<double>::nnz (void) const; |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
350 } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
351 |
1860 | 352 class |
6108 | 353 OCTAVE_API |
1860 | 354 Range |
3 | 355 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
356 public: |
1860 | 357 |
1528 | 358 Range (void) |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
359 : m_base (0), m_limit (0), m_inc (0), m_numel (0) |
28402
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
360 { } |
1528 | 361 |
28635
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
362 // Assume range is already properly constructed, so just copy internal |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
363 // values. However, we set LIMIT to the computed final value because |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
364 // that mimics the behavior of the other Range class constructors that |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
365 // reset limit to the computed final value. |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
366 |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
367 Range (const octave::range<double>& r) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
368 : m_base (r.base ()), m_limit (r.final_value ()), m_inc (r.increment ()), |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
369 m_numel (r.numel ()) |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
370 { } |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
371 |
27023
fc256e9d882e
use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
372 Range (const Range& r) = default; |
fc256e9d882e
use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
373 |
fc256e9d882e
use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
374 Range& operator = (const Range& r) = default; |
fc256e9d882e
use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
375 |
fc256e9d882e
use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
376 ~Range (void) = default; |
3 | 377 |
1528 | 378 Range (double b, double l) |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
379 : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ()) |
20513 | 380 { |
28592
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
381 if (! octave::math::isinf (m_limit)) |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
382 m_limit = limit_internal (); |
20513 | 383 } |
1528 | 384 |
385 Range (double b, double l, double i) | |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
386 : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ()) |
20513 | 387 { |
28592
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
388 if (! octave::math::isinf (m_limit)) |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
389 m_limit = limit_internal (); |
20513 | 390 } |
1528 | 391 |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
392 // NOTE: The following constructor may be deprecated and removed after |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
393 // the arithmetic operators are removed. |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
394 |
28635
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
395 // For operators' usage (to preserve element count) and to create |
b6371946f106
new template for range objects
John W. Eaton <jwe@octave.org>
parents:
28592
diff
changeset
|
396 // constant row vectors (obsolete usage). |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
397 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
398 Range (double b, double i, octave_idx_type n) |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
399 : m_base (b), m_limit (b + (n-1) * i), m_inc (i), m_numel (n) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
400 { |
28592
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
401 if (! octave::math::isinf (m_limit)) |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
402 m_limit = limit_internal (); |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
403 } |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
404 |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
405 // The range has a finite number of elements. |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
406 bool ok (void) const |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
407 { |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
408 return (octave::math::isfinite (m_limit) |
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
409 && (m_numel >= 0 || m_numel == -2)); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
410 } |
8589
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
411 |
28402
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
412 double base (void) const { return m_base; } |
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
413 double limit (void) const { return m_limit; } |
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
414 double inc (void) const { return m_inc; } |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
28635
diff
changeset
|
415 double increment (void) const { return m_inc; } |
21134
2e5c1f766ac9
provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents:
21040
diff
changeset
|
416 |
28637
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
417 // We adjust the limit to be the final value, so return that. We |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
418 // could introduce a new variable to store the final value separately, |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
419 // but it seems like that would just add confusion. If we changed |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
420 // the meaning of the limit function, we would change the behavior of |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
421 // programs that expect limit to be the final value instead of the |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
422 // value of the limit when the range was created. This problem will |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
423 // be fixed with the new template range class. |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
424 double final_value (void) const { return m_limit; } |
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
425 |
28402
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
426 octave_idx_type numel (void) const { return m_numel; } |
25812
fc74c8d2a584
Clean up liboctave Range implementation.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
427 |
28402
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
428 dim_vector dims (void) const { return dim_vector (1, m_numel); } |
28004
403df0b32204
update out_of_range error messages
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
429 |
24780
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
430 octave_idx_type rows (void) const { return 1; } |
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
431 |
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
432 octave_idx_type cols (void) const { return numel (); } |
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
433 octave_idx_type columns (void) const { return numel (); } |
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
434 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
435 bool isempty (void) const { return numel () == 0; } |
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
436 |
2383 | 437 bool all_elements_are_ints (void) const; |
438 | |
645 | 439 Matrix matrix_value (void) const; |
440 | |
3 | 441 double min (void) const; |
442 double max (void) const; | |
443 | |
7458 | 444 void sort_internal (bool ascending = true); |
445 void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true); | |
446 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
447 Matrix diag (octave_idx_type k = 0) const; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
448 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
449 Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
7458 | 450 Range sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
451 sortmode mode = ASCENDING) const; |
208 | 452 |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
453 sortmode issorted (sortmode mode = ASCENDING) const; |
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
454 |
24859
00ecff875f8a
Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents:
24799
diff
changeset
|
455 octave_idx_type nnz (void) const; |
00ecff875f8a
Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents:
24799
diff
changeset
|
456 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
457 // Support for single-index subscripting, without generating matrix cache. |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
458 |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
459 double checkelem (octave_idx_type i) const; |
24780
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
460 double checkelem (octave_idx_type i, octave_idx_type j) const; |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
461 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
462 double elem (octave_idx_type i) const; |
24799
74a596fd6bab
Fix unused variable warning in Range elem(i,j) function introduced in 0d21e2a1cdfc.
Rik <rik@octave.org>
parents:
24780
diff
changeset
|
463 double elem (octave_idx_type /* i */, octave_idx_type j) const |
74a596fd6bab
Fix unused variable warning in Range elem(i,j) function introduced in 0d21e2a1cdfc.
Rik <rik@octave.org>
parents:
24780
diff
changeset
|
464 { return elem (j); } |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
465 |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
466 double operator () (octave_idx_type i) const { return elem (i); } |
24780
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
467 double operator () (octave_idx_type i, octave_idx_type j) const |
0d21e2a1cdfc
new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
468 { return elem (i, j); } |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
469 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
470 Array<double> index (const idx_vector& i) const; |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
471 |
20513 | 472 void set_base (double b); |
4811 | 473 |
20513 | 474 void set_limit (double l); |
4811 | 475 |
20513 | 476 void set_inc (double i); |
1528 | 477 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
478 friend OCTAVE_API std::ostream& operator << (std::ostream& os, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 const Range& r); |
6108 | 480 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); |
3 | 481 |
8971 | 482 friend OCTAVE_API Range operator - (const Range& r); |
483 friend OCTAVE_API Range operator + (double x, const Range& r); | |
484 friend OCTAVE_API Range operator + (const Range& r, double x); | |
485 friend OCTAVE_API Range operator - (double x, const Range& r); | |
486 friend OCTAVE_API Range operator - (const Range& r, double x); | |
487 friend OCTAVE_API Range operator * (double x, const Range& r); | |
488 friend OCTAVE_API Range operator * (const Range& r, double x); | |
489 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
490 private: |
1860 | 491 |
28402
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
492 double m_base; |
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
493 double m_limit; |
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
494 double m_inc; |
1860 | 495 |
28402
09a3c0e91e6e
style update for Range class
John W. Eaton <jwe@octave.org>
parents:
28004
diff
changeset
|
496 octave_idx_type m_numel; |
3 | 497 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
498 octave_idx_type numel_internal (void) const; |
4811 | 499 |
21321
79a51b7e00b6
eliminate some copy and paste code fragments in the Range class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
500 double limit_internal (void) const; |
79a51b7e00b6
eliminate some copy and paste code fragments in the Range class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
501 |
79a51b7e00b6
eliminate some copy and paste code fragments in the Range class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
502 void init (void); |
79a51b7e00b6
eliminate some copy and paste code fragments in the Range class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
503 |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
504 protected: |
8971 | 505 |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
506 // NOTE: The following constructor may be removed when the arithmetic |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
507 // operators are removed. |
18852
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
508 |
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
509 // For operators' usage (to allow all values to be set directly). |
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
510 Range (double b, double l, double i, octave_idx_type n) |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
511 : m_base (b), m_limit (l), m_inc (i), m_numel (n) |
28592
e70c859c4bff
allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents:
28524
diff
changeset
|
512 { } |
3 | 513 }; |
514 | |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
515 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") |
6108 | 516 extern OCTAVE_API Range operator - (const Range& r); |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
517 |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
518 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
519 extern OCTAVE_API Range operator + (double x, const Range& r); |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
520 |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
521 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
522 extern OCTAVE_API Range operator + (const Range& r, double x); |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
523 |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
524 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
525 extern OCTAVE_API Range operator - (double x, const Range& r); |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
526 |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
527 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
528 extern OCTAVE_API Range operator - (const Range& r, double x); |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
529 |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
530 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
531 extern OCTAVE_API Range operator * (double x, const Range& r); |
28524
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
532 |
455fe4a6f22c
deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents:
28402
diff
changeset
|
533 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable") |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
534 extern OCTAVE_API Range operator * (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
535 |
3 | 536 #endif |