26 #if defined (HAVE_CONFIG_H)
73 return m_matrix.index (idx, resize_ok);
115 std::string dimstr = dv.
str ();
116 return "[" + dimstr +
" " + tname +
"]";
151 m_matrix(i).break_closure_cycles (frame);
168 error (
"invalid empty index expression {}, use {:} instead");
174 if (tcell.
numel () == 1)
175 retval(0) = tcell(0, 0);
187 error (
"%s cannot be indexed with %c", nm.c_str (), type);
200 const std::list<octave_value_list>& idx,
213 if (idx.front ().empty ())
214 error (
"invalid empty index expression {}, use {:} instead");
220 if (tcell.
numel () == 1)
221 retval(0) = tcell(0, 0);
233 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
246 retval = retval(0).next_subsref (nargout, type, idx);
253 const std::list<octave_value_list>& idx,
270 if (tcell.
numel () == 1)
271 retval = tcell(0, 0);
283 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
303 const std::list<octave_value_list>& idx,
308 int n = type.length ();
312 clear_cellstr_cache ();
314 if (idx.front ().empty ())
315 error (
"missing index in indexed assignment");
323 if (
isempty () && type[1] ==
'.')
332 return tmp.
subsasgn (type, idx, rhs);
341 std::list<octave_value_list> next_idx (idx);
343 next_idx.erase (next_idx.begin ());
347 t_rhs = tmp.
subsasgn (type.substr (1), next_idx, rhs);
357 std::list<octave_value_list> next_idx (idx);
359 next_idx.erase (next_idx.begin ());
361 std::string next_type = type.substr (1);
363 if (tmpc.
numel () != 1)
378 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
387 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
432 tmp_cell = tmp_cell.
reshape (didx);
454 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
464 return tmp.
subsasgn (type, idx, rhs);
479 if (m_cellstr_cache.get ())
495 clear_cellstr_cache ();
502 clear_cellstr_cache ();
509 clear_cellstr_cache ();
516 std::size_t retval = 0;
530 error (
"sort: only cell arrays of character strings may be sorted");
534 tmp = tmp.
sort (dim, mode);
549 error (
"sort: only cell arrays of character strings may be sorted");
553 tmp = tmp.
sort (sidx, dim, mode);
567 error (
"issorted: A is not a cell array of strings");
582 error (
"sortrows: only cell arrays of character strings may be sorted");
597 error (
"issorted: A is not a cell array of strings");
609 error (
"invalid conversion from cell array to logical value");
629 std::queue<string_vector> strvec_queue;
637 n_elts += s_len ? s_len : 1;
641 if (s_max_len > max_len)
644 strvec_queue.push (s);
662 std::string t = s[j];
663 int t_len = t.length ();
665 if (pad && max_len > t_len)
666 t += std::string (max_len - t_len,
' ');
672 retval[k++] = std::string (max_len,
' ');
684 error (
"invalid conversion from cell array to array of strings");
686 if (m_cellstr_cache->isempty ())
689 return *m_cellstr_cache;
714 if (nr > 0 && nc > 0)
728 std::ostringstream buf;
729 buf <<
'[' << i+1 <<
',' << j+1 <<
']';
748 os <<
'(' << nr <<
'x' << nc <<
')';
756 os <<
'{' << dv.
str () <<
" Cell Array}";
786 #define CELL_ELT_TAG "<cell-element>"
794 os <<
"# ndims: " << dv.
ndims () <<
"\n";
796 for (
int i = 0; i < dv.
ndims (); i++)
817 os <<
"# rows: " <<
rows () <<
"\n"
818 <<
"# columns: " <<
columns () <<
"\n";
845 clear_cellstr_cache ();
849 keywords[0] =
"ndims";
850 keywords[1] =
"rows";
856 error (
"load: failed to extract number of rows and columns");
860 int mdims =
static_cast<int> (val);
863 error (
"load: failed to extract number of rows and columns");
868 for (
int i = 0; i < mdims; i++)
883 error (
"load: cell array element had unexpected name");
890 error (
"load: failed to load matrix constant");
894 else if (kw ==
"rows")
900 error (
"load: failed to extract number of rows and columns for cell array");
902 if (nr > 0 && nc > 0)
918 error (
"load: cell array element had unexpected name");
921 tmp.
elem (i, j) = t2;
926 error (
"load: failed to load cell element");
930 else if (nr == 0 || nc == 0)
949 int32_t di = - dv.
ndims ();
950 os.write (
reinterpret_cast<char *
> (&di), 4);
951 for (
int i = 0; i < dv.
ndims (); i++)
954 os.write (
reinterpret_cast<char *
> (&di), 4);
978 clear_cellstr_cache ();
981 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
993 for (
int i = 0; i < mdims; i++)
995 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
1028 error (
"load: cell array element had unexpected name");
1035 error (
"load: failed to load matrix constant");
1045 clear_cellstr_cache ();
1051 bool save_as_floats)
1053 #if defined (HAVE_HDF5)
1060 hsize_t rank = dv.
ndims ();
1061 hid_t space_hid, data_hid, size_hid;
1062 space_hid = data_hid = size_hid = -1;
1064 #if defined (HAVE_HDF5_18)
1068 data_hid = H5Gcreate (loc_id, name, 0);
1077 space_hid = H5Screate_simple (1, &rank,
nullptr);
1081 H5Gclose (data_hid);
1088 for (hsize_t i = 0; i < rank; i++)
1089 hdims[i] = dv(rank-i-1);
1091 #if defined (HAVE_HDF5_18)
1092 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1096 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1101 H5Sclose (space_hid);
1102 H5Gclose (data_hid);
1109 H5Dclose (size_hid);
1110 H5Sclose (space_hid);
1111 H5Gclose (data_hid);
1115 H5Dclose (size_hid);
1116 H5Sclose (space_hid);
1126 std::ostringstream buf;
1127 int digits =
static_cast<int> (
std::floor (::log10 (
static_cast<double>
1129 buf <<
'_' << std::setw (digits) << std::setfill (
'0') << i;
1130 std::string s = buf.str ();
1135 H5Gclose (data_hid);
1140 H5Gclose (data_hid);
1145 octave_unused_parameter (loc_id);
1146 octave_unused_parameter (name);
1147 octave_unused_parameter (save_as_floats);
1158 bool retval =
false;
1160 #if defined (HAVE_HDF5)
1162 clear_cellstr_cache ();
1171 #if defined (HAVE_HDF5_18)
1174 hid_t group_id = H5Gopen (loc_id, name);
1180 #if defined (HAVE_HDF5_18)
1183 hid_t data_hid = H5Dopen (group_id,
"dims");
1185 hid_t space_hid = H5Dget_space (data_hid);
1186 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1189 H5Dclose (data_hid);
1190 H5Gclose (group_id);
1197 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1208 H5Dclose (data_hid);
1209 H5Gclose (group_id);
1213 H5Dclose (data_hid);
1214 H5Gclose (group_id);
1216 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1221 herr_t retval2 = -1;
1225 int current_item = 0;
1227 hsize_t num_obj = 0;
1228 #if defined (HAVE_HDF5_18)
1231 group_id = H5Gopen (loc_id, name);
1233 H5Gget_num_objs (group_id, &num_obj);
1234 H5Gclose (group_id);
1239 if (current_item >=
static_cast<int> (num_obj))
1259 octave_unused_parameter (loc_id);
1260 octave_unused_parameter (name);
1270 DEFUN (iscell, args, ,
1277 if (args.length () != 1)
1280 return ovl (args(0).iscell ());
1283 DEFUN (cell, args, ,
1298 int nargin = args.length ();
1309 if (args(0).iscell ())
1319 for (
int i = 0; i < nargin; i++)
1320 dims(i) = (args(i).isempty ()
1321 ? 0 : args(i).xidx_type_value (
"cell: dimension must be a scalar integer"));
1350 DEFUN (iscellstr, args, ,
1358 if (args.length () != 1)
1361 return ovl (args(0).iscellstr ());
1364 DEFUN (cellstr, args, ,
1377 if (args.length () != 1)
1383 return ovl (args(0));
1386 string_vector s = args(0).xstring_vector_value (
"cellstr: argument STRING must be a 2-D character array");
1393 DEFUN (struct2cell, args, ,
1428 if (args.length () != 1)
1431 const octave_map m = args(0).xmap_value (
"struct2cell: argument S must be a structure");
1442 if (m_dv(m_dv.
ndims () - 1) == 1)
1447 result_dv(0) = num_fields;
1449 for (
int i = 1; i < result_dv.
ndims (); i++)
1450 result_dv(i) = m_dv(i-1);
1460 c.
xelem (i, j) =
m.contents(i)(j);
1477 OCTAVE_END_NAMESPACE(
octave)
1490 for (
mwIndex i = 0; i < nel; i++)
1491 elts[i] =
new mxArray (interleaved, p[i]);
1501 #define FORWARD_MAPPER(UMAP) \
1502 case umap_ ## UMAP: \
1503 return m_matrix.UMAP ()
void swap_bytes< 4 >(void *ptr)
T & elem(octave_idx_type n)
Size of the specified dimension.
std::size_t byte_size() const
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.
const T * data() const
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.
bool isempty() const
Size of the specified dimension.
sortmode issorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
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.
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 ().
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
virtual void assign(const std::string &, const octave_value &)
void delete_elements(const octave_value_list &idx)
octave_value fast_elem_extract(octave_idx_type n) const
octave_idx_type numel() const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
octave_idx_type rows() const
octave_idx_type columns() 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
virtual void assign(const std::string &, const octave_value &)
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
sortmode issorted(sortmode mode=UNSORTED) const
mxArray * as_mxArray(bool interleaved) const
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 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
std::string type_name() 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,...)
#define panic_impossible()
void err_indexed_cs_list()
void err_nonbraced_cs_list_assignment()
std::complex< T > floor(const std::complex< T > &x)
F77_RET_T const F77_DBLE * x
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)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
#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 check_dimensions(dim_vector &dim, const char *warnfor)