26 #if ! defined (octave_Array_h)
27 #define octave_Array_h 1
29 #include "octave-config.h"
125 template <
typename T>
141 : data (new T [l]), len (l), count (1)
143 std::copy (d, d+l, data);
146 template <
typename U>
148 : data (new T [l]), len (l), count (1)
150 std::copy (d, d+l, data);
156 : data (new T [n]), len (n), count (1) { }
159 : data (new T [n]), len (n), count (1)
161 std::fill_n (data, n, val);
165 : data (new T [a.len]), len (a.len), count (1)
189 ArrayRep *r =
new ArrayRep (slice_data, slice_len);
191 if (--rep->count == 0)
195 slice_data = rep->data;
210 typename ref_param<T>::type);
231 : dimensions (dv), rep(a.rep), slice_data (a.slice_data+l), slice_len (u-l)
245 : dimensions (adims),
246 rep (reinterpret_cast<typename
Array<T>::ArrayRep *> (arep)),
247 slice_data (sdata), slice_len (slen) { }
253 : dimensions (), rep (nil_rep ()), slice_data (rep->data),
262 rep (new typename
Array<T>::ArrayRep (dv.safe_numel ())),
263 slice_data (rep->data), slice_len (rep->len)
271 rep (new typename
Array<T>::ArrayRep (dv.safe_numel ())),
272 slice_data (rep->data), slice_len (rep->len)
282 template<
template <
typename...>
class Container>
286 template <
typename U>
288 : dimensions (a.
dims ()),
289 rep (new typename
Array<T>::ArrayRep (a.data (), a.
numel ())),
290 slice_data (rep->data), slice_len (rep->len)
295 : dimensions (a.dimensions), rep (a.rep), slice_data (a.slice_data),
296 slice_len (a.slice_len)
305 if (--rep->
count == 0)
313 if (--rep->
count == 0)
327 void fill (
const T&
val);
340 OCTAVE_DEPRECATED (
"use 'numel' instead")
353 OCTAVE_DEPRECATED (
"use 'numel' instead")
359 OCTAVE_DEPRECATED (
"use 'numel' instead")
370 if (dimensions.
ndims () != 2 || dimensions(1) != 1)
380 if (dimensions.
ndims () != 2 || dimensions(0) != 1)
390 if (dimensions.
ndims () != 2)
428 size_type
size (
const size_type
d)
const
432 return d >= ndims () ? 1 : dimensions(d);
436 {
return static_cast<size_t> (
numel ()) *
sizeof (T); }
459 {
return xelem (dim1 ()*j+i); }
461 {
return xelem (dim1 ()*j+i); }
464 {
return xelem (i, dim2 ()*k+j); }
466 {
return xelem (i, dim2 ()*k+j); }
469 {
return xelem (compute_index_unchecked (ra_idx)); }
472 {
return xelem (compute_index_unchecked (ra_idx)); }
491 {
return elem (i, dim2 ()*k+j); }
496 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
499 {
return checkelem (i, j); }
501 {
return checkelem (i, j, k); }
503 {
return checkelem (ra_idx); }
508 {
return elem (i, j, k); }
510 {
return elem (ra_idx); }
522 {
return xelem (i, j); }
525 {
return xelem (i, j, k); }
530 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
533 {
return checkelem (i, j); }
536 {
return checkelem (i, j, k); }
538 {
return checkelem (ra_idx); }
542 {
return elem (i, j); }
545 {
return elem (i, j, k); }
547 {
return elem (ra_idx); }
567 {
return Array<T> (*
this, new_dims); }
571 {
return permute (vec,
true); }
573 bool is_square (
void)
const {
return (dim1 () == dim2 ()); }
580 Array<T> hermitian (T (*
fcn) (
const T&) = 0)
const;
582 const T *
data (
void)
const {
return slice_data; }
586 T *fortran_vec (
void);
601 virtual T resize_fill_value (
void)
const;
608 resize2 (nr, nc, resize_fill_value ());
627 return index (i, resize_ok, resize_fill_value ());
633 bool resize_ok)
const
635 return index (i, j, resize_ok, resize_fill_value ());
642 return index (ia, resize_ok, resize_fill_value ());
651 assign (i, rhs, resize_fill_value ());
658 assign (i, j, rhs, resize_fill_value ());
664 assign (ia, rhs, resize_fill_value ());
675 void delete_elements (
int dim,
const idx_vector&
i);
692 if (rep->
count == 1 && slice_len != rep->
len)
694 ArrayRep *new_rep =
new ArrayRep (slice_data, slice_len);
697 slice_data = rep->
data;
701 void print_info (std::ostream& os,
const std::string& prefix)
const;
736 bool backward =
false)
const;
758 template <
typename U,
typename F>
764 const T *
m = data ();
770 for (i = 0; i < len - 3; i += 4)
775 p[i+1] =
fcn (m[i+1]);
776 p[i+2] =
fcn (m[i+2]);
777 p[i+3] =
fcn (m[i+3]);
790 template <
typename U>
793 {
return map<U, U (&) (T)> (
fcn); }
795 template <
typename U>
798 {
return map<U, U (&) (const T&)> (
fcn); }
802 template <
typename F,
bool zero>
805 return any_all_test<F, T, zero> (
fcn, data (),
numel ());
810 template <
typename F>
812 {
return test<F, false> (
fcn); }
814 template <
typename F>
816 {
return test<F, true> (
fcn); }
822 {
return test<bool (&) (T), false> (
fcn); }
825 {
return test<bool (&) (const T&), false> (
fcn); }
828 {
return test<bool (&) (T), true> (
fcn); }
831 {
return test<bool (&) (const T&), true> (
fcn); }
834 template <
typename U>
friend class Array;
861 template<
template <
typename...>
class Container>
863 : dimensions (dv), rep (new typename
Array<T>::
ArrayRep (dv.safe_numel ())),
864 slice_data (rep->
data), slice_len (rep->len)
870 (*current_liboctave_error_handler)
871 (
"reshape: can't reshape %i elements into %s array",
872 a.size (), new_dims_str.c_str ());
887 template <
typename ArrayClass>
890 typedef typename ArrayClass::element_type
T;
895 template <
typename X>
898 template <
typename X,
typename Y>
901 template <
typename X,
typename Y,
typename Z>
905 {
return ArrayClass::xelem (n); }
907 {
return ArrayClass::xelem (i, j); }
909 {
return ArrayClass::xelem (i, j, k); }
911 {
return ArrayClass::xelem (ra_idx); }
914 template <
typename T>
916 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
bool is_empty(void) const
Array(T *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
For jit support.
OCTAVE_EXPORT octave_value_list column
std::string str(char sep= 'x') const
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.
identity matrix If supplied two scalar respectively For allows like xample val
ArrayRep(octave_idx_type n, const T &val)
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
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)
OCTAVE_EXPORT octave_value_list page
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.
octave_idx_type numel(void) const
T * jit_slice_data(void) const
size_type size(const size_type d) const
Size of the specified dimension.
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
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
void clear(octave_idx_type r, octave_idx_type c)
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 const F77_DBLE F77_DBLE * d
OCTAVE_EXPORT octave_value_list return the value of the option it must match the dimension of the state and the relative tolerance must also be a vector of the same length tem it must match the dimension of the state and the absolute tolerance must also be a vector of the same length The local error test applied at each integration step is xample roup calculate Y_a and Y _d item Given Y
cell array If invoked with two or more scalar integer or a vector of integer values
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...
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
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)
octave_idx_type safe_numel(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)
nd deftypefn *octave_map m
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
dim_vector redim(int n) const
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Z
bool test_any(bool(&fcn)(const T &)) const
octave_idx_type slice_len
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
crefT xelem(octave_idx_type n) const
With real return the complex result
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
N Dimensional Array with copy-on-write semantics.
bool test(F fcn) const
Generic any/all test functionality with arbitrary predicate.
T::size_type numel(const T &str)
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
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
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
=val(i)}if ode{val(i)}occurs in table i
octave_idx_type size_type
Used for operator(), and returned by numel() and size() (beware: signed integer)
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
Array(const Array< U > &a)
Type conversion case.
octave_idx_type ndims(void) const
Number of dimensions.
the element is set to zero In other the statement xample y
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)
Vector representing the dimensions (size) of an Array.
void chop_trailing_singletons(void)
static void clear(octave::dynamic_library &oct_file)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
octave_idx_type columns(void) const
crefT elem(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
void * jit_array_rep(void) const
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