26 #if defined (HAVE_CONFIG_H)
42 if (
n == dimensions.
ndims ())
44 for (
int i = 0; i <
n; i++)
66 int nda = dimensions.
ndims ();
68 for (
int i = start_dimension; i <
n; i++)
70 if (
ra_idx(i) < (i < nda ? dimensions(i) : 1))
126 for (
int i = 0; i <
n; i++)
149 for (
int i = 0; i <
n; i++)
182 octave::err_index_out_of_range (1, 1,
n+1, dims.
numel (), dims);
195 octave::err_index_out_of_range (2, 1, i+1, dims(0), dims);
196 if (j >= dims.
numel (1))
197 octave::err_index_out_of_range (2, 2, j+1, dims.
numel (1), dims);
199 return j*dims(0) + i;
213 octave::err_index_out_of_range (3, 1, i+1, dims(0), dims);
215 octave::err_index_out_of_range (3, 2, j+1, dims(1), dims);
216 if (k >= dims.
numel (2))
217 octave::err_index_out_of_range (3, 3, k+1, dims.
numel (2), dims);
219 return (k*dims(1) + j)*dims(0) + i;
227 for (
int d = 0;
d < nd;
d++)
232 octave::err_index_out_of_range (nd,
d+1,
ra_idx(
d)+1, dv(
d), dims);
244 retval(i) = a(i).
elem (0);
267 assert (
n == dimensions.
ndims ());
271 static const char *tag[3] = {
"row",
"column",
nullptr };
273 for (
int i = 0; i <
n; i++)
274 retval(i) =
ra_idx(i).freeze (dimensions(i), tag[i < 2 ? i : 2],
285 bool found_first =
false;
287 for (
int i = 0; i <
n; i++)
305 octave_unused_parameter (
ra_idx);
320 if (
ra_idx(i).orig_empty ())
338 int n = frozen_lengths.
ndims ();
344 if (!
ra_idx(i).is_colon_equiv (frozen_lengths(i)))
380 retval(i) =
ra_idx(i).elem (result_idx(i));
390 int n_dims = dims.
ndims ();
394 for (
int i = 0; i < n_dims; i++)
397 assert (idx > 0 || idx < dims.
numel ());
410 int ial = ia.
numel ();
411 int rhdvl = rhdv.
ndims ();
413 bool *scalar =
new bool [ial];
414 bool *colon =
new bool [ial];
417 bool all_colons =
true;
418 for (
int i = 0; i < ial; i++)
421 scalar[i] = ia(i).is_scalar ();
422 colon[i] = ia(i).is_colon ();
423 if (! scalar[i]) nonsc++;
424 if (! colon[i]) rdv(i) = ia(i).extent (0);
425 all_colons = all_colons && colon[i];
435 else if (nonsc == rhdvl)
437 for (
int i = 0, j = 0; i < ial; i++)
439 if (scalar[i])
continue;
449 int rhdv0l = rhdv0.
ndims ();
450 for (
int i = 0, j = 0; i < ial; i++)
452 if (scalar[i])
continue;
454 rdv(i) = (j < rhdv0l) ? rhdv0(j++) : 1;
468 bool icol = i.is_colon ();
469 bool jcol = j.is_colon ();
471 if (icol && jcol && rhdv.
ndims () == 2)
476 else if (rhdv.
ndims () == 2
477 && ! i.is_scalar () && ! j.is_scalar ())
479 rdv(0) = (icol ? rhdv(0) : i.extent (0));
480 rdv(1) = (jcol ? rhdv(1) : j.extent (0));
487 rdv(0) = i.extent (0);
490 else if (! i.is_scalar ())
492 rdv(1) = j.extent (0);
495 else if (! j.is_scalar ())
509 (*current_liboctave_error_handler) (
"sub2ind: needs at least 2 indices");
512 bool all_ranges =
true;
522 all_ranges = all_ranges && idx.is_range ();
524 clen = idx.length (
n);
525 else if (clen != idx.length (
n))
526 (*current_liboctave_error_handler)
527 (
"sub2ind: lengths of indices must match");
529 if (idx.extent (
n) >
n)
530 octave::err_index_out_of_range (
len, i+1, idx.extent (
n),
n, dv);
532 catch (octave::index_exception& ie)
534 ie.set_pos_if_unset (
len, i+1);
536 std::string msg = ie.message ();
537 (*current_liboctave_error_with_id_handler)
538 (ie.err_id (),
"%s", msg.c_str ());
551 idx = dvx(i) * idx + idxa(i)(0);
554 else if (all_ranges && clen != 0)
563 start = dvx(i) * start + xstart;
564 step = dvx(i) * step + xstep;
566 retval = octave::idx_vector::make_range (start, step, clen);
584 (*idx_vec++ *=
n) += k;
588 idxa(i).copy_data (idx_vec);
605 if (idx.is_scalar ())
610 retval(j) = k % dv(j);
614 retval(
n-1) = idx(0) <
numel ? k % dv(
n-1) : k;
629 rdata[j](i) = k % dv(j);
633 rdata[
n-1](i) = idx(i) <
numel ? k % dv(
n-1) : k;
637 retval(j) = rdata[j];
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Array< octave::idx_vector > conv_to_array(const octave::idx_vector *tmp, const octave_idx_type len)
bool is_scalar(const dim_vector &dim)
int permute_vector_compare(const void *a, const void *b)
dim_vector zero_dims_inquire(const Array< octave::idx_vector > &ia, const dim_vector &rhdv)
Array< octave_idx_type > conv_to_int_array(const Array< octave::idx_vector > &a)
octave::idx_vector sub2ind(const dim_vector &dv, const Array< octave::idx_vector > &idxa)
bool all_ones(const Array< octave_idx_type > &arr)
octave_idx_type num_ones(const Array< octave_idx_type > &ra_idx)
bool all_colon_equiv(const Array< octave::idx_vector > &ra_idx, const dim_vector &frozen_lengths)
Array< octave_idx_type > get_ra_idx(octave_idx_type idx, const dim_vector &dims)
Array< octave_idx_type > get_elt_idx(const Array< octave::idx_vector > &ra_idx, const Array< octave_idx_type > &result_idx)
bool vector_equivalent(const dim_vector &dv)
bool any_ones(const Array< octave_idx_type > &arr)
dim_vector freeze(Array< octave::idx_vector > &ra_idx, const dim_vector &dimensions, int resize_ok)
bool any_orig_empty(const Array< octave::idx_vector > &ra_idx)
Array< octave::idx_vector > ind2sub(const dim_vector &dv, const octave::idx_vector &idx)
bool isvector(const dim_vector &dim)
bool index_in_bounds(const Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
bool all_ok(const Array< octave::idx_vector > &ra_idx)
void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension)
octave_idx_type get_scalar_idx(Array< octave_idx_type > &idx, dim_vector &dims)
T & elem(octave_idx_type n)
Size of the specified dimension.
T * fortran_vec()
Size of the specified dimension.
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
octave_idx_type numel() const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
octave_idx_type compute_index(const octave_idx_type *idx) const
Linear index from an index tuple.
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)
static dim_vector alloc(int n)
octave_idx_type ndims() const
Number of dimensions.
void chop_all_singletons()
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
virtual octave_idx_type numel() const
octave::idx_vector idx_vector
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
T::size_type numel(const T &str)
const octave_base_value const Array< octave_idx_type > & ra_idx