76template <
typename T,
bool is_
signed = true,
bool can_be_too_big = true>
77struct octave_base_int_helper
81 char_value_out_of_range (T val)
83 return val < 0 || val > std::numeric_limits<unsigned char>::max ();
88struct octave_base_int_helper<T, false, false>
91 static bool char_value_out_of_range (T) {
return false; }
95struct octave_base_int_helper<T, false, true>
98 static bool char_value_out_of_range (T val)
100 return val > std::numeric_limits<unsigned char>::max ();
105struct octave_base_int_helper<T, true, false>
108 static bool char_value_out_of_range (T val) {
return val < 0; }
118struct octave_base_int_helper_traits
120 static const bool can_be_larger_than_uchar_max =
true;
124struct octave_base_int_helper_traits<char>
126 static const bool can_be_larger_than_uchar_max =
false;
130struct octave_base_int_helper_traits<signed char>
132 static const bool can_be_larger_than_uchar_max =
false;
136struct octave_base_int_helper_traits<unsigned char>
138 static const bool can_be_larger_than_uchar_max =
false;
147 if (this->m_matrix.numel () == 1)
149 (this->m_matrix (0));
170 typename T::element_type tmp = this->m_matrix(i);
172 typedef typename T::element_type::val_type val_type;
174 val_type ival = tmp.value ();
176 static constexpr bool is_signed = std::numeric_limits<val_type>::is_signed;
177 static constexpr bool can_be_larger_than_uchar_max
178 = octave_base_int_helper_traits<val_type>::can_be_larger_than_uchar_max;
180 if (octave_base_int_helper<val_type, is_signed,
181 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
189 ::warning (
"range error for conversion to character value");
194 chm (i) =
static_cast<char> (ival);
202template <
typename MT>
206 return NDArray (this->m_matrix);
209template <
typename MT>
216template <
typename MT>
223template <
typename MT>
230template <
typename MT>
237template <
typename MT>
244template <
typename MT>
251template <
typename MT>
258template <
typename MT>
265template <
typename MT>
278 std::ostringstream buf;
289 os <<
"# ndims: " << dv.
ndims () <<
"\n";
291 for (
int i = 0; i < dv.
ndims (); i++)
294 os <<
"\n" << this->m_matrix;
306 error (
"load: failed to extract number of dimensions");
309 error (
"load: failed to extract number of rows and columns");
314 for (
int i = 0; i < mdims; i++)
322 error (
"load: failed to load matrix constant");
324 this->m_matrix = tmp;
338 int32_t tmp = - dv.
ndims ();
339 os.write (
reinterpret_cast<char *
> (&tmp), 4);
340 for (
int i=0; i < dv.
ndims (); i++)
343 os.write (
reinterpret_cast<char *
> (&tmp), 4);
346 os.write (
reinterpret_cast<const char *
> (this->m_matrix.data ()),
355 octave::mach_info::float_format)
358 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
370 for (
int i = 0; i < mdims; i++)
372 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
393 if (! is.read (
reinterpret_cast<char *
> (m.rwdata ()), m.byte_size ()))
398 int nel = dv.
numel ();
399 int bytes = nel / m.byte_size ();
400 for (
int i = 0; i < nel; i++)
426 const char *name,
bool)
430#if defined (HAVE_HDF5)
438 int rank = dv.
ndims ();
439 hid_t space_hid, data_hid;
440 space_hid = data_hid = -1;
444 for (
int i = 0; i < rank; i++)
445 hdims[i] = dv(rank-i-1);
447 space_hid = H5Screate_simple (rank, hdims,
nullptr);
449 if (space_hid < 0)
return false;
450#if defined (HAVE_HDF5_18)
451 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
455 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
460 H5Sclose (space_hid);
468 H5Sclose (space_hid);
471 octave_unused_parameter (loc_id);
473 octave_unused_parameter (name);
475 this->warn_save (
"hdf5");
489#if defined (HAVE_HDF5)
495 this->m_matrix.resize (dv);
499#if defined (HAVE_HDF5_18)
502 hid_t data_hid = H5Dopen (loc_id, name);
504 hid_t space_id = H5Dget_space (data_hid);
506 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
518 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
530 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
546 octave_unused_parameter (loc_id);
548 octave_unused_parameter (name);
550 this->warn_load (
"hdf5");
559 bool pr_as_read_syntax)
const
562 this->current_print_indent_level ());
571 T tmp = this->scalar;
573 typedef typename T::val_type val_type;
575 val_type ival = tmp.value ();
577 static constexpr bool is_signed = std::numeric_limits<val_type>::is_signed;
578 static constexpr bool can_be_larger_than_uchar_max
579 = octave_base_int_helper_traits<val_type>::can_be_larger_than_uchar_max;
581 if (octave_base_int_helper<val_type, is_signed,
582 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
588 ::warning (
"range error for conversion to character value");
591 retval =
octave_value (std::string (1,
static_cast<char> (ival)), type);
600 return static_cast<double> (this->scalar);
607 return static_cast<float> (this->scalar);
666template <
typename ST>
672 std::ostringstream buf;
681 os << this->scalar <<
"\n";
691 error (
"load: failed to load scalar constant");
700 os.write (
reinterpret_cast<char *
> (&(this->scalar)), this->byte_size ());
707 octave::mach_info::float_format)
711 if (! is.read (
reinterpret_cast<char *
> (&tmp), this->byte_size ()))
715 swap_bytes<sizeof (T)> (&tmp);
726 const char *name,
bool)
730#if defined (HAVE_HDF5)
733 hsize_t dimens[3] = {0};
734 hid_t space_hid, data_hid;
735 space_hid = data_hid = -1;
737 space_hid = H5Screate_simple (0, dimens,
nullptr);
738 if (space_hid < 0)
return false;
740#if defined (HAVE_HDF5_18)
741 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
745 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
750 H5Sclose (space_hid);
758 H5Sclose (space_hid);
761 octave_unused_parameter (loc_id);
763 octave_unused_parameter (name);
765 this->warn_save (
"hdf5");
777#if defined (HAVE_HDF5)
780#if defined (HAVE_HDF5_18)
783 hid_t data_hid = H5Dopen (loc_id, name);
785 hid_t space_id = H5Dget_space (data_hid);
787 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
810 octave_unused_parameter (loc_id);
812 octave_unused_parameter (name);
814 this->warn_load (
"hdf5");
void swap_bytes< 2 >(void *ptr)
void swap_bytes< 8 >(void *ptr)
void swap_bytes< 4 >(void *ptr)
Vector representing the dimensions (size) of an Array.
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
void resize(int n, int fill_value=0)
octave_idx_type ndims() const
Number of dimensions.
octave_value as_uint64() const
octave_value as_int64() const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
octave_value as_int8() const
octave_value as_int16() const
octave_base_value * try_narrowing_conversion()
octave_value as_uint16() const
octave_value as_single() const
bool save_ascii(std::ostream &os)
bool load_ascii(std::istream &is)
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
bool save_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name, bool)
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format)
octave_value as_uint8() const
octave_value as_uint32() const
octave_value convert_to_str_internal(bool, bool, char type) const
bool save_binary(std::ostream &os, bool)
octave_value as_double() const
octave_value as_int32() const
bool load_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name)
octave_value as_int8() const
octave_value as_double() const
octave_value as_single() const
bool load_ascii(std::istream &is)
octave_value as_int16() const
bool save_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name, bool)
bool load_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name)
octave_value convert_to_str_internal(bool, bool, char type) const
octave_value as_int32() const
octave_value as_int64() const
octave_value as_uint16() const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
octave_value as_uint8() const
octave_value as_uint64() const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format)
octave_value as_uint32() const
bool save_ascii(std::ostream &os)
bool save_binary(std::ostream &os, bool)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
void warning(const char *fmt,...)
void error(const char *fmt,...)
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
octave_int< uint32_t > octave_uint32
octave_int< int32_t > octave_int32
octave_int< int16_t > octave_int16
octave_int< int8_t > octave_int8
octave_int< int64_t > octave_int64
octave_int< uint64_t > octave_uint64
octave_int< uint16_t > octave_uint16
octave_int< uint8_t > octave_uint8
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray