26 #if ! defined (octave_Range_h)
27 #define octave_Range_h 1
29 #include "octave-config.h"
32 #include <type_traits>
49 range<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
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);
110 : m_base (
r.m_base), m_increment (
r.m_increment),
111 m_limit (
r.m_limit), m_final (
r.m_final),
112 m_numel (
r.m_numel), m_reverse (
r.m_reverse)
115 range<T>& operator = (
const range<T>&
r)
120 m_increment =
r.m_increment;
124 m_reverse =
r.m_reverse;
132 T
base (
void)
const {
return m_base; }
134 T
limit (
void)
const {
return m_limit; }
135 bool reverse (
void)
const {
return m_reverse; }
142 ? ((m_reverse ? m_increment > T (0)
143 : m_increment > T (0)) ? base () : final_value ())
150 ? ((m_reverse ? m_increment < T (0)
151 : m_increment > T (0)) ? final_value () : base ())
180 if (m_numel > 1 && (m_reverse ? m_increment < T (0)
181 : m_increment > T (0)))
183 else if (m_numel > 1 && (m_reverse ? m_increment > T (0)
184 : m_increment < T (0)))
198 if (i < 0 || i >= m_numel)
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 ();
217 return checkelem (j);
224 return (m_numel == 1 ? final_value () : m_base);
225 else if (i < m_numel - 1)
226 return (m_reverse ? m_base - T (i) * m_increment
227 : m_base + T (i) * m_increment);
229 return final_value ();
269 retval.
clear (idx_dims);
280 *array++ = (m_numel == 0 ? m_final : m_base);
281 else if (i < m_numel - 1)
282 *array++ = (m_reverse ? m_base - T (i) * m_increment
283 : m_base + T (i) * m_increment);
294 return array_value ().
diag (k);
305 retval(0) = final_value ();
314 retval.
xelem (i) = m_base - i * m_increment;
317 retval.
xelem (i) = m_base + i * m_increment;
319 retval.
xelem (nel - 1) = final_value ();
345 m_numel = ((m_increment == T (0)
346 || (m_limit > m_base && m_increment > T (0))
347 || (m_limit < m_base && m_increment < T (0)))
349 : (m_base - m_limit - m_increment) / m_increment);
351 m_final = m_base - (m_numel - 1) * m_increment;
355 m_numel = ((m_increment == T (0)
356 || (m_limit > m_base && m_increment < T (0))
357 || (m_limit < m_base && m_increment > T (0)))
359 : (m_limit - m_base + m_increment) / m_increment);
361 m_final = m_base + (m_numel - 1) * m_increment;
368 template <>
OCTAVE_API bool range<double>::all_elements_are_ints (
void)
const;
369 template <>
OCTAVE_API bool range<float>::all_elements_are_ints (
void)
const;
371 template <>
OCTAVE_API void range<double>::init (
void);
372 template <>
OCTAVE_API void range<float>::init (
void);
380 template <>
OCTAVE_API void range<octave_int8>::init (
void);
381 template <>
OCTAVE_API void range<octave_int16>::init (
void);
382 template <>
OCTAVE_API void range<octave_int32>::init (
void);
383 template <>
OCTAVE_API void range<octave_int64>::init (
void);
384 template <>
OCTAVE_API void range<octave_uint8>::init (
void);
385 template <>
OCTAVE_API void range<octave_uint16>::init (
void);
386 template <>
OCTAVE_API void range<octave_uint32>::init (
void);
387 template <>
OCTAVE_API void range<octave_uint64>::init (
void);
391 template <>
OCTAVE_API bool range<double>::is_storable (
void)
const;
392 template <>
OCTAVE_API bool range<float>::is_storable (
void)
const;
404 OCTAVE_DEPRECATED (7,
"use the 'octave::range<double>' class instead")
406 : m_base (0), m_limit (0), m_inc (0), m_numel (0)
414 OCTAVE_DEPRECATED (7,
"use the 'octave::range<double>' class instead")
416 : m_base (
r.base ()), m_limit (
r.final_value ()), m_inc (
r.increment ()),
426 OCTAVE_DEPRECATED (7,
"use the 'octave::range<double>' class instead")
428 : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ())
431 m_limit = limit_internal ();
434 OCTAVE_DEPRECATED (7,
"use the 'octave::range<double>' class instead")
435 Range (
double b,
double l,
double i)
436 : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ())
439 m_limit = limit_internal ();
448 OCTAVE_DEPRECATED (7,
"use the 'octave::range<double>' class instead")
450 : m_base (b), m_limit (b + (
n-1) * i), m_inc (i), m_numel (
n)
453 m_limit = limit_internal ();
460 && (m_numel >= 0 || m_numel == -2));
463 double base (
void)
const {
return m_base; }
464 double limit (
void)
const {
return m_limit; }
465 double inc (
void)
const {
return m_inc; }
488 OCTAVE_API bool all_elements_are_ints (
void)
const;
495 OCTAVE_API void sort_internal (
bool ascending =
true);
519 {
return elem (i, j); }
551 OCTAVE_API double limit_internal (
void)
const;
562 : m_base (b), m_limit (l), m_inc (i), m_numel (
n)
566 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
567 OCTAVE_DEPRECATED (7,
"arithmetic operations on Range objects are unreliable")
570 OCTAVE_DEPRECATED (7, "arithmetic operations on
Range objects are unreliable")
573 OCTAVE_DEPRECATED (7, "arithmetic operations on
Range objects are unreliable")
576 OCTAVE_DEPRECATED (7, "arithmetic operations on
Range objects are unreliable")
579 OCTAVE_DEPRECATED (7, "arithmetic operations on
Range objects are unreliable")
582 OCTAVE_DEPRECATED (7, "arithmetic operations on
Range objects are unreliable")
585 OCTAVE_DEPRECATED (7, "arithmetic operations on
Range objects are unreliable")
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
ComplexColumnVector operator*(const ComplexMatrix &m, const ColumnVector &a)
ComplexColumnVector operator-(const ComplexColumnVector &x)
ComplexColumnVector operator+(const ComplexColumnVector &x)
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
OCTARRAY_API void clear(void)
OCTARRAY_OVERRIDABLE_FUNC_API Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_API Array< T, Alloc > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
double increment(void) const
octave_idx_type rows(void) const
dim_vector dims(void) const
double final_value(void) const
Range(const Range &r)=default
octave_idx_type cols(void) const
Range(double b, double l, double i, octave_idx_type n)
octave_idx_type columns(void) const
octave_idx_type numel(void) const
double elem(octave_idx_type, octave_idx_type j) const
Vector representing the dimensions (size) of an Array.
bool isvector(void) const
bool is_colon(void) const
void loop(octave_idx_type n, Functor body) const
octave_idx_type length(octave_idx_type n=0) const
dim_vector orig_dimensions(void) const
octave_idx_type extent(octave_idx_type n) const
range(const range< T > &r)
dim_vector dims(void) 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
T final_value(void) const
octave_idx_type rows(void) const
octave_idx_type columns(void) const
OCTAVE_API octave_idx_type nnz(void) const
T elem(octave_idx_type i) 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)
T checkelem(octave_idx_type i, octave_idx_type j) const
bool is_storable(void) const
octave_idx_type numel(void) const
sortmode issorted(sortmode mode=ASCENDING) const
octave_idx_type cols(void) const
Array< T > array_value(void) const
T checkelem(octave_idx_type i) const
range(const T &base, const T &limit)
bool all_elements_are_ints(void) const
Array< T > index(const idx_vector &idx) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
static OCTAVE_NORETURN void err_index_out_of_range(void)
octave::idx_vector idx_vector
F77_RET_T const F77_DBLE * x
T::size_type numel(const T &str)