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;
187 {
return m_start + i * m_step; }
195 return m_len ?
std::max (n, m_start + 1 + (m_step < 0 ? 0 : m_step * (m_len - 1))) : n;
205 {
return m_start == 0 && m_step == 1 && m_len == n; }
214 OCTAVE_API std::ostream& print (std::ostream& os)
const;
216 OCTAVE_API range<double> unconvert (
void)
const;
243 template <
typename T>
253 {
return std::max (n, m_data + 1); }
258 { m_count++;
return this; }
263 {
return n == 1 && m_data == 0; }
269 OCTAVE_API std::ostream& print (std::ostream& os)
const;
286 : m_data (nullptr), m_len (0), m_ext (0), m_aowner (nullptr), m_orig_dims () { }
292 m_aowner (nullptr), m_orig_dims (od)
301 template <
typename T>
337 OCTAVE_API std::ostream& print (std::ostream& os)
const;
372 m_lsti (-1), m_lste (-1), m_aowner (nullptr), m_orig_dims (od)
399 { m_count++;
return this; }
406 {
return m_len == n && m_ext == n; }
408 const bool *
get_data (
void)
const {
return m_data; }
410 OCTAVE_API std::ostream& print (std::ostream& os)
const;
443 static OCTAVE_API idx_vector_rep * nil_rep (
void);
453#if OCTAVE_SIZEOF_INT != OCTAVE_SIZEOF_IDX_TYPE
458#if (OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_IDX_TYPE \
459 && OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_INT)
490 template <
typename T>
500 template <
typename T>
518 if (--m_rep->m_count == 0 && m_rep != nil_rep ())
526 if (--m_rep->m_count == 0 && m_rep != nil_rep ())
538 {
return m_rep->length (n); }
541 {
return m_rep->extent (n); }
544 {
return m_rep->xelem (n); }
547 {
return m_rep->xelem (n); }
550 {
return m_rep->xelem (n); }
554 operator bool (
void)
const {
return true; }
557 {
return m_rep->idx_class () == class_colon; }
560 {
return m_rep->idx_class () == class_scalar; }
563 {
return m_rep->idx_class () == class_range; }
566 {
return m_rep->is_colon_equiv (n); }
569 {
return idx_vector (m_rep->sort_uniq_clone (uniq)); }
572 {
return idx_vector (m_rep->sort_idx (sidx)); }
577 {
return orig_dimensions () (0); }
580 {
return orig_dimensions () (1); }
583 {
return (! is_colon () && orig_dimensions ().any_zero ()); }
587 std::ostream&
print (std::ostream& os)
const {
return m_rep->print (os); }
590 {
return a.
print (os); }
600 template <
typename T>
606 switch (m_rep->idx_class ())
609 std::copy_n (src,
len, dest);
617 const T *ssrc = src + start;
619 std::copy_n (ssrc,
len, dest);
621 std::reverse_copy (ssrc -
len + 1, ssrc + 1, dest);
623 std::fill_n (dest,
len, *ssrc);
644 dest[i] = src[data[i]];
654 if (data[i]) *dest++ = src[i];
674 template <
typename T>
680 switch (m_rep->idx_class ())
683 std::copy_n (src,
len, dest);
691 T *sdest = dest + start;
693 std::copy_n (src,
len, sdest);
695 std::reverse_copy (src, src +
len, sdest -
len + 1);
716 dest[data[i]] = src[i];
726 if (data[i]) dest[i] = *src++;
746 template <
typename T>
752 switch (m_rep->idx_class ())
755 std::fill_n (dest,
len, val);
763 T *sdest = dest + start;
765 std::fill_n (sdest,
len, val);
767 std::fill (sdest -
len + 1, sdest + 1, val);
798 if (data[i]) dest[i] = val;
816 template <
typename Functor>
822 switch (m_rep->idx_class ())
835 for (i = start, j = start +
len; i < j; i++) body (i);
837 for (i = start, j = start -
len; i > j; i--) body (i);
839 for (i = 0, j = start; i <
len; i++, j += step) body (j);
864 if (data[i]) body (i);
884 template <
typename Functor>
890 switch (m_rep->idx_class ())
895 for (i = 0; i <
len && body (i); i++) ;
907 for (i = start, j = start +
len; i < j && body (i); i++) ;
909 for (i = start, j = start -
len; i > j && body (i); i--) ;
911 for (i = 0, j = start; i <
len && body (j); i++, j += step) ;
919 ret = (body (r->
get_data ()) ? 1 : 0);
928 for (i = 0; i <
len && body (data[i]); i++) ;
997 unconvert (idx_class_type& iclass,
double&
scalar, range<double>&
range,
1012 {
return (*
this) (n); }
1015 {
return is_colon_equiv (n); }
1021 { *
this = sorted (uniq); }
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 ~idx_base_rep(void)=default
virtual bool is_colon_equiv(octave_idx_type) const
virtual octave_idx_type checkelem(octave_idx_type i) const =0
virtual octave_idx_type xelem(octave_idx_type i) const =0
virtual idx_base_rep * sort_idx(Array< octave_idx_type > &)=0
idx_base_rep(const idx_base_rep &)=delete
virtual octave_idx_type length(octave_idx_type n) const =0
virtual octave_idx_type extent(octave_idx_type n) const =0
virtual std::ostream & print(std::ostream &os) const =0
refcount< octave_idx_type > m_count
virtual idx_class_type idx_class(void) const
virtual idx_base_rep * sort_uniq_clone(bool uniq=false)=0
virtual dim_vector orig_dimensions(void) const
idx_colon_rep(const idx_colon_rep &idx)=delete
bool is_colon_equiv(octave_idx_type) const
octave_idx_type extent(octave_idx_type n) const
octave_idx_type xelem(octave_idx_type i) const
idx_class_type idx_class(void) const
idx_colon_rep(void)=default
octave_idx_type length(octave_idx_type n) const
idx_base_rep * sort_uniq_clone(bool=false)
idx_mask_rep(void)=delete
idx_base_rep * sort_uniq_clone(bool=false)
idx_mask_rep(bool *data, octave_idx_type len, octave_idx_type ext, const dim_vector &od, direct)
const bool * get_data(void) const
bool is_colon_equiv(octave_idx_type n) const
octave_idx_type length(octave_idx_type) const
octave_idx_type extent(octave_idx_type n) const
idx_mask_rep(const idx_mask_rep &idx)=delete
idx_class_type idx_class(void) const
dim_vector orig_dimensions(void) const
octave_idx_type extent(octave_idx_type n) const
bool is_colon_equiv(octave_idx_type n) const
idx_range_rep(void)=delete
dim_vector orig_dimensions(void) const
idx_class_type idx_class(void) const
octave_idx_type xelem(octave_idx_type i) const
octave_idx_type length(octave_idx_type) const
idx_range_rep(const idx_range_rep &idx)=delete
idx_range_rep(octave_idx_type start, octave_idx_type len, octave_idx_type step, direct)
octave_idx_type get_start(void) const
octave_idx_type get_step(void) const
dim_vector orig_dimensions(void) const
idx_class_type idx_class(void) const
idx_scalar_rep(void)=delete
octave_idx_type get_data(void) const
octave_idx_type length(octave_idx_type) const
idx_base_rep * sort_uniq_clone(bool=false)
idx_scalar_rep(octave_idx_type i, direct)
idx_scalar_rep(const idx_scalar_rep &idx)=delete
octave_idx_type xelem(octave_idx_type) const
octave_idx_type extent(octave_idx_type n) const
bool is_colon_equiv(octave_idx_type n) const
const octave_idx_type * get_data(void) const
Array< octave_idx_type > * m_aowner
const octave_idx_type * m_data
octave_idx_type xelem(octave_idx_type i) const
octave_idx_type length(octave_idx_type) const
idx_vector_rep(const idx_vector_rep &idx)=delete
idx_class_type idx_class(void) const
dim_vector orig_dimensions(void) const
idx_vector_rep(octave_idx_type *data, octave_idx_type len, octave_idx_type ext, const dim_vector &od, direct)
octave_idx_type extent(octave_idx_type n) const
idx_vector(octave_idx_type start, octave_idx_type limit, octave_idx_type step=1)
static idx_vector make_range(octave_idx_type start, octave_idx_type step, octave_idx_type len)
octave_idx_type orig_columns(void) const
bool is_colon(void) const
idx_vector(const Array< double > &nda)
void loop(octave_idx_type n, Functor body) const
idx_vector(const Array< octave_idx_type > &inda)
idx_vector(idx_base_rep *r)
idx_vector sorted(bool uniq=false) const
octave_idx_type extent(octave_idx_type n) const
octave_idx_type max(void) const
idx_vector(octave_idx_type i)
octave_idx_type orig_rows(void) const
octave_idx_type xelem(octave_idx_type n) const
idx_vector(const range< double > &r)
idx_vector(const Array< octave_idx_type > &inda, octave_idx_type ext)
octave_idx_type checkelem(octave_idx_type n) const
std::ostream & print(std::ostream &os) const
idx_class_type idx_class(void) const
idx_vector(const Array< octave_int< T > > &nda)
octave_idx_type assign(const T *src, octave_idx_type n, T *dest) const
bool is_scalar(void) const
idx_vector(const idx_vector &a)
octave_idx_type elem(octave_idx_type n) const
bool is_colon_equiv(octave_idx_type n, int) const
void sort(bool uniq=false)
octave_idx_type bloop(octave_idx_type n, Functor body) const
idx_vector(const Array< float > &nda)
idx_vector(octave_int< T > x)
idx_vector(const Sparse< bool > &nda)
octave_idx_type index(const T *src, octave_idx_type n, T *dest) const
idx_vector sorted(Array< octave_idx_type > &sidx) const
static const idx_vector colon
dim_vector orig_dimensions(void) const
octave_idx_type fill(const T &val, octave_idx_type n, T *dest) const
bool is_range(void) const
octave_idx_type length(octave_idx_type n=0) const
bool is_colon_equiv(octave_idx_type n) const
int orig_empty(void) const
octave::idx_vector idx_vector
F77_RET_T const F77_DBLE * x
std::ostream & operator<<(std::ostream &os, const CollocWt &a)
static bool scalar(const dim_vector &dims)