#include "tensorstore/index_space/index_transform.h"
template <DimensionIndex Rank, ContainerKind CKind>
Result<IndexTransform<Rank, Rank>> tensorstore::InverseTransform(
    
const IndexTransform<Rank, Rank, CKind>transform);

Returns the inverse transform if one exists.

A transform is invertible if, and only if, the following criteria are met:

  1. All output index maps are either:

    1. OutputIndexMethod::constant, or

    2. OutputIndexMethod::single_input_dimension, with a stride of 1 or -1 and a unique input dimension not referenced by any other output index map.

  2. Every input dimension not referenced by a OutputIndexMethod::single_input_dimension output index map must be a “singleton dimension” with explicit lower/upper bounds and an extent of 1.

Note that OutputIndexMethod::constant output index maps correspond to singleton input dimensions in the inverse transform, and vice versa. The labels of singleton input dimensions are not preserved.

For example:

Given a transform with domain:

"x": [1*, 5)
"":  [3,  4)
"y": [2,  8*)

and output index maps:

output[0] = 5 + -1 * input[2]
output[1] = 3 + 1 * input[0],
output[2] = 7

the inverse transform has a domain of:

"y": [-2*, 4)
"x": [ 4*, 8)
"":  [ 7,  8)

and output index maps:

output[0] = -3 + input[1]
output[1] = 3
output[2] = 5 + -1 * input[0]
Parameters:
const IndexTransform<Rank, Rank, CKind> &transform

The transform to invert. May be null, in which case a null transform is returned.

Returns:

The inverse transform if transform is invertible.

Error absl::StatusCode::kInvalidArgument:

if transform is not invertible.