24 #if defined (HAVE_CONFIG_H) 40 #include "builtin-defun-decls.h" 70 return matrix.index (idx, resize_ok);
96 matrix.delete_elements (idx);
113 return "[" + dimstr +
" " + tname +
"]";
147 const std::list<octave_value_list>& idx,
162 Cell tcell =
tmp.cell_value ();
164 if (tcell.numel () == 1)
177 error (
"%s cannot be indexed with %c",
nm.c_str (),
type[0]);
197 const std::list<octave_value_list>& idx,
212 const Cell tcell =
tmp.cell_value ();
214 if (tcell.numel () == 1)
227 error (
"%s cannot be indexed with %c",
nm.c_str (),
type[0]);
247 const std::list<octave_value_list>& idx,
252 int n =
type.length ();
258 if (idx.front ().empty ())
259 error (
"missing index in indexed assignment");
276 return tmp.subsasgn (
type, idx, rhs);
282 if (!
tmp.is_defined ())
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);
301 std::list<octave_value_list> next_idx (idx);
303 next_idx.erase (next_idx.begin ());
307 if (tmpc.
numel () != 1)
313 if (!
tmp.is_defined () ||
tmp.is_zero_by_zero ())
322 t_rhs =
tmp.subsasgn (next_type, next_idx, rhs);
331 error (
"%s cannot be indexed with %c",
nm.c_str (),
type[0]);
373 if (! idxf(
k).is_magic_colon ()) didx(
k) = idxf(
k).numel ();
375 if (didx.numel () == tmp_cell.
numel ())
376 tmp_cell = tmp_cell.
reshape (didx);
398 error (
"%s cannot be indexed with %c",
nm.c_str (),
type[0]);
408 return tmp.subsasgn (
type, idx, rhs);
474 error (
"sort: only cell arrays of character strings may be sorted");
493 error (
"sort: only cell arrays of character strings may be sorted");
511 error (
"issorted: A is not a cell array of strings");
526 error (
"sortrows: only cell arrays of character strings may be sorted");
541 error (
"issorted: A is not a cell array of strings");
553 error (
"invalid conversion from cell array to logical value");
573 std::queue<string_vector> strvec_queue;
581 n_elts += s_len ? s_len : 1;
585 if (s_max_len > max_len)
588 strvec_queue.push (
s);
609 if (pad && max_len > t_len)
630 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 <<
']';
681 val.print_with_name (
os, buf.str ());
696 os <<
'(' << nr <<
'x' << nc <<
')';
704 os <<
'{' <<
dv.
str () <<
" Cell Array}";
734 #define CELL_ELT_TAG "<cell-element>" 742 os <<
"# ndims: " <<
dv.
ndims () <<
"\n";
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)
898 os.
write (reinterpret_cast<char *> (&di), 4);
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) 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;
1082 H5Gclose (data_hid);
1087 H5Gclose (data_hid);
1092 octave_unused_parameter (loc_id);
1093 octave_unused_parameter (
name);
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 ();
1262 dims(
i) = (args(
i).isempty ()
1263 ? 0 : args(
i).xidx_type_value (
"cell: dimension must be a scalar integer"));
1268 dims.chop_trailing_singletons ();
1289 if (args.length () != 1)
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);
1430 #define FORWARD_MAPPER(UMAP) \ 1431 case umap_ ## UMAP: \ 1432 return matrix.UMAP () octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
string_vector string_vector_value(bool pad=false) const
Cell index(const octave_value_list &idx, bool resize_ok=false) const
std::string str(char sep='x') const
sortmode issorted(sortmode mode=UNSORTED) const
bool save_ascii(std::ostream &os)
void err_nonbraced_cs_list_assignment(void)
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
Array< std::string > cellstr_value(void) const
const T * data(void) const
void assign(const octave_value_list &idx, const MT &rhs)
OCTINTERP_API void print_usage(void)
identity matrix If supplied two scalar respectively For allows like xample val
const octave_hdf5_id octave_H5S_ALL
void delete_elements(const octave_value_list &idx)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).iscell())
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
string_vector string_vector_value(void) const
void delete_elements(const octave_value_list &idx)
void newline(std::ostream &os) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
bool is_cs_list(void) const
void resize(int n, int fill_value=0)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
std::complex< T > floor(const std::complex< T > &x)
octave_value_list list_value(void) const
#define FORWARD_MAPPER(UMAP)
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
octave_value fast_elem_extract(octave_idx_type n) const
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Cell cell_value(void) const
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
T & elem(octave_idx_type n)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
void * mex_get_data(void) const
Give a pointer to the data in mex format.
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
octave_value map(unary_mapper_t umap) const
virtual octave_value map(unary_mapper_t) const
void warn_load(const char *type) const
std::string type_name(void) const
void err_indexed_cs_list(void)
void print(std::ostream &os, bool pr_as_read_syntax=false)
octave_value storable_value(void) const
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
nd deftypefn *std::string name
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
void swap_bytes< 4 >(void *ptr)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
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 edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
bool iscellstr(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)
octave_idx_type rows(void) const
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
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)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
#define panic_impossible()
bool is_true(const std::string &s)
const Cell & contents(const_iterator p) const
void decrement_indent_level(void) const
void warn_save(const char *type) const
bool all_scalars(void) const
bool iscellstr(void) const
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
bool print_as_scalar(void) const
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_idx_type numel(void) const
void indent(std::ostream &os) const
OCTAVE_EXPORT octave_value_list iscellstr
void * mex_get_data(void) const
friend class octave_value
OCTINTERP_API void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
std::unique_ptr< Array< std::string > > cellstr_cache
mxArray * as_mxArray(void) const
octave_idx_type nfields(void) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
octave_value_list list_value(void) const
This is a simple wrapper template that will subclass an Array<T> type or any later type derived from ...
bool Vprint_empty_dimensions
Array< std::string > cellstr_value(void) const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
void clear_cellstr_cache(void) const
bool save_binary(std::ostream &os, bool &save_as_floats)
dim_vector dims(void) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)
octave_idx_type length(void) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void increment_indent_level(void) const
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
octave::refcount< octave_idx_type > count
octave_idx_type numel(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
bool print_name_tag(std::ostream &os, const std::string &name) const
size_t byte_size(void) const
const octave_hdf5_id octave_H5P_DEFAULT
octave_idx_type columns(void) const
Cell reshape(const dim_vector &new_dims) const
void assign(const octave_value_list &idx, const Cell &rhs)
octave_idx_type ndims(void) const
Number of dimensions.
dim_vector dims(void) const
octave_idx_type numel(void) const
Number of elements in the array.
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
write the output to stdout if nargout is
bool load_ascii(std::istream &is)
Vector representing the dimensions (size) of an Array.
size_t byte_size(void) const
OCTINTERP_API void check_dimensions(dim_vector &dim, const char *warnfor)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
Cell cell_value(void) const
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)
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
static int xisascii(int c)