continue; if (Tensors.isKroneckerOrMetric(st)) { usedTypes.add(getTypeEnum(st.getIndices().get(0))); continue; int[] free = new int[si.size()]; for (int i = si.size() - 1; i >= 0; --i) { usedTypes.add(getTypeEnum(si.get(i))); free[i] = createIndex(i, getType(si.get(i)), getState(si.get(i))); byte btype = type.getType(); samples.add(Tensors.createKronecker(setType(btype, 0), 0x80000000 | setType(btype, 1))); if (CC.isMetric(btype)) { samples.add(Tensors.createMetric(setType(btype, 0), setType(btype, 1))); samples.add(Tensors.createMetric(0x80000000 | setType(btype, 0), 0x80000000 | setType(btype, 1)));
/** * Creates tester to test identity mapping {@code from} -> {@code from} * * @param from array of from indices * @param sign sign */ public IndexMappingBufferTester(int[] from, boolean sign) { from = IndicesUtils.getIndicesNames(from); Arrays.sort(from); this.from = this.to = from; this.signum = sign; innerBuffer = new IndexMappingBufferImpl(); }
/** * Returns an array of indices names (with types) * * @param indices * @return array of indices names (with types) */ public static int[] getIndicesNames(int[] indices) { int a[] = new int[indices.length]; for (int i = a.length - 1; i >= 0; --i) a[i] = getNameWithType(indices[i]); return a; }
public IndexMappingBufferRecord(int from, int to) { this.toName = IndicesUtils.getNameWithType(to); states |= 1 << IndicesUtils.getStateInt(to); states |= (IndicesUtils.getStateInt(from) ^ IndicesUtils.getStateInt(to)) << 2; }
@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]; } }
protected static SimpleTensor setMatrixIndices(SimpleTensor gamma, int matrixUpper, int matrixLower) { int[] indices = gamma.getIndices().getAllIndices().copy(); for (int i = indices.length - 1; i >= 0; --i) if (!CC.isMetric(getType(indices[i]))) { indices[i] = getState(indices[i]) ? createIndex(matrixUpper, getType(indices[i]), getState(indices[i])) : createIndex(matrixLower, getType(indices[i]), getState(indices[i])); } return simpleTensor(gamma.getName(), IndicesFactory.createSimple(null, indices)); }
TIntHashSet freeIndices = new TIntHashSet(IndicesUtils.getIndicesNames(tensor.getIndices().getFree())); TIntHashSet dummies = new TIntHashSet(IndicesUtils.getIntersections( factorIndices.getUpper().toArray(), factorIndices.getLower().toArray())); SimpleIndices currentFactorIndices; 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); kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
public static Tensor applyIndexMappingAndRenameAllDummies(Tensor tensor, Mapping mapping, int[] allowedDummies) { if (TensorUtils.isZero(tensor)) return tensor; int[] freeIndicesNames = IndicesUtils.getIndicesNames(tensor.getIndices().getFree()); Arrays.sort(freeIndicesNames); if (!mapping.getFromNames().equalsToArray(freeIndicesNames)) throw new IllegalArgumentException("From indices names does not match free indices names of tensor. Tensor: " + tensor + " mapping: " + mapping); final int[] dummies = TensorUtils.getAllDummyIndicesT(tensor).toArray(); int[] from = new int[mapping.size() + dummies.length]; int[] to = new int[mapping.size() + dummies.length]; ArraysUtils.arraycopy(mapping.getFromNames(), 0, from, 0, mapping.size()); ArraysUtils.arraycopy(mapping.getToData(), 0, to, 0, mapping.size()); System.arraycopy(dummies, 0, from, mapping.size(), dummies.length); IndexGeneratorFromData generator = new IndexGeneratorFromData(allowedDummies); for (int i = mapping.size() + dummies.length - 1, mappingSize = mapping.size(); i >= mappingSize; --i) to[i] = generator.generate(IndicesUtils.getType(from[i])); ArraysUtils.quickSort(from, to); tensor = applyIndexMapping(tensor, new IndexMapper(from, to)); if (mapping.getSign()) tensor = Tensors.negate(tensor); return tensor; }
private Expression[] createOrtIdentities(SimpleTensor bar, SimpleTensor spinor) { if (bar == null || spinor == null) return null; int dummy = setState(false, bar.getIndices().get(matrixType, 0)); Tensor lhs0 = multiply(setMatrixIndices0(bar, dummy), setMatrixIndices0(spinor, inverseIndexState(dummy))); Tensor lhs1 = multiply( setMatrixIndices0(bar, dummy), simpleTensor(gammaName, createSimple(null, inverseIndexState(dummy), dummy + 1, setType(metricType, 0))), setIndices(momentum, createSimple(null, setState(true, setType(metricType, 0)))), setMatrixIndices0(spinor, inverseIndexState(dummy + 1))); return new Expression[]{expression(lhs0, Complex.ZERO), expression(lhs1, Complex.ZERO)}; }
private static void checkIndices(SimpleIndices upper, SimpleIndices lower) { if (upper.size() != lower.size()) throw new IllegalArgumentException("Upper indices size not equal to lower indices size."); int size = upper.size(); for (int i = 0; i < size; ++i) { if (!IndicesUtils.getState(upper.get(i)) || IndicesUtils.getState(lower.get(i))) throw new IllegalArgumentException(); if (IndicesUtils.getType(upper.get(i)) != IndicesUtils.getType(lower.get(i))) throw new IllegalArgumentException(); if (i != 0) if (IndicesUtils.getType(upper.get(i - 1)) != IndicesUtils.getType(upper.get(i))) throw new IllegalArgumentException("Many types."); } }
if (CC.isMetric(getType(indices.get(i)))) metricIndices.add(getNameWithType(indices.get(i))); else nonMetricIndices.add(indices.get(i)); 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);
/** * Creates with generator with specified engaged data. * * @param indices forbidden indices */ public IndexGeneratorImpl(final int[] indices) { if (indices.length == 0) return; for (int i = 0; i < indices.length; ++i) indices[i] = getNameWithType(indices[i]); Arrays.sort(indices); byte type = getType(indices[0]); indices[0] = getNameWithoutType(indices[0]); int prevIndex = 0; for (int i = 1; i < indices.length; ++i) { if (getType(indices[i]) != type) { generators.put(type, new IntGenerator(Arrays.copyOfRange(indices, prevIndex, i))); prevIndex = i; type = getType(indices[i]); } indices[i] = getNameWithoutType(indices[i]); } generators.put(type, new IntGenerator(Arrays.copyOfRange(indices, prevIndex, indices.length))); }
int i, j, k; for (i = 0; i < operatorOrder; ++i) covariantIndices[i] = IndicesUtils.createIndex(i, IndexType.LatinLower, true); upper[i - operatorOrder] = IndicesUtils.createIndex(i, IndexType.LatinLower, true); lower[i - operatorOrder] = IndicesUtils.createIndex(i + matrixIndicesCount / 2, IndexType.LatinLower, false); for (i = 0; i < actualHatQuantities; ++i) { hatQuantities[i] = new Expression[operatorOrder + 1 - i]; covariantIndicesString = IndicesUtils.toString(Arrays.copyOfRange(covariantIndices, 0, covariantIndices.length - i), OutputFormat.Redberry); for (j = 0; j < operatorOrder + 1 - i; ++j) { sb = new StringBuilder(); sb.append(getStringHatQuantitieName(i)). append(IndicesUtils.toString(Arrays.copyOfRange(covariantIndices, j, covariantIndices.length - i), OutputFormat.Redberry)). append("=iK*"). append(getStringInputName(1 + i)). append(covariantIndicesString); for (k = 0; k < j; ++k) sb.append("*n").append(IndicesUtils.toString(IndicesUtils.inverseIndexState(covariantIndices[k]), OutputFormat.Redberry)); covariantIndicesString = IndicesUtils.toString(covariantIndices, OutputFormat.Redberry); String matricIndices = IndicesUtils.toString(ArraysUtils.addAll(upper, lower), OutputFormat.Redberry); for (i = 0; i < operatorOrder + 1; ++i) { sb = new StringBuilder(); sb.append("Kn").append(IndicesUtils.toString(Arrays.copyOfRange(covariantIndices, i, covariantIndices.length), OutputFormat.Redberry)). append(matricIndices). append("=K"). append(matricIndices);
/** * Returns index type enum value. * * @param index index * @return index type enum value */ public static IndexType getTypeEnum(int index) { return IndexType.getType(getType(index)); }
@Override public boolean tryMap(int from, int to) { int fromState = IndicesUtils.getStateInt(from); if (fromState != IndicesUtils.getStateInt(to) && !CC.isMetric(IndicesUtils.getType(from))) return false; int fromName = IndicesUtils.getNameWithType(from); IndexMappingBufferRecord record = map.get(fromName); if (record == null) { record = new IndexMappingBufferRecord(from, to); map.put(fromName, record); return true; } return record.tryMap(from, to); }
IndexGeneratorImpl indexGenerator = new IndexGeneratorImpl(varIndices); 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);
protected Tensor[] createLine(final int length) { Tensor[] gammas = new Tensor[length]; int matrixIndex, u = matrixIndex = setType(matrixType, 0); for (int i = 0; i < length; ++i) gammas[i] = Tensors.simpleTensor(gammaName, createSimple(null, u | 0x80000000, u = ++matrixIndex, setType(metricType, i))); return gammas; }
for (int mapFrom = 0; mapFrom < size; ++mapFrom) { int fromIndex = fromIndices.get(mapFrom); IndexMappingBufferRecord bRec = currentBuffer.getMap().get(getNameWithType(fromIndex)); if (getRawStateInt(fromIndex) == bRec.getFromRawState()) return currentBuffer = null; int toIndex = inverseIndexState(setRawState(bRec.getToRawState(), bRec.getIndexName())); for (int mapTo = 0; mapTo < size; ++mapTo) { if (toIndices.get(mapTo) == toIndex) {
/** * 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); }
indicesSpace[b][i] = indexGenerator.generate(b); for (i = 0; i < diff; ++i) indicesSpace[b][i + diff] = IndicesUtils.inverseIndexState(indicesSpace[b][i]); System.arraycopy(freeIndices[b], 0, indicesSpace[b], diff * 2, freeIndices[b].length); shuffle(indicesSpace[b]); for (int[] sp : indicesSpace) { forbidden.ensureCapacity(sp.length); forbidden.addAll(IndicesUtils.getIndicesNames(sp)); else for (i = 0; i < typeData.length; ++i) factorIndices[position++] = IndicesUtils.setState(typeData.states.get(i), indicesSpace[b][--totalIndicesCounts[b]]);