STIR  6.2.0
Public Types | Public Member Functions | Friends | List of all members
stir::Array< 1, elemT > Class Template Reference

The 1-dimensional (partial) specialisation of Array. More...

#include "stir/Array.h"

Inheritance diagram for stir::Array< 1, elemT >:
Inheritance graph
[legend]

Public Types

typedef iterator full_iterator
 Iterator type for going through all elements. More...
 
typedef const_iterator const_full_iterator
 Iterator type for going through all elements of a const object.
 
typedef base_type::value_type value_type
 typedefs such that we do not need to have typename wherever we use these types defined in the base class
 
typedef base_type::reference reference
 
typedef base_type::const_reference const_reference
 
typedef base_type::difference_type difference_type
 
typedef base_type::size_type size_type
 
typedef base_type::iterator iterator
 
typedef base_type::const_iterator const_iterator
 
- Public Types inherited from stir::VectorWithOffset< elemT >
typedef size_t size_type
 
typedef elemT value_type
 
typedef value_type & reference
 
typedef const value_type & const_reference
 
typedef ptrdiff_t difference_type
 
typedef elemT * iterator
 
typedef elemT const * const_iterator
 
typedef std::reverse_iterator< iterator > reverse_iterator
 
typedef std::reverse_iterator< const_iterator > const_reverse_iterator
 

Public Member Functions

 Array ()
 default constructor: array of length 0
 
 Array (const IndexRange< 1 > &range)
 constructor given an IndexRange<1>, initialising elements to 0
 
 Array (const int min_index, const int max_index)
 constructor given first and last indices, initialising elements to 0
 
 Array (const IndexRange< 1 > &range, shared_ptr< elemT[]> data_sptr)
 constructor given an IndexRange<1>, pointing to existing contiguous data More...
 
 Array (const IndexRange< 1 > &range, const elemT *const data_ptr)
 constructor given an IndexRange<1> from existing contiguous data (will copy) More...
 
 Array (const NumericVectorWithOffset< elemT, elemT > &il)
 constructor from basetype
 
 Array (const self &t)
 Copy constructor.
 
 Array (Array &&other) noexcept
 move constructor More...
 
 ~Array () override
 virtual destructor
 
Arrayoperator= (const Array &other)
 assignment
 
IndexRange< 1 > get_index_range () const
 return the range of indices used
 
size_t size_all () const
 return the total number of elements in this array
 
virtual void grow (const IndexRange< 1 > &range)
 Array::grow initialises new elements to 0.
 
void grow (const int min_index, const int max_index) override
 grow the range of the vector, new elements are set to T() More...
 
virtual void resize (const IndexRange< 1 > &range)
 Array::resize initialises new elements to 0.
 
void resize (const int min_index, const int max_index) override
 change the range of the vector, new elements are set to T() More...
 
elemT sum () const
 return sum of all elements
 
elemT sum_positive () const
 add up all positive elemTs in the vector
 
elemT find_max () const
 return maximum value of all elements
 
elemT find_min () const
 return minimum value of all elements
 
bool is_regular () const
 checks if the index range is 'regular' (always true as this is the 1D case)
 
bool get_regular_range (BasicCoordinate< 1, int > &min, BasicCoordinate< 1, int > &max) const
 find regular range, returns false if the range is not regular
 
self operator+ (const base_type &iv) const
 elem by elem addition
 
self operator- (const base_type &iv) const
 elem by elem subtraction
 
self operator* (const base_type &iv) const
 elem by elem multiplication
 
self operator/ (const base_type &iv) const
 elem by elem division
 
self operator+ (const elemT a) const
 addition with an 'elemT'
 
self operator- (const elemT a) const
 subtraction with an 'elemT'
 
self operator* (const elemT a) const
 multiplication with an 'elemT'
 
self operator/ (const elemT a) const
 division with an 'elemT'
 
elemT & operator[] (int i)
 allow array-style access, read/write
 
const elemT & operator[] (int i) const
 array access, read-only
 
const elemT & operator[] (const BasicCoordinate< 1, int > &c) const
 allow array-style access giving its BasicCoordinate, read/write
 
elemT & operator[] (const BasicCoordinate< 1, int > &c)
 array access giving its BasicCoordinate, read-only
 
template<class elemT >
 Array (const base_type &il)
 
template<typename elemT >
 Array (const Array< 1, elemT > &other)
 
template<typename elemT >
 Array (Array< 1, elemT > &&other) noexcept
 
functions returning full_iterators
full_iterator begin_all ()
 start value for iterating through all elements in the array, see full_iterator
 
const_full_iterator begin_all () const
 start value for iterating through all elements in the (const) array, see full_iterator
 
const_full_iterator begin_all_const () const
 start value for iterating through all elements in the array, see full_iterator
 
full_iterator end_all ()
 end value for iterating through all elements in the array, see full_iterator
 
const_full_iterator end_all () const
 end value for iterating through all elements in the (const) array, see full_iterator
 
const_full_iterator end_all_const () const
 end value for iterating through all elements in the array, see full_iterator
 
access to the data via a pointer
bool is_contiguous () const
 return if the array is contiguous in memory (always true)
 
elemT * get_full_data_ptr ()
 member function for access to the data via a elemT*
 
const elemT * get_const_full_data_ptr () const
 member function for access to the data via a const elemT*
 
void release_full_data_ptr ()
 signal end of access to elemT*
 
void release_const_full_data_ptr () const
 signal end of access to const elemT*
 
indexed access with range checking (throw std:out_of_range)
elemT & at (int i)
 
const elemT & at (int i) const
 
elemT & at (const BasicCoordinate< 1, int > &c)
 
const elemT & at (const BasicCoordinate< 1, int > &c) const
 
- Public Member Functions inherited from stir::NumericVectorWithOffset< elemT, elemT >
 NumericVectorWithOffset (const VectorWithOffset< elemT > &t)
 Constructor from an object of this class' base_type.
 
 NumericVectorWithOffset (const NumericVectorWithOffset &t)
 Constructor from an object of this class' base_type.
 
 NumericVectorWithOffset (NumericVectorWithOffset &&other) noexcept
 move constructor More...
 
NumericVectorWithOffsetoperator= (const NumericVectorWithOffset &other)
 assignment
 
NumericVectorWithOffset operator+ (const NumericVectorWithOffset &v) const
 adding vectors, element by element
 
NumericVectorWithOffset operator+ (const elemT &v) const
 return a new vector with elements equal to the sum of the elements in the original and the elemT
 
NumericVectorWithOffset operator- (const NumericVectorWithOffset &v) const
 subtracting vectors, element by element
 
NumericVectorWithOffset operator- (const elemT &v) const
 return a new vector with elements equal to the difference of the elements in the original and the elemT
 
NumericVectorWithOffset operator* (const NumericVectorWithOffset &v) const
 multiplying vectors, element by element
 
NumericVectorWithOffset operator* (const elemT &v) const
 return a new vector with elements equal to the multiplication of the elements in the original and the elemT
 
NumericVectorWithOffset operator/ (const NumericVectorWithOffset &v) const
 dividing vectors, element by element
 
NumericVectorWithOffset operator/ (const elemT &v) const
 return a new vector with elements equal to the division of the elements in the original and the elemT
 
NumericVectorWithOffsetoperator+= (const NumericVectorWithOffset &v)
 adding elements of v to the current vector More...
 
NumericVectorWithOffsetoperator+= (const elemT &v)
 adding an elemT to the elements of the current vector
 
NumericVectorWithOffsetoperator-= (const NumericVectorWithOffset &v)
 subtracting elements of v from the current vector More...
 
NumericVectorWithOffsetoperator-= (const elemT &v)
 subtracting an elemT from the elements of the current vector
 
NumericVectorWithOffsetoperator*= (const NumericVectorWithOffset &v)
 multiplying elements of the current vector with elements of v More...
 
NumericVectorWithOffsetoperator*= (const elemT &v)
 multiplying the elements of the current vector with an elemT
 
NumericVectorWithOffsetoperator/= (const NumericVectorWithOffset &v)
 dividing all elements of the current vector by elements of v More...
 
NumericVectorWithOffsetoperator/= (const elemT &v)
 dividing the elements of the current vector by an elemT
 
STIR_DEPRECATED void axpby (const elemT2 a, const NumericVectorWithOffset &x, const elemT2 b, const NumericVectorWithOffset &y)
 
void axpby (const NUMBER2 a, const NumericVectorWithOffset &x, const NUMBER2 b, const NumericVectorWithOffset &y)
 
void xapyb (const NumericVectorWithOffset &x, const elemT a, const NumericVectorWithOffset &y, const elemT b)
 set values of the array to x*a+y*b, where a and b are scalar
 
void xapyb (const NumericVectorWithOffset &x, const NumericVectorWithOffset &a, const NumericVectorWithOffset &y, const NumericVectorWithOffset &b)
 set the values of the array to x*a+y*b, where a and b are vectors
 
void sapyb (const T2 &a, const NumericVectorWithOffset &y, const T2 &b)
 set the values of the array to self*a+y*b, where a and b are scalar or vectors
 
- Public Member Functions inherited from stir::VectorWithOffset< elemT >
 VectorWithOffset ()
 Default constructor: creates a vector of length 0.
 
 VectorWithOffset (const int hsz)
 Construct a VectorWithOffset of given length (initialised with T())
 
 VectorWithOffset (const int min_index, const int max_index)
 Construct a VectorWithOffset with offset min_index (initialised with T())
 
STIR_DEPRECATED VectorWithOffset (const int hsz, elemT *const data_ptr, elemT *const end_of_data_ptr)
 Construct a VectorWithOffset of given length pointing to existing data. More...
 
STIR_DEPRECATED VectorWithOffset (const int min_index, const int max_index, elemT *const data_ptr, elemT *const end_of_data_ptr)
 Construct a VectorWithOffset with offset min_index pointing to existing data. More...
 
 VectorWithOffset (const int hsz, const elemT *const data_ptr)
 Construct a VectorWithOffset of given length from a bare pointer (copying data)
 
 VectorWithOffset (const int min_index, const int max_index, const elemT *const data_ptr)
 Construct a VectorWithOffset with offset min_index from a bare pointer (copying data)
 
 VectorWithOffset (const int min_index, const int max_index, shared_ptr< elemT []> data_sptr)
 Construct a VectorWithOffset sharing existing data. More...
 
 VectorWithOffset (const int sz, shared_ptr< elemT []> data_sptr)
 Construct a VectorWithOffset sharing existing data. More...
 
 VectorWithOffset (const VectorWithOffset &il)
 copy constructor
 
 VectorWithOffset (VectorWithOffset &&other) noexcept
 move constructor More...
 
virtual ~VectorWithOffset ()
 Destructor.
 
void recycle ()
 Free all memory and make object as if default-constructed. More...
 
VectorWithOffsetoperator= (const VectorWithOffset &il)
 assignment operator with another vector More...
 
elemT & operator[] (int i)
 allow array-style access, read/write More...
 
const elemT & operator[] (int i) const
 array access, read-only More...
 
elemT & at (int i)
 allow array-style access, read/write, but with range checking (throws std::out_of_range)
 
const elemT & at (int i) const
 array access, read-only, but with range checking (throws std::out_of_range)
 
bool empty () const
 checks if the vector is empty
 
void fill (const elemT &n)
 fill elements with value n
 
void apply_lower_threshold (const elemT &lower)
 Sets elements below value to the value.
 
void apply_upper_threshold (const elemT &upper)
 Sets elements above value to the value.
 
int get_length () const
 return number of elements in this vector More...
 
size_t size () const
 return number of elements in this vector
 
int get_min_index () const
 get value of first valid index
 
int get_max_index () const
 get value of last valid index
 
void set_offset (const int min_index)
 change value of starting index
 
void set_min_index (const int min_index)
 identical to set_offset()
 
void grow (const unsigned int new_size)
 grow the range of the vector from 0 to new_size-1, new elements are set to T()
 
void resize (const unsigned int new_size)
 change the range of the vector from 0 to new_size-1, new elements are set to T()
 
void reserve (const int min_index, const int max_index)
 make the allocated range at least from min_index to max_index
 
void reserve (const unsigned int new_size)
 make the allocated range at least from 0 to new_size-1
 
size_t capacity () const
 get allocated size
 
bool owns_memory_for_data () const
 check if this object owns the memory for the data More...
 
int get_capacity_min_index () const
 get min_index within allocated range More...
 
int get_capacity_max_index () const
 get max_index within allocated range More...
 
bool operator== (const VectorWithOffset &iv) const
 
bool operator!= (const VectorWithOffset &iv) const
 
elemT * get_data_ptr ()
 member function for access to the data via a T* More...
 
const elemT * get_const_data_ptr () const
 member function for access to the data via a const T* More...
 
void release_data_ptr ()
 signal end of access to T* More...
 
void release_const_data_ptr () const
 signal end of access to const T* More...
 
iterator begin ()
 use to initialise an iterator to the first element of the vector
 
const_iterator begin () const
 use to initialise an iterator to the first element of the (const) vector
 
iterator end ()
 iterator 'past' the last element of the vector
 
const_iterator end () const
 iterator 'past' the last element of the (const) vector
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
VectorWithOffsetoperator+= (const VectorWithOffset &v)
 adding elements of v to the current vector
 
VectorWithOffsetoperator-= (const VectorWithOffset &v)
 subtracting elements of v from the current vector
 
VectorWithOffsetoperator*= (const VectorWithOffset &v)
 multiplying elements of the current vector with elements of v
 
VectorWithOffsetoperator/= (const VectorWithOffset &v)
 dividing all elements of the current vector by elements of v
 
VectorWithOffset operator+ (const VectorWithOffset &v) const
 adding vectors, element by element
 
VectorWithOffset operator- (const VectorWithOffset &v) const
 subtracting vectors, element by element
 
VectorWithOffset operator* (const VectorWithOffset &v) const
 multiplying vectors, element by element
 
VectorWithOffset operator/ (const VectorWithOffset &v) const
 dividing vectors, element by element
 

Friends

template<int num_dimensions2, class elemT2 >
class Array
 
void swap (Array &first, Array &second)
 Swap content/members of 2 objects.
 

Additional Inherited Members

- Protected Member Functions inherited from stir::VectorWithOffset< elemT >
void check_state () const
 Called internally to see if all variables are consistent. More...
 
void init (const int min_index, const int max_index, elemT *const data_ptr, bool copy_data)
 change vector with new index range and point to data_ptr More...
 
- Protected Attributes inherited from stir::VectorWithOffset< elemT >
elemT * num
 pointer to (*this)[0] (taking get_min_index() into account that is).
 

Detailed Description

template<class elemT>
class stir::Array< 1, elemT >

The 1-dimensional (partial) specialisation of Array.

Member Typedef Documentation

◆ full_iterator

template<class elemT >
typedef iterator stir::Array< 1, elemT >::full_iterator

Iterator type for going through all elements.

for 1D arrays, full iterators are equal to normal iterators

Constructor & Destructor Documentation

◆ Array() [1/3]

template<class elemT >
stir::Array< 1, elemT >::Array ( const IndexRange< 1 > &  range,
shared_ptr< elemT[]>  data_sptr 
)
inline

constructor given an IndexRange<1>, pointing to existing contiguous data

  • data_ptr should point to a contiguous block of correct size. The constructed Array will essentially be a "view" of the data_sptr block. Therefore, any modifications to the array will modify the data at data_sptr. This will be the case until the Array is resized.

◆ Array() [2/3]

template<class elemT >
stir::Array< 1, elemT >::Array ( const IndexRange< 1 > &  range,
const elemT *const  data_ptr 
)
inline

constructor given an IndexRange<1> from existing contiguous data (will copy)

  • data_ptr should point to a contiguous block of correct size.

References stir::Array< num_dimensions, elemT >::Array().

◆ Array() [3/3]

template<class elemT >
stir::Array< 1, elemT >::Array ( Array< 1, elemT > &&  other)
noexcept

move constructor

implementation uses the copy-and-swap idiom, see e.g. https://stackoverflow.com/a/3279550

Member Function Documentation

◆ grow()

template<class elemT >
void stir::Array< 1, elemT >::grow ( const int  min_index,
const int  max_index 
)
inlineoverridevirtual

grow the range of the vector, new elements are set to T()

Currently, it is only checked with assert() if old range is a subinterval of the new range.

grow() currently simply calls resize(). However, if you overload resize() in a derived class, it is probably safest to overload grow() as well.

Reimplemented from stir::VectorWithOffset< elemT >.

◆ resize()

template<class elemT >
void stir::Array< 1, elemT >::resize ( const int  min_index,
const int  max_index 
)
inlineoverridevirtual

change the range of the vector, new elements are set to T()

New memory is allocated if the range grows outside the range specified by get_capacity_min_index() till get_capacity_max_index(). Data is then copied and old memory deallocated (unless it is shared).

Todo:
in principle reallocation could be avoided when the new range would fit in the old one by shifting.

Reimplemented from stir::VectorWithOffset< elemT >.


The documentation for this class was generated from the following files: