26 #if defined (HAVE_CONFIG_H)
42 #include "builtin-defun-decls.h"
72 return matrix.index (idx, resize_ok);
98 matrix.delete_elements (idx);
114 std::string dimstr = dv.
str ();
115 return "[" + dimstr +
" " + tname +
"]";
148 const std::list<octave_value_list>& idx,
161 if (idx.front ().empty ())
162 error (
"invalid empty index expression");
168 if (tcell.
numel () == 1)
181 error (
"%s cannot be indexed with %c", nm.c_str (),
type[0]);
201 const std::list<octave_value_list>& idx,
218 if (tcell.
numel () == 1)
231 error (
"%s cannot be indexed with %c", nm.c_str (),
type[0]);
251 const std::list<octave_value_list>& idx,
256 int n =
type.length ();
262 if (idx.front ().empty ())
263 error (
"missing index in indexed assignment");
289 std::list<octave_value_list> next_idx (idx);
291 next_idx.erase (next_idx.begin ());
305 std::list<octave_value_list> next_idx (idx);
307 next_idx.erase (next_idx.begin ());
309 std::string next_type =
type.substr (1);
311 if (tmpc.
numel () != 1)
326 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
335 error (
"%s cannot be indexed with %c", nm.c_str (),
type[0]);
380 tmp_cell = tmp_cell.
reshape (didx);
402 error (
"%s cannot be indexed with %c", nm.c_str (),
type[0]);
478 error (
"sort: only cell arrays of character strings may be sorted");
482 tmp = tmp.
sort (dim, mode);
497 error (
"sort: only cell arrays of character strings may be sorted");
501 tmp = tmp.
sort (sidx, dim, mode);
515 error (
"issorted: A is not a cell array of strings");
530 error (
"sortrows: only cell arrays of character strings may be sorted");
545 error (
"issorted: A is not a cell array of strings");
557 error (
"invalid conversion from cell array to logical value");
577 std::queue<string_vector> strvec_queue;
585 n_elts += s_len ? s_len : 1;
589 if (s_max_len > max_len)
592 strvec_queue.push (s);
610 std::string t = s[j];
611 int t_len = t.length ();
613 if (pad && max_len > t_len)
614 t += std::string (max_len - t_len,
' ');
620 retval[k++] = std::string (max_len,
' ');
632 error (
"invalid conversion from cell array to array of strings");
662 if (nr > 0 && nc > 0)
676 std::ostringstream buf;
677 buf <<
'[' << i+1 <<
',' << j+1 <<
']';
696 os <<
'(' << nr <<
'x' << nc <<
')';
704 os <<
'{' << dv.
str () <<
" Cell Array}";
734 #define CELL_ELT_TAG "<cell-element>"
742 os <<
"# ndims: " << dv.
ndims () <<
"\n";
744 for (
int i = 0; i < dv.
ndims (); i++)
765 os <<
"# rows: " <<
rows () <<
"\n"
766 <<
"# columns: " <<
columns () <<
"\n";
797 keywords[0] =
"ndims";
798 keywords[1] =
"rows";
804 error (
"load: failed to extract number of rows and columns");
808 int mdims =
static_cast<int> (val);
811 error (
"load: failed to extract number of rows and columns");
816 for (
int i = 0; i < mdims; i++)
831 error (
"load: cell array element had unexpected name");
838 error (
"load: failed to load matrix constant");
842 else if (kw ==
"rows")
848 error (
"load: failed to extract number of rows and columns for cell array");
850 if (nr > 0 && nc > 0)
866 error (
"load: cell array element had unexpected name");
869 tmp.
elem (i, j) = t2;
874 error (
"load: failed to load cell element");
878 else if (nr == 0 || nc == 0)
897 int32_t di = - dv.
ndims ();
898 os.write (
reinterpret_cast<char *
> (&di), 4);
899 for (
int i = 0; i < dv.
ndims (); i++)
902 os.write (
reinterpret_cast<char *
> (&di), 4);
929 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
941 for (
int i = 0; i < mdims; i++)
943 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
976 error (
"load: cell array element had unexpected name");
983 error (
"load: failed to load matrix constant");
1001 #if defined (HAVE_HDF5)
1008 hsize_t rank = dv.
ndims ();
1009 hid_t space_hid, data_hid, size_hid;
1010 space_hid = data_hid = size_hid = -1;
1012 #if defined (HAVE_HDF5_18)
1016 data_hid = H5Gcreate (loc_id,
name, 0);
1025 space_hid = H5Screate_simple (1, &rank,
nullptr);
1029 H5Gclose (data_hid);
1036 for (hsize_t i = 0; i < rank; i++)
1037 hdims[i] = dv(rank-i-1);
1039 #if defined (HAVE_HDF5_18)
1040 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1043 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1048 H5Sclose (space_hid);
1049 H5Gclose (data_hid);
1056 H5Dclose (size_hid);
1057 H5Sclose (space_hid);
1058 H5Gclose (data_hid);
1062 H5Dclose (size_hid);
1063 H5Sclose (space_hid);
1073 std::ostringstream buf;
1074 int digits =
static_cast<int> (
std::floor (::log10 (
static_cast<double>
1076 buf <<
'_' << std::setw (digits) << std::setfill (
'0') << i;
1077 std::string s = buf.str ();
1082 H5Gclose (data_hid);
1087 H5Gclose (data_hid);
1092 octave_unused_parameter (loc_id);
1093 octave_unused_parameter (
name);
1094 octave_unused_parameter (save_as_floats);
1107 #if defined (HAVE_HDF5)
1118 #if defined (HAVE_HDF5_18)
1121 hid_t group_id = H5Gopen (loc_id,
name);
1127 #if defined (HAVE_HDF5_18)
1130 hid_t data_hid = H5Dopen (group_id,
"dims");
1132 hid_t space_hid = H5Dget_space (data_hid);
1133 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1136 H5Dclose (data_hid);
1137 H5Gclose (group_id);
1144 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1155 H5Dclose (data_hid);
1156 H5Gclose (group_id);
1160 H5Dclose (data_hid);
1161 H5Gclose (group_id);
1163 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1168 herr_t retval2 = -1;
1172 int current_item = 0;
1174 hsize_t num_obj = 0;
1175 #if defined (HAVE_HDF5_18)
1178 group_id = H5Gopen (loc_id,
name);
1180 H5Gget_num_objs (group_id, &num_obj);
1181 H5Gclose (group_id);
1186 if (current_item >=
static_cast<int> (num_obj))
1206 octave_unused_parameter (loc_id);
1207 octave_unused_parameter (
name);
1215 DEFUN (iscell, args, ,
1222 if (args.length () != 1)
1225 return ovl (args(0).iscell ());
1228 DEFUN (cell, args, ,
1243 int nargin = args.length ();
1261 for (
int i = 0; i < nargin; i++)
1262 dims(i) = (args(i).isempty ()
1263 ? 0 : args(i).xidx_type_value (
"cell: dimension must be a scalar integer"));
1281 DEFUN (iscellstr, args, ,
1289 if (args.length () != 1)
1292 return ovl (args(0).iscellstr ());
1295 DEFUN (cellstr, args, ,
1308 if (args.length () != 1)
1314 return ovl (args(0));
1317 string_vector s = args(0).xstring_vector_value (
"cellstr: argument STRING must be a 2-D character array");
1324 DEFUN (struct2cell, args, ,
1359 if (args.length () != 1)
1362 const octave_map m = args(0).xmap_value (
"struct2cell: argument S must be a structure");
1373 if (m_dv(m_dv.
ndims () - 1) == 1)
1378 result_dv(0) = num_fields;
1380 for (
int i = 1; i < result_dv.
ndims (); i++)
1381 result_dv(i) = m_dv(i-1);
1391 c.
xelem (i,j) =
m.contents(i)(j);
1419 for (
mwIndex i = 0; i < nel; i++)
1430 #define FORWARD_MAPPER(UMAP) \
1431 case umap_ ## UMAP: \
1432 return matrix.UMAP ()
void swap_bytes< 4 >(void *ptr)
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Array< T > sort(int dim=0, sortmode mode=ASCENDING) const
Size of the specified dimension.
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
sortmode issorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
T & elem(octave_idx_type n)
Size of the specified dimension.
size_t byte_size(void) const
Size of the specified dimension.
const T * data(void) const
Size of the specified dimension.
octave_idx_type cols(void) const
octave_idx_type rows(void) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
int ndims(void) const
Size of the specified dimension.
void * mex_get_data(void) const
Give a pointer to the data in mex format.
bool isempty(void) const
Size of the specified dimension.
bool iscellstr(void) const
Cell reshape(const dim_vector &new_dims) const
Array< std::string > cellstr_value(void) const
Cell index(const octave_value_list &idx, bool resize_ok=false) const
string_vector string_vector_value(void) 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)
void chop_trailing_singletons(void)
octave_idx_type ndims(void) 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_idx_type numel(void) const
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
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
dim_vector dims(void) const
octave_idx_type columns(void) const
octave::refcount< octave_idx_type > count
void decrement_indent_level(void) const
void increment_indent_level(void) const
void indent(std::ostream &os) const
void newline(std::ostream &os) const
virtual octave_value map(unary_mapper_t) const
void warn_load(const char *type) const
octave_idx_type rows(void) const
virtual bool is_magic_colon(void) const
friend class octave_value
void warn_save(const char *type) const
mxArray * as_mxArray(void) const
Cell cell_value(void) const
bool print_as_scalar(void) const
size_t byte_size(void) 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
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
std::unique_ptr< Array< std::string > > cellstr_cache
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)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
void * mex_get_data(void) const
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 clear_cellstr_cache(void) const
sortmode issorted(sortmode mode=UNSORTED) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Array< std::string > cellstr_value(void) const
octave_value_list list_value(void) const
std::string type_name(void) 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)
bool iscellstr(void) const
octave_idx_type length(void) const
bool all_scalars(void) 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())
bool is_cs_list(void) const
bool is_defined(void) const
Cell cell_value(void) const
bool is_zero_by_zero(void) const
octave_value storable_value(void) const
octave_value_list list_value(void) const
std::string type_name(void) const
dim_vector dims(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_idx_type max_length(void) const
octave_idx_type numel(void) const
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
#define panic_impossible()
void err_nonbraced_cs_list_assignment(void)
void err_indexed_cs_list(void)
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)
std::complex< T > floor(const std::complex< T > &x)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
static void check_dimensions(octave_idx_type &nr, octave_idx_type &nc, const char *warnfor)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
OCTAVE_EXPORT octave_value_list Fiscellstr(const octave_value_list &args, int)
#define FORWARD_MAPPER(UMAP)
static int xisascii(int c)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
bool Vprint_empty_dimensions