26 #if ! defined (octave_idx_vector_h)
27 #define octave_idx_vector_h 1
29 #include "octave-config.h"
73 template <
typename T,
typename D>
friend class std::unique_ptr;
118 virtual std::ostream&
print (std::ostream& os)
const = 0;
151 { m_count++;
return this; }
157 OCTAVE_API std::ostream& print (std::ostream& os)
const;
188 {
return m_start + i * m_step; }
196 return m_len ?
std::max (
n, m_start + 1 + (m_step < 0 ? 0 : m_step * (m_len - 1))) :
n;
206 {
return m_start == 0 && m_step == 1 && m_len ==
n; }
215 OCTAVE_API std::ostream& print (std::ostream& os)
const;
217 OCTAVE_API range<double> unconvert (
void)
const;
244 template <
typename T>
259 { m_count++;
return this; }
264 {
return n == 1 && m_data == 0; }
270 OCTAVE_API std::ostream& print (std::ostream& os)
const;
287 : m_data (nullptr), m_len (0), m_ext (0), m_aowner (nullptr), m_orig_dims () { }
293 m_aowner (nullptr), m_orig_dims (od)
302 template <
typename T>
338 OCTAVE_API std::ostream& print (std::ostream& os)
const;
373 m_lsti (-1), m_lste (-1), m_aowner (nullptr), m_orig_dims (od)
400 { m_count++;
return this; }
407 {
return m_len ==
n && m_ext ==
n; }
409 const bool *
get_data (
void)
const {
return m_data; }
411 OCTAVE_API std::ostream& print (std::ostream& os)
const;
444 static OCTAVE_API idx_vector_rep * nil_rep (
void);
454 #if OCTAVE_SIZEOF_INT != OCTAVE_SIZEOF_IDX_TYPE
459 #if (OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_IDX_TYPE \
460 && OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_INT)
491 template <
typename T>
501 template <
typename T>
519 if (--m_rep->m_count == 0 && m_rep != nil_rep ())
527 if (--m_rep->m_count == 0 && m_rep != nil_rep ())
539 {
return m_rep->length (
n); }
542 {
return m_rep->extent (
n); }
545 {
return m_rep->xelem (
n); }
548 {
return m_rep->xelem (
n); }
551 {
return m_rep->xelem (
n); }
555 operator bool (
void)
const {
return true; }
558 {
return m_rep->idx_class () == class_colon; }
561 {
return m_rep->idx_class () == class_scalar; }
564 {
return m_rep->idx_class () == class_range; }
567 {
return m_rep->is_colon_equiv (
n); }
570 {
return idx_vector (m_rep->sort_uniq_clone (uniq)); }
573 {
return idx_vector (m_rep->sort_idx (sidx)); }
578 {
return orig_dimensions () (0); }
581 {
return orig_dimensions () (1); }
584 {
return (! is_colon () && orig_dimensions ().any_zero ()); }
588 std::ostream&
print (std::ostream& os)
const {
return m_rep->print (os); }
591 {
return a.
print (os); }
601 template <
typename T>
607 switch (m_rep->idx_class ())
610 std::copy_n (src,
len, dest);
618 const T *ssrc = src + start;
620 std::copy_n (ssrc,
len, dest);
622 std::reverse_copy (ssrc -
len + 1, ssrc + 1, dest);
624 std::fill_n (dest,
len, *ssrc);
636 dest[0] = src[
r->get_data ()];
645 dest[i] = src[data[i]];
652 const bool *data =
r->get_data ();
655 if (data[i]) *dest++ = src[i];
675 template <
typename T>
681 switch (m_rep->idx_class ())
684 std::copy_n (src,
len, dest);
692 T *sdest = dest + start;
694 std::copy_n (src,
len, sdest);
696 std::reverse_copy (src, src +
len, sdest -
len + 1);
708 dest[
r->get_data ()] = src[0];
717 dest[data[i]] = src[i];
724 const bool *data =
r->get_data ();
727 if (data[i]) dest[i] = *src++;
747 template <
typename T>
753 switch (m_rep->idx_class ())
756 std::fill_n (dest,
len, val);
764 T *sdest = dest + start;
766 std::fill_n (sdest,
len, val);
768 std::fill (sdest -
len + 1, sdest + 1, val);
780 dest[
r->get_data ()] = val;
796 const bool *data =
r->get_data ();
799 if (data[i]) dest[i] = val;
817 template <
typename Functor>
823 switch (m_rep->idx_class ())
836 for (i = start, j = start +
len; i < j; i++) body (i);
838 for (i = start, j = start -
len; i > j; i--) body (i);
840 for (i = 0, j = start; i <
len; i++, j += step) body (j);
847 body (
r->get_data ());
862 const bool *data =
r->get_data ();
865 if (data[i]) body (i);
885 template <
typename Functor>
891 switch (m_rep->idx_class ())
896 for (i = 0; i <
len && body (i); i++) ;
908 for (i = start, j = start +
len; i < j && body (i); i++) ;
910 for (i = start, j = start -
len; i > j && body (i); i--) ;
912 for (i = 0, j = start; i <
len && body (j); i++, j += step) ;
920 ret = (body (
r->get_data ()) ? 1 : 0);
929 for (i = 0; i <
len && body (data[i]); i++) ;
937 const bool *data =
r->get_data ();
998 unconvert (idx_class_type& iclass,
double&
scalar, range<double>&
range,
1013 {
return (*
this) (
n); }
1016 {
return is_colon_equiv (
n); }
1022 { *
this = sorted (uniq); }
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
dim_vector freeze(Array< octave::idx_vector > &ra_idx, const dim_vector &dimensions, int resize_ok)
bool isvector(const dim_vector &dim)
charNDArray max(char d, const charNDArray &m)
Vector representing the dimensions (size) of an Array.
virtual dim_vector orig_dimensions(void) const
virtual octave_idx_type extent(octave_idx_type n) const =0
virtual idx_base_rep * sort_uniq_clone(bool uniq=false)=0
idx_base_rep(const idx_base_rep &)=delete
virtual octave_idx_type length(octave_idx_type n) const =0
virtual idx_base_rep * sort_idx(Array< octave_idx_type > &)=0
virtual std::ostream & print(std::ostream &os) const =0
virtual idx_class_type idx_class(void) const
virtual octave_idx_type xelem(octave_idx_type i) const =0
virtual octave_idx_type checkelem(octave_idx_type i) const =0
virtual bool is_colon_equiv(octave_idx_type) const
virtual ~idx_base_rep(void)=default
refcount< octave_idx_type > m_count
bool is_colon_equiv(octave_idx_type) const
octave_idx_type xelem(octave_idx_type i) const
octave_idx_type extent(octave_idx_type n) const
idx_colon_rep(void)=default
octave_idx_type length(octave_idx_type n) const
idx_colon_rep(const idx_colon_rep &idx)=delete
idx_base_rep * sort_uniq_clone(bool=false)
idx_class_type idx_class(void) const
idx_mask_rep(bool *data, octave_idx_type len, octave_idx_type ext, const dim_vector &od, direct)
idx_mask_rep(const idx_mask_rep &idx)=delete
dim_vector orig_dimensions(void) const
octave_idx_type length(octave_idx_type) const
idx_mask_rep(void)=delete
const bool * get_data(void) const
octave_idx_type extent(octave_idx_type n) const
idx_class_type idx_class(void) const
idx_base_rep * sort_uniq_clone(bool=false)
bool is_colon_equiv(octave_idx_type n) const
bool is_colon_equiv(octave_idx_type n) const
octave_idx_type get_step(void) const
octave_idx_type get_start(void) const
idx_class_type idx_class(void) const
idx_range_rep(const idx_range_rep &idx)=delete
idx_range_rep(void)=delete
octave_idx_type length(octave_idx_type) const
dim_vector orig_dimensions(void) const
octave_idx_type xelem(octave_idx_type i) const
octave_idx_type extent(octave_idx_type n) const
idx_range_rep(octave_idx_type start, octave_idx_type len, octave_idx_type step, direct)
idx_scalar_rep(const idx_scalar_rep &idx)=delete
octave_idx_type extent(octave_idx_type n) const
dim_vector orig_dimensions(void) const
octave_idx_type get_data(void) const
bool is_colon_equiv(octave_idx_type n) const
idx_scalar_rep(void)=delete
octave_idx_type length(octave_idx_type) const
idx_class_type idx_class(void) const
idx_base_rep * sort_uniq_clone(bool=false)
octave_idx_type xelem(octave_idx_type) const
idx_scalar_rep(octave_idx_type i, direct)
octave_idx_type xelem(octave_idx_type i) const
idx_vector_rep(octave_idx_type *data, octave_idx_type len, octave_idx_type ext, const dim_vector &od, direct)
idx_vector_rep(const idx_vector_rep &idx)=delete
Array< octave_idx_type > * m_aowner
idx_class_type idx_class(void) const
const octave_idx_type * get_data(void) const
const octave_idx_type * m_data
octave_idx_type length(octave_idx_type) const
dim_vector orig_dimensions(void) const
octave_idx_type extent(octave_idx_type n) const
octave_idx_type xelem(octave_idx_type n) const
octave_idx_type orig_rows(void) const
idx_vector(const Array< octave_idx_type > &inda, octave_idx_type ext)
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
idx_vector(octave_int< T > x)
idx_vector(idx_base_rep *r)
idx_vector(const range< double > &r)
idx_vector(const Sparse< bool > &nda)
void loop(octave_idx_type n, Functor body) const
idx_vector(const Array< double > &nda)
octave_idx_type bloop(octave_idx_type n, Functor body) const
octave_idx_type length(octave_idx_type n=0) const
octave_idx_type index(const T *src, octave_idx_type n, T *dest) const
void sort(bool uniq=false)
idx_vector(const Array< octave_int< T >> &nda)
bool is_scalar(void) const
octave_idx_type elem(octave_idx_type n) const
octave_idx_type assign(const T *src, octave_idx_type n, T *dest) const
octave_idx_type checkelem(octave_idx_type n) const
dim_vector orig_dimensions(void) const
idx_vector(const Array< float > &nda)
bool is_range(void) const
idx_vector sorted(Array< octave_idx_type > &sidx) const
std::ostream & print(std::ostream &os) const
static idx_vector make_range(octave_idx_type start, octave_idx_type step, octave_idx_type len)
idx_vector(const Array< octave_idx_type > &inda)
octave_idx_type orig_columns(void) const
idx_vector(const idx_vector &a)
idx_vector(octave_idx_type start, octave_idx_type limit, octave_idx_type step=1)
bool is_colon_equiv(octave_idx_type n, int) const
octave_idx_type max(void) const
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
idx_vector(octave_idx_type i)
int orig_empty(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave::idx_vector idx_vector
F77_RET_T const F77_DBLE * x
static bool scalar(const dim_vector &dims)