public IndexMappingBufferTester(Mapping mapping) { this.from = mapping.fromNames; this.to = IndicesUtils.getIndicesNames(mapping.toData); this.signum = mapping.getSign(); this.innerBuffer = new IndexMappingBufferImpl(); }
permutation[i] = i; return Permutations.createPermutation(mapping.getSign(), permutation); //this is inverse permutation
Tensor applyIndexMappingToTo(Tensor oldFrom, Tensor to, Mapping mapping, SubstitutionIterator iterator) { if (toIsSymbolic) return mapping.getSign() ? Tensors.negate(to) : to; if (possiblyAddsDummies) return ApplyIndexMapping.applyIndexMapping(to, mapping, iterator.getForbidden()); return ApplyIndexMapping.applyIndexMappingAndRenameAllDummies(to, mapping, TensorUtils.getAllDummyIndicesT(oldFrom).toArray()); }
/** * Applies specified mapping of indices to tensor preventing some dummy index to be equal to one of the specified * <i>forbidden</i> indices. * * @param tensor tensor * @param mapping mapping of indices * @param forbidden forbidden indices * @return tensor with renamed indices */ public static Tensor applyIndexMapping(Tensor tensor, Mapping mapping, int[] forbidden) { if (mapping.isEmpty()) { if (tensor.getIndices().getFree().size() != 0) throw new IllegalArgumentException("From length does not match free indices size."); return renameDummyWithSign(tensor, forbidden, mapping.getSign()); } int[] freeIndicesNames = IndicesUtils.getIndicesNames(tensor.getIndices().getFree()); Arrays.sort(freeIndicesNames); if (!mapping.getFromNames().equalsToArray(freeIndicesNames)) { String fromIndices; try { fromIndices = IndicesUtils.toString(mapping.getFromNames().copy()); } catch (Exception e) { fromIndices = "error"; } throw new IllegalArgumentException("From indices names (" + fromIndices + ") does not match free indices names of tensor (" + IndicesUtils.toString(freeIndicesNames) + ")."); } Tensor result = _applyIndexMapping(tensor, mapping, forbidden); return mapping.getSign() ? Tensors.negate(result) : result; }
match = IndexMappings.getFirst(transformed[0], oldCoefficient); if (match != null) { newCoefficient = match.getSign() ? Tensors.negate(transformed[1]) : transformed[1]; break;
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; }