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++)
196 if (j >= dims.
numel (1))
199 return j*dims(0) + i;
216 if (k >= dims.
numel (2))
219 return (k*dims(1) + j)*dims(0) + i;
227 for (
int d = 0;
d < nd;
d++)
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++)
329 if (
ra_idx(i).orig_empty ())
347 int n = frozen_lengths.
ndims ();
353 if (!
ra_idx(i).is_colon_equiv (frozen_lengths(i)))
399 int n_dims = dims.
ndims ();
403 for (
int i = 0; i < n_dims; i++)
406 assert (idx > 0 || idx < dims.
numel ());
415 for (
int i = 0; i < n_dims; i++)
417 std::cout <<
"idx: " << idx <<
", var: " << var
418 <<
", dims(" << i <<
"): " << dims(i) <<
"\n";
419 retval(i) = ((int)
floor(((idx) / (
double)var))) % dims(i);
431 int ial = ia.
numel ();
432 int rhdvl = rhdv.
ndims ();
434 bool *
scalar =
new bool [ial];
435 bool *colon =
new bool [ial];
438 bool all_colons =
true;
439 for (
int i = 0; i < ial; i++)
442 scalar[i] = ia(i).is_scalar ();
443 colon[i] = ia(i).is_colon ();
445 if (! colon[i]) rdv(i) = ia(i).extent (0);
446 all_colons = all_colons && colon[i];
456 else if (nonsc == rhdvl)
458 for (
int i = 0, j = 0; i < ial; i++)
470 int rhdv0l = rhdv0.
ndims ();
471 for (
int i = 0, j = 0; i < ial; i++)
475 rdv(i) = (j < rhdv0l) ? rhdv0(j++) : 1;
492 if (icol && jcol && rhdv.
ndims () == 2)
497 else if (rhdv.
ndims () == 2
500 rdv(0) = (icol ? rhdv(0) : i.
extent (0));
501 rdv(1) = (jcol ? rhdv(1) : j.
extent (0));
529 :
ind(_ind),
n(_n) { }
541 (*current_liboctave_error_handler) (
"sub2ind: needs at least 2 indices");
544 bool all_ranges =
true;
554 all_ranges = all_ranges && idx.
is_range ();
557 else if (clen != idx.
length (
n))
558 (*current_liboctave_error_handler)
559 (
"sub2ind: lengths of indices must match");
568 std::string msg = e.message ();
569 (*current_liboctave_error_with_id_handler)
570 (e.
err_id (),
"%s", msg.c_str ());
583 idx = dvx(i) * idx + idxa(i)(0);
586 else if (all_ranges && clen != 0)
595 start = dvx(i) * start + xstart;
596 step = dvx(i) * step + xstep;
610 idxa(i).copy_data (idx_vec);
628 (*current_liboctave_error_handler) (
"ind2sub: index out of range");
652 rdata[j](i) = k % dv(j);
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
bool is_scalar(const dim_vector &dim)
int permute_vector_compare(const void *a, const void *b)
Array< idx_vector > conv_to_array(const idx_vector *tmp, const octave_idx_type len)
Array< octave_idx_type > conv_to_int_array(const Array< idx_vector > &a)
bool all_ones(const Array< octave_idx_type > &arr)
octave_idx_type num_ones(const Array< octave_idx_type > &ra_idx)
Array< octave_idx_type > get_ra_idx(octave_idx_type idx, const dim_vector &dims)
Array< idx_vector > ind2sub(const dim_vector &dv, const idx_vector &idx)
bool vector_equivalent(const dim_vector &dv)
bool any_ones(const Array< octave_idx_type > &arr)
idx_vector sub2ind(const dim_vector &dv, const Array< idx_vector > &idxa)
Array< octave_idx_type > get_elt_idx(const Array< idx_vector > &ra_idx, const Array< octave_idx_type > &result_idx)
dim_vector freeze(Array< idx_vector > &ra_idx, const dim_vector &dimensions, int resize_ok)
dim_vector zero_dims_inquire(const Array< idx_vector > &ia, const dim_vector &rhdv)
bool any_orig_empty(const Array< idx_vector > &ra_idx)
bool isvector(const dim_vector &dim)
bool index_in_bounds(const Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
bool all_colon_equiv(const Array< idx_vector > &ra_idx, const dim_vector &frozen_lengths)
bool all_ok(const Array< 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)
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
T & elem(octave_idx_type n)
Size of the specified dimension.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
const T * fortran_vec(void) const
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
void chop_all_singletons(void)
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(void) const
Number of dimensions.
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
bool is_colon(void) const
octave_idx_type length(octave_idx_type n=0) const
bool is_scalar(void) const
dim_vector orig_dimensions(void) const
bool is_range(void) const
static idx_vector make_range(octave_idx_type start, octave_idx_type step, octave_idx_type len)
octave_idx_type extent(octave_idx_type n) const
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
virtual const char * err_id(void) const =0
void set_var(const std::string &var_arg="")
virtual octave_idx_type numel(void) const
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
std::complex< T > floor(const std::complex< T > &x)
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
void err_index_out_of_range(int nd, int dim, octave_idx_type idx, octave_idx_type ext, const dim_vector &dv)
#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
static bool scalar(const dim_vector &dims)
octave_value::octave_value(const Array< char > &chm, char type) return retval
sub2ind_helper(octave_idx_type *_ind, octave_idx_type _n)
void operator()(octave_idx_type k)