public static boolean haveEqualStates(int index1, int index2) { return getRawStateInt(index1) == getRawStateInt(index2); }
@Override public int map(int index) { int position = Arrays.binarySearch(from, 0, size, IndicesUtils.getNameWithType(index)); if (position < 0) return index; return IndicesUtils.getRawStateInt(index) ^ to[position]; }
public static List<Permutation> getIndicesSymmetriesForIndicesWithSameStates(final int[] indices, Tensor tensor) { List<Permutation> total = findIndicesSymmetries(indices, tensor); List<Permutation> symmetries = new ArrayList<>(); int i; OUT: for (Permutation s : total) { for (i = 0; i < indices.length; ++i) if (IndicesUtils.getRawStateInt(indices[i]) != IndicesUtils.getRawStateInt(indices[s.newIndexOf(i)])) continue OUT; symmetries.add(s); } return symmetries; }
@Override public int map(int index) { int position = Arrays.binarySearch(from, IndicesUtils.getNameWithType(index)); if (position < 0) return index; return IndicesUtils.getRawStateInt(index) ^ to[position]; } }
/** * Returns metric tensor if specified indices have same states and * Kronecker tensor if specified indices have different states. * * @param index1 first index * @param index2 second index * @return metric tensor if specified indices have same states and * Kronecker tensor if specified indices have different states * @throws IllegalArgumentException if indices have different types * @throws IllegalArgumentException if indices have same states and non metric types */ public SimpleTensor createMetricOrKronecker(int index1, int index2) { if (IndicesUtils.getRawStateInt(index1) == IndicesUtils.getRawStateInt(index2)) return createMetric(index1, index2); return createKronecker(index1, index2); }
/** * Creates mapping from given {@code from} and {@code to} arrays of indices. * * @param from indices from * @param to indices to * @param sign the sign of mapping */ public Mapping(final int[] from, final int[] to, final boolean sign) { if (from.length != to.length) throw new IllegalArgumentException("From length != to length."); fromNames = new int[from.length]; toData = new int[from.length]; for (int i = 0; i < from.length; ++i) { fromNames[i] = IndicesUtils.getNameWithType(from[i]); toData[i] = IndicesUtils.getRawStateInt(from[i]) ^ to[i]; } ArraysUtils.quickSort(fromNames, toData); this.sign = sign; }
to[i] = IndicesUtils.getRawStateInt(fromIndex) ^ IndicesUtils.parseIndex(fromTo[1]);
/** * Returns Kronecker tensor with specified upper and lower indices. * * @param index1 first index * @param index2 second index * @return Kronecker tensor with specified upper and lower indices * @throws IllegalArgumentException if indices have same states * @throws IllegalArgumentException if indices have different types */ public SimpleTensor createKronecker(int index1, int index2) { byte type; if ((type = IndicesUtils.getType(index1)) != IndicesUtils.getType(index2) || IndicesUtils.getRawStateInt(index1) == IndicesUtils.getRawStateInt(index2)) throw new IllegalArgumentException("This is not kronecker indices!"); if (!isMetric(type) && IndicesUtils.getState(index2)) { int t = index1; index1 = index2; index2 = t; } SimpleIndices indices = IndicesFactory.createSimple(null, index1, index2); NameDescriptor nd = nameManager.mapNameDescriptor(nameManager.getKroneckerName(), StructureOfIndices.create(indices)); int name = nd.getId(); return Tensors.simpleTensor(name, indices); }
index = currentFactorIndices.get(j); if (freeIndices.contains(getNameWithType(index))) { newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index))); from.add(index); to.add(newIndex); kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex))); } else if (IndicesUtils.getState(index) && dummies.contains(getNameWithType(index))) { newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index))); from.add(index); to.add(newIndex);
indices[j] = setRawState(getRawStateInt(var.getIndices().get(j)), ig.generate(getType(var.getIndices().get(j)))); varIndices = UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort(null, indices);
continue; if (getRawStateInt(fromIndex) == bRec.getFromRawState()) return currentBuffer = null;
for (; i < length; ++i) { type = getType(varIndices.get(i)); state = getRawStateInt(varIndices.get(i)); allFreeVarIndices[i] = setRawState(indexGenerator.generate(type), inverseIndexState(state)); allFreeArgIndices[i] = setRawState(indexGenerator.generate(type), state);