26#if defined (HAVE_CONFIG_H)
43#include "builtin-defun-decls.h"
71 m_matrix(i).break_closure_cycles (frame);
88 error (
"invalid empty index expression {}, use {:} instead");
94 if (tcell.
numel () == 1)
95 retval(0) = tcell(0, 0);
107 error (
"%s cannot be indexed with %c", nm.c_str (), type);
112 error (
"unexpected: index not '(', '{', or '.' in octave_cell::simple_subsref - please report this bug");
120 const std::list<octave_value_list>& idx,
133 if (idx.front ().empty ())
134 error (
"invalid empty index expression {}, use {:} instead");
140 if (tcell.
numel () == 1)
141 retval(0) = tcell(0, 0);
153 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
158 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsref - please report this bug");
166 retval = retval(0).next_subsref (nargout, type, idx);
173 const std::list<octave_value_list>& idx,
190 if (tcell.
numel () == 1)
191 retval = tcell(0, 0);
203 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
208 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsref - please report this bug");
223 const std::list<octave_value_list>& idx,
232 clear_cellstr_cache ();
234 if (idx.front ().empty ())
235 error (
"missing index in indexed assignment");
243 if (
isempty () && type[1] ==
'.')
252 return tmp.
subsasgn (type, idx, rhs);
261 std::list<octave_value_list> next_idx (std::next (idx.begin ()), idx.end ());
265 t_rhs = tmp.
subsasgn (type.substr (1), next_idx, rhs);
275 std::list<octave_value_list> next_idx (std::next (idx.begin ()), idx.end ());
277 std::string next_type = type.substr (1);
279 if (tmpc.
numel () != 1)
294 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
303 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
311 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsasgn - please report this bug");
348 tmp_cell = tmp_cell.
reshape (didx);
370 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
380 return tmp.
subsasgn (type, idx, rhs);
385 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsasgn - please report this bug");
395 if (m_cellstr_cache.get ())
411 clear_cellstr_cache ();
418 clear_cellstr_cache ();
425 clear_cellstr_cache ();
432 std::size_t retval = 0;
446 error (
"sort: only cell arrays of character strings may be sorted");
450 tmp = tmp.
sort (dim, mode);
465 error (
"sort: only cell arrays of character strings may be sorted");
469 tmp = tmp.
sort (sidx, dim, mode);
483 error (
"issorted: A is not a cell array of strings");
498 error (
"sortrows: only cell arrays of character strings may be sorted");
513 error (
"issorted: A is not a cell array of strings");
525 error (
"invalid conversion from cell array to logical value");
545 std::queue<string_vector> strvec_queue;
553 n_elts += s_len ? s_len : 1;
557 if (s_max_len > max_len)
560 strvec_queue.push (s);
578 std::string t = s[j];
579 int t_len = t.length ();
581 if (pad && max_len > t_len)
582 t += std::string (max_len - t_len,
' ');
588 retval[k++] = std::string (max_len,
' ');
600 error (
"invalid conversion from cell array to array of strings");
602 if (m_cellstr_cache->isempty ())
605 return *m_cellstr_cache;
630 if (nr > 0 && nc > 0)
644 std::ostringstream buf;
645 buf <<
'[' << i+1 <<
',' << j+1 <<
']';
664 os <<
'(' << nr <<
'x' << nc <<
')';
672 os <<
'{' << dv.
str () <<
" Cell Array}";
705#define CELL_ELT_TAG "<cell-element>"
713 os <<
"# ndims: " << dv.
ndims () <<
"\n";
715 for (
int i = 0; i < dv.
ndims (); i++)
736 os <<
"# rows: " <<
rows () <<
"\n"
737 <<
"# columns: " <<
columns () <<
"\n";
764 clear_cellstr_cache ();
768 keywords[0] =
"ndims";
769 keywords[1] =
"rows";
775 error (
"load: failed to extract number of rows and columns");
779 int mdims =
static_cast<int> (val);
782 error (
"load: failed to extract number of rows and columns");
787 for (
int i = 0; i < mdims; i++)
802 error (
"load: cell array element had unexpected name");
809 error (
"load: failed to load matrix constant");
813 else if (kw ==
"rows")
819 error (
"load: failed to extract number of rows and columns for cell array");
821 if (nr > 0 && nc > 0)
837 error (
"load: cell array element had unexpected name");
840 tmp.
elem (i, j) = t2;
845 error (
"load: failed to load cell element");
849 else if (nr == 0 || nc == 0)
852 error (
"unexpected dimensions in octave_cell::load_ascii - please report this bug");
855 error (
"unexpected dimensions keyword (= '%s') octave_cell::load_ascii - please report this bug", kw.c_str ());
868 int32_t di = - dv.
ndims ();
869 os.write (
reinterpret_cast<char *
> (&di), 4);
870 for (
int i = 0; i < dv.
ndims (); i++)
873 os.write (
reinterpret_cast<char *
> (&di), 4);
895 octave::mach_info::float_format fmt)
897 clear_cellstr_cache ();
900 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
912 for (
int i = 0; i < mdims; i++)
914 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
947 error (
"load: cell array element had unexpected name");
954 error (
"load: failed to load matrix constant");
964 clear_cellstr_cache ();
972#if defined (HAVE_HDF5)
979 hsize_t rank = dv.
ndims ();
980 hid_t space_hid, data_hid, size_hid;
981 space_hid = data_hid = size_hid = -1;
983#if defined (HAVE_HDF5_18)
987 data_hid = H5Gcreate (loc_id, name, 0);
996 space_hid = H5Screate_simple (1, &rank,
nullptr);
1000 H5Gclose (data_hid);
1007 for (hsize_t i = 0; i < rank; i++)
1008 hdims[i] = dv(rank-i-1);
1010#if defined (HAVE_HDF5_18)
1011 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1015 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1020 H5Sclose (space_hid);
1021 H5Gclose (data_hid);
1028 H5Dclose (size_hid);
1029 H5Sclose (space_hid);
1030 H5Gclose (data_hid);
1034 H5Dclose (size_hid);
1035 H5Sclose (space_hid);
1045 std::ostringstream buf;
1046 int digits =
static_cast<int> (std::floor (::log10 (
static_cast<double>
1048 buf <<
'_' << std::setw (digits) << std::setfill (
'0') << i;
1049 std::string s = buf.str ();
1054 H5Gclose (data_hid);
1059 H5Gclose (data_hid);
1064 octave_unused_parameter (loc_id);
1065 octave_unused_parameter (name);
1066 octave_unused_parameter (save_as_floats);
1077 bool retval =
false;
1079#if defined (HAVE_HDF5)
1081 clear_cellstr_cache ();
1090#if defined (HAVE_HDF5_18)
1093 hid_t group_id = H5Gopen (loc_id, name);
1099#if defined (HAVE_HDF5_18)
1102 hid_t data_hid = H5Dopen (group_id,
"dims");
1104 hid_t space_hid = H5Dget_space (data_hid);
1105 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1108 H5Dclose (data_hid);
1109 H5Gclose (group_id);
1116 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1127 H5Dclose (data_hid);
1128 H5Gclose (group_id);
1132 H5Dclose (data_hid);
1133 H5Gclose (group_id);
1135 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1140 herr_t retval2 = -1;
1144 int current_item = 0;
1146 hsize_t num_obj = 0;
1147#if defined (HAVE_HDF5_18)
1150 group_id = H5Gopen (loc_id, name);
1152 H5Gget_num_objs (group_id, &num_obj);
1153 H5Gclose (group_id);
1158 if (current_item >=
static_cast<int> (num_obj))
1178 octave_unused_parameter (loc_id);
1179 octave_unused_parameter (name);
1189DEFUN (iscell, args, ,
1196 if (args.length () != 1)
1199 return ovl (args(0).iscell ());
1217 int nargin = args.length ();
1228 if (args(0).iscell ())
1238 for (
int i = 0; i < nargin; i++)
1239 dims(i) = (args(i).isempty ()
1240 ? 0 : args(i).strict_idx_type_value (
"cell: dimension must be a scalar integer"));
1269DEFUN (iscellstr, args, ,
1277 if (args.length () != 1)
1280 return ovl (args(0).iscellstr ());
1283DEFUN (cellstr, args, ,
1296 if (args.length () != 1)
1302 return ovl (args(0));
1305 string_vector s = args(0).xstring_vector_value (
"cellstr: argument STRING must be a 2-D character array");
1312DEFUN (struct2cell, args, ,
1347 if (args.length () != 1)
1350 const octave_map m = args(0).xmap_value (
"struct2cell: argument S must be a structure");
1361 if (m_dv(m_dv.
ndims () - 1) == 1)
1366 result_dv(0) = num_fields;
1368 for (
int i = 1; i < result_dv.
ndims (); i++)
1369 result_dv(i) = m_dv(i-1);
1396OCTAVE_END_NAMESPACE(octave)
1405 mwSize nel =
numel ();
1409 for (mwIndex i = 0; i < nel; i++)
1410 elts[i] =
new mxArray (interleaved, p[i]);
1420#define FORWARD_MAPPER(UMAP) \
1421 case umap_ ## UMAP: \
1422 return m_matrix.UMAP ()
void swap_bytes< 4 >(void *ptr)
N Dimensional Array with copy-on-write semantics.
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.
std::size_t byte_size() const
Size of the specified dimension.
T & elem(octave_idx_type n)
Size of the specified dimension.
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.
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
octave_idx_type cols() const
Array< T, Alloc > sort(int dim=0, sortmode mode=ASCENDING) const
Size of the specified dimension.
const T * data() const
Size of the specified dimension.
sortmode issorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
octave_idx_type numel() const
Number of elements in the array.
Cell reshape(const dim_vector &new_dims) const
Cell index(const octave_value_list &idx, bool resize_ok=false) const
Array< std::string > cellstr_value() const
string_vector string_vector_value() 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 chop_trailing_singletons()
void resize(int n, int fill_value=0)
octave_idx_type ndims() const
Number of dimensions.
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
void delete_elements(const octave_value_list &idx)
octave_idx_type numel() const
void assign(const octave_value_list &idx, const MT &rhs)
octave_idx_type rows() const
octave_idx_type columns() const
virtual void short_disp(std::ostream &os) const
void increment_indent_level() const
void indent(std::ostream &os) const
void newline(std::ostream &os) const
virtual octave_value map(unary_mapper_t) const
octave::refcount< octave_idx_type > m_count
void warn_load(const char *type) const
virtual bool is_magic_colon() const
void decrement_indent_level() const
friend class octave_value
void warn_save(const char *type) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
void short_disp(std::ostream &os) const
octave_value map(unary_mapper_t umap) const
std::size_t byte_size() const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
bool print_as_scalar() const
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
const void * mex_get_data() const
Array< std::string > cellstr_value() const
bool save_binary(std::ostream &os, bool save_as_floats)
bool print_name_tag(std::ostream &os, const std::string &name) const
bool save_ascii(std::ostream &os)
std::string type_name() const
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_value_list simple_subsref(char type, octave_value_list &idx, int nargout)
void break_closure_cycles(const std::shared_ptr< octave::stack_frame > &frame)
void delete_elements(const octave_value_list &idx)
bool load_ascii(std::istream &is)
string_vector string_vector_value(bool pad=false) const
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
void assign(const octave_value_list &idx, const Cell &rhs)
sortmode issorted(sortmode mode=UNSORTED) const
mxArray * as_mxArray(bool interleaved) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_value_list list_value() const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
octave_idx_type nfields() const
const Cell & contents(const_iterator p) const
octave_idx_type numel() const
octave_idx_type length() const
octave_value_list list_value() const
void print_with_name(std::ostream &os, const std::string &name) const
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, std::size_t skip=1)
octave_value storable_value() const
bool is_zero_by_zero() const
octave_idx_type length() const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_idx_type max_length() const
octave_idx_type numel() const
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
void err_indexed_cs_list()
void err_nonbraced_cs_list_assignment()
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)
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc_in, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
bool save_binary_data(std::ostream &os, const octave_value &tc_in, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count, const bool do_name_validation)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
bool is_true(const std::string &s)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
octave_value_list Fiscellstr(const octave_value_list &args, int)
#define FORWARD_MAPPER(UMAP)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
bool Vprint_empty_dimensions
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
void check_dimensions(dim_vector &dim, const char *warnfor)