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 SimpleIndices getUpper() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.upper.length == 0) return EmptySimpleIndices.EMPTY_SIMPLE_INDICES_INSTANCE; return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort0(null, ul.upper, new UpperLowerIndices(ul.upper, new int[0])); }
/** * Returns {@code true} if this is structure of specified indices. * * @param indices indices * @return {@code true} if this is structure of specified indices */ public boolean isStructureOf(SimpleIndices indices) { if (size != indices.size()) return false; return equals(indices.getStructureOfIndices()); }
private SimpleIndices transformIndices(SimpleIndices old, NameAndStructureOfIndices oldDescriptor) { int[] newIndices = new int[old.size()]; for (int i = old.size() - 1; i >= 0; --i) { newIndices[i] = IndicesUtils.setType(transformer.newType(IndicesUtils.getTypeEnum(old.get(i)), oldDescriptor), old.get(i)); newIndices[i] = transformer.newIndex(newIndices[i], oldDescriptor); } return IndicesFactory.createSimple(null, newIndices); } }
/** * 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; }
/** * Creates symmetries with empty generating set. * * @param structureOfIndices structure of indices for which this symmetries can be assigned * @return symmetries with empty generating set for indices with specified structure */ public static IndicesSymmetries create(StructureOfIndices structureOfIndices) { if (structureOfIndices.size() == 0) return getEmpty(); return new IndicesSymmetries(structureOfIndices); }
/** * 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); }
/** * Appends specified {@code Indices}. * * @param indices indices to be appended * @return a reference to this object */ public IndicesBuilder append(Indices indices) { return append(indices.getAllIndices()); }
/** * 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 the structure of specified simple indices. * * @param indices simple indices */ public static StructureOfIndices create(SimpleIndices indices) { if (indices.size() == 0) return getEmpty(); return new StructureOfIndices(indices); }
@Override public Indices getLower() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.lower.length == 0) return EmptyIndices.EMPTY_INDICES_INSTANCE; return new SortedIndices(ul.lower, 0, new UpperLowerIndices(new int[0], ul.lower)); }
/** * Creates simple indices of simple tensor. * * @param symmetries symmetries * @param indices indices * @return simple indices of simple tensor */ public static SimpleIndices createOfTensor(IndicesSymmetries symmetries, SimpleIndices indices) { if (indices.size() == 0) return IndicesFactory.EMPTY_SIMPLE_INDICES; return new SimpleIndicesOfTensor(true, ((AbstractIndices) indices).data, symmetries); }
public static String toString(int[] indices, OutputFormat mode) { //todo refactor using StringBuilder since InconsistensIndicesException can be thrown return IndicesFactory.createSimple(null, indices).toString(mode); }
/** * For indices with zero length */ public static IndicesSymmetries getEmpty() { if (EMPTY_INDICES_SYMMETRIES == null) EMPTY_INDICES_SYMMETRIES = new IndicesSymmetries(StructureOfIndices.getEmpty(), Collections.EMPTY_LIST, null); return EMPTY_INDICES_SYMMETRIES; }
@Override protected SimpleIndices create(int[] data, IndicesSymmetries symmetries) { return new SimpleIndicesIsolated(true, data, symmetries == null ? null : symmetries.clone()); }
@Override public SimpleIndices getLower() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.lower.length == 0) return EmptySimpleIndices.EMPTY_SIMPLE_INDICES_INSTANCE; return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort0(null, ul.lower, new UpperLowerIndices(new int[0], ul.lower)); }
@Override public Indices getUpper() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.upper.length == 0) return EmptyIndices.EMPTY_INDICES_INSTANCE; return new SortedIndices(ul.upper, ul.upper.length, new UpperLowerIndices(ul.upper, new int[0])); }