44 template <
typename T,
typename Alloc>
54 template <
typename T,
typename Alloc>
56 : m_dimensions (dv), m_rep (a.m_rep),
57 m_slice_data (a.m_slice_data), m_slice_len (a.m_slice_len)
59 bool invalid_size =
false;
72 catch (
const std::bad_alloc&)
77 if (invalid_size || new_numel != a.
numel ())
82 (*current_liboctave_error_handler)
83 (
"reshape: can't reshape %s array to %s array",
84 dimensions_str.c_str (), new_dims_str.c_str ());
93 template <
typename T,
typename Alloc>
97 if (m_rep->m_count > 1)
101 m_slice_data = m_rep->m_data;
104 std::fill_n (m_slice_data, m_slice_len, val);
107 template <
typename T,
typename Alloc>
111 if (--m_rep->m_count == 0)
116 m_slice_data = m_rep->m_data;
117 m_slice_len = m_rep->m_len;
122 template <
typename T,
typename Alloc>
126 if (--m_rep->m_count == 0)
130 m_slice_data = m_rep->m_data;
131 m_slice_len = m_rep->m_len;
137 template <
typename T,
typename Alloc>
145 bool dims_changed =
false;
151 for (
int i = 0; i < ndims (); i++)
153 if (m_dimensions(i) == 1)
156 new_dimensions(k++) = m_dimensions(i);
171 new_dimensions.
resize (2);
173 new_dimensions(0) = tmp;
174 new_dimensions(1) = 1;
179 new_dimensions.
resize (k);
190 template <
typename T,
typename Alloc>
197 template <
typename T,
typename Alloc>
205 template <
typename T,
typename Alloc>
212 template <
typename T,
typename Alloc>
219 if (
n >= m_slice_len)
225 template <
typename T,
typename Alloc>
232 template <
typename T,
typename Alloc>
239 template <
typename T,
typename Alloc>
246 template <
typename T,
typename Alloc>
253 if (
n >= m_slice_len)
259 template <
typename T,
typename Alloc>
266 template <
typename T,
typename Alloc>
274 template <
typename T,
typename Alloc>
281 template <
typename T,
typename Alloc>
290 template <
typename T,
typename Alloc>
301 template <
typename T,
typename Alloc>
325 for (
int i = 1; i <
m_n+1; i++) cdim[i] = cdim[i-1] * dv(i-1);
328 for (
int k = 0; k <
m_n; k++)
336 for (
int k = 1; k <
m_n; k++)
361 template <
typename T>
365 template <
typename T>
376 if (lr ==
m && lc ==
m)
378 const T *ss = src + kc * nr + kr;
381 blk[j*
m+i] = ss[j*nr + i];
382 T *dd = dest + kr * nc + kc;
385 dd[j*nc+i] = blk[i*
m+j];
389 const T *ss = src + kc * nr + kr;
392 blk[j*
m+i] = ss[j*nr + i];
393 T *dd = dest + kr * nc + kc;
396 dd[j*nc+i] = blk[i*
m+j];
406 template <
typename T>
415 std::copy_n (src,
len, dest);
433 dest =
do_permute (src + i * step, dest, lev-1);
451 template <
typename T,
typename Alloc>
461 int perm_vec_len = perm_vec_arg.
numel ();
463 if (perm_vec_len < dv.
ndims ())
464 (*current_liboctave_error_handler)
465 (
"%s: invalid permutation vector", inv ?
"ipermute" :
"permute");
470 dv.
resize (perm_vec_len, 1);
475 bool identity =
true;
478 for (
int i = 0; i < perm_vec_len; i++)
481 if (perm_elt >= perm_vec_len || perm_elt < 0)
482 (*current_liboctave_error_handler)
483 (
"%s: permutation vector contains an invalid element",
484 inv ?
"ipermute" :
"permute");
486 if (checked[perm_elt])
487 (*current_liboctave_error_handler)
488 (
"%s: permutation vector cannot contain identical elements",
489 inv ?
"ipermute" :
"permute");
492 checked[perm_elt] =
true;
493 identity = identity && perm_elt == i;
502 for (
int i = 0; i < perm_vec_len; i++)
503 perm_vec(perm_vec_arg(i)) = i;
506 for (
int i = 0; i < perm_vec_len; i++)
507 dv_new(i) = dv(perm_vec(i));
539 for (
int i = 1; i <
m_n; i++)
566 template <
typename T>
569 template <
typename T>
572 template <
typename T>
583 template <
typename T>
584 T *
do_index (
const T *src, T *dest,
int lev)
const
600 template <
typename T>
601 const T *
do_assign (
const T *src, T *dest,
int lev)
const
617 template <
typename T>
618 void do_fill (
const T& val, T *dest,
int lev)
const
652 int l = ndv.
ndims ();
653 assert (odv.
ndims () == l);
656 for (; i < l-1 && ndv(i) == odv(i); i++) ld *= ndv(i);
665 for (
int j = 0; j <
m_n; j++)
668 m_sext[j] = sld *= odv(i+j);
669 m_dext[j] = dld *= ndv(i+j);
682 template <
typename T>
689 template <
typename T>
694 std::copy_n (src,
m_cext[0], dest);
702 for (k = 0; k <
m_cext[lev]; k++)
705 std::fill_n (dest + k * dd,
m_dext[lev] - k * dd, rfv);
717 template <
typename T,
typename Alloc>
749 if (i.extent (
n) !=
n)
752 dim_vector result_dims = i.orig_dimensions ();
755 if (
n != 1 && is_nd_vector () && idx_len != 1
767 if (idx_len != 0 && i.is_cont_range (
n, l, u))
784 template <
typename T,
typename Alloc>
794 if (i.is_colon () && j.is_colon ())
801 if (i.extent (
r) !=
r)
803 if (j.extent (c) != c)
812 if (ii.maybe_reduce (
r, j, c))
815 if (ii.length () > 0 && ii.is_cont_range (
n, l, u))
831 const T *src = data ();
835 dest += i.index (src +
r * j.xelem (k),
r, dest);
842 template <
typename T,
typename Alloc>
846 int ial = ia.
numel ();
851 retval = index (ia(0));
853 retval = index (ia(0), ia(1));
860 bool all_colons =
true;
861 for (
int i = 0; i < ial; i++)
863 if (ia(i).extent (dv(i)) != dv(i))
867 all_colons = all_colons && ia(i).is_colon ();
880 for (
int i = 0; i < ial; i++) rdv(i) = ia(i).length (dv(i));
906 template <
typename T,
typename Alloc>
910 static T zero = T ();
917 template <
typename T,
typename Alloc>
921 if (
n < 0 || ndims () != 2)
932 bool invalid =
false;
933 if (rows () == 0 || rows () == 1)
935 else if (columns () == 1)
944 if (
n == nx - 1 &&
n > 0)
947 if (m_rep->m_count == 1)
948 m_slice_data[m_slice_len-1] = T ();
952 else if (
n == nx + 1 && nx > 0)
955 if (m_rep->m_count == 1
956 && m_slice_data + m_slice_len < m_rep->m_data + m_rep->m_len)
958 m_slice_data[m_slice_len++] = rfv;
966 T *dest = tmp.fortran_vec ();
968 std::copy_n (data (), nx, dest);
981 std::copy_n (data (), n0, dest);
982 std::fill_n (dest + n0, n1, rfv);
988 template <
typename T,
typename Alloc>
992 if (
r < 0 || c < 0 || ndims () != 2)
997 if (
r != rx || c != cx)
1006 const T *src = data ();
1009 std::copy_n (src,
r * c0, dest);
1016 std::copy_n (src, r0, dest);
1019 std::fill_n (dest, r1, rfv);
1024 std::fill_n (dest,
r * c1, rfv);
1030 template <
typename T,
typename Alloc>
1034 int dvl = dv.
ndims ();
1036 resize2 (dv(0), dv(1), rfv);
1037 else if (m_dimensions != dv)
1039 if (m_dimensions.ndims () > dvl || dv.
any_neg ())
1052 template <
typename T,
typename Alloc>
1069 if (tmp.
numel () != nx)
1073 return tmp.
index (i);
1076 template <
typename T,
typename Alloc>
1079 bool resize_ok,
const T& rfv)
const
1089 if (
r != rx || c != cx)
1091 if (i.is_scalar () && j.is_scalar ())
1101 return tmp.
index (i, j);
1104 template <
typename T,
typename Alloc>
1107 bool resize_ok,
const T& rfv)
const
1112 int ial = ia.
numel ();
1115 for (
int i = 0; i < ial; i++)
1116 dvx(i) = ia(i).extent (dv(i));
1119 bool all_scalars =
true;
1120 for (
int i = 0; i < ial; i++)
1121 all_scalars = all_scalars && ia(i).is_scalar ();
1132 return tmp.
index (ia);
1135 template <
typename T,
typename Alloc>
1142 if (rhl != 1 && i.length (
n) != rhl)
1146 bool colon = i.is_colon_equiv (nx);
1151 if (m_dimensions.zero_by_zero () && colon)
1170 *
this = rhs.
reshape (m_dimensions);
1175 i.fill (rhs(0),
n, fortran_vec ());
1177 i.assign (rhs.
data (),
n, fortran_vec ());
1182 template <
typename T,
typename Alloc>
1187 bool initial_dims_all_zero = m_dimensions.all_zero ();
1201 if (initial_dims_all_zero)
1205 rdv(0) = i.extent (dv(0));
1206 rdv(1) = j.extent (dv(1));
1209 bool isfill = rhs.
numel () == 1;
1213 bool match = (isfill
1214 || (rhdv.
ndims () == 2 && il == rhdv(0) && jl == rhdv(1)));
1215 match = match || (il == 1 && jl == rhdv(0) && rhdv(1) == 1);
1219 bool all_colons = (i.is_colon_equiv (rdv(0))
1220 && j.is_colon_equiv (rdv(1)));
1244 *
this = rhs.
reshape (m_dimensions);
1254 const T *src = rhs.
data ();
1255 T *dest = fortran_vec ();
1258 if (ii.maybe_reduce (
r, j, c))
1261 ii.fill (*src,
n, dest);
1263 ii.assign (src,
n, dest);
1270 i.fill (*src,
r, dest +
r * j.xelem (k));
1275 src += i.assign (src,
r, dest +
r * j.xelem (k));
1281 else if ((il != 0 && jl != 0) || (rhdv(0) != 0 && rhdv(1) != 0))
1286 template <
typename T,
typename Alloc>
1291 int ial = ia.
numel ();
1295 assign (ia(0), rhs, rfv);
1297 assign (ia(0), ia(1), rhs, rfv);
1300 bool initial_dims_all_zero = m_dimensions.all_zero ();
1314 if (initial_dims_all_zero)
1319 for (
int i = 0; i < ial; i++)
1320 rdv(i) = ia(i).extent (dv(i));
1325 bool all_colons =
true;
1326 bool isfill = rhs.
numel () == 1;
1330 int rhdvl = rhdv.
ndims ();
1331 for (
int i = 0; i < ial; i++)
1333 all_colons = all_colons && ia(i).is_colon_equiv (rdv(i));
1335 if (l == 1)
continue;
1336 match = match && j < rhdvl && l == rhdv(j++);
1339 match = match && (j == rhdvl || rhdv(j) == 1);
1340 match = match || isfill;
1368 *
this = rhs.
reshape (m_dimensions);
1379 rh.
fill (rhs(0), fortran_vec ());
1387 bool lhsempty, rhsempty;
1388 lhsempty = rhsempty =
false;
1390 for (
int i = 0; i < ial; i++)
1394 lhsempty = lhsempty || (l == 0);
1395 rhsempty = rhsempty || (rhdv(j++) == 0);
1397 if (! lhsempty || ! rhsempty)
1414 template <
typename T,
typename Alloc>
1423 else if (i.length (
n) != 0)
1425 if (i.extent (
n) !=
n)
1429 bool col_vec = ndims () == 2 && columns () == 1 && rows () != 1;
1430 if (i.is_scalar () && i(0) ==
n-1 && m_dimensions.isvector ())
1435 else if (i.is_cont_range (
n, l, u))
1440 const T *src = data ();
1442 std::copy_n (src, l, dest);
1443 std::copy (src + u, src +
n, dest + l);
1449 *
this = index (i.complement (
n));
1454 template <
typename T,
typename Alloc>
1458 if (dim < 0 || dim >= ndims ())
1459 (*current_liboctave_error_handler) (
"invalid dimension in delete_elements");
1466 else if (i.length (
n) != 0)
1468 if (i.extent (
n) !=
n)
1473 if (i.is_cont_range (
n, l, u))
1481 for (
int k = 0; k < dim; k++) dl *= m_dimensions(k);
1482 for (
int k = dim + 1; k < ndims (); k++) du *= m_dimensions(k);
1486 const T *src = data ();
1488 l *= dl; u *= dl;
n *= dl;
1491 std::copy_n (src, l, dest);
1493 std::copy (src + u, src +
n, dest);
1504 ia (dim) = i.complement (
n);
1510 template <
typename T,
typename Alloc>
1514 int ial = ia.
numel ();
1517 delete_elements (ia(0));
1521 for (k = 0; k < ial; k++)
1523 if (! ia(k).is_colon ())
1539 delete_elements (dim, ia(dim));
1554 bool empty_assignment =
false;
1556 int num_non_colon_indices = 0;
1560 for (
int i = 0; i < ial; i++)
1564 if (ia(i).length (dim_len) == 0)
1566 empty_assignment =
true;
1570 if (! ia(i).is_colon_equiv (dim_len))
1572 num_non_colon_indices++;
1574 if (num_non_colon_indices == 2)
1579 if (! empty_assignment)
1580 (*current_liboctave_error_handler)
1581 (
"a null assignment can only have one non-colon index");
1587 template <
typename T,
typename Alloc>
1593 if (ndims () == 2 && a.
ndims () == 2)
1600 for (
int k = 2; k < a.
ndims (); k++)
1608 template <
typename T,
typename Alloc>
1623 template <
typename T,
typename Alloc>
1627 assert (ndims () == 2);
1632 if (nr >= 8 && nc >= 8)
1642 else if (nr > 1 && nc > 1)
1648 result.
xelem (j, i) = xelem (i, j);
1659 template <
typename T>
1666 template <
typename T,
typename Alloc>
1670 assert (ndims () == 2);
1678 if (nr >= 8 && nc >= 8)
1687 for (jj = 0; jj < (nc - 8 + 1); jj += 8)
1690 for (ii = 0; ii < (nr - 8 + 1); ii += 8)
1694 j < jj + 8; j++, idxj += nr)
1696 buf[k++] = xelem (i + idxj);
1703 result.
xelem (j + idxi) = fcn (buf[k]);
1709 result.
xelem (j, i) = fcn (xelem (i, j));
1714 result.
xelem (j, i) = fcn (xelem (i, j));
1724 result.
xelem (j, i) = fcn (xelem (i, j));
1764 template <
typename T,
typename Alloc>
1770 return m_slice_data;
1774 template <
typename T>
1781 template <
typename T,
typename Alloc>
1786 (*current_liboctave_error_handler) (
"sort: invalid dimension");
1795 if (dim >= dv.
ndims ())
1802 for (
int i = 0; i < dim; i++)
1805 T *v =
m.fortran_vec ();
1806 const T *ov = data ();
1830 if (sort_isnan<T> (tmp))
1842 std::reverse (v + ku, v + ns);
1844 std::rotate (v, v + ku, v + ns);
1859 offset += n_strides * stride * (ns - 1);
1866 T tmp = ov[i*stride + offset];
1867 if (sort_isnan<T> (tmp))
1874 lsort.
sort (buf, kl);
1879 std::reverse (buf + ku, buf + ns);
1881 std::rotate (buf, buf + ku, buf + ns);
1886 v[i*stride + offset] = buf[i];
1893 template <
typename T,
typename Alloc>
1898 if (dim < 0 || dim >= ndims ())
1899 (*current_liboctave_error_handler) (
"sort: invalid dimension");
1915 for (
int i = 0; i < dim; i++)
1918 T *v =
m.fortran_vec ();
1919 const T *ov = data ();
1943 if (sort_isnan<T> (tmp))
1958 lsort.
sort (v, vi, kl);
1963 std::reverse (v + ku, v + ns);
1964 std::reverse (vi + ku, vi + ns);
1967 std::rotate (v, v + ku, v + ns);
1968 std::rotate (vi, vi + ku, vi + ns);
1986 offset += n_strides * stride * (ns - 1);
1993 T tmp = ov[i*stride + offset];
1994 if (sort_isnan<T> (tmp))
2009 lsort.
sort (buf, bufi, kl);
2014 std::reverse (buf + ku, buf + ns);
2015 std::reverse (bufi + ku, bufi + ns);
2018 std::rotate (buf, buf + ku, buf + ns);
2019 std::rotate (bufi, bufi + ku, bufi + ns);
2025 v[i*stride + offset] = buf[i];
2027 vi[i*stride + offset] = bufi[i];
2034 template <
typename T,
typename Alloc>
2047 template <
typename T,
typename Alloc>
2061 compare_fcn_type compare
2079 template <
typename T,
typename Alloc>
2097 template <
typename T,
typename Alloc>
2106 if (
r <= 1 || c == 0)
2112 compare_fcn_type compare
2116 for (i = 0; i < cols (); i++)
2119 T u =
elem (rows () - 1, i);
2130 else if (compare (u, l))
2141 if (mode ==
UNSORTED && i == cols ())
2158 template <
typename T,
typename Alloc>
2176 return lsort.
lookup (data (),
n, value);
2179 template <
typename T,
typename Alloc>
2201 static const double ratio = 1.0;
2209 if ((vmode ==
ASCENDING && sort_isnan<T> (values(nval-1)))
2210 || (vmode ==
DESCENDING && sort_isnan<T> (values(0))))
2223 template <
typename T,
typename Alloc>
2227 const T *src = data ();
2230 const T zero = T ();
2238 template <
typename T,
typename Alloc>
2243 const T *src = data ();
2245 const T zero = T ();
2246 if (n < 0 || n >= nel)
2252 cnt += src[i] != zero;
2254 retval.
clear (cnt, 1);
2257 if (src[i] != zero) *dest++ = i;
2272 for (; l >= 0 && src[l] == zero; l--) ;
2281 std::reverse (rdata, rdata + k);
2290 for (; l != nel && src[l] == zero; l++) ;
2311 || (rows () == 0 && dims ().
numel (1) == 0))
2313 else if (rows () == 1 && ndims () == 2)
2319 template <
typename T,
typename Alloc>
2324 (*current_liboctave_error_handler) (
"nth_element: invalid dimension");
2327 if (dim >= dv.ndims ())
2328 dv.resize (dim+1, 1);
2335 dv.chop_trailing_singletons ();
2346 switch (
n.idx_class ())
2348 case octave::idx_vector::class_scalar:
2352 case octave::idx_vector::class_range:
2367 case octave::idx_vector::class_vector:
2370 if (
n(1) -
n(0) == 1)
2375 else if (
n(1) -
n(0) == -1)
2391 (*current_liboctave_error_handler)
2392 (
"nth_element: n must be a scalar or a contiguous range");
2396 if (lo < 0 || up > ns)
2397 (*current_liboctave_error_handler) (
"nth_element: invalid element index");
2402 for (
int i = 0; i < dim; i++)
2405 T *v =
m.fortran_vec ();
2406 const T *ov = data ();
2424 if (sort_isnan<T> (tmp))
2438 T tmp = ov[offset + i*stride];
2439 if (sort_isnan<T> (tmp))
2445 if (offset == stride-1)
2459 std::rotate (buf, buf + ku, buf + ns);
2473 v[offset + stride * i] = buf[lo + i];
2474 if (offset == stride-1)
2482 #define NO_INSTANTIATE_ARRAY_SORT_API(T, API) \
2483 template <> API Array<T> \
2484 Array<T>::sort (int, sortmode) const \
2488 template <> API Array<T> \
2489 Array<T>::sort (Array<octave_idx_type> &sidx, int, sortmode) const \
2491 sidx = Array<octave_idx_type> (); \
2494 template <> API sortmode \
2495 Array<T>::issorted (sortmode) const \
2499 API Array<T>::compare_fcn_type \
2500 safe_comparator (sortmode, const Array<T>&, bool) \
2504 template <> API Array<octave_idx_type> \
2505 Array<T>::sort_rows_idx (sortmode) const \
2507 return Array<octave_idx_type> (); \
2509 template <> API sortmode \
2510 Array<T>::is_sorted_rows (sortmode) const \
2514 template <> API octave_idx_type \
2515 Array<T>::lookup (T const &, sortmode) const \
2519 template <> API Array<octave_idx_type> \
2520 Array<T>::lookup (const Array<T>&, sortmode) const \
2522 return Array<octave_idx_type> (); \
2524 template <> API octave_idx_type \
2525 Array<T>::nnz (void) const \
2529 template <> API Array<octave_idx_type> \
2530 Array<T>::find (octave_idx_type, bool) const \
2532 return Array<octave_idx_type> (); \
2534 template <> API Array<T> \
2535 Array<T>::nth_element (const octave::idx_vector&, int) const { \
2536 return Array<T> (); \
2539 #define NO_INSTANTIATE_ARRAY_SORT(T) NO_INSTANTIATE_ARRAY_SORT_API (T,)
2541 template <
typename T,
typename Alloc>
2550 (*current_liboctave_error_handler) (
"Matrix must be 2-dimensional");
2555 if (nnr == 0 && nnc == 0)
2557 else if (nnr != 1 && nnc != 1)
2565 if (nnr > 0 && nnc > 0)
2574 d.xelem (i) =
elem (i, i+k);
2579 d.xelem (i) =
elem (i-k, i);
2584 d.xelem (i) =
elem (i, i);
2612 d.xelem (i+roff, i+coff) =
elem (0, i);
2620 d.xelem (i+roff, i+coff) =
elem (i, 0);
2627 template <
typename T,
typename Alloc>
2631 if (ndims () != 2 || (rows () != 1 && cols () != 1))
2632 (*current_liboctave_error_handler) (
"cat: invalid dimension");
2638 retval.xelem (i, i) = xelem (i);
2643 template <
typename T,
typename Alloc>
2650 if (dim == -1 || dim == -2)
2656 (*current_liboctave_error_handler) (
"cat: invalid dimension");
2659 return array_list[0];
2686 if (
n > 2 && dim > 1)
2706 if (! (dv.*concat_rule) (array_list[i].
dims (), dim))
2707 (*current_liboctave_error_handler) (
"cat: dimension mismatch");
2711 if (retval.isempty ())
2726 if (array_list[i].isempty ())
2732 if (dim < array_list[i].ndims ())
2733 u = l + array_list[i].
dims ()(dim);
2739 retval.assign (idxa, array_list[i]);
2747 template <
typename T,
typename Alloc>
2751 os << prefix <<
"m_rep address: " << m_rep <<
'\n'
2752 << prefix <<
"m_rep->m_len: " << m_rep->m_len <<
'\n'
2753 << prefix <<
"m_rep->m_data: " <<
static_cast<void *
> (m_rep->m_data) <<
'\n'
2754 << prefix <<
"m_rep->m_count: " << m_rep->m_count <<
'\n'
2755 << prefix <<
"m_slice_data: " <<
static_cast<void *
> (m_slice_data) <<
'\n'
2756 << prefix <<
"m_slice_len: " << m_slice_len <<
'\n';
2764 template <
typename T,
typename Alloc>
2767 bool retval = m_dimensions == dv;
2774 template <
typename T,
typename Alloc>
2782 #define INSTANTIATE_ARRAY(T, API) \
2783 template <> API void \
2784 Array<T>::instantiation_guard () { } \
2786 template class API Array<T>
2790 template <
typename T,
typename Alloc>
2796 int n_dims = a_dims.
ndims ();
2798 os << n_dims <<
"-dimensional array";
2801 os <<
" (" << a_dims.
str () <<
')';
2814 for (
int i = 2; i < n_dims; i++)
2858 for (
int i = 0; i <
m; i++)
2862 for (
int j = 2; j < n_dims - 1; j++)
2863 os <<
ra_idx(j) + 1 <<
',';
2865 os <<
ra_idx(n_dims - 1) + 1 <<
") = \n";
bool sort_isnan(typename ref_param< T >::type)
Array< T, Alloc >::compare_fcn_type safe_comparator(sortmode mode, const Array< T, Alloc > &, bool)
std::ostream & operator<<(std::ostream &os, const Array< T, Alloc > &a)
static T no_op_fcn(const T &x)
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
dim_vector zero_dims_inquire(const Array< octave::idx_vector > &ia, const dim_vector &rhdv)
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
The real representation of all arrays.
octave::refcount< octave_idx_type > m_count
N Dimensional Array with copy-on-write semantics.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns(void) const
OCTARRAY_API Array< T, Alloc > transpose(void) const
Size of the specified dimension.
OCTARRAY_API void clear(void)
OCTARRAY_API Array< T, Alloc > squeeze(void) const
Chop off leading singleton dimensions.
OCTARRAY_API Array< T, Alloc > index(const octave::idx_vector &i) const
Indexing without resizing.
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
friend class Array
Size of the specified dimension.
OCTARRAY_API void assign(const octave::idx_vector &i, const Array< T, Alloc > &rhs, const T &rfv)
Indexed assignment (always with resize & fill).
OCTARRAY_OVERRIDABLE_FUNC_API bool isempty(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim2(void) const
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim1(void) const
OCTARRAY_API Array< T, Alloc > nth_element(const octave::idx_vector &n, int dim=0) const
Returns the n-th element in increasing order, using the same ordering as used for sort.
OCTARRAY_API octave_idx_type nnz(void) const
Count nonzero elements.
OCTARRAY_API Array< T, Alloc > hermitian(T(*fcn)(const T &)=nullptr) const
Size of the specified dimension.
OCTARRAY_API void resize1(octave_idx_type n, const T &rfv)
Size of the specified dimension.
ref_param< T >::type crefT
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
static OCTARRAY_API void instantiation_guard()
Size of the specified dimension.
OCTARRAY_API Array< T, Alloc > column(octave_idx_type k) const
Extract column: A(:,k+1).
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_API Array< T, Alloc > linear_slice(octave_idx_type lo, octave_idx_type up) const
Extract a slice from this array as a column vector: A(:)(lo+1:up).
OCTARRAY_API bool optimize_dimensions(const dim_vector &dv)
Returns true if this->dims () == dv, and if so, replaces this->m_dimensions by a shallow copy of dv.
OCTARRAY_API Array< T, Alloc > page(octave_idx_type k) const
Extract page: A(:,:,k+1).
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
OCTARRAY_API Array< T, Alloc > & insert(const Array< T, Alloc > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
static OCTARRAY_API Array< T, Alloc >::ArrayRep * nil_rep(void)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_OVERRIDABLE_FUNC_API Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_API void delete_elements(const octave::idx_vector &i)
Deleting elements.
OCTARRAY_API Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
OCTARRAY_API Array< octave_idx_type > find(octave_idx_type n=-1, bool backward=false) const
Find indices of (at most n) nonzero elements.
OCTARRAY_API Array< T, Alloc > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Size of the specified dimension.
OCTARRAY_API Array< T, Alloc > sort(int dim=0, sortmode mode=ASCENDING) const
Size of the specified dimension.
OCTARRAY_API void print_info(std::ostream &os, const std::string &prefix) const
Size of the specified dimension.
OCTARRAY_API sortmode issorted(sortmode mode=UNSORTED) const
Ordering is auto-detected or can be specified.
virtual OCTARRAY_API T resize_fill_value(void) const
Size of the specified dimension.
OCTARRAY_API T & checkelem(octave_idx_type n)
Size of the specified dimension.
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_API void fill(const T &val)
OCTARRAY_OVERRIDABLE_FUNC_API T & elem(octave_idx_type n)
Size of the specified dimension.
OCTARRAY_API Array< T, Alloc > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
OCTARRAY_API octave_idx_type compute_index(octave_idx_type i, octave_idx_type j) const
Size of the specified dimension.
OCTARRAY_API octave_idx_type lookup(const T &value, sortmode mode=UNSORTED) const
Do a binary lookup in a sorted array.
Array< T, Alloc >::ArrayRep * m_rep
OCTARRAY_API void resize2(octave_idx_type nr, octave_idx_type nc, const T &rfv)
Resizing (with fill).
static OCTARRAY_API Array< T, Alloc > cat(int dim, octave_idx_type n, const Array< T, Alloc > *array_list)
Concatenation along a specified (0-based) dimension, equivalent to cat().
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
OCTAVE_API bool concat(const dim_vector &dvb, int dim)
This corresponds to cat().
OCTAVE_API void chop_all_singletons(void)
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.
bool zero_by_zero(void) const
void resize(int n, int fill_value=0)
static dim_vector alloc(int n)
OCTAVE_API bool hvcat(const dim_vector &dvb, int dim)
This corresponds to [,] (horzcat, dim = 0) and [;] (vertcat, dim = 1).
void chop_trailing_singletons(void)
octave_idx_type ndims(void) const
Number of dimensions.
bool is_nd_vector(void) const
OCTAVE_API dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
OCTAVE_API octave_idx_type safe_numel(void) const
The following function will throw a std::bad_alloc () exception if the requested size is larger than ...
dim_vector make_nd_vector(octave_idx_type n) const
virtual octave_idx_type numel(void) const
void set_compare(const compare_fcn_type &comp)
void sort_rows(const T *data, octave_idx_type *idx, octave_idx_type rows, octave_idx_type cols)
static bool descending_compare(typename ref_param< T >::type, typename ref_param< T >::type)
bool issorted(const T *data, octave_idx_type nel)
octave_idx_type lookup(const T *data, octave_idx_type nel, const T &value)
void sort(T *data, octave_idx_type nel)
void nth_element(T *data, octave_idx_type nel, octave_idx_type lo, octave_idx_type up=-1)
bool is_sorted_rows(const T *data, octave_idx_type rows, octave_idx_type cols)
void lookup_sorted(const T *data, octave_idx_type nel, const T *values, octave_idx_type nvalues, octave_idx_type *idx, bool rev=false)
void assign(const T *src, T *dest) const
octave::idx_vector * m_idx
rec_index_helper & operator=(const rec_index_helper &)=delete
const T * do_assign(const T *src, T *dest, int lev) const
rec_index_helper(const dim_vector &dv, const Array< octave::idx_vector > &ia)
void index(const T *src, T *dest) const
void do_fill(const T &val, T *dest, int lev) const
T * do_index(const T *src, T *dest, int lev) const
void fill(const T &val, T *dest) const
bool is_cont_range(octave_idx_type &l, octave_idx_type &u) const
~rec_permute_helper(void)
void permute(const T *src, T *dest) const
T * do_permute(const T *src, T *dest, int lev) const
static T * blk_trans(const T *src, T *dest, octave_idx_type nr, octave_idx_type nc)
octave_idx_type * m_stride
rec_permute_helper(const dim_vector &dv, const Array< octave_idx_type > &perm)
rec_permute_helper & operator=(const rec_permute_helper &)=delete
rec_permute_helper(const rec_permute_helper &)=delete
rec_resize_helper(const rec_resize_helper &)=delete
void do_resize_fill(const T *src, T *dest, const T &rfv, int lev) const
void resize_fill(const T *src, T *dest, const T &rfv) const
rec_resize_helper(const dim_vector &ndv, const dim_vector &odv)
rec_resize_helper & operator=(const rec_resize_helper &)=delete
if_then_else< is_class_type< T >::no, T, T const & >::result type
static OCTAVE_NORETURN void err_index_out_of_range(void)
octave::idx_vector idx_vector
void err_invalid_resize(void)
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
void err_del_index_out_of_range(bool is1d, octave_idx_type idx, octave_idx_type ext)
Complex log2(const Complex &x)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value)
T::size_type numel(const T &str)
const octave_base_value const Array< octave_idx_type > & ra_idx