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; }
private Tensor metric(Tensor[] gammas) { return multiply( //metric createMetricOrKronecker(gammas[0].getIndices().get(metricType, 0), gammas[1].getIndices().get(metricType, 0)), //matrix createMetricOrKronecker(gammas[0].getIndices().getUpper().get(matrixType, 0), gammas[1].getIndices().getLower().get(matrixType, 0))); }
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; } }
protected Tensor[] del(Tensor[] arr, int i) { Tensor t = arr[i]; arr = ArraysUtils.remove(arr, i); if (arr.length == 0) return arr; if (i == 0) arr[0] = setUpperMatrixIndex((SimpleTensor) arr[0], t.getIndices().getUpper().get(matrixType, 0)); else if (i == arr.length) arr[arr.length - 1] = setLowerMatrixIndex((SimpleTensor) arr[arr.length - 1], t.getIndices().getLower().get(matrixType, 0)); else arr[i] = setUpperMatrixIndex((SimpleTensor) arr[i], t.getIndices().getUpper().get(matrixType, 0)); return arr; }
/** * Returns metric tensor if specified indices have same states and * Kronecker tensor if specified indices have different states. * * @param indices indices * @return metric tensor if specified indices have same states and * Kronecker tensor if specified indices have different states * @throws IllegalArgumentException if indices have different types * @throws IllegalArgumentException if indices have same states and non metric types * @throws IllegalArgumentException if indices.size() != 2 */ public static SimpleTensor createMetricOrKronecker(Indices indices) { if (indices.size() != 2) throw new IllegalArgumentException("Inconsistent indices for metric: " + indices); return CC.current().createMetricOrKronecker(indices.get(0), indices.get(1)); }
private Tensor order(Tensor[] gammas) { int numberOfGammas = gammas.length; Tensor tensor = cache.get(numberOfGammas); if (tensor == null) cache.put(numberOfGammas, tensor = order0(createLine(numberOfGammas))); int[] iFrom = new int[numberOfGammas + 2], iTo = new int[numberOfGammas + 2]; for (int i = 0; i < numberOfGammas; ++i) { iFrom[i] = setType(metricType, i); iTo[i] = gammas[i].getIndices().get(metricType, 0); } iFrom[numberOfGammas] = setType(matrixType, 0) | 0x80000000; iTo[numberOfGammas] = gammas[0].getIndices().getUpper().get(matrixType, 0); iFrom[numberOfGammas + 1] = setType(matrixType, numberOfGammas); iTo[numberOfGammas + 1] = gammas[numberOfGammas - 1].getIndices().getLower().get(matrixType, 0); return eliminate(ApplyIndexMapping.applyIndexMapping(tensor, new Mapping(iFrom, iTo))); }
private static boolean containsSubIndices(Indices indices, Indices subIndices) { int[] indicesArray = IndicesUtils.getIndicesNames(indices); Arrays.sort(indicesArray); for (int i = 0, size = subIndices.size(); i < size; ++i) if (Arrays.binarySearch(indicesArray, getNameWithType(subIndices.get(i))) < 0) return false; return true; }
/** * Returns all non metric types that present in specified indices. * * @param indices indices * @return all non metric types that present in specified indices */ public static EnumSet<IndexType> nonMetricTypes(final Indices indices) { EnumSet<IndexType> types = EnumSet.noneOf(IndexType.class); for (int i = 0; i < indices.size(); ++i) { int index = indices.get(i); if (!CC.isMetric(getType(index))) types.add(getTypeEnum(index)); } return types; } }
private static boolean containsIndicesNames(TIntHashSet set, Indices indices) { for (int i = 0; i < indices.size(); ++i) if (set.contains(getNameWithType(indices.get(i)))) return true; return false; }
private static void getAllIndices1(ParseToken node, Set<Integer> set) { if (node instanceof ParseTokenSimpleTensor) { Indices indices = node.getIndices(); for (int i = indices.size() - 1; i >= 0; --i) set.add(IndicesUtils.getNameWithType(indices.get(i))); } else for (ParseToken pn : node.content) if (!(pn instanceof ParseTokenScalarFunction)) getAllIndices1(pn, set); }
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); }
/** * Returns {@code true} if specified indices contain any index with non metric type. * * @param indices indices * @return {@code true} if specified indices contain any index with non metric type */ public static boolean containsNonMetric(final Indices indices) { for (int i = 0; i < indices.size(); ++i) { if (!CC.isMetric(getType(indices.get(i)))) return true; } return false; }
/** * Returns an array of indices names (with types), presented in specified {@code Indices} * object with the same ordering. * * @param indices * @return array of indices names (with types) */ public static int[] getIndicesNames(Indices indices) { int a[] = new int[indices.size()]; for (int i = indices.size() - 1; i >= 0; --i) a[i] = getNameWithType(indices.get(i)); return a; }
private static void getAllIndicesT1(ParseToken node, TIntSet set) { if (node instanceof ParseTokenSimpleTensor) { Indices indices = node.getIndices(); for (int i = indices.size() - 1; i >= 0; --i) set.add(IndicesUtils.getNameWithType(indices.get(i))); } else for (ParseToken pn : node.content) if (!(pn instanceof ParseTokenScalarFunction)) getAllIndicesT1(pn, set); } }
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 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); }
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; }