26 #if ! defined (octave_idx_vector_h)
27 #define octave_idx_vector_h 1
29 #include "octave-config.h"
42 template <
typename T>
class Array;
43 template <
typename T>
class Sparse;
69 template <
typename T,
typename D>
friend class std::unique_ptr;
114 virtual std::ostream&
print (std::ostream& os)
const = 0;
149 { count++;
return this; }
155 std::ostream& print (std::ostream& os)
const;
185 {
return start + i * step; }
193 return len ?
std::max (
n, start + 1 + (step < 0 ? 0 : step * (
len - 1)))
204 {
return start == 0 && step == 1 &&
len ==
n; }
213 std::ostream& print (std::ostream& os)
const;
215 Range unconvert (
void)
const;
243 template <
typename T>
258 { count++;
return this; }
263 {
return n == 1 && data == 0; }
269 std::ostream& print (std::ostream& os)
const;
271 double unconvert (
void)
const;
286 : data (nullptr),
len (0), ext (0), aowner (nullptr), orig_dims ()
293 aowner (nullptr), orig_dims (od)
302 template <
typename T>
338 std::ostream& print (std::ostream& os)
const;
373 lsti (-1), lste (-1), aowner (nullptr), orig_dims (od)
400 { count++;
return this; }
407 {
return len ==
n && ext ==
n; }
409 const bool *
get_data (
void)
const {
return data; }
411 std::ostream& print (std::ostream& os)
const;
444 static idx_vector_rep *nil_rep (
void);
447 static idx_vector_rep *err_rep (
void);
455 if (--rep->count == 0)
471 #if OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_IDX_TYPE
506 template <
typename T>
516 template <
typename T>
539 if (--rep->count == 0 && rep != nil_rep ())
547 if (--rep->count == 0 && rep != nil_rep ())
559 {
return rep->length (
n); }
562 {
return rep->extent (
n); }
565 {
return rep->xelem (
n); }
568 {
return rep->xelem (
n); }
571 {
return rep->xelem (
n); }
573 operator bool (
void)
const
574 {
return ! rep->err; }
577 {
return rep->idx_class () == class_colon; }
580 {
return rep->idx_class () == class_scalar; }
583 {
return rep->idx_class () == class_range; }
586 {
return rep->is_colon_equiv (
n); }
589 {
return idx_vector (rep->sort_uniq_clone (uniq)); }
597 {
return orig_dimensions () (0); }
600 {
return orig_dimensions () (1); }
603 {
return (! is_colon () && orig_dimensions ().any_zero ()); }
607 std::ostream&
print (std::ostream& os)
const {
return rep->print (os); }
610 {
return a.
print (os); }
620 template <
typename T>
626 switch (rep->idx_class ())
629 std::copy_n (src,
len, dest);
637 const T *ssrc = src + start;
639 std::copy_n (ssrc,
len, dest);
641 std::reverse_copy (ssrc -
len + 1, ssrc + 1, dest);
643 std::fill_n (dest,
len, *ssrc);
655 dest[0] = src[
r->get_data ()];
664 dest[i] = src[data[i]];
671 const bool *data =
r->get_data ();
674 if (data[i]) *dest++ = src[i];
694 template <
typename T>
700 switch (rep->idx_class ())
703 std::copy_n (src,
len, dest);
711 T *sdest = dest + start;
713 std::copy_n (src,
len, sdest);
715 std::reverse_copy (src, src +
len, sdest -
len + 1);
727 dest[
r->get_data ()] = src[0];
736 dest[data[i]] = src[i];
743 const bool *data =
r->get_data ();
746 if (data[i]) dest[i] = *src++;
766 template <
typename T>
772 switch (rep->idx_class ())
775 std::fill_n (dest,
len, val);
783 T *sdest = dest + start;
785 std::fill_n (sdest,
len, val);
787 std::fill (sdest -
len + 1, sdest + 1, val);
799 dest[
r->get_data ()] = val;
815 const bool *data =
r->get_data ();
818 if (data[i]) dest[i] = val;
836 template <
typename Functor>
842 switch (rep->idx_class ())
855 for (i = start, j = start +
len; i < j; i++) body (i);
857 for (i = start, j = start -
len; i > j; i--) body (i);
859 for (i = 0, j = start; i <
len; i++, j += step) body (j);
866 body (
r->get_data ());
881 const bool *data =
r->get_data ();
884 if (data[i]) body (i);
904 template <
typename Functor>
910 switch (rep->idx_class ())
915 for (i = 0; i <
len && body (i); i++) ;
927 for (i = start, j = start +
len; i < j && body (i); i++) ;
929 for (i = start, j = start -
len; i > j && body (i); i--) ;
931 for (i = 0, j = start; i <
len && body (j); i++, j += step) ;
939 ret = (body (
r->get_data ()) ? 1 : 0);
948 for (i = 0; i <
len && body (data[i]); i++) ;
956 const bool *data =
r->get_data ();
1015 void unconvert (idx_class_type& iclass,
1031 {
return (*
this) (
n); }
1034 {
return is_colon_equiv (
n); }
1040 { *
this = sorted (uniq); }
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
dim_vector freeze(Array< idx_vector > &ra_idx, const dim_vector &dimensions, int resize_ok)
bool isvector(const dim_vector &dim)
charNDArray max(char d, const charNDArray &m)
N Dimensional Array with copy-on-write semantics.
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
octave::refcount< octave_idx_type > count
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
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(const idx_mask_rep &idx)=delete
idx_mask_rep(bool *_data, octave_idx_type _len, octave_idx_type _ext, const dim_vector &od, direct)
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
idx_range_rep(octave_idx_type _start, octave_idx_type _len, octave_idx_type _step, direct)
octave_idx_type extent(octave_idx_type n) const
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)
Array< octave_idx_type > * aowner
octave_idx_type xelem(octave_idx_type i) const
idx_vector_rep(const idx_vector_rep &idx)=delete
idx_class_type idx_class(void) const
idx_vector_rep(octave_idx_type *_data, octave_idx_type _len, octave_idx_type _ext, const dim_vector &od, direct)
const octave_idx_type * get_data(void) const
octave_idx_type length(octave_idx_type) const
dim_vector orig_dimensions(void) const
const octave_idx_type * data
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 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
idx_vector(const Range &r)
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
F77_RET_T const F77_DBLE * x
static bool scalar(const dim_vector &dims)