add EqualSpaced / setEqualSpaced
Reference issue
What does this implement/fix?
This MR introduces a new function: setEqualSpaced
. It is analogous to setLinSpaced
when size-1
is an exact multiple of high-low
. It is vectorized for all types (with add and multiply), and somewhat more intuitive. The current setLinSpaced
implementation is not vectorized for integer types, and has somewhat awkward floating point logic.
Index size = 10;
int low = 0;
int step = 1;
std::cout << VectorXi::EqualSpaced(size, low, step).transpose() << "\n"; // {0,1,2,3,4,5,6,7,8,9}
VectorXi test(size);
// basically performs this simple loop
for(Index i = 0; i < size; i++)
test(i) = low + i * step;
Additional information
Edited by Charles Schlosser