#include "tensorstore/index_space/dim_expression.h"
auto tensorstore::DimExpression<Op...>::Diagonal() const;

Extracts the diagonal of the selected dimensions.

The selected dimensions are removed from the new index space, and a new dimension corresponding to the diagonal is added as the first dimension, with an input domain equal to the intersection of the input domains of the selected dimensions. The new dimension selection is equal to {0}, corresponding to the newly added diagonal dimension.

The lower and upper bounds of the new diagonal dimension are implicit if, and only if, the lower or upper bounds, respectively, of every selected dimension are implicit.

For example: Dims(0, 2).Diagonal() has the following effects:

Before

After

Dimension selection

{0, 2}

{0}

Input domain

[1, 5], [2, 5], [3, 7]

[3, 5], [2, 5]

Labels

{"x", "y", "z"}

{"", "y"}

Equivalent input indices

{4, 3, 4}

{4, 3}

Equivalent input indices

{d, y, d}

{d, y}

where d is any index in [3, 5] and y is any index in [2, 5]. Note that the domain of the new dimension corresponding to the diagonal is the intersection of the domains of the "x" and "z" dimensions.

remark Diagonal() with zero selected dimensions adds a new dummy

dimension as the first dimension.

remark Diagonal() with a single selected dimension is equivalent to

MoveToFront().Label("").