26#if ! defined (octave_Range_h)
27#define octave_Range_h 1
29#include "octave-config.h"
48class range<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
53 : m_base (0), m_increment (0), m_limit (0), m_final (0), m_numel (0),
62 range (
const T& base,
const T& increment,
const T& limit,
64 : m_base (base), m_increment (increment), m_limit (limit),
65 m_final (), m_numel (), m_reverse (reverse)
70 range (
const T& base,
const T& limit)
71 : m_base (base), m_increment (1), m_limit (limit), m_final (), m_numel (),
84 range (
const T& base,
const T& increment,
const T& limit,
86 : m_base (base), m_increment (increment), m_limit (limit),
87 m_final (limit), m_numel (
numel), m_reverse (reverse)
102 T final_val = (reverse ? base - (
numel - 1) * increment
103 : base + (
numel - 1) * increment);
105 return range<T> (base, increment, final_val,
numel, reverse);
108 OCTAVE_DEFAULT_COPY_MOVE_DELETE (
range)
110 T base ()
const {
return m_base; }
112 T
limit ()
const {
return m_limit; }
120 ? ((m_reverse ? m_increment > T (0)
121 : m_increment > T (0)) ? base () : final_value ())
128 ? ((m_reverse ? m_increment < T (0)
129 : m_increment > T (0)) ? final_value () : base ())
158 if (m_numel > 1 && (m_reverse ? m_increment < T (0)
159 : m_increment > T (0)))
161 else if (m_numel > 1 && (m_reverse ? m_increment > T (0)
162 : m_increment < T (0)))
176 if (i < 0 || i >= m_numel)
181 return (m_numel == 1 ? final_value () : m_base);
182 else if (i < m_numel - 1)
183 return (m_reverse ? m_base + T (i) * m_increment
184 : m_base + T (i) * m_increment);
186 return final_value ();
195 return checkelem (j);
202 return (m_numel == 1 ? final_value () : m_base);
203 else if (i < m_numel - 1)
204 return (m_reverse ? m_base - T (i) * m_increment
205 : m_base + T (i) * m_increment);
207 return final_value ();
247 retval.
clear (idx_dims);
252 T *array = retval.
rwdata ();
258 *array++ = (m_numel == 0 ? m_final : m_base);
259 else if (i < m_numel - 1)
260 *array++ = (m_reverse ? m_base - T (i) * m_increment
261 : m_base + T (i) * m_increment);
272 return array_value ().
diag (k);
283 retval(0) = final_value ();
292 retval.
xelem (i) = m_base - i * m_increment;
295 retval.
xelem (i) = m_base + i * m_increment;
297 retval.
xelem (nel - 1) = final_value ();
323 m_numel = ((m_increment == T (0)
324 || (m_limit > m_base && m_increment > T (0))
325 || (m_limit < m_base && m_increment < T (0)))
327 : (m_base - m_limit - m_increment) / m_increment);
329 m_final = m_base - (m_numel - 1) * m_increment;
333 m_numel = ((m_increment == T (0)
334 || (m_limit > m_base && m_increment < T (0))
335 || (m_limit < m_base && m_increment > T (0)))
337 : (m_limit - m_base + m_increment) / m_increment);
339 m_final = m_base + (m_numel - 1) * m_increment;
362OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
T & xelem(octave_idx_type n)
Size of the specified dimension.
Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
T * rwdata()
Size of the specified dimension.
Array< T, Alloc > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Vector representing the dimensions (size) of an Array.
dim_vector orig_dimensions() const
void loop(octave_idx_type n, Functor body) const
octave_idx_type length(octave_idx_type n=0) const
octave_idx_type extent(octave_idx_type n) const
Array< T > diag(octave_idx_type k) const
range(const T &base, const T &increment, const T &limit, bool reverse=false)
octave_idx_type rows() const
bool all_elements_are_ints() const
static range< T > make_n_element_range(const T &base, const T &increment, octave_idx_type numel, bool reverse=false)
T elem(octave_idx_type i) const
octave_idx_type nnz() const
T elem(octave_idx_type, octave_idx_type j) const
range(const T &base, const T &increment, const T &limit, octave_idx_type numel, bool reverse=false)
Array< T > index(const idx_vector &idx) const
octave_idx_type columns() const
T checkelem(octave_idx_type i, octave_idx_type j) const
octave_idx_type numel() const
sortmode issorted(sortmode mode=ASCENDING) const
octave_idx_type cols() const
T checkelem(octave_idx_type i) const
Array< T > array_value() const
range(const T &base, const T &limit)
octave_idx_type nnz() const
bool all_elements_are_ints() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void err_index_out_of_range(int nd, int dim, octave_idx_type idx, octave_idx_type ext, const dim_vector &dv)
T::size_type numel(const T &str)