Browse Source

debug sparkstack

master
gjj 7 months ago
parent
commit
6c06abe48e
  1. 21
      algoim/sparkstack.hpp

21
algoim/sparkstack.hpp

@ -22,10 +22,11 @@ namespace algoim
template <typename... R>
static size_t alloc(T** ptr, size_t len, R... rest)
{
if (pos() + len > capacity)
{
std::cerr << "SparkStack<T = " << typeid(T).name() << ">: capacity=" << capacity << " and pos=" << pos() << " insufficient for request len=" << len << '\n';
std::cerr << " consider increasing const 'capacity', defined on line " << capacity_line << " in file " << __FILE__ << '\n';
if (pos() + len > capacity) {
std::cerr << "SparkStack<T = " << typeid(T).name() << ">: capacity=" << capacity << " and pos=" << pos()
<< " insufficient for request len=" << len << '\n';
std::cerr << " consider increasing const 'capacity', defined on line " << capacity_line << " in file "
<< __FILE__ << '\n';
throw std::bad_alloc();
}
*ptr = base() + pos();
@ -56,7 +57,6 @@ namespace algoim
SparkStack& operator=(SparkStack&&) = delete;
public:
// With parameters x0, n0, x1, n1, x2, n2, ..., allocate n0 elements and assign to x0, etc.
template <typename... R>
explicit SparkStack(T** ptr, size_t len, R&&... rest)
@ -71,8 +71,7 @@ namespace algoim
{
T* start = base() + pos();
len_ = alloc(ptr, len, rest...);
for (int i = 0; i < len_; ++i)
*(start + i) = value;
for (int i = 0; i < len_; ++i) *(start + i) = value;
}
// For each i, allocate ext(i) elements and assign to ptr(i)
@ -80,8 +79,7 @@ namespace algoim
explicit SparkStack(uvector<T*, N>& ptr, const uvector<int, N>& ext)
{
len_ = 0;
for (int i = 0; i < N; ++i)
len_ += alloc(&ptr(i), ext(i));
for (int i = 0; i < N; ++i) len_ += alloc(&ptr(i), ext(i));
}
// Allocate enough elements for one or more xarray's having pre-set extent
@ -92,10 +90,7 @@ namespace algoim
}
// Release memory when the SparkStack object goes out of scope
~SparkStack()
{
pos() -= len_;
}
~SparkStack() { pos() -= len_; }
};
#define algoim_CONCAT2(x, y) x##y

Loading…
Cancel
Save