@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; }
if (states[i] == null) for (int t = 0; ; ++t) { sb.append(IndexType.values()[i].getShortString()); if (t == typesCounts[i] - 1) break; for (int t = 0; t < typesCounts[i]; ++t) { sb.append('('); sb.append(IndexType.values()[i].getShortString()); sb.append(','); sb.append(states[i].get(t) ? 1 : 0);
if ((pn = node.content[i]).tokenType != TokenType.SimpleTensor) throw new IllegalArgumentException("Error in trace indices list."); if ((type = IndexType.fromShortString(((ParseTokenSimpleTensor) pn).name)) == null) if ((type = IndexType.valueOf(((ParseTokenSimpleTensor) pn).name)) == null) throw new IllegalArgumentException("Error in trace indices list."); types.add(type);
IndexType eType; for (byte type = IndexType.TYPES_COUNT - 1; type >= 0; --type) { eType = IndexType.values()[type]; singleType = parent.getIndices().getOfType(eType); from = fieldDescriptor.getParent().getStructureOfIndices().getTypeData(type).length;
/** * 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; }
@Override public int get(IndexType type, int position) { int type_ = type.getType(); 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; if (lowerPosition + position < upperPosition) return data[lowerPosition + position]; position = position - (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; if (lowerPosition + position < upperPosition) return data[lowerPosition + position]; throw new IndexOutOfBoundsException(); }
/** * 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."); }
/** * Returns states of specified type. * * @return states of specified type */ public BitArray getStates(IndexType type) { return states[type.getType()].clone(); }
@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); }
@Override public void apply(IndexGeneratorImpl generator, int[][] upper, int[][] lower) { OuterIndices innerIndices = innerTransformer.getOuterIndices(); int[][] preparedUpper = upper.clone(), preparedLower = lower.clone(); int i, generated; int[] l, u; for (IndexType type : typesToContract) { l = new int[innerIndices.lower[type.getType()]]; u = new int[innerIndices.lower[type.getType()]]; for (i = 0; i < l.length; ++i) { generated = generator.generate(type.getType()); l[i] = generated; u[i] = 0x80000000 | generated; } preparedLower[type.getType()] = l; preparedUpper[type.getType()] = u; } innerTransformer.apply(generator, preparedUpper, preparedLower); } }
@Override public Indices getOfType(IndexType type) { int type_ = type.getType(); int lowerPositionU = Arrays.binarySearch(data, 0, firstLower, (type_ << 24) | 0x80000000); if (lowerPositionU < 0) lowerPositionU = ~lowerPositionU; int upperPositionU = Arrays.binarySearch(data, lowerPositionU, firstLower, ((type_ + 1) << 24) | 0x80000000); if (upperPositionU < 0) upperPositionU = ~upperPositionU; int sizeU = upperPositionU - lowerPositionU; int lowerPositionL = Arrays.binarySearch(data, firstLower, data.length, type_ << 24); if (lowerPositionL < 0) lowerPositionL = ~lowerPositionL; int upperPositionL = Arrays.binarySearch(data, lowerPositionL, data.length, (type_ + 1) << 24); if (upperPositionL < 0) upperPositionL = ~upperPositionL; int sizeL = upperPositionL - lowerPositionL; if (sizeU + sizeL == data.length) return this; else if (sizeU + sizeL == 0) return IndicesFactory.EMPTY_INDICES; int[] indices = new int[sizeU + sizeL]; System.arraycopy(data, lowerPositionU, indices, 0, sizeU); System.arraycopy(data, lowerPositionL, indices, sizeU, sizeL); return new SortedIndices(indices, sizeU); }
/** * 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()); }