26#if defined (HAVE_CONFIG_H)
58 : m_base (0), m_limit (0), m_inc (0), m_numel (0)
66 Range (
const octave::range<double>& r)
67 : m_base (r.base ()), m_limit (r.final_value ()), m_inc (r.increment ()),
71 Range (
const Range& r) =
default;
73 Range& operator = (
const Range& r) =
default;
77 Range (
double b,
double l)
78 : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ())
80 if (! octave::math::isinf (m_limit))
81 m_limit = limit_internal ();
84 Range (
double b,
double l,
double i)
85 : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ())
87 if (! octave::math::isinf (m_limit))
88 m_limit = limit_internal ();
94 return (octave::math::isfinite (m_limit)
95 && (m_numel >= 0 || m_numel == -2));
98 double base ()
const {
return m_base; }
99 double limit ()
const {
return m_limit; }
100 double increment ()
const {
return m_inc; }
104 bool all_elements_are_ints ()
const;
106 Matrix matrix_value ()
const;
121 double limit_internal ()
const;
127Range::all_elements_are_ints ()
const
133 return (! (octave::math::isnan (m_base) || octave::math::isnan (m_inc))
134 && (octave::math::nint_big (m_base) == m_base || m_numel < 1)
135 && (octave::math::nint_big (m_inc) == m_inc || m_numel <= 1));
139Range::matrix_value ()
const
141 Matrix retval (1, m_numel);
150 double increment = m_inc;
152 retval.xelem (i) = b + i * increment;
154 retval.xelem (m_numel - 1) = m_limit;
173 retval = m_base + (m_numel - 1) * m_inc;
176 if (retval <= m_limit)
192 retval = m_base + (m_numel - 1) * m_inc;
201 if (retval >= m_limit)
243tfloor (
double x,
double ct)
258 double rmax = q / (2.0 - ct);
260 double t1 = 1.0 + std::floor (
x);
261 t1 = (ct / q) * (t1 < 0.0 ? -t1 : t1);
262 t1 = (rmax < t1 ? rmax : t1);
263 t1 = (ct > t1 ? ct : t1);
264 t1 = std::floor (
x + t1);
266 if (
x <= 0.0 || (t1 -
x) < rmax)
273teq (
double u,
double v,
274 double ct = 3.0 * std::numeric_limits<double>::epsilon ())
276 double tu = std::abs (u);
277 double tv = std::abs (v);
279 return std::abs (u - v) < ((tu > tv ? tu : tv) * ct);
283Range::numel_internal ()
const
287 if (! octave::math::isfinite (m_base) || ! octave::math::isfinite (m_inc)
288 || octave::math::isnan (m_limit))
290 else if (octave::math::isinf (m_limit)
291 && ((m_inc > 0 && m_limit > 0)
292 || (m_inc < 0 && m_limit < 0)))
293 retval = std::numeric_limits<octave_idx_type>::max () - 1;
295 || (m_limit > m_base && m_inc < 0)
296 || (m_limit < m_base && m_inc > 0))
302 double ct = 3.0 * std::numeric_limits<double>::epsilon ();
304 double tmp = tfloor ((m_limit - m_base + m_inc) / m_inc, ct);
318 if (! teq (m_base + (n_elt - 1) * m_inc, m_limit))
320 if (teq (m_base + (n_elt - 2) * m_inc, m_limit))
322 else if (teq (m_base + n_elt * m_inc, m_limit))
326 retval = ((n_elt < std::numeric_limits<octave_idx_type>::max ())
334Range::limit_internal ()
const
336 double new_limit = m_inc > 0 ?
max () :
min ();
339 if (all_elements_are_ints ())
340 new_limit = std::round (new_limit);
348 m_numel = numel_internal ();
350 if (! octave::math::isinf (m_limit))
351 m_limit = limit_internal ();
362 if (m_range->numel () < 0 && m_range->numel () != -2)
363 error (
"invalid range");
369 m_range.reset (
new Range (*(r.m_range)));
392 switch (m_range->numel ())
408 if (m_range->increment () == 0)
412 (octave::range<double> (m_range->base (), m_range->increment (),
413 m_range->limit (), m_range->numel ()));
424skip_comments (std::istream& is)
429 if (c ==
' ' || c ==
'\t' || c ==
'\n')
435 octave::skip_until_newline (is,
false);
444 double base, limit, inc;
445 is >> base >> limit >> inc;
448 error (
"load: failed to load range constant");
451 m_range.reset (
new Range (base, limit, inc));
453 m_range.reset (
new Range (base, inc,
static_cast<octave_idx_type> (limit)));
460 octave::mach_info::float_format )
463 if (! is.read (
reinterpret_cast<char *
> (&tmp), 1))
465 double bas, lim, inc;
466 if (! is.read (
reinterpret_cast<char *
> (&bas), 8))
470 if (! is.read (
reinterpret_cast<char *
> (&lim), 8))
474 if (! is.read (
reinterpret_cast<char *
> (&inc), 8))
479 m_range.reset (
new Range (bas, lim, inc));
481 m_range.reset (
new Range (bas, inc,
static_cast<octave_idx_type> (lim)));
486#if defined (HAVE_HDF5)
495hdf5_make_range_type (hid_t num_type)
497 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (
double) * 3);
499 H5Tinsert (type_id,
"base", 0 *
sizeof (
double), num_type);
500 H5Tinsert (type_id,
"limit", 1 *
sizeof (
double), num_type);
501 H5Tinsert (type_id,
"increment", 2 *
sizeof (
double), num_type);
513#if defined (HAVE_HDF5)
515#if defined (HAVE_HDF5_18)
518 hid_t data_hid = H5Dopen (loc_id, name);
520 hid_t type_hid = H5Dget_type (data_hid);
522 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE);
526 H5Tclose (range_type);
531 hid_t space_hid = H5Dget_space (data_hid);
532 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
536 H5Tclose (range_type);
537 H5Sclose (space_hid);
550 "OCTAVE_RANGE_NELEM", &nel))
551 m_range.reset (
new Range (rangevals[0], rangevals[2], nel));
554 if (rangevals[2] != 0)
555 m_range.reset (
new Range (rangevals[0], rangevals[1], rangevals[2]));
557 m_range.reset (
new Range (rangevals[0], rangevals[2],
562 H5Tclose (range_type);
563 H5Sclose (space_hid);
567 octave_unused_parameter (loc_id);
568 octave_unused_parameter (name);
void swap_bytes< 8 >(void *ptr)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
void warn_load(const char *type) const
virtual Matrix matrix_value(bool=false) const
bool load_ascii(std::istream &is)
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_base_value * try_narrowing_conversion()
type_conv_info numeric_conversion_function() const
static int static_type_id()
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
void error(const char *fmt,...)
F77_RET_T const F77_DBLE * x
bool hdf5_get_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
T::size_type numel(const T &str)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
octave_double_range octave_range