26 #if ! defined (octave_Range_h)
27 #define octave_Range_h 1
29 #include "octave-config.h"
32 #include <type_traits>
54 : m_base (0), m_increment (0), m_limit (0), m_final (0), m_numel (0),
63 range (
const T& base,
const T& increment,
const T& limit,
65 : m_base (base), m_increment (increment), m_limit (limit),
66 m_final (), m_numel (), m_reverse (reverse)
71 range (
const T& base,
const T& limit)
72 : m_base (base), m_increment (1), m_limit (limit), m_final (), m_numel (),
85 range (
const T& base,
const T& increment,
const T& limit,
87 : m_base (base), m_increment (increment), m_limit (limit),
88 m_final (limit), m_numel (
numel), m_reverse (reverse)
103 T final_val = (reverse ? base - (
numel - 1) * increment
104 : base + (
numel - 1) * increment);
106 return range<T> (base, increment, final_val,
numel, reverse);
109 OCTAVE_DEFAULT_COPY_MOVE_DELETE (
range)
111 T base ()
const {
return m_base; }
113 T
limit ()
const {
return m_limit; }
121 ? ((m_reverse ? m_increment > T (0)
122 : m_increment > T (0)) ? base () : final_value ())
129 ? ((m_reverse ? m_increment < T (0)
130 : m_increment > T (0)) ? final_value () : base ())
159 if (m_numel > 1 && (m_reverse ? m_increment < T (0)
160 : m_increment > T (0)))
162 else if (m_numel > 1 && (m_reverse ? m_increment > T (0)
163 : m_increment < T (0)))
177 if (i < 0 || i >= m_numel)
182 return (m_numel == 1 ? final_value () : m_base);
183 else if (i < m_numel - 1)
184 return (m_reverse ? m_base + T (i) * m_increment
185 : m_base + T (i) * m_increment);
187 return final_value ();
196 return checkelem (j);
203 return (m_numel == 1 ? final_value () : m_base);
204 else if (i < m_numel - 1)
205 return (m_reverse ? m_base - T (i) * m_increment
206 : m_base + T (i) * m_increment);
208 return final_value ();
248 retval.
clear (idx_dims);
259 *array++ = (m_numel == 0 ? m_final : m_base);
260 else if (i < m_numel - 1)
261 *array++ = (m_reverse ? m_base - T (i) * m_increment
262 : m_base + T (i) * m_increment);
273 return array_value ().
diag (k);
284 retval(0) = final_value ();
293 retval.
xelem (i) = m_base - i * m_increment;
296 retval.
xelem (i) = m_base + i * m_increment;
298 retval.
xelem (nel - 1) = final_value ();
324 m_numel = ((m_increment == T (0)
325 || (m_limit > m_base && m_increment > T (0))
326 || (m_limit < m_base && m_increment < T (0)))
328 : (m_base - m_limit - m_increment) / m_increment);
330 m_final = m_base - (m_numel - 1) * m_increment;
334 m_numel = ((m_increment == T (0)
335 || (m_limit > m_base && m_increment < T (0))
336 || (m_limit < m_base && m_increment > T (0)))
338 : (m_limit - m_base + m_increment) / m_increment);
340 m_final = m_base + (m_numel - 1) * m_increment;
363 OCTAVE_END_NAMESPACE(
octave)
T * fortran_vec()
Size of the specified dimension.
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.
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
range(const T &base, const T &increment, const T &limit, bool reverse=false)
static range< T > make_n_element_range(const T &base, const T &increment, octave_idx_type numel, bool reverse=false)
Array< T > diag(octave_idx_type k) const
octave_idx_type rows() const
bool all_elements_are_ints() const
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)
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)
Array< T > index(const idx_vector &idx) const
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)