Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to speed up STIR acquisition data algebra by avoiding unnecessary 0-fill of newly created data. #1549

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/buildblock/ProjDataInMemory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,8 @@ ProjDataInMemory::ProjDataInMemory(shared_ptr<const ExamInfo> const& exam_info_s
void
ProjDataInMemory::create_buffer(const bool initialise_with_0)
{
#if 0
float *b = new float[this->size_all()];
if (initialise_with_0)
memset(b, 0, this->size_all()*sizeof(float));
return b;
#else
this->buffer = Array<1, float>(static_cast<int>(this->size_all()));
#endif
this->buffer.set_initialise_with_zeros(initialise_with_0);
this->buffer.grow(0, this->size_all() - 1);
}

///////////////// /set functions
Expand Down
11 changes: 11 additions & 0 deletions src/include/stir/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
inline const elemT& at(const BasicCoordinate<1, int>& c) const;
//@}

void set_initialise_with_zeros(bool iwz)
{
init_with_zeros_ = iwz;
}
bool get_initialise_with_zeros() const
{
return init_with_zeros_;
}

private:
// Make sure we can call init() recursively.
template <int num_dimensions2, class elemT2>
Expand All @@ -579,6 +588,8 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
\arg data_ptr should start to a contiguous block of correct size
*/
inline void init(const IndexRange<1>& range, elemT* const data_ptr, bool copy_data);

bool init_with_zeros_ = true;
};

END_NAMESPACE_STIR
Expand Down
7 changes: 7 additions & 0 deletions src/include/stir/Array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@ Array<1, elemT>::resize(const int min_index, const int max_index)
const size_type oldlength = this->size();

base_type::resize(min_index, max_index);

if (!get_initialise_with_zeros())
{
this->check_state();
return;
}

if (oldlength == 0)
{
for (int i = this->get_min_index(); i <= this->get_max_index(); i++)
Expand Down
Loading