if (contraction == null) continue; Tensor t1 = pc.get(contraction.tIndex1); if (!(t1 instanceof SimpleTensor) || t1.getIndices().size() != 1) continue; modifiedElements.addAll(el.tIndex1, el.tIndex2); if (!el.available(mask)) { ordered.add(pc.get(el.tIndex1)); ordered.add(pc.get(el.tIndex2)); continue; ordered.add(pc.get(pg.gPositions.get(i))); Tensor g5 = pc.get(pg.gPositions.get(pg.g5Positions.first())); if (result instanceof Sum) result = FastTensors.multiplySumElementsOnFactorAndResolveDummies((Sum) result, g5);
IntArrayList list = new IntArrayList(); do { Tensor t = content.get(index); if (!(t instanceof SimpleTensor)) continue; int size = content.size(); for (index = 0; index < size; ++index) { current = content.get(index); if (!(current instanceof SimpleTensor)) continue; pb.put(content.get(i)); return pb.build();
ProductContent pc = product.getContent(); if (pc.size() == 1) { int dataHash = _hashWithIndices(pc.get(0), indices); return product.getFactor().isOneOrMinusOne() ? dataHash : dataHash * product.getFactor().hashCode(); hash += HashFunctions.JenkinWang32shift((int) pc.getStretchId(i)) * _hashWithIndices(pc.get(i), indices); return hash;
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()]); }
@Override protected Tensor transformLine(ProductOfGammas pg, IntArrayList modifiedElements) { assert pg.g5Positions.size() == 0 || (pg.g5Positions.size() == 1 && pg.g5Positions.first() == pg.length - 1) : "G5s are not simplified"; int length = pg.length; if (pg.g5Positions.size() == 1) --length; if (length <= 1) return null; ProductContent pc = pg.pc; StructureOfContractions st = pc.getStructureOfContractions(); Gamma[] gammas = new Gamma[length]; for (int i = 0; i < length; i++) { Tensor gamma = pc.get(pg.gPositions.get(i)); gammas[i] = new Gamma(gamma, gamma.getIndices().get(metricType, 0), getContraction(pg.gPositions.get(i), pc, st)); } Tensor ordered = orderArray(gammas); if (ordered == null) return null; if (pg.g5Positions.size() == 1) { Tensor g5 = pc.get(pg.gPositions.get(pg.g5Positions.first())); if (ordered instanceof Sum) ordered = multiplySumElementsOnFactorAndResolveDummies((Sum) ordered, g5); else ordered = multiplyAndRenameConflictingDummies(ordered, g5); } return ordered; }
public List<Tensor> toList() { List<Tensor> array = new ArrayList<>(gPositions.size()); for (int i = 0; i < gPositions.size(); i++) array.add(pc.get(gPositions.get(i))); return array; }
public Tensor[] toArray() { Tensor[] array = new Tensor[gPositions.size()]; for (int i = 0; i < gPositions.size(); i++) array[i] = pc.get(gPositions.get(i)); return array; }
private Tensor getContraction(int gamma, ProductContent pc, StructureOfContractions sc) { Indices indices = pc.get(gamma).getIndices(); int j = 0; for (; j < indices.size(); ++j) if (metricType.getType() == getType(indices.get(j))) break; int to = getToTensorIndex(sc.contractions[gamma][j]); if (to == -1) return null; return pc.get(to); }
private Tensor simplify(Element el, IntArrayList gPositions, ProductContent pc) { Tensor[] gammas = new Tensor[el.gIndex2 - el.gIndex1 + 1]; for (int i = el.gIndex1; i <= el.gIndex2; ++i) { gammas[i - el.gIndex1] = pc.get(gPositions.get(i)); if (!isGamma(pc.get(gPositions.get(i)))) return null;//can not simplify } Tensor r = order(gammas); Tensor m = multiply(pc.get(el.tIndex1), pc.get(el.tIndex2)); if (r instanceof Sum) r = FastTensors.multiplySumElementsOnFactor((Sum) r, m); else r = multiply(r, m); r = expandAndEliminate.transform(r); r = traceOfOne.transform(r); r = deltaTrace.transform(r); return r; }
public Indices getIndices() { IndicesBuilder indices = new IndicesBuilder(); for (int i = 0; i < length; i++) indices.append(pc.get(gPositions.get(i))); return indices.getIndices(); }
public Tensor toProduct() { ProductBuilder pb = new ProductBuilder(); for (int i = 0; i < gPositions.size(); i++) pb.put(pc.get(gPositions.get(i))); return pb.build(); }
private int withMomentum(int gamma, ProductContent pc, StructureOfContractions sc) { Indices indices = pc.get(gamma).getIndices(); int j = 0; for (; j < indices.size(); ++j) if (metricType.getType() == getType(indices.get(j))) break; return getToTensorIndex(sc.contractions[gamma][j]); }
private Element getContraction(int gIndex, int gamma, ProductContent pc, StructureOfContractions sc) { Indices indices = pc.get(gamma).getIndices(); int j = 0; for (; j < indices.size(); ++j) if (metricType.getType() == getType(indices.get(j))) break; int to = getToTensorIndex(sc.contractions[gamma][j]); if (to == -1) return null; return new Element(to, gIndex); }
private int[] getLinks(final int pivot) { if (pivot == DUMMY_PIVOT) return DUMMY; assert pivot >= 0; final int[] links = {NOT_INITIALIZED, NOT_INITIALIZED}; final long[] contractions = fcs.contractions[pivot]; Indices indices = pc.get(pivot).getIndices(); int index, toTensorIndex; for (int i = contractions.length - 1; i >= 0; --i) { index = indices.get(i); if (getType(index) != type.getType()) continue; toTensorIndex = getToTensorIndex(contractions[i]); int state = 1 - getStateInt(index); if (links[state] >= -1 && links[state] != toTensorIndex) links[state] = BRANCHING; if (links[state] == NOT_INITIALIZED) links[state] = toTensorIndex; } if (links[0] == NOT_INITIALIZED) links[0] = NO_LINKS; if (links[1] == NOT_INITIALIZED) links[1] = NO_LINKS; return links; }
@Override protected Tensor transformLine(ProductOfGammas pg, IntArrayList modifiedElements) { assert pg.g5Positions.size() == 0 || (pg.g5Positions.size() == 1 && pg.g5Positions.first() == pg.length - 1) : "G5s are not simplified"; int length = pg.length; if (pg.g5Positions.size() == 1) --length; if (length <= 1) return null; ProductContent pc = pg.pc; IntArrayList lengths = new IntArrayList(); for (int i = 0; i < length - 1; ++i) { Tensor g1 = pc.get(pg.gPositions.get(i)); for (int j = i + 1; j < length; ++j) { Tensor g2 = pc.get(pg.gPositions.get(j)); if (areContracted(g1.getIndices().get(metricType, 0), g2.getIndices().get(metricType, 0))) lengths.add(j - i + 1); } } if (lengths.isEmpty()) return null; lengths.sort(); Transformation[] overall = new Transformation[lengths.size() + 3]; for (int i = lengths.size() - 1; i >= 0; --i) overall[i] = createSubstitution(lengths.get(i)); overall[lengths.size()] = expandAndEliminate; overall[lengths.size() + 1] = deltaTrace; overall[lengths.size() + 2] = traceOfOne; return transform(Transformation.Util.applyUntilUnchanged(multiply(pg.toArray()), overall)); }
@Override protected Tensor transformLine(ProductOfGammas pg, IntArrayList modifiedElements) { //single matrix if (pg.length == 1) return null; //no g5s if (pg.g5Positions.isEmpty()) return null; if (pg.g5Positions.size() == 1) { //single g5 in trace -> nothing to do if (pg.graphType == GraphType.Cycle) return null; //single g5 at the last position -> nothing to do if (pg.g5Positions.first() == pg.length - 1) return null; } if (pg.g5Positions.size() == pg.length) {//only g5s if (pg.length % 2 == 0) { //all gammas cancel if (pg.graphType == GraphType.Cycle) return traceOfOne.get(1); else return createMetricOrKronecker(pg.getIndices().getFree()); } else { assert pg.graphType != GraphType.Cycle;//this should be already processed return setMatrixIndices((SimpleTensor) pg.pc.get(pg.gPositions.first()), pg.getIndices().getFree()); } } return simplifyProduct(pg.toList()); }
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()); }