14#ifndef __stir_Array_H__
15#define __stir_Array_H__
45template <
typename topleveliterT,
typename restiterT,
typename elemT,
typename _Ref,
typename _Ptr>
46class FullArrayIterator;
48template <
int num_dimensions,
typename elemT,
typename _Ref,
typename _Ptr>
49class FullArrayIterator;
50template <
int num_dimensions,
typename elemT,
typename _Ref,
typename _Ptr>
51class FullArrayConstIterator;
76template <
int num_dimensions,
typename elemT>
79#ifdef STIR_COMPILING_SWIG_WRAPPER
84 typedef Array<num_dimensions, elemT> self;
91 typedef typename base_type::reference reference;
92 typedef typename base_type::const_reference const_reference;
93 typedef typename base_type::difference_type difference_type;
94 typedef typename base_type::size_type size_type;
95 typedef typename base_type::iterator iterator;
96 typedef typename base_type::const_iterator const_iterator;
105 typedef elemT full_value_type;
106 typedef full_value_type* full_pointer;
107 typedef const full_value_type* const_full_pointer;
108 typedef full_value_type& full_reference;
109 typedef const full_value_type& const_full_reference;
123 const_full_reference,
129 typedef FullArrayConstIterator<num_dimensions, elemT, const_full_reference, const_full_pointer>
const_full_iterator;
171 friend inline void swap(Array& first, Array& second)
175 swap(
static_cast<base_type&
>(first),
static_cast<base_type&
>(second));
176 swap(first._allocated_full_data_ptr, second._allocated_full_data_ptr);
239 inline void fill(
const elemT& n);
263 inline const Array<num_dimensions - 1, elemT>&
operator[](
int i)
const;
274 inline Array<num_dimensions - 1, elemT>& at(
int i);
276 inline const Array<num_dimensions - 1, elemT>& at(
int i)
const;
287 inline self& operator+=(
const self& x)
292 inline self& operator-=(
const self& x)
294 base_type::operator-=(x);
297 inline self& operator*=(
const self& x)
299 base_type::operator*=(x);
302 inline self& operator/=(
const self& x)
304 base_type::operator/=(x);
307 inline self& operator+=(
const elemT x)
309 base_type::operator+=(x);
312 inline self& operator-=(
const elemT x)
314 base_type::operator-=(x);
317 inline self& operator*=(
const elemT x)
319 base_type::operator*=(x);
322 inline self& operator/=(
const elemT x)
324 base_type::operator/=(x);
327 inline self operator+(
const self& x)
const
332 inline self operator+(
const elemT x)
const
337 inline self operator-(
const self& x)
const
342 inline self operator-(
const elemT x)
const
347 inline self operator*(
const self& x)
const
352 inline self operator*(
const elemT x)
const
357 inline self operator/(
const self& x)
const
362 inline self operator/(
const elemT x)
const
370 template <
typename elemT2>
374 inline void xapyb(
const Array& x,
const elemT a,
const Array& y,
const elemT b);
377 inline void xapyb(
const Array& x,
const Array& a,
const Array& y,
const Array& b);
381 inline void sapyb(
const T& a,
const Array& y,
const T& b);
404 mutable bool _full_pointer_access;
407 shared_ptr<elemT[]> _allocated_full_data_ptr;
429 template <
int num_dimensions2,
class elemT2>
441template <
class elemT>
444#ifdef STIR_COMPILING_SWIG_WRAPPER
455 typedef typename base_type::value_type value_type;
456 typedef typename base_type::reference reference;
457 typedef typename base_type::const_reference const_reference;
458 typedef typename base_type::difference_type difference_type;
459 typedef typename base_type::size_type size_type;
460 typedef typename base_type::iterator
iterator;
481 inline Array(
const int min_index,
const int max_index);
504 inline Array(
const self& t);
515 friend inline void swap(
Array& first,
Array& second)
517 swap(
static_cast<base_type&
>(first),
static_cast<base_type&
>(second));
521 inline Array& operator=(
const Array& other);
526 inline full_iterator begin_all();
528 inline const_full_iterator begin_all()
const;
530 inline const_full_iterator begin_all_const()
const;
532 inline full_iterator end_all();
534 inline const_full_iterator end_all()
const;
536 inline const_full_iterator end_all_const()
const;
540 inline IndexRange<1> get_index_range()
const;
543 inline size_t size_all()
const;
546 inline virtual void grow(
const IndexRange<1>& range);
549 inline void grow(
const int min_index,
const int max_index)
override;
552 inline virtual void resize(
const IndexRange<1>& range);
554 inline void resize(
const int min_index,
const int max_index,
bool initialise_with_0);
556 inline void resize(
const int min_index,
const int max_index)
override;
561 bool is_contiguous()
const
566 inline elemT* get_full_data_ptr()
568 return this->get_data_ptr();
572 inline const elemT* get_const_full_data_ptr()
const
574 return this->get_const_data_ptr();
578 inline void release_full_data_ptr()
580 this->release_data_ptr();
584 inline void release_const_full_data_ptr()
const
586 this->release_const_data_ptr();
591 inline elemT
sum()
const;
594 inline elemT sum_positive()
const;
597 inline elemT find_max()
const;
600 inline elemT find_min()
const;
603 inline bool is_regular()
const;
606 bool get_regular_range(BasicCoordinate<1, int>& min, BasicCoordinate<1, int>& max)
const;
611 inline self operator+(
const base_type& iv)
const;
614 inline self operator-(
const base_type& iv)
const;
617 inline self operator*(
const base_type& iv)
const;
620 inline self operator/(
const base_type& iv)
const;
623 inline self operator+(
const elemT a)
const;
626 inline self operator-(
const elemT a)
const;
629 inline self operator*(
const elemT a)
const;
632 inline self operator/(
const elemT a)
const;
635 inline elemT& operator[](
int i);
638 inline const elemT& operator[](
int i)
const;
641 inline const elemT& operator[](
const BasicCoordinate<1, int>& c)
const;
644 inline elemT& operator[](
const BasicCoordinate<1, int>& c);
648 inline elemT& at(
int i);
650 inline const elemT& at(
int i)
const;
652 inline elemT& at(
const BasicCoordinate<1, int>& c);
654 inline const elemT& at(
const BasicCoordinate<1, int>& c)
const;
658 template <
int num_dimensions2,
class elemT2>
665 inline void init_with_copy(
const IndexRange<1>& range, elemT
const*
const data_ptr);
670 inline void init(
const IndexRange<1>& range, elemT*
const data_ptr,
bool copy_data);
679# include "FullArrayIterator2.h"
680# include "FullArrayConstIterator.h"
forward declaration of stir::Array class for multi-dimensional (numeric) arrays
inline implementations for the stir::Array class
This file declares the stir::ByteOrder class.
This file declares the stir::FullArrayIterator class.
This file defines the stir::IndexRange class.
defines the stir::NumericVectorWithOffset class
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
virtual void resize(const IndexRange< num_dimensions > &range)
change the array to a new range of indices, new elements are set to 0
Definition Array.inl:62
const Array< num_dimensions - 1, elemT > & operator[](int i) const
array access, read-only
Definition Array.inl:493
Array(const IndexRange< num_dimensions > &)
Construct an Array of given range of indices, elements are initialised to 0.
Definition Array.inl:115
full_iterator begin_all()
start value for iterating through all elements in the array, see full_iterator
Definition Array.inl:213
elemT & operator[](const BasicCoordinate< num_dimensions, int > &c)
allow array-style access given a BasicCoordinate to specify the indices, read/write
Definition Array.inl:499
FullArrayIterator< typename base_type::iterator, typename Array< num_dimensions - 1, std::complex< float > >::full_iterator, std::complex< float >, full_reference, full_pointer > full_iterator
Definition Array.h:117
Array< num_dimensions - 1, elemT > & operator[](int i)
allow array-style access, read/write
Definition Array.inl:486
const elemT & operator[](const BasicCoordinate< num_dimensions, int > &c) const
array access given a BasicCoordinate to specify the indices, read-only
Definition Array.inl:505
virtual void grow(const IndexRange< num_dimensions > &range)
alias for resize()
Definition Array.inl:103
const_full_iterator begin_all() const
start value for iterating through all elements in the (const) array, see full_iterator
Definition Array.inl:239
Array()
Construct an empty Array.
Definition Array.inl:109
bool is_contiguous() const
return if the array is contiguous in memory
Definition Array.inl:44
void apply_lower_threshold(const elemT &l)
Sets elements below value to the value.
Definition Array.inl:449
size_t size_all() const
return the total number of elements in this array
Definition Array.inl:262
const elemT * get_const_full_data_ptr() const
member function for access to the data via a const elemT*
Definition Array.inl:311
bool get_regular_range(BasicCoordinate< num_dimensions, int > &min, BasicCoordinate< num_dimensions, int > &max) const
find regular range, returns false if the range is not regular
Definition Array.inl:477
elemT sum_positive() const
return sum of all positive elements
Definition Array.inl:370
Array & operator=(Array other)
assignment operator
Definition Array.inl:176
void release_full_data_ptr()
signal end of access to elemT*
Definition Array.inl:329
Array(const base_type &t)
Construct an Array from an object of its base_type.
Definition Array.inl:148
elemT find_max() const
return maximum of all the elements
Definition Array.inl:387
STIR_DEPRECATED void axpby(const elemT2 a, const Array &x, const elemT2 b, const Array &y)
void xapyb(const Array &x, const Array &a, const Array &y, const Array &b)
set values of the array to x*a+y*b, where a and b are arrays
Definition Array.inl:563
void xapyb(const Array &x, const elemT a, const Array &y, const elemT b)
set values of the array to x*a+y*b, where a and b are scalar
Definition Array.inl:546
elemT * get_full_data_ptr()
member function for access to the data via a elemT*
Definition Array.inl:292
Array(Array &&other) noexcept
move constructor
Array(const self &t)
Copy constructor.
Definition Array.inl:136
base_type::value_type value_type
Definition Array.h:90
bool is_regular() const
checks if the index range is 'regular'
Definition Array.inl:469
const_full_iterator end_all_const() const
end value for iterating through all elements in the array, see full_iterator
Definition Array.inl:196
elemT find_min() const
return minimum of all the elements
Definition Array.inl:413
void sapyb(const T &a, const Array &y, const T &b)
set values of the array to self*a+y*b where a and b are scalar or arrays
Definition Array.inl:585
void release_const_full_data_ptr() const
signal end of access to const elemT*
Definition Array.inl:345
full_iterator end_all()
end value for iterating through all elements in the array, see full_iterator
Definition Array.inl:185
void fill(const elemT &n)
Fill elements with value n.
Definition Array.inl:439
const_full_iterator begin_all_const() const
start value for iterating through all elements in the array, see full_iterator
Definition Array.inl:226
elemT sum() const
return sum of all elements
Definition Array.inl:353
Array(const IndexRange< num_dimensions > &range, shared_ptr< elemT[]> data_sptr)
Construct an Array pointing to existing contiguous data.
Definition Array.inl:129
FullArrayIterator< typename base_type::const_iterator, typename Array< num_dimensions - 1, std::complex< float > >::const_full_iterator, std::complex< float >, const_full_reference, const_full_pointer > const_full_iterator
Definition Array.h:125
friend void swap(Array &first, Array &second)
Swap content/members of 2 objects.
Definition Array.h:171
const_full_iterator end_all() const
end value for iterating through all elements in the (const) array, see full_iterator
Definition Array.inl:206
~Array() override
virtual destructor, frees up any allocated memory
Definition Array.inl:157
void apply_upper_threshold(const elemT &u)
Sets elements above value to the value.
Definition Array.inl:459
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition BasicCoordinate.h:57
Class FullArrayIterator implements (forward) iterators that go through all elements of an Array.
Definition FullArrayIterator.h:49
This class defines ranges which can be 'irregular'.
Definition IndexRange.h:69
like VectorWithOffset, but with changes in various numeric operators
Definition NumericVectorWithOffset.h:48
NumericVectorWithOffset & operator+=(const NumericVectorWithOffset &v)
Definition NumericVectorWithOffset.inl:137
NumericVectorWithOffset(const VectorWithOffset< Array< num_dimensions - 1, elemT > > &t)
virtual void grow(const int min_index, const int max_index)
Definition VectorWithOffset.inl:491
virtual void resize(const int min_index, const int max_index)
Definition VectorWithOffset.inl:426
This file declares a deprecation macro.
#define STIR_DEPRECATED
Deprecation macro.
Definition deprecated.h:21
elemT sum(IterT start, IterT end, elemT init)
Compute the sum of a sequence using operator+=(), using an initial value.
Definition more_algorithms.inl:52
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast into the stir names...