26 #if defined (HAVE_CONFIG_H)
38 octave_fields::fields_rep *
39 octave_fields::nil_rep ()
46 : m_rep (new fields_rep)
50 (*m_rep)[fields(i)] = i;
54 : m_rep (new fields_rep)
58 (*m_rep)[std::string (*fields++)] =
n++;
64 return m_rep->find (field) != m_rep->end ();
70 auto p = m_rep->find (field);
71 return (p != m_rep->end ()) ? p->second : -1;
77 auto p = m_rep->find (field);
78 if (p != m_rep->end ())
84 return (*m_rep)[field] =
n;
91 auto p = m_rep->find (field);
92 if (p == m_rep->end ())
99 for (
auto& fld_idx : *m_rep)
101 if (fld_idx.second >=
n)
117 for (
auto& fld_idx : *m_rep)
132 auto q = other.
begin ();
133 for (; p !=
end () && q != other.
end (); p++, q++)
135 if (p->first == q->first)
136 perm[p->second] = q->second;
141 retval = (p ==
end () && q == other.
end ());
163 for (
auto& fld_idx : *
this)
164 retval.
xelem (fld_idx.second) = fld_idx.first;
170 (
const std::map<std::string, octave_value>&
m)
172 std::size_t sz =
m.size ();
175 for (
const auto& k_v :
m)
178 m_vals[i++] = k_v.second;
196 m_vals.push_back (val);
204 m_vals.erase (m_vals.begin () + idx);
222 retval.m_vals[i] = m_vals[perm.
xelem (i)];
231 if (m_keys.
is_same (other.m_keys))
237 error (
"orderfields: structs must have same fields up to order");
241 retval.m_vals[i] = m_vals[perm.
xelem (i)];
258 m_vals.resize (idx+1);
263 : m_keys (
m.m_keys), m_vals (), m_dimensions (1, 1)
269 m_vals.push_back (
Cell (m_dimensions));
270 m_vals[i].xelem (0) =
m.m_vals[i];
278 return (idx >= 0) ? m_vals[idx] :
Cell ();
285 m_dimensions = val.
dims ();
287 if (val.
dims () != m_dimensions)
288 error (
"octave_map::setfield: internal error");
294 m_vals.push_back (val);
302 m_vals.erase (m_vals.begin () + idx);
320 retval.m_vals[i] = m_vals[perm.
xelem (i)];
329 if (m_keys.
is_same (other.m_keys))
335 error (
"orderfields: structs must have same fields up to order");
339 retval.m_vals[i] = m_vals[perm.
xelem (i)];
356 m_vals.push_back (
Cell (m_dimensions));
366 dest.m_vals[i] = m_vals[i](idx);
407 extract_scalar (retval,
n);
419 if (rhs.m_keys.
is_same (m_keys))
422 m_vals[i](
n) = rhs.m_vals[i];
432 m_vals[i](
n) = rhs.m_vals[perm[i]];
447 retval.m_dimensions = m_dimensions.
squeeze ();
450 retval.m_vals[i] = m_vals[i].squeeze ();
452 retval.optimize_dimensions ();
471 retval.m_vals[i] = m_vals[i].permute (vec, inv);
478 retval.m_dimensions = retval.m_vals[0].dims ();
482 dummy = dummy.
permute (vec, inv);
483 retval.m_dimensions = dummy.
dims ();
486 retval.optimize_dimensions ();
503 retval.m_dimensions =
dim_vector (m_dimensions (1), m_dimensions (0));
507 retval.m_vals[i] = m_vals[i].transpose ();
509 retval.optimize_dimensions ();
527 retval.m_dimensions = dv;
536 retval.m_vals.reserve (nf);
538 retval.m_vals[i] = m_vals[i].reshape (dv);
548 retval.optimize_dimensions ();
582 m_vals[i].resize (dv,
Matrix ());
584 m_vals[i].resize (dv);
596 optimize_dimensions ();
605 retval.m_vals.reserve (nf);
614 retval.m_vals.push_back (
Cell (rd));
617 retval.m_vals[j].xelem (i) = map_list[i].m_vals[j];
626 retval.m_vals.reserve (nf);
633 field_list[i] = map_list[i].m_vals[j];
637 retval.m_dimensions = retval.m_vals[j].dims ();
662 template <
typename map>
668 new_map_list[idx] = map_list[idx];
680 new_map_list[i], perm);
683 catch (octave::execution_exception& ee)
685 error (ee,
"cat: field names mismatch in concatenating structs");
695 if (dim == -1 || dim == -2)
698 error (
"cat: invalid dimension");
701 retval = map_list[0];
705 for (idx = 0; idx <
n; idx++)
710 retval.m_keys = map_list[idx].m_keys;
718 bool all_same =
true;
721 all_same = map_list[idx].m_keys.
is_same (map_list[i].m_keys);
727 do_cat (dim,
n, map_list, retval);
733 permute_to_correct_order (
n, nf, idx, map_list, new_map_list);
735 do_cat (dim,
n, new_map_list, retval);
747 retval.optimize_dimensions ();
759 if (dim == -1 || dim == -2)
762 error (
"cat: invalid dimension");
765 retval = map_list[0];
770 for (idx = 0; idx <
n; idx++)
775 retval.m_keys = map_list[idx].m_keys;
781 bool all_same =
true;
787 all_same = map_list[idx].m_keys.
is_same (map_list[i].m_keys);
794 if (all_same && nf > 0)
795 do_cat (dim,
n, map_list, retval);
803 permute_to_correct_order (
n, nf, idx, map_list, new_map_list);
805 do_cat (dim,
n, new_map_list, retval);
813 if (! dv.
concat (map_list[i].m_dimensions, dim))
814 error (
"dimension mismatch in struct concatenation");
817 retval.m_dimensions = dv;
821 retval.optimize_dimensions ();
854 retval.m_vals[k] = m_vals[k].index (i, resize_ok);
857 retval.m_dimensions = retval.m_vals[0].dims ();
862 dummy = dummy.
index (i, resize_ok);
863 retval.m_dimensions = dummy.
dims ();
866 retval.optimize_dimensions ();
873 bool resize_ok)
const
879 retval.m_vals[k] = m_vals[k].index (i, j, resize_ok);
882 retval.m_dimensions = retval.m_vals[0].dims ();
887 dummy = dummy.
index (i, j, resize_ok);
888 retval.m_dimensions = dummy.
dims ();
891 retval.optimize_dimensions ();
903 retval.m_vals[k] = m_vals[k].index (ia, resize_ok);
906 retval.m_dimensions = retval.m_vals[0].dims ();
911 dummy = dummy.
index (ia, resize_ok);
912 retval.m_dimensions = dummy.
dims ();
915 retval.optimize_dimensions ();
940 retval =
index (i, resize_ok);
951 retval =
index (i, j, resize_ok);
959 for (k = 0; k < n_idx; k++)
960 ia(k) = idx(k).index_vector ();
962 retval =
index (ia, resize_ok);
967 catch (octave::index_exception& ie)
970 ie.set_pos_if_unset (n_idx, k+1);
981 return index (octave::idx_vector::colon, k);
988 octave::idx_vector::colon);
997 if (rhs.m_keys.
is_same (m_keys))
1005 m_dimensions = m_vals[0].dims ();
1009 Array<char> dummy (m_dimensions), rhs_dummy (rhs.m_dimensions);
1010 dummy.assign (i, rhs_dummy);
1011 m_dimensions = dummy.dims ();
1014 optimize_dimensions ();
1031 catch (octave::execution_exception& ee)
1033 error (ee,
"incompatible fields in struct assignment");
1045 if (rhs.m_keys.
is_same (m_keys))
1053 m_dimensions = m_vals[0].dims ();
1057 Array<char> dummy (m_dimensions), rhs_dummy (rhs.m_dimensions);
1058 dummy.assign (i, j, rhs_dummy);
1059 m_dimensions = dummy.dims ();
1062 optimize_dimensions ();
1079 catch (octave::execution_exception& ee)
1081 error (ee,
"incompatible fields in struct assignment");
1093 if (rhs.m_keys.
is_same (m_keys))
1101 m_dimensions = m_vals[0].dims ();
1105 Array<char> dummy (m_dimensions), rhs_dummy (rhs.m_dimensions);
1106 dummy.assign (ia, rhs_dummy);
1107 m_dimensions = dummy.dims ();
1110 optimize_dimensions ();
1127 catch (octave::execution_exception& ee)
1129 error (ee,
"incompatible fields in struct assignment");
1175 for (k = 0; k < n_idx; k++)
1176 ia(k) = idx(k).index_vector ();
1183 catch (octave::index_exception& ie)
1186 ie.set_pos_if_unset (n_idx, k+1);
1200 ref =
Cell (m_dimensions);
1204 if (ref.
dims () != m_dimensions)
1206 m_dimensions = ref.
dims ();
1211 if (&m_vals[i] != &ref)
1212 m_vals[i].resize (m_dimensions,
Matrix ());
1215 optimize_dimensions ();
1237 m_dimensions = m_vals[0].dims ();
1243 m_dimensions = dummy.
dims ();
1246 optimize_dimensions ();
1257 m_dimensions = m_vals[0].dims ();
1263 m_dimensions = dummy.
dims ();
1266 optimize_dimensions ();
1277 m_dimensions = m_vals[0].dims ();
1283 m_dimensions = dummy.
dims ();
1286 optimize_dimensions ();
1300 ia(i) = idx(i).index_vector ();
1302 catch (octave::index_exception& ie)
1305 ie.set_pos_if_unset (n_idx, i+1);
1325 for (
auto pa =
cbegin (); pa !=
cend (); pa++)
1329 if (pb == rb.
cend ())
1330 error (
"field name mismatch in structure concatenation");
1342 error (
"invalid structure concatenation");
1349 octave_map::optimize_dimensions ()
1355 if (! m_vals[i].optimize_dimensions (m_dimensions))
1356 error (
"internal error: dimension mismatch across fields in struct");
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
T * fortran_vec()
Size of the specified dimension.
Array< T, Alloc > index(const octave::idx_vector &i) const
Indexing without resizing.
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
void delete_elements(const octave::idx_vector &i)
Deleting elements.
Array< T, Alloc > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Size of the specified dimension.
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.
Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
Cell & insert(const Cell &a, octave_idx_type r, octave_idx_type c)
void assign(const octave_value_list &idx, const Cell &rhs, const octave_value &fill_val=Matrix())
Vector representing the dimensions (size) of an Array.
bool concat(const dim_vector &dvb, int dim)
This corresponds to cat().
void chop_trailing_singletons()
dim_vector squeeze() const
void resize(int n, int fill_value=0)
void orderfields(Array< octave_idx_type > &perm)
octave_idx_type rmfield(const std::string &name)
const_iterator end() const
const_iterator begin() const
octave_idx_type nfields() const
bool equal_up_to_order(const octave_fields &other, octave_idx_type *perm) const
bool is_same(const octave_fields &other) const
bool isfield(const std::string &name) const
string_vector fieldnames() const
octave_idx_type getfield(const std::string &name) const
const_iterator cbegin() const
void resize(const dim_vector &dv, bool fill=false)
Cell getfield(const std::string &key) const
void rmfield(const std::string &key)
octave_idx_type nfields() const
octave_map squeeze() const
octave_scalar_map fast_elem_extract(octave_idx_type n) const
const_iterator end() const
string_vector keys() const
octave_map reshape(const dim_vector &dv) const
octave_map permute(const Array< int > &vec, bool inv=false) const
octave_map orderfields() const
void delete_elements(const octave::idx_vector &i)
void setfield(const std::string &key, const Cell &val)
octave_map page(octave_idx_type k) const
const_iterator seek(const std::string &k) const
octave_map concat(const octave_map &rb, const Array< octave_idx_type > &ra_idx)
void assign(const std::string &k, const Cell &val)
std::string key(const_iterator p) const
octave_map transpose() const
const Cell & contents(const_iterator p) const
bool fast_elem_insert(octave_idx_type n, const octave_scalar_map &rhs)
const_iterator cend() const
static octave_map cat(int dim, octave_idx_type n, const octave_scalar_map *map_list)
octave_scalar_map elem(octave_idx_type n) const
octave_idx_type index(const_iterator p) const
octave_map(const octave_fields &k)
octave_map column(octave_idx_type k) const
octave_scalar_map(const octave_fields &k)
const octave_value & contents(const_iterator p) const
void setfield(const std::string &key, const octave_value &val)
void rmfield(const std::string &key)
octave_idx_type nfields() const
octave_scalar_map orderfields() const
octave_value getfield(const std::string &key) const
octave_idx_type length() const
std::string & xelem(octave_idx_type i)
octave_idx_type numel() const
void() error(const char *fmt,...)
#define error_unless(cond)
octave::idx_vector idx_vector
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void permute_to_correct_order1(const octave_scalar_map &ref, const octave_scalar_map &src, octave_scalar_map &dest, Array< octave_idx_type > &perm)
const octave_base_value const Array< octave_idx_type > & ra_idx
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))