Skip to content

Commit

Permalink
Array: clean-up
Browse files Browse the repository at this point in the history
- make sure it works with other STIR classes, not just floats etc
- re-instate VectorWithOffset constructors that take both start and end pointers for backwards compatibility
  • Loading branch information
KrisThielemans committed Aug 24, 2023
1 parent 109d57e commit 9d61813
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/include/stir/Array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ Array<num_dimensions, elemT>::Array(const IndexRange<num_dimensions>& range)
//grow(range);
this->_allocated_full_data_ptr = new elemT[range.size_all()];
// info("Array constructor range " + std::to_string(reinterpret_cast<std::size_t>(this->_allocated_full_data_ptr)) + " of size " + std::to_string(range.size_all()));
std::fill(this->_allocated_full_data_ptr, this->_allocated_full_data_ptr + range.size_all(), elemT(0));
// set elements to zero
std::for_each(this->_allocated_full_data_ptr, this->_allocated_full_data_ptr + range.size_all(), [](elemT& e) { assign(e, 0); });
this->init(range, this->_allocated_full_data_ptr, false);
}

Expand Down
24 changes: 20 additions & 4 deletions src/include/stir/VectorWithOffset.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,30 @@ class VectorWithOffset
inline VectorWithOffset(const int min_index, const int max_index);

//! Construct a VectorWithOffset of given length pointing to existing data
inline explicit
inline
VectorWithOffset(const int hsz,
T * const data_ptr);

T * const data_ptr,
T * const end_of_data_ptr);

//! Construct a VectorWithOffset of given length pointing to existing data
inline
VectorWithOffset(const int hsz,
T * const data_ptr)
: VectorWithOffset(hsz, data_ptr, data_ptr + hsz)
{}

//! Construct a VectorWithOffset with offset \c min_index point to existing data
inline
VectorWithOffset(const int min_index, const int max_index,
T * const data_ptr,
T * const end_of_data_ptr);

//! Construct a VectorWithOffset with offset \c min_index point to existing data
inline
VectorWithOffset(const int min_index, const int max_index,
T * const data_ptr);
T * const data_ptr)
: VectorWithOffset(min_index, max_index, data_ptr, data_ptr + (max_index - min_index + 1))
{}

//! copy constructor
inline VectorWithOffset(const VectorWithOffset &il) ;
Expand Down
21 changes: 6 additions & 15 deletions src/include/stir/VectorWithOffset.inl
Original file line number Diff line number Diff line change
Expand Up @@ -293,28 +293,30 @@ VectorWithOffset<T>::VectorWithOffset(const int min_index, const int max_index)

template <class T>
VectorWithOffset<T>::
VectorWithOffset(const int sz, T * const data_ptr)
VectorWithOffset(const int sz,
T * const data_ptr, T * const end_of_data_ptr)
: length(static_cast<unsigned>(sz)),
start(0),
pointer_access(false),
_owns_memory_for_data(false)
{
this->begin_allocated_memory = data_ptr;
this->end_allocated_memory = data_ptr + sz;
this->end_allocated_memory = end_of_data_ptr;
this->num = this->begin_allocated_memory - this->start;
this->check_state();
}

template <class T>
VectorWithOffset<T>::
VectorWithOffset(const int min_index, const int max_index, T * const data_ptr)
VectorWithOffset(const int min_index, const int max_index,
T * const data_ptr, T * const end_of_data_ptr)
: length(static_cast<unsigned>(max_index - min_index) + 1),
start(min_index),
pointer_access(false),
_owns_memory_for_data(false)
{
this->begin_allocated_memory = data_ptr;
this->end_allocated_memory = data_ptr + (max_index - min_index + 1);
this->end_allocated_memory = end_of_data_ptr;
this->num = this->begin_allocated_memory - this->start;
this->check_state();
}
Expand All @@ -335,17 +337,6 @@ VectorWithOffset<T>::~VectorWithOffset()
_destruct_and_deallocate();
}

#if 0
template <class T>
VectorWithOffset<T>&
VectorWithOffset<T>::
operator=(VectorWithOffset<T> other)
{
swap(*this, other);
return *this;
}
#endif

template <class T>
void
VectorWithOffset<T>::set_offset(const int min_index)
Expand Down

0 comments on commit 9d61813

Please sign in to comment.