Issue
Currently af::seq(0) incorrectly produces a sequence representing "all elements along an axis", instead of an empty sequence.
Demo:
auto x = af::constant(3, 3);
std::cout << af::toString("", x(af::seq(0))) << std::endl; // prints array of 3 elements
In fact, there seems to be no way to construct an "empty sequence" in ArrayFire at the moment.
Proposal
Currently in af::seq, a step size of 0 is used to represent span. Also see the static span instance.
However, we could naturally represent a span via af::seq(0, -1, 1).
By doing that, we can now use step size of 0 to represent empty sequence (which would otherwise be difficult due to the inclusive semantics of af::seq::end. We also need to figure out semantics/constraints of start and end in that case, but it should be pretty flexible.
Benefits
- It makes
af::seq's semantics more complete, i.e., makes af::seq(0) correct.
- It may help clients of ArrayFire, e.g., Flashlight. cc @jacobkahn
Issue
Currently
af::seq(0)incorrectly produces a sequence representing "all elements along an axis", instead of an empty sequence.Demo:
In fact, there seems to be no way to construct an "empty sequence" in ArrayFire at the moment.
Proposal
Currently in
af::seq, a step size of 0 is used to represent span. Also see the static span instance.However, we could naturally represent a span via
af::seq(0, -1, 1).By doing that, we can now use step size of 0 to represent empty sequence (which would otherwise be difficult due to the inclusive semantics of
af::seq::end. We also need to figure out semantics/constraints ofstartandendin that case, but it should be pretty flexible.Benefits
af::seq's semantics more complete, i.e., makesaf::seq(0)correct.