26 #if defined (HAVE_CONFIG_H)
45 OCTAVE_NORETURN
static
49 (*current_liboctave_error_handler) (
"invalid range used as index");
55 (*current_liboctave_error_handler)
56 (
"internal error: idx_vector index out of range");
77 (*current_liboctave_error_handler)
78 (
"internal error: as_array not allowed for this index class");
89 (*current_liboctave_error_handler)
90 (
"internal error: invalid character converted to idx_vector; must be ':'");
108 (*current_liboctave_error_handler)
109 (
"internal error: idx_colon_rep::sort_idx");
122 len (_step ? std::
max ((_limit - _start) / _step,
143 if (
r.all_elements_are_ints ())
155 double b =
r.base ();
156 double inc =
r.inc ();
165 if (i < 0 || i >=
len)
168 return start + i*step;
186 if (step < 0 && len > 0)
206 os << start <<
':' << step <<
':' << start +
len*step;
213 return Range (
static_cast<double> (start+1),
214 static_cast<double> (step),
len);
231 if (i <= 0 && ! conv_error)
245 if (
static_cast<double> (i) !=
x)
257 template <
typename T>
267 template <
typename T>
318 template <
typename T>
321 aowner (nullptr), orig_dims (nda.dims ())
378 aowner (nullptr), orig_dims (
len,
len)
391 :
idx_base_rep (), data (nullptr),
len (nnz), ext (0), aowner (nullptr),
420 aowner (nullptr), orig_dims ()
437 d[k++] = j * nr + bnda.
ridx (i);
456 if (n < 0 || n >=
len)
472 std::unique_ptr<idx_vector_rep> new_rep
479 new_rep->data = new_data;
481 std::copy_n (data,
len, new_data);
490 new_rep->len = new_len;
491 if (new_rep->orig_dims.ndims () == 2 && new_rep->orig_dims(0) == 1)
508 new_rep->len = new_len;
509 if (new_rep->orig_dims.ndims () == 2 && new_rep->orig_dims(0) == 1)
515 new_rep->data = new_data;
529 new_rep->data = new_data;
538 return new_rep.release ();
545 std::unique_ptr<idx_vector_rep> new_rep
551 idx.
clear (orig_dims);
557 new_rep->data = new_data;
558 std::copy_n (data,
len, new_data);
562 lsort.
sort (new_data, idx_data,
len);
572 idx.
clear (orig_dims);
576 new_rep->data = new_data;
594 return new_rep.release ();
603 os << data[i] <<
',' <<
' ';
647 lsti (-1), lste (-1), aowner (nullptr), orig_dims (
len,
len)
651 bool *
d =
new bool [1];
661 lsti (-1), lste (-1), aowner (nullptr), orig_dims ()
668 while (
ext > 0 && ! bnda(
ext-1))
693 while (! data[++lste]) ;
700 if (data[++lste]) --
n;
708 if (n < 0 || n >=
len)
720 os << data[i] <<
',' <<
' ';
779 if (nnz <= bnda.
numel () / factor)
789 bool reduced =
false;
891 if ((l*t ==
n && tj == 1) || (t == 0 && tj == 0))
970 if (
r->get_step () == 1)
973 u = l +
r->length (
n);
1046 assert (
r !=
nullptr);
1048 return r->get_data ();
1059 (*current_liboctave_error_handler) (
"colon not allowed");
1069 for (i = start, j = start +
len; i < j; i++) *data++ = i;
1070 else if (step == -1)
1071 for (i = start, j = start -
len; i > j; i--) *data++ = i;
1073 for (i = 0, j = start; i <
len; i++, j += step) *data++ = j;
1080 *data =
r->get_data ();
1088 std::copy_n (rdata,
len, data);
1095 const bool *mask =
r->get_data ();
1114 (*current_liboctave_error_handler)
1115 (
"internal error: out of range complement index requested");
1123 const bool *data =
r->get_data ();
1126 ndata[i] = ! data[i];
1127 std::fill_n (ndata + ext,
n - ext,
true);
1192 idx.
xelem (ri[i]) = i;
1210 const bool *data =
r->get_data ();
1219 ext = (
len > 0 ? idata[
len - 1] + 1 : 0);
1241 range =
r->unconvert ();
1255 array =
r->unconvert ();
1262 mask =
r->unconvert ();
1287 if (! resize_ok &&
extent (z_len) > z_len)
1289 (*current_liboctave_error_handler)
1290 (
"invalid matrix index = %" OCTAVE_IDX_TYPE_FORMAT,
extent (z_len));
1317 #define INSTANTIATE_SCALAR_VECTOR_REP_CONST(T) \
1318 template OCTAVE_API idx_vector::idx_scalar_rep::idx_scalar_rep (T); \
1319 template OCTAVE_API idx_vector::idx_vector_rep::idx_vector_rep (const Array<T>&);
template class OCTAVE_API Array< bool >
template class OCTAVE_API Array< octave_idx_type >
octave_idx_type nnz(void) const
Count nonzero elements.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
Array< octave_idx_type > find(octave_idx_type n=-1, bool backward=false) const
Find indices of (at most n) nonzero elements.
const T * data(void) const
Size of the specified dimension.
Array< T > reshape(octave_idx_type nr, octave_idx_type nc) const
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.
octave_idx_type cols(void) const
octave_idx_type * cidx(void)
octave_idx_type rows(void) const
dim_vector dims(void) const
octave_idx_type * ridx(void)
Vector representing the dimensions (size) of an Array.
bool isvector(void) const
dim_vector make_nd_vector(octave_idx_type n) const
virtual Array< octave_idx_type > as_array(void)
virtual octave_idx_type length(octave_idx_type n) const =0
virtual idx_class_type idx_class(void) const
virtual bool is_colon_equiv(octave_idx_type) const
idx_colon_rep(void)=default
std::ostream & print(std::ostream &os) const
OCTAVE_NORETURN idx_base_rep * sort_idx(Array< octave_idx_type > &)
octave_idx_type checkelem(octave_idx_type i) const
Array< octave_idx_type > as_array(void)
idx_mask_rep(void)=delete
idx_base_rep * sort_idx(Array< octave_idx_type > &)
octave_idx_type checkelem(octave_idx_type i) const
std::ostream & print(std::ostream &os) const
octave_idx_type xelem(octave_idx_type i) const
Array< bool > unconvert(void) const
octave_idx_type get_step(void) const
octave_idx_type checkelem(octave_idx_type i) const
octave_idx_type get_start(void) const
Range unconvert(void) const
idx_range_rep(void)=delete
octave_idx_type length(octave_idx_type) const
idx_base_rep * sort_idx(Array< octave_idx_type > &)
Array< octave_idx_type > as_array(void)
idx_base_rep * sort_uniq_clone(bool uniq=false)
std::ostream & print(std::ostream &os) const
octave_idx_type get_data(void) const
Array< octave_idx_type > as_array(void)
idx_scalar_rep(void)=delete
octave_idx_type checkelem(octave_idx_type i) const
std::ostream & print(std::ostream &os) const
idx_base_rep * sort_idx(Array< octave_idx_type > &)
double unconvert(void) const
Array< octave_idx_type > as_array(void)
idx_base_rep * sort_uniq_clone(bool uniq=false)
std::ostream & print(std::ostream &os) const
Array< double > unconvert(void) const
octave_idx_type checkelem(octave_idx_type i) const
const octave_idx_type * data
idx_base_rep * sort_idx(Array< octave_idx_type > &)
octave_idx_type ones_count(void) const
octave_idx_type xelem(octave_idx_type n) const
const octave_idx_type * raw(void)
bool is_colon(void) const
idx_vector sorted(bool uniq=false) const
octave_idx_type fill(const T &val, octave_idx_type n, T *dest) const
static const idx_vector colon
bool isvector(void) const
bool maybe_reduce(octave_idx_type n, const idx_vector &j, octave_idx_type nj)
void copy_data(octave_idx_type *data) const
void unconvert(idx_class_type &iclass, double &scalar, Range &range, Array< double > &array, Array< bool > &mask) const
octave_idx_type length(octave_idx_type n=0) const
octave_idx_type elem(octave_idx_type n) const
idx_vector unmask(void) const
octave_idx_type freeze(octave_idx_type z_len, const char *tag, bool resize_ok=false)
bool is_cont_range(octave_idx_type n, octave_idx_type &l, octave_idx_type &u) const
idx_vector complement(octave_idx_type n) const
dim_vector orig_dimensions(void) const
bool is_permutation(octave_idx_type n) const
Array< octave_idx_type > as_array(void) const
idx_vector inverse_permutation(octave_idx_type n) const
static idx_vector_rep * err_rep(void)
octave_idx_type max(void) const
octave_idx_type increment(void) const
static idx_vector_rep * nil_rep(void)
idx_class_type idx_class(void) const
octave_idx_type extent(octave_idx_type n) const
bool is_colon_equiv(octave_idx_type n) const
void set_compare(compare_fcn_type comp)
void sort(T *data, octave_idx_type nel)
#define INSTANTIATE_SCALAR_VECTOR_REP_CONST(T)
static OCTAVE_NORETURN void err_invalid_range(void)
static void err_index_out_of_range(void)
octave_idx_type convert_index(octave_idx_type i, bool &conv_error, octave_idx_type &ext)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
std::complex< T > trunc(const std::complex< T > &x)
Complex log2(const Complex &x)
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
#define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value)
T::size_type numel(const T &str)
static bool scalar(const dim_vector &dims)
octave_value::octave_value(const Array< char > &chm, char type) return retval