26 #if !defined (octave_Array_h)
27 #define octave_Array_h 1
60 : data (new T [l]), len (l), count (1)
62 std::copy (d, d+l, data);
67 : data (new T [l]), len (l), count (1)
69 std::copy (d, d+l, data);
72 ArrayRep (
void) : data (0), len (0), count (1) { }
75 : data (new T [n]), len (n), count (1) { }
78 : data (new T [n]), len (n), count (1)
80 std::fill_n (data, n, val);
84 : data (new T [a.len]), len (a.len), count (1)
108 ArrayRep *r =
new ArrayRep (slice_data, slice_len);
110 if (--rep->count == 0)
114 slice_data = rep->data;
123 typename ref_param<T>::type);
144 : dimensions (dv), rep(a.rep), slice_data (a.slice_data+l), slice_len (u-l)
166 : dimensions (adims),
167 rep (reinterpret_cast<typename
Array<T>::ArrayRep *> (arep)),
168 slice_data (sdata), slice_len (slen) { }
174 : dimensions (), rep (nil_rep ()), slice_data (rep->data),
183 rep (new typename
Array<T>::ArrayRep (dv.safe_numel ())),
184 slice_data (rep->data), slice_len (rep->len)
192 rep (new typename
Array<T>::ArrayRep (dv.safe_numel ())),
193 slice_data (rep->data), slice_len (rep->len)
205 : dimensions (a.dims ()),
206 rep (new typename
Array<T>::ArrayRep (a.data (), a.
length ())),
207 slice_data (rep->data), slice_len (rep->len)
212 : dimensions (a.dimensions), rep (a.rep), slice_data (a.slice_data),
213 slice_len (a.slice_len)
222 if (--rep->
count == 0)
230 if (--rep->
count == 0)
244 void fill (
const T& val);
282 if (dimensions.
length () != 2 || dimensions(1) != 1)
292 if (dimensions.
length () != 2 || dimensions(0) != 1)
302 if (dimensions.
length () != 2)
334 {
return static_cast<size_t> (numel ()) *
sizeof (T); }
357 {
return xelem (dim1 ()*j+i); }
359 {
return xelem (dim1 ()*j+i); }
362 {
return xelem (i, dim2 ()*k+j); }
364 {
return xelem (i, dim2 ()*k+j); }
367 {
return xelem (compute_index_unchecked (ra_idx)); }
370 {
return xelem (compute_index_unchecked (ra_idx)); }
389 {
return elem (i, dim2 ()*k+j); }
394 #if defined (BOUNDS_CHECKING)
397 {
return checkelem (i, j); }
399 {
return checkelem (i, j, k); }
401 {
return checkelem (ra_idx); }
406 {
return elem (i, j, k); }
408 {
return elem (ra_idx); }
420 {
return xelem (i, j); }
423 {
return xelem (i, j, k); }
428 #if defined (BOUNDS_CHECKING)
431 {
return checkelem (i, j); }
434 {
return checkelem (i, j, k); }
436 {
return checkelem (ra_idx); }
440 {
return elem (i, j); }
443 {
return elem (i, j, k); }
445 {
return elem (ra_idx); }
464 {
return Array<T> (*
this, new_dims); }
468 {
return permute (vec,
true); }
470 bool is_square (
void)
const {
return (dim1 () == dim2 ()); }
472 bool is_empty (
void)
const {
return numel () == 0; }
477 Array<T> hermitian (T (*fcn) (
const T&) = 0)
const;
479 const T *
data (
void)
const {
return slice_data; }
483 T *fortran_vec (
void);
498 virtual T resize_fill_value (
void)
const;
505 resize2 (nr, nc, resize_fill_value ());
511 void resize (
const dim_vector& dv,
const T& rfv);
525 return index (i, resize_ok, resize_fill_value ());
531 bool resize_ok)
const
533 return index (i, j, resize_ok, resize_fill_value ());
540 return index (ia, resize_ok, resize_fill_value ());
550 assign (i, rhs, resize_fill_value ());
557 assign (i, j, rhs, resize_fill_value ());
563 assign (ia, rhs, resize_fill_value ());
574 void delete_elements (
int dim,
const idx_vector& i);
591 if (rep->
count == 1 && slice_len != rep->
len)
593 ArrayRep *new_rep =
new ArrayRep (slice_data, slice_len);
596 slice_data = rep->
data;
600 void print_info (std::ostream& os,
const std::string& prefix)
const;
635 bool backward =
false)
const;
657 template <
class U,
class F>
663 const T *m = data ();
669 for (i = 0; i < len - 3; i += 4)
674 p[i+1] = fcn (m[i+1]);
675 p[i+2] = fcn (m[i+2]);
676 p[i+3] = fcn (m[i+3]);
692 {
return map<U, U (&) (T)> (fcn); }
696 map (U (&fcn) (
const T&))
const
697 {
return map<U, U (&) (const T&)> (fcn); }
701 template <
class F,
bool zero>
704 return any_all_test<F, T, zero> (fcn, data (),
length ());
711 {
return test<F, false> (fcn); }
715 {
return test<F, true> (fcn); }
721 {
return test<bool (&) (T), false> (fcn); }
724 {
return test<bool (&) (const T&), false> (fcn); }
727 {
return test<bool (&) (T), true> (fcn); }
730 {
return test<bool (&) (const T&), true> (fcn); }
733 template <
class U>
friend class Array;
761 template<
class ArrayClass>
764 typedef typename ArrayClass::element_type
T;
772 template <
class X,
class Y>
775 template <
class X,
class Y,
class Z>
779 {
return ArrayClass::xelem (n); }
781 {
return ArrayClass::xelem (i, j); }
783 {
return ArrayClass::xelem (i, j, k); }
785 {
return ArrayClass::xelem (ra_idx); }
790 operator << (std::ostream& os, const Array<T>& a);
Array< T > as_matrix(void) const
Return the array as a matrix.
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
T & elem(octave_idx_type i, octave_idx_type j, octave_idx_type k)
octave_idx_type compute_index_unchecked(const Array< octave_idx_type > &ra_idx) const
static void clear(octave_shlib &oct_file)
bool is_empty(void) const
Array(T *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
For jit support.
crefT elem(const Array< octave_idx_type > &ra_idx) const
Array< T > reshape(const dim_vector &new_dims) const
Array(void)
Empty ctor (0 by 0).
ref_param< T >::type crefT
const octave_base_value const Array< octave_idx_type > & ra_idx
void resize(const dim_vector &dv)
bool is_vector(void) const
void assign(const Array< idx_vector > &ia, const Array< T > &rhs)
octave_idx_type numel(void) const
Number of elements in the array.
ArrayRep(octave_idx_type n, const T &val)
crefT xelem(octave_idx_type i, octave_idx_type j) const
Array< U > map(U(&fcn)(T)) const
Overloads for function references.
T & operator()(octave_idx_type n)
octave_idx_type dim2(void) const
ArrayRep(U *d, octave_idx_type l)
void * mex_get_data(void) const
Give a pointer to the data in mex format.
Array(const Array< T > &a, const dim_vector &dv, octave_idx_type l, octave_idx_type u)
slice constructor
octave_idx_type * jit_dimensions(void) const
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Array(const Array< T > &a)
No type conversion case.
T * jit_slice_data(void) const
Array(const dim_vector &dv, const T &val)
nD initialized ctor.
T & elem(octave_idx_type n)
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
crefT xelem(const Array< octave_idx_type > &ra_idx) const
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type double const octave_idx_type double const octave_idx_type double const octave_idx_type double * Z
bool test_all(bool(&fcn)(T)) const
T & xelem(octave_idx_type i, octave_idx_type j, octave_idx_type k)
Array< T > as_row(void) const
Return the array as a row vector.
crefT xelem(octave_idx_type i, octave_idx_type j, octave_idx_type k) const
The real representation of all arrays.
octave_idx_type dim1(void) const
Array(const dim_vector &dv)
nD uninitialized ctor.
ArrayRep(const ArrayRep &a)
octave_idx_type rows(void) const
F77_RET_T const double const double double * d
void clear(octave_idx_type r, octave_idx_type c)
bool optimize_dimensions(const dim_vector &dv)
Returns true if this->dims () == dv, and if so, replaces this->dimensions by a shallow copy of dv...
octave_idx_type nelem(void) const
Number of elements in the array.
octave_idx_type * to_jit(void) const
Array< T > as_column(void) const
Return the array as a column vector.
static void instantiation_guard()
octave_idx_type dim3(void) const
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
size_t byte_size(void) const
void resize1(octave_idx_type n)
Array< T >::ArrayRep * nil_rep(void) const
int * jit_ref_count(void)
WARNING: Only call these functions from jit.
bool test_any(F fcn) const
Simpler calls.
void assign(const idx_vector &i, const Array< T > &rhs)
Array< U > map(F fcn) const
Apply function fcn to each element of the Array.
T & xelem(const Array< octave_idx_type > &ra_idx)
bool is_vector(void) const
T & xelem(octave_idx_type i, octave_idx_type j)
const T * data(void) const
ArrayClass::element_type T
ArrayRep(T *d, octave_idx_type l)
Array< T > index(const Array< idx_vector > &ia, bool resize_ok) const
bool is_square(void) const
octave_idx_type capacity(void) const
Number of elements in the array.
dim_vector redim(int n) const
bool test_any(bool(&fcn)(const T &)) const
octave_idx_type slice_len
crefT xelem(octave_idx_type n) const
if_then_else< is_class_type< T >::no, T, T const & >::result type
T & elem(octave_idx_type i, octave_idx_type j)
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
bool test_any(bool(&fcn)(T)) const
Overloads for function references.
T & xelem(octave_idx_type n)
bool test_all(F fcn) const
Handles the reference counting for all the derived classes.
octave_idx_type length(void) const
Number of elements in the array.
bool test(F fcn) const
Generic any/all test functionality with arbitrary predicate.
This is a simple wrapper template that will subclass an Array type or any later type derived from ...
octave_idx_type compute_index(const octave_idx_type *idx) const
Compute a linear index from an index tuple.
crefT elem(octave_idx_type i, octave_idx_type j) const
bool test_all(bool(&fcn)(const T &)) const
crefT elem(octave_idx_type i, octave_idx_type j, octave_idx_type k) const
octave_refcount< int > count
octave_idx_type length(void) const
Array< T > index(const idx_vector &i, const idx_vector &j, bool resize_ok) const
Array< T > index(const idx_vector &i, bool resize_ok) const
Array(const Array< U > &a)
Type conversion case.
void assign(const idx_vector &i, const idx_vector &j, const Array< T > &rhs)
Array< T > reshape(octave_idx_type nr, octave_idx_type nc) const
octave_idx_type pages(void) const
T & elem(const Array< octave_idx_type > &ra_idx)
void resize2(octave_idx_type nr, octave_idx_type nc)
void maybe_economize(void)
Array< T > ipermute(const Array< octave_idx_type > &vec) const
const T * fortran_vec(void) const
octave_idx_type cols(void) const
ArrayRep(octave_idx_type n)
void chop_trailing_singletons(void)
octave_idx_type columns(void) const
crefT elem(octave_idx_type n) const
void * jit_array_rep(void) const
F77_RET_T const double * x
Array< T >::ArrayRep * rep
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)
Array< U > map(U(&fcn)(const T &)) const