@Override public StructureOfIndices getStructureOfIndices() { return StructureOfIndices.create(this); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Wrapper wrapper = (Wrapper) o; return freeIndices.equals(wrapper.freeIndices) && IndexMappings.anyMappingExists(tensor, wrapper.tensor); }
pointers[j] = getTypeData((byte) j).from;
/** * 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(byte type, int count) { if (count == 0) return getEmpty(); return new StructureOfIndices(type, count); }
private static StructureOfIndices[] generateStructures(NameDescriptorForTensorFieldImpl parent, final int[] orders) { StructureOfIndices[] structureOfIndices = parent.structuresOfIndices.clone(); int j; for (int i = 0; i < orders.length; ++i) { for (j = 0; j < orders[i]; ++j) structureOfIndices[0] = structureOfIndices[0].append(structureOfIndices[i + 1].getInverted()); } return structureOfIndices; } }
/** * Adds specified symmetry to symmetries of indices of specified type. * * @param type type of indices * @param symmetry symmetry * @throws java.lang.IllegalStateException if this instance of symmetries is already in use (permutation group * calculated) * @throws java.lang.IllegalArgumentException if this structure of indices is inconsistent with specified * permutation (permutation mixes indices of different types) */ public void addSymmetry(byte type, Permutation symmetry) { if (symmetry.isIdentity()) return; if (permutationGroup != null) throw new IllegalStateException("Permutation group is already in use."); StructureOfIndices.TypeData data = structureOfIndices.getTypeData(type); if (data == null) throw new IllegalArgumentException("No such type: " + IndexType.getType(type)); if (data.length < symmetry.degree()) throw new IllegalArgumentException("Wrong symmetry length."); int[] s = new int[structureOfIndices.size()]; int i = 0; for (; i < data.from; ++i) s[i] = i; for (int j = 0; j < data.length; ++j, ++i) s[i] = symmetry.newIndexOf(j) + data.from; for (; i < structureOfIndices.size(); ++i) s[i] = i; generators.add(Permutations.createPermutation(symmetry.antisymmetry(), s)); }
private NameDescriptor createDescriptor(final String sname, final StructureOfIndices[] structuresOfIndices, int id) { if (structuresOfIndices.length != 1) return new NameDescriptorForTensorFieldImpl(sname, structuresOfIndices, id, sname.equals(diracDeltaName) && structuresOfIndices.length == 3); final StructureOfIndices its = structuresOfIndices[0]; if (its.size() != 2) return new NameDescriptorForSimpleTensor(sname, structuresOfIndices, id); for (byte b = 0; b < IndexType.TYPES_COUNT; ++b) if (its.typeCount(b) == 2) { if (CC.isMetric(b)) { if (sname.equals(kroneckerAndMetricNames[0]) || sname.equals(kroneckerAndMetricNames[1])) { NameDescriptor descriptor = new NameDescriptorForMetricAndKronecker(kroneckerAndMetricNames, b, id); descriptor.getSymmetries().add(b, false, 1, 0); return descriptor; } } else { if (sname.equals(kroneckerAndMetricNames[1])) throw new ParserException("Metric is not specified for non metric index type."); if (sname.equals(kroneckerAndMetricNames[0])) { if (its.getTypeData(b).states.get(0) != true || its.getTypeData(b).states.get(1) != false) throw new ParserException("Illegal Kroneckers indices states."); NameDescriptor descriptor = new NameDescriptorForMetricAndKronecker(kroneckerAndMetricNames, b, id); return descriptor; } } } return new NameDescriptorForSimpleTensor(sname, structuresOfIndices, id); }
public Tensor nextProductTree(int depth, Parameters parameters, Indices indices) { int productSize = getRandomValue(parameters.minProductSize, parameters.maxProductSize); indices = indices.getFree(); StructureOfIndices typeStructure = StructureOfIndices.create(IndicesFactory.createSimple(null, indices)); List<Tensor> descriptors = new ArrayList<>(); int totalIndicesCounts[] = new int[TYPES.length]; descriptors.add(nd = nextTensorTree(TensorType.Sum, depth - 1, parameters)); for (byte b : TYPES) { StructureOfIndices.TypeData typeData = IndicesFactory.createSimple(null, nd.getIndices().getFree()).getStructureOfIndices().getTypeData(b); if (typeData != null) totalIndicesCounts[b] += typeData.length; StructureOfIndices.TypeData typeData = typeStructure.getTypeData(b); if (typeData == null) continue; descriptors.add(nd = nextTensorTree(TensorType.Sum, depth - 1, parameters)); for (byte bb : TYPES) { StructureOfIndices.TypeData typeData1 = IndicesFactory.createSimple(null, nd.getIndices().getFree()).getStructureOfIndices().getTypeData(bb); if (typeData1 != null) totalIndicesCounts[bb] += typeData1.length; StructureOfIndices.TypeData typeData = typeStructure.getTypeData(b); if ((totalIndicesCounts[b] - (typeData == null ? 0 : typeData.length)) % 2 != 0) { int[] typeCount = new int[TYPES.length]; typeCount[b] = 1; descriptors.add(nextTensorTree(TensorType.Sum, depth - 1, parameters, IndicesFactory.createSimple(null, nextIndices(StructureOfIndices.create(TYPES, typeCount))))); ++totalIndicesCounts[b];
@Override public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; final StructureOfIndices other = (StructureOfIndices) obj; if (size != other.size()) return false; if (size == 0) return true; return Arrays.equals(this.typesCounts, other.typesCounts) && Arrays.deepEquals(this.states, other.states); }
final int argPosition, final int order) { if (!derivativeIndices.getStructureOfIndices().equals(parent.argIndices[argPosition].getInverted().getStructureOfIndices().pow(order))) throw new IllegalArgumentException("Illegal derivative indices."); eType = IndexType.values()[type]; singleType = parent.getIndices().getOfType(eType); from = fieldDescriptor.getParent().getStructureOfIndices().getTypeData(type).length; for (i = 0; i <= argPosition; ++i) from += structures[i + 1].getTypeData(type).length * orders[i]; for (i = 0; i < from; ++i) ib.append(singleType.get(i));
@Override public boolean is(ParseTokenSimpleTensor object) { String name = object.name; int i; for (i = 0; i < INPUT_VALUES_GENERAL_COUNT; ++i) if (name.equals(getStringInputName(i))) return true; for (i = 0; i < HAT_QUANTITIES_GENERAL_COUNT; ++i) if (name.equals(getStringHatQuantitieName(i))) return true; if (name.equals("F") && F_TYPES.isStructureOf(object.indices)) return true; if (name.equals("HATF")) return true; return false; } };
public NameAndStructureOfIndices[] getKeys() { IndexType[] toOmit = indicesAllowedToOmit.toArray(new IndexType[indicesAllowedToOmit.size()]); int omitted, i; NameAndStructureOfIndices[] keys = new NameAndStructureOfIndices[(1 << toOmit.length) - 1]; int[] allCounts; BitArray[] states; for (omitted = 1; omitted <= keys.length; ++omitted) { allCounts = originalStructureAndName.getStructure()[0].getTypesCounts(); states = originalStructureAndName.getStructure()[0].getStates(); for (i = 0; i < toOmit.length; ++i) if ((omitted & (1 << i)) != 0) { allCounts[toOmit[i].getType()] = 0; states[toOmit[i].getType()] = states[toOmit[i].getType()] == null ? null : BitArray.EMPTY; } StructureOfIndices[] structures = originalStructureAndName.getStructure().clone(); structures[0] = StructureOfIndices.create(allCounts, states); keys[omitted - 1] = new NameAndStructureOfIndices(originalStructureAndName.getName(), structures); } return keys; } }
for (i = 0; i < orders.length; ++i) for (j = 0; j < orders[i]; ++j) partition[++k] = structuresOfIndices[i + 1].getInverted(); int[][] mapping = baseStructure.getPartitionMappings(partition); symmetries.addSymmetry(convertPermutation(p, mapping[0], baseStructure.size())); int cycle[]; for (i = 0; i < orders.length; ++i) { if (structuresOfIndices[i + 1].size() != 0 && orders[i] >= 2) { cycle = Permutations.createBlockCycle(structuresOfIndices[i + 1].size(), 2); aggregator.addAll(mapping[j]); aggregator.addAll(mapping[j + 1]); symmetries.addSymmetry( Permutations.createPermutation(convertPermutation(cycle, aggregator.toArray(), baseStructure.size()))); aggregator.addAll(mapping[j + k]); cycle = Permutations.createBlockCycle(structuresOfIndices[i + 1].size(), orders[i]); symmetries.addSymmetry( Permutations.createPermutation(convertPermutation(cycle, aggregator.toArray(), baseStructure.size())));
private void ensurePartitionInitialized() { if (indicesPartitionMapping != null) return; if (!isDerivative()) { int[][] ret = new int[structuresOfIndices.length][]; Arrays.fill(ret, 1, ret.length, new int[0]); ret[0] = ArraysUtils.getSeriesFrom0(structuresOfIndices[0].size()); indicesPartitionMapping = ret; } NameDescriptorForTensorField parent = getParent(); StructureOfIndices[] partition = new StructureOfIndices[ArraysUtils.sum(orders) + 1]; partition[0] = parent.getStructureOfIndices(); int i, j; int totalOrder = 1; for (i = 0; i < structuresOfIndices.length - 1; ++i) { for (j = orders[i] - 1; j >= 0; --j) partition[totalOrder++] = parent.getArgStructureOfIndices(i); } indicesPartitionMapping = structuresOfIndices[0].getPartitionMappings(partition); }
public SimpleTransformer(ParseTokenSimpleTensor node, InsertionRule insertionRule) { this.node = node; //this.insertionRule = insertionRule; StructureOfIndices originalStructure = insertionRule.originalStructureAndName.getStructure()[0]; StructureOfIndices currentStructure = node.getIndicesTypeStructureAndName().getStructure()[0]; for (IndexType type : insertionRule.indicesAllowedToOmit) if (currentStructure.getStates(type).size() == 0) { BitArray originalStates = originalStructure.getStates(type); if (originalStates != null) { outerIndices.upper[type.getType()] = originalStates.bitCount(); outerIndices.lower[type.getType()] = originalStates.size() - outerIndices.upper[type.getType()]; } else { outerIndices.upper[type.getType()] = outerIndices.lower[type.getType()] = originalStructure.typeCount(type.getType()) / 2; } } else if (currentStructure.typeCount(type.getType()) != originalStructure.typeCount(type.getType())) throw new IllegalArgumentException(); outerIndices.init(); }
static final IndexType[] extractTypesFromMatrix(SimpleTensor matrix) { if (matrix.getIndices().size() != 3) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); NameDescriptor descriptor = CC.getNameDescriptor(matrix.getName()); StructureOfIndices typeStructure = descriptor.getStructureOfIndices(); byte metricType = -1, matrixType = -1; int typeCount; for (byte type = 0; type < IndexType.TYPES_COUNT; ++type) { typeCount = typeStructure.typeCount(type); if (typeCount == 0) continue; else if (typeCount == 2) { if (matrixType != -1) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); matrixType = type; if (CC.isMetric(matrixType)) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } else if (typeCount == 1) { if (metricType != -1) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); metricType = type; if (!CC.isMetric(metricType)) throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } else throw new IllegalArgumentException("Not a matrix: " + matrix + "."); } return new IndexType[]{IndexType.getType(metricType), IndexType.getType(matrixType)}; }
public static StructureOfIndices getEmpty() { if (EMPTY == null) EMPTY = new StructureOfIndices(); return EMPTY; }
@Override public StructureOfIndices getStructureOfIndices() { return StructureOfIndices.getEmpty(); } }
/** * @param indices sorted by type array of indices */ StructureOfIndices(int[] indices) { size = indices.length; int i; for (i = 0; i < size; ++i) ++typesCounts[IndicesUtils.getType(indices[i])]; int[] pointers = new int[IndexType.TYPES_COUNT]; for (i = 0; i < IndexType.TYPES_COUNT; ++i) if (!CC.isMetric((byte) i)) states[i] = createBBBA(typesCounts[i]); else pointers[i] = -1; byte type; for (i = 0; i < size; ++i) { type = IndicesUtils.getType(indices[i]); if (pointers[type] != -1) { if (IndicesUtils.getState(indices[i])) states[type].set(pointers[type]); ++pointers[type]; } } }
private void checkConsistency() { int i; for (i = 0; i < actualInput; ++i) { if (!(inputValues[i].get(0) instanceof SimpleTensor)) throw new IllegalArgumentException(); SimpleTensor st = (SimpleTensor) inputValues[i].get(0); NameDescriptor nd = CC.getNameDescriptor(st.getName()); if (!nd.getName(null).equals(getStringInputName(i))) throw new IllegalArgumentException(); } for (; i < INPUT_VALUES_GENERAL_COUNT; ++i) if (inputValues[i] != null) throw new IllegalArgumentException(); SimpleIndices indices = (SimpleIndices) inputValues[1].get(0).getIndices(); StructureOfIndices structureOfIndices = indices.getStructureOfIndices(); if (structureOfIndices.getTypeData(IndexType.LatinLower.getType()).length != structureOfIndices.size()) throw new IllegalArgumentException("Only Latin lower indices are legal."); int matrixIndicesCount = indices.size() - operatorOrder; if (matrixIndicesCount % 2 != 0) throw new IllegalArgumentException(); if (inputValues[0].get(0).getIndices().size() != matrixIndicesCount) throw new IllegalArgumentException(); for (i = 1; i < actualInput; ++i) { structureOfIndices = ((SimpleIndices) inputValues[i].get(0).getIndices()).getStructureOfIndices(); if (structureOfIndices.getTypeData(IndexType.LatinLower.getType()).length != structureOfIndices.size()) throw new IllegalArgumentException("Only Latin lower indices are legal."); if (structureOfIndices.size() + i - 1 != operatorOrder + matrixIndicesCount) throw new IllegalArgumentException(); } }