Skip to content

Commit

Permalink
adopted reviewer suggestion on bool arg for grow and resize
Browse files Browse the repository at this point in the history
  • Loading branch information
evgueni-ovtchinnikov committed Jan 7, 2025
1 parent 3ff116d commit b05ba0c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/buildblock/ProjDataInMemory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ ProjDataInMemory::ProjDataInMemory(shared_ptr<const ExamInfo> const& exam_info_s
void
ProjDataInMemory::create_buffer(const bool initialise_with_0)
{
this->buffer.set_initialise_with_zeros(initialise_with_0);
this->buffer.grow(0, this->size_all() - 1);
// this->buffer.set_initialise_with_zeros(initialise_with_0);
this->buffer.grow(0, this->size_all() - 1, initialise_with_0);
}

///////////////// /set functions
Expand Down
4 changes: 2 additions & 2 deletions src/include/stir/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,13 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
inline virtual void grow(const IndexRange<1>& range);

// Array::grow initialises new elements to 0
inline void grow(const int min_index, const int max_index) override;
inline virtual void grow(const int min_index, const int max_index, bool initialise_with_0 = true);

//! Array::resize initialises new elements to 0
inline virtual void resize(const IndexRange<1>& range);

// Array::resize initialises new elements to 0
inline void resize(const int min_index, const int max_index) override;
inline virtual void resize(const int min_index, const int max_index, bool initialise_with_0 = true);

//! \name access to the data via a pointer
//@{
Expand Down
11 changes: 6 additions & 5 deletions src/include/stir/Array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,16 @@ Array<1, elemT>::init(const IndexRange<1>& range, elemT* const data_ptr, bool co

template <class elemT>
void
Array<1, elemT>::resize(const int min_index, const int max_index)
Array<1, elemT>::resize(const int min_index, const int max_index, bool initialise_with_0)
{
this->check_state();
const int oldstart = this->get_min_index();
const size_type oldlength = this->size();

base_type::resize(min_index, max_index);
base_type::resize(min_index, max_index, initialise_with_0);

if (!get_initialise_with_zeros())
// if (!get_initialise_with_zeros())
if (!initialise_with_0)
{
this->check_state();
return;
Expand Down Expand Up @@ -614,9 +615,9 @@ Array<1, elemT>::resize(const IndexRange<1>& range)

template <class elemT>
void
Array<1, elemT>::grow(const int min_index, const int max_index)
Array<1, elemT>::grow(const int min_index, const int max_index, bool initialise_with_0)
{
resize(min_index, max_index);
resize(min_index, max_index, initialise_with_0);
}

template <class elemT>
Expand Down
4 changes: 2 additions & 2 deletions src/include/stir/VectorWithOffset.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class VectorWithOffset
resize() in a derived class, it is probably safest to overload
grow() as well.
*/
inline virtual void grow(const int min_index, const int max_index);
inline virtual void grow(const int min_index, const int max_index, bool initialise_with_0 = true);

//! grow the range of the vector from 0 to new_size-1, new elements are set to \c T()
inline void grow(const unsigned int new_size);
Expand All @@ -207,7 +207,7 @@ class VectorWithOffset
\todo in principle reallocation could be avoided when the new range would fit in the
old one by shifting.
*/
inline virtual void resize(const int min_index, const int max_index);
inline virtual void resize(const int min_index, const int max_index, bool initialise_with_0 = true);

//! change the range of the vector from 0 to new_size-1, new elements are set to \c T()
inline void resize(const unsigned int new_size);
Expand Down
6 changes: 3 additions & 3 deletions src/include/stir/VectorWithOffset.inl
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ VectorWithOffset<T>::reserve(const unsigned int new_size)
// the new members will be initialised with the default constructor for T
template <class T>
void
VectorWithOffset<T>::resize(const int min_index, const int max_index)
VectorWithOffset<T>::resize(const int min_index, const int max_index, bool initialise_with_0)
{
this->check_state();
if (min_index > max_index)
Expand Down Expand Up @@ -482,11 +482,11 @@ VectorWithOffset<T>::resize(const unsigned new_size)
// the new members will be initialised with the default constructor for T
template <class T>
void
VectorWithOffset<T>::grow(const int min_index, const int max_index)
VectorWithOffset<T>::grow(const int min_index, const int max_index, bool initialise_with_0)
{
// allow grow arbitrary when it's zero length
assert(length == 0 || (min_index <= this->get_min_index() && max_index >= this->get_max_index()));
this->resize(min_index, max_index);
this->resize(min_index, max_index, initialise_with_0);
}

template <class T>
Expand Down

0 comments on commit b05ba0c

Please sign in to comment.