ArraysUtils.stableSort(types, cosort);
int[] cosortInv = Combinatorics.inverse(cosort);
//Allocating resulting symmetries object
//it already contains identity symmetry
Symmetries resultingSymmetries =
SymmetriesFactory.createSymmetries(data.length);
int[] c;
int position = 0, k;
SimpleIndices sd = IndicesFactory.createSimple(null, data);
//rescaling symmetries to the actual length and positions corresponding
//to the sorted indices
for (Symmetries ss : this.symmetries) {
final List<Symmetry> basis = ss.getBasisSymmetries();
//iterating from 1 because zero'th element is always identity symmetry
for (k = 1; k < basis.size(); ++k) {
c = new int[data.length];
Symmetry s = basis.get(k);
for (j = 0; j < data.length; ++j)
if (cosort[j] < position || cosort[j] >= position + s.dimension())
c[j] = j;
else
c[j] = cosortInv[s.newIndexOf(cosort[j] - position) + position];
resultingSymmetries.addUnsafe(UnsafeCombinatorics.createUnsafe(c, s.isAntiSymmetry()));
}
//increasing position in the total symmetry array
position += ss.dimension();
}