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");
181 template <
typename T>
192 template <
typename T>
199 (default_numeric_conversion_function<T>, ov_mx_type::static_type_id ());
202 template <
typename T>
217 typename ov_mx_type::object_type
m (
dim_vector (1, 0));
218 retval =
new ov_mx_type (
m);
236 template <
typename T>
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]);
264 template <
typename T>
269 if (idx.
length () == 1 && ! resize_ok)
279 if (i.is_scalar () && i(0) <
numel ())
280 retval = m_range.elem (i(0));
282 retval = m_range.index (i);
284 catch (octave::index_exception& ie)
288 ie.set_pos_if_unset (1, 1);
298 return tmp.
index_op (idx, resize_ok);
302 template <
typename T>
310 template <
typename T>
320 "range",
"real scalar");
322 return m_range.base ();
325 template <
typename T>
335 "range",
"real scalar");
337 return m_range.base ();
340 template <
typename T>
344 const Array<T> matrix = raw_array_value ();
350 retval.
elem (i) =
static_cast<char> (matrix.
elem (i));
355 template <
typename T>
365 "range",
"complex scalar");
367 return Complex (m_range.base (), 0);
370 template <
typename T>
384 "range",
"complex scalar");
386 retval = m_range.base ();
391 template <
typename T>
395 Array<T> matrix = raw_array_value ();
397 if (warn && ! matrix.
test_all (octave::is_one_or_zero<T>))
403 template <
typename T>
407 Array<T> retval = raw_array_value ();
415 template <
typename T>
416 octave::range<double>
426 template <
typename T>
433 template <
typename T>
434 octave::range<octave_int8>
440 template <
typename T>
441 octave::range<octave_int16>
447 template <
typename T>
448 octave::range<octave_int32>
454 template <
typename T>
455 octave::range<octave_int64>
461 template <
typename T>
462 octave::range<octave_uint8>
468 template <
typename T>
469 octave::range<octave_uint16>
475 template <
typename T>
476 octave::range<octave_uint32>
482 template <
typename T>
483 octave::range<octave_uint64>
491 template <
typename T>
501 template <
typename T>
505 return NDArray (raw_array_value ());
508 template <
typename T>
515 template <
typename T>
522 template <
typename T>
529 template <
typename T>
536 template <
typename T>
543 template <
typename T>
550 template <
typename T>
557 template <
typename T>
564 template <
typename T>
571 template <
typename T>
575 print_raw (os, pr_as_read_syntax);
579 template <
typename T>
586 typename ov_mx_type::object_type tmp (raw_array_value ());
589 current_print_indent_level ());
592 template <
typename T>
602 if (
n == 0 ||
n == 1)
617 template <
typename T>
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')
656 template <
typename T>
663 template <
typename T>
668 std::ostringstream buf;
673 template <
typename T>
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);
709 template <
typename T>
752 template <
typename T>
754 xload_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);
774 template <
typename T>
843 template <
typename T>
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));
870 template <
typename T>
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);
911 template <
typename T>
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);
949 template <
typename T>
1021 #if defined (HAVE_HDF5)
1029 template <
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);
1042 template <
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);
1057 template <
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,
1089 H5Sclose (space_hid);
1090 H5Tclose (type_hid);
1095 range_vals[0] =
r.base ();
1096 if (
r.increment () != T (0))
1097 range_vals[1] =
r.limit ();
1099 range_vals[1] =
r.numel ();
1100 range_vals[2] =
r.increment ();
1101 range_vals[3] =
r.reverse ();
1109 "OCTAVE_RANGE_NELEM", &nel) >= 0;
1114 H5Dclose (data_hid);
1115 H5Tclose (type_hid);
1116 H5Sclose (space_hid);
1123 template <
typename T>
1126 bool save_as_floats)
1128 #if defined (HAVE_HDF5)
1129 return xsave_hdf5 (loc_id, name, save_as_floats, m_range, hdf5_save_type,
1132 octave_unused_parameter (loc_id);
1133 octave_unused_parameter (name);
1134 octave_unused_parameter (save_as_floats);
1149 bool save_as_floats)
1151 #if defined (HAVE_HDF5)
1152 return xsave_hdf5 (loc_id, name, save_as_floats, m_range, hdf5_save_type,
1155 octave_unused_parameter (loc_id);
1156 octave_unused_parameter (name);
1157 octave_unused_parameter (save_as_floats);
1168 bool save_as_floats)
1170 #if defined (HAVE_HDF5)
1171 return xsave_hdf5 (loc_id, name, save_as_floats, m_range, hdf5_save_type,
1174 octave_unused_parameter (loc_id);
1175 octave_unused_parameter (name);
1176 octave_unused_parameter (save_as_floats);
1187 bool save_as_floats)
1189 #if defined (HAVE_HDF5)
1190 return xsave_hdf5 (loc_id, name, save_as_floats, m_range, hdf5_save_type,
1193 octave_unused_parameter (loc_id);
1194 octave_unused_parameter (name);
1195 octave_unused_parameter (save_as_floats);
1206 bool save_as_floats)
1208 #if defined (HAVE_HDF5)
1209 return xsave_hdf5 (loc_id, name, save_as_floats, m_range, hdf5_save_type,
1212 octave_unused_parameter (loc_id);
1213 octave_unused_parameter (name);
1214 octave_unused_parameter (save_as_floats);
1224 #if defined (HAVE_HDF5)
1226 template <
typename T>
1231 bool retval =
false;
1233 # if defined (HAVE_HDF5_18)
1236 hid_t data_hid = H5Dopen (loc_id, name);
1238 hid_t type_hid = H5Dget_type (data_hid);
1240 hid_t range_type = with_reverse
1241 ? hdf5_make_range_rev_type<T> (h5_save_type)
1242 : hdf5_make_range_type<T> (h5_save_type);
1246 H5Tclose (range_type);
1247 H5Dclose (data_hid);
1251 hid_t space_hid = H5Dget_space (data_hid);
1252 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1256 H5Tclose (range_type);
1257 H5Sclose (space_hid);
1258 H5Dclose (data_hid);
1271 bool rev = with_reverse ?
static_cast<bool> (rangevals[3]) :
false;
1273 r = octave::range<T> (rangevals[0], rangevals[2], rangevals[1], rev);
1276 H5Tclose (range_type);
1277 H5Sclose (space_hid);
1278 H5Dclose (data_hid);
1285 template <
typename T>
1289 #if defined (HAVE_HDF5)
1290 return xload_hdf5 (loc_id, name, m_range, hdf5_save_type,
false);
1292 octave_unused_parameter (loc_id);
1293 octave_unused_parameter (name);
1309 #if defined (HAVE_HDF5)
1310 return xload_hdf5 (loc_id, name, m_range, hdf5_save_type,
true);
1312 octave_unused_parameter (loc_id);
1313 octave_unused_parameter (name);
1325 #if defined (HAVE_HDF5)
1326 return xload_hdf5 (loc_id, name, m_range, hdf5_save_type,
true);
1328 octave_unused_parameter (loc_id);
1329 octave_unused_parameter (name);
1341 #if defined (HAVE_HDF5)
1342 return xload_hdf5 (loc_id, name, m_range, hdf5_save_type,
true);
1344 octave_unused_parameter (loc_id);
1345 octave_unused_parameter (name);
1357 #if defined (HAVE_HDF5)
1358 return xload_hdf5 (loc_id, name, m_range, hdf5_save_type,
true);
1360 octave_unused_parameter (loc_id);
1361 octave_unused_parameter (name);
1397 template <
typename T>
1403 mxArray *retval =
new mxArray (interleaved, mx_class, dims (), mxREAL);
1406 mx_type *pd =
static_cast<mx_type *
> (retval->
get_data ());
1408 mwSize nel =
numel ();
1410 Array<T> matrix = raw_array_value ();
1412 const T *pdata = matrix.
data ();
1414 for (mwSize i = 0; i < nel; i++)
1420 template <
typename T>
1430 octave::range<double>
1441 octave::range<float>
1448 octave::range<octave_int8>
1455 octave::range<octave_int16>
1462 octave::range<octave_int32>
1469 octave::range<octave_int64>
1476 octave::range<octave_uint8>
1483 octave::range<octave_uint16>
1490 octave::range<octave_uint32>
1497 octave::range<octave_uint64>
1510 return *m_idx_cache;
1512 if (require_integers || m_range.all_elements_are_ints ())
1516 "non-integer range used as index");
1518 return octave_value (matrix_value ()).round ().index_vector ();
1525 return m_range.nnz ();
1549 Matrix mat = matrix_value ();
1551 return mat.
diag (nr, nc);
1559 current_print_indent_level ());
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
bool test_all(F fcn) const
Size of the specified dimension.
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API T & elem(octave_idx_type n)
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
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
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
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 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
Array< T > raw_array_value(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
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)
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)
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