I have a class holding an Eigen::Array of data and a method that adds new data (number of rows may vary) by appending to the array along the first axis. I solved the accumulation by creating a new Array of the right size and initializing it with the old and the new data.
typedef Eigen::Array<double, Eigen::Dynamic, 3> DataArray
class Accumulator {
void add(DataArray &new_data) {
DataArray accu(accumulated_data_.rows() + new_data.rows(), 3)
accu << accumulated_data_, new_data;
accumulated_data_ = accu;
}
DataArray accumulated_data_;
}
Is there anything wrong with doing it like this? Or is it preferred to resize the accumulated data array:
.resize()
and copy in both old and new- or
.conservative_resize()
and copy in the new data (requires block operations if new data is longer than 1 row)