//building index generator
IntArrayList usedIndices = new IntArrayList(TensorUtils.getAllIndicesNames(split.factoredOut));
usedIndices.addAll(factorsIndicesNames);
usedIndices.addAll(termIndicesNames);
IndexGenerator ig = new IndexGenerator(usedIndices.toArray());
List<Tensor> mkCollectedList = new ArrayList<>();
for (Map.Entry<Integer, IndexMappingBufferRecord> entry : concurentBuffer.getMap().entrySet()) {
int indexCollected, indexToCollect, rawState = ((entry.getValue().getStates() & 1) ^ 1) << 31;
boolean diffStatesInit = entry.getValue().diffStatesInitialized();
indexCollected = rawState | entry.getValue().getIndexName();
indexToCollect = (diffStatesInit ? 0x80000000 : 0) ^ (rawState | entry.getKey());
SimpleTensor mkCollected;
SimpleTensor mkToCollect;
if (indexToCollect == indexCollected)
continue;
else if (uncontractedIndicesToCollect.contains(getNameWithType(indexToCollect))
&& uncontractedIndicesCollected.contains(getNameWithType(indexCollected)))
mappingToCollect.add(inverseIndexState(indexToCollect),
inverseIndexState(indexCollected));
else if (uncontractedIndicesToCollect.contains(getNameWithType(indexToCollect))) {
mkCollected = CC.createMetricOrKronecker(inverseIndexState(indexToCollect), indexCollected);
factorsIndicesNames.add(getNameWithType(indexCollected));
factorsIndicesNames.add(getNameWithType(indexToCollect));
termIndicesNames.replaceFirst(getNameWithType(indexCollected), getNameWithType(indexToCollect));
mappingCollectedTensor.add(indexCollected, indexToCollect);
mkCollectedList.add(mkCollected);
} else if (uncontractedIndicesCollected.contains(getNameWithType(indexCollected))) {
mkToCollect = CC.createMetricOrKronecker(indexToCollect, inverseIndexState(indexCollected));
split.factoredOut.add(mkToCollect);
} else {
int newIndex = ig.generate(getType(indexToCollect));
factorsIndicesNames.add(getNameWithType(indexCollected));
factorsIndicesNames.add(newIndex);
termIndicesNames.replaceFirst(getNameWithType(indexCollected), newIndex);
newIndex = getRawStateInt(indexCollected) | newIndex;