26#if defined (HAVE_CONFIG_H)
42#include "builtin-defun-decls.h"
70 m_matrix(i).break_closure_cycles (frame);
87 error (
"invalid empty index expression {}, use {:} instead");
93 if (tcell.
numel () == 1)
94 retval(0) = tcell(0, 0);
106 error (
"%s cannot be indexed with %c", nm.c_str (), type);
111 error (
"unexpected: index not '(', '{', or '.' in octave_cell::simple_subsref - please report this bug");
119 const std::list<octave_value_list>& idx,
132 if (idx.front ().empty ())
133 error (
"invalid empty index expression {}, use {:} instead");
139 if (tcell.
numel () == 1)
140 retval(0) = tcell(0, 0);
152 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
157 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsref - please report this bug");
165 retval = retval(0).next_subsref (nargout, type, idx);
172 const std::list<octave_value_list>& idx,
189 if (tcell.
numel () == 1)
190 retval = tcell(0, 0);
202 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
207 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsref - please report this bug");
222 const std::list<octave_value_list>& idx,
231 clear_cellstr_cache ();
233 if (idx.front ().empty ())
234 error (
"missing index in indexed assignment");
242 if (
isempty () && type[1] ==
'.')
251 return tmp.
subsasgn (type, idx, rhs);
260 std::list<octave_value_list> next_idx (idx);
262 next_idx.erase (next_idx.begin ());
266 t_rhs = tmp.
subsasgn (type.substr (1), next_idx, rhs);
276 std::list<octave_value_list> next_idx (idx);
278 next_idx.erase (next_idx.begin ());
280 std::string next_type = type.substr (1);
282 if (tmpc.
numel () != 1)
297 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
306 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
314 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsasgn - please report this bug");
351 tmp_cell = tmp_cell.
reshape (didx);
373 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
383 return tmp.
subsasgn (type, idx, rhs);
388 error (
"unexpected: index not '(', '{', or '.' in octave_cell::subsasgn - please report this bug");
398 if (m_cellstr_cache.get ())
414 clear_cellstr_cache ();
421 clear_cellstr_cache ();
428 clear_cellstr_cache ();
435 std::size_t retval = 0;
449 error (
"sort: only cell arrays of character strings may be sorted");
453 tmp = tmp.
sort (dim, mode);
468 error (
"sort: only cell arrays of character strings may be sorted");
472 tmp = tmp.
sort (sidx, dim, mode);
486 error (
"issorted: A is not a cell array of strings");
501 error (
"sortrows: only cell arrays of character strings may be sorted");
516 error (
"issorted: A is not a cell array of strings");
528 error (
"invalid conversion from cell array to logical value");
548 std::queue<string_vector> strvec_queue;
556 n_elts += s_len ? s_len : 1;
560 if (s_max_len > max_len)
563 strvec_queue.push (s);
581 std::string t = s[j];
582 int t_len = t.length ();
584 if (pad && max_len > t_len)
585 t += std::string (max_len - t_len,
' ');
591 retval[k++] = std::string (max_len,
' ');
603 error (
"invalid conversion from cell array to array of strings");
605 if (m_cellstr_cache->isempty ())
608 return *m_cellstr_cache;
633 if (nr > 0 && nc > 0)
647 std::ostringstream buf;
648 buf <<
'[' << i+1 <<
',' << j+1 <<
']';
667 os <<
'(' << nr <<
'x' << nc <<
')';
675 os <<
'{' << dv.
str () <<
" Cell Array}";
708#define CELL_ELT_TAG "<cell-element>"
716 os <<
"# ndims: " << dv.
ndims () <<
"\n";
718 for (
int i = 0; i < dv.
ndims (); i++)
739 os <<
"# rows: " <<
rows () <<
"\n"
740 <<
"# columns: " <<
columns () <<
"\n";
767 clear_cellstr_cache ();
771 keywords[0] =
"ndims";
772 keywords[1] =
"rows";
778 error (
"load: failed to extract number of rows and columns");
782 int mdims =
static_cast<int> (val);
785 error (
"load: failed to extract number of rows and columns");
790 for (
int i = 0; i < mdims; i++)
805 error (
"load: cell array element had unexpected name");
812 error (
"load: failed to load matrix constant");
816 else if (kw ==
"rows")
822 error (
"load: failed to extract number of rows and columns for cell array");
824 if (nr > 0 && nc > 0)
840 error (
"load: cell array element had unexpected name");
843 tmp.
elem (i, j) = t2;
848 error (
"load: failed to load cell element");
852 else if (nr == 0 || nc == 0)
855 error (
"unexpected dimensions in octave_cell::load_ascii - please report this bug");
858 error (
"unexpected dimensions keyword (= '%s') octave_cell::load_ascii - please report this bug", kw.c_str ());
871 int32_t di = - dv.
ndims ();
872 os.write (
reinterpret_cast<char *
> (&di), 4);
873 for (
int i = 0; i < dv.
ndims (); i++)
876 os.write (
reinterpret_cast<char *
> (&di), 4);
898 octave::mach_info::float_format fmt)
900 clear_cellstr_cache ();
903 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
915 for (
int i = 0; i < mdims; i++)
917 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
950 error (
"load: cell array element had unexpected name");
957 error (
"load: failed to load matrix constant");
967 clear_cellstr_cache ();
975#if defined (HAVE_HDF5)
982 hsize_t rank = dv.
ndims ();
983 hid_t space_hid, data_hid, size_hid;
984 space_hid = data_hid = size_hid = -1;
986#if defined (HAVE_HDF5_18)
990 data_hid = H5Gcreate (loc_id, name, 0);
999 space_hid = H5Screate_simple (1, &rank,
nullptr);
1003 H5Gclose (data_hid);
1010 for (hsize_t i = 0; i < rank; i++)
1011 hdims[i] = dv(rank-i-1);
1013#if defined (HAVE_HDF5_18)
1014 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1018 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1023 H5Sclose (space_hid);
1024 H5Gclose (data_hid);
1031 H5Dclose (size_hid);
1032 H5Sclose (space_hid);
1033 H5Gclose (data_hid);
1037 H5Dclose (size_hid);
1038 H5Sclose (space_hid);
1048 std::ostringstream buf;
1049 int digits =
static_cast<int> (std::floor (::log10 (
static_cast<double>
1051 buf <<
'_' << std::setw (digits) << std::setfill (
'0') << i;
1052 std::string s = buf.str ();
1057 H5Gclose (data_hid);
1062 H5Gclose (data_hid);
1067 octave_unused_parameter (loc_id);
1068 octave_unused_parameter (name);
1069 octave_unused_parameter (save_as_floats);
1080 bool retval =
false;
1082#if defined (HAVE_HDF5)
1084 clear_cellstr_cache ();
1093#if defined (HAVE_HDF5_18)
1096 hid_t group_id = H5Gopen (loc_id, name);
1102#if defined (HAVE_HDF5_18)
1105 hid_t data_hid = H5Dopen (group_id,
"dims");
1107 hid_t space_hid = H5Dget_space (data_hid);
1108 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1111 H5Dclose (data_hid);
1112 H5Gclose (group_id);
1119 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1130 H5Dclose (data_hid);
1131 H5Gclose (group_id);
1135 H5Dclose (data_hid);
1136 H5Gclose (group_id);
1138 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1143 herr_t retval2 = -1;
1147 int current_item = 0;
1149 hsize_t num_obj = 0;
1150#if defined (HAVE_HDF5_18)
1153 group_id = H5Gopen (loc_id, name);
1155 H5Gget_num_objs (group_id, &num_obj);
1156 H5Gclose (group_id);
1161 if (current_item >=
static_cast<int> (num_obj))
1181 octave_unused_parameter (loc_id);
1182 octave_unused_parameter (name);
1192DEFUN (iscell, args, ,
1199 if (args.length () != 1)
1202 return ovl (args(0).iscell ());
1220 int nargin = args.length ();
1231 if (args(0).iscell ())
1241 for (
int i = 0; i < nargin; i++)
1242 dims(i) = (args(i).isempty ()
1243 ? 0 : args(i).strict_idx_type_value (
"cell: dimension must be a scalar integer"));
1272DEFUN (iscellstr, args, ,
1280 if (args.length () != 1)
1283 return ovl (args(0).iscellstr ());
1286DEFUN (cellstr, args, ,
1299 if (args.length () != 1)
1305 return ovl (args(0));
1308 string_vector s = args(0).xstring_vector_value (
"cellstr: argument STRING must be a 2-D character array");
1315DEFUN (struct2cell, args, ,
1350 if (args.length () != 1)
1353 const octave_map m = args(0).xmap_value (
"struct2cell: argument S must be a structure");
1364 if (m_dv(m_dv.
ndims () - 1) == 1)
1369 result_dv(0) = num_fields;
1371 for (
int i = 1; i < result_dv.
ndims (); i++)
1372 result_dv(i) = m_dv(i-1);
1399OCTAVE_END_NAMESPACE(octave)
1408 mwSize nel =
numel ();
1412 for (mwIndex i = 0; i < nel; i++)
1413 elts[i] =
new mxArray (interleaved, p[i]);
1423#define FORWARD_MAPPER(UMAP) \
1424 case umap_ ## UMAP: \
1425 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)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
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, 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)