26 #if defined (HAVE_CONFIG_H)
42 #include "builtin-defun-decls.h"
73 return m_matrix.index (idx, resize_ok);
115 std::string dimstr = dv.
str ();
116 return "[" + dimstr +
" " + tname +
"]";
150 m_matrix(i).break_closure_cycles (frame);
155 const std::list<octave_value_list>& idx,
168 if (idx.front ().empty ())
169 error (
"invalid empty index expression {}, use {:} instead");
175 if (tcell.
numel () == 1)
176 retval(0) = tcell(0, 0);
188 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
201 retval = retval(0).next_subsref (nargout, type, idx);
208 const std::list<octave_value_list>& idx,
225 if (tcell.
numel () == 1)
226 retval = tcell(0, 0);
238 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
258 const std::list<octave_value_list>& idx,
263 int n = type.length ();
269 if (idx.front ().empty ())
270 error (
"missing index in indexed assignment");
278 if (
isempty () && type[1] ==
'.')
287 return tmp.
subsasgn (type, idx, rhs);
296 std::list<octave_value_list> next_idx (idx);
298 next_idx.erase (next_idx.begin ());
302 t_rhs = tmp.
subsasgn (type.substr (1), next_idx, rhs);
312 std::list<octave_value_list> next_idx (idx);
314 next_idx.erase (next_idx.begin ());
316 std::string next_type = type.substr (1);
318 if (tmpc.
numel () != 1)
333 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
342 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
387 tmp_cell = tmp_cell.
reshape (didx);
409 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
419 return tmp.
subsasgn (type, idx, rhs);
471 std::size_t retval = 0;
485 error (
"sort: only cell arrays of character strings may be sorted");
489 tmp = tmp.
sort (dim, mode);
504 error (
"sort: only cell arrays of character strings may be sorted");
508 tmp = tmp.
sort (sidx, dim, mode);
522 error (
"issorted: A is not a cell array of strings");
537 error (
"sortrows: only cell arrays of character strings may be sorted");
552 error (
"issorted: A is not a cell array of strings");
564 error (
"invalid conversion from cell array to logical value");
584 std::queue<string_vector> strvec_queue;
592 n_elts += s_len ? s_len : 1;
596 if (s_max_len > max_len)
599 strvec_queue.push (s);
617 std::string t = s[j];
618 int t_len = t.length ();
620 if (pad && max_len > t_len)
621 t += std::string (max_len - t_len,
' ');
627 retval[k++] = std::string (max_len,
' ');
639 error (
"invalid conversion from cell array to array of strings");
669 if (nr > 0 && nc > 0)
683 std::ostringstream buf;
684 buf <<
'[' << i+1 <<
',' << j+1 <<
']';
703 os <<
'(' << nr <<
'x' << nc <<
')';
711 os <<
'{' << dv.
str () <<
" Cell Array}";
741 #define CELL_ELT_TAG "<cell-element>"
749 os <<
"# ndims: " << dv.
ndims () <<
"\n";
751 for (
int i = 0; i < dv.
ndims (); i++)
772 os <<
"# rows: " <<
rows () <<
"\n"
773 <<
"# columns: " <<
columns () <<
"\n";
804 keywords[0] =
"ndims";
805 keywords[1] =
"rows";
811 error (
"load: failed to extract number of rows and columns");
815 int mdims =
static_cast<int> (val);
818 error (
"load: failed to extract number of rows and columns");
823 for (
int i = 0; i < mdims; i++)
838 error (
"load: cell array element had unexpected name");
845 error (
"load: failed to load matrix constant");
849 else if (kw ==
"rows")
855 error (
"load: failed to extract number of rows and columns for cell array");
857 if (nr > 0 && nc > 0)
873 error (
"load: cell array element had unexpected name");
876 tmp.
elem (i, j) = t2;
881 error (
"load: failed to load cell element");
885 else if (nr == 0 || nc == 0)
904 int32_t di = - dv.
ndims ();
905 os.write (
reinterpret_cast<char *
> (&di), 4);
906 for (
int i = 0; i < dv.
ndims (); i++)
909 os.write (
reinterpret_cast<char *
> (&di), 4);
936 if (! is.read (
reinterpret_cast<char *
> (&mdims), 4))
948 for (
int i = 0; i < mdims; i++)
950 if (! is.read (
reinterpret_cast<char *
> (&di), 4))
983 error (
"load: cell array element had unexpected name");
990 error (
"load: failed to load matrix constant");
1006 bool save_as_floats)
1008 #if defined (HAVE_HDF5)
1015 hsize_t rank = dv.
ndims ();
1016 hid_t space_hid, data_hid, size_hid;
1017 space_hid = data_hid = size_hid = -1;
1019 #if defined (HAVE_HDF5_18)
1023 data_hid = H5Gcreate (loc_id, name, 0);
1032 space_hid = H5Screate_simple (1, &rank,
nullptr);
1036 H5Gclose (data_hid);
1043 for (hsize_t i = 0; i < rank; i++)
1044 hdims[i] = dv(rank-i-1);
1046 #if defined (HAVE_HDF5_18)
1047 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1051 size_hid = H5Dcreate (data_hid,
"dims",
H5T_NATIVE_IDX, space_hid,
1056 H5Sclose (space_hid);
1057 H5Gclose (data_hid);
1064 H5Dclose (size_hid);
1065 H5Sclose (space_hid);
1066 H5Gclose (data_hid);
1070 H5Dclose (size_hid);
1071 H5Sclose (space_hid);
1081 std::ostringstream buf;
1082 int digits =
static_cast<int> (
std::floor (::log10 (
static_cast<double>
1084 buf <<
'_' << std::setw (digits) << std::setfill (
'0') << i;
1085 std::string s = buf.str ();
1090 H5Gclose (data_hid);
1095 H5Gclose (data_hid);
1100 octave_unused_parameter (loc_id);
1101 octave_unused_parameter (name);
1102 octave_unused_parameter (save_as_floats);
1113 bool retval =
false;
1115 #if defined (HAVE_HDF5)
1126 #if defined (HAVE_HDF5_18)
1129 hid_t group_id = H5Gopen (loc_id, name);
1135 #if defined (HAVE_HDF5_18)
1138 hid_t data_hid = H5Dopen (group_id,
"dims");
1140 hid_t space_hid = H5Dget_space (data_hid);
1141 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
1144 H5Dclose (data_hid);
1145 H5Gclose (group_id);
1152 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
1163 H5Dclose (data_hid);
1164 H5Gclose (group_id);
1168 H5Dclose (data_hid);
1169 H5Gclose (group_id);
1171 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--)
1176 herr_t retval2 = -1;
1180 int current_item = 0;
1182 hsize_t num_obj = 0;
1183 #if defined (HAVE_HDF5_18)
1186 group_id = H5Gopen (loc_id, name);
1188 H5Gget_num_objs (group_id, &num_obj);
1189 H5Gclose (group_id);
1194 if (current_item >=
static_cast<int> (num_obj))
1214 octave_unused_parameter (loc_id);
1215 octave_unused_parameter (name);
1225 DEFUN (iscell, args, ,
1232 if (args.length () != 1)
1235 return ovl (args(0).iscell ());
1238 DEFUN (cell, args, ,
1253 int nargin = args.length ();
1264 if (args(0).iscell ())
1274 for (
int i = 0; i < nargin; i++)
1275 dims(i) = (args(i).isempty ()
1276 ? 0 : args(i).xidx_type_value (
"cell: dimension must be a scalar integer"));
1303 DEFUN (iscellstr, args, ,
1311 if (args.length () != 1)
1314 return ovl (args(0).iscellstr ());
1317 DEFUN (cellstr, args, ,
1330 if (args.length () != 1)
1336 return ovl (args(0));
1340 0).xstring_vector_value (
"cellstr: argument STRING must be a 2-D character array");
1347 DEFUN (struct2cell, args, ,
1382 if (args.length () != 1)
1385 const octave_map m = args(0).xmap_value (
"struct2cell: argument S must be a structure");
1396 if (m_dv(m_dv.
ndims () - 1) == 1)
1401 result_dv(0) = num_fields;
1403 for (
int i = 1; i < result_dv.
ndims (); i++)
1404 result_dv(i) = m_dv(i-1);
1414 c.
xelem (i, j) =
m.contents(i)(j);
1440 mwSize nel =
numel ();
1444 for (mwIndex i = 0; i < nel; i++)
1445 elts[i] =
new mxArray (interleaved, p[i]);
1455 #define FORWARD_MAPPER(UMAP) \
1456 case umap_ ## UMAP: \
1457 return m_matrix.UMAP ()
void swap_bytes< 4 >(void *ptr)
OCTARRAY_OVERRIDABLE_FUNC_API std::size_t byte_size(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API void make_unique(void)
OCTARRAY_OVERRIDABLE_FUNC_API bool isempty(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_API Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
OCTARRAY_API Array< T, Alloc > sort(int dim=0, sortmode mode=ASCENDING) const
Size of the specified dimension.
OCTARRAY_API sortmode issorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
OCTARRAY_OVERRIDABLE_FUNC_API int ndims(void) const
Size of the specified dimension.
OCTARRAY_API sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
OCTARRAY_OVERRIDABLE_FUNC_API T & elem(octave_idx_type n)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type cols(void) const
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
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.
OCTAVE_API 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.
OCTAVE_API dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
void * get_data(void) const
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
OCTINTERP_API bool fast_elem_insert(octave_idx_type n, const octave_value &x)
octave_idx_type numel(void) const
OCTINTERP_API octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
virtual void assign(const std::string &, const octave_value &)
OCTINTERP_API void delete_elements(const octave_value_list &idx)
OCTINTERP_API octave_value fast_elem_extract(octave_idx_type n) const
OCTINTERP_API 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
OCTINTERP_API void indent(std::ostream &os) const
OCTINTERP_API void newline(std::ostream &os) const
virtual octave_value map(unary_mapper_t) const
OCTINTERP_API void warn_load(const char *type) const
octave_idx_type rows(void) const
virtual bool is_magic_colon(void) const
friend class octave_value
OCTINTERP_API void warn_save(const char *type) const
Cell cell_value(void) const
bool print_as_scalar(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
const void * mex_get_data(void) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) 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)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
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 clear_cellstr_cache(void) const
std::unique_ptr< Array< std::string > > m_cellstr_cache
sortmode issorted(sortmode mode=UNSORTED) const
mxArray * as_mxArray(bool interleaved) 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)
std::size_t byte_size(void) const
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
OCTINTERP_API octave_value_list list_value(void) const
void print_with_name(std::ostream &os, const std::string &name) const
static OCTINTERP_API octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
bool is_cs_list(void) const
OCTINTERP_API octave_value storable_value(void) const
bool is_defined(void) const
Cell cell_value(void) const
bool is_zero_by_zero(void) const
OCTINTERP_API octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, std::size_t skip=1)
OCTINTERP_API octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
std::string type_name(void) const
dim_vector dims(void) const
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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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)
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)
#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_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
bool Vprint_empty_dimensions
static void check_dimensions(octave_idx_type &nr, octave_idx_type &nc, const char *warnfor)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)