26 #if defined (HAVE_CONFIG_H)
68 #if defined (HAVE_HDF5)
85 "double_range",
"double");
100 template <
typename T>
107 (default_numeric_conversion_function<T>, ov_mx_type::static_type_id ());
110 template <
typename T>
125 typename ov_mx_type::object_type
m (
dim_vector (1, 0));
126 retval =
new ov_mx_type (
m);
144 template <
typename T>
147 const std::list<octave_value_list>& idx)
154 retval = do_index_op (idx.front ());
160 std::string nm = type_name ();
161 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
172 template <
typename T>
177 if (idx.
length () == 1 && ! resize_ok)
187 if (i.is_scalar () && i(0) <
numel ())
188 retval = m_range.elem (i(0));
190 retval = m_range.index (i);
192 catch (octave::index_exception& ie)
196 ie.set_pos_if_unset (1, 1);
206 return tmp.
index_op (idx, resize_ok);
210 template <
typename T>
218 template <
typename T>
228 "range",
"real scalar");
230 return m_range.base ();
233 template <
typename T>
243 "range",
"real scalar");
245 return m_range.base ();
248 template <
typename T>
252 const Array<T> matrix = raw_array_value ();
258 retval.
elem (i) =
static_cast<char> (matrix.
elem (i));
263 template <
typename T>
273 "range",
"complex scalar");
275 return Complex (m_range.base (), 0);
278 template <
typename T>
292 "range",
"complex scalar");
294 retval = m_range.base ();
299 template <
typename T>
303 Array<T> matrix = raw_array_value ();
305 if (warn && ! matrix.
test_all (octave::is_one_or_zero<T>))
311 template <
typename T>
315 Array<T> retval = raw_array_value ();
323 template <
typename T>
324 octave::range<double>
332 template <
typename T>
342 template <
typename T>
346 return NDArray (raw_array_value ());
349 template <
typename T>
356 template <
typename T>
363 template <
typename T>
370 template <
typename T>
377 template <
typename T>
384 template <
typename T>
391 template <
typename T>
398 template <
typename T>
405 template <
typename T>
412 template <
typename T>
416 print_raw (os, pr_as_read_syntax);
420 template <
typename T>
427 typename ov_mx_type::object_type tmp (raw_array_value ());
430 current_print_indent_level ());
433 template <
typename T>
443 if (
n == 0 ||
n == 1)
458 template <
typename T>
468 os << m_range.base () <<
':';
472 if (m_range.increment () != T (1))
473 os << m_range.increment () <<
':';
475 os << m_range.limit ();
483 skip_comments (std::istream& is)
488 if (c ==
' ' || c ==
'\t' || c ==
'\n')
497 template <
typename T>
504 template <
typename T>
509 std::ostringstream buf;
514 template <
typename T>
517 const bool with_reverse)
520 T limit =
r.limit ();
521 T inc =
r.increment ();
522 bool rev =
r.reverse ();
526 os <<
"# base, limit, increment";
528 os <<
"# base, length, increment";
535 octave::write_value<T> (os, base);
538 octave::write_value<T> (os, limit);
542 octave::write_value<T> (os, inc);
550 template <
typename T>
561 template <
typename T>
563 xload_ascii (std::istream& is, octave::range<T>&
r,
const bool with_reverse)
570 is >> base >> limit >> inc;
576 error (
"load: failed to load range constant");
578 r = octave::range<T> (base, inc, limit, rev);
583 template <
typename T>
620 template <
typename T>
623 const octave::range<T>&
r,
const bool with_reverse)
628 os.write (
reinterpret_cast<char *
> (&tmp), 1);
631 T inc =
r.increment ();
635 os.write (
reinterpret_cast<char *
> (&bas),
sizeof (T));
636 os.write (
reinterpret_cast<char *
> (&lim),
sizeof (T));
637 os.write (
reinterpret_cast<char *
> (&inc),
sizeof (T));
640 bool rev =
r.reverse ();
641 os.write (
reinterpret_cast<char *
> (&rev),
sizeof (
bool));
647 template <
typename T>
651 return xsave_binary (os, save_as_floats, m_range,
false);
656 template <
typename T>
660 octave::range<T>&
r,
const bool with_reverse)
665 if (! is.read (
reinterpret_cast<char *
> (&tmp), 1))
668 if (! is.read (
reinterpret_cast<char *
> (&bas), sizeof (T)))
671 swap_bytes<sizeof (T)> (&bas);
672 if (! is.read (
reinterpret_cast<char *
> (&lim), sizeof (T)))
675 swap_bytes<sizeof (T)> (&lim);
676 if (! is.read (
reinterpret_cast<char *
> (&inc), sizeof (T)))
679 swap_bytes<sizeof (T)> (&inc);
683 if (! is.read (
reinterpret_cast<char *
> (&rev), sizeof (
bool)))
686 swap_bytes<sizeof (bool)> (&rev);
689 r = octave::range<T> (bas, inc, lim, rev);
694 template <
typename T>
730 #if defined (HAVE_HDF5)
738 template <
typename T>
740 hdf5_make_range_type (hid_t num_type)
742 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (T) * 3);
744 H5Tinsert (type_id,
"base", 0 *
sizeof (T), num_type);
745 H5Tinsert (type_id,
"limit", 1 *
sizeof (T), num_type);
746 H5Tinsert (type_id,
"increment", 2 *
sizeof (T), num_type);
751 template <
typename T>
753 hdf5_make_range_rev_type (hid_t num_type)
755 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (T) * 4);
757 H5Tinsert (type_id,
"base", 0 *
sizeof (T), num_type);
758 H5Tinsert (type_id,
"limit", 1 *
sizeof (T), num_type);
759 H5Tinsert (type_id,
"increment", 2 *
sizeof (T), num_type);
761 H5Tinsert (type_id,
"reverse", 3 *
sizeof (T), num_type);
766 template <
typename T>
769 bool ,
const octave::range<T>&
r,
774 hsize_t dimens[3] = {0};
775 hid_t space_hid, type_hid, data_hid;
776 space_hid = type_hid = data_hid = -1;
778 space_hid = H5Screate_simple (0, dimens,
nullptr);
779 if (space_hid < 0)
return false;
781 type_hid = with_reverse
782 ? hdf5_make_range_rev_type<T> (h5_save_type)
783 : hdf5_make_range_type<T> (h5_save_type);
786 H5Sclose (space_hid);
789 # if defined (HAVE_HDF5_18)
790 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid,
798 H5Sclose (space_hid);
804 range_vals[0] =
r.base ();
805 if (
r.increment () != T (0))
806 range_vals[1] =
r.limit ();
808 range_vals[1] =
r.numel ();
809 range_vals[2] =
r.increment ();
810 range_vals[3] =
r.reverse ();
818 "OCTAVE_RANGE_NELEM", &nel) >= 0;
825 H5Sclose (space_hid);
832 template <
typename T>
837 #if defined (HAVE_HDF5)
838 return xsave_hdf5 (loc_id, name, save_as_floats, m_range, hdf5_save_type,
841 octave_unused_parameter (loc_id);
842 octave_unused_parameter (name);
843 octave_unused_parameter (save_as_floats);
853 #if defined (HAVE_HDF5)
855 template <
typename T>
862 # if defined (HAVE_HDF5_18)
865 hid_t data_hid = H5Dopen (loc_id, name);
867 hid_t type_hid = H5Dget_type (data_hid);
869 hid_t range_type = with_reverse
870 ? hdf5_make_range_rev_type<T> (h5_save_type)
871 : hdf5_make_range_type<T> (h5_save_type);
875 H5Tclose (range_type);
880 hid_t space_hid = H5Dget_space (data_hid);
881 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
885 H5Tclose (range_type);
886 H5Sclose (space_hid);
900 bool rev = with_reverse ?
static_cast<bool> (rangevals[3]) :
false;
902 r = octave::range<T> (rangevals[0], rangevals[2], rangevals[1], rev);
905 H5Tclose (range_type);
906 H5Sclose (space_hid);
914 template <
typename T>
918 #if defined (HAVE_HDF5)
919 return xload_hdf5 (loc_id, name, m_range, hdf5_save_type,
false);
921 octave_unused_parameter (loc_id);
922 octave_unused_parameter (name);
958 template <
typename T>
967 mx_type *pd =
static_cast<mx_type *
> (retval->
get_data ());
971 Array<T> matrix = raw_array_value ();
973 const T *pdata = matrix.
data ();
975 for (
mwSize i = 0; i < nel; i++)
982 "trivial range",
"double");
984 template <
typename T>
1020 if (
static_cast<int> (m_range.final_value ()) != m_range.final_value ())
1022 if (
static_cast<int> (m_range.increment ()) != m_range.increment ())
1024 if (
static_cast<int> (m_range.base ()) != m_range.base ())
1026 if (
static_cast<int> (m_range.limit ()) != m_range.limit ())
1029 if (m_range.reverse ())
1035 template <
typename T>
1039 error (
"Type error returning trivial range");
1049 template <
typename T>
1059 octave::range<double>
1065 template <
typename T>
1090 return *m_idx_cache;
1092 if (require_integers || m_range.all_elements_are_ints ())
1096 "non-integer range used as index");
1098 return octave_value (matrix_value ()).round ().index_vector ();
1105 return m_range.nnz ();
1129 Matrix mat = matrix_value ();
1131 return mat.
diag (nr, nc);
1139 current_print_indent_level ());
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
T & elem(octave_idx_type n)
Size of the specified dimension.
bool test_all(F fcn) const
Size of the specified dimension.
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
const T * data() const
Size of the specified dimension.
Matrix diag(octave_idx_type k=0) const
Vector representing the dimensions (size) of an Array.
static octave_value make(double d)
octave_idx_type length() const
octave_value index_op(const octave_value_list &idx, bool resize_ok=false)
octave::idx_vector index_vector(bool require_integers=false) const
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, std::size_t skip=1)
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
octave_value as_double_or_copy() const
FloatComplex float_complex_value(bool=false) const
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
octave_value fast_elem_extract(octave_idx_type n) const
octave_value as_int64() const
octave_value diag(octave_idx_type k=0) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool flag)
octave_value resize(const dim_vector &dv, bool fill=false) const
octave_value as_uint32() const
octave_value as_uint16() const
bool could_be_trivial_range()
bool load_ascii(std::istream &is)
void short_disp(std::ostream &os) const
octave_value as_single() const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool save_ascii(std::ostream &os)
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
bool save_binary(std::ostream &os, bool save_as_floats)
double double_value(bool=false) const
Array< T > raw_array_value() const
octave_value as_uint64() const
float_display_format get_edit_display_format() const
octave_idx_type nnz() const
octave_value as_int8() const
octave_value as_int16() const
charNDArray char_array_value(bool=false) const
octave_value vm_extract_forloop_value(octave_idx_type idx)
boolNDArray bool_array_value(bool warn=false) const
type_conv_info numeric_conversion_function() const
float float_value(bool=false) const
mxArray * as_mxArray(bool interleaved) const
octave_value as_trivial_range()
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
octave_value as_double() const
octave::range< double > range_value() const
void print(std::ostream &os, bool pr_as_read_syntax=false)
octave_value convert_to_str_internal(bool pad, bool force, char type) const
octave_base_value * try_narrowing_conversion()
octave_value as_uint8() const
octave::idx_vector index_vector(bool require_integers=false) const
bool print_name_tag(std::ostream &os, const std::string &name) const
octave_value as_int32() const
Complex complex_value(bool=false) const
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
void warning_with_id(const char *id, const char *fmt,...)
void() error(const char *fmt,...)
#define panic_impossible()
void err_wrong_type_arg(const char *name, const char *s)
void err_invalid_conversion(const std::string &from, const std::string &to)
void warn_logical_conversion()
void warn_implicit_conversion(const char *id, const char *from, const char *to)
octave::idx_vector idx_vector
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
float lo_ieee_float_nan_value()
void skip_until_newline(std::istream &is, bool keep_newline)
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
octave_hdf5_err hdf5_add_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
std::complex< double > Complex
std::complex< float > FloatComplex
T::size_type numel(const T &str)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
#define DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
bool xsave_ascii(std::ostream &os, const octave::range< T > &r, const bool with_reverse)
bool xsave_binary(std::ostream &os, bool, const octave::range< T > &r, const bool with_reverse)
bool xload_binary(std::istream &is, bool swap, octave::mach_info::float_format, octave::range< T > &r, const bool with_reverse)
bool xsave_hdf5(octave_hdf5_id loc_id, const char *name, bool, const octave::range< T > &r, const octave_hdf5_id h5_save_type, const bool with_reverse)
bool xload_hdf5(octave_hdf5_id loc_id, const char *name, octave::range< T > &r, const octave_hdf5_id h5_save_type, const bool with_reverse)
bool xload_ascii(std::istream &is, octave::range< T > &r, const bool with_reverse)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
float_display_format make_format(const double &d)
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray