26 #if defined (HAVE_CONFIG_H)
59 : m_base (0), m_limit (0), m_inc (0), m_numel (0)
67 Range (
const octave::range<double>&
r)
68 : m_base (
r.base ()), m_limit (
r.final_value ()), m_inc (
r.increment ()),
72 Range (
const Range&
r) =
default;
74 Range& operator = (
const Range&
r) =
default;
78 Range (
double b,
double l)
79 : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ())
82 m_limit = limit_internal ();
85 Range (
double b,
double l,
double i)
86 : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ())
89 m_limit = limit_internal ();
96 && (m_numel >= 0 || m_numel == -2));
99 double base ()
const {
return m_base; }
100 double limit ()
const {
return m_limit; }
101 double increment ()
const {
return m_inc; }
105 bool all_elements_are_ints ()
const;
107 Matrix matrix_value ()
const;
122 double limit_internal ()
const;
128 Range::all_elements_are_ints ()
const
140 Range::matrix_value ()
const
142 Matrix retval (1, m_numel);
151 double increment = m_inc;
153 retval.xelem (i) = b + i * increment;
155 retval.xelem (m_numel - 1) = m_limit;
174 retval = m_base + (m_numel - 1) * m_inc;
177 if (retval <= m_limit)
193 retval = m_base + (m_numel - 1) * m_inc;
202 if (retval >= m_limit)
244 tfloor (
double x,
double ct)
259 double rmax = q / (2.0 - ct);
262 t1 = (ct / q) * (t1 < 0.0 ? -t1 : t1);
263 t1 = (rmax < t1 ? rmax : t1);
264 t1 = (ct > t1 ? ct : t1);
267 if (
x <= 0.0 || (t1 -
x) < rmax)
274 teq (
double u,
double v,
275 double ct = 3.0 * std::numeric_limits<double>::epsilon ())
277 double tu = std::abs (u);
278 double tv = std::abs (v);
280 return std::abs (u - v) < ((tu > tv ? tu : tv) * ct);
284 Range::numel_internal ()
const
292 && ((m_inc > 0 && m_limit > 0)
293 || (m_inc < 0 && m_limit < 0)))
296 || (m_limit > m_base && m_inc < 0)
297 || (m_limit < m_base && m_inc > 0))
303 double ct = 3.0 * std::numeric_limits<double>::epsilon ();
305 double tmp = tfloor ((m_limit - m_base + m_inc) / m_inc, ct);
319 if (! teq (m_base + (n_elt - 1) * m_inc, m_limit))
321 if (teq (m_base + (n_elt - 2) * m_inc, m_limit))
323 else if (teq (m_base + n_elt * m_inc, m_limit))
335 Range::limit_internal ()
const
337 double new_limit = m_inc > 0 ?
max () :
min ();
340 if (all_elements_are_ints ())
349 m_numel = numel_internal ();
352 m_limit = limit_internal ();
363 if (m_range->numel () < 0 && m_range->numel () != -2)
364 error (
"invalid range");
370 m_range.reset (
new Range (*(
r.m_range)));
393 switch (m_range->numel ())
409 if (m_range->increment () == 0)
413 (octave::range<double> (m_range->base (), m_range->increment (),
414 m_range->limit (), m_range->numel ()));
425 skip_comments (std::istream& is)
430 if (c ==
' ' || c ==
'\t' || c ==
'\n')
445 double base, limit, inc;
446 is >> base >> limit >> inc;
449 error (
"load: failed to load range constant");
452 m_range.reset (
new Range (base, limit, inc));
454 m_range.reset (
new Range (base, inc,
static_cast<octave_idx_type> (limit)));
464 if (! is.read (
reinterpret_cast<char *
> (&tmp), 1))
466 double bas, lim, inc;
467 if (! is.read (
reinterpret_cast<char *
> (&bas), 8))
471 if (! is.read (
reinterpret_cast<char *
> (&lim), 8))
475 if (! is.read (
reinterpret_cast<char *
> (&inc), 8))
480 m_range.reset (
new Range (bas, lim, inc));
482 m_range.reset (
new Range (bas, inc,
static_cast<octave_idx_type> (lim)));
487 #if defined (HAVE_HDF5)
496 hdf5_make_range_type (hid_t num_type)
498 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (
double) * 3);
500 H5Tinsert (type_id,
"base", 0 *
sizeof (
double), num_type);
501 H5Tinsert (type_id,
"limit", 1 *
sizeof (
double), num_type);
502 H5Tinsert (type_id,
"increment", 2 *
sizeof (
double), num_type);
514 #if defined (HAVE_HDF5)
516 #if defined (HAVE_HDF5_18)
519 hid_t data_hid = H5Dopen (loc_id, name);
521 hid_t type_hid = H5Dget_type (data_hid);
523 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE);
527 H5Tclose (range_type);
532 hid_t space_hid = H5Dget_space (data_hid);
533 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
537 H5Tclose (range_type);
538 H5Sclose (space_hid);
551 "OCTAVE_RANGE_NELEM", &nel))
552 m_range.reset (
new Range (rangevals[0], rangevals[2], nel));
555 if (rangevals[2] != 0)
556 m_range.reset (
new Range (rangevals[0], rangevals[1], rangevals[2]));
558 m_range.reset (
new Range (rangevals[0], rangevals[2],
563 H5Tclose (range_type);
564 H5Sclose (space_hid);
568 octave_unused_parameter (loc_id);
569 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,...)
octave_idx_type nint_big(double x)
std::complex< T > floor(const std::complex< T > &x)
F77_RET_T const F77_DBLE * x
void skip_until_newline(std::istream &is, bool keep_newline)
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