private static Tensor _applyIndexMapping(Tensor tensor, Mapping mapping, int[] forbidden) {
final int mappingSize = mapping.size();
int[] allForbidden = new int[mappingSize + forbidden.length];
IntArray toData = mapping.getToData(), fromNames = mapping.getFromNames();
ArraysUtils.arraycopy(toData, 0, allForbidden, 0, mappingSize);
System.arraycopy(forbidden, 0, allForbidden, mappingSize, forbidden.length);
int i;
for (i = allForbidden.length - 1; i >= 0; --i)
allForbidden[i] = IndicesUtils.getNameWithType(allForbidden[i]);
IntArrayList fromL = new IntArrayList(mappingSize), toL = new IntArrayList(mappingSize);
fromL.addAll(fromNames);
toL.addAll(toData);
Arrays.sort(allForbidden);
final int[] dummyIndices = TensorUtils.getAllDummyIndicesT(tensor).toArray();
final int[] forbiddenGeneratorIndices = new int[allForbidden.length + dummyIndices.length];
System.arraycopy(allForbidden, 0, forbiddenGeneratorIndices, 0, allForbidden.length);
System.arraycopy(dummyIndices, 0, forbiddenGeneratorIndices, allForbidden.length, dummyIndices.length);
IndexGeneratorImpl generator = new IndexGeneratorImpl(forbiddenGeneratorIndices);
for (int index : dummyIndices)
if (Arrays.binarySearch(allForbidden, index) >= 0) {
assert ArraysUtils.binarySearch(fromNames, index) < 0;
fromL.add(index);
toL.add(generator.generate(IndicesUtils.getType(index)));
}
int[] _from = fromL.toArray(), _to = toL.toArray();
ArraysUtils.quickSort(_from, _to);
return applyIndexMapping(tensor, new IndexMapper(_from, _to));
}