@Override public int size(IndexType type) { int type_ = type.getType() << 24; int i = 0; for (; i < data.length && (data[i] & 0x7F000000) != type_; ++i) ; int size = 0; for (; i + size < data.length && (data[i + size] & 0x7F000000) == type_; ++size) ; return size; }
/** * Returns whether states of specified type are set. * * @return whether states of specified type are set */ public boolean fixedStates(IndexType type) { return states[type.getType()] != null; }
@Override public int get(IndexType type, int position) { int type_ = type.getType() << 24; int i; for (i = 0; i < data.length && (data[i] & 0x7F000000) != type_; ++i) ; int index = data[i + position]; if ((index & 0x7F000000) != type_) throw new IndexOutOfBoundsException(); return index; }
private TraceTransformer(IITransformer innerTransformer, Set<IndexType> typesToContract) { this.innerTransformer = innerTransformer; this.typesToContract = new HashSet<>(typesToContract); outerIndices = innerTransformer.getOuterIndices().clone(); for (IndexType type : typesToContract) { if (outerIndices.upper[type.getType()] != outerIndices.lower[type.getType()]) throw new IllegalArgumentException("Illegal trace usage."); if (outerIndices.upper[type.getType()] == 0) this.typesToContract.remove(type); outerIndices.upper[type.getType()] = outerIndices.lower[type.getType()] = 0; } }
@Override public int size(IndexType type) { int type_ = type.getType(), size = 0; int lowerPosition = Arrays.binarySearch(data, 0, firstLower, (type_ << 24) | 0x80000000); if (lowerPosition < 0) lowerPosition = ~lowerPosition; int upperPosition = Arrays.binarySearch(data, lowerPosition, firstLower, ((type_ + 1) << 24) | 0x80000000); if (upperPosition < 0) upperPosition = ~upperPosition; size += upperPosition - lowerPosition; lowerPosition = Arrays.binarySearch(data, firstLower, data.length, type_ << 24); if (lowerPosition < 0) lowerPosition = ~lowerPosition; upperPosition = Arrays.binarySearch(data, lowerPosition, data.length, (type_ + 1) << 24); if (upperPosition < 0) upperPosition = ~upperPosition; size += upperPosition - lowerPosition; return size; }
/** * Generates new index of a particular type. * * @param type index type * @return new index of a particular type */ public int generate(IndexType type) { return generate(type.getType()); }
/** * Creates structure of indices, which contains indices only of specified metric type. * * @param type index type * @param count number of indices * @throws IllegalArgumentException if type is non metric */ public static StructureOfIndices create(IndexType type, int count) { return create(type.getType(), count); }
/** * Returns index type enum value. * * @param index index * @return index type enum value */ public static IndexType getTypeEnum(int index) { return IndexType.getType(getType(index)); }
/** * Creates single index with specified name, type and state. * * @param name index name * @param type index type * @param state index state * @return index */ public static int createIndex(int name, IndexType type, boolean state) { return createIndex(name, type.getType(), state); }
/** * Changes index type to specified, represented by byte. * <p/> * <br/>Expression used by this method is: <b><code>(0x80FFFFFF & index) | ((0x7F & type) << 24)</code></b> * * @param type IndexType * @param index index to change type in * @return index with new type */ public static int setType(IndexType type, int index) { return setType(type.getType(), index); }
public static void assertType(IndexType type) { if (CC.isMetric(type.getType())) throw new IllegalArgumentException("Type should be non-metric."); }
@Override public SimpleIndices getOfType(IndexType type) { int type_ = type.getType() << 24; int i = 0; for (; i < data.length && (data[i] & 0x7F000000) != type_; ++i) ; int start = i; for (; i < data.length && (data[i] & 0x7F000000) == type_; ++i) ; int[] newData; if (start == 0 && i == data.length) newData = data; else newData = Arrays.copyOfRange(data, start, i); return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort(null, newData); }
/** * Returns states of specified type. * * @return states of specified type */ public BitArray getStates(IndexType type) { return states[type.getType()].clone(); }
/** * Returns true if metric is defined for specified index type. * * @param type index type * @return true if metric is defined for specified index type */ public static boolean isMetric(IndexType type) { return current().isMetric(type.getType()); }
/** * {@inheritDoc} * * @throws IndexOutOfBoundsException if no more allowed indices exist */ @Override public int generate(byte type) { IntProvider ig = generators.get(type); if (ig == null) throw new IndexOutOfBoundsException("No allowed indices with specified type: " + IndexType.getType(type)); return setType(type, ig.getNext()); }
/** * Attaches symmetry to simple tensor with respect to indices of specified type. * * @param tensor simple tensor * @param type type of indices * @param permutation permutation * @throws java.lang.IllegalStateException if this tensor is already in use (it's permutation group calculated) * @throws java.lang.IllegalArgumentException if degree of specified permutation differs from the size of indices * of specified type */ public static void addSymmetry(SimpleTensor tensor, IndexType type, Permutation permutation) { tensor.getIndices().getSymmetries().addSymmetry(type.getType(), permutation); }
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); }
private SimpleTensor setMatrixIndices0(SimpleTensor tensor, int... indices) { int[] newIndices = new int[tensor.getIndices().size()]; int j = 0; for (int i = 0; i < tensor.getIndices().size(); ++i) if (getType(tensor.getIndices().get(i)) == matrixType.getType()) newIndices[i] = indices[j++]; else newIndices[i] = tensor.getIndices().get(i); return setIndices(tensor, createSimple(null, newIndices)); }