80 template <
typename T,
bool is_
signed = true,
bool can_be_too_big = true>
108 template <
typename T>
121 template <
typename T>
145 template <
typename T>
151 if (this->m_matrix.numel () == 1)
153 (this->m_matrix (0));
158 template <
typename T>
174 typename T::element_type tmp = this->m_matrix(i);
176 typedef typename T::element_type::val_type val_type;
178 val_type ival = tmp.value ();
180 static const bool is_signed = std::numeric_limits<val_type>::is_signed;
181 static const bool can_be_larger_than_uchar_max
185 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
193 ::warning (
"range error for conversion to character value");
198 chm (i) =
static_cast<char> (ival);
206 template <
typename MT>
210 return NDArray (this->m_matrix);
213 template <
typename MT>
220 template <
typename MT>
227 template <
typename MT>
234 template <
typename MT>
241 template <
typename MT>
248 template <
typename MT>
255 template <
typename MT>
262 template <
typename MT>
269 template <
typename MT>
276 template <
typename T>
282 std::ostringstream buf;
287 template <
typename T>
293 os <<
"# ndims: " << dv.
ndims () <<
"\n";
295 for (
int i = 0; i < dv.
ndims (); i++)
298 os <<
"\n" << this->m_matrix;
303 template <
typename T>
310 error (
"load: failed to extract number of dimensions");
313 error (
"load: failed to extract number of rows and columns");
318 for (
int i = 0; i < mdims; i++)
326 error (
"load: failed to load matrix constant");
328 this->m_matrix = tmp;
333 template <
typename T>
342 int32_t tmp = - dv.
ndims ();
343 os.write (
reinterpret_cast<char *
> (&tmp), 4);
344 for (
int i=0; i < dv.
ndims (); i++)
347 os.write (
reinterpret_cast<char *
> (&tmp), 4);
350 os.write (
reinterpret_cast<const char *
> (this->m_matrix.data ()),
356 template <
typename T>
362 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
374 for (
int i = 0; i < mdims; i++)
376 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
397 if (! is.read (
reinterpret_cast<char *
> (
m.fortran_vec ()),
m.byte_size ()))
402 int nel = dv.
numel ();
403 int bytes = nel /
m.byte_size ();
404 for (
int i = 0; i < nel; i++)
426 template <
typename T>
430 const char *name,
bool)
434 #if defined (HAVE_HDF5)
442 int rank = dv.
ndims ();
443 hid_t space_hid, data_hid;
444 space_hid = data_hid = -1;
448 for (
int i = 0; i < rank; i++)
449 hdims[i] = dv(rank-i-1);
451 space_hid = H5Screate_simple (rank, hdims,
nullptr);
453 if (space_hid < 0)
return false;
454 #if defined (HAVE_HDF5_18)
455 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
459 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
464 H5Sclose (space_hid);
472 H5Sclose (space_hid);
475 octave_unused_parameter (loc_id);
477 octave_unused_parameter (name);
479 this->warn_save (
"hdf5");
485 template <
typename T>
493 #if defined (HAVE_HDF5)
499 this->m_matrix.resize (dv);
503 #if defined (HAVE_HDF5_18)
506 hid_t data_hid = H5Dopen (loc_id, name);
508 hid_t space_id = H5Dget_space (data_hid);
510 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
522 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
534 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
550 octave_unused_parameter (loc_id);
552 octave_unused_parameter (name);
554 this->warn_load (
"hdf5");
560 template <
typename T>
563 bool pr_as_read_syntax)
const
566 this->current_print_indent_level ());
569 template <
typename T>
577 typedef typename T::val_type val_type;
579 val_type ival = tmp.value ();
581 static const bool is_signed = std::numeric_limits<val_type>::is_signed;
582 static const bool can_be_larger_than_uchar_max
586 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
592 ::warning (
"range error for conversion to character value");
595 retval =
octave_value (std::string (1,
static_cast<char> (ival)), type);
600 template <
typename T>
604 return static_cast<double> (this->
scalar);
607 template <
typename T>
611 return static_cast<float> (this->
scalar);
614 template <
typename T>
621 template <
typename T>
628 template <
typename T>
635 template <
typename T>
642 template <
typename T>
649 template <
typename T>
656 template <
typename T>
663 template <
typename T>
670 template <
typename ST>
676 std::ostringstream buf;
681 template <
typename T>
685 os << this->
scalar <<
"\n";
689 template <
typename T>
695 error (
"load: failed to load scalar constant");
700 template <
typename T>
704 os.write (
reinterpret_cast<char *
> (&(this->
scalar)), this->byte_size ());
708 template <
typename T>
715 if (! is.read (
reinterpret_cast<char *
> (&tmp), this->byte_size ()))
719 swap_bytes<sizeof (T)> (&tmp);
726 template <
typename T>
730 const char *name,
bool)
734 #if defined (HAVE_HDF5)
737 hsize_t dimens[3] = {0};
738 hid_t space_hid, data_hid;
739 space_hid = data_hid = -1;
741 space_hid = H5Screate_simple (0, dimens,
nullptr);
742 if (space_hid < 0)
return false;
744 #if defined (HAVE_HDF5_18)
745 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
749 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
754 H5Sclose (space_hid);
762 H5Sclose (space_hid);
765 octave_unused_parameter (loc_id);
767 octave_unused_parameter (name);
769 this->warn_save (
"hdf5");
775 template <
typename T>
781 #if defined (HAVE_HDF5)
784 #if defined (HAVE_HDF5_18)
787 hid_t data_hid = H5Dopen (loc_id, name);
789 hid_t space_id = H5Dget_space (data_hid);
791 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
814 octave_unused_parameter (loc_id);
816 octave_unused_parameter (name);
818 this->warn_load (
"hdf5");
void swap_bytes< 2 >(void *ptr)
void swap_bytes< 8 >(void *ptr)
void swap_bytes< 4 >(void *ptr)
charNDArray max(char d, const charNDArray &m)
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(void) const
Number of dimensions.
OCTINTERP_API octave_value as_int8(void) const
OCTINTERP_API octave_value as_uint16(void) const
OCTINTERP_API void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
OCTINTERP_API octave_value as_uint32(void) const
OCTINTERP_API octave_value as_int16(void) const
OCTINTERP_API octave_value as_int32(void) const
OCTINTERP_API octave_value as_double(void) const
OCTINTERP_API octave_value as_uint64(void) const
OCTINTERP_API bool save_ascii(std::ostream &os)
OCTINTERP_API bool load_ascii(std::istream &is)
OCTINTERP_API std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
OCTINTERP_API octave_value as_uint8(void) const
OCTINTERP_API octave_value as_int64(void) const
OCTINTERP_API octave_value as_single(void) const
OCTINTERP_API bool save_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name, bool)
OCTINTERP_API bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format)
OCTINTERP_API octave_base_value * try_narrowing_conversion(void)
OCTINTERP_API octave_value convert_to_str_internal(bool, bool, char type) const
OCTINTERP_API bool save_binary(std::ostream &os, bool)
OCTINTERP_API bool load_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name)
OCTINTERP_API bool load_ascii(std::istream &is)
OCTINTERP_API octave_value as_double(void) const
OCTINTERP_API bool save_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name, bool)
OCTINTERP_API bool load_hdf5_internal(octave_hdf5_id loc_id, octave_hdf5_id save_type, const char *name)
OCTINTERP_API octave_value as_uint16(void) const
OCTINTERP_API octave_value convert_to_str_internal(bool, bool, char type) const
OCTINTERP_API octave_value as_int16(void) const
OCTINTERP_API octave_value as_uint64(void) const
OCTINTERP_API octave_value as_single(void) const
OCTINTERP_API octave_value as_int8(void) const
OCTINTERP_API octave_value as_int32(void) const
OCTINTERP_API std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
OCTINTERP_API octave_value as_int64(void) const
OCTINTERP_API octave_value as_uint8(void) const
OCTINTERP_API bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format)
OCTINTERP_API octave_value as_uint32(void) const
OCTINTERP_API bool save_ascii(std::ostream &os)
OCTINTERP_API 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)
class OCTAVE_API FloatNDArray
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)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
static bool scalar(const dim_vector &dims)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
static bool char_value_out_of_range(T)
static bool char_value_out_of_range(T val)
static bool char_value_out_of_range(T val)
static const bool can_be_larger_than_uchar_max
static bool char_value_out_of_range(T val)
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray