private static boolean matchSimpleTensors(Tensor a, Tensor b) { if (a.getClass() != b.getClass()) return false; if (a.hashCode() != b.hashCode()) return false; if (TensorUtils.isPositiveIntegerPowerOfSimpleTensor(a)) return TensorUtils.isPositiveIntegerPowerOfSimpleTensor(b) && a.get(1).equals(b.get(1)) && matchSimpleTensors(a.get(0), b.get(0)); if (a instanceof TensorField) for (int i = a.size() - 1; i >= 0; --i) if (!IndexMappings.positiveMappingExists(a.get(i), b.get(i))) return false; return true; }
@Override public IndexMappingProvider create(IndexMappingProvider opu, Tensor from, Tensor to) { if (((TensorField) from).getName() != ((TensorField) to).getName()) return IndexMappingProvider.Util.EMPTY_PROVIDER; for (int i = 0; i < from.size(); ++i) { if (!IndexMappings.positiveMappingExists(from.get(i), to.get(i))) return IndexMappingProvider.Util.EMPTY_PROVIDER; } return new ProviderSimpleTensor(opu, (SimpleTensor) from, (SimpleTensor) to); } };
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); }