public static Tensor[] allStatesCombinations(Tensor st) {
Indices indices = st.getIndices().getFree();
int[] indicesArray = indices.getAllIndices().copy();
//lowering all indices
IntArrayList metricIndices = new IntArrayList(),
nonMetricIndices = new IntArrayList();
for (int i = 0; i < indices.size(); ++i) {
if (CC.isMetric(getType(indices.get(i))))
metricIndices.add(getNameWithType(indices.get(i)));
else
nonMetricIndices.add(indices.get(i));
}
final int[] metricInds = metricIndices.toArray();
ArrayList<Tensor> samples = new ArrayList<>(ArithmeticUtils.pow(2, metricInds.length));
IntCombinationsGenerator gen;
int[] temp;
ArrayList<Tensor> combinationArray;
for (int i = 0; i <= metricInds.length; ++i) {
gen = new IntCombinationsGenerator(metricInds.length, i);
combinationArray = new ArrayList<>();
combinations:
for (int[] combination : gen) {
temp = new int[metricInds.length];
Arrays.fill(temp, 0xFFFFFFFF);
for (int j = combination.length - 1; j >= 0; --j)
temp[combination[j]] = createIndex(j, getType(metricInds[combination[j]]), true);//raise index
int counter = combination.length;
for (int j = 0; j < metricInds.length; ++j)
if (temp[j] == 0xFFFFFFFF)
temp[j] = createIndex(counter++, getType(metricInds[j]), false);//lower index
IntArrayList _result = nonMetricIndices.clone();
_result.addAll(temp);
Tensor renamed = ApplyIndexMapping.applyIndexMapping(st, new Mapping(indicesArray, _result.toArray()));
//todo bottleneck
for (Tensor existing : combinationArray)
if (TensorUtils.compare1(existing, renamed) != null)
continue combinations;
combinationArray.add(renamed);