STIR 6.5.0
stir::NumericVectorWithOffset< T, elemT > Class Template Reference

like VectorWithOffset, but with changes in various numeric operators More...

#include "stir/NumericVectorWithOffset.h"

Inheritance diagram for stir::NumericVectorWithOffset< T, elemT >:

Public Member Functions

 NumericVectorWithOffset (const VectorWithOffset< T > &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
NumericVectorWithOffset & operator= (const NumericVectorWithOffset &other)
 assignment
NumericVectorWithOffset operator+ (const NumericVectorWithOffset &v) const
 adding vectors, element by element
NumericVectorWithOffset operator- (const NumericVectorWithOffset &v) const
 subtracting vectors, element by element
NumericVectorWithOffset operator* (const NumericVectorWithOffset &v) const
 multiplying vectors, element by element
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 sum of the elements in the original and the elemT
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 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 elemT &v) const
 return a new vector with elements equal to the division of the elements in the original and the elemT
NumericVectorWithOffset & operator+= (const NumericVectorWithOffset &v)
 adding elements of v to the current vector
NumericVectorWithOffset & operator-= (const NumericVectorWithOffset &v)
 subtracting elements of v from the current vector
NumericVectorWithOffset & operator*= (const NumericVectorWithOffset &v)
 multiplying elements of the current vector with elements of v
NumericVectorWithOffset & operator/= (const NumericVectorWithOffset &v)
 dividing all elements of the current vector by elements of v
NumericVectorWithOffset & operator+= (const elemT &v)
 adding an elemT to the elements of the current vector
NumericVectorWithOffset & operator-= (const elemT &v)
 subtracting an elemT from the elements of the current vector
NumericVectorWithOffset & operator*= (const elemT &v)
 multiplying the elements of the current vector with an elemT
NumericVectorWithOffset & operator/= (const elemT &v)
 dividing the elements of the current vector by an elemT
template<typename elemT2>
STIR_DEPRECATED void axpby (const elemT2 a, const NumericVectorWithOffset &x, const elemT2 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
template<class T2>
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
template<class NUMBER2>
void axpby (const NUMBER2 a, const NumericVectorWithOffset &x, const NUMBER2 b, const NumericVectorWithOffset &y)
Public Member Functions inherited from stir::VectorWithOffset< T >
int get_length () const
 return number of elements in this vector
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()
virtual void grow (const int min_index, const int max_index)
 grow the range of the vector, new elements are set to T()
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()
virtual void resize (const int min_index, const int max_index)
 change the range of the vector, 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
int get_capacity_min_index () const
 get min_index within allocated range
int get_capacity_max_index () const
 get max_index within allocated range
T & operator[] (int i)
 allow array-style access, read/write
const T & operator[] (int i) const
 array access, read-only
T & at (int i)
 allow array-style access, read/write, but with range checking (throws std::out_of_range)
const T & 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
bool operator== (const VectorWithOffset &iv) const
bool operator!= (const VectorWithOffset &iv) const
void fill (const T &n)
 fill elements with value n
void apply_lower_threshold (const T &lower)
 Sets elements below value to the value.
void apply_upper_threshold (const T &upper)
 Sets elements above value to the value.
T * get_data_ptr ()
 member function for access to the data via a T*
const T * get_const_data_ptr () const
 member function for access to the data via a const T*
void release_data_ptr ()
 signal end of access to T*
void release_const_data_ptr () const
 signal end of access to const T*
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 ()
reverse_iterator rend ()
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
VectorWithOffset & operator+= (const VectorWithOffset &v)
 adding elements of v to the current vector
VectorWithOffset & operator-= (const VectorWithOffset &v)
 subtracting elements of v from the current vector
VectorWithOffset & operator*= (const VectorWithOffset &v)
 multiplying elements of the current vector with elements of v
VectorWithOffset & operator/= (const VectorWithOffset &v)
 dividing all elements of the current vector by elements of v
 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, T *const data_ptr, T *const end_of_data_ptr)
 Construct a VectorWithOffset of given length pointing to existing data.
STIR_DEPRECATED VectorWithOffset (const int min_index, const int max_index, T *const data_ptr, T *const end_of_data_ptr)
 Construct a VectorWithOffset with offset min_index pointing to existing data.
 VectorWithOffset (const int hsz, const T *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 T *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< T[]> data_sptr)
 Construct a VectorWithOffset sharing existing data.
 VectorWithOffset (const int sz, shared_ptr< T[]> data_sptr)
 Construct a VectorWithOffset sharing existing data.
 VectorWithOffset (const VectorWithOffset &il)
 copy constructor
virtual ~VectorWithOffset ()
 Destructor.
 VectorWithOffset (VectorWithOffset &&other) noexcept
 move constructor
void recycle ()
 Free all memory and make object as if default-constructed.
VectorWithOffset & operator= (const VectorWithOffset &il)
 assignment operator with another vector
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

void swap (NumericVectorWithOffset &first, NumericVectorWithOffset &second)
 Swap content/members of 2 objects.

Additional Inherited Members

typedef T value_type
typedef value_type & reference
typedef const value_type & const_reference
typedef ptrdiff_t difference_type
typedef T * iterator
typedef T const * const_iterator
typedef std::reverse_iterator< iterator > reverse_iterator
typedef std::reverse_iterator< const_iterator > const_reverse_iterator
typedef size_t size_type
void check_state () const
 Called internally to see if all variables are consistent.
void init_with_copy (const int min_index, const int max_index, T const *const data_ptr)
 change vector to the new index range and copy data from data_ptr
void init (const int min_index, const int max_index, T *const data_ptr, bool copy_data)
 initialise vector to the given index range and either copy from or point to data_ptr
T * num
 pointer to (*this)[0] (taking get_min_index() into account that is).

Detailed Description

template<class T, class elemT>
class stir::NumericVectorWithOffset< T, elemT >

like VectorWithOffset, but with changes in various numeric operators

Compared to VectorWithOffset, the numeric operators +,-,,/ with NumericVectorWithOffset objects return an object with the largest index range of its arguments. Similarly operators +=,-=,=,/= potentially grow the *this object.

In addition, operators +=,-=,*=,/= with objects of type elemT are defined.

Warning
It is likely that the automatic growing feature will be removed at some point.

Constructor & Destructor Documentation

◆ NumericVectorWithOffset() [1/2]

template<class T, class NUMBER>
stir::NumericVectorWithOffset< T, NUMBER >::NumericVectorWithOffset ( const VectorWithOffset< T > & t)
inline

◆ NumericVectorWithOffset() [2/2]

template<class T, class elemT>
stir::NumericVectorWithOffset< T, elemT >::NumericVectorWithOffset ( NumericVectorWithOffset< T, elemT > && other)
noexcept

move constructor

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

Member Function Documentation

◆ operator=()

template<class T, class elemT>
NumericVectorWithOffset< T, NUMBER > & stir::NumericVectorWithOffset< T, NUMBER >::operator= ( const NumericVectorWithOffset< T, elemT > & other)

◆ operator+()

template<class T, class NUMBER>
NumericVectorWithOffset< T, NUMBER > stir::NumericVectorWithOffset< T, NUMBER >::operator+ ( const NumericVectorWithOffset< T, elemT > & v) const
inline

adding vectors, element by element

References stir::VectorWithOffset< T >::check_state(), and NumericVectorWithOffset().

◆ operator-()

template<class T, class NUMBER>
NumericVectorWithOffset< T, NUMBER > stir::NumericVectorWithOffset< T, NUMBER >::operator- ( const NumericVectorWithOffset< T, elemT > & v) const
inline

subtracting vectors, element by element

References stir::VectorWithOffset< T >::check_state(), and NumericVectorWithOffset().

◆ operator*()

template<class T, class NUMBER>
NumericVectorWithOffset< T, NUMBER > stir::NumericVectorWithOffset< T, NUMBER >::operator* ( const NumericVectorWithOffset< T, elemT > & v) const
inline

multiplying vectors, element by element

References stir::VectorWithOffset< T >::check_state(), and NumericVectorWithOffset().

◆ operator/()

template<class T, class NUMBER>
NumericVectorWithOffset< T, NUMBER > stir::NumericVectorWithOffset< T, NUMBER >::operator/ ( const NumericVectorWithOffset< T, elemT > & v) const
inline

dividing vectors, element by element

References NumericVectorWithOffset().

◆ operator+=()

template<class T, class NUMBER>
NumericVectorWithOffset< T, NUMBER > & stir::NumericVectorWithOffset< T, NUMBER >::operator+= ( const NumericVectorWithOffset< T, elemT > & v)
inline

adding elements of v to the current vector

This will grow the vector automatically if the 2nd argument has smaller min_index and/or larger max_index. New elements are first initialised with T() before adding.

References stir::VectorWithOffset< T >::check_state(), stir::VectorWithOffset< T >::get_length(), stir::VectorWithOffset< T >::get_max_index(), stir::VectorWithOffset< T >::get_min_index(), stir::VectorWithOffset< T >::grow(), stir::VectorWithOffset< T >::num, and NumericVectorWithOffset().

◆ operator-=()

◆ operator*=()

template<class T, class NUMBER>
NumericVectorWithOffset< T, NUMBER > & stir::NumericVectorWithOffset< T, NUMBER >::operator*= ( const NumericVectorWithOffset< T, elemT > & v)
inline

◆ operator/=()

template<class T, class NUMBER>
NumericVectorWithOffset< T, NUMBER > & stir::NumericVectorWithOffset< T, NUMBER >::operator/= ( const NumericVectorWithOffset< T, elemT > & v)
inline

◆ axpby()

template<class T, class elemT>
template<typename elemT2>
STIR_DEPRECATED void stir::NumericVectorWithOffset< T, elemT >::axpby ( const elemT2 a,
const NumericVectorWithOffset< T, elemT > & x,
const elemT2 b,
const NumericVectorWithOffset< T, elemT > & y )
inline
Deprecated
a*x+b*y (use xapyb)

◆ xapyb() [1/2]

template<class T, class elemT>
void stir::NumericVectorWithOffset< T, elemT >::xapyb ( const NumericVectorWithOffset< T, elemT > & x,
const elemT a,
const NumericVectorWithOffset< T, elemT > & y,
const elemT b )
inline

set values of the array to x*a+y*b, where a and b are scalar

Referenced by sapyb().

◆ xapyb() [2/2]

template<class T, class NUMBER>
void stir::NumericVectorWithOffset< T, NUMBER >::xapyb ( const NumericVectorWithOffset< T, elemT > & x,
const NumericVectorWithOffset< T, elemT > & a,
const NumericVectorWithOffset< T, elemT > & y,
const NumericVectorWithOffset< T, elemT > & b )
inline

◆ sapyb()

template<class T, class NUMBER>
template<class T2>
void stir::NumericVectorWithOffset< T, NUMBER >::sapyb ( const T2 & a,
const NumericVectorWithOffset< T, elemT > & y,
const T2 & b )
inline

set the values of the array to self*a+y*b, where a and b are scalar or vectors

References NumericVectorWithOffset(), and xapyb().


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