26#if defined (HAVE_CONFIG_H)
67#if defined (HAVE_HDF5)
146 "double_range",
"double");
153 "float_range",
"single");
156 "int8_range",
"int8");
159 "int16_range",
"int16");
162 "int32_range",
"int32");
165 "int64_range",
"int64");
168 "uint8_range",
"uint8");
171 "uint16_range",
"uint16");
174 "uint32_range",
"uint32");
177 "uint64_range",
"uint64");
199 (default_numeric_conversion_function<T>, ov_mx_type::static_type_id ());
217 typename ov_mx_type::object_type m (
dim_vector (1, 0));
218 retval =
new ov_mx_type (m);
239 const std::list<octave_value_list>& idx)
246 retval = do_index_op (idx.front ());
252 std::string nm = type_name ();
253 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
269 if (idx.
length () == 1 && ! resize_ok)
280 retval = m_range.elem (i(0));
282 retval = m_range.index (i);
298 return tmp.
index_op (idx, resize_ok);
320 "range",
"real scalar");
322 return m_range.base ();
335 "range",
"real scalar");
337 return m_range.base ();
344 const Array<T> matrix = raw_array_value ();
350 retval.
elem (i) =
static_cast<char> (matrix.
elem (i));
365 "range",
"complex scalar");
367 return Complex (m_range.base (), 0);
384 "range",
"complex scalar");
386 retval = m_range.base ();
395 Array<T> matrix = raw_array_value ();
397 if (warn && ! matrix.
test_all (octave::is_one_or_zero<T>))
407 Array<T> retval = raw_array_value ();
434octave::range<octave_int8>
441octave::range<octave_int16>
448octave::range<octave_int32>
455octave::range<octave_int64>
462octave::range<octave_uint8>
469octave::range<octave_uint16>
476octave::range<octave_uint32>
483octave::range<octave_uint64>
505 return NDArray (raw_array_value ());
575 print_raw (os, pr_as_read_syntax);
586 typename ov_mx_type::object_type tmp (raw_array_value ());
589 current_print_indent_level ());
602 if (n == 0 || n == 1)
627 os << m_range.base () <<
':';
631 if (m_range.increment () != T (1))
632 os << m_range.increment () <<
':';
634 os << m_range.limit ();
647 if (c ==
' ' || c ==
'\t' || c ==
'\n')
668 std::ostringstream buf;
676 const bool with_reverse)
679 T limit = r.limit ();
680 T inc = r.increment ();
681 bool rev = r.reverse ();
685 os <<
"# base, limit, increment";
687 os <<
"# base, length, increment";
694 octave::write_value<T> (os, base);
697 octave::write_value<T> (os, limit);
701 octave::write_value<T> (os, inc);
754xload_ascii (std::istream& is, octave::range<T>& r,
const bool with_reverse)
761 is >> base >> limit >> inc;
767 error (
"load: failed to load range constant");
769 r = octave::range<T> (base, inc, limit, rev);
846 const octave::range<T>& r,
const bool with_reverse)
851 os.write (
reinterpret_cast<char *
> (&tmp), 1);
854 T inc = r.increment ();
858 os.write (
reinterpret_cast<char *
> (&bas),
sizeof (T));
859 os.write (
reinterpret_cast<char *
> (&lim),
sizeof (T));
860 os.write (
reinterpret_cast<char *
> (&inc),
sizeof (T));
863 bool rev = r.reverse ();
864 os.write (
reinterpret_cast<char *
> (&rev),
sizeof (
bool));
874 return xsave_binary (os, save_as_floats, m_range,
false);
885 return xsave_binary (os, save_as_floats, m_range,
true);
892 return xsave_binary (os, save_as_floats, m_range,
true);
899 return xsave_binary (os, save_as_floats, m_range,
true);
906 return xsave_binary (os, save_as_floats, m_range,
true);
915 octave::range<T>& r,
const bool with_reverse)
920 if (! is.read (
reinterpret_cast<char *
> (&tmp), 1))
923 if (! is.read (
reinterpret_cast<char *
> (&bas), sizeof (T)))
926 swap_bytes<sizeof (T)> (&bas);
927 if (! is.read (
reinterpret_cast<char *
> (&lim), sizeof (T)))
930 swap_bytes<sizeof (T)> (&lim);
931 if (! is.read (
reinterpret_cast<char *
> (&inc), sizeof (T)))
934 swap_bytes<sizeof (T)> (&inc);
938 if (! is.read (
reinterpret_cast<char *
> (&rev), sizeof (
bool)))
941 swap_bytes<sizeof (bool)> (&rev);
944 r = octave::range<T> (bas, inc, lim, rev);
1021#if defined (HAVE_HDF5)
1029template <
typename T>
1033 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (T) * 3);
1035 H5Tinsert (type_id,
"base", 0 *
sizeof (T), num_type);
1036 H5Tinsert (type_id,
"limit", 1 *
sizeof (T), num_type);
1037 H5Tinsert (type_id,
"increment", 2 *
sizeof (T), num_type);
1042template <
typename T>
1046 hid_t type_id = H5Tcreate (H5T_COMPOUND,
sizeof (T) * 4);
1048 H5Tinsert (type_id,
"base", 0 *
sizeof (T), num_type);
1049 H5Tinsert (type_id,
"limit", 1 *
sizeof (T), num_type);
1050 H5Tinsert (type_id,
"increment", 2 *
sizeof (T), num_type);
1052 H5Tinsert (type_id,
"reverse", 3 *
sizeof (T), num_type);
1057template <
typename T>
1060 bool ,
const octave::range<T>& r,
1063 bool retval =
false;
1065 hsize_t dimens[3] = {0};
1066 hid_t space_hid, type_hid, data_hid;
1067 space_hid = type_hid = data_hid = -1;
1069 space_hid = H5Screate_simple (0, dimens,
nullptr);
1070 if (space_hid < 0)
return false;
1072 type_hid = with_reverse
1073 ? hdf5_make_range_rev_type<T> (h5_save_type)
1074 : hdf5_make_range_type<T> (h5_save_type);
1077 H5Sclose (space_hid);
1080# if defined (HAVE_HDF5_18)
1081 data_hid = H5Dcreate (loc_id,
name, type_hid, space_hid,
1088 H5Sclose (space_hid);
1089 H5Tclose (type_hid);
1094 range_vals[0] = r.base ();
1095 if (r.increment () != T (0))
1096 range_vals[1] = r.limit ();
1098 range_vals[1] = r.numel ();
1099 range_vals[2] = r.increment ();
1100 range_vals[3] = r.reverse ();
1108 "OCTAVE_RANGE_NELEM", &nel) >= 0;
1113 H5Dclose (data_hid);
1114 H5Tclose (type_hid);
1115 H5Sclose (space_hid);
1122template <
typename T>
1125 bool save_as_floats)
1127#if defined (HAVE_HDF5)
1128 return xsave_hdf5 (loc_id,
name, save_as_floats, m_range, hdf5_save_type,
1131 octave_unused_parameter (loc_id);
1132 octave_unused_parameter (
name);
1133 octave_unused_parameter (save_as_floats);
1148 bool save_as_floats)
1150#if defined (HAVE_HDF5)
1151 return xsave_hdf5 (loc_id,
name, save_as_floats, m_range, hdf5_save_type,
1154 octave_unused_parameter (loc_id);
1155 octave_unused_parameter (
name);
1156 octave_unused_parameter (save_as_floats);
1167 bool save_as_floats)
1169#if defined (HAVE_HDF5)
1170 return xsave_hdf5 (loc_id,
name, save_as_floats, m_range, hdf5_save_type,
1173 octave_unused_parameter (loc_id);
1174 octave_unused_parameter (
name);
1175 octave_unused_parameter (save_as_floats);
1186 bool save_as_floats)
1188#if defined (HAVE_HDF5)
1189 return xsave_hdf5 (loc_id,
name, save_as_floats, m_range, hdf5_save_type,
1192 octave_unused_parameter (loc_id);
1193 octave_unused_parameter (
name);
1194 octave_unused_parameter (save_as_floats);
1205 bool save_as_floats)
1207#if defined (HAVE_HDF5)
1208 return xsave_hdf5 (loc_id,
name, save_as_floats, m_range, hdf5_save_type,
1211 octave_unused_parameter (loc_id);
1212 octave_unused_parameter (
name);
1213 octave_unused_parameter (save_as_floats);
1223#if defined (HAVE_HDF5)
1225template <
typename T>
1230 bool retval =
false;
1232# if defined (HAVE_HDF5_18)
1235 hid_t data_hid = H5Dopen (loc_id,
name);
1237 hid_t type_hid = H5Dget_type (data_hid);
1239 hid_t range_type = with_reverse
1240 ? hdf5_make_range_rev_type<T> (h5_save_type)
1241 : hdf5_make_range_type<T> (h5_save_type);
1245 H5Tclose (range_type);
1246 H5Dclose (data_hid);
1250 hid_t space_hid = H5Dget_space (data_hid);
1251 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1255 H5Tclose (range_type);
1256 H5Sclose (space_hid);
1257 H5Dclose (data_hid);
1270 bool rev = with_reverse ?
static_cast<bool> (rangevals[3]) :
false;
1272 r = octave::range<T> (rangevals[0], rangevals[2], rangevals[1], rev);
1275 H5Tclose (range_type);
1276 H5Sclose (space_hid);
1277 H5Dclose (data_hid);
1284template <
typename T>
1288#if defined (HAVE_HDF5)
1289 return xload_hdf5 (loc_id,
name, m_range, hdf5_save_type,
false);
1291 octave_unused_parameter (loc_id);
1292 octave_unused_parameter (
name);
1308#if defined (HAVE_HDF5)
1311 octave_unused_parameter (loc_id);
1312 octave_unused_parameter (
name);
1324#if defined (HAVE_HDF5)
1327 octave_unused_parameter (loc_id);
1328 octave_unused_parameter (
name);
1340#if defined (HAVE_HDF5)
1343 octave_unused_parameter (loc_id);
1344 octave_unused_parameter (
name);
1356#if defined (HAVE_HDF5)
1359 octave_unused_parameter (loc_id);
1360 octave_unused_parameter (
name);
1396template <
typename T>
1402 mxArray *retval =
new mxArray (interleaved, mx_class, dims (), mxREAL);
1405 mx_type *pd =
static_cast<mx_type *
> (retval->
get_data ());
1407 mwSize nel =
numel ();
1409 Array<T> matrix = raw_array_value ();
1411 const T *pdata = matrix.
data ();
1413 for (mwSize i = 0; i < nel; i++)
1419template <
typename T>
1429octave::range<double>
1447octave::range<octave_int8>
1454octave::range<octave_int16>
1461octave::range<octave_int32>
1468octave::range<octave_int64>
1475octave::range<octave_uint8>
1482octave::range<octave_uint16>
1489octave::range<octave_uint32>
1496octave::range<octave_uint64>
1509 return *m_idx_cache;
1511 if (require_integers || m_range.all_elements_are_ints ())
1515 "non-integer range used as index");
1517 return octave_value (matrix_value ()).round ().index_vector ();
1524 return m_range.nnz ();
1548 Matrix mat = matrix_value ();
1550 return mat.
diag (nr, nc);
1558 current_print_indent_level ());
bool test_all(F fcn) const
Size of the specified dimension.
T & elem(octave_idx_type n)
Size of the specified dimension.
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
const T * data(void) const
Size of the specified dimension.
OCTAVE_API Matrix diag(octave_idx_type k=0) const
Vector representing the dimensions (size) of an Array.
void * get_data(void) const
bool is_scalar(void) const
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
octave_idx_type length(void) const
octave_value index_op(const octave_value_list &idx, bool resize_ok=false)
octave::idx_vector index_vector(bool require_integers=false) const
OCTINTERP_API 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
OCTINTERP_API FloatComplex float_complex_value(bool=false) const
OCTINTERP_API octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
OCTINTERP_API octave_value fast_elem_extract(octave_idx_type n) const
OCTINTERP_API octave_value as_int32(void) const
OCTINTERP_API type_conv_info numeric_conversion_function(void) const
OCTINTERP_API octave_value as_single(void) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_value diag(octave_idx_type k=0) const
OCTINTERP_API octave_value as_uint64(void) const
OCTINTERP_API bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool flag)
OCTINTERP_API octave_value resize(const dim_vector &dv, bool fill=false) const
OCTINTERP_API octave_value as_uint16(void) const
OCTINTERP_API float_display_format get_edit_display_format(void) const
OCTINTERP_API bool load_ascii(std::istream &is)
OCTINTERP_API octave_value as_int16(void) const
OCTINTERP_API void short_disp(std::ostream &os) const
OCTINTERP_API void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
OCTINTERP_API bool save_ascii(std::ostream &os)
OCTINTERP_API std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
OCTINTERP_API bool save_binary(std::ostream &os, bool save_as_floats)
OCTINTERP_API double double_value(bool=false) const
OCTINTERP_API octave_value as_double(void) const
OCTINTERP_API octave::range< double > range_value(void) const
Array< T > raw_array_value(void) const
OCTINTERP_API charNDArray char_array_value(bool=false) const
OCTINTERP_API boolNDArray bool_array_value(bool warn=false) const
OCTINTERP_API octave_base_value * try_narrowing_conversion(void)
OCTINTERP_API float float_value(bool=false) const
OCTINTERP_API octave_value as_uint32(void) const
OCTINTERP_API octave_value as_uint8(void) const
OCTINTERP_API mxArray * as_mxArray(bool interleaved) const
OCTINTERP_API octave_value as_int64(void) const
OCTINTERP_API bool load_hdf5(octave_hdf5_id loc_id, const char *name)
OCTINTERP_API bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
OCTINTERP_API octave_value as_int8(void) const
OCTINTERP_API void print(std::ostream &os, bool pr_as_read_syntax=false)
OCTINTERP_API octave_value convert_to_str_internal(bool pad, bool force, char type) const
octave_idx_type nnz(void) const
OCTINTERP_API octave::idx_vector index_vector(bool require_integers=false) const
OCTINTERP_API bool print_name_tag(std::ostream &os, const std::string &name) const
OCTINTERP_API 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)
void warn_implicit_conversion(const char *id, const char *from, const char *to)
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
float lo_ieee_float_nan_value(void)
OCTAVE_NAMESPACE_BEGIN 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)
class OCTAVE_API boolNDArray
class OCTAVE_API FloatMatrix
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)
bool xsave_ascii(std::ostream &os, const octave::range< T > &r, const bool with_reverse)
static hid_t hdf5_make_range_rev_type(hid_t num_type)
bool xsave_binary(std::ostream &os, bool, const octave::range< T > &r, const bool with_reverse)
static octave_base_value * default_numeric_conversion_function(const octave_base_value &a)
static void skip_comments(std::istream &is)
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)
static hid_t hdf5_make_range_type(hid_t num_type)
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