private SpinorType isSpinor(Tensor st) { if (u != null && anyMappingExists(st, u)) return SpinorType.u; else if (v != null && anyMappingExists(st, v)) return SpinorType.v; else if (uBar != null && anyMappingExists(st, uBar)) return SpinorType.uBar; else if (vBar != null && anyMappingExists(st, vBar)) return SpinorType.vBar; else return null; }
public SinglePairSource(Tensor from, Tensor to, int fromPointer) { this.mappingsPort = IndexMappings.createPort(from, to); this.fromPointer = new int[]{fromPointer}; }
@Override Tensor newTo_(Tensor currentNode, SubstitutionIterator iterator) { Mapping mapping = IndexMappings.getFirst(from, currentNode); if (mapping == null) return currentNode; return applyIndexMappingToTo(currentNode, to, mapping, iterator); } }
/** * Returns a set of all possible mappings of tensor {@code from} on tensor {@code to}. * * @param from from tensor * @param to to tensor * @return a set of all possible mappings of tensor {@code from} on tensor {@code to} */ public static Set<Mapping> getAllMappings(Tensor from, Tensor to) { return getAllMappings(IndexMappings.createPort(from, to)); }
/** * Creates output port of mappings of tensor {@code from} on tensor {@code to}. * * @param from from tensor * @param to to tensor * @return output port of mappings */ static OutputPort<IndexMappingBuffer> createPortOfBuffers(Tensor from, Tensor to) { return createPortOfBuffers(new IndexMappingBufferImpl(), from, to); }
public boolean test(Mapping buffer) { for (int i = 1; i < from.length; ++i) if (!IndexMappings.testMapping(buffer, from[i], to[currentPermutation[i]])) return false; return true; } }
static IndexMappingProvider createPort(IndexMappingProvider opu, Tensor from, Tensor to) { if (from.hashCode() != to.hashCode()) return IndexMappingProvider.Util.EMPTY_PROVIDER; if (from.getClass() != to.getClass()) { Tensor nonComplex; //Processing case -2*(1/2)*g_mn -> g_mn if (from instanceof Product && !(to instanceof Product)) { if (from.size() != 2) return IndexMappingProvider.Util.EMPTY_PROVIDER; if ((nonComplex = extractNonComplexFactor(from)) != null) return new MinusIndexMappingProviderWrapper(createPort(opu, nonComplex, to)); return IndexMappingProvider.Util.EMPTY_PROVIDER; } //Processing case g_mn -> -2*(1/2)*g_mn if (to instanceof Product && !(from instanceof Product)) { if (to.size() != 2) return IndexMappingProvider.Util.EMPTY_PROVIDER; if ((nonComplex = extractNonComplexFactor(to)) != null) return new MinusIndexMappingProviderWrapper(createPort(opu, from, nonComplex)); return IndexMappingProvider.Util.EMPTY_PROVIDER; } return IndexMappingProvider.Util.EMPTY_PROVIDER; } IndexMappingProviderFactory factory = map.get(from.getClass()); if (factory == null) throw new RuntimeException("Unsupported tensor type: " + from.getClass()); return factory.create(opu, from, to); }
mapping = createBijectiveProductPort(fromIndexless, extract(content.indexless, indexlessBijection)).take(); if (mapping != null) break; ProductsBijectionsPort dataPort = new ProductsBijectionsPort(fromContent, currentContent); while ((dataBijection = dataPort.take()) != null) { mapping = createBijectiveProductPort(fromData, extract(currentData, dataBijection)).take(); if (mapping != null) break; dataBijection = new int[1]; currentData = new Tensor[]{content.data}; mapping = getFirst(fromContent.get(0), content.data);
/** * Returns {@code true} if tensor u mathematically (not programming) equals to tensor v. * * @param u tensor * @param v tensor * @return {@code true} if specified tensors are mathematically (not programming) equal */ public static boolean equals(Tensor u, Tensor v) { return IndexMappings.equals(u, v); }
/** * Returns {@code true} if tensor u mathematically (not programming) equals to tensor v, * {@code false} if they they differ only in the sign and {@code null} otherwise. * * @param u tensor * @param v tensor * @return {@code true} {@code false} if tensor u mathematically (not programming) equals to tensor v, * {@code true} if they they differ only in the sign and {@code null} otherwise */ public static Boolean compare1(Tensor u, Tensor v) { return IndexMappings.compare1(u, v); }
Tensor[] toAddFactors = Permutations.permute(toAdd.factors, match); Mapping mapping = IndexMappings.createBijectiveProductPort(toAddFactors, base.factors).take();
static IndexMappingBuffer getFirstBuffer(Tensor from, Tensor to) { return createPortOfBuffers(from, to).take(); }
@Override public int[] _nextMapping(Mapping buffer) { if (!IndexMappings.testMapping(buffer, from, to)) return null; return fromPointer; }
SimpleProductMappingsPort(final IndexMappingProvider opu, final Tensor[] from, final Tensor[] to) { providers = new IndexMappingProvider[from.length]; providers[0] = IndexMappings.createPort(opu, from[0], to[0]); for (int i = 1; i < from.length; ++i) providers[i] = IndexMappings.createPort(providers[i - 1], from[i], to[i]); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Wrapper wrapper = (Wrapper) o; return freeIndices.equals(wrapper.freeIndices) && IndexMappings.anyMappingExists(tensor, wrapper.tensor); }
private static Mapping0 buildMapping(Tensor eps, Tensor part) { if (!(part instanceof Product)) return null; Product p = (Product) part; Complex factor = p.getFactor(); Mapping mapping = IndexMappings.getFirst(eps, p.getDataSubProduct()); if (mapping == null) return null; return new Mapping0(factor, mapping); }
/** * Returns the first mapping of tensor {@code from} on tensor {@code to}. * * @param from from tensor * @param to to tensor * @return mapping of indices of tensor {@code from} on tensor {@code to} */ public static Mapping getFirst(Tensor from, Tensor to) { IndexMappingBuffer buffer = createPortOfBuffers(from, to).take(); if (buffer == null) return null; return new Mapping(buffer); }
private static boolean testMapping(Mapping0 mapping0, Tensor eps, Tensor part) { if (!(part instanceof Product)) return false; Product p = (Product) part; Complex factor = p.getFactor(); Tensor ds = p.getDataSubProduct(); if (IndexMappings.testMapping(mapping0.mapping, eps, ds)) return factor.equals(mapping0.factor); else if (IndexMappings.testMapping(mapping0.mapping.addSign(true), eps, ds)) return factor.equals(mapping0.factor.negate()); return false; }
public static List<Permutation> findIndicesSymmetries(int[] indices, Tensor tensor) { return getSymmetriesFromMappings(indices, IndexMappings.createPort(tensor, tensor)); }
private static boolean match(ProductContent pc, Element a, Element b) { return IndexMappings.anyMappingExists(pc.get(a.tIndex1), pc.get(b.tIndex1)); }