tensorstore.IndexTransform.__getitem__(self, domain: IndexDomain) IndexTransform

Slices this index transform by another domain.

The result is determined by matching dimensions of domain to dimensions of self.domain either by label or by index, according to one of the following three cases:

domain is entirely unlabeled

Result is self[ts.d[:][domain.inclusive_min:domain.exclusive_max]. It is an error if self.input_rank != domain.rank.

self.domain is entirely unlabeled

Result is self[ts.d[:][domain.inclusive_min:domain.exclusive_max].labels[domain.labels]. It is an error if self.input_rank != domain.rank.

Both self.domain and domain have at least one labeled dimension.

Result is self[ts.d[dims][domain.inclusive_min:domain.exclusive_max], where the sequence of domain.rank dimension identifiers dims is determined as follows:

  1. If domain.labels[i] is specified (i.e. non-empty), dims[i] = self.input_labels.index(domain.labels[i]). It is an error if no such dimension exists.

  2. Otherwise, i is the jth unlabeled dimension of domain (left to right), and dims[i] = k, where k is the jth unlabeled dimension of self (left to right). It is an error if no such dimension exists.

If any dimensions of domain are unlabeled, then it is an error if self.input_rank != domain.rank. This condition is not strictly necessary but serves to avoid a discrepancy in behavior with normal domain alignment.

Example with all unlabeled dimensions

>>> a = ts.IndexTransform(input_inclusive_min=[0, 1],
...                       input_exclusive_max=[5, 7])
>>> b = ts.IndexDomain(inclusive_min=[2, 3], exclusive_max=[4, 6])
>>> transform[domain]
Rank 3 -> 3 index space transform:
  Input domain:
    0: [1, 4)
    1: [2, 5)
    2: [3, 6)
  Output index maps:
    out[0] = 0 + 1 * in[0]
    out[1] = 0 + 1 * in[1]
    out[2] = 0 + 1 * in[2]

Example with fully labeled dimensions

>>> a = ts.IndexTransform(input_inclusive_min=[0, 1, 2],
...                       input_exclusive_max=[5, 7, 8],
...                       input_labels=["x", "y", "z"])
>>> b = ts.IndexDomain(inclusive_min=[2, 3],
...                    exclusive_max=[6, 4],
...                    labels=["y", "x"])
>>> transform[domain]
Rank 3 -> 3 index space transform:
  Input domain:
    0: [1, 4)
    1: [2, 5)
    2: [3, 6)
  Output index maps:
    out[0] = 0 + 1 * in[0]
    out[1] = 0 + 1 * in[1]
    out[2] = 0 + 1 * in[2]

Example with mixed labeled and unlabeled dimensions

>>> a = ts.IndexTransform(input_inclusive_min=[0, 0, 0, 0],
...                       input_exclusive_max=[10, 10, 10, 10],
...                       input_labels=["x", "", "", "y"])
>>> b = ts.IndexDomain(inclusive_min=[1, 2, 3, 4],
...                    exclusive_max=[6, 7, 8, 9],
...                    labels=["y", "", "x", ""])
>>> a[b]
Rank 4 -> 4 index space transform:
  Input domain:
    0: [3, 8) "x"
    1: [2, 7)
    2: [4, 9)
    3: [1, 6) "y"
  Output index maps:
    out[0] = 0 + 1 * in[0]
    out[1] = 0 + 1 * in[1]
    out[2] = 0 + 1 * in[2]
    out[3] = 0 + 1 * in[3]

Note

On domain, implicit bounds indicators have no effect.