tensorstore_demo.IndexDomain.__getitem__(
    
selfother: IndexDomain-> IndexDomain

Slices this domain by another domain.

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

other is entirely unlabeled

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

self is entirely unlabeled

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

Both self and other have at least one labeled dimension.

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

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

  2. Otherwise, i is the jth unlabeled dimension of other (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 other are unlabeled, then it is an error if self.rank != other.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.IndexDomain(inclusive_min=[0, 1], exclusive_max=[5, 7])
>>> b = ts.IndexDomain(inclusive_min=[2, 3], exclusive_max=[4, 6])
>>> a[b]
{ [2, 4), [3, 6) }

Example with fully labeled dimensions

>>> a = ts.IndexDomain(inclusive_min=[0, 1, 2],
...                    exclusive_max=[5, 7, 8],
...                    labels=["x", "y", "z"])
>>> b = ts.IndexDomain(inclusive_min=[2, 3],
...                    exclusive_max=[6, 4],
...                    labels=["y", "x"])
>>> a[b]
{ "x": [3, 4), "y": [2, 6), "z": [2, 8) }

Example with mixed labeled and unlabeled dimensions

>>> a = ts.IndexDomain(inclusive_min=[0, 0, 0, 0],
...                    exclusive_max=[10, 10, 10, 10],
...                    labels=["x", "", "", "y"])
>>> b = ts.IndexDomain(inclusive_min=[1, 2, 3, 4],
...                    exclusive_max=[6, 7, 8, 9],
...                    labels=["y", "", "x", ""])
>>> a[b]
{ "x": [3, 8), [2, 7), [4, 9), "y": [1, 6) }

Note

On other, implicit bounds indicators have no effect.


Last update: Nov 16, 2024