/** * Returns true if at least one free index of {@code u} is contracted * with some free index of {@code v}. * * @param u tensor * @param v tensor * @return true if at least one free index of {@code u} is contracted * with some free index of {@code v} */ public static boolean haveIndicesIntersections(Tensor u, Tensor v) { return IndicesUtils.haveIntersections(u.getIndices(), v.getIndices()); }
public static boolean sumContainsIndexed(Tensor t) { if (!(t instanceof Sum)) return false; for (Tensor s : t) if (s.getIndices().size() != 0) return true; return false; }
/** * Appends indices of specified {@code Tensor}. * * @param tensor a tensor * @return a reference to this object */ public IndicesBuilder append(Tensor tensor) { return append(tensor.getIndices()); }
int[] getOriginalIndices(IndexType metricType) { int[] metricIndices = new int[originalArray.length]; for (int i = 0; i < originalArray.length; ++i) metricIndices[i] = originalArray[i].getIndices().get(metricType, 0); return metricIndices; } }
private static void checkConsistence(Tensor from, Tensor to) { if (!TensorUtils.isZeroOrIndeterminate(to)) if (!from.getIndices().getFree().equalsRegardlessOrder(to.getIndices().getFree())) throw new IllegalArgumentException("Tensor from free indices not equal to tensor to free indices: " + from.getIndices().getFree() + " " + to.getIndices().getFree()); }
private static Tensor[] expandSamples(Tensor[] samples) { //select diff samples: HashSet<Wrapper> set = new HashSet<>(); for (Tensor sample : samples) set.add(new Wrapper(sample)); ArrayList<Tensor> r = new ArrayList<>(); for (Wrapper st : set) { r.ensureCapacity(ArithmeticUtils.pow(2, st.tensor.getIndices().getFree().size())); r.addAll(Arrays.asList(TensorGeneratorUtils.allStatesCombinations(st.tensor))); } return r.toArray(new Tensor[r.size()]); }
public static boolean isSymbolic(Tensor t) { if (t.getIndices().size() != 0) return false; for (Tensor c : t) if (!isSymbolic(c)) return false; return true; }
protected final void swapAdj(Tensor[] gammas, int j) { Tensor t = gammas[j]; gammas[j] = setMatrixIndices((SimpleTensor) gammas[j + 1], gammas[j].getIndices().getOfType(matrixType)); gammas[j + 1] = setMatrixIndices((SimpleTensor) t, gammas[j + 1].getIndices().getOfType(matrixType)); }
public Expression[] getNablaS() { if (operatorOrder < 1) return new Expression[0]; Expression[] nablaS = new Expression[getHatQuantities(1).length]; StringBuilder sb; for (int i = 0; i < nablaS.length; ++i) { sb = new StringBuilder().append("NABLAS_{l_{9}}").append(getHatQuantities(1)[i].get(0).getIndices().toString(OutputFormat.Redberry)).append("=0"); nablaS[i] = (Expression) Tensors.parse(sb.toString()); } return nablaS; }
private Tensor orderArray(Tensor[] gammas) { Gamma[] gs = new Gamma[gammas.length]; for (int i = 0; i < gammas.length; ++i) gs[i] = new Gamma(gammas[i], gammas[i].getIndices().get(metricType, 0), null); return orderArray(gs); }
private Wrapper(Tensor tensor) { this.tensor = tensor; this.freeIndices = StructureOfIndices.create( IndicesFactory.createSimple(null, tensor.getIndices().getFree())); }
private static int hc(Tensor t, int[] inds) { Indices ind = t.getIndices().getFree(); int h = 31; int ii; for (int i = ind.size() - 1; i >= 0; --i) { ii = IndicesUtils.getNameWithType(ind.get(i)); if ((ii = Arrays.binarySearch(inds, ii)) >= 0) h ^= HashFunctions.JenkinWang32shift(ii); } return h; }
/** * @deprecated very unsafe method without checks */ @Deprecated public static Tensor multiplySumElementsOnFactors(Sum sum) { final Tensor[] newSumData = new Tensor[sum.size()]; for (int i = newSumData.length - 1; i >= 0; --i) newSumData[i] = multiply(CC.generateNewSymbol(), sum.get(i)); return new Sum(newSumData, IndicesFactory.create(newSumData[0].getIndices().getFree())); }
private static TIntHashSet getAllDummyIndicesT(boolean includeScalarFunctions, Tensor tensor) { TIntHashSet set = new TIntHashSet(); appendAllIndicesNamesT(tensor, set, includeScalarFunctions); set.removeAll(IndicesUtils.getIndicesNames(tensor.getIndices().getFree())); return set; }
private static Tensor applyIndexMapping(Tensor tensor, IndexMapper indexMapper) { if (tensor instanceof SimpleTensor) return applyIndexMapping(tensor, indexMapper, false); if (tensor instanceof Complex || tensor instanceof ScalarFunction) return tensor; return applyIndexMapping(tensor, indexMapper, indexMapper.contract(getIndicesNames(tensor.getIndices().getFree()))); }
@Override public IndexMappingProvider create(IndexMappingProvider opu, Tensor from, Tensor to) { if (((SimpleTensor) from).getName() != ((SimpleTensor) to).getName()) return IndexMappingProvider.Util.EMPTY_PROVIDER; if (from.getIndices().size() == 0) return new DummyIndexMappingProvider(opu); return new ProviderSimpleTensor(opu, (SimpleTensor) from, (SimpleTensor) to); } };
private static Tensor invertIndices(Tensor t) { Indices free = t.getIndices().getFree(); Mapping mapping = new Mapping(free.toArray(), free.getInverted().toArray()); return ApplyIndexMapping.applyIndexMapping(t, mapping); }
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 static Tensor multiplySumElementsOnFactor(Sum sum, Tensor factor, Transformation[] transformations) { if (TensorUtils.isZero(factor)) return Complex.ZERO; if (TensorUtils.isOne(factor)) return sum; if (TensorUtils.haveIndicesIntersections(sum, factor) || (sum.indices.size() == 0 && factor.getIndices().size() != 0)) return multiplyWithBuilder(sum, factor, transformations); else return multiplyWithFactory(sum, factor, transformations); }
Expression createSubstitution(int length) { if (length <= 2) return subs[length - 2]; Expression expr = substitutions.get(length); if (expr == null) { Tensor[] line = createLine(length); line[length - 1] = setMetricIndex((SimpleTensor) line[length - 1], IndicesUtils.inverseIndexState(line[0].getIndices().get(metricType, 0))); substitutions.put(length, expr = expression(multiply(line), createSubstitution0(line))); } return expr; }