26#if defined (HAVE_CONFIG_H)
60 T rmax = q / (2 - ct);
63 t1 = (ct / q) * (t1 < 0 ? -t1 : t1);
64 t1 = (rmax < t1 ? rmax : t1);
65 t1 = (ct > t1 ? ct : t1);
68 if (
x <= 0 || (t1 -
x) < rmax)
75 bool xteq (T u, T v, T ct = 3 * std::numeric_limits<T>::epsilon ())
80 return std::abs (u - v) < ((tu > tv ? tu : tv) * ct);
91 && ((inc > 0 && limit > 0)
92 || (inc < 0 && limit < 0)))
95 || (limit > base && inc < 0)
96 || (limit < base && inc > 0))
102 T ct = 3 * std::numeric_limits<T>::epsilon ();
104 T tmp =
xtfloor ((limit - base + inc) / inc, ct);
120 if (!
xteq (base + (n_elt - 1) * inc, limit))
122 if (
xteq (base + (n_elt - 2) * inc, limit))
124 else if (
xteq (base + n_elt * inc, limit))
135 template <
typename T>
156 template <
typename T>
167 retval = base + (nel - 1) * inc;
179 if ((inc > T (0) && retval >= limit) || (inc < T (0) && retval <= limit))
193 template <
typename T>
195 xinit (T base, T limit, T inc,
bool reverse, T& final_val,
212 || (limit < base && inc > 0)
213 || (limit > base && inc < 0))
222 if ((limit <= base && base + inc < limit)
223 || (limit >= base && base + inc > limit))
233 T dnel = (limit - base) / inc;
260 template <
typename T>
281 final_val = base - (nel - 1) * inc;
286 || (limit > base && inc < octave_int<T> (0))
292 final_val = base + (nel - 1) * inc;
296 template <
typename T>
305 range<double>::all_elements_are_ints (
void)
const
312 range<float>::all_elements_are_ints (
void)
const
319 range<double>::init (
void)
321 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
326 range<float>::init (
void)
328 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
337 range<octave_int8>::init (
void)
339 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
344 range<octave_int16>::init (
void)
346 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
351 range<octave_int32>::init (
void)
353 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
358 range<octave_int64>::init (
void)
360 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
365 range<octave_uint8>::init (
void)
367 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
372 range<octave_uint16>::init (
void)
374 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
379 range<octave_uint32>::init (
void)
381 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
386 range<octave_uint64>::init (
void)
388 xinit (m_base, m_limit, m_increment, m_reverse, m_final, m_numel);
395 range<double>::is_storable (
void)
const
402 range<float>::is_storable (
void)
const
407 template <
typename T>
418 if ((base > 0 && limit > 0) || (base < 0 && limit < 0))
428 if (base == 0 || final_val == 0)
443 range<double>::nnz (
void)
const
445 return xnnz (m_base, m_limit, m_increment, m_final, m_numel);
450 range<float>::nnz (
void)
const
452 return xnnz (m_base, m_limit, m_increment, m_final, m_numel);
480 else if (
m_inc != 0.0)
583 retval.
clear (idx_dims);
658 || (! ascending && m_base < m_limit && m_inc > 0.0))
674 bool reverse =
false;
677 || (! ascending && m_base < m_limit && m_inc > 0.0))
700 Range retval = *
this;
710 (*current_liboctave_error_handler) (
"Range::sort: invalid dimension");
719 Range retval = *
this;
729 (*current_liboctave_error_handler) (
"Range::sort: invalid dimension");
783 double b = a.
base ();
792 os << b + i * increment <<
' ';
910 double rmax = q / (2.0 - ct);
913 t1 = (ct / q) * (t1 < 0.0 ? -t1 : t1);
914 t1 = (rmax < t1 ? rmax : t1);
915 t1 = (ct > t1 ? ct : t1);
918 if (
x <= 0.0 || (t1 -
x) < rmax)
926 double ct = 3.0 * std::numeric_limits<double>::epsilon ())
931 return std::abs (u - v) < ((tu > tv ? tu : tv) * ct);
948 || (m_limit < m_base && m_inc > 0))
954 double ct = 3.0 * std::numeric_limits<double>::epsilon ();
Range operator*(double x, const Range &r)
Range operator-(const Range &r)
Range operator+(double x, const Range &r)
std::ostream & operator<<(std::ostream &os, const Range &a)
static bool teq(double u, double v, double ct=3.0 *std::numeric_limits< double >::epsilon())
std::istream & operator>>(std::istream &is, Range &a)
static double tfloor(double x, double ct)
charNDArray max(char d, const charNDArray &m)
T & xelem(octave_idx_type n)
Size of the specified dimension.
OCTARRAY_API void clear(void)
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
MArray< T > reshape(const dim_vector &new_dims) const
OCTAVE_API Matrix diag(octave_idx_type k=0) const
double increment(void) const
OCTAVE_API void set_inc(double i)
OCTAVE_API octave_idx_type numel_internal(void) const
OCTAVE_API Array< double > index(const octave::idx_vector &i) const
dim_vector dims(void) const
OCTAVE_API sortmode issorted(sortmode mode=ASCENDING) const
OCTAVE_API double elem(octave_idx_type i) const
OCTAVE_API Range sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
OCTAVE_API Matrix diag(octave_idx_type k=0) const
OCTAVE_API octave_idx_type nnz(void) const
OCTAVE_API double limit_internal(void) const
OCTAVE_API void init(void)
OCTAVE_API Matrix matrix_value(void) const
OCTAVE_API void set_base(double b)
OCTAVE_API void sort_internal(bool ascending=true)
OCTAVE_API bool all_elements_are_ints(void) const
octave_idx_type numel(void) const
OCTAVE_API double max(void) const
OCTAVE_API double min(void) const
OCTAVE_API double checkelem(octave_idx_type i) const
OCTAVE_API void set_limit(double l)
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 extent(octave_idx_type n) const
dim_vector orig_dimensions(void) const
octave_idx_type length(octave_idx_type n=0) const
F77_RET_T const F77_DBLE * x
octave_idx_type nint_big(double x)
std::complex< T > floor(const std::complex< T > &x)
static OCTAVE_NORETURN void err_index_out_of_range(void)
octave_idx_type xnnz(T base, T limit, T inc, T final_val, octave_idx_type nel)
octave_idx_type xnumel_internal(T base, T limit, T inc)
T xfinal_value(T base, T limit, T inc, octave_idx_type nel)
bool xis_storable(T base, T limit, octave_idx_type nel)
bool xteq(T u, T v, T ct=3 *std::numeric_limits< T >::epsilon())
void xinit(T base, T limit, T inc, bool reverse, T &final_val, octave_idx_type &nel)
bool xall_elements_are_ints(T base, T inc, T final_val, octave_idx_type nel)