26 #if defined (HAVE_CONFIG_H)
49 (*current_liboctave_error_handler) (
"invalid range used as index");
54 (*current_liboctave_error_handler)
55 (
"internal error: idx_vector index out of range");
66 (*current_liboctave_error_handler)
67 (
"internal error: as_array not allowed for this index class");
77 (*current_liboctave_error_handler)
78 (
"internal error: invalid character converted to idx_vector; must be ':'");
93 (*current_liboctave_error_handler)
94 (
"internal error: idx_colon_rep::sort_idx");
108 ? std::
max ((limit - start + step - (step > 0 ? 1 : -1)) / step,
129 if (
r.all_elements_are_ints ())
141 double b =
r.base ();
142 double inc =
r.increment ();
151 if (i < 0 || i >= m_len)
154 return m_start + i*m_step;
171 if (m_step < 0 && m_len > 0)
173 idx.
clear (1, m_len);
175 idx.
xelem (i) = m_len - 1 - i;
180 idx.
clear (1, m_len);
190 os << m_start <<
':' << m_step <<
':' << m_start + m_len *m_step;
196 return range<double>::make_n_element_range
197 (
static_cast<double> (m_start+1),
static_cast<double> (m_step), m_len);
204 retval.
xelem (i) = m_start + i*m_step;
224 if (
static_cast<double> (i) !=
x)
235 template <
typename T>
243 template <
typename T>
292 template <
typename T>
295 m_aowner (nullptr), m_orig_dims (nda.dims ())
334 m_orig_dims (inda.dims ())
349 :
idx_base_rep (), m_data (nullptr), m_len (b ? 1 : 0), m_ext (0),
350 m_aowner (nullptr), m_orig_dims (m_len, m_len)
363 :
idx_base_rep (), m_data (nullptr), m_len (nnz), m_ext (0),
364 m_aowner (nullptr), m_orig_dims ()
391 :
idx_base_rep (), m_data (nullptr), m_len (bnda.nnz ()), m_ext (0),
392 m_aowner (nullptr), m_orig_dims ()
409 d[k++] = j * nr + bnda.
ridx (i);
428 if (n < 0 || n >= m_len)
444 std::unique_ptr<idx_vector_rep> new_rep
451 new_rep->m_data = new_data;
453 std::copy_n (m_data, m_len, new_data);
456 lsort.
sort (new_data, m_len);
462 new_rep->m_len = new_len;
463 if (new_rep->m_orig_dims.ndims () == 2 && new_rep->m_orig_dims(0) == 1)
464 new_rep->m_orig_dims =
dim_vector (1, new_len);
466 new_rep->m_orig_dims =
dim_vector (new_len, 1);
474 has[m_data[i]] =
true;
480 new_rep->m_len = new_len;
481 if (new_rep->m_orig_dims.ndims () == 2 && new_rep->m_orig_dims(0) == 1)
482 new_rep->m_orig_dims =
dim_vector (1, new_len);
484 new_rep->m_orig_dims =
dim_vector (new_len, 1);
487 new_rep->m_data = new_data;
501 new_rep->m_data = new_data;
510 return new_rep.release ();
517 std::unique_ptr<idx_vector_rep> new_rep
523 idx.
clear (m_orig_dims);
529 new_rep->m_data = new_data;
530 std::copy_n (m_data, m_len, new_data);
534 lsort.
sort (new_data, idx_data, m_len);
544 idx.
clear (m_orig_dims);
548 new_rep->m_data = new_data;
566 return new_rep.release ();
574 os << m_data[i] <<
',' <<
' ';
577 os << m_data[m_len-1];
588 retval.
xelem (i) = m_data[i] + 1;
615 :
idx_base_rep (), m_data (nullptr), m_len (b ? 1 : 0), m_ext (0),
616 m_lsti (-1), m_lste (-1), m_aowner (nullptr), m_orig_dims (m_len, m_len)
620 bool *
d =
new bool [1];
630 m_lsti (-1), m_lste (-1), m_aowner (nullptr), m_orig_dims ()
661 while (! m_data[++m_lste]) ;
668 if (m_data[++m_lste]) --
n;
675 if (n < 0 || n >= m_len)
686 os << m_data[i] <<
',' <<
' ';
689 os << m_data[m_ext-1];
704 retval.
xelem (i) = m_data[i];
718 retval.
xelem (j++) = i;
727 idx.
clear (m_len, 1);
743 if (nnz <= bnda.
numel () / factor)
752 bool reduced =
false;
854 if ((l*t ==
n && tj == 1) || (t == 0 && tj == 0))
932 if (
r->get_step () == 1)
935 u = l +
r->length (
n);
1006 assert (
r !=
nullptr);
1008 return r->get_data ();
1018 (*current_liboctave_error_handler) (
"colon not allowed");
1028 for (i = m_start, j = m_start + m_len; i < j; i++) *m_data++ = i;
1029 else if (m_step == -1)
1030 for (i = m_start, j = m_start - m_len; i > j; i--) *m_data++ = i;
1032 for (i = 0, j = m_start; i < m_len; i++, j += m_step) *m_data++ = j;
1039 *m_data =
r->get_data ();
1047 std::copy_n (rdata, m_len, m_data);
1054 const bool *mask =
r->get_data ();
1072 (*current_liboctave_error_handler)
1073 (
"internal error: out of range complement index requested");
1081 const bool *m_data =
r->get_data ();
1084 ndata[i] = ! m_data[i];
1085 std::fill_n (ndata + m_ext,
n - m_ext,
true);
1100 bool retval =
false;
1148 idx.
xelem (ri[i]) = i;
1165 const bool *m_data =
r->get_data ();
1174 m_ext = (m_len > 0 ? idata[m_len - 1] + 1 : 0);
1176 return new idx_vector_rep (idata, m_len, m_ext,
r->orig_dimensions (),
1210 array =
r->unconvert ();
1217 mask =
r->unconvert ();
1240 if (! resize_ok &&
extent (z_len) > z_len)
1241 (*current_liboctave_error_handler)
1242 (
"invalid matrix index = %" OCTAVE_IDX_TYPE_FORMAT,
extent (z_len));
1264 #define INSTANTIATE_SCALAR_VECTOR_REP_CONST(T) \
1265 template OCTAVE_API idx_vector::idx_scalar_rep::idx_scalar_rep (T); \
1266 template OCTAVE_API idx_vector::idx_vector_rep::idx_vector_rep (const Array<T>&);
template class OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API Array< bool >
OCTARRAY_API void clear(void)
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_API octave_idx_type nnz(void) const
Count nonzero elements.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
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 Array< octave_idx_type > find(octave_idx_type n=-1, bool backward=false) const
Find indices of (at most n) nonzero elements.
OCTARRAY_API void fill(const T &val)
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type rows(void) const
octave_idx_type * cidx(void)
octave_idx_type * ridx(void)
dim_vector dims(void) const
octave_idx_type cols(void) const
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
OCTAVE_API std::ostream & print(std::ostream &os) const
OCTAVE_NORETURN idx_base_rep * sort_idx(Array< octave_idx_type > &)
OCTAVE_API octave_idx_type checkelem(octave_idx_type i) const
OCTAVE_API Array< octave_idx_type > as_array(void)
OCTAVE_API ~idx_mask_rep(void)
idx_mask_rep(void)=delete
OCTAVE_API idx_base_rep * sort_idx(Array< octave_idx_type > &)
octave_idx_type checkelem(octave_idx_type i) const
OCTAVE_API std::ostream & print(std::ostream &os) const
octave_idx_type xelem(octave_idx_type i) const
OCTAVE_API 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
idx_range_rep(void)=delete
octave_idx_type length(octave_idx_type) const
OCTAVE_API idx_base_rep * sort_idx(Array< octave_idx_type > &)
OCTAVE_API range< double > unconvert(void) const
OCTAVE_API Array< octave_idx_type > as_array(void)
OCTAVE_API idx_base_rep * sort_uniq_clone(bool uniq=false)
OCTAVE_API std::ostream & print(std::ostream &os) const
octave_idx_type get_data(void) const
OCTAVE_API Array< octave_idx_type > as_array(void)
idx_scalar_rep(void)=delete
OCTAVE_API octave_idx_type checkelem(octave_idx_type i) const
OCTAVE_API std::ostream & print(std::ostream &os) const
OCTAVE_API idx_base_rep * sort_idx(Array< octave_idx_type > &)
OCTAVE_API double unconvert(void) const
OCTAVE_API Array< octave_idx_type > as_array(void)
const octave_idx_type * m_data
idx_base_rep * sort_uniq_clone(bool uniq=false)
OCTAVE_API std::ostream & print(std::ostream &os) const
OCTAVE_API Array< double > unconvert(void) const
OCTAVE_API octave_idx_type checkelem(octave_idx_type i) const
OCTAVE_API idx_base_rep * sort_idx(Array< octave_idx_type > &)
OCTAVE_API octave_idx_type ones_count(void) const
octave_idx_type xelem(octave_idx_type n) const
const OCTAVE_API 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
OCTAVE_API bool isvector(void) const
OCTAVE_API bool maybe_reduce(octave_idx_type n, const idx_vector &j, octave_idx_type nj)
OCTAVE_API void copy_data(octave_idx_type *data) const
OCTAVE_API void unconvert(idx_class_type &iclass, double &scalar, range< double > &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
OCTAVE_API idx_vector unmask(void) const
OCTAVE_API octave_idx_type freeze(octave_idx_type z_len, const char *tag, bool resize_ok=false)
OCTAVE_API bool is_cont_range(octave_idx_type n, octave_idx_type &l, octave_idx_type &u) const
OCTAVE_API idx_vector complement(octave_idx_type n) const
dim_vector orig_dimensions(void) const
OCTAVE_API bool is_permutation(octave_idx_type n) const
OCTAVE_API Array< octave_idx_type > as_array(void) const
OCTAVE_API idx_vector inverse_permutation(octave_idx_type n) const
octave_idx_type max(void) const
OCTAVE_API octave_idx_type increment(void) const
static OCTAVE_API 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(const compare_fcn_type &comp)
void sort(T *data, octave_idx_type nel)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define INSTANTIATE_SCALAR_VECTOR_REP_CONST(T)
octave_idx_type convert_index(octave_idx_type i, octave_idx_type &ext)
static OCTAVE_NORETURN void err_invalid_range(void)
static OCTAVE_NORETURN void err_index_out_of_range(void)
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
Complex log2(const Complex &x)
std::complex< T > trunc(const std::complex< T > &x)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
#define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value)
T::size_type numel(const T &str)
static bool scalar(const dim_vector &dims)