Mercurial > octave
comparison liboctave/array/Range.h @ 30853:fc3bd70cd1be stable
eliminate range<T>::make_constant function
Overloading ranges as a way to create constant arrays adds complexity
to the range class for limited benefit. It is currently only used for
double-valued ranges and only provides constant row vectors. If this
optimization is determined to be useful, it would probably be best to
provide a data type that allows N-d constant arrays. The legacy range
class was revived in a previous changeset so that constant ranges
(increment == 0) can be loaded from existing data files and converted
to ordinary arrays automatically.
* Range.h (range<T>::make_constant): Delete. Remove all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 22 Mar 2022 00:01:53 -0400 |
parents | 95725e6ad9c1 |
children | db8735ee84da e88a07dec498 |
comparison
equal
deleted
inserted
replaced
30852:95725e6ad9c1 | 30853:fc3bd70cd1be |
---|---|
74 { | 74 { |
75 init (); | 75 init (); |
76 } | 76 } |
77 | 77 |
78 // Allow conversion from (presumably) properly constructed Range | 78 // Allow conversion from (presumably) properly constructed Range |
79 // objects and to create constant ranges (see the static | 79 // objects. The values of base, limit, increment, and numel must be |
80 // make_constant method). The values of base, limit, increment, | 80 // consistent. |
81 // and numel must be consistent. | |
82 | 81 |
83 // FIXME: Actually check that base, limit, increment, and numel are | 82 // FIXME: Actually check that base, limit, increment, and numel are |
84 // consistent. | 83 // consistent? |
85 | |
86 // FIXME: Is there a way to limit this to T == double? | |
87 | 84 |
88 range (const T& base, const T& increment, const T& limit, | 85 range (const T& base, const T& increment, const T& limit, |
89 octave_idx_type numel, bool reverse = false) | 86 octave_idx_type numel, bool reverse = false) |
90 : m_base (base), m_increment (increment), m_limit (limit), | 87 : m_base (base), m_increment (increment), m_limit (limit), |
91 m_final (limit), m_numel (numel), m_reverse (reverse) | 88 m_final (limit), m_numel (numel), m_reverse (reverse) |
92 { } | 89 { } |
93 | 90 |
94 range (const T& base, const T& increment, const T& limit, | |
95 const T& final, octave_idx_type numel, bool reverse = false) | |
96 : m_base (base), m_increment (increment), m_limit (limit), | |
97 m_final (final), m_numel (numel), m_reverse (reverse) | |
98 { } | |
99 | |
100 // We don't use a constructor for this because it will conflict with | |
101 // range<T> (base, limit) when T is octave_idx_type. | |
102 | |
103 static range<T> make_constant (const T& base, octave_idx_type numel, | |
104 bool reverse = false) | |
105 { | |
106 // We could just make this constructor public, but it allows | |
107 // inconsistent ranges to be constructed. And it is probably much | |
108 // clearer to see "make_constant" instead of puzzling over the | |
109 // purpose of this strange constructor form. | |
110 | |
111 return range<T> (base, T (), base, numel, reverse); | |
112 } | |
113 | |
114 // We don't use a constructor for this because it will conflict with | 91 // We don't use a constructor for this because it will conflict with |
115 // range<T> (base, limit, increment) when T is octave_idx_type. | 92 // range<T> (base, limit, increment) when T is octave_idx_type. |
116 | 93 |
117 static range<T> make_n_element_range (const T& base, const T& increment, | 94 static range<T> make_n_element_range (const T& base, const T& increment, |
118 octave_idx_type numel, | 95 octave_idx_type numel, |
119 bool reverse = false) | 96 bool reverse = false) |
120 { | 97 { |
121 // We could just make this constructor public, but it allows | 98 // We could just make this constructor public, but it allows |
122 // inconsistent ranges to be constructed. And it is probably much | 99 // inconsistent ranges to be constructed. And it is probably much |
123 // clearer to see "make_constant" instead of puzzling over the | 100 // clearer to see "make_n_element_range" instead of puzzling over the |
124 // purpose of this strange constructor form. | 101 // purpose of this strange constructor form. |
125 | 102 |
126 T final_val = (reverse ? base - (numel - 1) * increment | 103 T final_val = (reverse ? base - (numel - 1) * increment |
127 : base + (numel - 1) * increment); | 104 : base + (numel - 1) * increment); |
128 | 105 |