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_n (
d, l, data);
146 template <
typename U>
148 : data (new T [l]),
len (l), count (1)
150 std::copy_n (
d, l, data);
159 : data (new T [
n]),
len (
n), count (1) { }
162 : data (new T [
n]),
len (
n), count (1)
164 std::fill_n (data,
n, val);
168 : data (new T [a.
len]),
len (a.
len), count (1)
170 std::copy_n (a.
data, a.
len, data);
194 if (--rep->count == 0)
198 slice_data = rep->data;
234 : dimensions (dv), rep(a.rep), slice_data (a.slice_data+l), slice_len (u-l)
248 : dimensions (adims),
249 rep (reinterpret_cast<typename
Array<T>::
ArrayRep *> (arep)),
250 slice_data (sdata), slice_len (slen) { }
256 : dimensions (), rep (nil_rep ()), slice_data (rep->data),
266 slice_data (rep->data), slice_len (rep->
len)
275 slice_data (rep->data), slice_len (rep->
len)
285 template<
template <
typename...>
class Container>
289 template <
typename U>
291 : dimensions (a.dims ()),
293 slice_data (rep->data), slice_len (rep->
len)
298 : dimensions (a.dimensions), rep (a.rep), slice_data (a.slice_data),
299 slice_len (a.slice_len)
305 : dimensions (std::move (a.dimensions)), rep (a.rep),
306 slice_data (a.slice_data), slice_len (a.slice_len)
309 a.slice_data =
nullptr;
321 if (rep && --rep->
count == 0)
329 if (--rep->
count == 0)
347 dimensions = std::move (a.dimensions);
353 if (rep && --rep->
count == 0)
357 slice_data = a.slice_data;
358 slice_len = a.slice_len;
361 a.slice_data =
nullptr;
368 void fill (
const T& val);
384 if (dimensions.
ndims () != 2 || dimensions(1) != 1)
394 if (dimensions.
ndims () != 2 || dimensions(0) != 1)
404 if (dimensions.
ndims () != 2)
446 return d >= ndims () ? 1 : dimensions(
d);
450 {
return static_cast<size_t> (
numel ()) *
sizeof (T); }
473 {
return xelem (dim1 ()*j+i); }
475 {
return xelem (dim1 ()*j+i); }
478 {
return xelem (i, dim2 ()*k+j); }
480 {
return xelem (i, dim2 ()*k+j); }
483 {
return xelem (compute_index_unchecked (
ra_idx)); }
486 {
return xelem (compute_index_unchecked (
ra_idx)); }
508 {
return elem (i, dim2 ()*k+j); }
516 {
return elem (i, j, k); }
532 {
return xelem (i, j); }
535 {
return xelem (i, j, k); }
542 {
return elem (i, j); }
545 {
return elem (i, j, k); }
564 {
return Array<T> (*
this, new_dims); }
568 {
return permute (vec,
true); }
570 bool issquare (
void)
const {
return (dim1 () == dim2 ()); }
579 Array<T> hermitian (T (*fcn) (
const T&) =
nullptr)
const;
581 const T *
data (
void)
const {
return slice_data; }
585 T * fortran_vec (
void);
600 virtual T resize_fill_value (
void)
const;
607 resize2 (nr, nc, resize_fill_value ());
613 void resize (
const dim_vector& dv,
const T& rfv);
626 return index (i, resize_ok, resize_fill_value ());
632 bool resize_ok)
const
634 return index (i, j, resize_ok, resize_fill_value ());
641 return index (ia, resize_ok, resize_fill_value ());
650 assign (i, rhs, resize_fill_value ());
657 assign (i, j, rhs, resize_fill_value ());
663 assign (ia, rhs, resize_fill_value ());
674 void delete_elements (
int dim,
const idx_vector& i);
691 if (rep->
count == 1 && slice_len != rep->
len)
696 slice_data = rep->
data;
700 void print_info (std::ostream& os,
const std::string& prefix)
const;
735 bool backward =
false)
const;
757 template <
typename U,
typename F>
763 const T *
m = data ();
769 for (i = 0; i <
len - 3; i += 4)
774 p[i+1] = fcn (
m[i+1]);
775 p[i+2] = fcn (
m[i+2]);
776 p[i+3] = fcn (
m[i+3]);
789 template <
typename U>
792 {
return map<U, U (&) (T)> (fcn); }
794 template <
typename U>
796 map (U (&fcn) (
const T&))
const
797 {
return map<U, U (&) (const T&)> (fcn); }
801 template <
typename F,
bool zero>
804 return any_all_test<F, T, zero> (fcn, data (),
numel ());
809 template <
typename F>
811 {
return test<F, false> (fcn); }
813 template <
typename F>
815 {
return test<F, true> (fcn); }
821 {
return test<bool (&) (T), false> (fcn); }
824 {
return test<bool (&) (const T&), false> (fcn); }
827 {
return test<bool (&) (T), true> (fcn); }
830 {
return test<bool (&) (const T&), true> (fcn); }
833 template <
typename U>
friend class Array;
860 template<
template <
typename...>
class Container>
869 (*current_liboctave_error_handler)
870 (
"reshape: can't reshape %zi elements into %s array",
871 a.size (), new_dims_str.c_str ());
881 template <
typename T>
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
std::ostream & operator<<(std::ostream &os, const Array< T > &a)
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
The real representation of all arrays.
ArrayRep(octave_idx_type n)
ArrayRep(T *d, octave_idx_type l)
octave_idx_type numel(void) const
ArrayRep(U *d, octave_idx_type l)
ArrayRep(const ArrayRep &a)
ArrayRep(octave_idx_type n, const T &val)
octave::refcount< octave_idx_type > count
N Dimensional Array with copy-on-write semantics.
bool is_nd_vector(void) const
Size of the specified dimension.
void assign(const idx_vector &i, const idx_vector &j, const Array< T > &rhs)
Size of the specified dimension.
Array< U > map(F fcn) const
Apply function fcn to each element of the Array<T>.
Array< T > as_column(void) const
Return the array as a column vector.
crefT xelem(octave_idx_type n) const
Size of the specified dimension.
Array(const dim_vector &dv)
nD uninitialized ctor.
Array< T >::ArrayRep * rep
octave_idx_type * jit_dimensions(void) const
Size of the specified dimension.
Array(T *sdata, octave_idx_type slen, octave_idx_type *adims, void *arep)
For jit support.
octave_idx_type pages(void) const
Size of the specified dimension.
T & elem(const Array< octave_idx_type > &ra_idx)
Size of the specified dimension.
static void instantiation_guard()
Size of the specified dimension.
void assign(const idx_vector &i, const Array< T > &rhs)
Size of the specified dimension.
Array(const Array< T > &a)
No type conversion case.
Array< T > as_matrix(void) const
Return the array as a matrix.
Array< T > index(const idx_vector &i, const idx_vector &j, bool resize_ok) const
Size of the specified dimension.
octave_idx_type dim3(void) const
Size of the specified dimension.
crefT xelem(octave_idx_type i, octave_idx_type j, octave_idx_type k) const
Size of the specified dimension.
T & xelem(octave_idx_type i, octave_idx_type j, octave_idx_type k)
Size of the specified dimension.
Array(const Array< T > &a, const dim_vector &dv, octave_idx_type l, octave_idx_type u)
slice constructor
Array(const Array< U > &a)
Type conversion case.
octave_idx_type columns(void) const
bool test_any(bool(&fcn)(T)) const
Overloads for function references.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
bool test_any(bool(&fcn)(const T &)) const
Size of the specified dimension.
bool test_any(F fcn) const
Simpler calls.
bool isvector(void) const
Size of the specified dimension.
void * jit_array_rep(void) const
Size of the specified dimension.
Array(const Container< T > &a, const dim_vector &dv)
Constructor from standard library sequence containers.
T & elem(octave_idx_type n)
Size of the specified dimension.
bool test_all(bool(&fcn)(T)) const
Size of the specified dimension.
void resize2(octave_idx_type nr, octave_idx_type nc)
Size of the specified dimension.
crefT xelem(octave_idx_type i, octave_idx_type j) const
Size of the specified dimension.
size_t byte_size(void) const
Size of the specified dimension.
void assign(const Array< idx_vector > &ia, const Array< T > &rhs)
Size of the specified dimension.
Array< T > index(const idx_vector &i, bool resize_ok) const
Size of the specified dimension.
void resize(const dim_vector &dv)
Size of the specified dimension.
crefT elem(octave_idx_type n) const
Size of the specified dimension.
bool issquare(void) const
Size of the specified dimension.
const T * data(void) const
Size of the specified dimension.
void maybe_economize(void)
Size of the specified dimension.
T & elem(octave_idx_type i, octave_idx_type j)
Size of the specified dimension.
bool test(F fcn) const
Generic any/all test functionality with arbitrary predicate.
Array< U > map(U(&fcn)(T)) const
Overloads for function references.
void resize1(octave_idx_type n)
Size of the specified dimension.
octave_idx_type cols(void) const
T & xelem(octave_idx_type i, octave_idx_type j)
Size of the specified dimension.
T & elem(octave_idx_type i, octave_idx_type j, octave_idx_type k)
Size of the specified dimension.
T & xelem(const Array< octave_idx_type > &ra_idx)
Size of the specified dimension.
Array< T > ipermute(const Array< octave_idx_type > &vec) const
Size of the specified dimension.
octave_idx_type rows(void) const
Array< T > reshape(const dim_vector &new_dims) const
Size of the specified dimension.
friend class Array
Size of the specified dimension.
T * jit_slice_data(void) const
Size of the specified dimension.
Array< T > index(const Array< idx_vector > &ia, bool resize_ok) const
Size of the specified dimension.
ref_param< T >::type crefT
int jit_ref_count(void)
WARNING: Only call these functions from jit.
octave_idx_type slice_len
bool test_all(bool(&fcn)(const T &)) const
Size of the specified dimension.
Array< T > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
bool test_all(F fcn) const
Size of the specified dimension.
octave_idx_type dim2(void) const
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Array< T > as_row(void) const
Return the array as a row vector.
crefT xelem(const Array< octave_idx_type > &ra_idx) const
Size of the specified dimension.
int ndims(void) const
Size of the specified dimension.
crefT elem(const Array< octave_idx_type > &ra_idx) const
Size of the specified dimension.
crefT elem(octave_idx_type i, octave_idx_type j) const
Size of the specified dimension.
const T * fortran_vec(void) const
Size of the specified dimension.
octave_idx_type size_type
Used for operator(), and returned by numel() and size() (beware: signed integer)
void * mex_get_data(void) const
Give a pointer to the data in mex format.
bool is_shared(void)
Size of the specified dimension.
crefT elem(octave_idx_type i, octave_idx_type j, octave_idx_type k) const
Size of the specified dimension.
Array(const dim_vector &dv, const T &val)
nD initialized ctor.
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 compute_index_unchecked(const Array< octave_idx_type > &ra_idx) const
Size of the specified dimension.
octave_idx_type dim1(void) const
Array< U > map(U(&fcn)(const T &)) const
Size of the specified dimension.
Array(void)
Empty ctor (0 by 0).
size_type size(const size_type d) const
Size of the specified dimension.
bool isempty(void) const
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
octave_idx_type compute_index(const octave_idx_type *idx) const
Linear index from an index tuple.
std::string str(char sep='x') const
bool isvector(void) const
void chop_trailing_singletons(void)
octave_idx_type ndims(void) const
Number of dimensions.
bool is_nd_vector(void) const
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
octave_idx_type * to_jit(void) const
octave_idx_type safe_numel(void) const
The following function will throw a std::bad_alloc () exception if the requested size is larger than ...
count_type value(void) const
virtual octave_idx_type numel(void) const
if_then_else< is_class_type< T >::no, T, T const & >::result type
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
T::size_type numel(const T &str)
const octave_base_value const Array< octave_idx_type > & ra_idx
octave_value::octave_value(const Array< char > &chm, char type) return retval
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)