25 #if ! defined (octave_Array_h) 26 #define octave_Array_h 1 28 #include "octave-config.h" 124 template <
typename T>
140 : data (new T [l]), len (l), count (1)
142 std::copy_n (
d, l, data);
145 template <
typename U>
147 : data (new T [l]), len (l), count (1)
149 std::copy_n (
d, l, data);
155 ArrayRep (
void) : data (new T [0]), len (0), count (1) { }
158 : data (new T [n]), len (n), count (1) { }
161 : data (new T [n]), len (n), count (1)
163 std::fill_n (data, n,
val);
167 : data (new T [
a.len]), len (
a.len), count (1)
169 std::copy_n (
a.data,
a.len, data);
191 ArrayRep *r =
new ArrayRep (slice_data, slice_len);
193 if (--rep->count == 0)
197 slice_data = rep->data;
233 : dimensions (
dv), rep(
a.rep), slice_data (
a.slice_data+l), slice_len (
u-l)
247 : dimensions (adims),
248 rep (reinterpret_cast<typename
Array<T>::ArrayRep *> (arep)),
249 slice_data (sdata), slice_len (slen) { }
255 : dimensions (), rep (nil_rep ()), slice_data (rep->data),
264 rep (new typename
Array<T>::ArrayRep (
dv.safe_numel ())),
265 slice_data (rep->data), slice_len (rep->len)
273 rep (new typename
Array<T>::ArrayRep (
dv.safe_numel ())),
274 slice_data (rep->data), slice_len (rep->len)
284 template<
template <
typename...>
class Container>
288 template <
typename U>
290 : dimensions (
a.
dims ()),
291 rep (new typename
Array<T>::ArrayRep (
a.data (),
a.
numel ())),
292 slice_data (rep->data), slice_len (rep->len)
297 : dimensions (
a.dimensions), rep (
a.rep), slice_data (
a.slice_data),
298 slice_len (
a.slice_len)
307 if (--rep->
count == 0)
315 if (--rep->
count == 0)
321 dimensions =
a.dimensions;
322 slice_data =
a.slice_data;
323 slice_len =
a.slice_len;
329 void fill (
const T&
val);
342 OCTAVE_DEPRECATED (4.4,
"use 'numel' instead")
356 OCTAVE_DEPRECATED (4.4,
"use 'numel' instead")
362 OCTAVE_DEPRECATED (4.4,
"use 'numel' instead")
373 if (dimensions.
ndims () != 2 || dimensions(1) != 1)
383 if (dimensions.
ndims () != 2 || dimensions(0) != 1)
393 if (dimensions.
ndims () != 2)
435 return d >= ndims () ? 1 : dimensions(
d);
439 {
return static_cast<size_t> (
numel ()) *
sizeof (T); }
462 {
return xelem (dim1 ()*j+
i); }
464 {
return xelem (dim1 ()*j+
i); }
467 {
return xelem (
i, dim2 ()*
k+j); }
469 {
return xelem (
i, dim2 ()*
k+j); }
472 {
return xelem (compute_index_unchecked (
ra_idx)); }
475 {
return xelem (compute_index_unchecked (
ra_idx)); }
497 {
return elem (
i, dim2 ()*
k+j); }
505 {
return elem (
i, j,
k); }
521 {
return xelem (
i, j); }
524 {
return xelem (
i, j,
k); }
531 {
return elem (
i, j); }
534 {
return elem (
i, j,
k); }
553 {
return Array<T> (*
this, new_dims); }
557 {
return permute (vec,
true); }
559 bool issquare (
void)
const {
return (dim1 () == dim2 ()); }
561 OCTAVE_DEPRECATED (4.4,
"use 'issquare' instead")
563 {
return issquare (); }
567 OCTAVE_DEPRECATED (4.4,
"use 'isempty' instead")
569 {
return isempty (); }
573 OCTAVE_DEPRECATED (4.4,
"use 'isvector' instead")
580 Array<T> hermitian (T (*
fcn) (
const T&) =
nullptr)
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;
715 OCTAVE_DEPRECATED (4.4,
"use 'issorted' instead")
717 {
return issorted (
mode); }
740 bool backward =
false)
const;
762 template <
typename U,
typename F>
768 const T *m = data ();
774 for (
i = 0;
i < len - 3;
i += 4)
794 template <
typename U>
797 {
return map<U, U (&) (T)> (
fcn); }
799 template <
typename U>
802 {
return map<U, U (&) (const T&)> (
fcn); }
806 template <
typename F,
bool zero>
809 return any_all_test<F, T, zero> (
fcn, data (),
numel ());
814 template <
typename F>
816 {
return test<F, false> (
fcn); }
818 template <
typename F>
820 {
return test<F, true> (
fcn); }
826 {
return test<bool (&) (T), false> (
fcn); }
829 {
return test<bool (&) (const T&), false> (
fcn); }
832 {
return test<bool (&) (T), true> (
fcn); }
835 {
return test<bool (&) (const T&), true> (
fcn); }
838 template <
typename U>
friend class Array;
865 template<
template <
typename...>
class Container>
874 (*current_liboctave_error_handler)
875 (
"reshape: can't reshape %i elements into %s array",
876 a.size (), new_dims_str.c_str ());
891 template <
typename ArrayClass>
894 typedef typename ArrayClass::element_type
T;
899 template <
typename X>
902 template <
typename X,
typename Y>
905 template <
typename X,
typename Y,
typename Z>
909 {
return ArrayClass::xelem (n); }
911 {
return ArrayClass::xelem (
i, j); }
913 {
return ArrayClass::xelem (
i, j,
k); }
915 {
return ArrayClass::xelem (
ra_idx); }
918 template <
typename T>
920 operator << (std::ostream& os, const Array<T>&
a);
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 rows(void) const
std::string str(char sep='x') const
octave_idx_type pages(void) const
bool test_any(F fcn) const
Simpler calls.
Array(T *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
For jit support.
octave_idx_type compute_index(const octave_idx_type *idx) const
Linear index from an index tuple.
OCTAVE_EXPORT octave_value_list column
Array< T > reshape(const dim_vector &new_dims) const
octave_idx_type dim3(void) const
Array(void)
Empty ctor (0 by 0).
ref_param< T >::type crefT
octave_idx_type dim1(void) const
const octave_base_value const Array< octave_idx_type > & ra_idx
void resize(const dim_vector &dv)
Resizing (with fill).
const T * data(void) const
void assign(const Array< idx_vector > &ia, const Array< T > &rhs)
Indexed assignment (always with resize & fill).
identity matrix If supplied two scalar respectively For allows like xample val
ArrayRep(octave_idx_type n, const T &val)
octave_idx_type safe_numel(void) const
The following function will throw a std::bad_alloc () exception if the requested size is larger than ...
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
bool isvector(void) const
T & operator()(octave_idx_type n)
ArrayRep(U *d, octave_idx_type l)
octave_idx_type * jit_dimensions(void) const
WARNING: Only call these functions from jit.
OCTAVE_EXPORT octave_value_list page
const T * fortran_vec(void) const
Array(const Array< T > &a, const dim_vector &dv, octave_idx_type l, octave_idx_type u)
slice constructor
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.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Array< T > ipermute(const Array< octave_idx_type > &vec) const
Array(const dim_vector &dv, const T &val)
nD initialized ctor.
bool test_any(bool(&fcn)(T)) const
Overloads for function references.
octave_idx_type columns(void) const
T & elem(octave_idx_type n)
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
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
T & xelem(octave_idx_type i, octave_idx_type j, octave_idx_type k)
void * mex_get_data(void) const
Give a pointer to the data in mex format.
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
The real representation of all arrays.
virtual octave_idx_type numel(const octave_value_list &)
Array< T > as_matrix(void) const
Return the array as a matrix.
Array(const dim_vector &dv)
nD uninitialized ctor.
ArrayRep(const ArrayRep &a)
Array< U > map(U(&fcn)(const T &)) const
Overloads for function references.
Array< T > index(const idx_vector &i, const idx_vector &j, bool resize_ok) const
Indexing with possible resizing and fill.
void clear(octave_idx_type r, octave_idx_type c)
octave_idx_type numel(void) const
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
Array< U > map(U(&fcn)(T)) const
Overloads for function references.
octave_idx_type cols(void) const
cell array If invoked with two or more scalar integer or a vector of integer values
Array< T > reshape(octave_idx_type nr, octave_idx_type nc) const
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
static void instantiation_guard()
void resize1(octave_idx_type n)
Resizing (with fill).
int * jit_ref_count(void)
WARNING: Only call these functions from jit.
bool issquare(void) const
Array< T > as_column(void) const
Return the array as a column vector.
octave_idx_type * to_jit(void) const
void assign(const idx_vector &i, const Array< T > &rhs)
Indexed assignment (always with resize & fill).
T & xelem(const Array< octave_idx_type > &ra_idx)
Array< T > index(const idx_vector &i, bool resize_ok) const
Indexing with possible resizing and fill.
octave_idx_type compute_index_unchecked(const Array< octave_idx_type > &ra_idx) const
crefT elem(octave_idx_type i, octave_idx_type j) const
T & xelem(octave_idx_type i, octave_idx_type j)
octave_idx_type dim2(void) const
ArrayClass::element_type T
ArrayRep(T *d, octave_idx_type l)
bool test_any(bool(&fcn)(const T &)) const
Overloads for function references.
size_type size(const size_type d) const
Size of the specified dimension.
T * jit_slice_data(void) const
WARNING: Only call these functions from jit.
octave_idx_type slice_len
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
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
With real return the complex result
if_then_else< is_class_type< T >::no, T, T const & >::result type
bool isvector(const dim_vector &dim)
crefT xelem(const Array< octave_idx_type > &ra_idx) const
T & elem(octave_idx_type i, octave_idx_type j)
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
T & xelem(octave_idx_type n)
bool test_all(F fcn) const
Simpler calls.
Array< T > as_row(void) const
Return the array as a row vector.
N Dimensional Array with copy-on-write semantics.
bool is_nd_vector(void) const
T::size_type numel(const T &str)
This is a simple wrapper template that will subclass an Array<T> type or any later type derived from ...
bool test_all(bool(&fcn)(T)) const
Overloads for function references.
crefT elem(const Array< octave_idx_type > &ra_idx) const
Array< U > map(F fcn) const
Apply function fcn to each element of the Array<T>.
crefT elem(octave_idx_type n) const
crefT xelem(octave_idx_type i, octave_idx_type j, octave_idx_type k) const
octave_idx_type size_type
Used for operator(), and returned by numel() and size() (beware: signed integer)
bool test(F fcn) const
Generic any/all test functionality with arbitrary predicate.
Array(const Array< U > &a)
Type conversion case.
octave::refcount< int > count
bool isvector(void) const
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)
Indexed assignment (always with resize & fill).
T & elem(const Array< octave_idx_type > &ra_idx)
void resize2(octave_idx_type nr, octave_idx_type nc)
Resizing (with fill).
bool test_all(bool(&fcn)(const T &)) const
Overloads for function references.
crefT elem(octave_idx_type i, octave_idx_type j, octave_idx_type k) const
void maybe_economize(void)
octave_idx_type ndims(void) const
Number of dimensions.
crefT xelem(octave_idx_type i, octave_idx_type j) const
Array< T > index(const Array< idx_vector > &ia, bool resize_ok) const
Indexing with possible resizing and fill.
octave_idx_type numel(void) const
Number of elements in the array.
crefT xelem(octave_idx_type n) const
void * jit_array_rep(void) const
WARNING: Only call these functions from jit.
ArrayRep(octave_idx_type n)
bool is_nd_vector(void) const
Vector representing the dimensions (size) of an Array.
size_t byte_size(void) const
void chop_trailing_singletons(void)
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
nd group nd example For each display the value
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
Array< T >::ArrayRep * rep
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)