/** * Creates partition of graph (or equivalently the product of indexed tensors) specified by {@link ProductContent} * taking into account edges (dummy indices) of specified {@link IndexType}. This method returns an array of all its * sub-graphs of types specified by {@link GraphType}. * * @param p {@link ProductContent} representing the graph * @param type type of edges to be taken into account in partition * @since 1.1 */ public static PrimitiveSubgraph[] calculatePartition(ProductContent p, IndexType type) { return new PrimitiveSubgraphPartition(p, type).partition; }
public It(int gamma, int gamma5, Product product, IndexType matrixType, Indicator<GraphType> filter) { this.gamma = gamma; this.gamma5 = gamma5; this.product = product; this.content = product.getContent(); this.matrixType = matrixType; this.partition = PrimitiveSubgraphPartition.calculatePartition(this.content, matrixType); this.filter = filter; }
left = right = getLinks(pivot); return processGraph(pivot); return new PrimitiveSubgraph(GraphType.Cycle, new int[]{pivot}); return processGraph(pivot); return new PrimitiveSubgraph(GraphType.Cycle, deque2array(positions)); left = getLinks(leftPivot); return processGraph(pivot); return new PrimitiveSubgraph(GraphType.Cycle, deque2array(positions)); left = getLinks(leftPivot); right = getLinks(rightPivot); return new PrimitiveSubgraph(GraphType.Line, deque2array(positions));
void printData() { ArrayList<SubgraphContainer> subgraphs = new ArrayList<>(); for (IndexType type : matrixTypes) { PrimitiveSubgraph[] sgs = PrimitiveSubgraphPartition.calculatePartition(getContent(), type); out0: for (PrimitiveSubgraph sg : sgs) { int[] partition = sg.getPartition(); TIntHashSet points = new TIntHashSet(partition); boolean newSg = true, newGraph = false; if (points.equals(container.points)) { if (container.graphType != sg.getGraphType() || !Arrays.equals(container.partition, partition)) { fillGraphPrint(subgraphs.get(i).partition); matched.add(i); } else if (includes(partition, container.partition) && sg.getGraphType() == container.graphType) { subgraphs.add(new SubgraphContainer(sg.getGraphType(), partition, points, type)); else if (newGraph) fillGraphPrint(partition);
= PrimitiveSubgraphPartition.calculatePartition(pc, matrixType); for (PrimitiveSubgraph subgraph : partition) { matched.clear(); if (subgraph.getGraphType() != GraphType.Line) continue; SpinorType left = isSpinor(pc.get(subgraph.getPosition(0))), right = isSpinor(pc.get(subgraph.getPosition(subgraph.size() - 1))); if (left == null && right == null) continue; for (int i = 0; i < subgraph.size(); ++i) { if (!isGamma(pc.get(subgraph.getPosition(i)))) continue; int mIndex = withMomentum(subgraph.getPosition(i), pc, st); if (mIndex != -1) { Tensor co = pc.get(mIndex); int gSize = subgraph.size(); Tensor spinors = product.select(momentums.toArray()); if (left != null) { spinors = multiply(spinors, pc.get(subgraph.getPosition(0))); --gSize; spinors = multiply(spinors, pc.get(subgraph.getPosition(subgraph.size() - 1))); --gSize; if (right == null || (left != null && matched.first() < subgraph.size() - matched.last())) { Tensor r = pc.get(subgraph.getPosition(i));
private Tensor expandDiracStructures(final Tensor t) { FromChildToParentIterator iterator = new FromChildToParentIterator(t); Tensor current; while ((current = iterator.next()) != null) { if (!(current instanceof Product)) continue; //early termination if (!containsGammaOr5Matrices(current)) continue; Product product = (Product) current; //positions of matrices PrimitiveSubgraph[] partition = PrimitiveSubgraphPartition.calculatePartition(product.getContent(), matrixType); //traces (expand brackets) boolean containsTraces = false; traces: for (PrimitiveSubgraph subgraph : partition) { if (subgraph.getGraphType() != GraphType.Cycle) continue traces; //expand each cycle containsTraces = true; } if (containsTraces) iterator.set(multiply(product.getIndexlessSubProduct(), expandAndEliminate.transform(product.getDataSubProduct()))); } return iterator.result(); }
if (filter.is(partition[iPartition].getGraphType())) break; if (iSubgraphPosition == currentSubgraph.size()) { ++iPartition; iSubgraphPosition = 0; break; int p = currentSubgraph.getPosition(iSubgraphPosition); if (isGamma(content.get(p))) gPositions.add(p); if (currentSubgraph.getGraphType() == GraphType.Cycle && g5Positions.size() == 1 && gPositions.size() == currentSubgraph.size() && g5Positions.first() != currentSubgraph.size() - 1) { int g5 = g5Positions.first(), size = currentSubgraph.size(); g5Positions.set(0, size - 1); for (int i = 0; i <= g5; ++i) gPositions.set(size - g5 - 1 + i, currentSubgraph.getPosition(i)); for (int i = g5 + 1; i < size; ++i) gPositions.set(i - g5 - 1, currentSubgraph.getPosition(i)); if (currentSubgraph.getGraphType() == GraphType.Cycle && gPositions.size() == currentSubgraph.size()) graphType = GraphType.Cycle;
stack.push(new BreadthFirstPointer(m1, fromIndex[m1])); stack.push(new BreadthFirstPointer(pointsTo, fromIndex[pointsTo])); } while ((m1 = firstM1(components)) != vertices);
infoTensorIndicesTo = Arrays.copyOf(infoTensorIndicesTo, infoTensorIndicesTo.length - shift); int[] components = GraphUtils.calculateConnectedComponents(infoTensorIndicesFrom, infoTensorIndicesTo, data.length); componentCount = components[components.length - 1]; this.components = Arrays.copyOfRange(components, 0, components.length - 1);
public SeedPlanter() { int[][] hits = new int[seeds.length][]; IntArrayList hitList = new IntArrayList(); for (int seedIndex = 0; seedIndex < seeds.length; ++seedIndex) { hitList.clear(); for (int i = 0; i < targetData.length; ++i) if (weakMatch(fromData[seeds[seedIndex]], targetData[i]) && GraphUtils.componentSize(seeds[seedIndex], fromFContractions.components) <= GraphUtils.componentSize(i, targetFContractions.components)) hitList.add(i); hits[seedIndex] = hitList.toArray(); } combinationsPort = new IntDistinctTuplesPort(hits); }
private PrimitiveSubgraph[] calculatePartition() { List<PrimitiveSubgraph> subgraphs = new ArrayList<>(); for (int pivot = 0; pivot < size; ++pivot) if (pc.get(pivot).getIndices().size(type) != 0 && !used.get(pivot)) subgraphs.add(calculateComponent(pivot)); return subgraphs.toArray(new PrimitiveSubgraph[subgraphs.size()]); }
private PrimitiveSubgraph processGraph(int pivot) { IntArrayList positions = new IntArrayList(); positions.add(pivot); IntArrayList stack = new IntArrayList(); stack.push(pivot); used.set(pivot); long[] contractions; Indices indices; int currentPivot, index, toTensorIndex; while (!stack.isEmpty()) { currentPivot = stack.pop(); indices = pc.get(currentPivot).getIndices(); contractions = fcs.contractions[currentPivot]; for (int i = contractions.length - 1; i >= 0; --i) { index = indices.get(i); if (getType(index) != type.getType()) continue; toTensorIndex = getToTensorIndex(contractions[i]); if (toTensorIndex == -1 || used.get(toTensorIndex)) continue; used.set(toTensorIndex); positions.add(toTensorIndex); stack.push(toTensorIndex); } } return new PrimitiveSubgraph(GraphType.Graph, positions.toArray()); }
private static Tensor inverseOrderInProduct(Product product, IndexType type) { ProductContent pc = product.getContent(); PrimitiveSubgraph[] subgraphs = PrimitiveSubgraphPartition.calculatePartition(pc, type); Tensor[] data = pc.getDataCopy(); boolean somethingDone = false; for (PrimitiveSubgraph ps : subgraphs) { if (ps.getGraphType() == GraphType.Graph) throw new IllegalArgumentException("Not a product of matrices."); if (ps.getGraphType() != GraphType.Line) continue; int[] partition = ps.getPartition();
/** * Creates partition of graph (or equivalently the product of indexed tensors) specified by {@link ProductContent} * taking into account edges (dummy indices) of specified {@link IndexType}. * * @param productContent {@link ProductContent} representing the graph * @param type type of edges to be taken into account in partition */ public PrimitiveSubgraphPartition(ProductContent productContent, IndexType type) { this.pc = productContent; this.fcs = pc.getStructureOfContractions(); this.size = pc.size(); this.type = type; this.used = new BitArray(size); this.partition = calculatePartition(); }
/** * Creates a partition of graph (or equivalently the product of indexed tensors) specified by {@link Product} taking * into account edges (dummy indices) of specified {@link IndexType}. This method returns an array of all its * sub-graphs of types specified by {@link GraphType}. <b>Note</b>, that only indexed part of specified product * (i.e. its {@link ProductContent}) will be taken into account. So the positions of sub-graphs elements in {@link * PrimitiveSubgraph} may not be equal to the positions of tensors in product (since it can e.g. have a symbolic * part), but strictly corresponds to the positions of tensors in its {@link ProductContent}, i.e. in the indexed * part of the product. * * @param p {@link Product} representing the graph * @param type type of edges to be taken into account in partition * @return the partition of graph, i.e. an array of all its sub-graphs of types specified by {@link GraphType} * @since 1.1 */ public static PrimitiveSubgraph[] calculatePartition(Product p, IndexType type) { return new PrimitiveSubgraphPartition(p.getContent(), type).partition; }
int[] components = GraphUtils.calculateConnectedComponents( infoToTensorIndices(upperInfo), infoToTensorIndices(lowerInfo), data.length + 1);
ProductContent productContent = product.getContent(); PrimitiveSubgraph[] subgraphs = PrimitiveSubgraphPartition.calculatePartition(productContent, matrixType); for (PrimitiveSubgraph subgraph : subgraphs) { if (subgraph.getGraphType() != GraphType.Cycle) continue; int[] partition = subgraph.getPartition(); for (int i = partition.length - 1; i >= 0; --i) { partition[i] = sizeOfIndexless + partition[i];