-
#include "tensorstore/index_space/alignment.h" -
Result<IndexTransform<>> tensorstore::AlignDomainTo(
IndexDomainView<> source,
IndexDomainView<> target,
DomainAlignmentOptions options = DomainAlignmentOptions::all); Attempts to align the
sourcedomain to match thetargetdomain.This is used to align dimensions for TensorStore read/write/copy operations.
First, a subset of dimensions of
sourceis matched to a subset of dimensions oftarget, according to one of two cases:- M1. At least one of
sourceortargetis entirely unlabeled (all dimension labels are empty). In this case, the last
match_rank = std::min(source.rank(), target.rank())dimensions ofsourcematch in order to the lastmatch_rankdimensions oftarget, i.e. dimensionsource.rank() - match_rank + iofsourcematches to dimensiontarget.rank() - match_rank + ioftarget, for0 <= i < rank. This case also applies ifoptionsexcludesDomainAlignmentOptions::permute.- M2. Both
sourceandtargethave at least one labeled dimension. In this case, dimensions of
sourceandtargetwith matching labels are matched. Any remaining labeled dimensions remain unmatched. The unlabeled dimensions ofsourceare matched to the unlabeled dimensions oftargetusing the same method as in case M1 (right to left).
The matching is then validated as follows:
- V1. For each match between a dimension
iofsourceand a dimension joftarget, ifsource.shape()[i] != target.shape()[j], the match is dropped. Note that ifsource.shape()[i] != 1, this leads to an error in the following step (V2).- V2. For every unmatched dimension
iofsource, source.shape()[i]must equal1.
If matching succeeds, a new
alignmenttransform with an (input) domain equal totargetand an output rank equal tosource.rank()is computed as follows:- A1. For each dimension
joftargetwith a matching dimension iofsource, output dimensioniofalignmenthas aOutputIndexMethod::single_input_dimensionmap to input dimensionjwith a stride of1and offset ofsource.origin()[i] - target.origin()[j].- A2. For every unmatched dimension
iofsource, output dimension iofalignmentis aOutputIndexMethod::constantmap with an offset ofsource.origin()[i]. (It must be the case thatsource.shape()[i] == 1.)
The return value is
alignment.Examples (input dimensions refer to dimensions of
target, while output dimensions refer to dimensions ofsource):All unlabeled dimensions:
source:
[3, 7), [5, 6), [4, 10)target:
[2, 6), [0, 4), [6, 12)alignment: rank 3 -> 3, with:
output dimension 0 -> input dimension 0, offset 1
output dimension 1 -> constant 5
output dimension 2 -> input dimension 2, offset -2
All labeled dimensions:
source:
"x": [3, 7), "y": [5, 6), "z": [4, 10)target:
"z": [6, 12), "x": [4, 8), "y": [0, 4)alignment: rank 3 -> 3, with:
output dimension 0 -> input dimension 1, offset -1
output dimension 1 -> constant 5
output dimension 2 -> input dimension 0, offset -2
Partially labeled dimensions:
source:
"x": [3, 7), "y": [5, 6), "": [4, 10)target:
"": [0, 10) "": [6, 12), "x": [4, 8), "y": [0, 4)alignment: rank 4 -> 3, with:
output dimension 0 -> input dimension 2, offset -1
output dimension 1 -> constant 5
output dimension 2 -> input dimension 1, offset -2
Mismatched labeled dimensions:
source:
"x": [3, 7), "y": [5, 6), "z": [4, 10)target:
"z": [6, 12), "w": [4, 8), "y": [0, 4)ERROR: Unmatched source dimension
0 {"x": [3, 7)}does not have a size of 1
- Parameters:¶
- IndexDomainView<> source¶
The source domain.
- IndexDomainView<> target¶
The target domain to which
sourceshould be aligned.- DomainAlignmentOptions options = DomainAlignmentOptions::all¶
Specifies the transformations that are permitted. By default, all transformations (permutation, translation, broadcasting) are permitted.
- M1. At least one of