//Used to build chain of permutators
PermutationInfo previousInfo = null;
//Here added bijections will be collected
IntArrayList addedBijections = new IntArrayList();
//Iterating through seeds
for (int i = 0; i < seeds.length; ++i) {
//Index of seed in from array
int seedFromIndex = seeds[i];
//Seed tensor (used only to get indices -> index Ids)
Tensor seedFrom = fromData[seedFromIndex];
//Seed index in target array (bijection for this tensor should already be provided by upper level port)
int seedTargetIndex = bijection[seedFromIndex];
//Diff ids of indices. Cloned because it will be sorted.
short[] diffIds = seedFrom.getIndices().getDiffIds().clone(); // (!!!)
//Sorting with permutation retrieval.
//This step needed because we use the fastest (we think so)
//method of collecting indices with the same index id [Permutable indices].
int[] diffIdsPermutation = ArraysUtils.quickSortP(diffIds);
//Creating array for permutation infos for current bijection.
// permutationInfos[i] = new ArrayList<>();
//Iterating through stretches of indices
for (Stretch stretch : new StretchIteratorS(diffIds))
if (stretch.length == 1) { //Indices with unique index id (stretch.length == 1) [Non permutable indices].
//Corresponding contraction in from tensor
long fromIndexContraction = fromContractions[seedFromIndex][diffIdsPermutation[stretch.from]];
//Corresponding contraction in target tensor
long targetIndexContraction = targetContractions[seedTargetIndex][diffIdsPermutation[stretch.from]];
final int fromTensorIndex = getToTensorIndex(fromIndexContraction); //Index of contracting tensor in from array
if (fromTensorIndex == -1) //Not contracted index of from
continue;
if (getToIndexId(fromIndexContraction) != getToIndexId(targetIndexContraction)) { //Contracts with different index id
closed = true;
return;
}
final int targetTensorIndex = getToTensorIndex(targetIndexContraction); //Index of contracting tensor in target array
if (targetTensorIndex == -1) {//Not contracted index of target (but from is contracted with some tensor),
// so this bijection is impossible
closed = true;
return;
}
//Checking weak match between corresponding contracting tensors
if (!weakMatch(fromData[fromTensorIndex], targetData[targetTensorIndex])) {
//Early termination
closed = true;
return;
}
if (bijection[fromTensorIndex] == -1) { //This bijection is free
//Adding new bijection
if (alreadyContains(bijection, targetTensorIndex)) {
closed = true;
return;
}
bijection[fromTensorIndex] = targetTensorIndex;
addedBijections.add(fromTensorIndex);
} else if (bijection[fromTensorIndex] != targetTensorIndex) { //Testing weather new bijection is consistent with already existing
closed = true;
return;
}
} else { //There are several indices with the same index id.