26 #if !defined (octave_Array_h)
27 #define octave_Array_h 1
75 std::copy (d, d+l, data);
78 ArrayRep (
void) : data (0), len (0), count (1) { }
90 : data (
no_ctor_new<T> (a.len)), len (a.len), count (1)
110 void make_unique (
void)
114 ArrayRep *r =
new ArrayRep (slice_data, slice_len);
116 if (--rep->count == 0)
120 slice_data = rep->data;
129 typename ref_param<T>::type);
150 : dimensions (dv), rep(a.rep), slice_data (a.slice_data+l), slice_len (u-l)
172 : dimensions (adims),
173 rep (reinterpret_cast<typename
Array<T>::ArrayRep *> (arep)),
174 slice_data (sdata), slice_len (slen) { }
181 : dimensions (), rep (nil_rep ()), slice_data (rep->data),
190 slice_data (rep->
data), slice_len (rep->
len)
196 slice_data (rep->
data), slice_len (rep->
len)
204 rep (new typename
Array<T>::ArrayRep (dv.safe_numel ())),
205 slice_data (rep->data), slice_len (rep->len)
213 rep (new typename
Array<T>::ArrayRep (dv.safe_numel ())),
214 slice_data (rep->data), slice_len (rep->len)
226 : dimensions (a.dims ()),
227 rep (new typename
Array<T>::ArrayRep (a.data (), a.
length ())),
228 slice_data (rep->data), slice_len (rep->len)
233 : dimensions (a.dimensions), rep (a.rep), slice_data (a.slice_data),
234 slice_len (a.slice_len)
243 if (--rep->
count == 0)
251 if (--rep->
count == 0)
265 void fill (
const T& val);
286 if (dimensions.
length () != 2 || dimensions(1) != 1)
296 if (dimensions.
length () != 2 || dimensions(0) != 1)
306 if (dimensions.
length () != 2)
317 size_t byte_size (
void)
const
318 {
return static_cast<size_t> (numel ()) *
sizeof (T); }
343 {
return xelem (dim1 ()*j+i); }
345 {
return xelem (dim1 ()*j+i); }
348 {
return xelem (i, dim2 ()*k+j); }
350 {
return xelem (i, dim2 ()*k+j); }
353 {
return xelem (compute_index_unchecked (ra_idx)); }
356 {
return xelem (compute_index_unchecked (ra_idx)); }
375 {
return elem (i, dim2 ()*k+j); }
380 #if defined (BOUNDS_CHECKING)
383 {
return checkelem (i, j); }
385 {
return checkelem (i, j, k); }
387 {
return checkelem (ra_idx); }
392 {
return elem (i, j, k); }
394 {
return elem (ra_idx); }
406 {
return xelem (i, j); }
409 {
return xelem (i, j, k); }
414 #if defined (BOUNDS_CHECKING)
417 {
return checkelem (i, j); }
420 {
return checkelem (i, j, k); }
422 {
return checkelem (ra_idx); }
426 {
return elem (i, j); }
429 {
return elem (i, j, k); }
431 {
return elem (ra_idx); }
450 {
return Array<T> (*
this, new_dims); }
454 {
return permute (vec,
true); }
456 bool is_square (
void)
const {
return (dim1 () == dim2 ()); }
458 bool is_empty (
void)
const {
return numel () == 0; }
463 Array<T> hermitian (T (*fcn) (
const T&) = 0)
const;
465 const T *
data (
void)
const {
return slice_data; }
469 T *fortran_vec (
void);
483 virtual T resize_fill_value (
void)
const;
495 resize2 (nr, nc, rfv);
500 resize2 (nr, nc, resize_fill_value ());
503 void resize (
const dim_vector& dv,
const T& rfv);
513 return index (i, resize_ok, resize_fill_value ());
519 bool resize_ok)
const
521 return index (i, j, resize_ok, resize_fill_value ());
528 return index (ia, resize_ok, resize_fill_value ());
536 assign (i, rhs, resize_fill_value ());
543 assign (i, j, rhs, resize_fill_value ());
549 assign (ia, rhs, resize_fill_value ());
558 void delete_elements (
int dim,
const idx_vector& i);
572 void maybe_economize (
void)
574 if (rep->
count == 1 && slice_len != rep->
len)
576 ArrayRep *new_rep =
new ArrayRep (slice_data, slice_len);
579 slice_data = rep->
data;
583 void print_info (std::ostream& os,
const std::string& prefix)
const;
617 bool backward =
false)
const;
633 template <
class U,
class F>
639 const T *m = data ();
645 for (i = 0; i < len - 3; i += 4)
650 p[i+1] = fcn (m[i+1]);
651 p[i+2] = fcn (m[i+2]);
652 p[i+3] = fcn (m[i+3]);
666 map (U (&fcn) (T))
const
667 {
return map<U, U (&) (T)> (fcn); }
671 map (U (&fcn) (
const T&))
const
672 {
return map<U, U (&) (const T&)> (fcn); }
675 template <
class F,
bool zero>
676 bool test (
F fcn)
const
678 return any_all_test<F, T, zero> (fcn, data (),
length ());
683 bool test_any (
F fcn)
const
684 {
return test<F, false> (fcn); }
687 bool test_all (
F fcn)
const
688 {
return test<F, true> (fcn); }
691 bool test_any (
bool (&fcn) (T))
const
692 {
return test<bool (&) (T), false> (fcn); }
694 bool test_any (
bool (&fcn) (
const T&))
const
695 {
return test<bool (&) (const T&), false> (fcn); }
697 bool test_all (
bool (&fcn) (T))
const
698 {
return test<bool (&) (T), true> (fcn); }
700 bool test_all (
bool (&fcn) (
const T&))
const
701 {
return test<bool (&) (const T&), true> (fcn); }
703 template <
class U>
friend class Array;
737 template<
class ArrayClass>
740 typedef typename ArrayClass::element_type
T;
748 template <
class X,
class Y>
751 template <
class X,
class Y,
class Z>
755 {
return ArrayClass::xelem (n); }
757 {
return ArrayClass::xelem (i, j); }
759 {
return ArrayClass::xelem (i, j, k); }
761 {
return ArrayClass::xelem (ra_idx); }
766 operator << (std::ostream& os, const Array<T>& a);