Skip to content

Change af::seq representation to allow empty sequence #3278

@StrongerXi

Description

@StrongerXi

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

  1. It makes af::seq's semantics more complete, i.e., makes af::seq(0) correct.
  2. It may help clients of ArrayFire, e.g., Flashlight. cc @jacobkahn

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions