/** * Returns mapping, formed from this mapping by multiplying by specified sign. * * @param sign false - plus, true - minus one * @return a new mapping, formed from this mapping by multiplying by specified sign */ public Mapping addSign(boolean sign) { return new Mapping(fromNames, toData, sign ^ this.sign, true); }
@Override public Mapping take() { IndexMappingBuffer temp = innerPort.take(); if (temp == null) return null; return new Mapping(temp); } }
/** * Returns the first mapping of tensor {@code from} on tensor {@code to}. * * @param from from tensor * @param to to tensor * @return mapping of indices of tensor {@code from} on tensor {@code to} */ public static Mapping getFirst(Tensor from, Tensor to) { IndexMappingBuffer buffer = createPortOfBuffers(from, to).take(); if (buffer == null) return null; return new Mapping(buffer); }
private static Tensor permute(Tensor tensor, int[] indicesArray, int[] upperPermutation, int[] lowerPermutation, List<int[]> generatedPermutations, List<Permutation> symmetries) { //creating resulting permutation upper indices are first, //because initial indices are sorted int[] permutation = new int[upperPermutation.length + lowerPermutation.length]; System.arraycopy(upperPermutation, 0, permutation, 0, upperPermutation.length); System.arraycopy(lowerPermutation, 0, permutation, upperPermutation.length, lowerPermutation.length); //TODO discover better algorithm (possible using stretches of symmetries) //checking wheather the way beetween current permutation and already //generated combinatorics exists throw any possible combination of symmetries for (int[] p : generatedPermutations) for (Permutation symmetry : symmetries) if (Arrays.equals(permutation, symmetry.permute(p))) return null; generatedPermutations.add(permutation); //processing new indices from permutation final int[] newIndices = new int[indicesArray.length]; for (int i = 0; i < indicesArray.length; ++i) newIndices[i] = indicesArray[permutation[i]]; //processing new tensor return ApplyIndexMapping.applyIndexMapping(tensor, new Mapping(indicesArray, newIndices), new int[0]); }
to[i] = IndicesUtils.getRawStateInt(fromIndex) ^ IndicesUtils.parseIndex(fromTo[1]); return new Mapping(from, to, sign);
@Override Tensor differentiateSimpleTensorWithoutCheck(SimpleTensor simpleTensor) { int[] to = simpleTensor.getIndices().getAllIndices().copy(); to = addAll(to, freeVarIndices); return applyIndexMapping(derivative, new Mapping(allFreeFrom, to), new int[0]); }
private static Tensor setIndices(Tensor t, Indices from, Indices to) { return ApplyIndexMapping.applyIndexMapping(t, new Mapping(from.getAllIndices().copy(), to.getAllIndices().copy()), new int[0]); }
private static Tensor invertIndices(Tensor t) { Indices free = t.getIndices().getFree(); Mapping mapping = new Mapping(free.toArray(), free.getInverted().toArray()); return ApplyIndexMapping.applyIndexMapping(t, mapping); }
private Tensor __newTo(DFromTo fromTo, TensorField currentField, Tensor currentNode, SubstitutionIterator iterator) { TensorField from = fromTo.from; Mapping mapping = IndexMappings.simpleTensorsPort(from, currentField).take(); if (mapping == null) return currentNode; Indices[] fromIndices = from.getArgIndices(), currentIndices = currentField.getArgIndices(); List<Tensor> argFrom = new ArrayList<>(), argTo = new ArrayList<>(); Tensor fArg; int[] cIndices, fIndices; int i; for (i = from.size() - 1; i >= 0; --i) { if (IndexMappings.positiveMappingExists(currentNode.get(i), from.get(i))) continue; fIndices = fromIndices[i].getAllIndices().copy(); cIndices = currentIndices[i].getAllIndices().copy(); assert cIndices.length == fIndices.length; fArg = ApplyIndexMapping.applyIndexMapping(from.get(i), new Mapping(fIndices, cIndices), new int[0]); argFrom.add(fArg); argTo.add(currentNode.get(i)); } Tensor newTo = fromTo.to; newTo = new SubstitutionTransformation( argFrom.toArray(new Tensor[argFrom.size()]), argTo.toArray(new Tensor[argTo.size()]), false).transform(newTo); return applyIndexMappingToTo(currentNode, newTo, mapping, iterator); }
/** * Inverts indices of tensor * * @param tensor tensor * @return tensor with inverted indices */ public static Tensor invertIndices(Tensor tensor) { Indices indices = tensor.getIndices().getFree(); if (indices.size() == 0) return tensor; return applyIndexMapping(tensor, new Mapping(indices.toArray(), indices.getInverted().toArray())); } }
private static Transformation createSubstitution(TensorField dd) { Tensor from = dd.get(0), to = dd.get(1); to = ApplyIndexMapping.applyIndexMapping(to, new Mapping(dd.getArgIndices(1).toArray(), dd.getArgIndices(0).toArray()), new int[0]); return new SubstitutionTransformation(from, to); }
private static Expression compileExpr0(Tensor lhs, Tensor rhs) { return expression(lhs, ApplyIndexMapping.applyIndexMapping(rhs, new Mapping(rhs.getIndices().getFree().toArray(), lhs.getIndices().getFree().toArray()))); } }
return applyIndexMapping(tensor, new Mapping(from, to, mapping.getSign()), forbidden);
IntArrayList _result = nonMetricIndices.clone(); _result.addAll(temp); Tensor renamed = ApplyIndexMapping.applyIndexMapping(st, new Mapping(indicesArray, _result.toArray()));
private Tensor orderArray(Gamma[] gammas) { final int numberOfGammas = gammas.length; int[] permutation = Permutations.createIdentityArray(numberOfGammas); Tensor fGamma = gammas[0].gamma, lGamma = gammas[gammas.length - 1].gamma; int[] mIndices = new int[numberOfGammas]; for (int i = 0; i < numberOfGammas; ++i) mIndices[i] = gammas[i].index; //use stable sort! //!! gammas is lost now !! ArraysUtils.insertionSort(gammas, permutation); if (Permutations.isIdentity(permutation)) return null;//signals that array is sorted! Cached cached = cache.get(new IntArray(permutation)); if (cached == null) { Tensor[] arr = createArray(permutation); Tensor ordered = eliminate(orderArray0(arr.clone())); cache.put(new IntArray(permutation), cached = new Cached(arr, ordered)); } int[] iFrom = new int[numberOfGammas + 2], iTo = new int[numberOfGammas + 2]; System.arraycopy(cached.getOriginalIndices(metricType), 0, iFrom, 0, numberOfGammas); System.arraycopy(mIndices, 0, iTo, 0, numberOfGammas); iFrom[numberOfGammas] = cached.originalArray[0].getIndices().getUpper().get(matrixType, 0); iTo[numberOfGammas] = fGamma.getIndices().getUpper().get(matrixType, 0); iFrom[numberOfGammas + 1] = cached.originalArray[numberOfGammas - 1].getIndices().getLower().get(matrixType, 0); iTo[numberOfGammas + 1] = lGamma.getIndices().getLower().get(matrixType, 0); return eliminate(ApplyIndexMapping.applyIndexMapping(cached.ordered, new Mapping(iFrom, iTo))); }
permutation = cosetRepresentatives.next(); sb.put(ApplyIndexMapping.applyIndexMappingAutomatically(t, new Mapping(indicesArray, permutation.permute(indicesArray), permutation.antisymmetry())));
private Tensor order(Tensor[] gammas) { int numberOfGammas = gammas.length; Tensor tensor = cache.get(numberOfGammas); if (tensor == null) cache.put(numberOfGammas, tensor = order0(createLine(numberOfGammas))); int[] iFrom = new int[numberOfGammas + 2], iTo = new int[numberOfGammas + 2]; for (int i = 0; i < numberOfGammas; ++i) { iFrom[i] = setType(metricType, i); iTo[i] = gammas[i].getIndices().get(metricType, 0); } iFrom[numberOfGammas] = setType(matrixType, 0) | 0x80000000; iTo[numberOfGammas] = gammas[0].getIndices().getUpper().get(matrixType, 0); iFrom[numberOfGammas + 1] = setType(matrixType, numberOfGammas); iTo[numberOfGammas + 1] = gammas[numberOfGammas - 1].getIndices().getLower().get(matrixType, 0); return eliminate(ApplyIndexMapping.applyIndexMapping(tensor, new Mapping(iFrom, iTo))); }
newIndices[k + termUp.size()] = lowerArray[l++]; temp = ApplyIndexMapping.applyIndexMapping(temp, new Mapping(oldIndices, newIndices), indices.getAllIndices().copy()); tCombination.add(temp);
Tensor move0(Tensor[] gammas, int index, boolean left) { if (gammas.length == 1) return gammas[0]; if ((index == 0 && left) || (index == gammas.length - 1 && !left)) return multiply(gammas); int numberOfGammas = gammas.length; IntArrayList iFrom = new IntArrayList(numberOfGammas + 2), iTo = new IntArrayList(numberOfGammas + 2), g5s = new IntArrayList(); for (int i = 0; i < numberOfGammas; ++i) { if (isGamma5(gammas[i])) g5s.add(i); else { iFrom.add(setType(metricType, i)); iTo.add(gammas[i].getIndices().get(metricType, 0)); } } iFrom.add(setType(matrixType, 0) | 0x80000000); iTo.add(gammas[0].getIndices().getUpper().get(matrixType, 0)); iFrom.add(setType(matrixType, numberOfGammas)); iTo.add(gammas[numberOfGammas - 1].getIndices().getLower().get(matrixType, 0)); Holder key = new Holder(index, numberOfGammas, g5s, left); Tensor tensor = cache.get(key); if (tensor == null) cache.put(key, tensor = left ? toLeft0(createLine(numberOfGammas, g5s), index) : toRight0(createLine(numberOfGammas, g5s), index)); return eliminate(ApplyIndexMapping.applyIndexMapping(tensor, new Mapping(iFrom.toArray(), iTo.toArray()))); }
new Mapping(allIndices, addAll(varIndices.getInverted().getAllIndices().copy(), allFreeArgIndices)), new int[0]);