for (i = 1; i <= fromContent.size(); ++i) if (i == fromContent.size() || !fromContent.getStructureOfContractionsHashed().get(i).equals(fromContent.getStructureOfContractionsHashed().get(i - 1))) { if (i - 1 != begin) stretches.add(new Pair(fromContent.getRange(begin, i), toContent.getRange(begin, i))); else providers.add(lastOutput = IndexMappings.createPort(lastOutput, fromContent.get(begin), toContent.get(begin))); begin = i;
public ProductsBijectionsPort(ProductContent fromContent, ProductContent targetContent) { //this.targetContent = targetContent; //this.fromContent = fromContent; this.targetFContractions = targetContent.getStructureOfContractions(); this.fromFContractions = fromContent.getStructureOfContractions(); this.fromContractions = fromFContractions.contractions; this.targetContractions = targetFContractions.contractions; int[] seeds = new int[fromFContractions.componentCount]; Arrays.fill(seeds, -1); for (int i = 0; i < fromFContractions.components.length; ++i) if (seeds[fromFContractions.components[i]] == -1) seeds[fromFContractions.components[i]] = i; this.seeds = seeds; this.fromData = fromContent.getRange(0, fromContent.size()); this.targetData = targetContent.getRange(0, targetContent.size()); this.planter = new SeedPlanter(); }
public PrimitiveProductSubstitution(Tensor from, Tensor to) { super(from, to); Product product = (Product) from; this.fromFactor = product.getFactor(); this.fromIndexless = product.getIndexless(); this.fromContent = product.getContent(); this.fromData = fromContent.getDataCopy(); }
/** * 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(); }
StructureOfContractionsHashed cs = content.getStructureOfContractionsHashed(); short si = content.getStretchIndexByHash(name); if (si == -1) return tensor; short[] sIndices = content.getStretchIds(); //For preformance. int index = Arrays.binarySearch(sIndices, si); while (index >= 0 && sIndices[index--] == si); IntArrayList list = new IntArrayList(); do { Tensor t = content.get(index); if (!(t instanceof SimpleTensor)) continue; IntArrayList toRemvoe = new IntArrayList(); Tensor current; 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();
StructureOfContractions sc = pc.getStructureOfContractions(); 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);
int i = 0, sizeOfComponent = content.size(); for (; i < sizeOfComponent; ++i) if (isLeviCivita(content.get(i), leviCivita)) epsPositions.add(i); StructureOfContractions fs = content.getStructureOfContractions(); sizeOfComponent = epsPositions.size(); if (toIndex == -1) continue; temp = content.get(toIndex); if (isLeviCivita(temp, leviCivita)) continue; int[] epsIndices = content.get(epsPositions.get(i)).getIndices().getFree().getAllIndices().copy();
Product product = (Product) tensor; ProductContent pc = product.getContent(); if (pc.size() == 1) { int dataHash = _hashWithIndices(pc.get(0), indices); return product.getFactor().isOneOrMinusOne() ? dataHash : dataHash * product.getFactor().hashCode(); for (int i = pc.size() - 1; i >= 0; --i) hash += HashFunctions.JenkinWang32shift((int) pc.getStretchId(i)) * _hashWithIndices(pc.get(i), indices); return hash;
if (content.data instanceof Product) { ProductContent currentContent = ((Product) content.data).getContent(); currentData = currentContent.getDataCopy(); ProductsBijectionsPort dataPort = new ProductsBijectionsPort(fromContent, currentContent); while ((dataBijection = dataPort.take()) != null) { if (fromContent.size() != 0) return null; dataBijection = new int[0]; mapping = Mapping.IDENTITY_MAPPING; } else { if (fromContent.size() != 1) return null; dataBijection = new int[1]; currentData = new Tensor[]{content.data}; mapping = getFirst(fromContent.get(0), content.data); (content.data instanceof Product) ? content.data.size() : 1 - fromContent.size()); int pivot = 0; int i, j = 0;
private int calculateHash() { int result; if (factor == Complex.ONE || factor == Complex.MINUS_ONE) result = 0; //important for -a.hash() == a.hash() else result = factor.hashCode(); for (Tensor t : indexlessData) result = result * 31 + t.hashCode(); for (Tensor t : data) result = result * 17 + t.hashCode(); if (factor == Complex.MINUS_ONE && size() == 2) return result; return result - 79 * getContent().getStructureOfContractionsHashed().hashCode(); }
Product product = (Product) tensor; ProductContent content = product.getContent(); factor = content.getNonScalar(); Tensor[] scalars = content.getScalars(); int dataLength = factor instanceof Product ? product.data.length - ((Product) factor).data.length
/** * Returns all scalar factors in this product excluding the numerical factor. For example, if * this is 2*a*f_mn*G^mn*f_a*T^ab, the result will be [a,f_mn*G^mn]. * * @return all scalar factors in this product excluding the numerical factor */ public Tensor[] getAllScalarsWithoutFactor() { Tensor[] scalras = getContent().getScalars(); Tensor[] allScalars = new Tensor[indexlessData.length + scalras.length]; System.arraycopy(indexlessData, 0, allScalars, 0, indexlessData.length); System.arraycopy(scalras, 0, allScalars, indexlessData.length, scalras.length); return allScalars; }
Tensor nonScalar = pc.getNonScalar(); if (nonScalar == null) return;
ProductContent content = new ProductContent(structureOfContractionsHashed, structureOfContractions, scalars, nonScalar, stretchIndices, data); contentReference.resetReferent(content);
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; }
return IndexMappingProvider.Util.EMPTY_PROVIDER; ProductContent fromContent = pfrom.getContent(), toContent = pto.getContent(); if (!fromContent.getStructureOfContractionsHashed().equals(toContent.getStructureOfContractionsHashed())) return IndexMappingProvider.Util.EMPTY_PROVIDER; Tensor[] fromScalars = pfrom.getAllScalarsWithoutFactor(), toScalars = pto.getAllScalarsWithoutFactor();
/** * Returns all scalar factors in this product. For example, if this is 2*a*f_mn*G^mn*f_a*T^ab, the * result will be [2,a,f_mn*G^mn]. * * @return all scalar factors in this product */ public Tensor[] getAllScalars() { Tensor[] scalras = getContent().getScalars(); if (factor == Complex.ONE) { Tensor[] allScalars = new Tensor[indexlessData.length + scalras.length]; System.arraycopy(indexlessData, 0, allScalars, 0, indexlessData.length); System.arraycopy(scalras, 0, allScalars, indexlessData.length, scalras.length); return allScalars; } else { Tensor[] allScalars = new Tensor[1 + indexlessData.length + scalras.length]; allScalars[0] = factor; System.arraycopy(indexlessData, 0, allScalars, 1, indexlessData.length); System.arraycopy(scalras, 0, allScalars, indexlessData.length + 1, scalras.length); return allScalars; } }