25 #if ! defined (octave_idx_vector_h)
26 #define octave_idx_vector_h 1
28 #include "octave-config.h"
41 template <
typename T>
class Array;
68 template <
typename T,
typename D>
friend class std::unique_ptr;
95 virtual idx_base_rep *sort_uniq_clone (
bool uniq =
false) = 0;
106 virtual std::ostream& print (std::ostream& os)
const = 0;
140 { count++;
return this; }
146 std::ostream&
print (std::ostream& os)
const;
167 :
start(0), len(0), step(1) { }
176 {
return start + i * step; }
184 return len ?
std::max (n,
start + 1 + (step < 0 ? 0 : step * (len - 1)))
195 {
return start == 0 && step == 1 && len == n; }
204 std::ostream&
print (std::ostream& os)
const;
233 template <
typename T>
248 { count++;
return this; }
253 {
return n == 1 && data == 0; }
259 std::ostream&
print (std::ostream& os)
const;
282 : data (_data), len (_len), ext (_ext), aowner (0), orig_dims (od) { }
285 : data (0), len (0), ext (0), aowner (0), orig_dims ()
294 template <
typename T>
324 std::ostream&
print (std::ostream& os)
const;
359 : data (_data), len (_len), ext (_ext), lsti (-1), lste (-1),
360 aowner (0), orig_dims (od) { }
363 : data (0), len (0), ext (0), lsti (-1), lste (-1), aowner (0),
385 { count++;
return this; }
392 {
return len == n && ext == n; }
396 std::ostream&
print (std::ostream& os)
const;
433 static idx_vector_rep *nil_rep (
void);
436 static idx_vector_rep *err_rep (
void);
444 if (--rep->count == 0)
489 template <
typename T>
499 template <
typename T>
522 if (--rep->count == 0)
530 if (--rep->count == 0)
542 {
return rep->length (n); }
545 {
return rep->extent (n); }
548 {
return rep->xelem (n); }
551 {
return rep->checkelem (n); }
555 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
556 return rep->checkelem (n);
558 return rep->xelem (n);
563 {
return ! rep->err; }
566 {
return rep->idx_class () == class_colon; }
569 {
return rep->idx_class () == class_scalar; }
572 {
return rep->idx_class () == class_range; }
575 {
return rep->is_colon_equiv (n); }
578 {
return idx_vector (rep->sort_uniq_clone (uniq)); }
586 {
return orig_dimensions () (0); }
589 {
return orig_dimensions () (1); }
592 {
return (! is_colon () && orig_dimensions ().any_zero ()); }
596 std::ostream&
print (std::ostream& os)
const {
return rep->print (os); }
599 {
return a.
print (os); }
609 template <
typename T>
615 switch (rep->idx_class ())
618 std::copy (src, src + len, dest);
626 const T *ssrc = src +
start;
628 std::copy (ssrc, ssrc + len, dest);
630 std::reverse_copy (ssrc - len + 1, ssrc + 1, dest);
632 std::fill_n (dest, len, *ssrc);
653 dest[
i] = src[data[
i]];
663 if (data[
i]) *dest++ = src[
i];
683 template <
typename T>
689 switch (rep->idx_class ())
692 std::copy (src, src + len, dest);
700 T *sdest = dest +
start;
702 std::copy (src, src + len, sdest);
704 std::reverse_copy (src, src + len, sdest - len + 1);
725 dest[data[
i]] = src[
i];
735 if (data[
i]) dest[
i] = *src++;
755 template <
typename T>
761 switch (rep->idx_class ())
764 std::fill (dest, dest + len, val);
772 T *sdest = dest +
start;
774 std::fill (sdest, sdest + len, val);
776 std::fill (sdest - len + 1, sdest + 1, val);
807 if (data[
i]) dest[
i] =
val;
825 template <
typename Functor>
831 switch (rep->idx_class ())
844 for (i = start, j = start + len; i < j; i++) body (i);
846 for (i = start, j = start - len; i > j; i--) body (i);
848 for (i = 0, j = start; i < len; i++, j += step) body (j);
873 if (data[
i]) body (i);
893 template <
typename Functor>
899 switch (rep->idx_class ())
904 for (i = 0; i < len && body (i); i++) ;
916 for (i = start, j = start + len; i < j && body (i); i++) ;
918 for (i = start, j = start - len; i > j && body (i); i--) ;
920 for (i = 0, j = start; i < len && body (j); i++, j += step) ;
928 ret = body (r->
get_data ()) ? 1 : 0;
937 for (i = 0; i < len && body (data[i]); i++) ;
1004 void unconvert (idx_class_type& iclass,
1020 {
return (*
this) (n); }
1023 {
return is_colon_equiv (n); }
1029 { *
this = sorted (uniq); }
octave_idx_type elem(octave_idx_type n) const
virtual Array< octave_idx_type > as_array(void)
idx_class_type idx_class(void) const
virtual ~idx_base_rep(void)
octave_idx_type length(octave_idx_type n) const
idx_base_rep * sort_uniq_clone(bool=false)
bool is_colon_equiv(octave_idx_type n, int) const
octave_idx_type extent(octave_idx_type n) const
octave_idx_type length(octave_idx_type n=0) const
octave_idx_type extent(octave_idx_type n) const
idx_vector(const Array< octave_idx_type > &inda)
idx_class_type idx_class(void) const
nd group nd example oindent but is performed more efficiently If only and it is a scalar
static const idx_vector colon
octave_idx_type assign(const T *src, octave_idx_type n, T *dest) const
int orig_empty(void) const
identity matrix If supplied two scalar respectively For allows like xample val
octave_refcount< int > count
idx_vector(const Range &r)
octave_idx_type max(void) const
bool is_vector(const dim_vector &dim)
dim_vector orig_dimensions(void) const
octave_idx_type xelem(octave_idx_type n) const
octave_idx_type get_step(void) const
octave_idx_type fill(const T &val, octave_idx_type n, T *dest) const
octave_idx_type get_start(void) const
idx_class_type idx_class(void) const
bool is_colon_equiv(octave_idx_type n) const
octave_idx_type checkelem(octave_idx_type n) const
std::ostream & print(std::ostream &os) const
octave_idx_type length(octave_idx_type) const
idx_vector(const Array< octave_int< T > > &nda)
dim_vector orig_dimensions(void) const
octave_idx_type xelem(octave_idx_type) const
octave_idx_type xelem(octave_idx_type i) const
octave_idx_type length(octave_idx_type) const
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
virtual bool is_colon_equiv(octave_idx_type) const
void loop(octave_idx_type n, Functor body) const
dim_vector orig_dimensions(void) const
octave_idx_type index(const T *src, octave_idx_type n, T *dest) const
then the function must return scalars which will be concatenated into the return array(s).If code
octave_idx_type length(octave_idx_type) const
dim_vector orig_dimensions(void) const
octave_idx_type length(octave_idx_type) const
idx_range_rep(octave_idx_type _start, octave_idx_type _len, octave_idx_type _step, direct)
virtual idx_class_type idx_class(void) const
octave_idx_type xelem(octave_idx_type i) const
dim_vector freeze(Array< idx_vector > &ra_idx, const dim_vector &dimensions, int resize_ok)
idx_vector_rep(octave_idx_type *_data, octave_idx_type _len, octave_idx_type _ext, const dim_vector &od, direct)
idx_vector(octave_idx_type i)
octave_idx_type extent(octave_idx_type n) const
virtual octave_idx_type xelem(octave_idx_type i) const =0
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
idx_mask_rep(bool *_data, octave_idx_type _len, octave_idx_type _ext, const dim_vector &od, direct)
void sort(bool uniq=false)
octave_idx_type orig_rows(void) const
virtual octave_idx_type checkelem(octave_idx_type i) const =0
idx_base_rep & operator=(const idx_base_rep &)
virtual dim_vector orig_dimensions(void) const
octave_idx_type bloop(octave_idx_type n, Functor body) const
bool is_colon_equiv(octave_idx_type n) const
bool is_colon_equiv(octave_idx_type n) const
idx_vector(const Array< float > &nda)
N Dimensional Array with copy-on-write semantics.
octave_idx_type xelem(octave_idx_type i) const
charNDArray max(char d, const charNDArray &m)
idx_class_type idx_class(void) const
octave_idx_type extent(octave_idx_type n) const
bool is_range(void) const
idx_vector(const Array< double > &nda)
idx_class_type idx_class(void) const
idx_vector(const Array< octave_idx_type > &inda, octave_idx_type ext)
idx_base_rep * sort_uniq_clone(bool=false)
idx_scalar_rep(octave_idx_type i, direct)
=val(i)}if ode{val(i)}occurs in table i
idx_vector(idx_base_rep *r)
idx_vector sorted(Array< octave_idx_type > &sidx) const
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
bool is_scalar(void) const
idx_vector(octave_idx_type start, octave_idx_type limit, octave_idx_type step=1)
const octave_idx_type * data
idx_vector(octave_int< T > x)
virtual idx_base_rep * sort_idx(Array< octave_idx_type > &)=0
idx_vector(const Sparse< bool > &nda)
octave_idx_type get_data(void) const
void unconvert(idx_class_type &iclass, double &scalar, Range &range, Array< double > &array, Array< bool > &mask) const
idx_class_type idx_class(void) const
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
Array< octave_idx_type > * aowner
dim_vector orig_dimensions(void) const
virtual idx_base_rep * sort_uniq_clone(bool uniq=false)=0
octave_idx_type orig_columns(void) const
bool is_colon_equiv(octave_idx_type) const
idx_base_rep * sort_uniq_clone(bool=false)
const octave_idx_type * get_data(void) const
const bool * get_data(void) const
Vector representing the dimensions (size) of an Array.
static idx_vector make_range(octave_idx_type start, octave_idx_type step, octave_idx_type len)
virtual std::ostream & print(std::ostream &os) const =0
idx_vector sorted(bool uniq=false) const
OCTAVE_EXPORT octave_value_list or cell arrays Arguments are concatenated vertically The returned values are padded with blanks as needed to make each row of the string array have the same length Empty input strings are significant and will concatenated in the output For numerical each element is converted to the corresponding ASCII character A range error results if an input is outside the ASCII range(0-255).For cell arrays
bool is_colon_equiv(octave_idx_type n) const
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
bool is_colon(void) const
idx_vector(const idx_vector &a)
octave_idx_type extent(octave_idx_type n) const
octave_idx_type extent(octave_idx_type n) const