indicesSpace[b][i + diff] = IndicesUtils.inverseIndexState(indicesSpace[b][i]);
System.arraycopy(freeIndices[b], 0, indicesSpace[b], diff * 2, freeIndices[b].length);
shuffle(indicesSpace[b]);
}
TIntHashSet forbidden = new TIntHashSet();
for (int[] sp : indicesSpace) {
forbidden.ensureCapacity(sp.length);
forbidden.addAll(IndicesUtils.getIndicesNames(sp));
}
//Creating resulting product
ProductBuilder pb = new ProductBuilder(10, avrProductSize);
for (Tensor descriptor : descriptors) {
StructureOfIndices its = IndicesFactory.createSimple(null, descriptor.getIndices().getFree()).getStructureOfIndices();
int[] factorIndices = new int[its.size()];
int position = 0;
for (byte b : TYPES) {
StructureOfIndices.TypeData typeData = its.getTypeData(b);
if (typeData == null)
continue;
for (i = 0; i < typeData.length; ++i)
factorIndices[position++] = indicesSpace[b][--totalIndicesCounts[b]];
}
descriptor = ApplyIndexMapping.applyIndexMapping(descriptor,
new Mapping(descriptor.getIndices().getFree().getAllIndices().copy(), factorIndices), forbidden.toArray());
descriptor = ApplyIndexMapping.renameDummy(descriptor, forbidden.toArray());
forbidden.addAll(TensorUtils.getAllIndicesNamesT(descriptor));
pb.put(descriptor);
}