26 #if defined (HAVE_CONFIG_H)
74 if (nda.
numel () == 1)
91 bool resize_ok,
char type)
135 for (k = 0; k <
len; k++)
136 idx_vec(k) = idx(k).index_vector ();
143 catch (octave::index_exception& ie)
146 ie.set_pos_if_unset (
len, k+1);
164 #define CHAR_MATRIX_CONV(TNAME, FCN) \
166 if (! force_string_conv) \
167 err_invalid_conversion ("string", TNAME); \
169 warn_implicit_conversion ("Octave:str-to-num", "string", TNAME); \
171 return octave_char_matrix::FCN ()
215 error (
"invalid conversion of charNDArray to string_vector");
233 error (
"invalid conversion of charNDArray to string");
239 "multi-row character matrix converted to a string, only the first row is used");
260 error (
"cellstr: cannot convert multidimensional arrays");
264 retval.
clear (nr, 1);
273 bool pr_as_read_syntax)
const
288 std::size_t max_len = 100;
290 os << (tmp.length () > max_len ? tmp.substr (0, 100) : tmp);
316 std::string dimstr = dv.
str ();
317 return "[" + dimstr +
" " + tname +
"]";
327 os <<
"# ndims: " << dv.
ndims () <<
"\n";
328 for (
int i=0; i < dv.
ndims (); i++)
340 os <<
"# elements: " << elements <<
"\n";
344 os <<
"# length: " <<
len <<
"\n";
346 const char *tmp = tstr.data ();
347 if (tstr.length () >
len)
362 keywords[0] =
"ndims";
363 keywords[1] =
"elements";
364 keywords[2] =
"length";
370 error (
"load: failed to extract number of rows and columns");
377 error (
"load: failed to extract matrix size");
382 for (
int i = 0; i < mdims; i++)
386 error (
"load: failed to read dimensions");
398 if (! is.read (ftmp, dv.
numel ()) || ! is)
399 error (
"load: failed to load string constant");
404 else if (kw ==
"elements")
409 error (
"load: failed to extract number of string elements");
415 for (
int i = 0; i < elements; i++)
419 error (
"load: failed to extract string length for element %d",
428 if (
len > 0 && ! is.read (ptmp,
len))
429 error (
"load: failed to load string constant");
434 chm.
resize (elements, max_len, 0);
442 else if (kw ==
"length")
456 if (
len > 0 && ! is.read (ptmp,
len))
457 error (
"load: failed to load string constant");
460 error (
"load: failed to load string constant");
480 int32_t tmp = - dv.
ndims ();
481 os.write (
reinterpret_cast<char *
> (&tmp), 4);
482 for (
int i=0; i < dv.
ndims (); i++)
485 os.write (
reinterpret_cast<char *
> (&tmp), 4);
489 os.write (
m.data (), dv.
numel ());
498 if (! is.read (
reinterpret_cast<char *
> (&elements), 4))
505 int32_t mdims = - elements;
510 for (
int i = 0; i < mdims; i++)
512 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
532 char *tmp =
m.fortran_vec ();
533 is.read (tmp, dv.
numel ());
544 for (
int i = 0; i < elements; i++)
547 if (! is.read (
reinterpret_cast<char *
> (&
len), 4))
553 if (! is.read (pbtmp,
len))
558 chm.
resize (elements, max_len, 0);
573 #if defined (HAVE_HDF5)
580 int rank = dv.
ndims ();
581 hid_t space_hid, data_hid;
582 space_hid = data_hid = -1;
588 for (
int i = 0; i < rank; i++)
589 hdims[i] = dv(rank-i-1);
591 space_hid = H5Screate_simple (rank, hdims,
nullptr);
594 #if defined (HAVE_HDF5_18)
595 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid,
599 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid,
604 H5Sclose (space_hid);
610 for (
int i = 0; i < dv.
numel (); ++i)
617 H5Sclose (space_hid);
620 octave_unused_parameter (loc_id);
621 octave_unused_parameter (name);
634 #if defined (HAVE_HDF5)
643 #if defined (HAVE_HDF5_18)
646 hid_t data_hid = H5Dopen (loc_id, name);
648 hid_t space_hid = H5Dget_space (data_hid);
649 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
650 hid_t type_hid = H5Dget_type (data_hid);
651 hid_t type_class_hid = H5Tget_class (type_hid);
653 if (type_class_hid == H5T_INTEGER)
658 H5Sclose (space_hid);
666 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
678 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
683 char *str =
m.fortran_vec ();
692 H5Sclose (space_hid);
702 int slen = H5Tget_size (type_hid);
706 H5Sclose (space_hid);
714 hid_t st_id = H5Tcopy (H5T_C_S1);
715 H5Tset_size (st_id, slen+1);
721 H5Sclose (space_hid);
730 H5Sclose (space_hid);
738 hsize_t elements, maxdim;
739 H5Sget_simple_extent_dims (space_hid, &elements, &maxdim);
740 int slen = H5Tget_size (type_hid);
744 H5Sclose (space_hid);
758 hid_t st_id = H5Tcopy (H5T_C_S1);
759 H5Tset_size (st_id, slen+1);
766 H5Sclose (space_hid);
772 for (hsize_t i = 0; i < elements; ++i)
774 chm.
insert (s + i*(slen+1), i, 0);
781 H5Sclose (space_hid);
789 H5Sclose (space_hid);
796 octave_unused_parameter (loc_id);
797 octave_unused_parameter (name);
void swap_bytes< 4 >(void *ptr)
N Dimensional Array with copy-on-write semantics.
T * fortran_vec()
Size of the specified dimension.
Array< T, Alloc > index(const octave::idx_vector &i) const
Indexing without resizing.
int ndims() const
Size of the specified dimension.
octave_idx_type rows() const
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
const T * data() const
Size of the specified dimension.
octave_idx_type cols() const
bool isempty() const
Size of the specified dimension.
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
void resize(octave_idx_type nr, octave_idx_type nc, char rfv=0)
charMatrix & insert(const char *s, octave_idx_type r, octave_idx_type c)
std::string row_as_string(octave_idx_type, bool strip_ws=false) const
Vector representing the dimensions (size) of an Array.
std::string str(char sep='x') const
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_idx_type numel() const
octave_idx_type rows() const
int current_print_indent_level() const
bool is_zero_by_zero() const
void warn_load(const char *type) const
virtual bool is_sq_string() const
friend class octave_value
void warn_save(const char *type) const
void short_disp(std::ostream &os) const
ComplexMatrix complex_matrix_value(bool=false) const
NDArray array_value(bool=false) const
std::string type_name() const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool load_ascii(std::istream &is)
Array< std::string > cellstr_value() const
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)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
octave_value resize(const dim_vector &dv, bool fill=false) const
string_vector string_vector_value(bool pad=false) const
Matrix matrix_value(bool=false) const
Complex complex_value(bool=false) const
bool save_ascii(std::ostream &os)
double double_value(bool=false) const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
octave_value do_index_op_internal(const octave_value_list &idx, bool resize_ok, char type='"')
ComplexNDArray complex_array_value(bool=false) const
std::string string_value(bool force=false) const
type_conv_info numeric_conversion_function() const
bool save_binary(std::ostream &os, bool save_as_floats)
charMatrix char_matrix_value(bool=false) const
charNDArray char_array_value(bool=false) const
static int static_type_id()
octave_idx_type length() const
void resize(octave_idx_type n, const std::string &rfv="")
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()
octave::idx_vector idx_vector
void skip_preceeding_newline(std::istream &is)
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)
std::string undo_string_escapes(const std::string &s)
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
#define CHAR_MATRIX_CONV(TNAME, FCN)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)