69 return matrix.index (idx, resize_ok);
95 matrix.delete_elements (idx);
134 error (
"assignment to cell array failed");
139 const std::list<octave_value_list>& idx,
141 const std::list<octave_lvalue> *lvalue_list)
160 retval(0) = tcell(0,0);
170 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
183 retval = (lvalue_list
184 ? retval(0).next_subsref (nargout, type, idx, lvalue_list)
185 : retval(0).next_subsref (nargout, type, idx));
192 const std::list<octave_value_list>& idx,
222 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
242 const std::list<octave_value_list>& idx,
253 if (idx.front ().empty ())
255 error (
"missing index in indexed assignment");
274 return tmp.
subsasgn (type, idx, rhs);
285 std::list<octave_value_list> next_idx (idx);
287 next_idx.erase (next_idx.begin ());
291 t_rhs = tmp.
subsasgn (type.substr (1), next_idx, rhs);
304 std::list<octave_value_list> next_idx (idx);
306 next_idx.erase (next_idx.begin ());
308 std::string next_type = type.substr (1);
310 if (tmpc.
numel () == 1)
325 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
342 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
389 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel ();
391 if (didx.numel () == tmp_cell.
numel ())
392 tmp_cell = tmp_cell.
reshape (didx);
426 return tmp.
subsasgn (type, idx, rhs);
431 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
503 tmp = tmp.
sort (dim, mode);
509 error (
"sort: only cell arrays of character strings may be sorted");
524 tmp = tmp.
sort (sidx, dim, mode);
530 error (
"sort: only cell arrays of character strings may be sorted");
547 error (
"issorted: A is not a cell array of strings");
565 error (
"sortrows: only cell arrays of character strings may be sorted");
582 error (
"issorted: A is not a cell array of strings");
590 error (
"invalid conversion from cell array to logical value");
611 std::queue<string_vector> strvec_queue;
622 n_elts += s_len ? s_len : 1;
626 if (s_max_len > max_len)
629 strvec_queue.push (s);
647 std::string t = s[j];
650 if (pad && max_len > t_len)
651 t += std::string (max_len - t_len,
' ');
657 retval[k++] = std::string (max_len,
' ');
659 retval[k++] = std::string ();
678 error (
"invalid conversion from cell array to array of strings");
705 if (nr > 0 && nc > 0)
720 std::ostringstream buf;
721 buf <<
"[" << i+1 <<
"," << j+1 <<
"]";
740 os <<
"(" << nr <<
"x" << nc <<
")";
748 os <<
"{" << dv.
str () <<
" Cell Array}";
759 #define CELL_ELT_TAG "<cell-element>"
767 os <<
"# ndims: " << d.
length () <<
"\n";
769 for (
int i = 0; i < d.
length (); i++)
790 os <<
"# rows: " <<
rows () <<
"\n"
791 <<
"# columns: " <<
columns () <<
"\n";
824 keywords[0] =
"ndims";
825 keywords[1] =
"rows";
834 int mdims =
static_cast<int> (val);
841 for (
int i = 0; i < mdims; i++)
862 error (
"load: cell array element had unexpected name");
872 error (
"load: failed to load matrix constant");
878 error (
"load: failed to extract number of rows and columns");
882 else if (kw ==
"rows")
889 if (nr > 0 && nc > 0)
907 tmp.
elem (i, j) = t2;
911 error (
"load: cell array element had unexpected name");
913 goto cell_read_error;
924 error (
"load: failed to load cell element");
928 else if (nr == 0 || nc == 0)
935 error (
"load: failed to extract number of rows and columns for cell array");
944 error (
"load: failed to extract number of rows and columns");
959 int32_t di = - d.
length ();
960 os.write (reinterpret_cast<char *> (&di), 4);
961 for (
int i = 0; i < d.
length (); i++)
964 os.write (reinterpret_cast<char *> (&di), 4);
992 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
1004 for (
int i = 0; i < mdims; i++)
1006 if (! is.read (reinterpret_cast<char *> (&di), 4))
1045 error (
"load: cell array element had unexpected name");
1055 error (
"load: failed to load matrix constant");
1072 #if defined (HAVE_HDF5)
1079 hsize_t rank = dv.
length ();
1080 hid_t space_hid, data_hid, size_hid;
1081 space_hid = data_hid = size_hid = -1;
1084 data_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1086 data_hid = H5Gcreate (loc_id, name, 0);
1095 space_hid = H5Screate_simple (1, &rank, 0);
1099 H5Gclose (data_hid);
1106 for (hsize_t i = 0; i < rank; i++)
1107 hdims[i] = dv(rank-i-1);
1110 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1111 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1113 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1118 H5Sclose (space_hid);
1119 H5Gclose (data_hid);
1124 H5P_DEFAULT, hdims) < 0)
1126 H5Dclose (size_hid);
1127 H5Sclose (space_hid);
1128 H5Gclose (data_hid);
1132 H5Dclose (size_hid);
1133 H5Sclose (space_hid);
1143 std::ostringstream buf;
1144 int digits =
static_cast<int> (
gnulib::floor (::log10 (static_cast<double>
1146 buf <<
"_" << std::setw (digits) << std::setfill (
'0') << i;
1147 std::string s = buf.str ();
1152 H5Gclose (data_hid);
1157 H5Gclose (data_hid);
1170 bool retval =
false;
1172 #if defined (HAVE_HDF5)
1184 hid_t group_id = H5Gopen (loc_id, name, H5P_DEFAULT);
1186 hid_t group_id = H5Gopen (loc_id, name);
1193 hid_t data_hid = H5Dopen (group_id,
"dims", H5P_DEFAULT);
1195 hid_t data_hid = H5Dopen (group_id,
"dims");
1197 hid_t space_hid = H5Dget_space (data_hid);
1198 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1201 H5Dclose (data_hid);
1202 H5Gclose (group_id);
1209 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1218 H5P_DEFAULT, tmp) < 0)
1220 H5Dclose (data_hid);
1221 H5Gclose (group_id);
1225 H5Dclose (data_hid);
1226 H5Gclose (group_id);
1228 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1233 herr_t retval2 = -1;
1237 int current_item = 0;
1239 hsize_t num_obj = 0;
1241 group_id = H5Gopen (loc_id, name, H5P_DEFAULT);
1243 group_id = H5Gopen (loc_id, name);
1245 H5Gget_num_objs (group_id, &num_obj);
1246 H5Gclose (group_id);
1251 if (current_item >= static_cast<int> (num_obj))
1254 retval2 = H5Giterate (loc_id, name, ¤t_item,
1278 DEFUN (iscell, args, ,
1280 @deftypefn {Built-in Function} {} iscell (@var{x})\n\
1281 Return true if @var{x} is a cell array object.\n\
1282 @seealso{ismatrix, isstruct, iscellstr, isa}\n\
1287 if (args.length () == 1)
1295 DEFUN (cell, args, ,
1297 @deftypefn {Built-in Function} {} cell (@var{n})\n\
1298 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n})\n\
1299 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n}, @var{k}, @dots{})\n\
1300 @deftypefnx {Built-in Function} {} cell ([@var{m} @var{n} @dots{}])\n\
1301 Create a new cell array object.\n\
1303 If invoked with a single scalar integer argument, return a square\n\
1304 @nospell{NxN} cell array. If invoked with two or more scalar integer\n\
1305 arguments, or a vector of integer values, return an array with the given\n\
1307 @seealso{cellstr, mat2cell, num2cell, struct2cell}\n\
1312 int nargin = args.
length ();
1330 for (
int i = 0; i < nargin; i++)
1332 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value ();
1336 error (
"cell: expecting scalar arguments");
1357 DEFUN (iscellstr, args, ,
1359 @deftypefn {Built-in Function} {} iscellstr (@var{cell})\n\
1360 Return true if every element of the cell array @var{cell} is a character\n\
1367 if (args.length () == 1)
1380 DEFUN (cellstr, args, ,
1382 @deftypefn {Built-in Function} {@var{cstr} =} cellstr (@var{strmat})\n\
1383 Create a new cell array object from the elements of the string array\n\
1386 Each row of @var{strmat} becomes an element of @var{cstr}. Any trailing\n\
1387 spaces in a row are deleted before conversion.\n\
1389 To convert back from a cellstr to a character array use @code{char}.\n\
1390 @seealso{cell, char}\n\
1395 if (args.length () == 1)
1410 error (
"cellstr: argument STRING must be a 2-D character array");
1419 DEFUN (struct2cell, args, ,
1421 @deftypefn {Built-in Function} {@var{c} =} struct2cell (@var{s})\n\
1422 Create a new cell array from the objects stored in the struct object.\n\
1424 If @var{f} is the number of fields in the structure, the resulting cell\n\
1425 array will have a dimension vector corresponding to\n\
1426 @code{[@var{f} size(@var{s})]}. For example:\n\
1430 s = struct (\"name\", @{\"Peter\", \"Hannah\", \"Robert\"@},\n\
1431 \"age\", @{23, 16, 3@});\n\
1432 c = struct2cell (s)\n\
1433 @result{} c = @{2x1x3 Cell Array@}\n\
1451 @seealso{cell2struct, fieldnames}\n\
1456 int nargin = args.
length ();
1473 if (m_dv (m_dv.
length () - 1) == 1)
1478 result_dv(0) = num_fields;
1480 for (
int i = 1; i < result_dv.
length (); i++)
1481 result_dv(i) = m_dv(i-1);
1496 error (
"struct2cell: argument S must be a structure");
1527 for (
mwIndex i = 0; i < nel; i++)
1538 #define FORWARD_MAPPER(UMAP) \
1539 case umap_ ## UMAP: \
1540 return matrix.UMAP ()
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
octave_value map(unary_mapper_t umap) const
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
const Cell & contents(const_iterator p) const
bool is_true(const std::string &s)
bool is_empty(void) const
std::string str(char sep= 'x') const
bool save_ascii(std::ostream &os)
octave_refcount< octave_idx_type > count
const std::string & name(void) const
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
void increment_indent_level(void) const
octave_idx_type columns(void) const
Cell reshape(const dim_vector &new_dims) const
octave_idx_type max_length(void) const
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
void assign(const octave_value_list &idx, const MT &rhs)
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
void gripe_load(const char *type) const
static int xtoascii(int c)
octave_idx_type length(void) const
void delete_elements(const octave_value_list &idx)
void delete_elements(const octave_value_list &idx)
bool load_binary(std::istream &is, bool swap, oct_mach_info::float_format fmt)
bool is_defined(void) const
void * mex_get_data(void) const
Give a pointer to the data in mex format.
octave_idx_type numel(void) const
void resize(int n, int fill_value=0)
static void gripe_failed_assignment(void)
#define DEFUN(name, args_name, nargout_name, doc)
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
void error(const char *fmt,...)
Cell cell_value(void) const
void indent(std::ostream &os) const
void * get_data(void) const
#define FORWARD_MAPPER(UMAP)
std::auto_ptr< Array< std::string > > cellstr_cache
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
void gripe_save(const char *type) const
octave_value_list list_value(void) const
T & elem(octave_idx_type n)
octave_idx_type numel(void) const
herr_t hdf5_read_next_data(hid_t group_id, const char *name, void *dv)
OCTAVE_EXPORT octave_value_list Fiscellstr(const octave_value_list &args, int)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
void newline(std::ostream &os) const
bool is_empty(void) const
static void check_dimensions(octave_idx_type &nr, octave_idx_type &nc, const char *warnfor)
octave_idx_type rows(void) const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
F77_RET_T const double const double double * d
int load_hdf5_empty(hid_t loc_id, const char *name, dim_vector &d)
void gripe_indexed_cs_list(void)
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Cell cell_value(void) const
OCTAVE_EMPTY_CPP_ARG std::string type_name(void) const
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
void print(std::ostream &os, bool pr_as_read_syntax=false)
size_t byte_size(void) const
size_t byte_size(void) const
Array< std::string > cellstr_value(void) const
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
void swap_bytes< 4 >(void *ptr)
bool is_null_value(void) const
Array< T > sort(int dim=0, sortmode mode=ASCENDING) const
void gripe_nonbraced_cs_list_assignment(void)
octave_idx_type nfields(void) const
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
octave_idx_type numel(const octave_value_list &idx)
Array< std::string > cellstr_value(void) const
bool add_hdf5_data(hid_t loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
bool save_ascii_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_as_global, int precision)
const T * data(void) const
void resize(const dim_vector &dv, const T &rfv)
dim_vector dims(void) const
void clear_cellstr_cache(void) const
bool is_cellstr(void) const
#define panic_impossible()
std::string read_binary_data(std::istream &is, bool swap, oct_mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
dim_vector redim(int n) const
bool is_cellstr(void) const
octave_idx_type length(void) const
mxArray * as_mxArray(void) const
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
void * mex_get_data(void) const
void decrement_indent_level(void) const
friend class octave_value
dim_vector dims(void) const
sortmode is_sorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_idx_type length(void) const
Number of elements in the array.
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
This is a simple wrapper template that will subclass an Array type or any later type derived from ...
bool Vprint_empty_dimensions
string_vector all_strings(bool pad=false) const
bool print_as_scalar(void) const
bool save_binary(std::ostream &os, bool &save_as_floats)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
const octave_base_value & get_rep(void) const
bool is_cs_list(void) const
void print_with_name(std::ostream &os, const std::string &name) const
Cell index(const octave_value_list &idx, bool resize_ok=false) const
octave_value fast_elem_extract(octave_idx_type n) const
int save_hdf5_empty(hid_t loc_id, const char *name, const dim_vector d)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
virtual octave_value map(unary_mapper_t) const
bool is_cellstr(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
static const pair_type keywords[]
octave_value_list list_value(void) const
void assign(const octave_value_list &idx, const Cell &rhs)
std::complex< T > floor(const std::complex< T > &x)
void short_disp(std::ostream &os) const
bool all_scalars(void) const
octave_idx_type cols(void) const
bool load_ascii(std::istream &is)
sortmode is_sorted(sortmode mode=UNSORTED) const
octave_value storable_value(void) const
void chop_trailing_singletons(void)
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
bool is_zero_by_zero(void) const
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
octave_idx_type rows(void) const
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
F77_RET_T const double * x
static int xisascii(int c)
std::string read_ascii_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)