Skip to content

Instantly share code, notes, and snippets.

@JohanMabille
Last active January 6, 2020 19:28
Show Gist options
  • Save JohanMabille/86149df73602d64642cf57db730e9301 to your computer and use it in GitHub Desktop.
Save JohanMabille/86149df73602d64642cf57db730e9301 to your computer and use it in GitHub Desktop.
xtensor_8_N_14.hpp
template <layout_type L>
struct stepper_tools
{
template <class S, class IT, class ST>
static void increment_stepper(S& stepper,
IT& index,
const ST& shape);
};
template <>
template <class S, class IT, class ST>
void stepper_tools<layout_type::row_major>::increment_stepper(S& stepper,
IT& index,
const ST& shape)
{
using size_type = typename S::size_type;
size_type i = index.size();
while (i != 0)
{
--i;
if (index[i] != shape[i] - 1)
{
++index[i];
stepper.step(i);
return;
}
else
{
index[i] = 0;
if (i != 0)
{
stepper.reset(i);
}
}
}
if (i == 0)
{
std::copy(shape.cbegin(), shape.cend(), index.begin());
stepper.to_end(layout_type::row_major);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment