/** * Returns an array of indices names (with types) * * @param indices * @return array of indices names (with types) */ public static int[] getIndicesNames(int[] indices) { int a[] = new int[indices.length]; for (int i = a.length - 1; i >= 0; --i) a[i] = getNameWithType(indices[i]); return a; }
@Override public boolean tryMap(int from, int to) { int fromName = IndicesUtils.getNameWithType(from), toName = IndicesUtils.getNameWithType(to); int position; if ((position = Arrays.binarySearch(this.from, fromName)) < 0) return innerBuffer.tryMap(from, to); return this.to[position] == toName; }
private static boolean containsIndicesNames(TIntHashSet set, int[] indices) { for (int i : indices) if (set.contains(getNameWithType(i))) return true; return false; }
@Override public int map(int index) { int position = Arrays.binarySearch(from, 0, size, IndicesUtils.getNameWithType(index)); if (position < 0) return index; return IndicesUtils.getRawStateInt(index) ^ to[position]; }
@Override public int map(int index) { int position = Arrays.binarySearch(from, IndicesUtils.getNameWithType(index)); if (position < 0) return index; return IndicesUtils.getRawStateInt(index) ^ to[position]; } }
/** * Returns an array of indices names (with types) * * @param indices * @return array of indices names (with types) */ public static int[] getIndicesNames(IntArray indices) { int a[] = new int[indices.length()]; for (int i = a.length - 1; i >= 0; --i) a[i] = getNameWithType(indices.get(i)); return a; }
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; }
/** * Creates mapping from given {@code from} and {@code to} arrays of indices. * * @param from indices from * @param to indices to * @param sign the sign of mapping */ public Mapping(final int[] from, final int[] to, final boolean sign) { if (from.length != to.length) throw new IllegalArgumentException("From length != to length."); fromNames = new int[from.length]; toData = new int[from.length]; for (int i = 0; i < from.length; ++i) { fromNames[i] = IndicesUtils.getNameWithType(from[i]); toData[i] = IndicesUtils.getRawStateInt(from[i]) ^ to[i]; } ArraysUtils.quickSort(fromNames, toData); this.sign = sign; }
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); }
public IndexMappingBufferRecord(int from, int to) { this.toName = IndicesUtils.getNameWithType(to); states |= 1 << IndicesUtils.getStateInt(to); states |= (IndicesUtils.getStateInt(from) ^ IndicesUtils.getStateInt(to)) << 2; }
/** * 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; }
/** * This method returns array of integers representing set of indices names * present in the {@link Indices} object. * * @param indices object to process * @return see description */ public static int[] getSortedDistinctIndicesNames(Indices indices) { int[] indsArray = indices.getAllIndices().copy(); for (int i = 0; i < indsArray.length; ++i) indsArray[i] = IndicesUtils.getNameWithType(indsArray[i]); return MathUtils.getSortedDistinct(indsArray); }
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 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); } }
public IndicesInsertion(SimpleIndices upper, SimpleIndices lower, Indicator<ParseTokenSimpleTensor> indicator) { checkIndices(upper, lower); int[] upperArray = new int[upper.size()]; for (int i = upper.size() - 1; i >= 0; --i) upperArray[i] = IndicesUtils.getNameWithType(upper.get(i)); this.upper = upperArray; this.lower = lower.getAllIndices().copy(); this.indicator = indicator; }
public boolean tryMap(int from, int to) { if (IndicesUtils.getNameWithType(to) != toName) return false; if ((IndicesUtils.getStateInt(from) != IndicesUtils.getStateInt(to)) != ((states & 0x4) == 0x4)) throw new InconsistentIndicesException(from); if ((states & (1 << IndicesUtils.getStateInt(to))) != 0) throw new InconsistentIndicesException(to); states |= 1 << IndicesUtils.getStateInt(to); return true; }
@Override public boolean tryMap(int from, int to) { int fromState = IndicesUtils.getStateInt(from); if (fromState != IndicesUtils.getStateInt(to) && !CC.isMetric(IndicesUtils.getType(from))) return false; int fromName = IndicesUtils.getNameWithType(from); IndexMappingBufferRecord record = map.get(fromName); if (record == null) { record = new IndexMappingBufferRecord(from, to); map.put(fromName, record); return true; } return record.tryMap(from, to); }
private PermutationGroup conjugatedSymmetriesOfSubIndices(SimpleIndices allIndices) { //positions of indices in allIndices that should be stabilized int[] stabilizedPoints = new int[allIndices.size() - indices.size()]; int[] nonStabilizedPoints = new int[indices.size()]; int[] mapping = new int[indices.size()]; int sPointer = 0, nPointer = 0, index; for (int s = 0; s < allIndices.size(); ++s) { index = Arrays.binarySearch(sortedIndicesNames, getNameWithType(allIndices.get(s))); if (index < 0) stabilizedPoints[sPointer++] = s; else { nonStabilizedPoints[nPointer] = s; mapping[nPointer++] = index; } } PermutationGroup result = allIndices.getSymmetries().getPermutationGroup(). pointwiseStabilizerRestricted(stabilizedPoints); return result.conjugate(Permutations.createPermutation(mapping)); }
private static void appendAllIndicesNamesT(Tensor tensor, TIntHashSet set, boolean includeScalarFunctions) { if (tensor instanceof SimpleTensor) { Indices ind = tensor.getIndices(); set.ensureCapacity(ind.size()); final int size = ind.size(); for (int i = 0; i < size; ++i) set.add(IndicesUtils.getNameWithType(ind.get(i))); } else if (tensor instanceof Power) { appendAllIndicesNamesT(tensor.get(0), set); } else if (tensor instanceof ScalarFunction && !includeScalarFunctions) return; else { Tensor t; for (int i = tensor.size() - 1; i >= 0; --i) { t = tensor.get(i); appendAllIndicesNamesT(t, set); } } }